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;
162 GdkModifierType start_button_mask;
167 GtkTargetList *source_targets;
168 GdkDragAction source_actions;
170 GtkTargetList *dest_targets;
171 GdkDragAction dest_actions;
173 GtkTreeRowReference *dest_item;
174 GtkIconViewDropPosition dest_pos;
177 GtkTreeRowReference *scroll_to_path;
178 gfloat scroll_to_row_align;
179 gfloat scroll_to_col_align;
180 guint scroll_to_use_align : 1;
182 guint source_set : 1;
184 guint reorderable : 1;
185 guint empty_view_drop :1;
187 guint ctrl_pressed : 1;
188 guint shift_pressed : 1;
201 ACTIVATE_CURSOR_ITEM,
225 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
226 static void gtk_icon_view_finalize (GObject *object);
227 static void gtk_icon_view_set_property (GObject *object,
231 static void gtk_icon_view_get_property (GObject *object,
236 /* GtkObject vfuncs */
237 static void gtk_icon_view_destroy (GtkObject *object);
239 /* GtkWidget vfuncs */
240 static void gtk_icon_view_realize (GtkWidget *widget);
241 static void gtk_icon_view_unrealize (GtkWidget *widget);
242 static void gtk_icon_view_style_set (GtkWidget *widget,
243 GtkStyle *previous_style);
244 static void gtk_icon_view_state_changed (GtkWidget *widget,
245 GtkStateType previous_state);
246 static void gtk_icon_view_size_request (GtkWidget *widget,
247 GtkRequisition *requisition);
248 static void gtk_icon_view_size_allocate (GtkWidget *widget,
249 GtkAllocation *allocation);
250 static gboolean gtk_icon_view_expose (GtkWidget *widget,
251 GdkEventExpose *expose);
252 static gboolean gtk_icon_view_motion (GtkWidget *widget,
253 GdkEventMotion *event);
254 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
255 GdkEventButton *event);
256 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
257 GdkEventButton *event);
258 static gboolean gtk_icon_view_key_press (GtkWidget *widget,
260 static gboolean gtk_icon_view_key_release (GtkWidget *widget,
262 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
265 /* GtkContainer vfuncs */
266 static void gtk_icon_view_remove (GtkContainer *container,
268 static void gtk_icon_view_forall (GtkContainer *container,
269 gboolean include_internals,
270 GtkCallback callback,
271 gpointer callback_data);
273 /* GtkIconView vfuncs */
274 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
276 GtkAdjustment *vadj);
277 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
278 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
279 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
280 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
281 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
283 /* Internal functions */
284 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
285 GtkIconView *icon_view);
286 static void gtk_icon_view_layout (GtkIconView *icon_view);
287 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
290 GtkIconViewItem *item,
292 GdkDrawable *drawable,
295 gboolean draw_focus);
296 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
299 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
301 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
302 GtkIconViewItem *item);
303 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
304 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
305 GtkIconViewItem *item,
307 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
310 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
311 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
312 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
313 GtkIconViewItem *item,
318 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
319 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
320 GtkIconViewItem *item);
321 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
322 GtkIconViewItem *item,
324 static void gtk_icon_view_update_rubberband (gpointer data);
325 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
326 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
327 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
330 GtkMovementStep step,
332 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
333 GtkMovementStep step,
335 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
337 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
339 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
341 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
343 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
344 GtkIconViewItem *item);
345 static void gtk_icon_view_select_item (GtkIconView *icon_view,
346 GtkIconViewItem *item);
347 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
348 GtkIconViewItem *item);
349 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
350 GtkIconViewItem *anchor,
351 GtkIconViewItem *cursor);
352 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
355 gboolean only_in_cell,
356 GtkIconViewCellInfo **cell_at_pos);
357 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
358 GtkIconViewItem *item,
359 GtkIconViewCellInfo *cell_info,
360 GdkRectangle *cell_area);
361 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
362 GtkIconViewItem *item,
363 GtkIconViewCellInfo *info,
365 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
366 GtkCellRenderer *renderer);
367 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
368 GtkIconViewItem *item);
369 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
370 GtkCellRenderer *renderer,
372 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
373 GtkCellRenderer *renderer,
375 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
376 GtkCellRenderer *renderer,
377 const gchar *attribute,
379 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
380 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
381 GtkCellRenderer *renderer);
382 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
383 GtkCellRenderer *cell,
384 GtkCellLayoutDataFunc func,
386 GDestroyNotify destroy);
387 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
388 GtkCellRenderer *cell,
390 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
392 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
393 GtkIconViewItem *item,
394 GtkIconViewCellInfo *cell_info,
396 static void gtk_icon_view_put (GtkIconView *icon_view,
398 GtkIconViewItem *item,
400 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
401 GtkIconView *icon_view);
402 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
403 GtkIconViewItem *item,
404 GtkIconViewCellInfo *cell_info,
406 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
407 gboolean cancel_editing);
409 /* Source side drag signals */
410 static void gtk_icon_view_drag_begin (GtkWidget *widget,
411 GdkDragContext *context);
412 static void gtk_icon_view_drag_end (GtkWidget *widget,
413 GdkDragContext *context);
414 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
415 GdkDragContext *context,
416 GtkSelectionData *selection_data,
419 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
420 GdkDragContext *context);
422 /* Target side drag signals */
423 static void gtk_icon_view_drag_leave (GtkWidget *widget,
424 GdkDragContext *context,
426 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
427 GdkDragContext *context,
431 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
432 GdkDragContext *context,
436 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
437 GdkDragContext *context,
440 GtkSelectionData *selection_data,
443 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
444 GdkEventMotion *event);
446 static void remove_scroll_timeout (GtkIconView *icon_view);
447 static void clear_dest_info (GtkIconView *icon_view);
448 static void clear_source_info (GtkIconView *icon_view);
450 static void adjust_wrap_width (GtkIconView *icon_view,
451 GtkIconViewItem *item);
453 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
455 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
456 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
457 gtk_icon_view_cell_layout_init))
460 gtk_icon_view_class_init (GtkIconViewClass *klass)
462 GObjectClass *gobject_class;
463 GtkObjectClass *object_class;
464 GtkWidgetClass *widget_class;
465 GtkContainerClass *container_class;
466 GtkBindingSet *binding_set;
468 binding_set = gtk_binding_set_by_class (klass);
470 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
472 gobject_class = (GObjectClass *) klass;
473 object_class = (GtkObjectClass *) klass;
474 widget_class = (GtkWidgetClass *) klass;
475 container_class = (GtkContainerClass *) klass;
477 gobject_class->finalize = gtk_icon_view_finalize;
478 gobject_class->set_property = gtk_icon_view_set_property;
479 gobject_class->get_property = gtk_icon_view_get_property;
481 object_class->destroy = gtk_icon_view_destroy;
483 widget_class->realize = gtk_icon_view_realize;
484 widget_class->unrealize = gtk_icon_view_unrealize;
485 widget_class->style_set = gtk_icon_view_style_set;
486 widget_class->get_accessible = gtk_icon_view_get_accessible;
487 widget_class->size_request = gtk_icon_view_size_request;
488 widget_class->size_allocate = gtk_icon_view_size_allocate;
489 widget_class->expose_event = gtk_icon_view_expose;
490 widget_class->motion_notify_event = gtk_icon_view_motion;
491 widget_class->button_press_event = gtk_icon_view_button_press;
492 widget_class->button_release_event = gtk_icon_view_button_release;
493 widget_class->key_press_event = gtk_icon_view_key_press;
494 widget_class->key_release_event = gtk_icon_view_key_release;
495 widget_class->drag_begin = gtk_icon_view_drag_begin;
496 widget_class->drag_end = gtk_icon_view_drag_end;
497 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
498 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
499 widget_class->drag_leave = gtk_icon_view_drag_leave;
500 widget_class->drag_motion = gtk_icon_view_drag_motion;
501 widget_class->drag_drop = gtk_icon_view_drag_drop;
502 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
503 widget_class->state_changed = gtk_icon_view_state_changed;
505 container_class->remove = gtk_icon_view_remove;
506 container_class->forall = gtk_icon_view_forall;
508 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
509 klass->select_all = gtk_icon_view_real_select_all;
510 klass->unselect_all = gtk_icon_view_real_unselect_all;
511 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
512 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
513 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
514 klass->move_cursor = gtk_icon_view_real_move_cursor;
518 * GtkIconView:selection-mode:
520 * The ::selection-mode property specifies the selection mode of
521 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
522 * is enabled, for the other modes, only keyboard selection is possible.
526 g_object_class_install_property (gobject_class,
528 g_param_spec_enum ("selection-mode",
529 P_("Selection mode"),
530 P_("The selection mode"),
531 GTK_TYPE_SELECTION_MODE,
532 GTK_SELECTION_SINGLE,
533 GTK_PARAM_READWRITE));
536 * GtkIconView:pixbuf-column:
538 * The ::pixbuf-column property contains the number of the model column
539 * containing the pixbufs which are displayed. The pixbuf column must be
540 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
541 * display of pixbufs.
545 g_object_class_install_property (gobject_class,
547 g_param_spec_int ("pixbuf-column",
549 P_("Model column used to retrieve the icon pixbuf from"),
551 GTK_PARAM_READWRITE));
554 * GtkIconView:text-column:
556 * The ::text-column property contains the number of the model column
557 * containing the texts which are displayed. The text column must be
558 * of type #G_TYPE_STRING. If this property and the :markup-column
559 * property are both set to -1, no texts are displayed.
563 g_object_class_install_property (gobject_class,
565 g_param_spec_int ("text-column",
567 P_("Model column used to retrieve the text from"),
569 GTK_PARAM_READWRITE));
573 * GtkIconView:markup-column:
575 * The ::markup-column property contains the number of the model column
576 * containing markup information to be displayed. The markup column must be
577 * of type #G_TYPE_STRING. If this property and the :text-column property
578 * are both set to column numbers, it overrides the text column.
579 * If both are set to -1, no texts are displayed.
583 g_object_class_install_property (gobject_class,
585 g_param_spec_int ("markup-column",
587 P_("Model column used to retrieve the text if using Pango markup"),
589 GTK_PARAM_READWRITE));
591 g_object_class_install_property (gobject_class,
593 g_param_spec_object ("model",
594 P_("Icon View Model"),
595 P_("The model for the icon view"),
597 GTK_PARAM_READWRITE));
600 * GtkIconView:columns:
602 * The columns property contains the number of the columns in which the
603 * items should be displayed. If it is -1, the number of columns will
604 * be chosen automatically to fill the available area.
608 g_object_class_install_property (gobject_class,
610 g_param_spec_int ("columns",
611 P_("Number of columns"),
612 P_("Number of columns to display"),
614 GTK_PARAM_READWRITE));
618 * GtkIconView:item-width:
620 * The item-width property specifies the width to use for each item.
621 * If it is set to -1, the icon view will automatically determine a
622 * suitable item size.
626 g_object_class_install_property (gobject_class,
628 g_param_spec_int ("item-width",
629 P_("Width for each item"),
630 P_("The width used for each item"),
632 GTK_PARAM_READWRITE));
635 * GtkIconView:spacing:
637 * The spacing property specifies the space which is inserted between
638 * the cells (i.e. the icon and the text) of an item.
642 g_object_class_install_property (gobject_class,
644 g_param_spec_int ("spacing",
646 P_("Space which is inserted between cells of an item"),
648 GTK_PARAM_READWRITE));
651 * GtkIconView:row-spacing:
653 * The row-spacing property specifies the space which is inserted between
654 * the rows of the icon view.
658 g_object_class_install_property (gobject_class,
660 g_param_spec_int ("row-spacing",
662 P_("Space which is inserted between grid rows"),
664 GTK_PARAM_READWRITE));
667 * GtkIconView:column-spacing:
669 * The column-spacing property specifies the space which is inserted between
670 * the columns of the icon view.
674 g_object_class_install_property (gobject_class,
676 g_param_spec_int ("column-spacing",
677 P_("Column Spacing"),
678 P_("Space which is inserted between grid columns"),
680 GTK_PARAM_READWRITE));
683 * GtkIconView:margin:
685 * The margin property specifies the space which is inserted
686 * at the edges of the icon view.
690 g_object_class_install_property (gobject_class,
692 g_param_spec_int ("margin",
694 P_("Space which is inserted at the edges of the icon view"),
696 GTK_PARAM_READWRITE));
700 * GtkIconView:orientation:
702 * The orientation property specifies how the cells (i.e. the icon and
703 * the text) of the item are positioned relative to each other.
707 g_object_class_install_property (gobject_class,
709 g_param_spec_enum ("orientation",
711 P_("How the text and icon of each item are positioned relative to each other"),
712 GTK_TYPE_ORIENTATION,
713 GTK_ORIENTATION_VERTICAL,
714 GTK_PARAM_READWRITE));
717 * GtkIconView:reorderable:
719 * The reorderable property specifies if the items can be reordered
724 g_object_class_install_property (gobject_class,
726 g_param_spec_boolean ("reorderable",
728 P_("View is reorderable"),
732 /* Style properties */
733 gtk_widget_class_install_style_property (widget_class,
734 g_param_spec_boxed ("selection-box-color",
735 P_("Selection Box Color"),
736 P_("Color of the selection box"),
738 GTK_PARAM_READABLE));
740 gtk_widget_class_install_style_property (widget_class,
741 g_param_spec_uchar ("selection-box-alpha",
742 P_("Selection Box Alpha"),
743 P_("Opacity of the selection box"),
746 GTK_PARAM_READABLE));
749 widget_class->set_scroll_adjustments_signal =
750 g_signal_new (I_("set_scroll_adjustments"),
751 G_TYPE_FROM_CLASS (gobject_class),
753 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
755 _gtk_marshal_VOID__OBJECT_OBJECT,
757 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
759 icon_view_signals[ITEM_ACTIVATED] =
760 g_signal_new (I_("item_activated"),
761 G_TYPE_FROM_CLASS (gobject_class),
763 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
765 g_cclosure_marshal_VOID__BOXED,
769 icon_view_signals[SELECTION_CHANGED] =
770 g_signal_new (I_("selection-changed"),
771 G_TYPE_FROM_CLASS (gobject_class),
773 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
775 g_cclosure_marshal_VOID__VOID,
778 icon_view_signals[SELECT_ALL] =
779 g_signal_new (I_("select_all"),
780 G_TYPE_FROM_CLASS (gobject_class),
781 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
782 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
784 g_cclosure_marshal_VOID__VOID,
787 icon_view_signals[UNSELECT_ALL] =
788 g_signal_new (I_("unselect_all"),
789 G_TYPE_FROM_CLASS (gobject_class),
790 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
791 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
793 g_cclosure_marshal_VOID__VOID,
796 icon_view_signals[SELECT_CURSOR_ITEM] =
797 g_signal_new (I_("select_cursor_item"),
798 G_TYPE_FROM_CLASS (gobject_class),
799 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
800 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
802 g_cclosure_marshal_VOID__VOID,
805 icon_view_signals[TOGGLE_CURSOR_ITEM] =
806 g_signal_new (I_("toggle_cursor_item"),
807 G_TYPE_FROM_CLASS (gobject_class),
808 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
809 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
811 g_cclosure_marshal_VOID__VOID,
814 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
815 g_signal_new (I_("activate_cursor_item"),
816 G_TYPE_FROM_CLASS (gobject_class),
817 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
818 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
820 _gtk_marshal_BOOLEAN__VOID,
823 icon_view_signals[MOVE_CURSOR] =
824 g_signal_new (I_("move_cursor"),
825 G_TYPE_FROM_CLASS (gobject_class),
826 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
827 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
829 _gtk_marshal_BOOLEAN__ENUM_INT,
831 GTK_TYPE_MOVEMENT_STEP,
835 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
837 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
839 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
840 "toggle_cursor_item", 0);
842 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
843 "activate_cursor_item", 0);
844 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
845 "activate_cursor_item", 0);
846 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
847 "activate_cursor_item", 0);
848 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
849 "activate_cursor_item", 0);
851 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
852 GTK_MOVEMENT_DISPLAY_LINES, -1);
853 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
854 GTK_MOVEMENT_DISPLAY_LINES, -1);
856 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
857 GTK_MOVEMENT_DISPLAY_LINES, 1);
858 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
859 GTK_MOVEMENT_DISPLAY_LINES, 1);
861 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
862 GTK_MOVEMENT_DISPLAY_LINES, -1);
864 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
865 GTK_MOVEMENT_DISPLAY_LINES, 1);
867 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
868 GTK_MOVEMENT_BUFFER_ENDS, -1);
869 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
870 GTK_MOVEMENT_BUFFER_ENDS, -1);
872 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
873 GTK_MOVEMENT_BUFFER_ENDS, 1);
874 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
875 GTK_MOVEMENT_BUFFER_ENDS, 1);
877 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
878 GTK_MOVEMENT_PAGES, -1);
879 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
880 GTK_MOVEMENT_PAGES, -1);
882 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
883 GTK_MOVEMENT_PAGES, 1);
884 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
885 GTK_MOVEMENT_PAGES, 1);
887 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
888 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
889 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
890 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
892 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
893 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
894 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
895 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
899 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
901 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
902 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
903 iface->clear = gtk_icon_view_cell_layout_clear;
904 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
905 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
906 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
907 iface->reorder = gtk_icon_view_cell_layout_reorder;
908 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
912 gtk_icon_view_init (GtkIconView *icon_view)
914 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
916 icon_view->priv->width = 0;
917 icon_view->priv->height = 0;
918 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
919 icon_view->priv->pressed_button = -1;
920 icon_view->priv->press_start_x = -1;
921 icon_view->priv->press_start_y = -1;
922 icon_view->priv->text_column = -1;
923 icon_view->priv->markup_column = -1;
924 icon_view->priv->pixbuf_column = -1;
925 icon_view->priv->text_cell = -1;
926 icon_view->priv->pixbuf_cell = -1;
928 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
930 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
932 icon_view->priv->cell_list = NULL;
933 icon_view->priv->n_cells = 0;
934 icon_view->priv->cursor_cell = -1;
936 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
938 icon_view->priv->columns = -1;
939 icon_view->priv->item_width = -1;
940 icon_view->priv->spacing = 0;
941 icon_view->priv->row_spacing = 6;
942 icon_view->priv->column_spacing = 6;
943 icon_view->priv->margin = 6;
947 gtk_icon_view_destroy (GtkObject *object)
949 GtkIconView *icon_view;
951 icon_view = GTK_ICON_VIEW (object);
953 gtk_icon_view_stop_editing (icon_view, TRUE);
955 gtk_icon_view_set_model (icon_view, NULL);
957 if (icon_view->priv->layout_idle_id != 0)
959 g_source_remove (icon_view->priv->layout_idle_id);
960 icon_view->priv->layout_idle_id = 0;
963 if (icon_view->priv->scroll_to_path != NULL)
965 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
966 icon_view->priv->scroll_to_path = NULL;
969 remove_scroll_timeout (icon_view);
971 if (icon_view->priv->hadjustment != NULL)
973 g_object_unref (icon_view->priv->hadjustment);
974 icon_view->priv->hadjustment = NULL;
977 if (icon_view->priv->vadjustment != NULL)
979 g_object_unref (icon_view->priv->vadjustment);
980 icon_view->priv->vadjustment = NULL;
983 clear_dest_info (icon_view);
984 clear_source_info (icon_view);
986 (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
989 /* GObject methods */
991 gtk_icon_view_finalize (GObject *object)
993 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
995 (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
1000 gtk_icon_view_set_property (GObject *object,
1002 const GValue *value,
1005 GtkIconView *icon_view;
1007 icon_view = GTK_ICON_VIEW (object);
1011 case PROP_SELECTION_MODE:
1012 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1014 case PROP_PIXBUF_COLUMN:
1015 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1017 case PROP_TEXT_COLUMN:
1018 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1020 case PROP_MARKUP_COLUMN:
1021 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1024 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1026 case PROP_ORIENTATION:
1027 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1030 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1032 case PROP_ITEM_WIDTH:
1033 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1036 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1038 case PROP_ROW_SPACING:
1039 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1041 case PROP_COLUMN_SPACING:
1042 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1045 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1047 case PROP_REORDERABLE:
1048 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1052 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1058 gtk_icon_view_get_property (GObject *object,
1063 GtkIconView *icon_view;
1065 icon_view = GTK_ICON_VIEW (object);
1069 case PROP_SELECTION_MODE:
1070 g_value_set_enum (value, icon_view->priv->selection_mode);
1072 case PROP_PIXBUF_COLUMN:
1073 g_value_set_int (value, icon_view->priv->pixbuf_column);
1075 case PROP_TEXT_COLUMN:
1076 g_value_set_int (value, icon_view->priv->text_column);
1078 case PROP_MARKUP_COLUMN:
1079 g_value_set_int (value, icon_view->priv->markup_column);
1082 g_value_set_object (value, icon_view->priv->model);
1084 case PROP_ORIENTATION:
1085 g_value_set_enum (value, icon_view->priv->orientation);
1088 g_value_set_int (value, icon_view->priv->columns);
1090 case PROP_ITEM_WIDTH:
1091 g_value_set_int (value, icon_view->priv->item_width);
1094 g_value_set_int (value, icon_view->priv->spacing);
1096 case PROP_ROW_SPACING:
1097 g_value_set_int (value, icon_view->priv->row_spacing);
1099 case PROP_COLUMN_SPACING:
1100 g_value_set_int (value, icon_view->priv->column_spacing);
1103 g_value_set_int (value, icon_view->priv->margin);
1105 case PROP_REORDERABLE:
1106 g_value_set_boolean (value, icon_view->priv->reorderable);
1110 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1115 /* GtkWidget signals */
1117 gtk_icon_view_realize (GtkWidget *widget)
1119 GtkIconView *icon_view;
1120 GdkWindowAttr attributes;
1121 gint attributes_mask;
1123 icon_view = GTK_ICON_VIEW (widget);
1125 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1127 /* Make the main, clipping window */
1128 attributes.window_type = GDK_WINDOW_CHILD;
1129 attributes.x = widget->allocation.x;
1130 attributes.y = widget->allocation.y;
1131 attributes.width = widget->allocation.width;
1132 attributes.height = widget->allocation.height;
1133 attributes.wclass = GDK_INPUT_OUTPUT;
1134 attributes.visual = gtk_widget_get_visual (widget);
1135 attributes.colormap = gtk_widget_get_colormap (widget);
1136 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1138 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1140 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1141 &attributes, attributes_mask);
1142 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1143 gdk_window_set_user_data (widget->window, widget);
1145 /* Make the window for the icon view */
1148 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1149 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1150 attributes.event_mask = (GDK_EXPOSURE_MASK |
1152 GDK_POINTER_MOTION_MASK |
1153 GDK_BUTTON_PRESS_MASK |
1154 GDK_BUTTON_RELEASE_MASK |
1155 GDK_KEY_PRESS_MASK |
1156 GDK_KEY_RELEASE_MASK) |
1157 gtk_widget_get_events (widget);
1159 icon_view->priv->bin_window = gdk_window_new (widget->window,
1160 &attributes, attributes_mask);
1161 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1163 widget->style = gtk_style_attach (widget->style, widget->window);
1164 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1166 gdk_window_show (icon_view->priv->bin_window);
1170 gtk_icon_view_unrealize (GtkWidget *widget)
1172 GtkIconView *icon_view;
1174 icon_view = GTK_ICON_VIEW (widget);
1176 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1177 gdk_window_destroy (icon_view->priv->bin_window);
1178 icon_view->priv->bin_window = NULL;
1180 /* GtkWidget::unrealize destroys children and widget->window */
1181 if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
1182 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
1186 gtk_icon_view_state_changed (GtkWidget *widget,
1187 GtkStateType previous_state)
1189 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1191 if (GTK_WIDGET_REALIZED (widget))
1193 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1194 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1197 gtk_widget_queue_draw (widget);
1201 gtk_icon_view_style_set (GtkWidget *widget,
1202 GtkStyle *previous_style)
1204 GtkIconView *icon_view;
1206 g_return_if_fail (GTK_IS_ICON_VIEW (widget));
1208 icon_view = GTK_ICON_VIEW (widget);
1210 if (GTK_WIDGET_REALIZED (widget))
1212 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1213 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1216 gtk_widget_queue_resize (widget);
1220 gtk_icon_view_size_request (GtkWidget *widget,
1221 GtkRequisition *requisition)
1223 GtkIconView *icon_view;
1226 icon_view = GTK_ICON_VIEW (widget);
1228 requisition->width = icon_view->priv->width;
1229 requisition->height = icon_view->priv->height;
1231 tmp_list = icon_view->priv->children;
1235 GtkIconViewChild *child = tmp_list->data;
1236 GtkRequisition child_requisition;
1238 tmp_list = tmp_list->next;
1240 if (GTK_WIDGET_VISIBLE (child->widget))
1241 gtk_widget_size_request (child->widget, &child_requisition);
1246 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1250 for (list = icon_view->priv->children; list; list = list->next)
1252 GtkIconViewChild *child = list->data;
1253 GtkAllocation allocation;
1255 /* totally ignore our child's requisition */
1256 if (child->cell < 0)
1258 allocation.x = child->item->x;
1259 allocation.y = child->item->y;
1260 allocation.width = child->item->width;
1261 allocation.height = child->item->height;
1265 GdkRectangle *box = &child->item->box[child->cell];
1267 allocation.x = box->x;
1268 allocation.y = box->y;
1269 allocation.width = box->width;
1270 allocation.height = box->height;
1273 gtk_widget_size_allocate (child->widget, &allocation);
1278 gtk_icon_view_size_allocate (GtkWidget *widget,
1279 GtkAllocation *allocation)
1281 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1283 GtkAdjustment *hadjustment, *vadjustment;
1285 widget->allocation = *allocation;
1287 if (GTK_WIDGET_REALIZED (widget))
1289 gdk_window_move_resize (widget->window,
1290 allocation->x, allocation->y,
1291 allocation->width, allocation->height);
1292 gdk_window_resize (icon_view->priv->bin_window,
1293 MAX (icon_view->priv->width, allocation->width),
1294 MAX (icon_view->priv->height, allocation->height));
1297 gtk_icon_view_layout (icon_view);
1299 gtk_icon_view_allocate_children (icon_view);
1301 hadjustment = icon_view->priv->hadjustment;
1302 vadjustment = icon_view->priv->vadjustment;
1304 hadjustment->page_size = allocation->width;
1305 hadjustment->page_increment = allocation->width * 0.9;
1306 hadjustment->step_increment = allocation->width * 0.1;
1307 hadjustment->lower = 0;
1308 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1310 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1311 gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
1313 vadjustment->page_size = allocation->height;
1314 vadjustment->page_increment = allocation->height * 0.9;
1315 vadjustment->step_increment = allocation->height * 0.1;
1316 vadjustment->lower = 0;
1317 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1319 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1320 gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
1322 if (GTK_WIDGET_REALIZED (widget) &&
1323 icon_view->priv->scroll_to_path)
1326 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1327 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1328 icon_view->priv->scroll_to_path = NULL;
1330 gtk_icon_view_scroll_to_path (icon_view, path,
1331 icon_view->priv->scroll_to_use_align,
1332 icon_view->priv->scroll_to_row_align,
1333 icon_view->priv->scroll_to_col_align);
1334 gtk_tree_path_free (path);
1338 gtk_adjustment_changed (hadjustment);
1339 gtk_adjustment_changed (vadjustment);
1344 gtk_icon_view_expose (GtkWidget *widget,
1345 GdkEventExpose *expose)
1347 GtkIconView *icon_view;
1352 GtkIconViewDropPosition dest_pos;
1353 GtkIconViewItem *dest_item = NULL;
1355 icon_view = GTK_ICON_VIEW (widget);
1357 if (expose->window != icon_view->priv->bin_window)
1360 cr = gdk_cairo_create (icon_view->priv->bin_window);
1361 cairo_set_line_width (cr, 1.);
1363 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1367 dest_index = gtk_tree_path_get_indices (path)[0];
1368 gtk_tree_path_free (path);
1373 for (icons = icon_view->priv->items; icons; icons = icons->next)
1375 GtkIconViewItem *item = icons->data;
1380 area.width = item->width;
1381 area.height = item->height;
1383 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1386 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1387 icon_view->priv->bin_window,
1388 item->x, item->y, TRUE);
1390 if (dest_index == item->index)
1398 case GTK_ICON_VIEW_DROP_INTO:
1399 gtk_paint_focus (widget->style,
1400 icon_view->priv->bin_window,
1401 GTK_WIDGET_STATE (widget),
1404 "iconview-drop-indicator",
1405 dest_item->x, dest_item->y,
1406 dest_item->width, dest_item->height);
1408 case GTK_ICON_VIEW_DROP_ABOVE:
1409 gtk_paint_focus (widget->style,
1410 icon_view->priv->bin_window,
1411 GTK_WIDGET_STATE (widget),
1414 "iconview-drop-indicator",
1415 dest_item->x, dest_item->y - 1,
1416 dest_item->width, 2);
1418 case GTK_ICON_VIEW_DROP_LEFT:
1419 gtk_paint_focus (widget->style,
1420 icon_view->priv->bin_window,
1421 GTK_WIDGET_STATE (widget),
1424 "iconview-drop-indicator",
1425 dest_item->x - 1, dest_item->y,
1426 2, dest_item->height);
1428 case GTK_ICON_VIEW_DROP_BELOW:
1429 gtk_paint_focus (widget->style,
1430 icon_view->priv->bin_window,
1431 GTK_WIDGET_STATE (widget),
1434 "iconview-drop-indicator",
1435 dest_item->x, dest_item->y + dest_item->height - 1,
1436 dest_item->width, 2);
1438 case GTK_ICON_VIEW_DROP_RIGHT:
1439 gtk_paint_focus (widget->style,
1440 icon_view->priv->bin_window,
1441 GTK_WIDGET_STATE (widget),
1444 "iconview-drop-indicator",
1445 dest_item->x + dest_item->width - 1, dest_item->y,
1446 2, dest_item->height);
1447 case GTK_ICON_VIEW_NO_DROP: ;
1452 if (icon_view->priv->doing_rubberband)
1454 GdkRectangle *rectangles;
1457 gdk_region_get_rectangles (expose->region,
1461 while (n_rectangles--)
1462 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1464 g_free (rectangles);
1469 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);
1475 rubberband_scroll_timeout (gpointer data)
1477 GtkIconView *icon_view;
1482 value = MIN (icon_view->priv->vadjustment->value +
1483 icon_view->priv->scroll_value_diff,
1484 icon_view->priv->vadjustment->upper -
1485 icon_view->priv->vadjustment->page_size);
1487 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1489 gtk_icon_view_update_rubberband (icon_view);
1495 gtk_icon_view_motion (GtkWidget *widget,
1496 GdkEventMotion *event)
1498 GtkIconView *icon_view;
1501 icon_view = GTK_ICON_VIEW (widget);
1503 gtk_icon_view_maybe_begin_drag (icon_view, event);
1505 if (icon_view->priv->doing_rubberband)
1507 gtk_icon_view_update_rubberband (widget);
1509 abs_y = event->y - icon_view->priv->height *
1510 (icon_view->priv->vadjustment->value /
1511 (icon_view->priv->vadjustment->upper -
1512 icon_view->priv->vadjustment->lower));
1514 if (abs_y < 0 || abs_y > widget->allocation.height)
1517 icon_view->priv->scroll_value_diff = abs_y;
1519 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1521 icon_view->priv->event_last_x = event->x;
1522 icon_view->priv->event_last_y = event->y;
1524 if (icon_view->priv->scroll_timeout_id == 0)
1525 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1529 remove_scroll_timeout (icon_view);
1536 gtk_icon_view_remove (GtkContainer *container,
1539 GtkIconView *icon_view;
1540 GtkIconViewChild *child = NULL;
1543 icon_view = GTK_ICON_VIEW (container);
1545 tmp_list = icon_view->priv->children;
1548 child = tmp_list->data;
1549 if (child->widget == widget)
1551 gtk_widget_unparent (widget);
1553 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1554 g_list_free_1 (tmp_list);
1559 tmp_list = tmp_list->next;
1564 gtk_icon_view_forall (GtkContainer *container,
1565 gboolean include_internals,
1566 GtkCallback callback,
1567 gpointer callback_data)
1569 GtkIconView *icon_view;
1570 GtkIconViewChild *child = NULL;
1573 icon_view = GTK_ICON_VIEW (container);
1575 tmp_list = icon_view->priv->children;
1578 child = tmp_list->data;
1579 tmp_list = tmp_list->next;
1581 (* callback) (child->widget, callback_data);
1586 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1587 GtkIconViewItem *item,
1588 GtkIconViewCellInfo *info,
1593 GdkRectangle cell_area;
1594 gboolean visible, mode;
1596 gtk_icon_view_set_cell_data (icon_view, item);
1598 g_object_get (info->cell,
1599 "visible", &visible,
1603 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1605 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1607 path = gtk_tree_path_new_from_indices (item->index, -1);
1608 path_string = gtk_tree_path_to_string (path);
1609 gtk_tree_path_free (path);
1611 gtk_cell_renderer_activate (info->cell,
1613 GTK_WIDGET (icon_view),
1619 g_free (path_string);
1624 gtk_icon_view_put (GtkIconView *icon_view,
1626 GtkIconViewItem *item,
1629 GtkIconViewChild *child;
1631 child = g_new (GtkIconViewChild, 1);
1633 child->widget = widget;
1637 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1639 if (GTK_WIDGET_REALIZED (icon_view))
1640 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1642 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1646 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1647 GtkIconView *icon_view)
1650 GtkIconViewItem *item;
1652 if (icon_view->priv->edited_item == NULL)
1655 item = icon_view->priv->edited_item;
1656 icon_view->priv->edited_item = NULL;
1657 icon_view->priv->editable = NULL;
1658 for (l = icon_view->priv->cell_list; l; l = l->next)
1660 GtkIconViewCellInfo *info = l->data;
1662 info->editing = FALSE;
1665 if (GTK_WIDGET_HAS_FOCUS (editable))
1666 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1668 g_signal_handlers_disconnect_by_func (editable,
1669 gtk_icon_view_remove_widget,
1672 gtk_container_remove (GTK_CONTAINER (icon_view),
1673 GTK_WIDGET (editable));
1675 gtk_icon_view_queue_draw_item (icon_view, item);
1680 gtk_icon_view_start_editing (GtkIconView *icon_view,
1681 GtkIconViewItem *item,
1682 GtkIconViewCellInfo *info,
1687 GdkRectangle cell_area;
1688 gboolean visible, mode;
1689 GtkCellEditable *editable;
1691 gtk_icon_view_set_cell_data (icon_view, item);
1693 g_object_get (info->cell,
1694 "visible", &visible,
1697 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1699 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1701 path = gtk_tree_path_new_from_indices (item->index, -1);
1702 path_string = gtk_tree_path_to_string (path);
1703 gtk_tree_path_free (path);
1705 editable = gtk_cell_renderer_start_editing (info->cell,
1707 GTK_WIDGET (icon_view),
1712 g_free (path_string);
1714 /* FIXME ugly special case */
1715 if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
1716 g_object_set (editable, "has-frame", TRUE, NULL);
1718 /* the rest corresponds to tree_view_real_start_editing... */
1719 icon_view->priv->edited_item = item;
1720 icon_view->priv->editable = editable;
1721 info->editing = TRUE;
1723 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1725 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1727 gtk_widget_grab_focus (GTK_WIDGET (editable));
1728 g_signal_connect (editable, "remove_widget",
1729 G_CALLBACK (gtk_icon_view_remove_widget),
1736 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1737 gboolean cancel_editing)
1739 GtkCellRenderer *cell = NULL;
1740 GtkIconViewItem *item;
1743 if (icon_view->priv->edited_item == NULL)
1747 * This is very evil. We need to do this, because
1748 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1749 * later on. If gtk_icon_view_row_changed notices
1750 * icon_view->priv->edited_item != NULL, it'll call
1751 * gtk_icon_view_stop_editing again. Bad things will happen then.
1753 * Please read that again if you intend to modify anything here.
1756 item = icon_view->priv->edited_item;
1757 icon_view->priv->edited_item = NULL;
1759 for (l = icon_view->priv->cell_list; l; l = l->next)
1761 GtkIconViewCellInfo *info = l->data;
1773 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1774 if (!cancel_editing)
1775 gtk_cell_editable_editing_done (icon_view->priv->editable);
1777 icon_view->priv->edited_item = item;
1779 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1783 * gtk_icon_view_set_cursor:
1784 * @icon_view: A #GtkIconView
1785 * @path: A #GtkTreePath
1786 * @cell: One of the cell renderers of @icon_view, or %NULL
1787 * @start_editing: %TRUE if the specified cell should start being edited.
1789 * Sets the current keyboard focus to be at @path, and selects it. This is
1790 * useful when you want to focus the user's attention on a particular item.
1791 * If @cell is not %NULL, then focus is given to the cell specified by
1792 * it. Additionally, if @start_editing is %TRUE, then editing should be
1793 * started in the specified cell.
1795 * This function is often followed by <literal>gtk_widget_grab_focus
1796 * (icon_view)</literal> in order to give keyboard focus to the widget.
1797 * Please note that editing can only happen when the widget is realized.
1802 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1804 GtkCellRenderer *cell,
1805 gboolean start_editing)
1807 GtkIconViewItem *item = NULL;
1808 GtkIconViewCellInfo *info = NULL;
1812 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1813 g_return_if_fail (path != NULL);
1814 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1816 gtk_icon_view_stop_editing (icon_view, TRUE);
1818 if (gtk_tree_path_get_depth (path) == 1)
1819 item = g_list_nth_data (icon_view->priv->items,
1820 gtk_tree_path_get_indices(path)[0]);
1826 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1830 if (info->cell == cell)
1839 g_return_if_fail (cell == NULL || info != NULL);
1841 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1842 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1844 if (info && start_editing)
1845 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1849 * gtk_icon_view_get_cursor:
1850 * @icon_view: A #GtkIconView
1851 * @path: Return location for the current cursor path, or %NULL
1852 * @cell: Return location the current focus cell, or %NULL
1854 * Fills in @path and @cell with the current cursor path and cell.
1855 * If the cursor isn't currently set, then *@path will be %NULL.
1856 * If no cell currently has focus, then *@cell will be %NULL.
1858 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1860 * Return value: %TRUE if the cursor is set.
1865 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1867 GtkCellRenderer **cell)
1869 GtkIconViewItem *item;
1870 GtkIconViewCellInfo *info;
1872 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1874 item = icon_view->priv->cursor_item;
1875 if (icon_view->priv->cursor_cell < 0)
1878 info = g_list_nth_data (icon_view->priv->cell_list,
1879 icon_view->priv->cursor_cell);
1884 *path = gtk_tree_path_new_from_indices (item->index, -1);
1897 return (item != NULL);
1901 gtk_icon_view_button_press (GtkWidget *widget,
1902 GdkEventButton *event)
1904 GtkIconView *icon_view;
1905 GtkIconViewItem *item;
1906 GtkIconViewCellInfo *info = NULL;
1907 gboolean dirty = FALSE;
1908 GtkCellRendererMode mode;
1911 icon_view = GTK_ICON_VIEW (widget);
1913 if (event->window != icon_view->priv->bin_window)
1916 if (!GTK_WIDGET_HAS_FOCUS (widget))
1917 gtk_widget_grab_focus (widget);
1919 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1921 item = gtk_icon_view_get_item_at_coords (icon_view,
1927 g_object_get (info->cell, "mode", &mode, NULL);
1929 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
1930 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1931 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
1935 gtk_icon_view_scroll_to_item (icon_view, item);
1937 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1939 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1941 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1942 (event->state & GDK_SHIFT_MASK))
1944 gtk_icon_view_unselect_all_internal (icon_view);
1946 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1947 if (!icon_view->priv->anchor_item)
1948 icon_view->priv->anchor_item = item;
1950 gtk_icon_view_select_all_between (icon_view,
1951 icon_view->priv->anchor_item,
1957 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
1958 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
1959 (event->state & GDK_CONTROL_MASK))
1961 item->selected = !item->selected;
1962 gtk_icon_view_queue_draw_item (icon_view, item);
1967 if (!item->selected)
1969 gtk_icon_view_unselect_all_internal (icon_view);
1971 item->selected = TRUE;
1972 gtk_icon_view_queue_draw_item (icon_view, item);
1976 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1977 icon_view->priv->anchor_item = item;
1980 /* Save press to possibly begin a drag */
1981 if (icon_view->priv->pressed_button < 0)
1983 icon_view->priv->pressed_button = event->button;
1984 icon_view->priv->press_start_x = event->x;
1985 icon_view->priv->press_start_y = event->y;
1988 if (!icon_view->priv->last_single_clicked)
1989 icon_view->priv->last_single_clicked = item;
1991 /* cancel the current editing, if it exists */
1992 gtk_icon_view_stop_editing (icon_view, TRUE);
1994 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1995 gtk_icon_view_item_activate_cell (icon_view, item, info,
1997 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1998 gtk_icon_view_start_editing (icon_view, item, info,
2003 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
2004 !(event->state & GDK_CONTROL_MASK))
2006 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2009 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2010 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
2015 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2017 item = gtk_icon_view_get_item_at_coords (icon_view,
2022 if (item && item == icon_view->priv->last_single_clicked)
2026 path = gtk_tree_path_new_from_indices (item->index, -1);
2027 gtk_icon_view_item_activated (icon_view, path);
2028 gtk_tree_path_free (path);
2031 icon_view->priv->last_single_clicked = NULL;
2032 icon_view->priv->pressed_button = -1;
2036 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2038 return event->button == 1;
2042 gtk_icon_view_button_release (GtkWidget *widget,
2043 GdkEventButton *event)
2045 GtkIconView *icon_view;
2047 icon_view = GTK_ICON_VIEW (widget);
2049 if (icon_view->priv->pressed_button == event->button)
2050 icon_view->priv->pressed_button = -1;
2052 gtk_icon_view_stop_rubberbanding (icon_view);
2054 remove_scroll_timeout (icon_view);
2060 gtk_icon_view_key_press (GtkWidget *widget,
2063 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2065 if (icon_view->priv->doing_rubberband)
2067 if (event->keyval == GDK_Escape)
2068 gtk_icon_view_stop_rubberbanding (icon_view);
2073 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event) (widget, event);
2077 gtk_icon_view_key_release (GtkWidget *widget,
2080 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
2082 if (icon_view->priv->doing_rubberband)
2085 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->key_press_event) (widget, event);
2089 gtk_icon_view_update_rubberband (gpointer data)
2091 GtkIconView *icon_view;
2093 GdkRectangle old_area;
2094 GdkRectangle new_area;
2095 GdkRectangle common;
2096 GdkRegion *invalid_region;
2098 icon_view = GTK_ICON_VIEW (data);
2100 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2105 old_area.x = MIN (icon_view->priv->rubberband_x1,
2106 icon_view->priv->rubberband_x2);
2107 old_area.y = MIN (icon_view->priv->rubberband_y1,
2108 icon_view->priv->rubberband_y2);
2109 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2110 icon_view->priv->rubberband_x1) + 1;
2111 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2112 icon_view->priv->rubberband_y1) + 1;
2114 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2115 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2116 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2117 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2119 invalid_region = gdk_region_rectangle (&old_area);
2120 gdk_region_union_with_rect (invalid_region, &new_area);
2122 gdk_rectangle_intersect (&old_area, &new_area, &common);
2123 if (common.width > 2 && common.height > 2)
2125 GdkRegion *common_region;
2127 /* make sure the border is invalidated */
2133 common_region = gdk_region_rectangle (&common);
2135 gdk_region_subtract (invalid_region, common_region);
2136 gdk_region_destroy (common_region);
2139 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2141 gdk_region_destroy (invalid_region);
2143 icon_view->priv->rubberband_x2 = x;
2144 icon_view->priv->rubberband_y2 = y;
2146 gtk_icon_view_update_rubberband_selection (icon_view);
2150 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2156 g_assert (!icon_view->priv->doing_rubberband);
2158 for (items = icon_view->priv->items; items; items = items->next)
2160 GtkIconViewItem *item = items->data;
2162 item->selected_before_rubberbanding = item->selected;
2165 icon_view->priv->rubberband_x1 = x;
2166 icon_view->priv->rubberband_y1 = y;
2167 icon_view->priv->rubberband_x2 = x;
2168 icon_view->priv->rubberband_y2 = y;
2170 icon_view->priv->doing_rubberband = TRUE;
2172 gtk_grab_add (GTK_WIDGET (icon_view));
2176 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2178 if (!icon_view->priv->doing_rubberband)
2181 icon_view->priv->doing_rubberband = FALSE;
2183 gtk_grab_remove (GTK_WIDGET (icon_view));
2185 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2189 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2192 gint x, y, width, height;
2193 gboolean dirty = FALSE;
2195 x = MIN (icon_view->priv->rubberband_x1,
2196 icon_view->priv->rubberband_x2);
2197 y = MIN (icon_view->priv->rubberband_y1,
2198 icon_view->priv->rubberband_y2);
2199 width = ABS (icon_view->priv->rubberband_x1 -
2200 icon_view->priv->rubberband_x2);
2201 height = ABS (icon_view->priv->rubberband_y1 -
2202 icon_view->priv->rubberband_y2);
2204 for (items = icon_view->priv->items; items; items = items->next)
2206 GtkIconViewItem *item = items->data;
2210 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2211 x, y, width, height);
2213 selected = is_in ^ item->selected_before_rubberbanding;
2215 if (item->selected != selected)
2217 item->selected = selected;
2219 gtk_icon_view_queue_draw_item (icon_view, item);
2224 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2228 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2229 GtkIconViewItem *item,
2238 for (l = icon_view->priv->cell_list; l; l = l->next)
2240 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2242 if (!info->cell->visible)
2245 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2247 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2248 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2256 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2258 gboolean dirty = FALSE;
2261 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2264 for (items = icon_view->priv->items; items; items = items->next)
2266 GtkIconViewItem *item = items->data;
2270 item->selected = FALSE;
2272 gtk_icon_view_queue_draw_item (icon_view, item);
2280 /* GtkIconView signals */
2282 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2283 GtkAdjustment *hadj,
2284 GtkAdjustment *vadj)
2286 gboolean need_adjust = FALSE;
2289 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2291 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2293 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2295 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2297 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2299 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2300 0, 0, NULL, NULL, icon_view);
2301 g_object_unref (icon_view->priv->hadjustment);
2304 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2306 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2307 0, 0, NULL, NULL, icon_view);
2308 g_object_unref (icon_view->priv->vadjustment);
2311 if (icon_view->priv->hadjustment != hadj)
2313 icon_view->priv->hadjustment = hadj;
2314 g_object_ref_sink (icon_view->priv->hadjustment);
2316 g_signal_connect (icon_view->priv->hadjustment, "value_changed",
2317 G_CALLBACK (gtk_icon_view_adjustment_changed),
2322 if (icon_view->priv->vadjustment != vadj)
2324 icon_view->priv->vadjustment = vadj;
2325 g_object_ref_sink (icon_view->priv->vadjustment);
2327 g_signal_connect (icon_view->priv->vadjustment, "value_changed",
2328 G_CALLBACK (gtk_icon_view_adjustment_changed),
2334 gtk_icon_view_adjustment_changed (NULL, icon_view);
2338 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2340 gtk_icon_view_select_all (icon_view);
2344 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2346 gtk_icon_view_unselect_all (icon_view);
2350 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2352 gtk_icon_view_unselect_all (icon_view);
2354 if (icon_view->priv->cursor_item != NULL)
2355 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2359 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2362 GtkCellRendererMode mode;
2363 GtkIconViewCellInfo *info = NULL;
2365 if (!icon_view->priv->cursor_item)
2368 info = g_list_nth_data (icon_view->priv->cell_list,
2369 icon_view->priv->cursor_cell);
2373 g_object_get (info->cell, "mode", &mode, NULL);
2375 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2377 gtk_icon_view_item_activate_cell (icon_view,
2378 icon_view->priv->cursor_item,
2382 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2384 gtk_icon_view_start_editing (icon_view,
2385 icon_view->priv->cursor_item,
2391 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2392 gtk_icon_view_item_activated (icon_view, path);
2393 gtk_tree_path_free (path);
2399 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2401 if (!icon_view->priv->cursor_item)
2404 switch (icon_view->priv->selection_mode)
2406 case GTK_SELECTION_NONE:
2408 case GTK_SELECTION_BROWSE:
2409 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2411 case GTK_SELECTION_SINGLE:
2412 if (icon_view->priv->cursor_item->selected)
2413 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2415 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2417 case GTK_SELECTION_MULTIPLE:
2418 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2419 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2421 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2426 /* Internal functions */
2428 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2429 GtkIconView *icon_view)
2431 if (GTK_WIDGET_REALIZED (icon_view))
2433 gdk_window_move (icon_view->priv->bin_window,
2434 - icon_view->priv->hadjustment->value,
2435 - icon_view->priv->vadjustment->value);
2437 if (icon_view->priv->doing_rubberband)
2438 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2440 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2445 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2450 gint *maximum_width)
2453 gint x, current_width;
2454 GList *items, *last_item;
2461 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2462 max_height = g_new0 (gint, icon_view->priv->n_cells);
2469 gtk_widget_style_get (GTK_WIDGET (icon_view),
2470 "focus-line-width", &focus_width,
2473 x += icon_view->priv->margin + focus_width;
2474 current_width += 2 * (icon_view->priv->margin + focus_width);
2479 GtkIconViewItem *item = items->data;
2481 gtk_icon_view_calculate_item_size (icon_view, item);
2482 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2484 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2486 current_width += item->width;
2488 if (items != first_item)
2490 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2491 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2495 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2497 item->y = *y + focus_width;
2498 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2500 x = current_width - (icon_view->priv->margin + focus_width);
2502 for (i = 0; i < icon_view->priv->n_cells; i++)
2503 max_height[i] = MAX (max_height[i], item->box[i].height);
2505 if (current_width > *maximum_width)
2506 *maximum_width = current_width;
2512 items = items->next;
2517 /* Now go through the row again and align the icons */
2518 for (items = first_item; items != last_item; items = items->next)
2520 GtkIconViewItem *item = items->data;
2522 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2524 /* We may want to readjust the new y coordinate. */
2525 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2526 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2529 item->col = col - 1 - item->col;
2532 g_free (max_height);
2538 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2541 if (upper != adj->upper)
2543 gdouble min = MAX (0.0, upper - adj->page_size);
2544 gboolean value_changed = FALSE;
2548 if (adj->value > min)
2551 value_changed = TRUE;
2554 gtk_adjustment_changed (adj);
2557 gtk_adjustment_value_changed (adj);
2562 gtk_icon_view_layout (GtkIconView *icon_view)
2564 gint y = 0, maximum_width = 0;
2570 if (icon_view->priv->layout_idle_id != 0)
2572 g_source_remove (icon_view->priv->layout_idle_id);
2573 icon_view->priv->layout_idle_id = 0;
2576 if (icon_view->priv->model == NULL)
2579 widget = GTK_WIDGET (icon_view);
2581 item_width = icon_view->priv->item_width;
2585 for (icons = icon_view->priv->items; icons; icons = icons->next)
2587 GtkIconViewItem *item = icons->data;
2588 gtk_icon_view_calculate_item_size (icon_view, item);
2589 item_width = MAX (item_width, item->width);
2594 icons = icon_view->priv->items;
2595 y += icon_view->priv->margin;
2600 gtk_icon_view_set_cell_data (icon_view, icons->data);
2601 adjust_wrap_width (icon_view, icons->data);
2606 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2608 &y, &maximum_width);
2611 while (icons != NULL);
2613 if (maximum_width != icon_view->priv->width)
2614 icon_view->priv->width = maximum_width;
2616 y += icon_view->priv->margin;
2618 if (y != icon_view->priv->height)
2619 icon_view->priv->height = y;
2621 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2622 icon_view->priv->width);
2623 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2624 icon_view->priv->height);
2626 if (icon_view->priv->width != widget->requisition.width ||
2627 icon_view->priv->height != widget->requisition.height)
2628 gtk_widget_queue_resize_no_redraw (widget);
2630 if (GTK_WIDGET_REALIZED (icon_view))
2631 gdk_window_resize (icon_view->priv->bin_window,
2632 MAX (icon_view->priv->width, widget->allocation.width),
2633 MAX (icon_view->priv->height, widget->allocation.height));
2635 if (icon_view->priv->scroll_to_path)
2639 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2640 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2641 icon_view->priv->scroll_to_path = NULL;
2643 gtk_icon_view_scroll_to_path (icon_view, path,
2644 icon_view->priv->scroll_to_use_align,
2645 icon_view->priv->scroll_to_row_align,
2646 icon_view->priv->scroll_to_col_align);
2647 gtk_tree_path_free (path);
2650 gtk_widget_queue_draw (widget);
2654 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2655 GtkIconViewItem *item,
2656 GtkIconViewCellInfo *info,
2657 GdkRectangle *cell_area)
2659 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2661 cell_area->x = item->box[info->position].x - item->before[info->position];
2662 cell_area->y = item->y;
2663 cell_area->width = item->box[info->position].width +
2664 item->before[info->position] + item->after[info->position];
2665 cell_area->height = item->height;
2669 cell_area->x = item->x;
2670 cell_area->y = item->box[info->position].y - item->before[info->position];
2671 cell_area->width = item->width;
2672 cell_area->height = item->box[info->position].height +
2673 item->before[info->position] + item->after[info->position];
2678 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2679 GtkIconViewItem *item,
2680 GtkIconViewCellInfo *info,
2683 *box = item->box[info->position];
2686 /* try to guess a reasonable wrap width for an implicit text cell renderer
2689 adjust_wrap_width (GtkIconView *icon_view,
2690 GtkIconViewItem *item)
2692 GtkIconViewCellInfo *text_info;
2693 GtkIconViewCellInfo *pixbuf_info;
2694 gint pixbuf_width, wrap_width;
2696 if (icon_view->priv->text_cell != -1 &&
2697 icon_view->priv->pixbuf_cell != -1)
2701 text_info = g_list_nth_data (icon_view->priv->cell_list,
2702 icon_view->priv->text_cell);
2703 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2704 icon_view->priv->pixbuf_cell);
2706 gtk_cell_renderer_get_size (pixbuf_info->cell,
2707 GTK_WIDGET (icon_view),
2713 if (icon_view->priv->item_width > 0)
2714 item_width = icon_view->priv->item_width;
2716 item_width = item->width;
2718 if (item->width == -1)
2721 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2723 wrap_width = MAX (2 * pixbuf_width, 50);
2725 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2726 wrap_width = item_width;
2728 wrap_width = item_width - pixbuf_width - icon_view->priv->spacing;
2730 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2731 g_object_set (text_info->cell, "width", wrap_width, NULL);
2736 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2737 GtkIconViewItem *item)
2742 if (item->width != -1 && item->height != -1)
2745 if (item->n_cells != icon_view->priv->n_cells)
2747 g_free (item->before);
2748 g_free (item->after);
2751 item->before = g_new0 (gint, icon_view->priv->n_cells);
2752 item->after = g_new0 (gint, icon_view->priv->n_cells);
2753 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2755 item->n_cells = icon_view->priv->n_cells;
2758 gtk_icon_view_set_cell_data (icon_view, item);
2760 spacing = icon_view->priv->spacing;
2764 for (l = icon_view->priv->cell_list; l; l = l->next)
2766 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2768 if (!info->cell->visible)
2771 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2773 &item->box[info->position].width,
2774 &item->box[info->position].height);
2776 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2778 item->width += item->box[info->position].width
2779 + (info->position > 0 ? spacing : 0);
2780 item->height = MAX (item->height, item->box[info->position].height);
2784 item->width = MAX (item->width, item->box[info->position].width);
2785 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2791 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2792 GtkIconViewItem *item,
2795 GdkRectangle cell_area;
2801 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2803 gtk_icon_view_set_cell_data (icon_view, item);
2805 spacing = icon_view->priv->spacing;
2808 for (i = 0; i < icon_view->priv->n_cells; i++)
2810 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2811 item->height = MAX (item->height, max_height[i]);
2813 item->height += max_height[i] + (i > 0 ? spacing : 0);
2816 cell_area.x = item->x;
2817 cell_area.y = item->y;
2819 for (k = 0; k < 2; k++)
2820 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2822 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2824 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2827 if (!info->cell->visible)
2830 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2832 cell_area.width = item->box[info->position].width;
2833 cell_area.height = item->height;
2837 cell_area.width = item->width;
2838 cell_area.height = max_height[i];
2841 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2843 &item->box[info->position].x, &item->box[info->position].y,
2844 &item->box[info->position].width, &item->box[info->position].height);
2846 item->box[info->position].x += cell_area.x;
2847 item->box[info->position].y += cell_area.y;
2848 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2850 item->before[info->position] = item->box[info->position].x - cell_area.x;
2851 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2852 cell_area.x += cell_area.width + spacing;
2856 if (item->box[info->position].width > item->width)
2858 item->width = item->box[info->position].width;
2859 cell_area.width = item->width;
2861 item->before[info->position] = item->box[info->position].y - cell_area.y;
2862 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2863 cell_area.y += cell_area.height + spacing;
2867 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2869 for (i = 0; i < icon_view->priv->n_cells; i++)
2871 item->box[i].x = item->x + item->width -
2872 (item->box[i].x + item->box[i].width - item->x);
2878 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2880 g_list_foreach (icon_view->priv->items,
2881 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2885 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2892 gtk_icon_view_paint_item (GtkIconView *icon_view,
2894 GtkIconViewItem *item,
2896 GdkDrawable *drawable,
2899 gboolean draw_focus)
2901 gint focus_width, focus_pad;
2903 GdkRectangle cell_area, box;
2907 GtkCellRendererState flags;
2909 if (icon_view->priv->model == NULL)
2912 gtk_icon_view_set_cell_data (icon_view, item);
2914 gtk_widget_style_get (GTK_WIDGET (icon_view),
2915 "focus-line-width", &focus_width,
2916 "focus-padding", &focus_pad,
2919 padding = focus_width;
2923 flags = GTK_CELL_RENDERER_SELECTED;
2924 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2925 state = GTK_STATE_SELECTED;
2927 state = GTK_STATE_ACTIVE;
2932 state = GTK_STATE_NORMAL;
2935 #ifdef DEBUG_ICON_VIEW
2936 gdk_draw_rectangle (drawable,
2937 GTK_WIDGET (icon_view)->style->black_gc,
2940 item->width, item->height);
2944 for (l = icon_view->priv->cell_list; l; l = l->next)
2946 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2948 if (!info->cell->visible)
2951 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2953 /* FIXME we hardwire background drawing behind text
2954 * cell renderers here
2956 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
2958 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
2959 cairo_rectangle (cr,
2960 x - item->x + box.x,
2961 y - item->y + box.y,
2962 box.width, box.height);
2967 for (l = icon_view->priv->cell_list; l; l = l->next)
2969 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2971 if (!info->cell->visible)
2974 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
2976 #ifdef DEBUG_ICON_VIEW
2977 gdk_draw_rectangle (drawable,
2978 GTK_WIDGET (icon_view)->style->black_gc,
2980 x - item->x + cell_area.x,
2981 y - item->y + cell_area.y,
2982 cell_area.width, cell_area.height);
2984 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2986 gdk_draw_rectangle (drawable,
2987 GTK_WIDGET (icon_view)->style->black_gc,
2989 x - item->x + box.x,
2990 y - item->y + box.y,
2991 box.width, box.height);
2994 cell_area.x = x - item->x + cell_area.x;
2995 cell_area.y = y - item->y + cell_area.y;
2997 gtk_cell_renderer_render (info->cell,
2999 GTK_WIDGET (icon_view),
3000 &cell_area, &cell_area, area, flags);
3004 /* FIXME where to draw the focus with generic cell renderers ? */
3006 GTK_WIDGET_HAS_FOCUS (icon_view) &&
3007 item == icon_view->priv->cursor_item)
3008 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3010 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3012 if (!info->cell->visible)
3015 if (icon_view->priv->cursor_cell < 0 &&
3016 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
3017 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
3018 icon_view->priv->cursor_cell = i;
3020 if (i == icon_view->priv->cursor_cell)
3022 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3024 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
3028 GTK_WIDGET (icon_view),
3030 x - item->x + box.x - padding,
3031 y - item->y + box.y - padding,
3032 box.width + 2 * padding,
3033 box.height + 2 * padding);
3040 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
3045 GdkRectangle rubber_rect;
3046 GdkColor *fill_color_gdk;
3047 guchar fill_color_alpha;
3049 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
3050 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
3051 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
3052 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
3054 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3057 gtk_widget_style_get (GTK_WIDGET (icon_view),
3058 "selection-box-color", &fill_color_gdk,
3059 "selection-box-alpha", &fill_color_alpha,
3062 if (!fill_color_gdk)
3063 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3065 cairo_set_source_rgba (cr,
3066 fill_color_gdk->red / 65535.,
3067 fill_color_gdk->green / 65535.,
3068 fill_color_gdk->blue / 65535.,
3069 fill_color_alpha / 255.);
3072 gdk_cairo_rectangle (cr, &rect);
3076 /* Draw the border without alpha */
3077 cairo_set_source_rgb (cr,
3078 fill_color_gdk->red / 65535.,
3079 fill_color_gdk->green / 65535.,
3080 fill_color_gdk->blue / 65535.);
3081 cairo_rectangle (cr,
3082 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3083 rubber_rect.width - 1, rubber_rect.height - 1);
3087 gdk_color_free (fill_color_gdk);
3091 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3097 index = gtk_tree_path_get_indices (path)[0];
3099 for (l = icon_view->priv->items; l; l = l->next)
3101 GtkIconViewItem *item = l->data;
3103 if (item->index == index)
3105 gtk_icon_view_queue_draw_item (icon_view, item);
3112 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3113 GtkIconViewItem *item)
3118 gtk_widget_style_get (GTK_WIDGET (icon_view),
3119 "focus-line-width", &focus_width,
3122 rect.x = item->x - focus_width;
3123 rect.y = item->y - focus_width;
3124 rect.width = item->width + 2 * focus_width;
3125 rect.height = item->height + 2 * focus_width;
3127 if (icon_view->priv->bin_window)
3128 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3132 layout_callback (gpointer user_data)
3134 GtkIconView *icon_view;
3136 icon_view = GTK_ICON_VIEW (user_data);
3138 icon_view->priv->layout_idle_id = 0;
3140 gtk_icon_view_layout (icon_view);
3146 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3148 if (icon_view->priv->layout_idle_id != 0)
3151 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3155 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3156 GtkIconViewItem *item,
3160 AtkObject *item_obj;
3162 if (icon_view->priv->cursor_item == item &&
3163 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3166 if (icon_view->priv->cursor_item != NULL)
3167 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3169 icon_view->priv->cursor_item = item;
3170 if (cursor_cell >= 0)
3171 icon_view->priv->cursor_cell = cursor_cell;
3173 gtk_icon_view_queue_draw_item (icon_view, item);
3175 /* Notify that accessible focus object has changed */
3176 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3177 item_obj = atk_object_ref_accessible_child (obj, item->index);
3179 if (item_obj != NULL)
3181 atk_focus_tracker_notify (item_obj);
3182 g_object_unref (item_obj);
3187 static GtkIconViewItem *
3188 gtk_icon_view_item_new (void)
3190 GtkIconViewItem *item;
3192 item = g_new0 (GtkIconViewItem, 1);
3201 gtk_icon_view_item_free (GtkIconViewItem *item)
3203 g_return_if_fail (item != NULL);
3205 g_free (item->before);
3206 g_free (item->after);
3213 static GtkIconViewItem *
3214 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3217 gboolean only_in_cell,
3218 GtkIconViewCellInfo **cell_at_pos)
3223 for (items = icon_view->priv->items; items; items = items->next)
3225 GtkIconViewItem *item = items->data;
3227 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3228 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3230 if (only_in_cell || cell_at_pos)
3232 gtk_icon_view_set_cell_data (icon_view, item);
3234 for (l = icon_view->priv->cell_list; l; l = l->next)
3236 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3238 if (!info->cell->visible)
3241 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3243 if ((x >= box.x && x <= box.x + box.width &&
3244 y >= box.y && y <= box.y + box.height) ||
3246 x <= box.x + box.width &&
3248 y <= box.y + box.height))
3251 *cell_at_pos = info;
3261 *cell_at_pos = NULL;
3272 gtk_icon_view_select_item (GtkIconView *icon_view,
3273 GtkIconViewItem *item)
3275 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3276 g_return_if_fail (item != NULL);
3281 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3283 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3284 gtk_icon_view_unselect_all_internal (icon_view);
3286 item->selected = TRUE;
3288 gtk_icon_view_queue_draw_item (icon_view, item);
3290 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3295 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3296 GtkIconViewItem *item)
3298 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3299 g_return_if_fail (item != NULL);
3301 if (!item->selected)
3304 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3305 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3308 item->selected = FALSE;
3310 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3312 gtk_icon_view_queue_draw_item (icon_view, item);
3316 verify_items (GtkIconView *icon_view)
3321 for (items = icon_view->priv->items; items; items = items->next)
3323 GtkIconViewItem *item = items->data;
3325 if (item->index != i)
3326 g_error ("List item does not match its index: "
3327 "item index %d and list index %d\n", item->index, i);
3334 gtk_icon_view_row_changed (GtkTreeModel *model,
3339 GtkIconViewItem *item;
3341 GtkIconView *icon_view;
3343 icon_view = GTK_ICON_VIEW (data);
3345 gtk_icon_view_stop_editing (icon_view, TRUE);
3347 index = gtk_tree_path_get_indices(path)[0];
3348 item = g_list_nth_data (icon_view->priv->items, index);
3350 gtk_icon_view_item_invalidate_size (item);
3351 gtk_icon_view_queue_layout (icon_view);
3353 verify_items (icon_view);
3357 gtk_icon_view_row_inserted (GtkTreeModel *model,
3363 GtkIconViewItem *item;
3364 gboolean iters_persist;
3365 GtkIconView *icon_view;
3368 icon_view = GTK_ICON_VIEW (data);
3370 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3372 index = gtk_tree_path_get_indices(path)[0];
3374 item = gtk_icon_view_item_new ();
3379 item->index = index;
3381 /* FIXME: We can be more efficient here,
3382 we can store a tail pointer and use that when
3383 appending (which is a rather common operation)
3385 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3388 list = g_list_nth (icon_view->priv->items, index + 1);
3389 for (; list; list = list->next)
3396 verify_items (icon_view);
3398 gtk_icon_view_queue_layout (icon_view);
3402 gtk_icon_view_row_deleted (GtkTreeModel *model,
3407 GtkIconView *icon_view;
3408 GtkIconViewItem *item;
3410 gboolean emit = FALSE;
3412 icon_view = GTK_ICON_VIEW (data);
3414 index = gtk_tree_path_get_indices(path)[0];
3416 list = g_list_nth (icon_view->priv->items, index);
3419 gtk_icon_view_stop_editing (icon_view, TRUE);
3421 if (item == icon_view->priv->anchor_item)
3422 icon_view->priv->anchor_item = NULL;
3424 if (item == icon_view->priv->cursor_item)
3425 icon_view->priv->cursor_item = NULL;
3430 gtk_icon_view_item_free (item);
3432 for (next = list->next; next; next = next->next)
3439 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3441 verify_items (icon_view);
3443 gtk_icon_view_queue_layout (icon_view);
3446 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3450 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3451 GtkTreePath *parent,
3458 GtkIconView *icon_view;
3459 GList *items = NULL, *list;
3460 GtkIconViewItem **item_array;
3463 icon_view = GTK_ICON_VIEW (data);
3465 gtk_icon_view_stop_editing (icon_view, TRUE);
3467 length = gtk_tree_model_iter_n_children (model, NULL);
3469 order = g_new (gint, length);
3470 for (i = 0; i < length; i++)
3471 order [new_order[i]] = i;
3473 item_array = g_new (GtkIconViewItem *, length);
3474 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3475 item_array[order[i]] = list->data;
3478 for (i = length - 1; i >= 0; i--)
3480 item_array[i]->index = i;
3481 items = g_list_prepend (items, item_array[i]);
3484 g_free (item_array);
3485 g_list_free (icon_view->priv->items);
3486 icon_view->priv->items = items;
3488 gtk_icon_view_queue_layout (icon_view);
3490 verify_items (icon_view);
3494 gtk_icon_view_build_items (GtkIconView *icon_view)
3498 gboolean iters_persist;
3499 GList *items = NULL;
3501 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3503 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3511 GtkIconViewItem *item = gtk_icon_view_item_new ();
3520 items = g_list_prepend (items, item);
3522 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3524 icon_view->priv->items = g_list_reverse (items);
3528 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3531 GtkMovementStep step,
3535 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3536 I_("move_cursor"), 2,
3540 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3545 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3548 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3553 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3560 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3561 GtkMovementStep step,
3564 GdkModifierType state;
3566 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3567 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3568 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3569 step == GTK_MOVEMENT_DISPLAY_LINES ||
3570 step == GTK_MOVEMENT_PAGES ||
3571 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3573 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3576 gtk_icon_view_stop_editing (icon_view, FALSE);
3577 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3579 if (gtk_get_current_event_state (&state))
3581 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3582 icon_view->priv->ctrl_pressed = TRUE;
3583 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3584 icon_view->priv->shift_pressed = TRUE;
3586 /* else we assume not pressed */
3590 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3591 case GTK_MOVEMENT_VISUAL_POSITIONS:
3592 gtk_icon_view_move_cursor_left_right (icon_view, count);
3594 case GTK_MOVEMENT_DISPLAY_LINES:
3595 gtk_icon_view_move_cursor_up_down (icon_view, count);
3597 case GTK_MOVEMENT_PAGES:
3598 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3600 case GTK_MOVEMENT_BUFFER_ENDS:
3601 gtk_icon_view_move_cursor_start_end (icon_view, count);
3604 g_assert_not_reached ();
3607 icon_view->priv->ctrl_pressed = FALSE;
3608 icon_view->priv->shift_pressed = FALSE;
3613 static GtkIconViewItem *
3614 find_item (GtkIconView *icon_view,
3615 GtkIconViewItem *current,
3621 GtkIconViewItem *item;
3623 /* FIXME: this could be more efficient
3625 row = current->row + row_ofs;
3626 col = current->col + col_ofs;
3628 for (items = icon_view->priv->items; items; items = items->next)
3631 if (item->row == row && item->col == col)
3639 find_cell (GtkIconView *icon_view,
3640 GtkIconViewItem *item,
3642 GtkOrientation orientation,
3653 if (icon_view->priv->orientation != orientation)
3656 gtk_icon_view_set_cell_data (icon_view, item);
3658 focusable = g_new0 (gint, icon_view->priv->n_cells);
3663 for (k = 0; k < 2; k++)
3664 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3666 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3668 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3671 if (!info->cell->visible)
3674 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3677 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3680 current = n_focusable;
3682 focusable[n_focusable] = i;
3688 if (n_focusable == 0)
3689 focusable[n_focusable++] = first_text;
3693 current = step > 0 ? 0 : n_focusable - 1;
3694 cell = focusable[current];
3697 if (current + *count < 0)
3700 *count = current + *count;
3702 else if (current + *count > n_focusable - 1)
3705 *count = current + *count - (n_focusable - 1);
3709 cell = focusable[current + *count];
3718 static GtkIconViewItem *
3719 find_item_page_up_down (GtkIconView *icon_view,
3720 GtkIconViewItem *current,
3727 y = current->y + count * icon_view->priv->vadjustment->page_size;
3729 item = g_list_find (icon_view->priv->items, current);
3734 for (next = item->next; next; next = next->next)
3736 if (((GtkIconViewItem *)next->data)->col == col)
3739 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3749 for (next = item->prev; next; next = next->prev)
3751 if (((GtkIconViewItem *)next->data)->col == col)
3754 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3768 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3769 GtkIconViewItem *anchor,
3770 GtkIconViewItem *cursor)
3773 GtkIconViewItem *item;
3774 gint row1, row2, col1, col2;
3775 gboolean dirty = FALSE;
3777 if (anchor->row < cursor->row)
3788 if (anchor->col < cursor->col)
3799 for (items = icon_view->priv->items; items; items = items->next)
3803 if (row1 <= item->row && item->row <= row2 &&
3804 col1 <= item->col && item->col <= col2)
3806 if (!item->selected)
3809 item->selected = TRUE;
3811 gtk_icon_view_queue_draw_item (icon_view, item);
3819 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3822 GtkIconViewItem *item;
3824 gboolean dirty = FALSE;
3827 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3830 if (!icon_view->priv->cursor_item)
3835 list = icon_view->priv->items;
3837 list = g_list_last (icon_view->priv->items);
3839 item = list ? list->data : NULL;
3844 item = icon_view->priv->cursor_item;
3845 cell = icon_view->priv->cursor_cell;
3846 step = count > 0 ? 1 : -1;
3849 cell = find_cell (icon_view, item, cell,
3850 GTK_ORIENTATION_VERTICAL,
3855 item = find_item (icon_view, item, step, 0);
3856 count = count - step;
3862 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3866 if (icon_view->priv->ctrl_pressed ||
3867 !icon_view->priv->shift_pressed ||
3868 !icon_view->priv->anchor_item ||
3869 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3870 icon_view->priv->anchor_item = item;
3872 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3874 if (!icon_view->priv->ctrl_pressed &&
3875 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3877 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3878 dirty = gtk_icon_view_select_all_between (icon_view,
3879 icon_view->priv->anchor_item,
3883 gtk_icon_view_scroll_to_item (icon_view, item);
3886 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3890 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3893 GtkIconViewItem *item;
3894 gboolean dirty = FALSE;
3896 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3899 if (!icon_view->priv->cursor_item)
3904 list = icon_view->priv->items;
3906 list = g_list_last (icon_view->priv->items);
3908 item = list ? list->data : NULL;
3911 item = find_item_page_up_down (icon_view,
3912 icon_view->priv->cursor_item,
3915 if (item == icon_view->priv->cursor_item)
3916 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3921 if (icon_view->priv->ctrl_pressed ||
3922 !icon_view->priv->shift_pressed ||
3923 !icon_view->priv->anchor_item ||
3924 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3925 icon_view->priv->anchor_item = item;
3927 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3929 if (!icon_view->priv->ctrl_pressed &&
3930 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3932 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3933 dirty = gtk_icon_view_select_all_between (icon_view,
3934 icon_view->priv->anchor_item,
3938 gtk_icon_view_scroll_to_item (icon_view, item);
3941 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3945 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3948 GtkIconViewItem *item;
3950 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;
3969 item = icon_view->priv->cursor_item;
3970 cell = icon_view->priv->cursor_cell;
3971 step = count > 0 ? 1 : -1;
3974 cell = find_cell (icon_view, item, cell,
3975 GTK_ORIENTATION_HORIZONTAL,
3980 item = find_item (icon_view, item, 0, step);
3981 count = count - step;
3987 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3991 if (icon_view->priv->ctrl_pressed ||
3992 !icon_view->priv->shift_pressed ||
3993 !icon_view->priv->anchor_item ||
3994 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3995 icon_view->priv->anchor_item = item;
3997 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3999 if (!icon_view->priv->ctrl_pressed &&
4000 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4002 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4003 dirty = gtk_icon_view_select_all_between (icon_view,
4004 icon_view->priv->anchor_item,
4008 gtk_icon_view_scroll_to_item (icon_view, item);
4011 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4015 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
4018 GtkIconViewItem *item;
4020 gboolean dirty = FALSE;
4022 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
4026 list = icon_view->priv->items;
4028 list = g_list_last (icon_view->priv->items);
4030 item = list ? list->data : NULL;
4032 if (item == icon_view->priv->cursor_item)
4033 gtk_widget_error_bell (GTK_WIDGET (icon_view));
4038 if (icon_view->priv->ctrl_pressed ||
4039 !icon_view->priv->shift_pressed ||
4040 !icon_view->priv->anchor_item ||
4041 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4042 icon_view->priv->anchor_item = item;
4044 gtk_icon_view_set_cursor_item (icon_view, item, -1);
4046 if (!icon_view->priv->ctrl_pressed &&
4047 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
4049 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4050 dirty = gtk_icon_view_select_all_between (icon_view,
4051 icon_view->priv->anchor_item,
4055 gtk_icon_view_scroll_to_item (icon_view, item);
4058 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4062 * gtk_icon_view_scroll_to_path:
4063 * @icon_view: A #GtkIconView.
4064 * @path: The path of the item to move to.
4065 * @use_align: whether to use alignment arguments, or %FALSE.
4066 * @row_align: The vertical alignment of the item specified by @path.
4067 * @col_align: The horizontal alignment of the item specified by @path.
4069 * Moves the alignments of @icon_view to the position specified by @path.
4070 * @row_align determines where the row is placed, and @col_align determines
4071 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4072 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4075 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4076 * tree does the minimum amount of work to scroll the item onto the screen.
4077 * This means that the item will be scrolled to the edge closest to its current
4078 * position. If the item is currently visible on the screen, nothing is done.
4080 * This function only works if the model is set, and @path is a valid row on
4081 * the model. If the model changes before the @icon_view is realized, the
4082 * centered path will be modified to reflect this change.
4087 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4093 GtkIconViewItem *item = NULL;
4095 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4096 g_return_if_fail (path != NULL);
4097 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4098 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4100 if (gtk_tree_path_get_depth (path) > 0)
4101 item = g_list_nth_data (icon_view->priv->items,
4102 gtk_tree_path_get_indices(path)[0]);
4104 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
4106 if (icon_view->priv->scroll_to_path)
4107 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4109 icon_view->priv->scroll_to_path = NULL;
4112 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4114 icon_view->priv->scroll_to_use_align = use_align;
4115 icon_view->priv->scroll_to_row_align = row_align;
4116 icon_view->priv->scroll_to_col_align = col_align;
4125 gfloat offset, value;
4127 gtk_widget_style_get (GTK_WIDGET (icon_view),
4128 "focus-line-width", &focus_width,
4131 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4133 offset = y + item->y - focus_width -
4134 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4135 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4136 icon_view->priv->vadjustment->lower,
4137 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4138 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4140 offset = x + item->x - focus_width -
4141 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4142 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4143 icon_view->priv->hadjustment->lower,
4144 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4145 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4147 gtk_adjustment_changed (icon_view->priv->hadjustment);
4148 gtk_adjustment_changed (icon_view->priv->vadjustment);
4151 gtk_icon_view_scroll_to_item (icon_view, item);
4156 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4157 GtkIconViewItem *item)
4159 gint x, y, width, height;
4162 gtk_widget_style_get (GTK_WIDGET (icon_view),
4163 "focus-line-width", &focus_width,
4166 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4168 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4170 if (y + item->y - focus_width < 0)
4171 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4172 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4173 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4174 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4175 icon_view->priv->vadjustment->value + y + item->y + item->height
4176 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4178 if (x + item->x - focus_width < 0)
4179 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4180 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4181 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4182 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4183 icon_view->priv->hadjustment->value + x + item->x + item->width
4184 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4186 gtk_adjustment_changed (icon_view->priv->hadjustment);
4187 gtk_adjustment_changed (icon_view->priv->vadjustment);
4190 /* GtkCellLayout implementation */
4191 static GtkIconViewCellInfo *
4192 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4193 GtkCellRenderer *renderer)
4197 for (i = icon_view->priv->cell_list; i; i = i->next)
4199 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4201 if (info->cell == renderer)
4209 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4210 GtkIconViewItem *item)
4213 gboolean iters_persist;
4216 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4222 path = gtk_tree_path_new_from_indices (item->index, -1);
4223 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4225 gtk_tree_path_free (path);
4230 for (i = icon_view->priv->cell_list; i; i = i->next)
4233 GtkIconViewCellInfo *info = i->data;
4235 g_object_freeze_notify (G_OBJECT (info->cell));
4237 for (j = info->attributes; j && j->next; j = j->next->next)
4239 gchar *property = j->data;
4240 gint column = GPOINTER_TO_INT (j->next->data);
4241 GValue value = {0, };
4243 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4245 g_object_set_property (G_OBJECT (info->cell),
4247 g_value_unset (&value);
4251 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4253 icon_view->priv->model,
4257 g_object_thaw_notify (G_OBJECT (info->cell));
4262 free_cell_attributes (GtkIconViewCellInfo *info)
4266 list = info->attributes;
4267 while (list && list->next)
4269 g_free (list->data);
4270 list = list->next->next;
4273 g_slist_free (info->attributes);
4274 info->attributes = NULL;
4278 free_cell_info (GtkIconViewCellInfo *info)
4280 free_cell_attributes (info);
4282 g_object_unref (info->cell);
4285 (* info->destroy) (info->func_data);
4291 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4292 GtkCellRenderer *renderer,
4295 GtkIconViewCellInfo *info;
4296 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4298 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4299 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4301 g_object_ref_sink (renderer);
4303 info = g_new0 (GtkIconViewCellInfo, 1);
4304 info->cell = renderer;
4305 info->expand = expand ? TRUE : FALSE;
4306 info->pack = GTK_PACK_START;
4307 info->position = icon_view->priv->n_cells;
4309 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4310 icon_view->priv->n_cells++;
4314 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4315 GtkCellRenderer *renderer,
4318 GtkIconViewCellInfo *info;
4319 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4321 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4322 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4324 g_object_ref_sink (renderer);
4326 info = g_new0 (GtkIconViewCellInfo, 1);
4327 info->cell = renderer;
4328 info->expand = expand ? TRUE : FALSE;
4329 info->pack = GTK_PACK_END;
4330 info->position = icon_view->priv->n_cells;
4332 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4333 icon_view->priv->n_cells++;
4337 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4338 GtkCellRenderer *renderer,
4339 const gchar *attribute,
4342 GtkIconViewCellInfo *info;
4343 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4345 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4346 g_return_if_fail (info != NULL);
4348 info->attributes = g_slist_prepend (info->attributes,
4349 GINT_TO_POINTER (column));
4350 info->attributes = g_slist_prepend (info->attributes,
4351 g_strdup (attribute));
4355 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4357 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4359 while (icon_view->priv->cell_list)
4361 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4362 free_cell_info (info);
4363 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4364 icon_view->priv->cell_list);
4367 icon_view->priv->n_cells = 0;
4371 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4372 GtkCellRenderer *cell,
4373 GtkCellLayoutDataFunc func,
4375 GDestroyNotify destroy)
4377 GtkIconViewCellInfo *info;
4378 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4380 info = gtk_icon_view_get_cell_info (icon_view, cell);
4381 g_return_if_fail (info != NULL);
4385 GDestroyNotify d = info->destroy;
4387 info->destroy = NULL;
4388 d (info->func_data);
4392 info->func_data = func_data;
4393 info->destroy = destroy;
4397 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4398 GtkCellRenderer *renderer)
4400 GtkIconViewCellInfo *info;
4402 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4404 free_cell_attributes (info);
4408 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4409 GtkCellRenderer *cell,
4412 GtkIconView *icon_view;
4414 GtkIconViewCellInfo *info;
4417 icon_view = GTK_ICON_VIEW (layout);
4419 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4421 info = gtk_icon_view_get_cell_info (icon_view, cell);
4423 g_return_if_fail (info != NULL);
4424 g_return_if_fail (position >= 0);
4426 link = g_list_find (icon_view->priv->cell_list, info);
4428 g_return_if_fail (link != NULL);
4430 icon_view->priv->cell_list = g_list_remove_link (icon_view->priv->cell_list,
4432 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4435 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4442 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4446 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4448 GtkIconView *icon_view = (GtkIconView *)layout;
4449 GList *retval = NULL, *l;
4451 for (l = icon_view->priv->cell_list; l; l = l->next)
4453 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4455 retval = g_list_prepend (retval, info->cell);
4458 return g_list_reverse (retval);
4465 * gtk_icon_view_new:
4467 * Creates a new #GtkIconView widget
4469 * Return value: A newly created #GtkIconView widget
4474 gtk_icon_view_new (void)
4476 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4480 * gtk_icon_view_new_with_model:
4481 * @model: The model.
4483 * Creates a new #GtkIconView widget with the model @model.
4485 * Return value: A newly created #GtkIconView widget.
4490 gtk_icon_view_new_with_model (GtkTreeModel *model)
4492 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4497 * gtk_icon_view_get_path_at_pos:
4498 * @icon_view: A #GtkIconView.
4499 * @x: The x position to be identified
4500 * @y: The y position to be identified
4502 * Finds the path at the point (@x, @y), relative to widget coordinates.
4503 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4504 * the cell at the specified position.
4506 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4507 * if no icon exists at that position.
4512 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4516 GtkIconViewItem *item;
4519 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4521 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4526 path = gtk_tree_path_new_from_indices (item->index, -1);
4532 * gtk_icon_view_get_item_at_pos:
4533 * @icon_view: A #GtkIconView.
4534 * @x: The x position to be identified
4535 * @y: The y position to be identified
4536 * @path: Return location for the path, or %NULL
4537 * @cell: Return location for the renderer responsible for the cell
4538 * at (@x, @y), or %NULL
4540 * Finds the path at the point (@x, @y), relative to widget coordinates.
4541 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4542 * obtains the cell at the specified position. The returned path should
4543 * be freed with gtk_tree_path_free().
4545 * Return value: %TRUE if an item exists at the specified position
4550 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4554 GtkCellRenderer **cell)
4556 GtkIconViewItem *item;
4557 GtkIconViewCellInfo *info;
4559 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4561 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4566 *path = gtk_tree_path_new_from_indices (item->index, -1);
4579 return (item != NULL);
4584 * gtk_icon_view_get_visible_range:
4585 * @icon_view: A #GtkIconView
4586 * @start_path: Return location for start of region, or %NULL
4587 * @end_path: Return location for end of region, or %NULL
4589 * Sets @start_path and @end_path to be the first and last visible path.
4590 * Note that there may be invisible paths in between.
4592 * Both paths should be freed with gtk_tree_path_free() after use.
4594 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4599 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4600 GtkTreePath **start_path,
4601 GtkTreePath **end_path)
4603 gint start_index = -1;
4604 gint end_index = -1;
4607 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4609 if (icon_view->priv->hadjustment == NULL ||
4610 icon_view->priv->vadjustment == NULL)
4613 if (start_path == NULL && end_path == NULL)
4616 for (icons = icon_view->priv->items; icons; icons = icons->next)
4618 GtkIconViewItem *item = icons->data;
4620 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4621 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4622 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4623 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4625 if (start_index == -1)
4626 start_index = item->index;
4627 end_index = item->index;
4631 if (start_path && start_index != -1)
4632 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4633 if (end_path && end_index != -1)
4634 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4636 return start_index != -1;
4640 * gtk_icon_view_selected_foreach:
4641 * @icon_view: A #GtkIconView.
4642 * @func: The funcion to call for each selected icon.
4643 * @data: User data to pass to the function.
4645 * Calls a function for each selected icon. Note that the model or
4646 * selection cannot be modified from within this function.
4651 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4652 GtkIconViewForeachFunc func,
4657 for (list = icon_view->priv->items; list; list = list->next)
4659 GtkIconViewItem *item = list->data;
4660 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4663 (* func) (icon_view, path, data);
4665 gtk_tree_path_free (path);
4670 * gtk_icon_view_set_selection_mode:
4671 * @icon_view: A #GtkIconView.
4672 * @mode: The selection mode
4674 * Sets the selection mode of the @icon_view.
4679 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4680 GtkSelectionMode mode)
4682 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4684 if (mode == icon_view->priv->selection_mode)
4687 if (mode == GTK_SELECTION_NONE ||
4688 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4689 gtk_icon_view_unselect_all (icon_view);
4691 icon_view->priv->selection_mode = mode;
4693 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4697 * gtk_icon_view_get_selection_mode:
4698 * @icon_view: A #GtkIconView.
4700 * Gets the selection mode of the @icon_view.
4702 * Return value: the current selection mode
4707 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4709 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4711 return icon_view->priv->selection_mode;
4715 * gtk_icon_view_set_model:
4716 * @icon_view: A #GtkIconView.
4717 * @model: The model.
4719 * Sets the model for a #GtkIconView.
4720 * If the @icon_view already has a model set, it will remove
4721 * it before setting the new model. If @model is %NULL, then
4722 * it will unset the old model.
4727 gtk_icon_view_set_model (GtkIconView *icon_view,
4728 GtkTreeModel *model)
4730 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4731 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4733 if (icon_view->priv->model == model)
4736 if (icon_view->priv->scroll_to_path)
4738 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4739 icon_view->priv->scroll_to_path = NULL;
4742 gtk_icon_view_stop_editing (icon_view, TRUE);
4748 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
4750 if (icon_view->priv->pixbuf_column != -1)
4752 column_type = gtk_tree_model_get_column_type (model,
4753 icon_view->priv->pixbuf_column);
4755 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4758 if (icon_view->priv->text_column != -1)
4760 column_type = gtk_tree_model_get_column_type (model,
4761 icon_view->priv->text_column);
4763 g_return_if_fail (column_type == G_TYPE_STRING);
4766 if (icon_view->priv->markup_column != -1)
4768 column_type = gtk_tree_model_get_column_type (model,
4769 icon_view->priv->markup_column);
4771 g_return_if_fail (column_type == G_TYPE_STRING);
4776 if (icon_view->priv->model)
4778 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4779 gtk_icon_view_row_changed,
4781 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4782 gtk_icon_view_row_inserted,
4784 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4785 gtk_icon_view_row_deleted,
4787 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4788 gtk_icon_view_rows_reordered,
4791 g_object_unref (icon_view->priv->model);
4793 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4794 g_list_free (icon_view->priv->items);
4795 icon_view->priv->items = NULL;
4796 icon_view->priv->anchor_item = NULL;
4797 icon_view->priv->cursor_item = NULL;
4798 icon_view->priv->last_single_clicked = NULL;
4799 icon_view->priv->width = 0;
4800 icon_view->priv->height = 0;
4803 icon_view->priv->model = model;
4805 if (icon_view->priv->model)
4807 g_object_ref (icon_view->priv->model);
4808 g_signal_connect (icon_view->priv->model,
4810 G_CALLBACK (gtk_icon_view_row_changed),
4812 g_signal_connect (icon_view->priv->model,
4814 G_CALLBACK (gtk_icon_view_row_inserted),
4816 g_signal_connect (icon_view->priv->model,
4818 G_CALLBACK (gtk_icon_view_row_deleted),
4820 g_signal_connect (icon_view->priv->model,
4822 G_CALLBACK (gtk_icon_view_rows_reordered),
4825 gtk_icon_view_build_items (icon_view);
4827 gtk_icon_view_queue_layout (icon_view);
4830 g_object_notify (G_OBJECT (icon_view), "model");
4832 if (GTK_WIDGET_REALIZED (icon_view))
4833 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4837 * gtk_icon_view_get_model:
4838 * @icon_view: a #GtkIconView
4840 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4843 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
4848 gtk_icon_view_get_model (GtkIconView *icon_view)
4850 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4852 return icon_view->priv->model;
4856 update_text_cell (GtkIconView *icon_view)
4858 GtkIconViewCellInfo *info;
4862 if (icon_view->priv->text_column == -1 &&
4863 icon_view->priv->markup_column == -1)
4865 if (icon_view->priv->text_cell != -1)
4867 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
4868 icon_view->priv->pixbuf_cell--;
4870 info = g_list_nth_data (icon_view->priv->cell_list,
4871 icon_view->priv->text_cell);
4873 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
4875 free_cell_info (info);
4877 icon_view->priv->n_cells--;
4878 icon_view->priv->text_cell = -1;
4883 if (icon_view->priv->text_cell == -1)
4885 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
4886 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4887 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4890 if (info->cell == cell)
4892 icon_view->priv->text_cell = i;
4898 info = g_list_nth_data (icon_view->priv->cell_list,
4899 icon_view->priv->text_cell);
4901 if (icon_view->priv->markup_column != -1)
4902 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4904 "markup", icon_view->priv->markup_column,
4907 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4909 "text", icon_view->priv->text_column,
4912 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4913 g_object_set (info->cell,
4914 "alignment", PANGO_ALIGN_CENTER,
4915 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4920 g_object_set (info->cell,
4921 "alignment", PANGO_ALIGN_LEFT,
4922 "wrap-mode", PANGO_WRAP_WORD_CHAR,
4930 update_pixbuf_cell (GtkIconView *icon_view)
4932 GtkIconViewCellInfo *info;
4936 if (icon_view->priv->pixbuf_column == -1)
4938 if (icon_view->priv->pixbuf_cell != -1)
4940 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
4941 icon_view->priv->text_cell--;
4943 info = g_list_nth_data (icon_view->priv->cell_list,
4944 icon_view->priv->pixbuf_cell);
4946 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
4948 free_cell_info (info);
4950 icon_view->priv->n_cells--;
4951 icon_view->priv->pixbuf_cell = -1;
4956 if (icon_view->priv->pixbuf_cell == -1)
4958 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
4960 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4961 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4964 if (info->cell == cell)
4966 icon_view->priv->pixbuf_cell = i;
4972 info = g_list_nth_data (icon_view->priv->cell_list,
4973 icon_view->priv->pixbuf_cell);
4975 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4977 "pixbuf", icon_view->priv->pixbuf_column,
4980 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4981 g_object_set (info->cell,
4982 "follow-state", TRUE,
4987 g_object_set (info->cell,
4988 "follow-state", TRUE,
4996 * gtk_icon_view_set_text_column:
4997 * @icon_view: A #GtkIconView.
4998 * @column: A column in the currently used model, or -1 to display no text
5000 * Sets the column with text for @icon_view to be @column. The text
5001 * column must be of type #G_TYPE_STRING.
5006 gtk_icon_view_set_text_column (GtkIconView *icon_view,
5009 if (column == icon_view->priv->text_column)
5013 icon_view->priv->text_column = -1;
5016 if (icon_view->priv->model != NULL)
5020 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5022 g_return_if_fail (column_type == G_TYPE_STRING);
5025 icon_view->priv->text_column = column;
5028 gtk_icon_view_stop_editing (icon_view, TRUE);
5030 update_text_cell (icon_view);
5032 gtk_icon_view_invalidate_sizes (icon_view);
5033 gtk_icon_view_queue_layout (icon_view);
5035 g_object_notify (G_OBJECT (icon_view), "text-column");
5039 * gtk_icon_view_get_text_column:
5040 * @icon_view: A #GtkIconView.
5042 * Returns the column with text for @icon_view.
5044 * Returns: the text column, or -1 if it's unset.
5049 gtk_icon_view_get_text_column (GtkIconView *icon_view)
5051 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5053 return icon_view->priv->text_column;
5057 * gtk_icon_view_set_markup_column:
5058 * @icon_view: A #GtkIconView.
5059 * @column: A column in the currently used model, or -1 to display no text
5061 * Sets the column with markup information for @icon_view to be
5062 * @column. The markup column must be of type #G_TYPE_STRING.
5063 * If the markup column is set to something, it overrides
5064 * the text column set by gtk_icon_view_set_text_column().
5069 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5072 if (column == icon_view->priv->markup_column)
5076 icon_view->priv->markup_column = -1;
5079 if (icon_view->priv->model != NULL)
5083 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5085 g_return_if_fail (column_type == G_TYPE_STRING);
5088 icon_view->priv->markup_column = column;
5091 gtk_icon_view_stop_editing (icon_view, TRUE);
5093 update_text_cell (icon_view);
5095 gtk_icon_view_invalidate_sizes (icon_view);
5096 gtk_icon_view_queue_layout (icon_view);
5098 g_object_notify (G_OBJECT (icon_view), "markup-column");
5102 * gtk_icon_view_get_markup_column:
5103 * @icon_view: A #GtkIconView.
5105 * Returns the column with markup text for @icon_view.
5107 * Returns: the markup column, or -1 if it's unset.
5112 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5114 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5116 return icon_view->priv->markup_column;
5120 * gtk_icon_view_set_pixbuf_column:
5121 * @icon_view: A #GtkIconView.
5122 * @column: A column in the currently used model, or -1 to disable
5124 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5125 * column must be of type #GDK_TYPE_PIXBUF
5130 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5133 if (column == icon_view->priv->pixbuf_column)
5137 icon_view->priv->pixbuf_column = -1;
5140 if (icon_view->priv->model != NULL)
5144 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5146 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5149 icon_view->priv->pixbuf_column = column;
5152 gtk_icon_view_stop_editing (icon_view, TRUE);
5154 update_pixbuf_cell (icon_view);
5156 gtk_icon_view_invalidate_sizes (icon_view);
5157 gtk_icon_view_queue_layout (icon_view);
5159 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5164 * gtk_icon_view_get_pixbuf_column:
5165 * @icon_view: A #GtkIconView.
5167 * Returns the column with pixbufs for @icon_view.
5169 * Returns: the pixbuf column, or -1 if it's unset.
5174 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5176 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5178 return icon_view->priv->pixbuf_column;
5182 * gtk_icon_view_select_path:
5183 * @icon_view: A #GtkIconView.
5184 * @path: The #GtkTreePath to be selected.
5186 * Selects the row at @path.
5191 gtk_icon_view_select_path (GtkIconView *icon_view,
5194 GtkIconViewItem *item = NULL;
5196 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5197 g_return_if_fail (icon_view->priv->model != NULL);
5198 g_return_if_fail (path != NULL);
5200 if (gtk_tree_path_get_depth (path) > 0)
5201 item = g_list_nth_data (icon_view->priv->items,
5202 gtk_tree_path_get_indices(path)[0]);
5205 gtk_icon_view_select_item (icon_view, item);
5209 * gtk_icon_view_unselect_path:
5210 * @icon_view: A #GtkIconView.
5211 * @path: The #GtkTreePath to be unselected.
5213 * Unselects the row at @path.
5218 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5221 GtkIconViewItem *item;
5223 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5224 g_return_if_fail (icon_view->priv->model != NULL);
5225 g_return_if_fail (path != NULL);
5227 item = g_list_nth_data (icon_view->priv->items,
5228 gtk_tree_path_get_indices(path)[0]);
5233 gtk_icon_view_unselect_item (icon_view, item);
5237 * gtk_icon_view_get_selected_items:
5238 * @icon_view: A #GtkIconView.
5240 * Creates a list of paths of all selected items. Additionally, if you are
5241 * planning on modifying the model after calling this function, you may
5242 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5243 * To do this, you can use gtk_tree_row_reference_new().
5245 * To free the return value, use:
5246 * <informalexample><programlisting>
5247 * g_list_foreach (list, gtk_tree_path_free, NULL);
5248 * g_list_free (list);
5249 * </programlisting></informalexample>
5251 * Return value: A #GList containing a #GtkTreePath for each selected row.
5256 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5259 GList *selected = NULL;
5261 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5263 for (list = icon_view->priv->items; list != NULL; list = list->next)
5265 GtkIconViewItem *item = list->data;
5269 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5271 selected = g_list_prepend (selected, path);
5279 * gtk_icon_view_select_all:
5280 * @icon_view: A #GtkIconView.
5282 * Selects all the icons. @icon_view must has its selection mode set
5283 * to #GTK_SELECTION_MULTIPLE.
5288 gtk_icon_view_select_all (GtkIconView *icon_view)
5291 gboolean dirty = FALSE;
5293 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5295 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5298 for (items = icon_view->priv->items; items; items = items->next)
5300 GtkIconViewItem *item = items->data;
5302 if (!item->selected)
5305 item->selected = TRUE;
5306 gtk_icon_view_queue_draw_item (icon_view, item);
5311 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5315 * gtk_icon_view_unselect_all:
5316 * @icon_view: A #GtkIconView.
5318 * Unselects all the icons.
5323 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5325 gboolean dirty = FALSE;
5327 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5329 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5332 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5335 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5339 * gtk_icon_view_path_is_selected:
5340 * @icon_view: A #GtkIconView.
5341 * @path: A #GtkTreePath to check selection on.
5343 * Returns %TRUE if the icon pointed to by @path is currently
5344 * selected. If @path does not point to a valid location, %FALSE is returned.
5346 * Return value: %TRUE if @path is selected.
5351 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5354 GtkIconViewItem *item;
5356 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5357 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5358 g_return_val_if_fail (path != NULL, FALSE);
5360 item = g_list_nth_data (icon_view->priv->items,
5361 gtk_tree_path_get_indices(path)[0]);
5366 return item->selected;
5370 * gtk_icon_view_item_activated:
5371 * @icon_view: A #GtkIconView
5372 * @path: The #GtkTreePath to be activated
5374 * Activates the item determined by @path.
5379 gtk_icon_view_item_activated (GtkIconView *icon_view,
5382 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5383 g_return_if_fail (path != NULL);
5385 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5389 * gtk_icon_view_set_orientation:
5390 * @icon_view: a #GtkIconView
5391 * @orientation: the relative position of texts and icons
5393 * Sets the ::orientation property which determines whether the labels
5394 * are drawn beside the icons instead of below.
5399 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5400 GtkOrientation orientation)
5402 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5404 if (icon_view->priv->orientation != orientation)
5406 icon_view->priv->orientation = orientation;
5408 gtk_icon_view_stop_editing (icon_view, TRUE);
5409 gtk_icon_view_invalidate_sizes (icon_view);
5410 gtk_icon_view_queue_layout (icon_view);
5412 update_text_cell (icon_view);
5413 update_pixbuf_cell (icon_view);
5415 g_object_notify (G_OBJECT (icon_view), "orientation");
5420 * gtk_icon_view_get_orientation:
5421 * @icon_view: a #GtkIconView
5423 * Returns the value of the ::orientation property which determines
5424 * whether the labels are drawn beside the icons instead of below.
5426 * Return value: the relative position of texts and icons
5431 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5433 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5434 GTK_ORIENTATION_VERTICAL);
5436 return icon_view->priv->orientation;
5440 * gtk_icon_view_set_columns:
5441 * @icon_view: a #GtkIconView
5442 * @columns: the number of columns
5444 * Sets the ::columns property which determines in how
5445 * many columns the icons are arranged. If @columns is
5446 * -1, the number of columns will be chosen automatically
5447 * to fill the available area.
5452 gtk_icon_view_set_columns (GtkIconView *icon_view,
5455 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5457 if (icon_view->priv->columns != columns)
5459 icon_view->priv->columns = columns;
5461 gtk_icon_view_stop_editing (icon_view, TRUE);
5462 gtk_icon_view_queue_layout (icon_view);
5464 g_object_notify (G_OBJECT (icon_view), "columns");
5469 * gtk_icon_view_get_columns:
5470 * @icon_view: a #GtkIconView
5472 * Returns the value of the ::columns property.
5474 * Return value: the number of columns, or -1
5479 gtk_icon_view_get_columns (GtkIconView *icon_view)
5481 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5483 return icon_view->priv->columns;
5487 * gtk_icon_view_set_item_width:
5488 * @icon_view: a #GtkIconView
5489 * @item_width: the width for each item
5491 * Sets the ::item-width property which specifies the width
5492 * to use for each item. If it is set to -1, the icon view will
5493 * automatically determine a suitable item size.
5498 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5501 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5503 if (icon_view->priv->item_width != item_width)
5505 icon_view->priv->item_width = item_width;
5507 gtk_icon_view_stop_editing (icon_view, TRUE);
5508 gtk_icon_view_invalidate_sizes (icon_view);
5509 gtk_icon_view_queue_layout (icon_view);
5511 update_text_cell (icon_view);
5513 g_object_notify (G_OBJECT (icon_view), "item-width");
5518 * gtk_icon_view_get_item_width:
5519 * @icon_view: a #GtkIconView
5521 * Returns the value of the ::item-width property.
5523 * Return value: the width of a single item, or -1
5528 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5530 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5532 return icon_view->priv->item_width;
5537 * gtk_icon_view_set_spacing:
5538 * @icon_view: a #GtkIconView
5539 * @spacing: the spacing
5541 * Sets the ::spacing property which specifies the space
5542 * which is inserted between the cells (i.e. the icon and
5543 * the text) of an item.
5548 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5551 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5553 if (icon_view->priv->spacing != spacing)
5555 icon_view->priv->spacing = spacing;
5557 gtk_icon_view_stop_editing (icon_view, TRUE);
5558 gtk_icon_view_invalidate_sizes (icon_view);
5559 gtk_icon_view_queue_layout (icon_view);
5561 g_object_notify (G_OBJECT (icon_view), "spacing");
5566 * gtk_icon_view_get_spacing:
5567 * @icon_view: a #GtkIconView
5569 * Returns the value of the ::spacing property.
5571 * Return value: the space between cells
5576 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5578 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5580 return icon_view->priv->spacing;
5584 * gtk_icon_view_set_row_spacing:
5585 * @icon_view: a #GtkIconView
5586 * @row_spacing: the row spacing
5588 * Sets the ::row-spacing property which specifies the space
5589 * which is inserted between the rows of the icon view.
5594 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5597 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5599 if (icon_view->priv->row_spacing != row_spacing)
5601 icon_view->priv->row_spacing = row_spacing;
5603 gtk_icon_view_stop_editing (icon_view, TRUE);
5604 gtk_icon_view_invalidate_sizes (icon_view);
5605 gtk_icon_view_queue_layout (icon_view);
5607 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5612 * gtk_icon_view_get_row_spacing:
5613 * @icon_view: a #GtkIconView
5615 * Returns the value of the ::row-spacing property.
5617 * Return value: the space between rows
5622 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5624 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5626 return icon_view->priv->row_spacing;
5630 * gtk_icon_view_set_column_spacing:
5631 * @icon_view: a #GtkIconView
5632 * @column_spacing: the column spacing
5634 * Sets the ::column-spacing property which specifies the space
5635 * which is inserted between the columns of the icon view.
5640 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5641 gint column_spacing)
5643 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5645 if (icon_view->priv->column_spacing != column_spacing)
5647 icon_view->priv->column_spacing = column_spacing;
5649 gtk_icon_view_stop_editing (icon_view, TRUE);
5650 gtk_icon_view_invalidate_sizes (icon_view);
5651 gtk_icon_view_queue_layout (icon_view);
5653 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5658 * gtk_icon_view_get_column_spacing:
5659 * @icon_view: a #GtkIconView
5661 * Returns the value of the ::column-spacing property.
5663 * Return value: the space between columns
5668 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5670 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5672 return icon_view->priv->column_spacing;
5676 * gtk_icon_view_set_margin:
5677 * @icon_view: a #GtkIconView
5678 * @margin: the margin
5680 * Sets the ::margin property which specifies the space
5681 * which is inserted at the top, bottom, left and right
5687 gtk_icon_view_set_margin (GtkIconView *icon_view,
5690 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5692 if (icon_view->priv->margin != margin)
5694 icon_view->priv->margin = margin;
5696 gtk_icon_view_stop_editing (icon_view, TRUE);
5697 gtk_icon_view_invalidate_sizes (icon_view);
5698 gtk_icon_view_queue_layout (icon_view);
5700 g_object_notify (G_OBJECT (icon_view), "margin");
5705 * gtk_icon_view_get_margin:
5706 * @icon_view: a #GtkIconView
5708 * Returns the value of the ::margin property.
5710 * Return value: the space at the borders
5715 gtk_icon_view_get_margin (GtkIconView *icon_view)
5717 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5719 return icon_view->priv->margin;
5723 /* Get/set whether drag_motion requested the drag data and
5724 * drag_data_received should thus not actually insert the data,
5725 * since the data doesn't result from a drop.
5728 set_status_pending (GdkDragContext *context,
5729 GdkDragAction suggested_action)
5731 g_object_set_data (G_OBJECT (context),
5732 I_("gtk-icon-view-status-pending"),
5733 GINT_TO_POINTER (suggested_action));
5736 static GdkDragAction
5737 get_status_pending (GdkDragContext *context)
5739 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5740 "gtk-icon-view-status-pending"));
5744 unset_reorderable (GtkIconView *icon_view)
5746 if (icon_view->priv->reorderable)
5748 icon_view->priv->reorderable = FALSE;
5749 g_object_notify (G_OBJECT (icon_view), "reorderable");
5754 clear_source_info (GtkIconView *icon_view)
5756 if (icon_view->priv->source_targets)
5757 gtk_target_list_unref (icon_view->priv->source_targets);
5758 icon_view->priv->source_targets = NULL;
5760 icon_view->priv->source_set = FALSE;
5764 clear_dest_info (GtkIconView *icon_view)
5766 if (icon_view->priv->dest_targets)
5767 gtk_target_list_unref (icon_view->priv->dest_targets);
5768 icon_view->priv->dest_targets = NULL;
5770 icon_view->priv->dest_set = FALSE;
5774 set_source_row (GdkDragContext *context,
5775 GtkTreeModel *model,
5776 GtkTreePath *source_row)
5779 g_object_set_data_full (G_OBJECT (context),
5780 I_("gtk-icon-view-source-row"),
5781 gtk_tree_row_reference_new (model, source_row),
5782 (GDestroyNotify) gtk_tree_row_reference_free);
5784 g_object_set_data_full (G_OBJECT (context),
5785 I_("gtk-icon-view-source-row"),
5790 get_source_row (GdkDragContext *context)
5792 GtkTreeRowReference *ref;
5794 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5797 return gtk_tree_row_reference_get_path (ref);
5804 GtkTreeRowReference *dest_row;
5805 gboolean empty_view_drop;
5806 gboolean drop_append_mode;
5810 dest_row_free (gpointer data)
5812 DestRow *dr = (DestRow *)data;
5814 gtk_tree_row_reference_free (dr->dest_row);
5819 set_dest_row (GdkDragContext *context,
5820 GtkTreeModel *model,
5821 GtkTreePath *dest_row,
5822 gboolean empty_view_drop,
5823 gboolean drop_append_mode)
5829 g_object_set_data_full (G_OBJECT (context),
5830 I_("gtk-icon-view-dest-row"),
5835 dr = g_new0 (DestRow, 1);
5837 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5838 dr->empty_view_drop = empty_view_drop;
5839 dr->drop_append_mode = drop_append_mode;
5840 g_object_set_data_full (G_OBJECT (context),
5841 I_("gtk-icon-view-dest-row"),
5842 dr, (GDestroyNotify) dest_row_free);
5846 get_dest_row (GdkDragContext *context)
5850 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5854 GtkTreePath *path = NULL;
5857 path = gtk_tree_row_reference_get_path (dr->dest_row);
5858 else if (dr->empty_view_drop)
5859 path = gtk_tree_path_new_from_indices (0, -1);
5863 if (path && dr->drop_append_mode)
5864 gtk_tree_path_next (path);
5873 check_model_dnd (GtkTreeModel *model,
5874 GType required_iface,
5875 const gchar *signal)
5877 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5879 g_warning ("You must override the default '%s' handler "
5880 "on GtkIconView when using models that don't support "
5881 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5882 "is to connect to '%s' and call "
5883 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5884 "the default handler from running. Look at the source code "
5885 "for the default handler in gtkiconview.c to get an idea what "
5886 "your handler should do. (gtkiconview.c is in the GTK+ source "
5887 "code.) If you're using GTK+ from a language other than C, "
5888 "there may be a more natural way to override default handlers, e.g. via derivation.",
5889 signal, g_type_name (required_iface), signal);
5897 remove_scroll_timeout (GtkIconView *icon_view)
5899 if (icon_view->priv->scroll_timeout_id != 0)
5901 g_source_remove (icon_view->priv->scroll_timeout_id);
5903 icon_view->priv->scroll_timeout_id = 0;
5908 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5910 gint px, py, x, y, width, height;
5911 gint hoffset, voffset;
5914 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
5915 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
5917 /* see if we are near the edge. */
5918 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5920 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5922 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5924 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5928 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
5929 icon_view->priv->vadjustment->lower,
5930 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
5931 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
5935 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
5936 icon_view->priv->hadjustment->lower,
5937 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
5938 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
5944 drag_scroll_timeout (gpointer data)
5946 GtkIconView *icon_view = GTK_ICON_VIEW (data);
5948 gtk_icon_view_autoscroll (icon_view);
5955 set_destination (GtkIconView *icon_view,
5956 GdkDragContext *context,
5959 GdkDragAction *suggested_action,
5963 GtkTreePath *path = NULL;
5964 GtkIconViewDropPosition pos;
5965 GtkIconViewDropPosition old_pos;
5966 GtkTreePath *old_dest_path = NULL;
5967 gboolean can_drop = FALSE;
5969 widget = GTK_WIDGET (icon_view);
5971 *suggested_action = 0;
5974 if (!icon_view->priv->dest_set)
5976 /* someone unset us as a drag dest, note that if
5977 * we return FALSE drag_leave isn't called
5980 gtk_icon_view_set_drag_dest_item (icon_view,
5982 GTK_ICON_VIEW_DROP_LEFT);
5984 remove_scroll_timeout (GTK_ICON_VIEW (widget));
5986 return FALSE; /* no longer a drop site */
5989 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
5990 if (*target == GDK_NONE)
5993 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
5996 GtkTreeModel *model;
5998 /* the row got dropped on empty space, let's setup a special case
6002 gtk_tree_path_free (path);
6004 model = gtk_icon_view_get_model (icon_view);
6006 n_children = gtk_tree_model_iter_n_children (model, NULL);
6009 pos = GTK_ICON_VIEW_DROP_BELOW;
6010 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6014 pos = GTK_ICON_VIEW_DROP_ABOVE;
6015 path = gtk_tree_path_new_from_indices (0, -1);
6025 gtk_icon_view_get_drag_dest_item (icon_view,
6030 gtk_tree_path_free (old_dest_path);
6032 if (TRUE /* FIXME if the location droppable predicate */)
6040 GtkWidget *source_widget;
6042 *suggested_action = context->suggested_action;
6043 source_widget = gtk_drag_get_source_widget (context);
6045 if (source_widget == widget)
6047 /* Default to MOVE, unless the user has
6048 * pressed ctrl or shift to affect available actions
6050 if ((context->actions & GDK_ACTION_MOVE) != 0)
6051 *suggested_action = GDK_ACTION_MOVE;
6054 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6059 /* can't drop here */
6060 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6062 GTK_ICON_VIEW_DROP_LEFT);
6066 gtk_tree_path_free (path);
6072 get_logical_destination (GtkIconView *icon_view,
6073 gboolean *drop_append_mode)
6075 /* adjust path to point to the row the drop goes in front of */
6076 GtkTreePath *path = NULL;
6077 GtkIconViewDropPosition pos;
6079 *drop_append_mode = FALSE;
6081 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6086 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6087 pos == GTK_ICON_VIEW_DROP_BELOW)
6090 GtkTreeModel *model = icon_view->priv->model;
6092 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6093 !gtk_tree_model_iter_next (model, &iter))
6094 *drop_append_mode = TRUE;
6097 *drop_append_mode = FALSE;
6098 gtk_tree_path_next (path);
6106 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6107 GdkEventMotion *event)
6109 GdkDragContext *context;
6110 GtkTreePath *path = NULL;
6112 GtkTreeModel *model;
6113 gboolean retval = FALSE;
6115 if (!icon_view->priv->source_set)
6118 if (icon_view->priv->pressed_button < 0)
6121 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6122 icon_view->priv->press_start_x,
6123 icon_view->priv->press_start_y,
6124 event->x, event->y))
6127 model = gtk_icon_view_get_model (icon_view);
6132 button = icon_view->priv->pressed_button;
6133 icon_view->priv->pressed_button = -1;
6135 path = gtk_icon_view_get_path_at_pos (icon_view,
6136 icon_view->priv->press_start_x,
6137 icon_view->priv->press_start_y);
6142 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6143 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6147 /* FIXME Check whether we're a start button, if not return FALSE and
6151 /* Now we can begin the drag */
6155 context = gtk_drag_begin (GTK_WIDGET (icon_view),
6156 icon_view->priv->source_targets,
6157 icon_view->priv->source_actions,
6161 set_source_row (context, model, path);
6165 gtk_tree_path_free (path);
6170 /* Source side drag signals */
6172 gtk_icon_view_drag_begin (GtkWidget *widget,
6173 GdkDragContext *context)
6175 GtkIconView *icon_view;
6176 GtkIconViewItem *item;
6181 icon_view = GTK_ICON_VIEW (widget);
6183 /* if the user uses a custom DnD impl, we don't set the icon here */
6184 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6187 item = gtk_icon_view_get_item_at_coords (icon_view,
6188 icon_view->priv->press_start_x,
6189 icon_view->priv->press_start_y,
6193 g_return_if_fail (item != NULL);
6195 x = icon_view->priv->press_start_x - item->x + 1;
6196 y = icon_view->priv->press_start_y - item->y + 1;
6198 path = gtk_tree_path_new_from_indices (item->index, -1);
6199 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6200 gtk_tree_path_free (path);
6202 gtk_drag_set_icon_pixmap (context,
6203 gdk_drawable_get_colormap (icon),
6208 g_object_unref (icon);
6212 gtk_icon_view_drag_end (GtkWidget *widget,
6213 GdkDragContext *context)
6219 gtk_icon_view_drag_data_get (GtkWidget *widget,
6220 GdkDragContext *context,
6221 GtkSelectionData *selection_data,
6225 GtkIconView *icon_view;
6226 GtkTreeModel *model;
6227 GtkTreePath *source_row;
6229 icon_view = GTK_ICON_VIEW (widget);
6230 model = gtk_icon_view_get_model (icon_view);
6235 if (!icon_view->priv->dest_set)
6238 source_row = get_source_row (context);
6240 if (source_row == NULL)
6243 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6244 * any model; for DragSource models there are some other targets
6248 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6249 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6254 /* If drag_data_get does nothing, try providing row data. */
6255 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6256 gtk_tree_set_row_drag_data (selection_data,
6261 gtk_tree_path_free (source_row);
6265 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6266 GdkDragContext *context)
6268 GtkTreeModel *model;
6269 GtkIconView *icon_view;
6270 GtkTreePath *source_row;
6272 icon_view = GTK_ICON_VIEW (widget);
6273 model = gtk_icon_view_get_model (icon_view);
6275 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6278 if (!icon_view->priv->dest_set)
6281 source_row = get_source_row (context);
6283 if (source_row == NULL)
6286 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6289 gtk_tree_path_free (source_row);
6291 set_source_row (context, NULL, NULL);
6294 /* Target side drag signals */
6296 gtk_icon_view_drag_leave (GtkWidget *widget,
6297 GdkDragContext *context,
6300 GtkIconView *icon_view;
6302 icon_view = GTK_ICON_VIEW (widget);
6304 /* unset any highlight row */
6305 gtk_icon_view_set_drag_dest_item (icon_view,
6307 GTK_ICON_VIEW_DROP_LEFT);
6309 remove_scroll_timeout (icon_view);
6313 gtk_icon_view_drag_motion (GtkWidget *widget,
6314 GdkDragContext *context,
6319 GtkTreePath *path = NULL;
6320 GtkIconViewDropPosition pos;
6321 GtkIconView *icon_view;
6322 GdkDragAction suggested_action = 0;
6326 icon_view = GTK_ICON_VIEW (widget);
6328 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6331 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6333 /* we only know this *after* set_desination_row */
6334 empty = icon_view->priv->empty_view_drop;
6336 if (path == NULL && !empty)
6338 /* Can't drop here. */
6339 gdk_drag_status (context, 0, time);
6343 if (icon_view->priv->scroll_timeout_id == 0)
6345 icon_view->priv->scroll_timeout_id =
6346 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6349 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6351 /* Request data so we can use the source row when
6352 * determining whether to accept the drop
6354 set_status_pending (context, suggested_action);
6355 gtk_drag_get_data (widget, context, target, time);
6359 set_status_pending (context, 0);
6360 gdk_drag_status (context, suggested_action, time);
6365 gtk_tree_path_free (path);
6371 gtk_icon_view_drag_drop (GtkWidget *widget,
6372 GdkDragContext *context,
6377 GtkIconView *icon_view;
6379 GdkDragAction suggested_action = 0;
6380 GdkAtom target = GDK_NONE;
6381 GtkTreeModel *model;
6382 gboolean drop_append_mode;
6384 icon_view = GTK_ICON_VIEW (widget);
6385 model = gtk_icon_view_get_model (icon_view);
6387 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6389 if (!icon_view->priv->dest_set)
6392 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6395 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6398 path = get_logical_destination (icon_view, &drop_append_mode);
6400 if (target != GDK_NONE && path != NULL)
6402 /* in case a motion had requested drag data, change things so we
6403 * treat drag data receives as a drop.
6405 set_status_pending (context, 0);
6406 set_dest_row (context, model, path,
6407 icon_view->priv->empty_view_drop, drop_append_mode);
6411 gtk_tree_path_free (path);
6413 /* Unset this thing */
6414 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6416 if (target != GDK_NONE)
6418 gtk_drag_get_data (widget, context, target, time);
6426 gtk_icon_view_drag_data_received (GtkWidget *widget,
6427 GdkDragContext *context,
6430 GtkSelectionData *selection_data,
6435 gboolean accepted = FALSE;
6436 GtkTreeModel *model;
6437 GtkIconView *icon_view;
6438 GtkTreePath *dest_row;
6439 GdkDragAction suggested_action;
6440 gboolean drop_append_mode;
6442 icon_view = GTK_ICON_VIEW (widget);
6443 model = gtk_icon_view_get_model (icon_view);
6445 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6448 if (!icon_view->priv->dest_set)
6451 suggested_action = get_status_pending (context);
6453 if (suggested_action)
6455 /* We are getting this data due to a request in drag_motion,
6456 * rather than due to a request in drag_drop, so we are just
6457 * supposed to call drag_status, not actually paste in the
6460 path = get_logical_destination (icon_view, &drop_append_mode);
6463 suggested_action = 0;
6465 if (suggested_action)
6467 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6470 suggested_action = 0;
6473 gdk_drag_status (context, suggested_action, time);
6476 gtk_tree_path_free (path);
6478 /* If you can't drop, remove user drop indicator until the next motion */
6479 if (suggested_action == 0)
6480 gtk_icon_view_set_drag_dest_item (icon_view,
6482 GTK_ICON_VIEW_DROP_LEFT);
6487 dest_row = get_dest_row (context);
6489 if (dest_row == NULL)
6492 if (selection_data->length >= 0)
6494 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6500 gtk_drag_finish (context,
6502 (context->action == GDK_ACTION_MOVE),
6505 gtk_tree_path_free (dest_row);
6508 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6511 /* Drag-and-Drop support */
6513 * gtk_icon_view_enable_model_drag_source:
6514 * @icon_view: a #GtkIconTreeView
6515 * @start_button_mask: Mask of allowed buttons to start drag
6516 * @targets: the table of targets that the drag will support
6517 * @n_targets: the number of items in @targets
6518 * @actions: the bitmask of possible actions for a drag from this
6521 * Turns @icon_view into a drag source for automatic DND.
6526 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6527 GdkModifierType start_button_mask,
6528 const GtkTargetEntry *targets,
6530 GdkDragAction actions)
6532 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6534 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6536 clear_source_info (icon_view);
6537 icon_view->priv->start_button_mask = start_button_mask;
6538 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6539 icon_view->priv->source_actions = actions;
6541 icon_view->priv->source_set = TRUE;
6543 unset_reorderable (icon_view);
6547 * gtk_icon_view_enable_model_drag_dest:
6548 * @icon_view: a #GtkIconView
6549 * @targets: the table of targets that the drag will support
6550 * @n_targets: the number of items in @targets
6551 * @actions: the bitmask of possible actions for a drag to this
6554 * Turns @icon_view into a drop destination for automatic DND.
6559 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6560 const GtkTargetEntry *targets,
6562 GdkDragAction actions)
6564 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6566 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6568 clear_dest_info (icon_view);
6570 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6571 icon_view->priv->dest_actions = actions;
6573 icon_view->priv->dest_set = TRUE;
6575 unset_reorderable (icon_view);
6579 * gtk_icon_view_unset_model_drag_source:
6580 * @icon_view: a #GtkIconView
6582 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6587 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6589 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6591 if (icon_view->priv->source_set)
6593 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6594 clear_source_info (icon_view);
6597 unset_reorderable (icon_view);
6601 * gtk_icon_view_unset_model_drag_dest:
6602 * @icon_view: a #GtkIconView
6604 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6609 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6611 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6613 if (icon_view->priv->dest_set)
6615 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6616 clear_dest_info (icon_view);
6619 unset_reorderable (icon_view);
6622 /* These are useful to implement your own custom stuff. */
6624 * gtk_icon_view_set_drag_dest_item:
6625 * @icon_view: a #GtkIconView
6626 * @path: The path of the item to highlight, or %NULL.
6627 * @pos: Specifies where to drop, relative to the item
6629 * Sets the item that is highlighted for feedback.
6634 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6636 GtkIconViewDropPosition pos)
6638 /* Note; this function is exported to allow a custom DND
6639 * implementation, so it can't touch TreeViewDragInfo
6642 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6644 if (icon_view->priv->dest_item)
6646 GtkTreePath *current_path;
6647 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6648 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6649 icon_view->priv->dest_item = NULL;
6651 gtk_icon_view_queue_draw_path (icon_view, current_path);
6652 gtk_tree_path_free (current_path);
6655 /* special case a drop on an empty model */
6656 icon_view->priv->empty_view_drop = FALSE;
6657 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
6658 && gtk_tree_path_get_depth (path) == 1
6659 && gtk_tree_path_get_indices (path)[0] == 0)
6663 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6666 if (n_children == 0)
6667 icon_view->priv->empty_view_drop = TRUE;
6670 icon_view->priv->dest_pos = pos;
6674 icon_view->priv->dest_item =
6675 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6676 icon_view->priv->model, path);
6678 gtk_icon_view_queue_draw_path (icon_view, path);
6683 * gtk_icon_view_get_drag_dest_item:
6684 * @icon_view: a #GtkIconView
6685 * @path: Return location for the path of the highlighted item, or %NULL.
6686 * @pos: Return location for the drop position, or %NULL
6688 * Gets information about the item that is highlighted for feedback.
6693 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6695 GtkIconViewDropPosition *pos)
6697 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6701 if (icon_view->priv->dest_item)
6702 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6708 *pos = icon_view->priv->dest_pos;
6712 * gtk_icon_view_get_dest_item_at_pos:
6713 * @icon_view: a #GtkIconView
6714 * @drag_x: the position to determine the destination item for
6715 * @drag_y: the position to determine the destination item for
6716 * @path: Return location for the path of the item, or %NULL.
6717 * @pos: Return location for the drop position, or %NULL
6719 * Determines the destination item for a given position.
6721 * Return value: whether there is an item at the given position.
6726 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6730 GtkIconViewDropPosition *pos)
6732 GtkIconViewItem *item;
6734 /* Note; this function is exported to allow a custom DND
6735 * implementation, so it can't touch TreeViewDragInfo
6738 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6739 g_return_val_if_fail (drag_x >= 0, FALSE);
6740 g_return_val_if_fail (drag_y >= 0, FALSE);
6741 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6747 item = gtk_icon_view_get_item_at_coords (icon_view,
6748 drag_x + icon_view->priv->hadjustment->value,
6749 drag_y + icon_view->priv->vadjustment->value,
6756 *path = gtk_tree_path_new_from_indices (item->index, -1);
6760 if (drag_x < item->x + item->width / 4)
6761 *pos = GTK_ICON_VIEW_DROP_LEFT;
6762 else if (drag_x > item->x + item->width * 3 / 4)
6763 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6764 else if (drag_y < item->y + item->height / 4)
6765 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6766 else if (drag_y > item->y + item->height * 3 / 4)
6767 *pos = GTK_ICON_VIEW_DROP_BELOW;
6769 *pos = GTK_ICON_VIEW_DROP_INTO;
6776 * gtk_icon_view_create_drag_icon:
6777 * @icon_view: a #GtkIconView
6778 * @path: a #GtkTreePath in @icon_view
6780 * Creates a #GdkPixmap representation of the item at @path.
6781 * This image is used for a drag icon.
6783 * Return value: a newly-allocated pixmap of the drag icon.
6788 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6793 GdkPixmap *drawable;
6798 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6799 g_return_val_if_fail (path != NULL, NULL);
6801 widget = GTK_WIDGET (icon_view);
6803 if (!GTK_WIDGET_REALIZED (widget))
6806 index = gtk_tree_path_get_indices (path)[0];
6808 for (l = icon_view->priv->items; l; l = l->next)
6810 GtkIconViewItem *item = l->data;
6812 if (index == item->index)
6814 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
6819 cr = gdk_cairo_create (drawable);
6820 cairo_set_line_width (cr, 1.);
6822 gdk_cairo_set_source_color
6823 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
6824 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
6829 area.width = item->width;
6830 area.height = item->height;
6832 gtk_icon_view_paint_item (icon_view, cr, item, &area,
6833 drawable, 1, 1, FALSE);
6835 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6836 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
6849 * gtk_icon_view_get_reorderable:
6850 * @icon_view: a #GtkIconView
6852 * Retrieves whether the user can reorder the list via drag-and-drop.
6853 * See gtk_icon_view_set_reorderable().
6855 * Return value: %TRUE if the list can be reordered.
6860 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6862 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6864 return icon_view->priv->reorderable;
6867 static const GtkTargetEntry item_targets[] = {
6868 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6873 * gtk_icon_view_set_reorderable:
6874 * @icon_view: A #GtkIconView.
6875 * @reorderable: %TRUE, if the list of items can be reordered.
6877 * This function is a convenience function to allow you to reorder models that
6878 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6879 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6880 * the user can reorder the model by dragging and dropping rows. The
6881 * developer can listen to these changes by connecting to the model's
6882 * row_inserted and row_deleted signals.
6884 * This function does not give you any degree of control over the order -- any
6885 * reordering is allowed. If more control is needed, you should probably
6886 * handle drag and drop manually.
6891 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6892 gboolean reorderable)
6894 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6896 reorderable = reorderable != FALSE;
6898 if (icon_view->priv->reorderable == reorderable)
6903 gtk_icon_view_enable_model_drag_source (icon_view,
6906 G_N_ELEMENTS (item_targets),
6908 gtk_icon_view_enable_model_drag_dest (icon_view,
6910 G_N_ELEMENTS (item_targets),
6915 gtk_icon_view_unset_model_drag_source (icon_view);
6916 gtk_icon_view_unset_model_drag_dest (icon_view);
6919 icon_view->priv->reorderable = reorderable;
6921 g_object_notify (G_OBJECT (icon_view), "reorderable");
6925 /* Accessibility Support */
6927 static gpointer accessible_parent_class;
6928 static gpointer accessible_item_parent_class;
6929 static GQuark accessible_private_data_quark = 0;
6931 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6932 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6933 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6935 static GType gtk_icon_view_item_accessible_get_type (void);
6946 GtkIconViewItem *item;
6950 AtkStateSet *state_set;
6954 GtkTextBuffer *text_buffer;
6956 gchar *action_descriptions[LAST_ACTION];
6957 gchar *image_description;
6958 guint action_idle_handler;
6959 } GtkIconViewItemAccessible;
6961 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
6967 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
6972 typedef struct _GtkIconViewItemAccessibleClass
6974 AtkObjectClass parent_class;
6976 } GtkIconViewItemAccessibleClass;
6978 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
6981 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
6983 GtkIconViewItemAccessible *item;
6984 GtkIconView *icon_view;
6987 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
6988 item->action_idle_handler = 0;
6990 if (item->widget != NULL)
6992 icon_view = GTK_ICON_VIEW (item->widget);
6993 path = gtk_tree_path_new_from_indices (item->item->index, -1);
6994 gtk_icon_view_item_activated (icon_view, path);
6995 gtk_tree_path_free (path);
7002 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
7005 GtkIconViewItemAccessible *item;
7007 if (i < 0 || i >= LAST_ACTION)
7010 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7012 if (!GTK_IS_ICON_VIEW (item->widget))
7015 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7020 case ACTION_ACTIVATE:
7021 if (!item->action_idle_handler)
7022 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
7025 g_assert_not_reached ();
7033 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
7038 static const gchar *
7039 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
7042 GtkIconViewItemAccessible *item;
7044 if (i < 0 || i >= LAST_ACTION)
7047 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7049 if (item->action_descriptions[i])
7050 return item->action_descriptions[i];
7052 return gtk_icon_view_item_accessible_action_descriptions[i];
7055 static const gchar *
7056 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7059 if (i < 0 || i >= LAST_ACTION)
7062 return gtk_icon_view_item_accessible_action_names[i];
7066 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7068 const gchar *description)
7070 GtkIconViewItemAccessible *item;
7072 if (i < 0 || i >= LAST_ACTION)
7075 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7077 g_free (item->action_descriptions[i]);
7079 item->action_descriptions[i] = g_strdup (description);
7085 atk_action_item_interface_init (AtkActionIface *iface)
7087 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7088 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7089 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7090 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7091 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7094 static const gchar *
7095 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7097 GtkIconViewItemAccessible *item;
7099 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7101 return item->image_description;
7105 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7106 const gchar *description)
7108 GtkIconViewItemAccessible *item;
7110 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7112 g_free (item->image_description);
7113 item->image_description = g_strdup (item->image_description);
7119 get_pixbuf_box (GtkIconView *icon_view,
7120 GtkIconViewItem *item,
7125 for (l = icon_view->priv->cell_list; l; l = l->next)
7127 GtkIconViewCellInfo *info = l->data;
7129 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7131 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7141 get_text (GtkIconView *icon_view,
7142 GtkIconViewItem *item)
7147 for (l = icon_view->priv->cell_list; l; l = l->next)
7149 GtkIconViewCellInfo *info = l->data;
7151 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7153 g_object_get (info->cell, "text", &text, NULL);
7163 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7167 GtkIconViewItemAccessible *item;
7170 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7172 if (!GTK_IS_ICON_VIEW (item->widget))
7175 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7178 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7181 *height = box.height;
7186 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7189 AtkCoordType coord_type)
7191 GtkIconViewItemAccessible *item;
7194 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7196 if (!GTK_IS_ICON_VIEW (item->widget))
7199 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7202 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7204 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7206 *x+= box.x - item->item->x;
7207 *y+= box.y - item->item->y;
7213 atk_image_item_interface_init (AtkImageIface *iface)
7215 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7216 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7217 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7218 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7222 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7226 GtkIconViewItemAccessible *item;
7227 GtkTextIter start, end;
7228 GtkTextBuffer *buffer;
7230 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7232 if (!GTK_IS_ICON_VIEW (item->widget))
7235 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7238 buffer = item->text_buffer;
7239 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7241 gtk_text_buffer_get_end_iter (buffer, &end);
7243 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7245 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7249 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7252 GtkIconViewItemAccessible *item;
7253 GtkTextIter start, end;
7254 GtkTextBuffer *buffer;
7258 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7260 if (!GTK_IS_ICON_VIEW (item->widget))
7263 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7266 buffer = item->text_buffer;
7267 if (offset >= gtk_text_buffer_get_char_count (buffer))
7270 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7272 gtk_text_iter_forward_char (&end);
7273 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7274 unichar = g_utf8_get_char (string);
7282 get_pango_text_offsets (PangoLayout *layout,
7283 GtkTextBuffer *buffer,
7285 AtkTextBoundary boundary_type,
7289 GtkTextIter *start_iter,
7290 GtkTextIter *end_iter)
7292 PangoLayoutIter *iter;
7293 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7294 gint index, start_index, end_index;
7296 gboolean found = FALSE;
7298 text = pango_layout_get_text (layout);
7299 index = g_utf8_offset_to_pointer (text, offset) - text;
7300 iter = pango_layout_get_iter (layout);
7303 line = pango_layout_iter_get_line_readonly (iter);
7304 start_index = line->start_index;
7305 end_index = start_index + line->length;
7307 if (index >= start_index && index <= end_index)
7310 * Found line for offset
7316 * We want the previous line
7320 switch (boundary_type)
7322 case ATK_TEXT_BOUNDARY_LINE_START:
7323 end_index = start_index;
7324 start_index = prev_line->start_index;
7326 case ATK_TEXT_BOUNDARY_LINE_END:
7328 start_index = prev_prev_line->start_index +
7329 prev_prev_line->length;
7330 end_index = prev_line->start_index + prev_line->length;
7333 g_assert_not_reached();
7337 start_index = end_index = 0;
7340 switch (boundary_type)
7342 case ATK_TEXT_BOUNDARY_LINE_START:
7343 if (pango_layout_iter_next_line (iter))
7344 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7346 case ATK_TEXT_BOUNDARY_LINE_END:
7348 start_index = prev_line->start_index +
7352 g_assert_not_reached();
7357 * We want the next line
7359 if (pango_layout_iter_next_line (iter))
7361 line = pango_layout_iter_get_line_readonly (iter);
7362 switch (boundary_type)
7364 case ATK_TEXT_BOUNDARY_LINE_START:
7365 start_index = line->start_index;
7366 if (pango_layout_iter_next_line (iter))
7367 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7369 end_index = start_index + line->length;
7371 case ATK_TEXT_BOUNDARY_LINE_END:
7372 start_index = end_index;
7373 end_index = line->start_index + line->length;
7376 g_assert_not_reached();
7380 start_index = end_index;
7386 prev_prev_line = prev_line;
7389 while (pango_layout_iter_next_line (iter));
7393 start_index = prev_line->start_index + prev_line->length;
7394 end_index = start_index;
7396 pango_layout_iter_free (iter);
7397 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7398 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7400 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7401 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7406 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7408 AtkTextBoundary boundary_type,
7412 GtkIconViewItemAccessible *item;
7413 GtkTextIter start, end;
7414 GtkTextBuffer *buffer;
7416 GtkIconView *icon_view;
7419 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7421 if (!GTK_IS_ICON_VIEW (item->widget))
7424 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7427 buffer = item->text_buffer;
7429 if (!gtk_text_buffer_get_char_count (buffer))
7433 return g_strdup ("");
7435 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7439 switch (boundary_type)
7441 case ATK_TEXT_BOUNDARY_CHAR:
7442 gtk_text_iter_backward_char(&start);
7444 case ATK_TEXT_BOUNDARY_WORD_START:
7445 if (!gtk_text_iter_starts_word (&start))
7446 gtk_text_iter_backward_word_start (&start);
7448 gtk_text_iter_backward_word_start(&start);
7450 case ATK_TEXT_BOUNDARY_WORD_END:
7451 if (gtk_text_iter_inside_word (&start) &&
7452 !gtk_text_iter_starts_word (&start))
7453 gtk_text_iter_backward_word_start (&start);
7454 while (!gtk_text_iter_ends_word (&start))
7456 if (!gtk_text_iter_backward_char (&start))
7460 gtk_text_iter_backward_word_start(&start);
7461 while (!gtk_text_iter_ends_word (&start))
7463 if (!gtk_text_iter_backward_char (&start))
7467 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7468 if (!gtk_text_iter_starts_sentence (&start))
7469 gtk_text_iter_backward_sentence_start (&start);
7471 gtk_text_iter_backward_sentence_start (&start);
7473 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7474 if (gtk_text_iter_inside_sentence (&start) &&
7475 !gtk_text_iter_starts_sentence (&start))
7476 gtk_text_iter_backward_sentence_start (&start);
7477 while (!gtk_text_iter_ends_sentence (&start))
7479 if (!gtk_text_iter_backward_char (&start))
7483 gtk_text_iter_backward_sentence_start (&start);
7484 while (!gtk_text_iter_ends_sentence (&start))
7486 if (!gtk_text_iter_backward_char (&start))
7490 case ATK_TEXT_BOUNDARY_LINE_START:
7491 case ATK_TEXT_BOUNDARY_LINE_END:
7493 icon_view = GTK_ICON_VIEW (item->widget);
7494 /* FIXME we probably have to use GailTextCell to salvage this */
7495 gtk_icon_view_update_item_text (icon_view, item->item);
7496 get_pango_text_offsets (icon_view->priv->layout,
7509 *start_offset = gtk_text_iter_get_offset (&start);
7510 *end_offset = gtk_text_iter_get_offset (&end);
7512 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7516 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7518 AtkTextBoundary boundary_type,
7522 GtkIconViewItemAccessible *item;
7523 GtkTextIter start, end;
7524 GtkTextBuffer *buffer;
7526 GtkIconView *icon_view;
7529 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7531 if (!GTK_IS_ICON_VIEW (item->widget))
7534 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7537 buffer = item->text_buffer;
7539 if (!gtk_text_buffer_get_char_count (buffer))
7543 return g_strdup ("");
7545 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7549 switch (boundary_type)
7551 case ATK_TEXT_BOUNDARY_CHAR:
7552 gtk_text_iter_forward_char (&end);
7554 case ATK_TEXT_BOUNDARY_WORD_START:
7555 if (!gtk_text_iter_starts_word (&start))
7556 gtk_text_iter_backward_word_start (&start);
7557 if (gtk_text_iter_inside_word (&end))
7558 gtk_text_iter_forward_word_end (&end);
7559 while (!gtk_text_iter_starts_word (&end))
7561 if (!gtk_text_iter_forward_char (&end))
7565 case ATK_TEXT_BOUNDARY_WORD_END:
7566 if (gtk_text_iter_inside_word (&start) &&
7567 !gtk_text_iter_starts_word (&start))
7568 gtk_text_iter_backward_word_start (&start);
7569 while (!gtk_text_iter_ends_word (&start))
7571 if (!gtk_text_iter_backward_char (&start))
7574 gtk_text_iter_forward_word_end (&end);
7576 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7577 if (!gtk_text_iter_starts_sentence (&start))
7578 gtk_text_iter_backward_sentence_start (&start);
7579 if (gtk_text_iter_inside_sentence (&end))
7580 gtk_text_iter_forward_sentence_end (&end);
7581 while (!gtk_text_iter_starts_sentence (&end))
7583 if (!gtk_text_iter_forward_char (&end))
7587 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7588 if (gtk_text_iter_inside_sentence (&start) &&
7589 !gtk_text_iter_starts_sentence (&start))
7590 gtk_text_iter_backward_sentence_start (&start);
7591 while (!gtk_text_iter_ends_sentence (&start))
7593 if (!gtk_text_iter_backward_char (&start))
7596 gtk_text_iter_forward_sentence_end (&end);
7598 case ATK_TEXT_BOUNDARY_LINE_START:
7599 case ATK_TEXT_BOUNDARY_LINE_END:
7601 icon_view = GTK_ICON_VIEW (item->widget);
7602 /* FIXME we probably have to use GailTextCell to salvage this */
7603 gtk_icon_view_update_item_text (icon_view, item->item);
7604 get_pango_text_offsets (icon_view->priv->layout,
7618 *start_offset = gtk_text_iter_get_offset (&start);
7619 *end_offset = gtk_text_iter_get_offset (&end);
7621 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7625 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7627 AtkTextBoundary boundary_type,
7631 GtkIconViewItemAccessible *item;
7632 GtkTextIter start, end;
7633 GtkTextBuffer *buffer;
7635 GtkIconView *icon_view;
7638 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7640 if (!GTK_IS_ICON_VIEW (item->widget))
7643 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7646 buffer = item->text_buffer;
7648 if (!gtk_text_buffer_get_char_count (buffer))
7652 return g_strdup ("");
7654 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7658 switch (boundary_type)
7660 case ATK_TEXT_BOUNDARY_CHAR:
7661 gtk_text_iter_forward_char(&start);
7662 gtk_text_iter_forward_chars(&end, 2);
7664 case ATK_TEXT_BOUNDARY_WORD_START:
7665 if (gtk_text_iter_inside_word (&end))
7666 gtk_text_iter_forward_word_end (&end);
7667 while (!gtk_text_iter_starts_word (&end))
7669 if (!gtk_text_iter_forward_char (&end))
7673 if (!gtk_text_iter_is_end (&end))
7675 gtk_text_iter_forward_word_end (&end);
7676 while (!gtk_text_iter_starts_word (&end))
7678 if (!gtk_text_iter_forward_char (&end))
7683 case ATK_TEXT_BOUNDARY_WORD_END:
7684 gtk_text_iter_forward_word_end (&end);
7686 if (!gtk_text_iter_is_end (&end))
7687 gtk_text_iter_forward_word_end (&end);
7689 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7690 if (gtk_text_iter_inside_sentence (&end))
7691 gtk_text_iter_forward_sentence_end (&end);
7692 while (!gtk_text_iter_starts_sentence (&end))
7694 if (!gtk_text_iter_forward_char (&end))
7698 if (!gtk_text_iter_is_end (&end))
7700 gtk_text_iter_forward_sentence_end (&end);
7701 while (!gtk_text_iter_starts_sentence (&end))
7703 if (!gtk_text_iter_forward_char (&end))
7708 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7709 gtk_text_iter_forward_sentence_end (&end);
7711 if (!gtk_text_iter_is_end (&end))
7712 gtk_text_iter_forward_sentence_end (&end);
7714 case ATK_TEXT_BOUNDARY_LINE_START:
7715 case ATK_TEXT_BOUNDARY_LINE_END:
7717 icon_view = GTK_ICON_VIEW (item->widget);
7718 /* FIXME we probably have to use GailTextCell to salvage this */
7719 gtk_icon_view_update_item_text (icon_view, item->item);
7720 get_pango_text_offsets (icon_view->priv->layout,
7732 *start_offset = gtk_text_iter_get_offset (&start);
7733 *end_offset = gtk_text_iter_get_offset (&end);
7735 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7739 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7741 GtkIconViewItemAccessible *item;
7743 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7745 if (!GTK_IS_ICON_VIEW (item->widget))
7748 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7751 return gtk_text_buffer_get_char_count (item->text_buffer);
7755 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7761 AtkCoordType coord_type)
7763 GtkIconViewItemAccessible *item;
7765 GtkIconView *icon_view;
7766 PangoRectangle char_rect;
7767 const gchar *item_text;
7771 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7773 if (!GTK_IS_ICON_VIEW (item->widget))
7776 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7780 icon_view = GTK_ICON_VIEW (item->widget);
7781 /* FIXME we probably have to use GailTextCell to salvage this */
7782 gtk_icon_view_update_item_text (icon_view, item->item);
7783 item_text = pango_layout_get_text (icon_view->priv->layout);
7784 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7785 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7787 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7788 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7789 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7790 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7791 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7792 *width = char_rect.width / PANGO_SCALE;
7793 *height = char_rect.height / PANGO_SCALE;
7798 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7801 AtkCoordType coord_type)
7803 GtkIconViewItemAccessible *item;
7806 GtkIconView *icon_view;
7807 const gchar *item_text;
7812 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7814 if (!GTK_IS_ICON_VIEW (item->widget))
7817 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7821 icon_view = GTK_ICON_VIEW (item->widget);
7822 /* FIXME we probably have to use GailTextCell to salvage this */
7823 gtk_icon_view_update_item_text (icon_view, item->item);
7824 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7825 x -= l_x + item->item->layout_x - item->item->x;
7826 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7827 y -= l_y + item->item->layout_y - item->item->y;
7828 item_text = pango_layout_get_text (icon_view->priv->layout);
7829 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7840 offset = g_utf8_strlen (item_text, -1);
7842 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7848 atk_text_item_interface_init (AtkTextIface *iface)
7850 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7851 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7852 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7853 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7854 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7855 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7856 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7857 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7861 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7866 AtkCoordType coord_type)
7868 GtkIconViewItemAccessible *item;
7869 AtkObject *parent_obj;
7872 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7874 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7875 if (!GTK_IS_WIDGET (item->widget))
7878 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7881 *width = item->item->width;
7882 *height = item->item->height;
7883 if (gtk_icon_view_item_accessible_is_showing (item))
7885 parent_obj = gtk_widget_get_accessible (item->widget);
7886 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7887 *x = l_x + item->item->x;
7888 *y = l_y + item->item->y;
7898 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7900 GtkIconViewItemAccessible *item;
7901 GtkWidget *toplevel;
7903 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7905 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7906 if (!GTK_IS_WIDGET (item->widget))
7909 gtk_widget_grab_focus (item->widget);
7910 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
7911 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7912 if (GTK_WIDGET_TOPLEVEL (toplevel))
7913 gtk_window_present (GTK_WINDOW (toplevel));
7919 atk_component_item_interface_init (AtkComponentIface *iface)
7921 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7922 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7926 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7927 AtkStateType state_type,
7928 gboolean emit_signal)
7932 rc = atk_state_set_add_state (item->state_set, state_type);
7934 * The signal should only be generated if the value changed,
7935 * not when the item is set up. So states that are set
7936 * initially should pass FALSE as the emit_signal argument.
7941 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7942 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7943 if (state_type == ATK_STATE_VISIBLE)
7944 g_signal_emit_by_name (item, "visible_data_changed");
7951 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7952 AtkStateType state_type,
7953 gboolean emit_signal)
7955 if (atk_state_set_contains_state (item->state_set, state_type))
7959 rc = atk_state_set_remove_state (item->state_set, state_type);
7961 * The signal should only be generated if the value changed,
7962 * not when the item is set up. So states that are set
7963 * initially should pass FALSE as the emit_signal argument.
7968 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7969 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7970 if (state_type == ATK_STATE_VISIBLE)
7971 g_signal_emit_by_name (item, "visible_data_changed");
7981 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7983 GtkIconView *icon_view;
7984 GdkRectangle visible_rect;
7985 gboolean is_showing;
7988 * An item is considered "SHOWING" if any part of the item is in the
7989 * visible rectangle.
7992 if (!GTK_IS_ICON_VIEW (item->widget))
7995 if (item->item == NULL)
7998 icon_view = GTK_ICON_VIEW (item->widget);
8000 if (icon_view->priv->hadjustment)
8001 visible_rect.x += icon_view->priv->hadjustment->value;
8003 if (icon_view->priv->hadjustment)
8004 visible_rect.y += icon_view->priv->vadjustment->value;
8005 visible_rect.width = item->widget->allocation.width;
8006 visible_rect.height = item->widget->allocation.height;
8008 if (((item->item->x + item->item->width) < visible_rect.x) ||
8009 ((item->item->y + item->item->height) < (visible_rect.y)) ||
8010 (item->item->x > (visible_rect.x + visible_rect.width)) ||
8011 (item->item->y > (visible_rect.y + visible_rect.height)))
8020 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
8021 gboolean emit_signal)
8023 if (gtk_icon_view_item_accessible_is_showing (item))
8024 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
8027 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
8032 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
8036 item->state_set = atk_state_set_new ();
8038 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
8039 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
8040 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
8041 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
8042 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
8044 for (i = 0; i < LAST_ACTION; i++)
8045 item->action_descriptions[i] = NULL;
8047 item->image_description = NULL;
8049 item->action_idle_handler = 0;
8053 gtk_icon_view_item_accessible_finalize (GObject *object)
8055 GtkIconViewItemAccessible *item;
8058 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8060 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8063 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8065 if (item->state_set)
8066 g_object_unref (item->state_set);
8068 if (item->text_buffer)
8069 g_object_unref (item->text_buffer);
8071 for (i = 0; i < LAST_ACTION; i++)
8072 g_free (item->action_descriptions[i]);
8074 g_free (item->image_description);
8076 if (item->action_idle_handler)
8078 g_source_remove (item->action_idle_handler);
8079 item->action_idle_handler = 0;
8082 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8085 static G_CONST_RETURN gchar*
8086 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8092 GtkIconViewItemAccessible *item;
8093 GtkTextIter start_iter;
8094 GtkTextIter end_iter;
8096 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8098 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8099 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8101 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8106 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8108 GtkIconViewItemAccessible *item;
8110 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8111 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8114 return gtk_widget_get_accessible (item->widget);
8120 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8122 GtkIconViewItemAccessible *item;
8124 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8125 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8127 return item->item->index;
8130 static AtkStateSet *
8131 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8133 GtkIconViewItemAccessible *item;
8134 GtkIconView *icon_view;
8136 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8137 g_return_val_if_fail (item->state_set, NULL);
8142 icon_view = GTK_ICON_VIEW (item->widget);
8143 if (icon_view->priv->cursor_item == item->item)
8144 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8146 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8148 return g_object_ref (item->state_set);
8152 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8154 GObjectClass *gobject_class;
8156 accessible_item_parent_class = g_type_class_peek_parent (klass);
8158 gobject_class = (GObjectClass *)klass;
8160 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8162 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8163 klass->get_name = gtk_icon_view_item_accessible_get_name;
8164 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8165 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8169 gtk_icon_view_item_accessible_get_type (void)
8171 static GType type = 0;
8175 const GTypeInfo tinfo =
8177 sizeof (GtkIconViewItemAccessibleClass),
8178 (GBaseInitFunc) NULL, /* base init */
8179 (GBaseFinalizeFunc) NULL, /* base finalize */
8180 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8181 (GClassFinalizeFunc) NULL, /* class finalize */
8182 NULL, /* class data */
8183 sizeof (GtkIconViewItemAccessible), /* instance size */
8184 0, /* nb preallocs */
8185 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8186 NULL /* value table */
8189 static const GInterfaceInfo atk_component_info =
8191 (GInterfaceInitFunc) atk_component_item_interface_init,
8192 (GInterfaceFinalizeFunc) NULL,
8195 static const GInterfaceInfo atk_action_info =
8197 (GInterfaceInitFunc) atk_action_item_interface_init,
8198 (GInterfaceFinalizeFunc) NULL,
8201 static const GInterfaceInfo atk_image_info =
8203 (GInterfaceInitFunc) atk_image_item_interface_init,
8204 (GInterfaceFinalizeFunc) NULL,
8207 static const GInterfaceInfo atk_text_info =
8209 (GInterfaceInitFunc) atk_text_item_interface_init,
8210 (GInterfaceFinalizeFunc) NULL,
8214 type = g_type_register_static (ATK_TYPE_OBJECT,
8215 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8216 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8217 &atk_component_info);
8218 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8220 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8222 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8229 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8230 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8231 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8233 static GType gtk_icon_view_accessible_get_type (void);
8238 } GtkIconViewAccessible;
8244 } GtkIconViewItemAccessibleInfo;
8250 GtkAdjustment *old_hadj;
8251 GtkAdjustment *old_vadj;
8253 GtkTreeModel *model;
8255 } GtkIconViewAccessiblePrivate;
8257 static GtkIconViewAccessiblePrivate *
8258 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8260 return g_object_get_qdata (G_OBJECT (accessible),
8261 accessible_private_data_quark);
8265 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8269 GtkIconViewItemAccessibleInfo *info;
8270 GtkIconViewItemAccessibleInfo *tmp_info;
8271 GtkIconViewAccessiblePrivate *priv;
8274 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8276 info->index = index;
8278 priv = gtk_icon_view_accessible_get_priv (accessible);
8279 items = priv->items;
8282 tmp_info = items->data;
8283 if (tmp_info->index > index)
8285 items = items->next;
8287 priv->items = g_list_insert_before (priv->items, items, info);
8288 priv->old_hadj = NULL;
8289 priv->old_vadj = NULL;
8293 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8295 GtkIconView *icon_view;
8298 widget = GTK_ACCESSIBLE (accessible)->widget;
8302 icon_view = GTK_ICON_VIEW (widget);
8304 return g_list_length (icon_view->priv->items);
8308 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8311 GtkIconViewAccessiblePrivate *priv;
8312 GtkIconViewItemAccessibleInfo *info;
8315 priv = gtk_icon_view_accessible_get_priv (accessible);
8316 items = priv->items;
8321 if (info->index == index)
8323 items = items->next;
8329 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8332 GtkIconView *icon_view;
8336 GtkIconViewItemAccessible *a11y_item;
8338 widget = GTK_ACCESSIBLE (accessible)->widget;
8342 icon_view = GTK_ICON_VIEW (widget);
8343 icons = g_list_nth (icon_view->priv->items, index);
8347 GtkIconViewItem *item = icons->data;
8349 g_return_val_if_fail (item->index == index, NULL);
8350 obj = gtk_icon_view_accessible_find_child (accessible, index);
8355 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8356 gtk_icon_view_item_accessible_info_new (accessible,
8359 obj->role = ATK_ROLE_ICON;
8360 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8361 a11y_item->item = item;
8362 a11y_item->widget = widget;
8363 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8365 gtk_icon_view_set_cell_data (icon_view, item);
8366 text = get_text (icon_view, item);
8369 gtk_text_buffer_set_text (a11y_item->text_buffer, text, -1);
8373 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8374 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8382 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8385 GtkIconViewAccessiblePrivate *priv;
8386 GtkIconViewItemAccessibleInfo *info;
8387 GtkIconViewItemAccessible *item;
8390 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8394 gboolean act_on_item;
8396 widget = GTK_ACCESSIBLE (view)->widget;
8400 items = priv->items;
8402 act_on_item = (list == NULL);
8407 info = (GtkIconViewItemAccessibleInfo *)items->data;
8408 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8410 if (act_on_item == FALSE && list == items)
8414 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8416 items = items->next;
8422 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8423 GtkIconView *icon_view)
8426 GtkIconViewAccessible *view;
8429 * The scrollbars have changed
8431 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8432 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8434 gtk_icon_view_accessible_traverse_items (view, NULL);
8438 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8439 GtkAdjustment *hadj,
8440 GtkAdjustment *vadj)
8443 GtkIconViewAccessiblePrivate *priv;
8445 atk_obj = gtk_widget_get_accessible (widget);
8446 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8448 if (priv->old_hadj != hadj)
8452 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8453 (gpointer *)&priv->old_hadj);
8455 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8456 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8459 priv->old_hadj = hadj;
8462 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8463 (gpointer *)&priv->old_hadj);
8464 g_signal_connect (hadj,
8466 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8470 if (priv->old_vadj != vadj)
8474 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8475 (gpointer *)&priv->old_vadj);
8477 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8478 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8481 priv->old_vadj = vadj;
8484 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8485 (gpointer *)&priv->old_vadj);
8486 g_signal_connect (vadj,
8488 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8495 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8502 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8503 g_signal_emit_by_name (atk_obj, "visible_data_changed");
8509 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8514 GtkIconViewAccessiblePrivate *priv;
8515 GtkIconViewItemAccessibleInfo *info;
8516 GtkIconViewAccessible *view;
8517 GtkIconViewItemAccessible *item;
8523 index = gtk_tree_path_get_indices(path)[0];
8524 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8525 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8526 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8528 items = priv->items;
8533 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8534 if (info->index != item->item->index)
8536 if (info->index < index)
8537 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8539 if (tmp_list == NULL)
8542 info->index = item->item->index;
8545 items = items->next;
8547 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8548 g_signal_emit_by_name (atk_obj, "children_changed::add",
8554 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8558 GtkIconViewAccessiblePrivate *priv;
8559 GtkIconViewItemAccessibleInfo *info;
8560 GtkIconViewAccessible *view;
8561 GtkIconViewItemAccessible *item;
8564 GList *deleted_item;
8568 index = gtk_tree_path_get_indices(path)[0];
8569 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8570 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8571 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8573 items = priv->items;
8575 deleted_item = NULL;
8580 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8581 if (info->index == index)
8583 deleted_item = items;
8585 if (info->index != item->item->index)
8587 if (tmp_list == NULL)
8590 info->index = item->item->index;
8593 items = items->next;
8595 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8598 info = deleted_item->data;
8599 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8601 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8605 priv->items = g_list_remove_link (priv->items, deleted_item);
8613 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8614 GtkIconViewItemAccessibleInfo *i2)
8616 return i1->index - i2->index;
8620 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8626 GtkIconViewAccessiblePrivate *priv;
8627 GtkIconViewItemAccessibleInfo *info;
8628 GtkIconView *icon_view;
8629 GtkIconViewItemAccessible *item;
8633 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8634 icon_view = GTK_ICON_VIEW (user_data);
8635 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8637 items = priv->items;
8641 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8642 info->index = new_order[info->index];
8643 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8644 items = items->next;
8646 priv->items = g_list_sort (priv->items,
8647 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8653 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8658 obj = G_OBJECT (model);
8659 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8660 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8661 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8662 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8666 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8670 obj = G_OBJECT (icon_view->priv->model);
8671 g_signal_connect_data (obj, "row_changed",
8672 (GCallback) gtk_icon_view_accessible_model_row_changed,
8673 icon_view, NULL, 0);
8674 g_signal_connect_data (obj, "row_inserted",
8675 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8676 icon_view, NULL, G_CONNECT_AFTER);
8677 g_signal_connect_data (obj, "row_deleted",
8678 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8679 icon_view, NULL, G_CONNECT_AFTER);
8680 g_signal_connect_data (obj, "rows_reordered",
8681 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8682 icon_view, NULL, G_CONNECT_AFTER);
8686 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8688 GtkIconViewItemAccessibleInfo *info;
8691 items = priv->items;
8694 info = (GtkIconViewItemAccessibleInfo *) items->data;
8695 g_object_unref (info->item);
8696 g_free (items->data);
8697 items = items->next;
8699 g_list_free (priv->items);
8704 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8707 GtkIconView *icon_view;
8710 GtkIconViewAccessiblePrivate *priv;
8712 if (strcmp (pspec->name, "model") == 0)
8714 widget = GTK_WIDGET (obj);
8715 atk_obj = gtk_widget_get_accessible (widget);
8716 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8719 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8720 (gpointer *)&priv->model);
8721 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8723 gtk_icon_view_accessible_clear_cache (priv);
8725 icon_view = GTK_ICON_VIEW (obj);
8726 priv->model = icon_view->priv->model;
8727 /* If there is no model the GtkIconView is probably being destroyed */
8730 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8731 gtk_icon_view_accessible_connect_model_signals (icon_view);
8739 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8742 GtkIconViewAccessiblePrivate *priv;
8743 GtkIconView *icon_view;
8745 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8746 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8748 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8749 g_object_set_qdata (G_OBJECT (accessible),
8750 accessible_private_data_quark,
8753 icon_view = GTK_ICON_VIEW (data);
8754 if (icon_view->priv->hadjustment)
8756 priv->old_hadj = icon_view->priv->hadjustment;
8757 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
8758 g_signal_connect (icon_view->priv->hadjustment,
8760 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8763 if (icon_view->priv->vadjustment)
8765 priv->old_vadj = icon_view->priv->vadjustment;
8766 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
8767 g_signal_connect (icon_view->priv->vadjustment,
8769 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8772 g_signal_connect_after (data,
8773 "set_scroll_adjustments",
8774 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
8776 g_signal_connect (data,
8778 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8781 priv->model = icon_view->priv->model;
8784 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8785 gtk_icon_view_accessible_connect_model_signals (icon_view);
8788 accessible->role = ATK_ROLE_LAYERED_PANE;
8792 gtk_icon_view_accessible_finalize (GObject *object)
8794 GtkIconViewAccessiblePrivate *priv;
8796 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8797 gtk_icon_view_accessible_clear_cache (priv);
8801 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8805 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8806 GtkAccessible *accessible)
8809 GtkIconViewAccessiblePrivate *priv;
8811 atk_obj = ATK_OBJECT (accessible);
8812 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8815 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8816 (gpointer *)&priv->old_hadj);
8818 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8819 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8821 priv->old_hadj = NULL;
8825 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8826 (gpointer *)&priv->old_vadj);
8828 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8829 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8831 priv->old_vadj = NULL;
8836 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8838 if (accessible->widget)
8840 g_signal_connect_after (accessible->widget,
8842 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8845 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8849 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8851 GObjectClass *gobject_class;
8852 GtkAccessibleClass *accessible_class;
8854 accessible_parent_class = g_type_class_peek_parent (klass);
8856 gobject_class = (GObjectClass *)klass;
8857 accessible_class = (GtkAccessibleClass *)klass;
8859 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8861 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8862 klass->ref_child = gtk_icon_view_accessible_ref_child;
8863 klass->initialize = gtk_icon_view_accessible_initialize;
8865 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8867 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8871 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8874 AtkCoordType coord_type)
8877 GtkIconView *icon_view;
8878 GtkIconViewItem *item;
8881 widget = GTK_ACCESSIBLE (component)->widget;
8883 /* State is defunct */
8886 icon_view = GTK_ICON_VIEW (widget);
8887 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8888 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8890 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8896 atk_component_interface_init (AtkComponentIface *iface)
8898 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8902 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8906 GtkIconView *icon_view;
8907 GtkIconViewItem *item;
8909 widget = GTK_ACCESSIBLE (selection)->widget;
8913 icon_view = GTK_ICON_VIEW (widget);
8915 item = g_list_nth_data (icon_view->priv->items, i);
8920 gtk_icon_view_select_item (icon_view, item);
8926 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8929 GtkIconView *icon_view;
8931 widget = GTK_ACCESSIBLE (selection)->widget;
8935 icon_view = GTK_ICON_VIEW (widget);
8936 gtk_icon_view_unselect_all (icon_view);
8942 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8947 GtkIconView *icon_view;
8948 GtkIconViewItem *item;
8950 widget = GTK_ACCESSIBLE (selection)->widget;
8954 icon_view = GTK_ICON_VIEW (widget);
8956 l = icon_view->priv->items;
8963 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8974 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8977 GtkIconView *icon_view;
8978 GtkIconViewItem *item;
8982 widget = GTK_ACCESSIBLE (selection)->widget;
8986 icon_view = GTK_ICON_VIEW (widget);
8988 l = icon_view->priv->items;
9004 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
9008 GtkIconView *icon_view;
9009 GtkIconViewItem *item;
9011 widget = GTK_ACCESSIBLE (selection)->widget;
9015 icon_view = GTK_ICON_VIEW (widget);
9017 item = g_list_nth_data (icon_view->priv->items, i);
9021 return item->selected;
9025 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
9029 GtkIconView *icon_view;
9030 GtkIconViewItem *item;
9034 widget = GTK_ACCESSIBLE (selection)->widget;
9038 icon_view = GTK_ICON_VIEW (widget);
9039 l = icon_view->priv->items;
9048 gtk_icon_view_unselect_item (icon_view, item);
9060 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9063 GtkIconView *icon_view;
9065 widget = GTK_ACCESSIBLE (selection)->widget;
9069 icon_view = GTK_ICON_VIEW (widget);
9070 gtk_icon_view_select_all (icon_view);
9075 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9077 iface->add_selection = gtk_icon_view_accessible_add_selection;
9078 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9079 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9080 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9081 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9082 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9083 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9087 gtk_icon_view_accessible_get_type (void)
9089 static GType type = 0;
9093 static GTypeInfo tinfo =
9096 (GBaseInitFunc) NULL, /* base init */
9097 (GBaseFinalizeFunc) NULL, /* base finalize */
9098 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9099 (GClassFinalizeFunc) NULL, /* class finalize */
9100 NULL, /* class data */
9101 0, /* instance size */
9102 0, /* nb preallocs */
9103 (GInstanceInitFunc) NULL, /* instance init */
9104 NULL /* value table */
9106 static const GInterfaceInfo atk_component_info =
9108 (GInterfaceInitFunc) atk_component_interface_init,
9109 (GInterfaceFinalizeFunc) NULL,
9112 static const GInterfaceInfo atk_selection_info =
9114 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9115 (GInterfaceFinalizeFunc) NULL,
9120 * Figure out the size of the class and instance
9121 * we are deriving from
9123 AtkObjectFactory *factory;
9126 GType derived_atk_type;
9128 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9129 factory = atk_registry_get_factory (atk_get_default_registry (),
9131 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9132 g_type_query (derived_atk_type, &query);
9133 tinfo.class_size = query.class_size;
9134 tinfo.instance_size = query.instance_size;
9136 type = g_type_register_static (derived_atk_type,
9137 I_("GtkIconViewAccessible"),
9139 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9140 &atk_component_info);
9141 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9142 &atk_selection_info);
9148 gtk_icon_view_accessible_new (GObject *obj)
9150 AtkObject *accessible;
9152 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9154 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9155 atk_object_initialize (accessible, obj);
9161 gtk_icon_view_accessible_factory_get_accessible_type (void)
9163 return gtk_icon_view_accessible_get_type ();
9167 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9169 return gtk_icon_view_accessible_new (obj);
9173 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9175 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9176 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9180 gtk_icon_view_accessible_factory_get_type (void)
9182 static GType type = 0;
9186 const GTypeInfo tinfo =
9188 sizeof (AtkObjectFactoryClass),
9189 NULL, /* base_init */
9190 NULL, /* base_finalize */
9191 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9192 NULL, /* class_finalize */
9193 NULL, /* class_data */
9194 sizeof (AtkObjectFactory),
9195 0, /* n_preallocs */
9199 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9200 I_("GtkIconViewAccessibleFactory"),
9208 gtk_icon_view_get_accessible (GtkWidget *widget)
9210 static gboolean first_time = TRUE;
9214 AtkObjectFactory *factory;
9215 AtkRegistry *registry;
9217 GType derived_atk_type;
9220 * Figure out whether accessibility is enabled by looking at the
9221 * type of the accessible object which would be created for
9222 * the parent type of GtkIconView.
9224 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9226 registry = atk_get_default_registry ();
9227 factory = atk_registry_get_factory (registry,
9229 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9230 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9231 atk_registry_set_factory_type (registry,
9233 gtk_icon_view_accessible_factory_get_type ());
9236 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9239 #define __GTK_ICON_VIEW_C__
9240 #include "gtkaliasdef.c"