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 AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
261 /* GtkContainer vfuncs */
262 static void gtk_icon_view_remove (GtkContainer *container,
264 static void gtk_icon_view_forall (GtkContainer *container,
265 gboolean include_internals,
266 GtkCallback callback,
267 gpointer callback_data);
269 /* GtkIconView vfuncs */
270 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
272 GtkAdjustment *vadj);
273 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
274 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
275 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
276 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
277 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
279 /* Internal functions */
280 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
281 GtkIconView *icon_view);
282 static void gtk_icon_view_layout (GtkIconView *icon_view);
283 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
286 GtkIconViewItem *item,
288 GdkDrawable *drawable,
291 gboolean draw_focus);
292 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
295 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
297 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
298 GtkIconViewItem *item);
299 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
300 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
301 GtkIconViewItem *item,
303 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
306 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
307 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
308 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
309 GtkIconViewItem *item,
314 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
315 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
316 GtkIconViewItem *item);
317 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
318 GtkIconViewItem *item,
320 static void gtk_icon_view_update_rubberband (gpointer data);
321 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
322 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
323 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
326 GtkMovementStep step,
328 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
329 GtkMovementStep step,
331 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
333 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
335 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
337 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
339 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
340 GtkIconViewItem *item);
341 static void gtk_icon_view_select_item (GtkIconView *icon_view,
342 GtkIconViewItem *item);
343 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
344 GtkIconViewItem *item);
345 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
346 GtkIconViewItem *anchor,
347 GtkIconViewItem *cursor);
348 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
351 gboolean only_in_cell,
352 GtkIconViewCellInfo **cell_at_pos);
353 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
354 GtkIconViewItem *item,
355 GtkIconViewCellInfo *cell_info,
356 GdkRectangle *cell_area);
357 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
358 GtkIconViewItem *item,
359 GtkIconViewCellInfo *info,
361 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
362 GtkCellRenderer *renderer);
363 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
364 GtkIconViewItem *item);
365 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
366 GtkCellRenderer *renderer,
368 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
369 GtkCellRenderer *renderer,
371 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
372 GtkCellRenderer *renderer,
373 const gchar *attribute,
375 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
376 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
377 GtkCellRenderer *renderer);
378 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
379 GtkCellRenderer *cell,
380 GtkCellLayoutDataFunc func,
382 GDestroyNotify destroy);
383 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
384 GtkCellRenderer *cell,
386 static GList * gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout);
388 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
389 GtkIconViewItem *item,
390 GtkIconViewCellInfo *cell_info,
392 static void gtk_icon_view_put (GtkIconView *icon_view,
394 GtkIconViewItem *item,
396 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
397 GtkIconView *icon_view);
398 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
399 GtkIconViewItem *item,
400 GtkIconViewCellInfo *cell_info,
402 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
403 gboolean cancel_editing);
405 /* Source side drag signals */
406 static void gtk_icon_view_drag_begin (GtkWidget *widget,
407 GdkDragContext *context);
408 static void gtk_icon_view_drag_end (GtkWidget *widget,
409 GdkDragContext *context);
410 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
411 GdkDragContext *context,
412 GtkSelectionData *selection_data,
415 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
416 GdkDragContext *context);
418 /* Target side drag signals */
419 static void gtk_icon_view_drag_leave (GtkWidget *widget,
420 GdkDragContext *context,
422 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
423 GdkDragContext *context,
427 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
428 GdkDragContext *context,
432 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
433 GdkDragContext *context,
436 GtkSelectionData *selection_data,
439 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
440 GdkEventMotion *event);
442 static void remove_scroll_timeout (GtkIconView *icon_view);
443 static void clear_dest_info (GtkIconView *icon_view);
444 static void clear_source_info (GtkIconView *icon_view);
447 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
449 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
450 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
451 gtk_icon_view_cell_layout_init))
454 gtk_icon_view_class_init (GtkIconViewClass *klass)
456 GObjectClass *gobject_class;
457 GtkObjectClass *object_class;
458 GtkWidgetClass *widget_class;
459 GtkContainerClass *container_class;
460 GtkBindingSet *binding_set;
462 binding_set = gtk_binding_set_by_class (klass);
464 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
466 gobject_class = (GObjectClass *) klass;
467 object_class = (GtkObjectClass *) klass;
468 widget_class = (GtkWidgetClass *) klass;
469 container_class = (GtkContainerClass *) klass;
471 gobject_class->finalize = gtk_icon_view_finalize;
472 gobject_class->set_property = gtk_icon_view_set_property;
473 gobject_class->get_property = gtk_icon_view_get_property;
475 object_class->destroy = gtk_icon_view_destroy;
477 widget_class->realize = gtk_icon_view_realize;
478 widget_class->unrealize = gtk_icon_view_unrealize;
479 widget_class->style_set = gtk_icon_view_style_set;
480 widget_class->get_accessible = gtk_icon_view_get_accessible;
481 widget_class->size_request = gtk_icon_view_size_request;
482 widget_class->size_allocate = gtk_icon_view_size_allocate;
483 widget_class->expose_event = gtk_icon_view_expose;
484 widget_class->motion_notify_event = gtk_icon_view_motion;
485 widget_class->button_press_event = gtk_icon_view_button_press;
486 widget_class->button_release_event = gtk_icon_view_button_release;
487 widget_class->drag_begin = gtk_icon_view_drag_begin;
488 widget_class->drag_end = gtk_icon_view_drag_end;
489 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
490 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
491 widget_class->drag_leave = gtk_icon_view_drag_leave;
492 widget_class->drag_motion = gtk_icon_view_drag_motion;
493 widget_class->drag_drop = gtk_icon_view_drag_drop;
494 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
495 widget_class->state_changed = gtk_icon_view_state_changed;
497 container_class->remove = gtk_icon_view_remove;
498 container_class->forall = gtk_icon_view_forall;
500 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
501 klass->select_all = gtk_icon_view_real_select_all;
502 klass->unselect_all = gtk_icon_view_real_unselect_all;
503 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
504 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
505 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
506 klass->move_cursor = gtk_icon_view_real_move_cursor;
510 * GtkIconView:selection-mode:
512 * The ::selection-mode property specifies the selection mode of
513 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
514 * is enabled, for the other modes, only keyboard selection is possible.
518 g_object_class_install_property (gobject_class,
520 g_param_spec_enum ("selection-mode",
521 P_("Selection mode"),
522 P_("The selection mode"),
523 GTK_TYPE_SELECTION_MODE,
524 GTK_SELECTION_SINGLE,
525 GTK_PARAM_READWRITE));
528 * GtkIconView:pixbuf-column:
530 * The ::pixbuf-column property contains the number of the model column
531 * containing the pixbufs which are displayed. The pixbuf column must be
532 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
533 * display of pixbufs.
537 g_object_class_install_property (gobject_class,
539 g_param_spec_int ("pixbuf-column",
541 P_("Model column used to retrieve the icon pixbuf from"),
543 GTK_PARAM_READWRITE));
546 * GtkIconView:text-column:
548 * The ::text-column property contains the number of the model column
549 * containing the texts which are displayed. The text column must be
550 * of type #G_TYPE_STRING. If this property and the :markup-column
551 * property are both set to -1, no texts are displayed.
555 g_object_class_install_property (gobject_class,
557 g_param_spec_int ("text-column",
559 P_("Model column used to retrieve the text from"),
561 GTK_PARAM_READWRITE));
565 * GtkIconView:markup-column:
567 * The ::markup-column property contains the number of the model column
568 * containing markup information to be displayed. The markup column must be
569 * of type #G_TYPE_STRING. If this property and the :text-column property
570 * are both set to column numbers, it overrides the text column.
571 * If both are set to -1, no texts are displayed.
575 g_object_class_install_property (gobject_class,
577 g_param_spec_int ("markup-column",
579 P_("Model column used to retrieve the text if using Pango markup"),
581 GTK_PARAM_READWRITE));
583 g_object_class_install_property (gobject_class,
585 g_param_spec_object ("model",
586 P_("Icon View Model"),
587 P_("The model for the icon view"),
589 GTK_PARAM_READWRITE));
592 * GtkIconView:columns:
594 * The columns property contains the number of the columns in which the
595 * items should be displayed. If it is -1, the number of columns will
596 * be chosen automatically to fill the available area.
600 g_object_class_install_property (gobject_class,
602 g_param_spec_int ("columns",
603 P_("Number of columns"),
604 P_("Number of columns to display"),
606 GTK_PARAM_READWRITE));
610 * GtkIconView:item-width:
612 * The item-width property specifies the width to use for each item.
613 * If it is set to -1, the icon view will automatically determine a
614 * suitable item size.
618 g_object_class_install_property (gobject_class,
620 g_param_spec_int ("item-width",
621 P_("Width for each item"),
622 P_("The width used for each item"),
624 GTK_PARAM_READWRITE));
627 * GtkIconView:spacing:
629 * The spacing property specifies the space which is inserted between
630 * the cells (i.e. the icon and the text) of an item.
634 g_object_class_install_property (gobject_class,
636 g_param_spec_int ("spacing",
638 P_("Space which is inserted between cells of an item"),
640 GTK_PARAM_READWRITE));
643 * GtkIconView:row-spacing:
645 * The row-spacing property specifies the space which is inserted between
646 * the rows of the icon view.
650 g_object_class_install_property (gobject_class,
652 g_param_spec_int ("row-spacing",
654 P_("Space which is inserted between grid rows"),
656 GTK_PARAM_READWRITE));
659 * GtkIconView:column-spacing:
661 * The column-spacing property specifies the space which is inserted between
662 * the columns of the icon view.
666 g_object_class_install_property (gobject_class,
668 g_param_spec_int ("column-spacing",
669 P_("Column Spacing"),
670 P_("Space which is inserted between grid columns"),
672 GTK_PARAM_READWRITE));
675 * GtkIconView:margin:
677 * The margin property specifies the space which is inserted
678 * at the edges of the icon view.
682 g_object_class_install_property (gobject_class,
684 g_param_spec_int ("margin",
686 P_("Space which is inserted at the edges of the icon view"),
688 GTK_PARAM_READWRITE));
692 * GtkIconView:orientation:
694 * The orientation property specifies how the cells (i.e. the icon and
695 * the text) of the item are positioned relative to each other.
699 g_object_class_install_property (gobject_class,
701 g_param_spec_enum ("orientation",
703 P_("How the text and icon of each item are positioned relative to each other"),
704 GTK_TYPE_ORIENTATION,
705 GTK_ORIENTATION_VERTICAL,
706 GTK_PARAM_READWRITE));
709 * GtkIconView:reorderable:
711 * The reorderable property specifies if the items can be reordered
716 g_object_class_install_property (gobject_class,
718 g_param_spec_boolean ("reorderable",
720 P_("View is reorderable"),
724 /* Style properties */
725 gtk_widget_class_install_style_property (widget_class,
726 g_param_spec_boxed ("selection-box-color",
727 P_("Selection Box Color"),
728 P_("Color of the selection box"),
730 GTK_PARAM_READABLE));
732 gtk_widget_class_install_style_property (widget_class,
733 g_param_spec_uchar ("selection-box-alpha",
734 P_("Selection Box Alpha"),
735 P_("Opacity of the selection box"),
738 GTK_PARAM_READABLE));
741 widget_class->set_scroll_adjustments_signal =
742 g_signal_new (I_("set_scroll_adjustments"),
743 G_TYPE_FROM_CLASS (gobject_class),
745 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
747 _gtk_marshal_VOID__OBJECT_OBJECT,
749 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
751 icon_view_signals[ITEM_ACTIVATED] =
752 g_signal_new (I_("item_activated"),
753 G_TYPE_FROM_CLASS (gobject_class),
755 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
757 g_cclosure_marshal_VOID__BOXED,
761 icon_view_signals[SELECTION_CHANGED] =
762 g_signal_new (I_("selection-changed"),
763 G_TYPE_FROM_CLASS (gobject_class),
765 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
767 g_cclosure_marshal_VOID__VOID,
770 icon_view_signals[SELECT_ALL] =
771 g_signal_new (I_("select_all"),
772 G_TYPE_FROM_CLASS (gobject_class),
773 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
774 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
776 g_cclosure_marshal_VOID__VOID,
779 icon_view_signals[UNSELECT_ALL] =
780 g_signal_new (I_("unselect_all"),
781 G_TYPE_FROM_CLASS (gobject_class),
782 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
783 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
785 g_cclosure_marshal_VOID__VOID,
788 icon_view_signals[SELECT_CURSOR_ITEM] =
789 g_signal_new (I_("select_cursor_item"),
790 G_TYPE_FROM_CLASS (gobject_class),
791 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
792 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
794 g_cclosure_marshal_VOID__VOID,
797 icon_view_signals[TOGGLE_CURSOR_ITEM] =
798 g_signal_new (I_("toggle_cursor_item"),
799 G_TYPE_FROM_CLASS (gobject_class),
800 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
801 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
803 g_cclosure_marshal_VOID__VOID,
806 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
807 g_signal_new (I_("activate_cursor_item"),
808 G_TYPE_FROM_CLASS (gobject_class),
809 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
810 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
812 _gtk_marshal_BOOLEAN__VOID,
815 icon_view_signals[MOVE_CURSOR] =
816 g_signal_new (I_("move_cursor"),
817 G_TYPE_FROM_CLASS (gobject_class),
818 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
819 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
821 _gtk_marshal_BOOLEAN__ENUM_INT,
823 GTK_TYPE_MOVEMENT_STEP,
827 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
829 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
831 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
832 "toggle_cursor_item", 0);
834 gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
835 "activate_cursor_item", 0);
836 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
837 "activate_cursor_item", 0);
838 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
839 "activate_cursor_item", 0);
840 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
841 "activate_cursor_item", 0);
843 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
844 GTK_MOVEMENT_DISPLAY_LINES, -1);
845 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
846 GTK_MOVEMENT_DISPLAY_LINES, -1);
848 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
849 GTK_MOVEMENT_DISPLAY_LINES, 1);
850 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
851 GTK_MOVEMENT_DISPLAY_LINES, 1);
853 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
854 GTK_MOVEMENT_DISPLAY_LINES, -1);
856 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
857 GTK_MOVEMENT_DISPLAY_LINES, 1);
859 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
860 GTK_MOVEMENT_BUFFER_ENDS, -1);
861 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
862 GTK_MOVEMENT_BUFFER_ENDS, -1);
864 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
865 GTK_MOVEMENT_BUFFER_ENDS, 1);
866 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
867 GTK_MOVEMENT_BUFFER_ENDS, 1);
869 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
870 GTK_MOVEMENT_PAGES, -1);
871 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
872 GTK_MOVEMENT_PAGES, -1);
874 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
875 GTK_MOVEMENT_PAGES, 1);
876 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
877 GTK_MOVEMENT_PAGES, 1);
879 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
880 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
881 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
882 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
884 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
885 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
886 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
887 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
891 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
893 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
894 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
895 iface->clear = gtk_icon_view_cell_layout_clear;
896 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
897 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
898 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
899 iface->reorder = gtk_icon_view_cell_layout_reorder;
900 iface->get_cells = gtk_icon_view_cell_layout_get_cells;
904 gtk_icon_view_init (GtkIconView *icon_view)
906 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
908 icon_view->priv->width = 0;
909 icon_view->priv->height = 0;
910 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
911 icon_view->priv->pressed_button = -1;
912 icon_view->priv->press_start_x = -1;
913 icon_view->priv->press_start_y = -1;
914 icon_view->priv->text_column = -1;
915 icon_view->priv->markup_column = -1;
916 icon_view->priv->pixbuf_column = -1;
917 icon_view->priv->text_cell = -1;
918 icon_view->priv->pixbuf_cell = -1;
920 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
922 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
924 icon_view->priv->cell_list = NULL;
925 icon_view->priv->n_cells = 0;
926 icon_view->priv->cursor_cell = -1;
928 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
930 icon_view->priv->columns = -1;
931 icon_view->priv->item_width = -1;
932 icon_view->priv->spacing = 0;
933 icon_view->priv->row_spacing = 6;
934 icon_view->priv->column_spacing = 6;
935 icon_view->priv->margin = 6;
939 gtk_icon_view_destroy (GtkObject *object)
941 GtkIconView *icon_view;
943 icon_view = GTK_ICON_VIEW (object);
945 gtk_icon_view_stop_editing (icon_view, TRUE);
947 gtk_icon_view_set_model (icon_view, NULL);
949 if (icon_view->priv->layout_idle_id != 0)
951 g_source_remove (icon_view->priv->layout_idle_id);
952 icon_view->priv->layout_idle_id = 0;
955 if (icon_view->priv->scroll_to_path != NULL)
957 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
958 icon_view->priv->scroll_to_path = NULL;
961 remove_scroll_timeout (icon_view);
963 if (icon_view->priv->hadjustment != NULL)
965 g_object_unref (icon_view->priv->hadjustment);
966 icon_view->priv->hadjustment = NULL;
969 if (icon_view->priv->vadjustment != NULL)
971 g_object_unref (icon_view->priv->vadjustment);
972 icon_view->priv->vadjustment = NULL;
975 clear_dest_info (icon_view);
976 clear_source_info (icon_view);
978 (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
981 /* GObject methods */
983 gtk_icon_view_finalize (GObject *object)
985 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
987 (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
992 gtk_icon_view_set_property (GObject *object,
997 GtkIconView *icon_view;
999 icon_view = GTK_ICON_VIEW (object);
1003 case PROP_SELECTION_MODE:
1004 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
1006 case PROP_PIXBUF_COLUMN:
1007 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
1009 case PROP_TEXT_COLUMN:
1010 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
1012 case PROP_MARKUP_COLUMN:
1013 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
1016 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
1018 case PROP_ORIENTATION:
1019 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
1022 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
1024 case PROP_ITEM_WIDTH:
1025 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
1028 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
1030 case PROP_ROW_SPACING:
1031 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1033 case PROP_COLUMN_SPACING:
1034 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1037 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1039 case PROP_REORDERABLE:
1040 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1044 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1050 gtk_icon_view_get_property (GObject *object,
1055 GtkIconView *icon_view;
1057 icon_view = GTK_ICON_VIEW (object);
1061 case PROP_SELECTION_MODE:
1062 g_value_set_enum (value, icon_view->priv->selection_mode);
1064 case PROP_PIXBUF_COLUMN:
1065 g_value_set_int (value, icon_view->priv->pixbuf_column);
1067 case PROP_TEXT_COLUMN:
1068 g_value_set_int (value, icon_view->priv->text_column);
1070 case PROP_MARKUP_COLUMN:
1071 g_value_set_int (value, icon_view->priv->markup_column);
1074 g_value_set_object (value, icon_view->priv->model);
1076 case PROP_ORIENTATION:
1077 g_value_set_enum (value, icon_view->priv->orientation);
1080 g_value_set_int (value, icon_view->priv->columns);
1082 case PROP_ITEM_WIDTH:
1083 g_value_set_int (value, icon_view->priv->item_width);
1086 g_value_set_int (value, icon_view->priv->spacing);
1088 case PROP_ROW_SPACING:
1089 g_value_set_int (value, icon_view->priv->row_spacing);
1091 case PROP_COLUMN_SPACING:
1092 g_value_set_int (value, icon_view->priv->column_spacing);
1095 g_value_set_int (value, icon_view->priv->margin);
1097 case PROP_REORDERABLE:
1098 g_value_set_boolean (value, icon_view->priv->reorderable);
1102 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1107 /* GtkWidget signals */
1109 gtk_icon_view_realize (GtkWidget *widget)
1111 GtkIconView *icon_view;
1112 GdkWindowAttr attributes;
1113 gint attributes_mask;
1115 icon_view = GTK_ICON_VIEW (widget);
1117 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1119 /* Make the main, clipping window */
1120 attributes.window_type = GDK_WINDOW_CHILD;
1121 attributes.x = widget->allocation.x;
1122 attributes.y = widget->allocation.y;
1123 attributes.width = widget->allocation.width;
1124 attributes.height = widget->allocation.height;
1125 attributes.wclass = GDK_INPUT_OUTPUT;
1126 attributes.visual = gtk_widget_get_visual (widget);
1127 attributes.colormap = gtk_widget_get_colormap (widget);
1128 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1130 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1132 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1133 &attributes, attributes_mask);
1134 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1135 gdk_window_set_user_data (widget->window, widget);
1137 /* Make the window for the icon view */
1140 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1141 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1142 attributes.event_mask = (GDK_EXPOSURE_MASK |
1144 GDK_POINTER_MOTION_MASK |
1145 GDK_BUTTON_PRESS_MASK |
1146 GDK_BUTTON_RELEASE_MASK |
1147 GDK_KEY_PRESS_MASK |
1148 GDK_KEY_RELEASE_MASK) |
1149 gtk_widget_get_events (widget);
1151 icon_view->priv->bin_window = gdk_window_new (widget->window,
1152 &attributes, attributes_mask);
1153 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1155 widget->style = gtk_style_attach (widget->style, widget->window);
1156 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1158 gdk_window_show (icon_view->priv->bin_window);
1162 gtk_icon_view_unrealize (GtkWidget *widget)
1164 GtkIconView *icon_view;
1166 icon_view = GTK_ICON_VIEW (widget);
1168 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1169 gdk_window_destroy (icon_view->priv->bin_window);
1170 icon_view->priv->bin_window = NULL;
1172 /* GtkWidget::unrealize destroys children and widget->window */
1173 if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
1174 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
1178 gtk_icon_view_state_changed (GtkWidget *widget,
1179 GtkStateType previous_state)
1181 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1183 if (GTK_WIDGET_REALIZED (widget))
1185 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1186 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1189 gtk_widget_queue_draw (widget);
1193 gtk_icon_view_style_set (GtkWidget *widget,
1194 GtkStyle *previous_style)
1196 GtkIconView *icon_view;
1198 g_return_if_fail (GTK_IS_ICON_VIEW (widget));
1200 icon_view = GTK_ICON_VIEW (widget);
1202 if (GTK_WIDGET_REALIZED (widget))
1204 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1205 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1208 gtk_widget_queue_resize (widget);
1212 gtk_icon_view_size_request (GtkWidget *widget,
1213 GtkRequisition *requisition)
1215 GtkIconView *icon_view;
1218 icon_view = GTK_ICON_VIEW (widget);
1220 requisition->width = icon_view->priv->width;
1221 requisition->height = icon_view->priv->height;
1223 tmp_list = icon_view->priv->children;
1227 GtkIconViewChild *child = tmp_list->data;
1228 GtkRequisition child_requisition;
1230 tmp_list = tmp_list->next;
1232 if (GTK_WIDGET_VISIBLE (child->widget))
1233 gtk_widget_size_request (child->widget, &child_requisition);
1238 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1242 for (list = icon_view->priv->children; list; list = list->next)
1244 GtkIconViewChild *child = list->data;
1245 GtkAllocation allocation;
1247 /* totally ignore our child's requisition */
1248 if (child->cell < 0)
1250 allocation.x = child->item->x;
1251 allocation.y = child->item->y;
1252 allocation.width = child->item->width;
1253 allocation.height = child->item->height;
1257 GdkRectangle *box = &child->item->box[child->cell];
1259 allocation.x = box->x;
1260 allocation.y = box->y;
1261 allocation.width = box->width;
1262 allocation.height = box->height;
1265 gtk_widget_size_allocate (child->widget, &allocation);
1270 gtk_icon_view_size_allocate (GtkWidget *widget,
1271 GtkAllocation *allocation)
1273 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1275 GtkAdjustment *hadjustment, *vadjustment;
1277 widget->allocation = *allocation;
1279 if (GTK_WIDGET_REALIZED (widget))
1281 gdk_window_move_resize (widget->window,
1282 allocation->x, allocation->y,
1283 allocation->width, allocation->height);
1284 gdk_window_resize (icon_view->priv->bin_window,
1285 MAX (icon_view->priv->width, allocation->width),
1286 MAX (icon_view->priv->height, allocation->height));
1289 gtk_icon_view_layout (icon_view);
1291 gtk_icon_view_allocate_children (icon_view);
1293 hadjustment = icon_view->priv->hadjustment;
1294 vadjustment = icon_view->priv->vadjustment;
1296 hadjustment->page_size = allocation->width;
1297 hadjustment->page_increment = allocation->width * 0.9;
1298 hadjustment->step_increment = allocation->width * 0.1;
1299 hadjustment->lower = 0;
1300 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1302 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1303 gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
1305 vadjustment->page_size = allocation->height;
1306 vadjustment->page_increment = allocation->height * 0.9;
1307 vadjustment->step_increment = allocation->height * 0.1;
1308 vadjustment->lower = 0;
1309 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1311 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1312 gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
1314 if (GTK_WIDGET_REALIZED (widget) &&
1315 icon_view->priv->scroll_to_path)
1318 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1319 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1320 icon_view->priv->scroll_to_path = NULL;
1322 gtk_icon_view_scroll_to_path (icon_view, path,
1323 icon_view->priv->scroll_to_use_align,
1324 icon_view->priv->scroll_to_row_align,
1325 icon_view->priv->scroll_to_col_align);
1326 gtk_tree_path_free (path);
1330 gtk_adjustment_changed (hadjustment);
1331 gtk_adjustment_changed (vadjustment);
1336 gtk_icon_view_expose (GtkWidget *widget,
1337 GdkEventExpose *expose)
1339 GtkIconView *icon_view;
1344 GtkIconViewDropPosition dest_pos;
1345 GtkIconViewItem *dest_item = NULL;
1347 icon_view = GTK_ICON_VIEW (widget);
1349 if (expose->window != icon_view->priv->bin_window)
1352 cr = gdk_cairo_create (icon_view->priv->bin_window);
1353 cairo_set_line_width (cr, 1.);
1355 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1359 dest_index = gtk_tree_path_get_indices (path)[0];
1360 gtk_tree_path_free (path);
1365 for (icons = icon_view->priv->items; icons; icons = icons->next)
1367 GtkIconViewItem *item = icons->data;
1372 area.width = item->width;
1373 area.height = item->height;
1375 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1378 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1379 icon_view->priv->bin_window,
1380 item->x, item->y, TRUE);
1382 if (dest_index == item->index)
1390 case GTK_ICON_VIEW_DROP_INTO:
1391 gtk_paint_focus (widget->style,
1392 icon_view->priv->bin_window,
1393 GTK_WIDGET_STATE (widget),
1396 "iconview-drop-indicator",
1397 dest_item->x, dest_item->y,
1398 dest_item->width, dest_item->height);
1400 case GTK_ICON_VIEW_DROP_ABOVE:
1401 gtk_paint_focus (widget->style,
1402 icon_view->priv->bin_window,
1403 GTK_WIDGET_STATE (widget),
1406 "iconview-drop-indicator",
1407 dest_item->x, dest_item->y - 1,
1408 dest_item->width, 2);
1410 case GTK_ICON_VIEW_DROP_LEFT:
1411 gtk_paint_focus (widget->style,
1412 icon_view->priv->bin_window,
1413 GTK_WIDGET_STATE (widget),
1416 "iconview-drop-indicator",
1417 dest_item->x - 1, dest_item->y,
1418 2, dest_item->height);
1420 case GTK_ICON_VIEW_DROP_BELOW:
1421 gtk_paint_focus (widget->style,
1422 icon_view->priv->bin_window,
1423 GTK_WIDGET_STATE (widget),
1426 "iconview-drop-indicator",
1427 dest_item->x, dest_item->y + dest_item->height - 1,
1428 dest_item->width, 2);
1430 case GTK_ICON_VIEW_DROP_RIGHT:
1431 gtk_paint_focus (widget->style,
1432 icon_view->priv->bin_window,
1433 GTK_WIDGET_STATE (widget),
1436 "iconview-drop-indicator",
1437 dest_item->x + dest_item->width - 1, dest_item->y,
1438 2, dest_item->height);
1439 case GTK_ICON_VIEW_NO_DROP: ;
1444 if (icon_view->priv->doing_rubberband)
1446 GdkRectangle *rectangles;
1449 gdk_region_get_rectangles (expose->region,
1453 while (n_rectangles--)
1454 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1456 g_free (rectangles);
1461 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);
1467 rubberband_scroll_timeout (gpointer data)
1469 GtkIconView *icon_view;
1474 value = MIN (icon_view->priv->vadjustment->value +
1475 icon_view->priv->scroll_value_diff,
1476 icon_view->priv->vadjustment->upper -
1477 icon_view->priv->vadjustment->page_size);
1479 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1481 gtk_icon_view_update_rubberband (icon_view);
1487 gtk_icon_view_motion (GtkWidget *widget,
1488 GdkEventMotion *event)
1490 GtkIconView *icon_view;
1493 icon_view = GTK_ICON_VIEW (widget);
1495 gtk_icon_view_maybe_begin_drag (icon_view, event);
1497 if (icon_view->priv->doing_rubberband)
1499 gtk_icon_view_update_rubberband (widget);
1501 abs_y = event->y - icon_view->priv->height *
1502 (icon_view->priv->vadjustment->value /
1503 (icon_view->priv->vadjustment->upper -
1504 icon_view->priv->vadjustment->lower));
1506 if (abs_y < 0 || abs_y > widget->allocation.height)
1509 icon_view->priv->scroll_value_diff = abs_y;
1511 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1513 icon_view->priv->event_last_x = event->x;
1514 icon_view->priv->event_last_y = event->y;
1516 if (icon_view->priv->scroll_timeout_id == 0)
1517 icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
1521 remove_scroll_timeout (icon_view);
1528 gtk_icon_view_remove (GtkContainer *container,
1531 GtkIconView *icon_view;
1532 GtkIconViewChild *child = NULL;
1535 icon_view = GTK_ICON_VIEW (container);
1537 tmp_list = icon_view->priv->children;
1540 child = tmp_list->data;
1541 if (child->widget == widget)
1543 gtk_widget_unparent (widget);
1545 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1546 g_list_free_1 (tmp_list);
1551 tmp_list = tmp_list->next;
1556 gtk_icon_view_forall (GtkContainer *container,
1557 gboolean include_internals,
1558 GtkCallback callback,
1559 gpointer callback_data)
1561 GtkIconView *icon_view;
1562 GtkIconViewChild *child = NULL;
1565 icon_view = GTK_ICON_VIEW (container);
1567 tmp_list = icon_view->priv->children;
1570 child = tmp_list->data;
1571 tmp_list = tmp_list->next;
1573 (* callback) (child->widget, callback_data);
1578 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1579 GtkIconViewItem *item,
1580 GtkIconViewCellInfo *info,
1585 GdkRectangle cell_area;
1586 gboolean visible, mode;
1588 gtk_icon_view_set_cell_data (icon_view, item);
1590 g_object_get (info->cell,
1591 "visible", &visible,
1595 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1597 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1599 path = gtk_tree_path_new_from_indices (item->index, -1);
1600 path_string = gtk_tree_path_to_string (path);
1601 gtk_tree_path_free (path);
1603 gtk_cell_renderer_activate (info->cell,
1605 GTK_WIDGET (icon_view),
1611 g_free (path_string);
1616 gtk_icon_view_put (GtkIconView *icon_view,
1618 GtkIconViewItem *item,
1621 GtkIconViewChild *child;
1623 child = g_new (GtkIconViewChild, 1);
1625 child->widget = widget;
1629 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1631 if (GTK_WIDGET_REALIZED (icon_view))
1632 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1634 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1638 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1639 GtkIconView *icon_view)
1642 GtkIconViewItem *item;
1644 if (icon_view->priv->edited_item == NULL)
1647 item = icon_view->priv->edited_item;
1648 icon_view->priv->edited_item = NULL;
1649 icon_view->priv->editable = NULL;
1650 for (l = icon_view->priv->cell_list; l; l = l->next)
1652 GtkIconViewCellInfo *info = l->data;
1654 info->editing = FALSE;
1657 if (GTK_WIDGET_HAS_FOCUS (editable))
1658 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1660 g_signal_handlers_disconnect_by_func (editable,
1661 gtk_icon_view_remove_widget,
1664 gtk_container_remove (GTK_CONTAINER (icon_view),
1665 GTK_WIDGET (editable));
1667 gtk_icon_view_queue_draw_item (icon_view, item);
1672 gtk_icon_view_start_editing (GtkIconView *icon_view,
1673 GtkIconViewItem *item,
1674 GtkIconViewCellInfo *info,
1679 GdkRectangle cell_area;
1680 gboolean visible, mode;
1681 GtkCellEditable *editable;
1683 gtk_icon_view_set_cell_data (icon_view, item);
1685 g_object_get (info->cell,
1686 "visible", &visible,
1689 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1691 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1693 path = gtk_tree_path_new_from_indices (item->index, -1);
1694 path_string = gtk_tree_path_to_string (path);
1695 gtk_tree_path_free (path);
1697 editable = gtk_cell_renderer_start_editing (info->cell,
1699 GTK_WIDGET (icon_view),
1704 g_free (path_string);
1706 /* FIXME ugly special case */
1707 if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
1708 g_object_set (editable, "has-frame", TRUE, NULL);
1710 /* the rest corresponds to tree_view_real_start_editing... */
1711 icon_view->priv->edited_item = item;
1712 icon_view->priv->editable = editable;
1713 info->editing = TRUE;
1715 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1717 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1719 gtk_widget_grab_focus (GTK_WIDGET (editable));
1720 g_signal_connect (editable, "remove_widget",
1721 G_CALLBACK (gtk_icon_view_remove_widget),
1728 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1729 gboolean cancel_editing)
1731 GtkCellRenderer *cell = NULL;
1732 GtkIconViewItem *item;
1735 if (icon_view->priv->edited_item == NULL)
1739 * This is very evil. We need to do this, because
1740 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1741 * later on. If gtk_icon_view_row_changed notices
1742 * icon_view->priv->edited_item != NULL, it'll call
1743 * gtk_icon_view_stop_editing again. Bad things will happen then.
1745 * Please read that again if you intend to modify anything here.
1748 item = icon_view->priv->edited_item;
1749 icon_view->priv->edited_item = NULL;
1751 for (l = icon_view->priv->cell_list; l; l = l->next)
1753 GtkIconViewCellInfo *info = l->data;
1765 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1766 if (!cancel_editing)
1767 gtk_cell_editable_editing_done (icon_view->priv->editable);
1769 icon_view->priv->edited_item = item;
1771 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1775 * gtk_icon_view_set_cursor:
1776 * @icon_view: A #GtkIconView
1777 * @path: A #GtkTreePath
1778 * @cell: One of the cell renderers of @icon_view, or %NULL
1779 * @start_editing: %TRUE if the specified cell should start being edited.
1781 * Sets the current keyboard focus to be at @path, and selects it. This is
1782 * useful when you want to focus the user's attention on a particular item.
1783 * If @cell is not %NULL, then focus is given to the cell specified by
1784 * it. Additionally, if @start_editing is %TRUE, then editing should be
1785 * started in the specified cell.
1787 * This function is often followed by <literal>gtk_widget_grab_focus
1788 * (icon_view)</literal> in order to give keyboard focus to the widget.
1789 * Please note that editing can only happen when the widget is realized.
1794 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1796 GtkCellRenderer *cell,
1797 gboolean start_editing)
1799 GtkIconViewItem *item = NULL;
1800 GtkIconViewCellInfo *info = NULL;
1804 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1805 g_return_if_fail (path != NULL);
1806 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1808 gtk_icon_view_stop_editing (icon_view, TRUE);
1810 if (gtk_tree_path_get_depth (path) == 1)
1811 item = g_list_nth_data (icon_view->priv->items,
1812 gtk_tree_path_get_indices(path)[0]);
1818 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1822 if (info->cell == cell)
1831 g_return_if_fail (cell == NULL || info != NULL);
1833 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1834 gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
1836 if (info && start_editing)
1837 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1841 * gtk_icon_view_get_cursor:
1842 * @icon_view: A #GtkIconView
1843 * @path: Return location for the current cursor path, or %NULL
1844 * @cell: Return location the current focus cell, or %NULL
1846 * Fills in @path and @cell with the current cursor path and cell.
1847 * If the cursor isn't currently set, then *@path will be %NULL.
1848 * If no cell currently has focus, then *@cell will be %NULL.
1850 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1852 * Return value: %TRUE if the cursor is set.
1857 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1859 GtkCellRenderer **cell)
1861 GtkIconViewItem *item;
1862 GtkIconViewCellInfo *info;
1864 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1866 item = icon_view->priv->cursor_item;
1867 if (icon_view->priv->cursor_cell < 0)
1870 info = g_list_nth_data (icon_view->priv->cell_list,
1871 icon_view->priv->cursor_cell);
1876 *path = gtk_tree_path_new_from_indices (item->index, -1);
1889 return (item != NULL);
1893 gtk_icon_view_button_press (GtkWidget *widget,
1894 GdkEventButton *event)
1896 GtkIconView *icon_view;
1897 GtkIconViewItem *item;
1898 GtkIconViewCellInfo *info = NULL;
1899 gboolean dirty = FALSE;
1900 GtkCellRendererMode mode;
1903 icon_view = GTK_ICON_VIEW (widget);
1905 if (event->window != icon_view->priv->bin_window)
1908 if (!GTK_WIDGET_HAS_FOCUS (widget))
1909 gtk_widget_grab_focus (widget);
1911 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1913 item = gtk_icon_view_get_item_at_coords (icon_view,
1919 g_object_get (info->cell, "mode", &mode, NULL);
1921 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
1922 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1923 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
1927 gtk_icon_view_scroll_to_item (icon_view, item);
1929 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1931 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1933 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1934 (event->state & GDK_SHIFT_MASK))
1936 gtk_icon_view_unselect_all_internal (icon_view);
1938 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1939 if (!icon_view->priv->anchor_item)
1940 icon_view->priv->anchor_item = item;
1942 gtk_icon_view_select_all_between (icon_view,
1943 icon_view->priv->anchor_item,
1949 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
1950 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
1951 (event->state & GDK_CONTROL_MASK))
1953 item->selected = !item->selected;
1954 gtk_icon_view_queue_draw_item (icon_view, item);
1959 if (!item->selected)
1961 gtk_icon_view_unselect_all_internal (icon_view);
1963 item->selected = TRUE;
1964 gtk_icon_view_queue_draw_item (icon_view, item);
1968 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1969 icon_view->priv->anchor_item = item;
1972 /* Save press to possibly begin a drag */
1973 if (icon_view->priv->pressed_button < 0)
1975 icon_view->priv->pressed_button = event->button;
1976 icon_view->priv->press_start_x = event->x;
1977 icon_view->priv->press_start_y = event->y;
1980 if (!icon_view->priv->last_single_clicked)
1981 icon_view->priv->last_single_clicked = item;
1983 /* cancel the current editing, if it exists */
1984 gtk_icon_view_stop_editing (icon_view, TRUE);
1986 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1987 gtk_icon_view_item_activate_cell (icon_view, item, info,
1989 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1990 gtk_icon_view_start_editing (icon_view, item, info,
1995 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
1996 !(event->state & GDK_CONTROL_MASK))
1998 dirty = gtk_icon_view_unselect_all_internal (icon_view);
2001 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
2002 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
2007 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
2009 item = gtk_icon_view_get_item_at_coords (icon_view,
2014 if (item && item == icon_view->priv->last_single_clicked)
2018 path = gtk_tree_path_new_from_indices (item->index, -1);
2019 gtk_icon_view_item_activated (icon_view, path);
2020 gtk_tree_path_free (path);
2023 icon_view->priv->last_single_clicked = NULL;
2024 icon_view->priv->pressed_button = -1;
2028 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2030 return event->button == 1;
2034 gtk_icon_view_button_release (GtkWidget *widget,
2035 GdkEventButton *event)
2037 GtkIconView *icon_view;
2039 icon_view = GTK_ICON_VIEW (widget);
2041 if (icon_view->priv->pressed_button == event->button)
2042 icon_view->priv->pressed_button = -1;
2044 gtk_icon_view_stop_rubberbanding (icon_view);
2046 remove_scroll_timeout (icon_view);
2052 gtk_icon_view_update_rubberband (gpointer data)
2054 GtkIconView *icon_view;
2056 GdkRectangle old_area;
2057 GdkRectangle new_area;
2058 GdkRectangle common;
2059 GdkRegion *invalid_region;
2061 icon_view = GTK_ICON_VIEW (data);
2063 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2068 old_area.x = MIN (icon_view->priv->rubberband_x1,
2069 icon_view->priv->rubberband_x2);
2070 old_area.y = MIN (icon_view->priv->rubberband_y1,
2071 icon_view->priv->rubberband_y2);
2072 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2073 icon_view->priv->rubberband_x1) + 1;
2074 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2075 icon_view->priv->rubberband_y1) + 1;
2077 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2078 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2079 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2080 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2082 invalid_region = gdk_region_rectangle (&old_area);
2083 gdk_region_union_with_rect (invalid_region, &new_area);
2085 gdk_rectangle_intersect (&old_area, &new_area, &common);
2086 if (common.width > 2 && common.height > 2)
2088 GdkRegion *common_region;
2090 /* make sure the border is invalidated */
2096 common_region = gdk_region_rectangle (&common);
2098 gdk_region_subtract (invalid_region, common_region);
2099 gdk_region_destroy (common_region);
2102 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2104 gdk_region_destroy (invalid_region);
2106 icon_view->priv->rubberband_x2 = x;
2107 icon_view->priv->rubberband_y2 = y;
2109 gtk_icon_view_update_rubberband_selection (icon_view);
2113 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2119 g_assert (!icon_view->priv->doing_rubberband);
2121 for (items = icon_view->priv->items; items; items = items->next)
2123 GtkIconViewItem *item = items->data;
2125 item->selected_before_rubberbanding = item->selected;
2128 icon_view->priv->rubberband_x1 = x;
2129 icon_view->priv->rubberband_y1 = y;
2130 icon_view->priv->rubberband_x2 = x;
2131 icon_view->priv->rubberband_y2 = y;
2133 icon_view->priv->doing_rubberband = TRUE;
2135 gtk_grab_add (GTK_WIDGET (icon_view));
2139 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2141 if (!icon_view->priv->doing_rubberband)
2144 icon_view->priv->doing_rubberband = FALSE;
2146 gtk_grab_remove (GTK_WIDGET (icon_view));
2148 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2152 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2155 gint x, y, width, height;
2156 gboolean dirty = FALSE;
2158 x = MIN (icon_view->priv->rubberband_x1,
2159 icon_view->priv->rubberband_x2);
2160 y = MIN (icon_view->priv->rubberband_y1,
2161 icon_view->priv->rubberband_y2);
2162 width = ABS (icon_view->priv->rubberband_x1 -
2163 icon_view->priv->rubberband_x2);
2164 height = ABS (icon_view->priv->rubberband_y1 -
2165 icon_view->priv->rubberband_y2);
2167 for (items = icon_view->priv->items; items; items = items->next)
2169 GtkIconViewItem *item = items->data;
2173 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2174 x, y, width, height);
2176 selected = is_in ^ item->selected_before_rubberbanding;
2178 if (item->selected != selected)
2180 item->selected = selected;
2182 gtk_icon_view_queue_draw_item (icon_view, item);
2187 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2191 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2192 GtkIconViewItem *item,
2201 for (l = icon_view->priv->cell_list; l; l = l->next)
2203 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2205 if (!info->cell->visible)
2208 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2210 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2211 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2219 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2221 gboolean dirty = FALSE;
2224 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2227 for (items = icon_view->priv->items; items; items = items->next)
2229 GtkIconViewItem *item = items->data;
2233 item->selected = FALSE;
2235 gtk_icon_view_queue_draw_item (icon_view, item);
2243 /* GtkIconView signals */
2245 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2246 GtkAdjustment *hadj,
2247 GtkAdjustment *vadj)
2249 gboolean need_adjust = FALSE;
2252 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2254 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2256 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2258 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2260 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2262 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2263 0, 0, NULL, NULL, icon_view);
2264 g_object_unref (icon_view->priv->hadjustment);
2267 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2269 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2270 0, 0, NULL, NULL, icon_view);
2271 g_object_unref (icon_view->priv->vadjustment);
2274 if (icon_view->priv->hadjustment != hadj)
2276 icon_view->priv->hadjustment = hadj;
2277 g_object_ref_sink (icon_view->priv->hadjustment);
2279 g_signal_connect (icon_view->priv->hadjustment, "value_changed",
2280 G_CALLBACK (gtk_icon_view_adjustment_changed),
2285 if (icon_view->priv->vadjustment != vadj)
2287 icon_view->priv->vadjustment = vadj;
2288 g_object_ref_sink (icon_view->priv->vadjustment);
2290 g_signal_connect (icon_view->priv->vadjustment, "value_changed",
2291 G_CALLBACK (gtk_icon_view_adjustment_changed),
2297 gtk_icon_view_adjustment_changed (NULL, icon_view);
2301 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2303 gtk_icon_view_select_all (icon_view);
2307 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2309 gtk_icon_view_unselect_all (icon_view);
2313 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2315 gtk_icon_view_unselect_all (icon_view);
2317 if (icon_view->priv->cursor_item != NULL)
2318 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2322 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2325 GtkCellRendererMode mode;
2326 GtkIconViewCellInfo *info = NULL;
2328 if (!icon_view->priv->cursor_item)
2331 info = g_list_nth_data (icon_view->priv->cell_list,
2332 icon_view->priv->cursor_cell);
2336 g_object_get (info->cell, "mode", &mode, NULL);
2338 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2340 gtk_icon_view_item_activate_cell (icon_view,
2341 icon_view->priv->cursor_item,
2345 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2347 gtk_icon_view_start_editing (icon_view,
2348 icon_view->priv->cursor_item,
2354 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2355 gtk_icon_view_item_activated (icon_view, path);
2356 gtk_tree_path_free (path);
2362 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2364 if (!icon_view->priv->cursor_item)
2367 switch (icon_view->priv->selection_mode)
2369 case GTK_SELECTION_NONE:
2371 case GTK_SELECTION_BROWSE:
2372 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2374 case GTK_SELECTION_SINGLE:
2375 if (icon_view->priv->cursor_item->selected)
2376 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2378 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2380 case GTK_SELECTION_MULTIPLE:
2381 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2382 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2384 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2389 /* Internal functions */
2391 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2392 GtkIconView *icon_view)
2394 if (GTK_WIDGET_REALIZED (icon_view))
2396 gdk_window_move (icon_view->priv->bin_window,
2397 - icon_view->priv->hadjustment->value,
2398 - icon_view->priv->vadjustment->value);
2400 if (icon_view->priv->doing_rubberband)
2401 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2403 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2408 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2413 gint *maximum_width)
2416 gint x, current_width;
2417 GList *items, *last_item;
2424 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2425 max_height = g_new0 (gint, icon_view->priv->n_cells);
2432 gtk_widget_style_get (GTK_WIDGET (icon_view),
2433 "focus-line-width", &focus_width,
2436 x += icon_view->priv->margin + focus_width;
2437 current_width += 2 * (icon_view->priv->margin + focus_width);
2442 GtkIconViewItem *item = items->data;
2444 gtk_icon_view_calculate_item_size (icon_view, item);
2445 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2447 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2449 current_width += item->width;
2451 if (items != first_item)
2453 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2454 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2458 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2460 item->y = *y + focus_width;
2461 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2463 x = current_width - (icon_view->priv->margin + focus_width);
2465 for (i = 0; i < icon_view->priv->n_cells; i++)
2466 max_height[i] = MAX (max_height[i], item->box[i].height);
2468 if (current_width > *maximum_width)
2469 *maximum_width = current_width;
2475 items = items->next;
2480 /* Now go through the row again and align the icons */
2481 for (items = first_item; items != last_item; items = items->next)
2483 GtkIconViewItem *item = items->data;
2485 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2487 /* We may want to readjust the new y coordinate. */
2488 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2489 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2492 item->col = col - 1 - item->col;
2495 g_free (max_height);
2501 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2504 if (upper != adj->upper)
2506 gdouble min = MAX (0.0, upper - adj->page_size);
2507 gboolean value_changed = FALSE;
2511 if (adj->value > min)
2514 value_changed = TRUE;
2517 gtk_adjustment_changed (adj);
2520 gtk_adjustment_value_changed (adj);
2525 gtk_icon_view_layout (GtkIconView *icon_view)
2527 gint y = 0, maximum_width = 0;
2533 if (icon_view->priv->layout_idle_id != 0)
2535 g_source_remove (icon_view->priv->layout_idle_id);
2536 icon_view->priv->layout_idle_id = 0;
2539 if (icon_view->priv->model == NULL)
2542 widget = GTK_WIDGET (icon_view);
2544 item_width = icon_view->priv->item_width;
2548 for (icons = icon_view->priv->items; icons; icons = icons->next)
2550 GtkIconViewItem *item = icons->data;
2551 gtk_icon_view_calculate_item_size (icon_view, item);
2552 item_width = MAX (item_width, item->width);
2556 icons = icon_view->priv->items;
2557 y += icon_view->priv->margin;
2562 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2564 &y, &maximum_width);
2567 while (icons != NULL);
2569 if (maximum_width != icon_view->priv->width)
2570 icon_view->priv->width = maximum_width;
2572 y += icon_view->priv->margin;
2574 if (y != icon_view->priv->height)
2575 icon_view->priv->height = y;
2577 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
2578 icon_view->priv->width);
2579 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
2580 icon_view->priv->height);
2582 if (GTK_WIDGET_REALIZED (icon_view))
2583 gdk_window_resize (icon_view->priv->bin_window,
2584 MAX (icon_view->priv->width, widget->allocation.width),
2585 MAX (icon_view->priv->height, widget->allocation.height));
2587 if (icon_view->priv->scroll_to_path)
2591 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
2592 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
2593 icon_view->priv->scroll_to_path = NULL;
2595 gtk_icon_view_scroll_to_path (icon_view, path,
2596 icon_view->priv->scroll_to_use_align,
2597 icon_view->priv->scroll_to_row_align,
2598 icon_view->priv->scroll_to_col_align);
2599 gtk_tree_path_free (path);
2602 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2606 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2607 GtkIconViewItem *item,
2608 GtkIconViewCellInfo *info,
2609 GdkRectangle *cell_area)
2611 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2613 cell_area->x = item->box[info->position].x - item->before[info->position];
2614 cell_area->y = item->y;
2615 cell_area->width = item->box[info->position].width +
2616 item->before[info->position] + item->after[info->position];
2617 cell_area->height = item->height;
2621 cell_area->x = item->x;
2622 cell_area->y = item->box[info->position].y - item->before[info->position];
2623 cell_area->width = item->width;
2624 cell_area->height = item->box[info->position].height +
2625 item->before[info->position] + item->after[info->position];
2630 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2631 GtkIconViewItem *item,
2632 GtkIconViewCellInfo *info,
2635 *box = item->box[info->position];
2638 /* try to guess a reasonable wrap width for an implicit text cell renderer
2641 adjust_wrap_width (GtkIconView *icon_view,
2642 GtkIconViewItem *item)
2644 GtkIconViewCellInfo *text_info;
2645 GtkIconViewCellInfo *pixbuf_info;
2646 gint pixbuf_width, wrap_width;
2648 if (icon_view->priv->text_cell != -1 &&
2649 icon_view->priv->pixbuf_cell != -1)
2651 text_info = g_list_nth_data (icon_view->priv->cell_list,
2652 icon_view->priv->text_cell);
2653 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2654 icon_view->priv->pixbuf_cell);
2656 gtk_cell_renderer_get_size (pixbuf_info->cell,
2657 GTK_WIDGET (icon_view),
2662 if (item->width == -1)
2663 wrap_width = MAX (2 * pixbuf_width, 50);
2664 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2665 wrap_width = item->width;
2667 wrap_width = item->width - pixbuf_width - icon_view->priv->spacing;
2669 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2670 g_object_set (text_info->cell, "width", wrap_width, NULL);
2675 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2676 GtkIconViewItem *item)
2681 if (item->width != -1 && item->height != -1)
2684 if (item->n_cells != icon_view->priv->n_cells)
2686 g_free (item->before);
2687 g_free (item->after);
2690 item->before = g_new0 (gint, icon_view->priv->n_cells);
2691 item->after = g_new0 (gint, icon_view->priv->n_cells);
2692 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2694 item->n_cells = icon_view->priv->n_cells;
2697 gtk_icon_view_set_cell_data (icon_view, item);
2699 spacing = icon_view->priv->spacing;
2703 for (l = icon_view->priv->cell_list; l; l = l->next)
2705 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2707 if (!info->cell->visible)
2710 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2712 &item->box[info->position].width,
2713 &item->box[info->position].height);
2715 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2717 item->width += item->box[info->position].width
2718 + (info->position > 0 ? spacing : 0);
2719 item->height = MAX (item->height, item->box[info->position].height);
2723 item->width = MAX (item->width, item->box[info->position].width);
2724 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2730 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2731 GtkIconViewItem *item,
2734 GdkRectangle cell_area;
2740 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2742 gtk_icon_view_set_cell_data (icon_view, item);
2744 spacing = icon_view->priv->spacing;
2747 for (i = 0; i < icon_view->priv->n_cells; i++)
2749 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2750 item->height = MAX (item->height, max_height[i]);
2752 item->height += max_height[i] + (i > 0 ? spacing : 0);
2755 cell_area.x = item->x;
2756 cell_area.y = item->y;
2758 for (k = 0; k < 2; k++)
2759 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2761 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2763 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2766 if (!info->cell->visible)
2769 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2771 cell_area.width = item->box[info->position].width;
2772 cell_area.height = item->height;
2776 cell_area.width = item->width;
2777 cell_area.height = max_height[i];
2780 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2782 &item->box[info->position].x, &item->box[info->position].y,
2783 &item->box[info->position].width, &item->box[info->position].height);
2785 item->box[info->position].x += cell_area.x;
2786 item->box[info->position].y += cell_area.y;
2787 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2789 item->before[info->position] = item->box[info->position].x - cell_area.x;
2790 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2791 cell_area.x += cell_area.width + spacing;
2795 if (item->box[info->position].width > item->width)
2797 item->width = item->box[info->position].width;
2798 cell_area.width = item->width;
2800 item->before[info->position] = item->box[info->position].y - cell_area.y;
2801 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2802 cell_area.y += cell_area.height + spacing;
2806 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2808 for (i = 0; i < icon_view->priv->n_cells; i++)
2810 item->box[i].x = item->x + item->width -
2811 (item->box[i].x + item->box[i].width - item->x);
2817 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2819 g_list_foreach (icon_view->priv->items,
2820 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2824 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2831 gtk_icon_view_paint_item (GtkIconView *icon_view,
2833 GtkIconViewItem *item,
2835 GdkDrawable *drawable,
2838 gboolean draw_focus)
2840 gint focus_width, focus_pad;
2842 GdkRectangle cell_area, box;
2846 GtkCellRendererState flags;
2848 if (icon_view->priv->model == NULL)
2851 gtk_icon_view_set_cell_data (icon_view, item);
2853 gtk_widget_style_get (GTK_WIDGET (icon_view),
2854 "focus-line-width", &focus_width,
2855 "focus-padding", &focus_pad,
2858 padding = focus_width;
2862 flags = GTK_CELL_RENDERER_SELECTED;
2863 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2864 state = GTK_STATE_SELECTED;
2866 state = GTK_STATE_ACTIVE;
2871 state = GTK_STATE_NORMAL;
2874 #ifdef DEBUG_ICON_VIEW
2875 gdk_draw_rectangle (drawable,
2876 GTK_WIDGET (icon_view)->style->black_gc,
2879 item->width, item->height);
2883 for (l = icon_view->priv->cell_list; l; l = l->next)
2885 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2887 if (!info->cell->visible)
2890 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2892 /* FIXME we hardwire background drawing behind text
2893 * cell renderers here
2895 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
2897 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
2898 cairo_rectangle (cr,
2899 x - item->x + box.x,
2900 y - item->y + box.y,
2901 box.width, box.height);
2906 for (l = icon_view->priv->cell_list; l; l = l->next)
2908 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2910 if (!info->cell->visible)
2913 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
2915 #ifdef DEBUG_ICON_VIEW
2916 gdk_draw_rectangle (drawable,
2917 GTK_WIDGET (icon_view)->style->black_gc,
2919 x - item->x + cell_area.x,
2920 y - item->y + cell_area.y,
2921 cell_area.width, cell_area.height);
2923 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2925 gdk_draw_rectangle (drawable,
2926 GTK_WIDGET (icon_view)->style->black_gc,
2928 x - item->x + box.x,
2929 y - item->y + box.y,
2930 box.width, box.height);
2933 cell_area.x = x - item->x + cell_area.x;
2934 cell_area.y = y - item->y + cell_area.y;
2936 gtk_cell_renderer_render (info->cell,
2938 GTK_WIDGET (icon_view),
2939 &cell_area, &cell_area, area, flags);
2943 /* FIXME where to draw the focus with generic cell renderers ? */
2945 GTK_WIDGET_HAS_FOCUS (icon_view) &&
2946 item == icon_view->priv->cursor_item)
2947 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2949 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2951 if (!info->cell->visible)
2954 if (icon_view->priv->cursor_cell < 0 &&
2955 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
2956 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
2957 icon_view->priv->cursor_cell = i;
2959 if (i == icon_view->priv->cursor_cell)
2961 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2963 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
2967 GTK_WIDGET (icon_view),
2969 x - item->x + box.x - padding,
2970 y - item->y + box.y - padding,
2971 box.width + 2 * padding,
2972 box.height + 2 * padding);
2979 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2984 GdkRectangle rubber_rect;
2985 GdkColor *fill_color_gdk;
2986 guchar fill_color_alpha;
2988 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2989 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2990 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2991 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2993 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
2996 gtk_widget_style_get (GTK_WIDGET (icon_view),
2997 "selection-box-color", &fill_color_gdk,
2998 "selection-box-alpha", &fill_color_alpha,
3001 if (!fill_color_gdk)
3002 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
3004 cairo_set_source_rgba (cr,
3005 fill_color_gdk->red / 65535.,
3006 fill_color_gdk->green / 65535.,
3007 fill_color_gdk->blue / 65535.,
3008 fill_color_alpha / 255.);
3011 gdk_cairo_rectangle (cr, &rect);
3015 /* Draw the border without alpha */
3016 cairo_set_source_rgb (cr,
3017 fill_color_gdk->red / 65535.,
3018 fill_color_gdk->green / 65535.,
3019 fill_color_gdk->blue / 65535.);
3020 cairo_rectangle (cr,
3021 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3022 rubber_rect.width - 1, rubber_rect.height - 1);
3026 gdk_color_free (fill_color_gdk);
3030 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
3036 index = gtk_tree_path_get_indices (path)[0];
3038 for (l = icon_view->priv->items; l; l = l->next)
3040 GtkIconViewItem *item = l->data;
3042 if (item->index == index)
3044 gtk_icon_view_queue_draw_item (icon_view, item);
3051 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
3052 GtkIconViewItem *item)
3057 gtk_widget_style_get (GTK_WIDGET (icon_view),
3058 "focus-line-width", &focus_width,
3061 rect.x = item->x - focus_width;
3062 rect.y = item->y - focus_width;
3063 rect.width = item->width + 2 * focus_width;
3064 rect.height = item->height + 2 * focus_width;
3066 if (icon_view->priv->bin_window)
3067 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3071 layout_callback (gpointer user_data)
3073 GtkIconView *icon_view;
3075 icon_view = GTK_ICON_VIEW (user_data);
3077 icon_view->priv->layout_idle_id = 0;
3079 gtk_icon_view_layout (icon_view);
3085 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3087 if (icon_view->priv->layout_idle_id != 0)
3090 icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
3094 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3095 GtkIconViewItem *item,
3099 AtkObject *item_obj;
3101 if (icon_view->priv->cursor_item == item &&
3102 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3105 if (icon_view->priv->cursor_item != NULL)
3106 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3108 icon_view->priv->cursor_item = item;
3109 if (cursor_cell >= 0)
3110 icon_view->priv->cursor_cell = cursor_cell;
3112 gtk_icon_view_queue_draw_item (icon_view, item);
3114 /* Notify that accessible focus object has changed */
3115 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3116 item_obj = atk_object_ref_accessible_child (obj, item->index);
3118 if (item_obj != NULL)
3120 atk_focus_tracker_notify (item_obj);
3121 g_object_unref (item_obj);
3126 static GtkIconViewItem *
3127 gtk_icon_view_item_new (void)
3129 GtkIconViewItem *item;
3131 item = g_new0 (GtkIconViewItem, 1);
3140 gtk_icon_view_item_free (GtkIconViewItem *item)
3142 g_return_if_fail (item != NULL);
3144 g_free (item->before);
3145 g_free (item->after);
3152 static GtkIconViewItem *
3153 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3156 gboolean only_in_cell,
3157 GtkIconViewCellInfo **cell_at_pos)
3162 for (items = icon_view->priv->items; items; items = items->next)
3164 GtkIconViewItem *item = items->data;
3166 if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
3167 y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
3169 if (only_in_cell || cell_at_pos)
3171 gtk_icon_view_set_cell_data (icon_view, item);
3173 for (l = icon_view->priv->cell_list; l; l = l->next)
3175 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3177 if (!info->cell->visible)
3180 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3182 if ((x >= box.x && x <= box.x + box.width &&
3183 y >= box.y && y <= box.y + box.height) ||
3185 x <= box.x + box.width &&
3187 y <= box.y + box.height))
3190 *cell_at_pos = info;
3200 *cell_at_pos = NULL;
3211 gtk_icon_view_select_item (GtkIconView *icon_view,
3212 GtkIconViewItem *item)
3214 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3215 g_return_if_fail (item != NULL);
3220 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3222 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3223 gtk_icon_view_unselect_all_internal (icon_view);
3225 item->selected = TRUE;
3227 gtk_icon_view_queue_draw_item (icon_view, item);
3229 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3234 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3235 GtkIconViewItem *item)
3237 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3238 g_return_if_fail (item != NULL);
3240 if (!item->selected)
3243 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3244 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3247 item->selected = FALSE;
3249 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3251 gtk_icon_view_queue_draw_item (icon_view, item);
3255 verify_items (GtkIconView *icon_view)
3260 for (items = icon_view->priv->items; items; items = items->next)
3262 GtkIconViewItem *item = items->data;
3264 if (item->index != i)
3265 g_error ("List item does not match its index: "
3266 "item index %d and list index %d\n", item->index, i);
3273 gtk_icon_view_row_changed (GtkTreeModel *model,
3278 GtkIconViewItem *item;
3280 GtkIconView *icon_view;
3282 icon_view = GTK_ICON_VIEW (data);
3284 gtk_icon_view_stop_editing (icon_view, TRUE);
3286 index = gtk_tree_path_get_indices(path)[0];
3287 item = g_list_nth_data (icon_view->priv->items, index);
3289 gtk_icon_view_item_invalidate_size (item);
3290 gtk_icon_view_queue_layout (icon_view);
3292 verify_items (icon_view);
3296 gtk_icon_view_row_inserted (GtkTreeModel *model,
3302 GtkIconViewItem *item;
3303 gboolean iters_persist;
3304 GtkIconView *icon_view;
3307 icon_view = GTK_ICON_VIEW (data);
3309 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3311 index = gtk_tree_path_get_indices(path)[0];
3313 item = gtk_icon_view_item_new ();
3318 item->index = index;
3320 /* FIXME: We can be more efficient here,
3321 we can store a tail pointer and use that when
3322 appending (which is a rather common operation)
3324 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3327 list = g_list_nth (icon_view->priv->items, index + 1);
3328 for (; list; list = list->next)
3335 verify_items (icon_view);
3337 gtk_icon_view_queue_layout (icon_view);
3341 gtk_icon_view_row_deleted (GtkTreeModel *model,
3346 GtkIconView *icon_view;
3347 GtkIconViewItem *item;
3349 gboolean emit = FALSE;
3351 icon_view = GTK_ICON_VIEW (data);
3353 index = gtk_tree_path_get_indices(path)[0];
3355 list = g_list_nth (icon_view->priv->items, index);
3358 gtk_icon_view_stop_editing (icon_view, TRUE);
3360 if (item == icon_view->priv->anchor_item)
3361 icon_view->priv->anchor_item = NULL;
3363 if (item == icon_view->priv->cursor_item)
3364 icon_view->priv->cursor_item = NULL;
3369 gtk_icon_view_item_free (item);
3371 for (next = list->next; next; next = next->next)
3378 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3380 verify_items (icon_view);
3382 gtk_icon_view_queue_layout (icon_view);
3385 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3389 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3390 GtkTreePath *parent,
3397 GtkIconView *icon_view;
3398 GList *items = NULL, *list;
3399 GtkIconViewItem **item_array;
3402 icon_view = GTK_ICON_VIEW (data);
3404 gtk_icon_view_stop_editing (icon_view, TRUE);
3406 length = gtk_tree_model_iter_n_children (model, NULL);
3408 order = g_new (gint, length);
3409 for (i = 0; i < length; i++)
3410 order [new_order[i]] = i;
3412 item_array = g_new (GtkIconViewItem *, length);
3413 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3414 item_array[order[i]] = list->data;
3417 for (i = length - 1; i >= 0; i--)
3419 item_array[i]->index = i;
3420 items = g_list_prepend (items, item_array[i]);
3423 g_free (item_array);
3424 g_list_free (icon_view->priv->items);
3425 icon_view->priv->items = items;
3427 gtk_icon_view_queue_layout (icon_view);
3429 verify_items (icon_view);
3433 gtk_icon_view_build_items (GtkIconView *icon_view)
3437 gboolean iters_persist;
3438 GList *items = NULL;
3440 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3442 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3450 GtkIconViewItem *item = gtk_icon_view_item_new ();
3459 items = g_list_prepend (items, item);
3461 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3463 icon_view->priv->items = g_list_reverse (items);
3467 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3470 GtkMovementStep step,
3474 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3475 I_("move_cursor"), 2,
3479 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3484 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3487 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3492 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3499 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3500 GtkMovementStep step,
3503 GdkModifierType state;
3505 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3506 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3507 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3508 step == GTK_MOVEMENT_DISPLAY_LINES ||
3509 step == GTK_MOVEMENT_PAGES ||
3510 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3512 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3515 gtk_icon_view_stop_editing (icon_view, FALSE);
3516 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3518 if (gtk_get_current_event_state (&state))
3520 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3521 icon_view->priv->ctrl_pressed = TRUE;
3522 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3523 icon_view->priv->shift_pressed = TRUE;
3525 /* else we assume not pressed */
3529 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3530 case GTK_MOVEMENT_VISUAL_POSITIONS:
3531 gtk_icon_view_move_cursor_left_right (icon_view, count);
3533 case GTK_MOVEMENT_DISPLAY_LINES:
3534 gtk_icon_view_move_cursor_up_down (icon_view, count);
3536 case GTK_MOVEMENT_PAGES:
3537 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3539 case GTK_MOVEMENT_BUFFER_ENDS:
3540 gtk_icon_view_move_cursor_start_end (icon_view, count);
3543 g_assert_not_reached ();
3546 icon_view->priv->ctrl_pressed = FALSE;
3547 icon_view->priv->shift_pressed = FALSE;
3552 static GtkIconViewItem *
3553 find_item (GtkIconView *icon_view,
3554 GtkIconViewItem *current,
3560 GtkIconViewItem *item;
3562 /* FIXME: this could be more efficient
3564 row = current->row + row_ofs;
3565 col = current->col + col_ofs;
3567 for (items = icon_view->priv->items; items; items = items->next)
3570 if (item->row == row && item->col == col)
3578 find_cell (GtkIconView *icon_view,
3579 GtkIconViewItem *item,
3581 GtkOrientation orientation,
3592 if (icon_view->priv->orientation != orientation)
3595 gtk_icon_view_set_cell_data (icon_view, item);
3597 focusable = g_new0 (gint, icon_view->priv->n_cells);
3602 for (k = 0; k < 2; k++)
3603 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3605 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3607 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3610 if (!info->cell->visible)
3613 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3616 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3619 current = n_focusable;
3621 focusable[n_focusable] = i;
3627 if (n_focusable == 0)
3628 focusable[n_focusable++] = first_text;
3632 current = step > 0 ? 0 : n_focusable - 1;
3633 cell = focusable[current];
3636 if (current + *count < 0)
3639 *count = current + *count;
3641 else if (current + *count > n_focusable - 1)
3644 *count = current + *count - (n_focusable - 1);
3648 cell = focusable[current + *count];
3657 static GtkIconViewItem *
3658 find_item_page_up_down (GtkIconView *icon_view,
3659 GtkIconViewItem *current,
3666 y = current->y + count * icon_view->priv->vadjustment->page_size;
3668 item = g_list_find (icon_view->priv->items, current);
3673 for (next = item->next; next; next = next->next)
3675 if (((GtkIconViewItem *)next->data)->col == col)
3678 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3688 for (next = item->prev; next; next = next->prev)
3690 if (((GtkIconViewItem *)next->data)->col == col)
3693 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3707 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3708 GtkIconViewItem *anchor,
3709 GtkIconViewItem *cursor)
3712 GtkIconViewItem *item;
3713 gint row1, row2, col1, col2;
3714 gboolean dirty = FALSE;
3716 if (anchor->row < cursor->row)
3727 if (anchor->col < cursor->col)
3738 for (items = icon_view->priv->items; items; items = items->next)
3742 if (row1 <= item->row && item->row <= row2 &&
3743 col1 <= item->col && item->col <= col2)
3745 if (!item->selected)
3748 item->selected = TRUE;
3750 gtk_icon_view_queue_draw_item (icon_view, item);
3758 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3761 GtkIconViewItem *item;
3763 gboolean dirty = FALSE;
3766 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3769 if (!icon_view->priv->cursor_item)
3774 list = icon_view->priv->items;
3776 list = g_list_last (icon_view->priv->items);
3778 item = list ? list->data : NULL;
3783 item = icon_view->priv->cursor_item;
3784 cell = icon_view->priv->cursor_cell;
3785 step = count > 0 ? 1 : -1;
3788 cell = find_cell (icon_view, item, cell,
3789 GTK_ORIENTATION_VERTICAL,
3794 item = find_item (icon_view, item, step, 0);
3795 count = count - step;
3801 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3805 if (icon_view->priv->ctrl_pressed ||
3806 !icon_view->priv->shift_pressed ||
3807 !icon_view->priv->anchor_item ||
3808 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3809 icon_view->priv->anchor_item = item;
3811 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3813 if (!icon_view->priv->ctrl_pressed &&
3814 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3816 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3817 dirty = gtk_icon_view_select_all_between (icon_view,
3818 icon_view->priv->anchor_item,
3822 gtk_icon_view_scroll_to_item (icon_view, item);
3825 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3829 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3832 GtkIconViewItem *item;
3833 gboolean dirty = FALSE;
3835 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3838 if (!icon_view->priv->cursor_item)
3843 list = icon_view->priv->items;
3845 list = g_list_last (icon_view->priv->items);
3847 item = list ? list->data : NULL;
3850 item = find_item_page_up_down (icon_view,
3851 icon_view->priv->cursor_item,
3854 if (item == icon_view->priv->cursor_item)
3855 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3860 if (icon_view->priv->ctrl_pressed ||
3861 !icon_view->priv->shift_pressed ||
3862 !icon_view->priv->anchor_item ||
3863 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3864 icon_view->priv->anchor_item = item;
3866 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3868 if (!icon_view->priv->ctrl_pressed &&
3869 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3871 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3872 dirty = gtk_icon_view_select_all_between (icon_view,
3873 icon_view->priv->anchor_item,
3877 gtk_icon_view_scroll_to_item (icon_view, item);
3880 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3884 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3887 GtkIconViewItem *item;
3889 gboolean dirty = FALSE;
3892 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3895 if (!icon_view->priv->cursor_item)
3900 list = icon_view->priv->items;
3902 list = g_list_last (icon_view->priv->items);
3904 item = list ? list->data : NULL;
3908 item = icon_view->priv->cursor_item;
3909 cell = icon_view->priv->cursor_cell;
3910 step = count > 0 ? 1 : -1;
3913 cell = find_cell (icon_view, item, cell,
3914 GTK_ORIENTATION_HORIZONTAL,
3919 item = find_item (icon_view, item, 0, step);
3920 count = count - step;
3926 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3930 if (icon_view->priv->ctrl_pressed ||
3931 !icon_view->priv->shift_pressed ||
3932 !icon_view->priv->anchor_item ||
3933 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3934 icon_view->priv->anchor_item = item;
3936 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3938 if (!icon_view->priv->ctrl_pressed &&
3939 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3941 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3942 dirty = gtk_icon_view_select_all_between (icon_view,
3943 icon_view->priv->anchor_item,
3947 gtk_icon_view_scroll_to_item (icon_view, item);
3950 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3954 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3957 GtkIconViewItem *item;
3959 gboolean dirty = FALSE;
3961 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3965 list = icon_view->priv->items;
3967 list = g_list_last (icon_view->priv->items);
3969 item = list ? list->data : NULL;
3971 if (item == icon_view->priv->cursor_item)
3972 gtk_widget_error_bell (GTK_WIDGET (icon_view));
3977 if (icon_view->priv->ctrl_pressed ||
3978 !icon_view->priv->shift_pressed ||
3979 !icon_view->priv->anchor_item ||
3980 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3981 icon_view->priv->anchor_item = item;
3983 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3985 if (!icon_view->priv->ctrl_pressed &&
3986 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3988 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3989 dirty = gtk_icon_view_select_all_between (icon_view,
3990 icon_view->priv->anchor_item,
3994 gtk_icon_view_scroll_to_item (icon_view, item);
3997 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4001 * gtk_icon_view_scroll_to_path:
4002 * @icon_view: A #GtkIconView.
4003 * @path: The path of the item to move to.
4004 * @use_align: whether to use alignment arguments, or %FALSE.
4005 * @row_align: The vertical alignment of the item specified by @path.
4006 * @col_align: The horizontal alignment of the item specified by @path.
4008 * Moves the alignments of @icon_view to the position specified by @path.
4009 * @row_align determines where the row is placed, and @col_align determines
4010 * where @column is placed. Both are expected to be between 0.0 and 1.0.
4011 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
4014 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
4015 * tree does the minimum amount of work to scroll the item onto the screen.
4016 * This means that the item will be scrolled to the edge closest to its current
4017 * position. If the item is currently visible on the screen, nothing is done.
4019 * This function only works if the model is set, and @path is a valid row on
4020 * the model. If the model changes before the @icon_view is realized, the
4021 * centered path will be modified to reflect this change.
4026 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
4032 GtkIconViewItem *item = NULL;
4034 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4035 g_return_if_fail (path != NULL);
4036 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
4037 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
4039 if (gtk_tree_path_get_depth (path) > 0)
4040 item = g_list_nth_data (icon_view->priv->items,
4041 gtk_tree_path_get_indices(path)[0]);
4043 if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
4045 if (icon_view->priv->scroll_to_path)
4046 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4048 icon_view->priv->scroll_to_path = NULL;
4051 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
4053 icon_view->priv->scroll_to_use_align = use_align;
4054 icon_view->priv->scroll_to_row_align = row_align;
4055 icon_view->priv->scroll_to_col_align = col_align;
4064 gfloat offset, value;
4066 gtk_widget_style_get (GTK_WIDGET (icon_view),
4067 "focus-line-width", &focus_width,
4070 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4072 offset = y + item->y - focus_width -
4073 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4074 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4075 icon_view->priv->vadjustment->lower,
4076 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4077 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4079 offset = x + item->x - focus_width -
4080 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4081 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4082 icon_view->priv->hadjustment->lower,
4083 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4084 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4086 gtk_adjustment_changed (icon_view->priv->hadjustment);
4087 gtk_adjustment_changed (icon_view->priv->vadjustment);
4090 gtk_icon_view_scroll_to_item (icon_view, item);
4095 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4096 GtkIconViewItem *item)
4098 gint x, y, width, height;
4101 gtk_widget_style_get (GTK_WIDGET (icon_view),
4102 "focus-line-width", &focus_width,
4105 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4107 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4109 if (y + item->y - focus_width < 0)
4110 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4111 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4112 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4113 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4114 icon_view->priv->vadjustment->value + y + item->y + item->height
4115 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4117 if (x + item->x - focus_width < 0)
4118 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4119 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4120 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4121 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4122 icon_view->priv->hadjustment->value + x + item->x + item->width
4123 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4125 gtk_adjustment_changed (icon_view->priv->hadjustment);
4126 gtk_adjustment_changed (icon_view->priv->vadjustment);
4129 /* GtkCellLayout implementation */
4130 static GtkIconViewCellInfo *
4131 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4132 GtkCellRenderer *renderer)
4136 for (i = icon_view->priv->cell_list; i; i = i->next)
4138 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4140 if (info->cell == renderer)
4148 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4149 GtkIconViewItem *item)
4152 gboolean iters_persist;
4155 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4161 path = gtk_tree_path_new_from_indices (item->index, -1);
4162 if (!gtk_tree_model_get_iter (icon_view->priv->model, &iter, path))
4164 gtk_tree_path_free (path);
4169 for (i = icon_view->priv->cell_list; i; i = i->next)
4172 GtkIconViewCellInfo *info = i->data;
4174 g_object_freeze_notify (G_OBJECT (info->cell));
4176 for (j = info->attributes; j && j->next; j = j->next->next)
4178 gchar *property = j->data;
4179 gint column = GPOINTER_TO_INT (j->next->data);
4180 GValue value = {0, };
4182 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4184 g_object_set_property (G_OBJECT (info->cell),
4186 g_value_unset (&value);
4190 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4192 icon_view->priv->model,
4196 g_object_thaw_notify (G_OBJECT (info->cell));
4199 adjust_wrap_width (icon_view, item);
4203 free_cell_attributes (GtkIconViewCellInfo *info)
4207 list = info->attributes;
4208 while (list && list->next)
4210 g_free (list->data);
4211 list = list->next->next;
4214 g_slist_free (info->attributes);
4215 info->attributes = NULL;
4219 free_cell_info (GtkIconViewCellInfo *info)
4221 free_cell_attributes (info);
4223 g_object_unref (info->cell);
4226 (* info->destroy) (info->func_data);
4232 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4233 GtkCellRenderer *renderer,
4236 GtkIconViewCellInfo *info;
4237 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4239 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4240 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4242 g_object_ref_sink (renderer);
4244 info = g_new0 (GtkIconViewCellInfo, 1);
4245 info->cell = renderer;
4246 info->expand = expand ? TRUE : FALSE;
4247 info->pack = GTK_PACK_START;
4248 info->position = icon_view->priv->n_cells;
4250 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4251 icon_view->priv->n_cells++;
4255 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4256 GtkCellRenderer *renderer,
4259 GtkIconViewCellInfo *info;
4260 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4262 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4263 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4265 g_object_ref_sink (renderer);
4267 info = g_new0 (GtkIconViewCellInfo, 1);
4268 info->cell = renderer;
4269 info->expand = expand ? TRUE : FALSE;
4270 info->pack = GTK_PACK_END;
4271 info->position = icon_view->priv->n_cells;
4273 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4274 icon_view->priv->n_cells++;
4278 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4279 GtkCellRenderer *renderer,
4280 const gchar *attribute,
4283 GtkIconViewCellInfo *info;
4284 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4286 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4287 g_return_if_fail (info != NULL);
4289 info->attributes = g_slist_prepend (info->attributes,
4290 GINT_TO_POINTER (column));
4291 info->attributes = g_slist_prepend (info->attributes,
4292 g_strdup (attribute));
4296 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4298 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4300 while (icon_view->priv->cell_list)
4302 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4303 free_cell_info (info);
4304 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4305 icon_view->priv->cell_list);
4308 icon_view->priv->n_cells = 0;
4312 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4313 GtkCellRenderer *cell,
4314 GtkCellLayoutDataFunc func,
4316 GDestroyNotify destroy)
4318 GtkIconViewCellInfo *info;
4319 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4321 info = gtk_icon_view_get_cell_info (icon_view, cell);
4322 g_return_if_fail (info != NULL);
4326 GDestroyNotify d = info->destroy;
4328 info->destroy = NULL;
4329 d (info->func_data);
4333 info->func_data = func_data;
4334 info->destroy = destroy;
4338 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4339 GtkCellRenderer *renderer)
4341 GtkIconViewCellInfo *info;
4343 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4345 free_cell_attributes (info);
4349 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4350 GtkCellRenderer *cell,
4353 GtkIconView *icon_view;
4355 GtkIconViewCellInfo *info;
4358 icon_view = GTK_ICON_VIEW (layout);
4360 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4362 info = gtk_icon_view_get_cell_info (icon_view, cell);
4364 g_return_if_fail (info != NULL);
4365 g_return_if_fail (position >= 0);
4367 link = g_list_find (icon_view->priv->cell_list, info);
4369 g_return_if_fail (link != NULL);
4371 icon_view->priv->cell_list = g_list_remove_link (icon_view->priv->cell_list,
4373 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4376 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4383 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4387 gtk_icon_view_cell_layout_get_cells (GtkCellLayout *layout)
4389 GtkIconView *icon_view = (GtkIconView *)layout;
4390 GList *retval = NULL, *l;
4392 for (l = icon_view->priv->cell_list; l; l = l->next)
4394 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
4396 retval = g_list_prepend (retval, info->cell);
4399 return g_list_reverse (retval);
4406 * gtk_icon_view_new:
4408 * Creates a new #GtkIconView widget
4410 * Return value: A newly created #GtkIconView widget
4415 gtk_icon_view_new (void)
4417 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4421 * gtk_icon_view_new_with_model:
4422 * @model: The model.
4424 * Creates a new #GtkIconView widget with the model @model.
4426 * Return value: A newly created #GtkIconView widget.
4431 gtk_icon_view_new_with_model (GtkTreeModel *model)
4433 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4438 * gtk_icon_view_get_path_at_pos:
4439 * @icon_view: A #GtkIconView.
4440 * @x: The x position to be identified
4441 * @y: The y position to be identified
4443 * Finds the path at the point (@x, @y), relative to widget coordinates.
4444 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4445 * the cell at the specified position.
4447 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4448 * if no icon exists at that position.
4453 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4457 GtkIconViewItem *item;
4460 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4462 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4467 path = gtk_tree_path_new_from_indices (item->index, -1);
4473 * gtk_icon_view_get_item_at_pos:
4474 * @icon_view: A #GtkIconView.
4475 * @x: The x position to be identified
4476 * @y: The y position to be identified
4477 * @path: Return location for the path, or %NULL
4478 * @cell: Return location for the renderer responsible for the cell
4479 * at (@x, @y), or %NULL
4481 * Finds the path at the point (@x, @y), relative to widget coordinates.
4482 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4483 * obtains the cell at the specified position. The returned path should
4484 * be freed with gtk_tree_path_free().
4486 * Return value: %TRUE if an item exists at the specified position
4491 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4495 GtkCellRenderer **cell)
4497 GtkIconViewItem *item;
4498 GtkIconViewCellInfo *info;
4500 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4502 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4507 *path = gtk_tree_path_new_from_indices (item->index, -1);
4520 return (item != NULL);
4525 * gtk_icon_view_get_visible_range:
4526 * @icon_view: A #GtkIconView
4527 * @start_path: Return location for start of region, or %NULL
4528 * @end_path: Return location for end of region, or %NULL
4530 * Sets @start_path and @end_path to be the first and last visible path.
4531 * Note that there may be invisible paths in between.
4533 * Both paths should be freed with gtk_tree_path_free() after use.
4535 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4540 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4541 GtkTreePath **start_path,
4542 GtkTreePath **end_path)
4544 gint start_index = -1;
4545 gint end_index = -1;
4548 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4550 if (icon_view->priv->hadjustment == NULL ||
4551 icon_view->priv->vadjustment == NULL)
4554 if (start_path == NULL && end_path == NULL)
4557 for (icons = icon_view->priv->items; icons; icons = icons->next)
4559 GtkIconViewItem *item = icons->data;
4561 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4562 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4563 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4564 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4566 if (start_index == -1)
4567 start_index = item->index;
4568 end_index = item->index;
4572 if (start_path && start_index != -1)
4573 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4574 if (end_path && end_index != -1)
4575 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4577 return start_index != -1;
4581 * gtk_icon_view_selected_foreach:
4582 * @icon_view: A #GtkIconView.
4583 * @func: The funcion to call for each selected icon.
4584 * @data: User data to pass to the function.
4586 * Calls a function for each selected icon. Note that the model or
4587 * selection cannot be modified from within this function.
4592 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4593 GtkIconViewForeachFunc func,
4598 for (list = icon_view->priv->items; list; list = list->next)
4600 GtkIconViewItem *item = list->data;
4601 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4604 (* func) (icon_view, path, data);
4606 gtk_tree_path_free (path);
4611 * gtk_icon_view_set_selection_mode:
4612 * @icon_view: A #GtkIconView.
4613 * @mode: The selection mode
4615 * Sets the selection mode of the @icon_view.
4620 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4621 GtkSelectionMode mode)
4623 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4625 if (mode == icon_view->priv->selection_mode)
4628 if (mode == GTK_SELECTION_NONE ||
4629 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4630 gtk_icon_view_unselect_all (icon_view);
4632 icon_view->priv->selection_mode = mode;
4634 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4638 * gtk_icon_view_get_selection_mode:
4639 * @icon_view: A #GtkIconView.
4641 * Gets the selection mode of the @icon_view.
4643 * Return value: the current selection mode
4648 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4650 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4652 return icon_view->priv->selection_mode;
4656 * gtk_icon_view_set_model:
4657 * @icon_view: A #GtkIconView.
4658 * @model: The model.
4660 * Sets the model for a #GtkIconView.
4661 * If the @icon_view already has a model set, it will remove
4662 * it before setting the new model. If @model is %NULL, then
4663 * it will unset the old model.
4668 gtk_icon_view_set_model (GtkIconView *icon_view,
4669 GtkTreeModel *model)
4671 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4672 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4674 if (icon_view->priv->model == model)
4677 if (icon_view->priv->scroll_to_path)
4679 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4680 icon_view->priv->scroll_to_path = NULL;
4683 gtk_icon_view_stop_editing (icon_view, TRUE);
4689 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
4691 if (icon_view->priv->pixbuf_column != -1)
4693 column_type = gtk_tree_model_get_column_type (model,
4694 icon_view->priv->pixbuf_column);
4696 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4699 if (icon_view->priv->text_column != -1)
4701 column_type = gtk_tree_model_get_column_type (model,
4702 icon_view->priv->text_column);
4704 g_return_if_fail (column_type == G_TYPE_STRING);
4707 if (icon_view->priv->markup_column != -1)
4709 column_type = gtk_tree_model_get_column_type (model,
4710 icon_view->priv->markup_column);
4712 g_return_if_fail (column_type == G_TYPE_STRING);
4717 if (icon_view->priv->model)
4719 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4720 gtk_icon_view_row_changed,
4722 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4723 gtk_icon_view_row_inserted,
4725 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4726 gtk_icon_view_row_deleted,
4728 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4729 gtk_icon_view_rows_reordered,
4732 g_object_unref (icon_view->priv->model);
4734 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4735 g_list_free (icon_view->priv->items);
4736 icon_view->priv->items = NULL;
4737 icon_view->priv->anchor_item = NULL;
4738 icon_view->priv->cursor_item = NULL;
4739 icon_view->priv->last_single_clicked = NULL;
4740 icon_view->priv->width = 0;
4741 icon_view->priv->height = 0;
4744 icon_view->priv->model = model;
4746 if (icon_view->priv->model)
4748 g_object_ref (icon_view->priv->model);
4749 g_signal_connect (icon_view->priv->model,
4751 G_CALLBACK (gtk_icon_view_row_changed),
4753 g_signal_connect (icon_view->priv->model,
4755 G_CALLBACK (gtk_icon_view_row_inserted),
4757 g_signal_connect (icon_view->priv->model,
4759 G_CALLBACK (gtk_icon_view_row_deleted),
4761 g_signal_connect (icon_view->priv->model,
4763 G_CALLBACK (gtk_icon_view_rows_reordered),
4766 gtk_icon_view_build_items (icon_view);
4768 gtk_icon_view_queue_layout (icon_view);
4771 g_object_notify (G_OBJECT (icon_view), "model");
4773 if (GTK_WIDGET_REALIZED (icon_view))
4774 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4778 * gtk_icon_view_get_model:
4779 * @icon_view: a #GtkIconView
4781 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4784 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
4789 gtk_icon_view_get_model (GtkIconView *icon_view)
4791 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4793 return icon_view->priv->model;
4797 update_text_cell (GtkIconView *icon_view)
4799 GtkIconViewCellInfo *info;
4803 if (icon_view->priv->text_column == -1 &&
4804 icon_view->priv->markup_column == -1)
4806 if (icon_view->priv->text_cell != -1)
4808 if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
4809 icon_view->priv->pixbuf_cell--;
4811 info = g_list_nth_data (icon_view->priv->cell_list,
4812 icon_view->priv->text_cell);
4814 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
4816 free_cell_info (info);
4818 icon_view->priv->n_cells--;
4819 icon_view->priv->text_cell = -1;
4824 if (icon_view->priv->text_cell == -1)
4826 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
4827 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4828 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4831 if (info->cell == cell)
4833 icon_view->priv->text_cell = i;
4839 info = g_list_nth_data (icon_view->priv->cell_list,
4840 icon_view->priv->text_cell);
4842 if (icon_view->priv->markup_column != -1)
4843 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4845 "markup", icon_view->priv->markup_column,
4848 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4850 "text", icon_view->priv->text_column,
4853 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4854 g_object_set (info->cell,
4855 "alignment", PANGO_ALIGN_CENTER,
4856 "wrap-mode", PANGO_WRAP_WORD,
4857 "wrap-width", icon_view->priv->item_width,
4862 g_object_set (info->cell,
4863 "alignment", PANGO_ALIGN_LEFT,
4864 "wrap-mode", PANGO_WRAP_WORD,
4865 "wrap-width", icon_view->priv->item_width,
4873 update_pixbuf_cell (GtkIconView *icon_view)
4875 GtkIconViewCellInfo *info;
4879 if (icon_view->priv->pixbuf_column == -1)
4881 if (icon_view->priv->pixbuf_cell != -1)
4883 if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
4884 icon_view->priv->text_cell--;
4886 info = g_list_nth_data (icon_view->priv->cell_list,
4887 icon_view->priv->pixbuf_cell);
4889 icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
4891 free_cell_info (info);
4893 icon_view->priv->n_cells--;
4894 icon_view->priv->pixbuf_cell = -1;
4899 if (icon_view->priv->pixbuf_cell == -1)
4901 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
4903 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4904 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4907 if (info->cell == cell)
4909 icon_view->priv->pixbuf_cell = i;
4915 info = g_list_nth_data (icon_view->priv->cell_list,
4916 icon_view->priv->pixbuf_cell);
4918 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4920 "pixbuf", icon_view->priv->pixbuf_column,
4923 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4924 g_object_set (info->cell,
4925 "follow-state", TRUE,
4930 g_object_set (info->cell,
4931 "follow-state", TRUE,
4939 * gtk_icon_view_set_text_column:
4940 * @icon_view: A #GtkIconView.
4941 * @column: A column in the currently used model, or -1 to display no text
4943 * Sets the column with text for @icon_view to be @column. The text
4944 * column must be of type #G_TYPE_STRING.
4949 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4952 if (column == icon_view->priv->text_column)
4956 icon_view->priv->text_column = -1;
4959 if (icon_view->priv->model != NULL)
4963 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4965 g_return_if_fail (column_type == G_TYPE_STRING);
4968 icon_view->priv->text_column = column;
4971 gtk_icon_view_stop_editing (icon_view, TRUE);
4973 update_text_cell (icon_view);
4975 gtk_icon_view_invalidate_sizes (icon_view);
4976 gtk_icon_view_queue_layout (icon_view);
4978 g_object_notify (G_OBJECT (icon_view), "text-column");
4982 * gtk_icon_view_get_text_column:
4983 * @icon_view: A #GtkIconView.
4985 * Returns the column with text for @icon_view.
4987 * Returns: the text column, or -1 if it's unset.
4992 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4994 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4996 return icon_view->priv->text_column;
5000 * gtk_icon_view_set_markup_column:
5001 * @icon_view: A #GtkIconView.
5002 * @column: A column in the currently used model, or -1 to display no text
5004 * Sets the column with markup information for @icon_view to be
5005 * @column. The markup column must be of type #G_TYPE_STRING.
5006 * If the markup column is set to something, it overrides
5007 * the text column set by gtk_icon_view_set_text_column().
5012 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
5015 if (column == icon_view->priv->markup_column)
5019 icon_view->priv->markup_column = -1;
5022 if (icon_view->priv->model != NULL)
5026 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5028 g_return_if_fail (column_type == G_TYPE_STRING);
5031 icon_view->priv->markup_column = column;
5034 gtk_icon_view_stop_editing (icon_view, TRUE);
5036 update_text_cell (icon_view);
5038 gtk_icon_view_invalidate_sizes (icon_view);
5039 gtk_icon_view_queue_layout (icon_view);
5041 g_object_notify (G_OBJECT (icon_view), "markup-column");
5045 * gtk_icon_view_get_markup_column:
5046 * @icon_view: A #GtkIconView.
5048 * Returns the column with markup text for @icon_view.
5050 * Returns: the markup column, or -1 if it's unset.
5055 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
5057 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5059 return icon_view->priv->markup_column;
5063 * gtk_icon_view_set_pixbuf_column:
5064 * @icon_view: A #GtkIconView.
5065 * @column: A column in the currently used model, or -1 to disable
5067 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
5068 * column must be of type #GDK_TYPE_PIXBUF
5073 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
5076 if (column == icon_view->priv->pixbuf_column)
5080 icon_view->priv->pixbuf_column = -1;
5083 if (icon_view->priv->model != NULL)
5087 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
5089 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
5092 icon_view->priv->pixbuf_column = column;
5095 gtk_icon_view_stop_editing (icon_view, TRUE);
5097 update_pixbuf_cell (icon_view);
5099 gtk_icon_view_invalidate_sizes (icon_view);
5100 gtk_icon_view_queue_layout (icon_view);
5102 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5107 * gtk_icon_view_get_pixbuf_column:
5108 * @icon_view: A #GtkIconView.
5110 * Returns the column with pixbufs for @icon_view.
5112 * Returns: the pixbuf column, or -1 if it's unset.
5117 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5119 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5121 return icon_view->priv->pixbuf_column;
5125 * gtk_icon_view_select_path:
5126 * @icon_view: A #GtkIconView.
5127 * @path: The #GtkTreePath to be selected.
5129 * Selects the row at @path.
5134 gtk_icon_view_select_path (GtkIconView *icon_view,
5137 GtkIconViewItem *item = NULL;
5139 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5140 g_return_if_fail (icon_view->priv->model != NULL);
5141 g_return_if_fail (path != NULL);
5143 if (gtk_tree_path_get_depth (path) > 0)
5144 item = g_list_nth_data (icon_view->priv->items,
5145 gtk_tree_path_get_indices(path)[0]);
5148 gtk_icon_view_select_item (icon_view, item);
5152 * gtk_icon_view_unselect_path:
5153 * @icon_view: A #GtkIconView.
5154 * @path: The #GtkTreePath to be unselected.
5156 * Unselects the row at @path.
5161 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5164 GtkIconViewItem *item;
5166 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5167 g_return_if_fail (icon_view->priv->model != NULL);
5168 g_return_if_fail (path != NULL);
5170 item = g_list_nth_data (icon_view->priv->items,
5171 gtk_tree_path_get_indices(path)[0]);
5176 gtk_icon_view_unselect_item (icon_view, item);
5180 * gtk_icon_view_get_selected_items:
5181 * @icon_view: A #GtkIconView.
5183 * Creates a list of paths of all selected items. Additionally, if you are
5184 * planning on modifying the model after calling this function, you may
5185 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5186 * To do this, you can use gtk_tree_row_reference_new().
5188 * To free the return value, use:
5189 * <informalexample><programlisting>
5190 * g_list_foreach (list, gtk_tree_path_free, NULL);
5191 * g_list_free (list);
5192 * </programlisting></informalexample>
5194 * Return value: A #GList containing a #GtkTreePath for each selected row.
5199 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5202 GList *selected = NULL;
5204 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5206 for (list = icon_view->priv->items; list != NULL; list = list->next)
5208 GtkIconViewItem *item = list->data;
5212 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5214 selected = g_list_prepend (selected, path);
5222 * gtk_icon_view_select_all:
5223 * @icon_view: A #GtkIconView.
5225 * Selects all the icons. @icon_view must has its selection mode set
5226 * to #GTK_SELECTION_MULTIPLE.
5231 gtk_icon_view_select_all (GtkIconView *icon_view)
5234 gboolean dirty = FALSE;
5236 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5238 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5241 for (items = icon_view->priv->items; items; items = items->next)
5243 GtkIconViewItem *item = items->data;
5245 if (!item->selected)
5248 item->selected = TRUE;
5249 gtk_icon_view_queue_draw_item (icon_view, item);
5254 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5258 * gtk_icon_view_unselect_all:
5259 * @icon_view: A #GtkIconView.
5261 * Unselects all the icons.
5266 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5268 gboolean dirty = FALSE;
5270 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5272 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5275 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5278 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5282 * gtk_icon_view_path_is_selected:
5283 * @icon_view: A #GtkIconView.
5284 * @path: A #GtkTreePath to check selection on.
5286 * Returns %TRUE if the icon pointed to by @path is currently
5287 * selected. If @path does not point to a valid location, %FALSE is returned.
5289 * Return value: %TRUE if @path is selected.
5294 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5297 GtkIconViewItem *item;
5299 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5300 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5301 g_return_val_if_fail (path != NULL, FALSE);
5303 item = g_list_nth_data (icon_view->priv->items,
5304 gtk_tree_path_get_indices(path)[0]);
5309 return item->selected;
5313 * gtk_icon_view_item_activated:
5314 * @icon_view: A #GtkIconView
5315 * @path: The #GtkTreePath to be activated
5317 * Activates the item determined by @path.
5322 gtk_icon_view_item_activated (GtkIconView *icon_view,
5325 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5326 g_return_if_fail (path != NULL);
5328 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5332 * gtk_icon_view_set_orientation:
5333 * @icon_view: a #GtkIconView
5334 * @orientation: the relative position of texts and icons
5336 * Sets the ::orientation property which determines whether the labels
5337 * are drawn beside the icons instead of below.
5342 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5343 GtkOrientation orientation)
5345 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5347 if (icon_view->priv->orientation != orientation)
5349 icon_view->priv->orientation = orientation;
5351 gtk_icon_view_stop_editing (icon_view, TRUE);
5352 gtk_icon_view_invalidate_sizes (icon_view);
5353 gtk_icon_view_queue_layout (icon_view);
5355 update_text_cell (icon_view);
5356 update_pixbuf_cell (icon_view);
5358 g_object_notify (G_OBJECT (icon_view), "orientation");
5363 * gtk_icon_view_get_orientation:
5364 * @icon_view: a #GtkIconView
5366 * Returns the value of the ::orientation property which determines
5367 * whether the labels are drawn beside the icons instead of below.
5369 * Return value: the relative position of texts and icons
5374 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5376 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5377 GTK_ORIENTATION_VERTICAL);
5379 return icon_view->priv->orientation;
5383 * gtk_icon_view_set_columns:
5384 * @icon_view: a #GtkIconView
5385 * @columns: the number of columns
5387 * Sets the ::columns property which determines in how
5388 * many columns the icons are arranged. If @columns is
5389 * -1, the number of columns will be chosen automatically
5390 * to fill the available area.
5395 gtk_icon_view_set_columns (GtkIconView *icon_view,
5398 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5400 if (icon_view->priv->columns != columns)
5402 icon_view->priv->columns = columns;
5404 gtk_icon_view_stop_editing (icon_view, TRUE);
5405 gtk_icon_view_queue_layout (icon_view);
5407 g_object_notify (G_OBJECT (icon_view), "columns");
5412 * gtk_icon_view_get_columns:
5413 * @icon_view: a #GtkIconView
5415 * Returns the value of the ::columns property.
5417 * Return value: the number of columns, or -1
5422 gtk_icon_view_get_columns (GtkIconView *icon_view)
5424 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5426 return icon_view->priv->columns;
5430 * gtk_icon_view_set_item_width:
5431 * @icon_view: a #GtkIconView
5432 * @item_width: the width for each item
5434 * Sets the ::item-width property which specifies the width
5435 * to use for each item. If it is set to -1, the icon view will
5436 * automatically determine a suitable item size.
5441 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5444 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5446 if (icon_view->priv->item_width != item_width)
5448 icon_view->priv->item_width = item_width;
5450 gtk_icon_view_stop_editing (icon_view, TRUE);
5451 gtk_icon_view_invalidate_sizes (icon_view);
5452 gtk_icon_view_queue_layout (icon_view);
5454 update_text_cell (icon_view);
5456 g_object_notify (G_OBJECT (icon_view), "item-width");
5461 * gtk_icon_view_get_item_width:
5462 * @icon_view: a #GtkIconView
5464 * Returns the value of the ::item-width property.
5466 * Return value: the width of a single item, or -1
5471 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5473 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5475 return icon_view->priv->item_width;
5480 * gtk_icon_view_set_spacing:
5481 * @icon_view: a #GtkIconView
5482 * @spacing: the spacing
5484 * Sets the ::spacing property which specifies the space
5485 * which is inserted between the cells (i.e. the icon and
5486 * the text) of an item.
5491 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5494 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5496 if (icon_view->priv->spacing != spacing)
5498 icon_view->priv->spacing = spacing;
5500 gtk_icon_view_stop_editing (icon_view, TRUE);
5501 gtk_icon_view_invalidate_sizes (icon_view);
5502 gtk_icon_view_queue_layout (icon_view);
5504 g_object_notify (G_OBJECT (icon_view), "spacing");
5509 * gtk_icon_view_get_spacing:
5510 * @icon_view: a #GtkIconView
5512 * Returns the value of the ::spacing property.
5514 * Return value: the space between cells
5519 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5521 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5523 return icon_view->priv->spacing;
5527 * gtk_icon_view_set_row_spacing:
5528 * @icon_view: a #GtkIconView
5529 * @row_spacing: the row spacing
5531 * Sets the ::row-spacing property which specifies the space
5532 * which is inserted between the rows of the icon view.
5537 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5540 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5542 if (icon_view->priv->row_spacing != row_spacing)
5544 icon_view->priv->row_spacing = row_spacing;
5546 gtk_icon_view_stop_editing (icon_view, TRUE);
5547 gtk_icon_view_invalidate_sizes (icon_view);
5548 gtk_icon_view_queue_layout (icon_view);
5550 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5555 * gtk_icon_view_get_row_spacing:
5556 * @icon_view: a #GtkIconView
5558 * Returns the value of the ::row-spacing property.
5560 * Return value: the space between rows
5565 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5567 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5569 return icon_view->priv->row_spacing;
5573 * gtk_icon_view_set_column_spacing:
5574 * @icon_view: a #GtkIconView
5575 * @column_spacing: the column spacing
5577 * Sets the ::column-spacing property which specifies the space
5578 * which is inserted between the columns of the icon view.
5583 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5584 gint column_spacing)
5586 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5588 if (icon_view->priv->column_spacing != column_spacing)
5590 icon_view->priv->column_spacing = column_spacing;
5592 gtk_icon_view_stop_editing (icon_view, TRUE);
5593 gtk_icon_view_invalidate_sizes (icon_view);
5594 gtk_icon_view_queue_layout (icon_view);
5596 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5601 * gtk_icon_view_get_column_spacing:
5602 * @icon_view: a #GtkIconView
5604 * Returns the value of the ::column-spacing property.
5606 * Return value: the space between columns
5611 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5613 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5615 return icon_view->priv->column_spacing;
5619 * gtk_icon_view_set_margin:
5620 * @icon_view: a #GtkIconView
5621 * @margin: the margin
5623 * Sets the ::margin property which specifies the space
5624 * which is inserted at the top, bottom, left and right
5630 gtk_icon_view_set_margin (GtkIconView *icon_view,
5633 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5635 if (icon_view->priv->margin != margin)
5637 icon_view->priv->margin = margin;
5639 gtk_icon_view_stop_editing (icon_view, TRUE);
5640 gtk_icon_view_invalidate_sizes (icon_view);
5641 gtk_icon_view_queue_layout (icon_view);
5643 g_object_notify (G_OBJECT (icon_view), "margin");
5648 * gtk_icon_view_get_margin:
5649 * @icon_view: a #GtkIconView
5651 * Returns the value of the ::margin property.
5653 * Return value: the space at the borders
5658 gtk_icon_view_get_margin (GtkIconView *icon_view)
5660 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5662 return icon_view->priv->margin;
5666 /* Get/set whether drag_motion requested the drag data and
5667 * drag_data_received should thus not actually insert the data,
5668 * since the data doesn't result from a drop.
5671 set_status_pending (GdkDragContext *context,
5672 GdkDragAction suggested_action)
5674 g_object_set_data (G_OBJECT (context),
5675 I_("gtk-icon-view-status-pending"),
5676 GINT_TO_POINTER (suggested_action));
5679 static GdkDragAction
5680 get_status_pending (GdkDragContext *context)
5682 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5683 "gtk-icon-view-status-pending"));
5687 unset_reorderable (GtkIconView *icon_view)
5689 if (icon_view->priv->reorderable)
5691 icon_view->priv->reorderable = FALSE;
5692 g_object_notify (G_OBJECT (icon_view), "reorderable");
5697 clear_source_info (GtkIconView *icon_view)
5699 if (icon_view->priv->source_targets)
5700 gtk_target_list_unref (icon_view->priv->source_targets);
5701 icon_view->priv->source_targets = NULL;
5703 icon_view->priv->source_set = FALSE;
5707 clear_dest_info (GtkIconView *icon_view)
5709 if (icon_view->priv->dest_targets)
5710 gtk_target_list_unref (icon_view->priv->dest_targets);
5711 icon_view->priv->dest_targets = NULL;
5713 icon_view->priv->dest_set = FALSE;
5717 set_source_row (GdkDragContext *context,
5718 GtkTreeModel *model,
5719 GtkTreePath *source_row)
5722 g_object_set_data_full (G_OBJECT (context),
5723 I_("gtk-icon-view-source-row"),
5724 gtk_tree_row_reference_new (model, source_row),
5725 (GDestroyNotify) gtk_tree_row_reference_free);
5727 g_object_set_data_full (G_OBJECT (context),
5728 I_("gtk-icon-view-source-row"),
5733 get_source_row (GdkDragContext *context)
5735 GtkTreeRowReference *ref;
5737 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5740 return gtk_tree_row_reference_get_path (ref);
5747 GtkTreeRowReference *dest_row;
5748 gboolean empty_view_drop;
5749 gboolean drop_append_mode;
5753 dest_row_free (gpointer data)
5755 DestRow *dr = (DestRow *)data;
5757 gtk_tree_row_reference_free (dr->dest_row);
5762 set_dest_row (GdkDragContext *context,
5763 GtkTreeModel *model,
5764 GtkTreePath *dest_row,
5765 gboolean empty_view_drop,
5766 gboolean drop_append_mode)
5772 g_object_set_data_full (G_OBJECT (context),
5773 I_("gtk-icon-view-dest-row"),
5778 dr = g_new0 (DestRow, 1);
5780 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5781 dr->empty_view_drop = empty_view_drop;
5782 dr->drop_append_mode = drop_append_mode;
5783 g_object_set_data_full (G_OBJECT (context),
5784 I_("gtk-icon-view-dest-row"),
5785 dr, (GDestroyNotify) dest_row_free);
5789 get_dest_row (GdkDragContext *context)
5793 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5797 GtkTreePath *path = NULL;
5800 path = gtk_tree_row_reference_get_path (dr->dest_row);
5801 else if (dr->empty_view_drop)
5802 path = gtk_tree_path_new_from_indices (0, -1);
5806 if (path && dr->drop_append_mode)
5807 gtk_tree_path_next (path);
5816 check_model_dnd (GtkTreeModel *model,
5817 GType required_iface,
5818 const gchar *signal)
5820 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5822 g_warning ("You must override the default '%s' handler "
5823 "on GtkIconView when using models that don't support "
5824 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5825 "is to connect to '%s' and call "
5826 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5827 "the default handler from running. Look at the source code "
5828 "for the default handler in gtkiconview.c to get an idea what "
5829 "your handler should do. (gtkiconview.c is in the GTK+ source "
5830 "code.) If you're using GTK+ from a language other than C, "
5831 "there may be a more natural way to override default handlers, e.g. via derivation.",
5832 signal, g_type_name (required_iface), signal);
5840 remove_scroll_timeout (GtkIconView *icon_view)
5842 if (icon_view->priv->scroll_timeout_id != 0)
5844 g_source_remove (icon_view->priv->scroll_timeout_id);
5846 icon_view->priv->scroll_timeout_id = 0;
5851 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5853 gint px, py, x, y, width, height;
5854 gint hoffset, voffset;
5857 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
5858 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
5860 /* see if we are near the edge. */
5861 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5863 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5865 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5867 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5871 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
5872 icon_view->priv->vadjustment->lower,
5873 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
5874 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
5878 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
5879 icon_view->priv->hadjustment->lower,
5880 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
5881 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
5887 drag_scroll_timeout (gpointer data)
5889 GtkIconView *icon_view = GTK_ICON_VIEW (data);
5891 gtk_icon_view_autoscroll (icon_view);
5898 set_destination (GtkIconView *icon_view,
5899 GdkDragContext *context,
5902 GdkDragAction *suggested_action,
5906 GtkTreePath *path = NULL;
5907 GtkIconViewDropPosition pos;
5908 GtkIconViewDropPosition old_pos;
5909 GtkTreePath *old_dest_path = NULL;
5910 gboolean can_drop = FALSE;
5912 widget = GTK_WIDGET (icon_view);
5914 *suggested_action = 0;
5917 if (!icon_view->priv->dest_set)
5919 /* someone unset us as a drag dest, note that if
5920 * we return FALSE drag_leave isn't called
5923 gtk_icon_view_set_drag_dest_item (icon_view,
5925 GTK_ICON_VIEW_DROP_LEFT);
5927 remove_scroll_timeout (GTK_ICON_VIEW (widget));
5929 return FALSE; /* no longer a drop site */
5932 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
5933 if (*target == GDK_NONE)
5936 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
5939 GtkTreeModel *model;
5941 /* the row got dropped on empty space, let's setup a special case
5945 gtk_tree_path_free (path);
5947 model = gtk_icon_view_get_model (icon_view);
5949 n_children = gtk_tree_model_iter_n_children (model, NULL);
5952 pos = GTK_ICON_VIEW_DROP_BELOW;
5953 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5957 pos = GTK_ICON_VIEW_DROP_ABOVE;
5958 path = gtk_tree_path_new_from_indices (0, -1);
5968 gtk_icon_view_get_drag_dest_item (icon_view,
5973 gtk_tree_path_free (old_dest_path);
5975 if (TRUE /* FIXME if the location droppable predicate */)
5983 GtkWidget *source_widget;
5985 *suggested_action = context->suggested_action;
5986 source_widget = gtk_drag_get_source_widget (context);
5988 if (source_widget == widget)
5990 /* Default to MOVE, unless the user has
5991 * pressed ctrl or shift to affect available actions
5993 if ((context->actions & GDK_ACTION_MOVE) != 0)
5994 *suggested_action = GDK_ACTION_MOVE;
5997 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6002 /* can't drop here */
6003 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
6005 GTK_ICON_VIEW_DROP_LEFT);
6009 gtk_tree_path_free (path);
6015 get_logical_destination (GtkIconView *icon_view,
6016 gboolean *drop_append_mode)
6018 /* adjust path to point to the row the drop goes in front of */
6019 GtkTreePath *path = NULL;
6020 GtkIconViewDropPosition pos;
6022 *drop_append_mode = FALSE;
6024 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6029 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
6030 pos == GTK_ICON_VIEW_DROP_BELOW)
6033 GtkTreeModel *model = icon_view->priv->model;
6035 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6036 !gtk_tree_model_iter_next (model, &iter))
6037 *drop_append_mode = TRUE;
6040 *drop_append_mode = FALSE;
6041 gtk_tree_path_next (path);
6049 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
6050 GdkEventMotion *event)
6052 GdkDragContext *context;
6053 GtkTreePath *path = NULL;
6055 GtkTreeModel *model;
6056 gboolean retval = FALSE;
6058 if (!icon_view->priv->source_set)
6061 if (icon_view->priv->pressed_button < 0)
6064 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
6065 icon_view->priv->press_start_x,
6066 icon_view->priv->press_start_y,
6067 event->x, event->y))
6070 model = gtk_icon_view_get_model (icon_view);
6075 button = icon_view->priv->pressed_button;
6076 icon_view->priv->pressed_button = -1;
6078 path = gtk_icon_view_get_path_at_pos (icon_view,
6079 icon_view->priv->press_start_x,
6080 icon_view->priv->press_start_y);
6085 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6086 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6090 /* FIXME Check whether we're a start button, if not return FALSE and
6094 /* Now we can begin the drag */
6098 context = gtk_drag_begin (GTK_WIDGET (icon_view),
6099 icon_view->priv->source_targets,
6100 icon_view->priv->source_actions,
6104 set_source_row (context, model, path);
6108 gtk_tree_path_free (path);
6113 /* Source side drag signals */
6115 gtk_icon_view_drag_begin (GtkWidget *widget,
6116 GdkDragContext *context)
6118 GtkIconView *icon_view;
6119 GtkIconViewItem *item;
6124 icon_view = GTK_ICON_VIEW (widget);
6126 /* if the user uses a custom DnD impl, we don't set the icon here */
6127 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6130 item = gtk_icon_view_get_item_at_coords (icon_view,
6131 icon_view->priv->press_start_x,
6132 icon_view->priv->press_start_y,
6136 g_return_if_fail (item != NULL);
6138 x = icon_view->priv->press_start_x - item->x + 1;
6139 y = icon_view->priv->press_start_y - item->y + 1;
6141 path = gtk_tree_path_new_from_indices (item->index, -1);
6142 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6143 gtk_tree_path_free (path);
6145 gtk_drag_set_icon_pixmap (context,
6146 gdk_drawable_get_colormap (icon),
6151 g_object_unref (icon);
6155 gtk_icon_view_drag_end (GtkWidget *widget,
6156 GdkDragContext *context)
6162 gtk_icon_view_drag_data_get (GtkWidget *widget,
6163 GdkDragContext *context,
6164 GtkSelectionData *selection_data,
6168 GtkIconView *icon_view;
6169 GtkTreeModel *model;
6170 GtkTreePath *source_row;
6172 icon_view = GTK_ICON_VIEW (widget);
6173 model = gtk_icon_view_get_model (icon_view);
6178 if (!icon_view->priv->dest_set)
6181 source_row = get_source_row (context);
6183 if (source_row == NULL)
6186 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6187 * any model; for DragSource models there are some other targets
6191 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6192 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6197 /* If drag_data_get does nothing, try providing row data. */
6198 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6199 gtk_tree_set_row_drag_data (selection_data,
6204 gtk_tree_path_free (source_row);
6208 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6209 GdkDragContext *context)
6211 GtkTreeModel *model;
6212 GtkIconView *icon_view;
6213 GtkTreePath *source_row;
6215 icon_view = GTK_ICON_VIEW (widget);
6216 model = gtk_icon_view_get_model (icon_view);
6218 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6221 if (!icon_view->priv->dest_set)
6224 source_row = get_source_row (context);
6226 if (source_row == NULL)
6229 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6232 gtk_tree_path_free (source_row);
6234 set_source_row (context, NULL, NULL);
6237 /* Target side drag signals */
6239 gtk_icon_view_drag_leave (GtkWidget *widget,
6240 GdkDragContext *context,
6243 GtkIconView *icon_view;
6245 icon_view = GTK_ICON_VIEW (widget);
6247 /* unset any highlight row */
6248 gtk_icon_view_set_drag_dest_item (icon_view,
6250 GTK_ICON_VIEW_DROP_LEFT);
6252 remove_scroll_timeout (icon_view);
6256 gtk_icon_view_drag_motion (GtkWidget *widget,
6257 GdkDragContext *context,
6262 GtkTreePath *path = NULL;
6263 GtkIconViewDropPosition pos;
6264 GtkIconView *icon_view;
6265 GdkDragAction suggested_action = 0;
6269 icon_view = GTK_ICON_VIEW (widget);
6271 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6274 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6276 /* we only know this *after* set_desination_row */
6277 empty = icon_view->priv->empty_view_drop;
6279 if (path == NULL && !empty)
6281 /* Can't drop here. */
6282 gdk_drag_status (context, 0, time);
6286 if (icon_view->priv->scroll_timeout_id == 0)
6288 icon_view->priv->scroll_timeout_id =
6289 gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
6292 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6294 /* Request data so we can use the source row when
6295 * determining whether to accept the drop
6297 set_status_pending (context, suggested_action);
6298 gtk_drag_get_data (widget, context, target, time);
6302 set_status_pending (context, 0);
6303 gdk_drag_status (context, suggested_action, time);
6308 gtk_tree_path_free (path);
6314 gtk_icon_view_drag_drop (GtkWidget *widget,
6315 GdkDragContext *context,
6320 GtkIconView *icon_view;
6322 GdkDragAction suggested_action = 0;
6323 GdkAtom target = GDK_NONE;
6324 GtkTreeModel *model;
6325 gboolean drop_append_mode;
6327 icon_view = GTK_ICON_VIEW (widget);
6328 model = gtk_icon_view_get_model (icon_view);
6330 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6332 if (!icon_view->priv->dest_set)
6335 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6338 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6341 path = get_logical_destination (icon_view, &drop_append_mode);
6343 if (target != GDK_NONE && path != NULL)
6345 /* in case a motion had requested drag data, change things so we
6346 * treat drag data receives as a drop.
6348 set_status_pending (context, 0);
6349 set_dest_row (context, model, path,
6350 icon_view->priv->empty_view_drop, drop_append_mode);
6354 gtk_tree_path_free (path);
6356 /* Unset this thing */
6357 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6359 if (target != GDK_NONE)
6361 gtk_drag_get_data (widget, context, target, time);
6369 gtk_icon_view_drag_data_received (GtkWidget *widget,
6370 GdkDragContext *context,
6373 GtkSelectionData *selection_data,
6378 gboolean accepted = FALSE;
6379 GtkTreeModel *model;
6380 GtkIconView *icon_view;
6381 GtkTreePath *dest_row;
6382 GdkDragAction suggested_action;
6383 gboolean drop_append_mode;
6385 icon_view = GTK_ICON_VIEW (widget);
6386 model = gtk_icon_view_get_model (icon_view);
6388 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6391 if (!icon_view->priv->dest_set)
6394 suggested_action = get_status_pending (context);
6396 if (suggested_action)
6398 /* We are getting this data due to a request in drag_motion,
6399 * rather than due to a request in drag_drop, so we are just
6400 * supposed to call drag_status, not actually paste in the
6403 path = get_logical_destination (icon_view, &drop_append_mode);
6406 suggested_action = 0;
6408 if (suggested_action)
6410 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6413 suggested_action = 0;
6416 gdk_drag_status (context, suggested_action, time);
6419 gtk_tree_path_free (path);
6421 /* If you can't drop, remove user drop indicator until the next motion */
6422 if (suggested_action == 0)
6423 gtk_icon_view_set_drag_dest_item (icon_view,
6425 GTK_ICON_VIEW_DROP_LEFT);
6430 dest_row = get_dest_row (context);
6432 if (dest_row == NULL)
6435 if (selection_data->length >= 0)
6437 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6443 gtk_drag_finish (context,
6445 (context->action == GDK_ACTION_MOVE),
6448 gtk_tree_path_free (dest_row);
6451 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6454 /* Drag-and-Drop support */
6456 * gtk_icon_view_enable_model_drag_source:
6457 * @icon_view: a #GtkIconTreeView
6458 * @start_button_mask: Mask of allowed buttons to start drag
6459 * @targets: the table of targets that the drag will support
6460 * @n_targets: the number of items in @targets
6461 * @actions: the bitmask of possible actions for a drag from this
6464 * Turns @icon_view into a drag source for automatic DND.
6469 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6470 GdkModifierType start_button_mask,
6471 const GtkTargetEntry *targets,
6473 GdkDragAction actions)
6475 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6477 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6479 clear_source_info (icon_view);
6480 icon_view->priv->start_button_mask = start_button_mask;
6481 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6482 icon_view->priv->source_actions = actions;
6484 icon_view->priv->source_set = TRUE;
6486 unset_reorderable (icon_view);
6490 * gtk_icon_view_enable_model_drag_dest:
6491 * @icon_view: a #GtkIconView
6492 * @targets: the table of targets that the drag will support
6493 * @n_targets: the number of items in @targets
6494 * @actions: the bitmask of possible actions for a drag to this
6497 * Turns @icon_view into a drop destination for automatic DND.
6502 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6503 const GtkTargetEntry *targets,
6505 GdkDragAction actions)
6507 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6509 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6511 clear_dest_info (icon_view);
6513 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6514 icon_view->priv->dest_actions = actions;
6516 icon_view->priv->dest_set = TRUE;
6518 unset_reorderable (icon_view);
6522 * gtk_icon_view_unset_model_drag_source:
6523 * @icon_view: a #GtkIconView
6525 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6530 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6532 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6534 if (icon_view->priv->source_set)
6536 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6537 clear_source_info (icon_view);
6540 unset_reorderable (icon_view);
6544 * gtk_icon_view_unset_model_drag_dest:
6545 * @icon_view: a #GtkIconView
6547 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6552 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6554 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6556 if (icon_view->priv->dest_set)
6558 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6559 clear_dest_info (icon_view);
6562 unset_reorderable (icon_view);
6565 /* These are useful to implement your own custom stuff. */
6567 * gtk_icon_view_set_drag_dest_item:
6568 * @icon_view: a #GtkIconView
6569 * @path: The path of the item to highlight, or %NULL.
6570 * @pos: Specifies where to drop, relative to the item
6572 * Sets the item that is highlighted for feedback.
6577 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6579 GtkIconViewDropPosition pos)
6581 /* Note; this function is exported to allow a custom DND
6582 * implementation, so it can't touch TreeViewDragInfo
6585 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6587 if (icon_view->priv->dest_item)
6589 GtkTreePath *current_path;
6590 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6591 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6592 icon_view->priv->dest_item = NULL;
6594 gtk_icon_view_queue_draw_path (icon_view, current_path);
6595 gtk_tree_path_free (current_path);
6598 /* special case a drop on an empty model */
6599 icon_view->priv->empty_view_drop = FALSE;
6600 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
6601 && gtk_tree_path_get_depth (path) == 1
6602 && gtk_tree_path_get_indices (path)[0] == 0)
6606 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6609 if (n_children == 0)
6610 icon_view->priv->empty_view_drop = TRUE;
6613 icon_view->priv->dest_pos = pos;
6617 icon_view->priv->dest_item =
6618 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6619 icon_view->priv->model, path);
6621 gtk_icon_view_queue_draw_path (icon_view, path);
6626 * gtk_icon_view_get_drag_dest_item:
6627 * @icon_view: a #GtkIconView
6628 * @path: Return location for the path of the highlighted item, or %NULL.
6629 * @pos: Return location for the drop position, or %NULL
6631 * Gets information about the item that is highlighted for feedback.
6636 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6638 GtkIconViewDropPosition *pos)
6640 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6644 if (icon_view->priv->dest_item)
6645 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6651 *pos = icon_view->priv->dest_pos;
6655 * gtk_icon_view_get_dest_item_at_pos:
6656 * @icon_view: a #GtkIconView
6657 * @drag_x: the position to determine the destination item for
6658 * @drag_y: the position to determine the destination item for
6659 * @path: Return location for the path of the item, or %NULL.
6660 * @pos: Return location for the drop position, or %NULL
6662 * Determines the destination item for a given position.
6664 * Return value: whether there is an item at the given position.
6669 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6673 GtkIconViewDropPosition *pos)
6675 GtkIconViewItem *item;
6677 /* Note; this function is exported to allow a custom DND
6678 * implementation, so it can't touch TreeViewDragInfo
6681 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6682 g_return_val_if_fail (drag_x >= 0, FALSE);
6683 g_return_val_if_fail (drag_y >= 0, FALSE);
6684 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6690 item = gtk_icon_view_get_item_at_coords (icon_view,
6691 drag_x + icon_view->priv->hadjustment->value,
6692 drag_y + icon_view->priv->vadjustment->value,
6699 *path = gtk_tree_path_new_from_indices (item->index, -1);
6703 if (drag_x < item->x + item->width / 4)
6704 *pos = GTK_ICON_VIEW_DROP_LEFT;
6705 else if (drag_x > item->x + item->width * 3 / 4)
6706 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6707 else if (drag_y < item->y + item->height / 4)
6708 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6709 else if (drag_y > item->y + item->height * 3 / 4)
6710 *pos = GTK_ICON_VIEW_DROP_BELOW;
6712 *pos = GTK_ICON_VIEW_DROP_INTO;
6719 * gtk_icon_view_create_drag_icon:
6720 * @icon_view: a #GtkIconView
6721 * @path: a #GtkTreePath in @icon_view
6723 * Creates a #GdkPixmap representation of the item at @path.
6724 * This image is used for a drag icon.
6726 * Return value: a newly-allocated pixmap of the drag icon.
6731 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6736 GdkPixmap *drawable;
6741 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
6742 g_return_val_if_fail (path != NULL, NULL);
6744 widget = GTK_WIDGET (icon_view);
6746 if (!GTK_WIDGET_REALIZED (widget))
6749 index = gtk_tree_path_get_indices (path)[0];
6751 for (l = icon_view->priv->items; l; l = l->next)
6753 GtkIconViewItem *item = l->data;
6755 if (index == item->index)
6757 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
6762 cr = gdk_cairo_create (drawable);
6763 cairo_set_line_width (cr, 1.);
6765 gdk_cairo_set_source_color
6766 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
6767 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
6772 area.width = item->width;
6773 area.height = item->height;
6775 gtk_icon_view_paint_item (icon_view, cr, item, &area,
6776 drawable, 1, 1, FALSE);
6778 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6779 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
6792 * gtk_icon_view_get_reorderable:
6793 * @icon_view: a #GtkIconView
6795 * Retrieves whether the user can reorder the list via drag-and-drop.
6796 * See gtk_icon_view_set_reorderable().
6798 * Return value: %TRUE if the list can be reordered.
6803 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6805 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6807 return icon_view->priv->reorderable;
6810 static const GtkTargetEntry item_targets[] = {
6811 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6816 * gtk_icon_view_set_reorderable:
6817 * @icon_view: A #GtkIconView.
6818 * @reorderable: %TRUE, if the list of items can be reordered.
6820 * This function is a convenience function to allow you to reorder models that
6821 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6822 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6823 * the user can reorder the model by dragging and dropping rows. The
6824 * developer can listen to these changes by connecting to the model's
6825 * row_inserted and row_deleted signals.
6827 * This function does not give you any degree of control over the order -- any
6828 * reordering is allowed. If more control is needed, you should probably
6829 * handle drag and drop manually.
6834 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6835 gboolean reorderable)
6837 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6839 reorderable = reorderable != FALSE;
6841 if (icon_view->priv->reorderable == reorderable)
6846 gtk_icon_view_enable_model_drag_source (icon_view,
6849 G_N_ELEMENTS (item_targets),
6851 gtk_icon_view_enable_model_drag_dest (icon_view,
6853 G_N_ELEMENTS (item_targets),
6858 gtk_icon_view_unset_model_drag_source (icon_view);
6859 gtk_icon_view_unset_model_drag_dest (icon_view);
6862 icon_view->priv->reorderable = reorderable;
6864 g_object_notify (G_OBJECT (icon_view), "reorderable");
6868 /* Accessibility Support */
6870 static gpointer accessible_parent_class;
6871 static gpointer accessible_item_parent_class;
6872 static GQuark accessible_private_data_quark = 0;
6874 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6875 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6876 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6878 static GType gtk_icon_view_item_accessible_get_type (void);
6889 GtkIconViewItem *item;
6893 AtkStateSet *state_set;
6897 GtkTextBuffer *text_buffer;
6899 gchar *action_descriptions[LAST_ACTION];
6900 gchar *image_description;
6901 guint action_idle_handler;
6902 } GtkIconViewItemAccessible;
6904 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
6910 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
6915 typedef struct _GtkIconViewItemAccessibleClass
6917 AtkObjectClass parent_class;
6919 } GtkIconViewItemAccessibleClass;
6921 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
6924 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
6926 GtkIconViewItemAccessible *item;
6927 GtkIconView *icon_view;
6930 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
6931 item->action_idle_handler = 0;
6933 if (item->widget != NULL)
6935 icon_view = GTK_ICON_VIEW (item->widget);
6936 path = gtk_tree_path_new_from_indices (item->item->index, -1);
6937 gtk_icon_view_item_activated (icon_view, path);
6938 gtk_tree_path_free (path);
6945 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
6948 GtkIconViewItemAccessible *item;
6950 if (i < 0 || i >= LAST_ACTION)
6953 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6955 if (!GTK_IS_ICON_VIEW (item->widget))
6958 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6963 case ACTION_ACTIVATE:
6964 if (!item->action_idle_handler)
6965 item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
6968 g_assert_not_reached ();
6976 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
6981 static const gchar *
6982 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
6985 GtkIconViewItemAccessible *item;
6987 if (i < 0 || i >= LAST_ACTION)
6990 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6992 if (item->action_descriptions[i])
6993 return item->action_descriptions[i];
6995 return gtk_icon_view_item_accessible_action_descriptions[i];
6998 static const gchar *
6999 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
7002 if (i < 0 || i >= LAST_ACTION)
7005 return gtk_icon_view_item_accessible_action_names[i];
7009 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
7011 const gchar *description)
7013 GtkIconViewItemAccessible *item;
7015 if (i < 0 || i >= LAST_ACTION)
7018 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
7020 g_free (item->action_descriptions[i]);
7022 item->action_descriptions[i] = g_strdup (description);
7028 atk_action_item_interface_init (AtkActionIface *iface)
7030 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
7031 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
7032 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
7033 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
7034 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
7037 static const gchar *
7038 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
7040 GtkIconViewItemAccessible *item;
7042 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7044 return item->image_description;
7048 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
7049 const gchar *description)
7051 GtkIconViewItemAccessible *item;
7053 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7055 g_free (item->image_description);
7056 item->image_description = g_strdup (item->image_description);
7062 get_pixbuf_box (GtkIconView *icon_view,
7063 GtkIconViewItem *item,
7068 for (l = icon_view->priv->cell_list; l; l = l->next)
7070 GtkIconViewCellInfo *info = l->data;
7072 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
7074 gtk_icon_view_get_cell_box (icon_view, item, info, box);
7084 get_text (GtkIconView *icon_view,
7085 GtkIconViewItem *item)
7090 for (l = icon_view->priv->cell_list; l; l = l->next)
7092 GtkIconViewCellInfo *info = l->data;
7094 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7096 g_object_get (info->cell, "text", &text, NULL);
7106 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7110 GtkIconViewItemAccessible *item;
7113 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7115 if (!GTK_IS_ICON_VIEW (item->widget))
7118 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7121 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7124 *height = box.height;
7129 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7132 AtkCoordType coord_type)
7134 GtkIconViewItemAccessible *item;
7137 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7139 if (!GTK_IS_ICON_VIEW (item->widget))
7142 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7145 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7147 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7149 *x+= box.x - item->item->x;
7150 *y+= box.y - item->item->y;
7156 atk_image_item_interface_init (AtkImageIface *iface)
7158 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7159 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7160 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7161 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7165 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7169 GtkIconViewItemAccessible *item;
7170 GtkTextIter start, end;
7171 GtkTextBuffer *buffer;
7173 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7175 if (!GTK_IS_ICON_VIEW (item->widget))
7178 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7181 buffer = item->text_buffer;
7182 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7184 gtk_text_buffer_get_end_iter (buffer, &end);
7186 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7188 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7192 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7195 GtkIconViewItemAccessible *item;
7196 GtkTextIter start, end;
7197 GtkTextBuffer *buffer;
7201 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7203 if (!GTK_IS_ICON_VIEW (item->widget))
7206 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7209 buffer = item->text_buffer;
7210 if (offset >= gtk_text_buffer_get_char_count (buffer))
7213 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7215 gtk_text_iter_forward_char (&end);
7216 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7217 unichar = g_utf8_get_char (string);
7225 get_pango_text_offsets (PangoLayout *layout,
7226 GtkTextBuffer *buffer,
7228 AtkTextBoundary boundary_type,
7232 GtkTextIter *start_iter,
7233 GtkTextIter *end_iter)
7235 PangoLayoutIter *iter;
7236 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7237 gint index, start_index, end_index;
7239 gboolean found = FALSE;
7241 text = pango_layout_get_text (layout);
7242 index = g_utf8_offset_to_pointer (text, offset) - text;
7243 iter = pango_layout_get_iter (layout);
7246 line = pango_layout_iter_get_line_readonly (iter);
7247 start_index = line->start_index;
7248 end_index = start_index + line->length;
7250 if (index >= start_index && index <= end_index)
7253 * Found line for offset
7259 * We want the previous line
7263 switch (boundary_type)
7265 case ATK_TEXT_BOUNDARY_LINE_START:
7266 end_index = start_index;
7267 start_index = prev_line->start_index;
7269 case ATK_TEXT_BOUNDARY_LINE_END:
7271 start_index = prev_prev_line->start_index +
7272 prev_prev_line->length;
7273 end_index = prev_line->start_index + prev_line->length;
7276 g_assert_not_reached();
7280 start_index = end_index = 0;
7283 switch (boundary_type)
7285 case ATK_TEXT_BOUNDARY_LINE_START:
7286 if (pango_layout_iter_next_line (iter))
7287 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7289 case ATK_TEXT_BOUNDARY_LINE_END:
7291 start_index = prev_line->start_index +
7295 g_assert_not_reached();
7300 * We want the next line
7302 if (pango_layout_iter_next_line (iter))
7304 line = pango_layout_iter_get_line_readonly (iter);
7305 switch (boundary_type)
7307 case ATK_TEXT_BOUNDARY_LINE_START:
7308 start_index = line->start_index;
7309 if (pango_layout_iter_next_line (iter))
7310 end_index = pango_layout_iter_get_line_readonly (iter)->start_index;
7312 end_index = start_index + line->length;
7314 case ATK_TEXT_BOUNDARY_LINE_END:
7315 start_index = end_index;
7316 end_index = line->start_index + line->length;
7319 g_assert_not_reached();
7323 start_index = end_index;
7329 prev_prev_line = prev_line;
7332 while (pango_layout_iter_next_line (iter));
7336 start_index = prev_line->start_index + prev_line->length;
7337 end_index = start_index;
7339 pango_layout_iter_free (iter);
7340 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7341 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7343 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7344 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7349 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7351 AtkTextBoundary boundary_type,
7355 GtkIconViewItemAccessible *item;
7356 GtkTextIter start, end;
7357 GtkTextBuffer *buffer;
7359 GtkIconView *icon_view;
7362 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7364 if (!GTK_IS_ICON_VIEW (item->widget))
7367 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7370 buffer = item->text_buffer;
7372 if (!gtk_text_buffer_get_char_count (buffer))
7376 return g_strdup ("");
7378 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7382 switch (boundary_type)
7384 case ATK_TEXT_BOUNDARY_CHAR:
7385 gtk_text_iter_backward_char(&start);
7387 case ATK_TEXT_BOUNDARY_WORD_START:
7388 if (!gtk_text_iter_starts_word (&start))
7389 gtk_text_iter_backward_word_start (&start);
7391 gtk_text_iter_backward_word_start(&start);
7393 case ATK_TEXT_BOUNDARY_WORD_END:
7394 if (gtk_text_iter_inside_word (&start) &&
7395 !gtk_text_iter_starts_word (&start))
7396 gtk_text_iter_backward_word_start (&start);
7397 while (!gtk_text_iter_ends_word (&start))
7399 if (!gtk_text_iter_backward_char (&start))
7403 gtk_text_iter_backward_word_start(&start);
7404 while (!gtk_text_iter_ends_word (&start))
7406 if (!gtk_text_iter_backward_char (&start))
7410 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7411 if (!gtk_text_iter_starts_sentence (&start))
7412 gtk_text_iter_backward_sentence_start (&start);
7414 gtk_text_iter_backward_sentence_start (&start);
7416 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7417 if (gtk_text_iter_inside_sentence (&start) &&
7418 !gtk_text_iter_starts_sentence (&start))
7419 gtk_text_iter_backward_sentence_start (&start);
7420 while (!gtk_text_iter_ends_sentence (&start))
7422 if (!gtk_text_iter_backward_char (&start))
7426 gtk_text_iter_backward_sentence_start (&start);
7427 while (!gtk_text_iter_ends_sentence (&start))
7429 if (!gtk_text_iter_backward_char (&start))
7433 case ATK_TEXT_BOUNDARY_LINE_START:
7434 case ATK_TEXT_BOUNDARY_LINE_END:
7436 icon_view = GTK_ICON_VIEW (item->widget);
7437 /* FIXME we probably have to use GailTextCell to salvage this */
7438 gtk_icon_view_update_item_text (icon_view, item->item);
7439 get_pango_text_offsets (icon_view->priv->layout,
7452 *start_offset = gtk_text_iter_get_offset (&start);
7453 *end_offset = gtk_text_iter_get_offset (&end);
7455 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7459 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7461 AtkTextBoundary boundary_type,
7465 GtkIconViewItemAccessible *item;
7466 GtkTextIter start, end;
7467 GtkTextBuffer *buffer;
7469 GtkIconView *icon_view;
7472 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7474 if (!GTK_IS_ICON_VIEW (item->widget))
7477 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7480 buffer = item->text_buffer;
7482 if (!gtk_text_buffer_get_char_count (buffer))
7486 return g_strdup ("");
7488 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7492 switch (boundary_type)
7494 case ATK_TEXT_BOUNDARY_CHAR:
7495 gtk_text_iter_forward_char (&end);
7497 case ATK_TEXT_BOUNDARY_WORD_START:
7498 if (!gtk_text_iter_starts_word (&start))
7499 gtk_text_iter_backward_word_start (&start);
7500 if (gtk_text_iter_inside_word (&end))
7501 gtk_text_iter_forward_word_end (&end);
7502 while (!gtk_text_iter_starts_word (&end))
7504 if (!gtk_text_iter_forward_char (&end))
7508 case ATK_TEXT_BOUNDARY_WORD_END:
7509 if (gtk_text_iter_inside_word (&start) &&
7510 !gtk_text_iter_starts_word (&start))
7511 gtk_text_iter_backward_word_start (&start);
7512 while (!gtk_text_iter_ends_word (&start))
7514 if (!gtk_text_iter_backward_char (&start))
7517 gtk_text_iter_forward_word_end (&end);
7519 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7520 if (!gtk_text_iter_starts_sentence (&start))
7521 gtk_text_iter_backward_sentence_start (&start);
7522 if (gtk_text_iter_inside_sentence (&end))
7523 gtk_text_iter_forward_sentence_end (&end);
7524 while (!gtk_text_iter_starts_sentence (&end))
7526 if (!gtk_text_iter_forward_char (&end))
7530 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7531 if (gtk_text_iter_inside_sentence (&start) &&
7532 !gtk_text_iter_starts_sentence (&start))
7533 gtk_text_iter_backward_sentence_start (&start);
7534 while (!gtk_text_iter_ends_sentence (&start))
7536 if (!gtk_text_iter_backward_char (&start))
7539 gtk_text_iter_forward_sentence_end (&end);
7541 case ATK_TEXT_BOUNDARY_LINE_START:
7542 case ATK_TEXT_BOUNDARY_LINE_END:
7544 icon_view = GTK_ICON_VIEW (item->widget);
7545 /* FIXME we probably have to use GailTextCell to salvage this */
7546 gtk_icon_view_update_item_text (icon_view, item->item);
7547 get_pango_text_offsets (icon_view->priv->layout,
7561 *start_offset = gtk_text_iter_get_offset (&start);
7562 *end_offset = gtk_text_iter_get_offset (&end);
7564 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7568 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7570 AtkTextBoundary boundary_type,
7574 GtkIconViewItemAccessible *item;
7575 GtkTextIter start, end;
7576 GtkTextBuffer *buffer;
7578 GtkIconView *icon_view;
7581 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7583 if (!GTK_IS_ICON_VIEW (item->widget))
7586 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7589 buffer = item->text_buffer;
7591 if (!gtk_text_buffer_get_char_count (buffer))
7595 return g_strdup ("");
7597 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7601 switch (boundary_type)
7603 case ATK_TEXT_BOUNDARY_CHAR:
7604 gtk_text_iter_forward_char(&start);
7605 gtk_text_iter_forward_chars(&end, 2);
7607 case ATK_TEXT_BOUNDARY_WORD_START:
7608 if (gtk_text_iter_inside_word (&end))
7609 gtk_text_iter_forward_word_end (&end);
7610 while (!gtk_text_iter_starts_word (&end))
7612 if (!gtk_text_iter_forward_char (&end))
7616 if (!gtk_text_iter_is_end (&end))
7618 gtk_text_iter_forward_word_end (&end);
7619 while (!gtk_text_iter_starts_word (&end))
7621 if (!gtk_text_iter_forward_char (&end))
7626 case ATK_TEXT_BOUNDARY_WORD_END:
7627 gtk_text_iter_forward_word_end (&end);
7629 if (!gtk_text_iter_is_end (&end))
7630 gtk_text_iter_forward_word_end (&end);
7632 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7633 if (gtk_text_iter_inside_sentence (&end))
7634 gtk_text_iter_forward_sentence_end (&end);
7635 while (!gtk_text_iter_starts_sentence (&end))
7637 if (!gtk_text_iter_forward_char (&end))
7641 if (!gtk_text_iter_is_end (&end))
7643 gtk_text_iter_forward_sentence_end (&end);
7644 while (!gtk_text_iter_starts_sentence (&end))
7646 if (!gtk_text_iter_forward_char (&end))
7651 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7652 gtk_text_iter_forward_sentence_end (&end);
7654 if (!gtk_text_iter_is_end (&end))
7655 gtk_text_iter_forward_sentence_end (&end);
7657 case ATK_TEXT_BOUNDARY_LINE_START:
7658 case ATK_TEXT_BOUNDARY_LINE_END:
7660 icon_view = GTK_ICON_VIEW (item->widget);
7661 /* FIXME we probably have to use GailTextCell to salvage this */
7662 gtk_icon_view_update_item_text (icon_view, item->item);
7663 get_pango_text_offsets (icon_view->priv->layout,
7675 *start_offset = gtk_text_iter_get_offset (&start);
7676 *end_offset = gtk_text_iter_get_offset (&end);
7678 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7682 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7684 GtkIconViewItemAccessible *item;
7686 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7688 if (!GTK_IS_ICON_VIEW (item->widget))
7691 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7694 return gtk_text_buffer_get_char_count (item->text_buffer);
7698 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7704 AtkCoordType coord_type)
7706 GtkIconViewItemAccessible *item;
7708 GtkIconView *icon_view;
7709 PangoRectangle char_rect;
7710 const gchar *item_text;
7714 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7716 if (!GTK_IS_ICON_VIEW (item->widget))
7719 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7723 icon_view = GTK_ICON_VIEW (item->widget);
7724 /* FIXME we probably have to use GailTextCell to salvage this */
7725 gtk_icon_view_update_item_text (icon_view, item->item);
7726 item_text = pango_layout_get_text (icon_view->priv->layout);
7727 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7728 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7730 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7731 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7732 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7733 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7734 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7735 *width = char_rect.width / PANGO_SCALE;
7736 *height = char_rect.height / PANGO_SCALE;
7741 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7744 AtkCoordType coord_type)
7746 GtkIconViewItemAccessible *item;
7749 GtkIconView *icon_view;
7750 const gchar *item_text;
7755 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7757 if (!GTK_IS_ICON_VIEW (item->widget))
7760 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7764 icon_view = GTK_ICON_VIEW (item->widget);
7765 /* FIXME we probably have to use GailTextCell to salvage this */
7766 gtk_icon_view_update_item_text (icon_view, item->item);
7767 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7768 x -= l_x + item->item->layout_x - item->item->x;
7769 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7770 y -= l_y + item->item->layout_y - item->item->y;
7771 item_text = pango_layout_get_text (icon_view->priv->layout);
7772 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7783 offset = g_utf8_strlen (item_text, -1);
7785 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7791 atk_text_item_interface_init (AtkTextIface *iface)
7793 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7794 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7795 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7796 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7797 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7798 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7799 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7800 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7804 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7809 AtkCoordType coord_type)
7811 GtkIconViewItemAccessible *item;
7812 AtkObject *parent_obj;
7815 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7817 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7818 if (!GTK_IS_WIDGET (item->widget))
7821 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7824 *width = item->item->width;
7825 *height = item->item->height;
7826 if (gtk_icon_view_item_accessible_is_showing (item))
7828 parent_obj = gtk_widget_get_accessible (item->widget);
7829 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7830 *x = l_x + item->item->x;
7831 *y = l_y + item->item->y;
7841 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7843 GtkIconViewItemAccessible *item;
7844 GtkWidget *toplevel;
7846 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7848 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7849 if (!GTK_IS_WIDGET (item->widget))
7852 gtk_widget_grab_focus (item->widget);
7853 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
7854 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7855 if (GTK_WIDGET_TOPLEVEL (toplevel))
7856 gtk_window_present (GTK_WINDOW (toplevel));
7862 atk_component_item_interface_init (AtkComponentIface *iface)
7864 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7865 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7869 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7870 AtkStateType state_type,
7871 gboolean emit_signal)
7875 rc = atk_state_set_add_state (item->state_set, state_type);
7877 * The signal should only be generated if the value changed,
7878 * not when the item is set up. So states that are set
7879 * initially should pass FALSE as the emit_signal argument.
7884 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7885 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7886 if (state_type == ATK_STATE_VISIBLE)
7887 g_signal_emit_by_name (item, "visible_data_changed");
7894 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7895 AtkStateType state_type,
7896 gboolean emit_signal)
7898 if (atk_state_set_contains_state (item->state_set, state_type))
7902 rc = atk_state_set_remove_state (item->state_set, state_type);
7904 * The signal should only be generated if the value changed,
7905 * not when the item is set up. So states that are set
7906 * initially should pass FALSE as the emit_signal argument.
7911 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7912 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7913 if (state_type == ATK_STATE_VISIBLE)
7914 g_signal_emit_by_name (item, "visible_data_changed");
7924 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7926 GtkIconView *icon_view;
7927 GdkRectangle visible_rect;
7928 gboolean is_showing;
7931 * An item is considered "SHOWING" if any part of the item is in the
7932 * visible rectangle.
7935 if (!GTK_IS_ICON_VIEW (item->widget))
7938 if (item->item == NULL)
7941 icon_view = GTK_ICON_VIEW (item->widget);
7943 if (icon_view->priv->hadjustment)
7944 visible_rect.x += icon_view->priv->hadjustment->value;
7946 if (icon_view->priv->hadjustment)
7947 visible_rect.y += icon_view->priv->vadjustment->value;
7948 visible_rect.width = item->widget->allocation.width;
7949 visible_rect.height = item->widget->allocation.height;
7951 if (((item->item->x + item->item->width) < visible_rect.x) ||
7952 ((item->item->y + item->item->height) < (visible_rect.y)) ||
7953 (item->item->x > (visible_rect.x + visible_rect.width)) ||
7954 (item->item->y > (visible_rect.y + visible_rect.height)))
7963 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
7964 gboolean emit_signal)
7966 if (gtk_icon_view_item_accessible_is_showing (item))
7967 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
7970 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
7975 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
7979 item->state_set = atk_state_set_new ();
7981 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
7982 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
7983 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
7984 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
7985 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
7987 for (i = 0; i < LAST_ACTION; i++)
7988 item->action_descriptions[i] = NULL;
7990 item->image_description = NULL;
7992 item->action_idle_handler = 0;
7996 gtk_icon_view_item_accessible_finalize (GObject *object)
7998 GtkIconViewItemAccessible *item;
8001 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
8003 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
8006 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
8008 if (item->state_set)
8009 g_object_unref (item->state_set);
8011 if (item->text_buffer)
8012 g_object_unref (item->text_buffer);
8014 for (i = 0; i < LAST_ACTION; i++)
8015 g_free (item->action_descriptions[i]);
8017 g_free (item->image_description);
8019 if (item->action_idle_handler)
8021 g_source_remove (item->action_idle_handler);
8022 item->action_idle_handler = 0;
8025 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
8028 static G_CONST_RETURN gchar*
8029 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
8035 GtkIconViewItemAccessible *item;
8036 GtkTextIter start_iter;
8037 GtkTextIter end_iter;
8039 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8041 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
8042 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
8044 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
8049 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
8051 GtkIconViewItemAccessible *item;
8053 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
8054 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8057 return gtk_widget_get_accessible (item->widget);
8063 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
8065 GtkIconViewItemAccessible *item;
8067 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
8068 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8070 return item->item->index;
8073 static AtkStateSet *
8074 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
8076 GtkIconViewItemAccessible *item;
8077 GtkIconView *icon_view;
8079 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8080 g_return_val_if_fail (item->state_set, NULL);
8085 icon_view = GTK_ICON_VIEW (item->widget);
8086 if (icon_view->priv->cursor_item == item->item)
8087 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
8089 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
8091 return g_object_ref (item->state_set);
8095 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8097 GObjectClass *gobject_class;
8099 accessible_item_parent_class = g_type_class_peek_parent (klass);
8101 gobject_class = (GObjectClass *)klass;
8103 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8105 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8106 klass->get_name = gtk_icon_view_item_accessible_get_name;
8107 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8108 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8112 gtk_icon_view_item_accessible_get_type (void)
8114 static GType type = 0;
8118 const GTypeInfo tinfo =
8120 sizeof (GtkIconViewItemAccessibleClass),
8121 (GBaseInitFunc) NULL, /* base init */
8122 (GBaseFinalizeFunc) NULL, /* base finalize */
8123 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8124 (GClassFinalizeFunc) NULL, /* class finalize */
8125 NULL, /* class data */
8126 sizeof (GtkIconViewItemAccessible), /* instance size */
8127 0, /* nb preallocs */
8128 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8129 NULL /* value table */
8132 static const GInterfaceInfo atk_component_info =
8134 (GInterfaceInitFunc) atk_component_item_interface_init,
8135 (GInterfaceFinalizeFunc) NULL,
8138 static const GInterfaceInfo atk_action_info =
8140 (GInterfaceInitFunc) atk_action_item_interface_init,
8141 (GInterfaceFinalizeFunc) NULL,
8144 static const GInterfaceInfo atk_image_info =
8146 (GInterfaceInitFunc) atk_image_item_interface_init,
8147 (GInterfaceFinalizeFunc) NULL,
8150 static const GInterfaceInfo atk_text_info =
8152 (GInterfaceInitFunc) atk_text_item_interface_init,
8153 (GInterfaceFinalizeFunc) NULL,
8157 type = g_type_register_static (ATK_TYPE_OBJECT,
8158 I_("GtkIconViewItemAccessible"), &tinfo, 0);
8159 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8160 &atk_component_info);
8161 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8163 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8165 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8172 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8173 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8174 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8176 static GType gtk_icon_view_accessible_get_type (void);
8181 } GtkIconViewAccessible;
8187 } GtkIconViewItemAccessibleInfo;
8193 GtkAdjustment *old_hadj;
8194 GtkAdjustment *old_vadj;
8196 GtkTreeModel *model;
8198 } GtkIconViewAccessiblePrivate;
8200 static GtkIconViewAccessiblePrivate *
8201 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8203 return g_object_get_qdata (G_OBJECT (accessible),
8204 accessible_private_data_quark);
8208 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8212 GtkIconViewItemAccessibleInfo *info;
8213 GtkIconViewItemAccessibleInfo *tmp_info;
8214 GtkIconViewAccessiblePrivate *priv;
8217 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8219 info->index = index;
8221 priv = gtk_icon_view_accessible_get_priv (accessible);
8222 items = priv->items;
8225 tmp_info = items->data;
8226 if (tmp_info->index > index)
8228 items = items->next;
8230 priv->items = g_list_insert_before (priv->items, items, info);
8231 priv->old_hadj = NULL;
8232 priv->old_vadj = NULL;
8236 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8238 GtkIconView *icon_view;
8241 widget = GTK_ACCESSIBLE (accessible)->widget;
8245 icon_view = GTK_ICON_VIEW (widget);
8247 return g_list_length (icon_view->priv->items);
8251 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8254 GtkIconViewAccessiblePrivate *priv;
8255 GtkIconViewItemAccessibleInfo *info;
8258 priv = gtk_icon_view_accessible_get_priv (accessible);
8259 items = priv->items;
8264 if (info->index == index)
8266 items = items->next;
8272 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8275 GtkIconView *icon_view;
8279 GtkIconViewItemAccessible *a11y_item;
8281 widget = GTK_ACCESSIBLE (accessible)->widget;
8285 icon_view = GTK_ICON_VIEW (widget);
8286 icons = g_list_nth (icon_view->priv->items, index);
8290 GtkIconViewItem *item = icons->data;
8292 g_return_val_if_fail (item->index == index, NULL);
8293 obj = gtk_icon_view_accessible_find_child (accessible, index);
8296 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8297 gtk_icon_view_item_accessible_info_new (accessible,
8300 obj->role = ATK_ROLE_ICON;
8301 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8302 a11y_item->item = item;
8303 a11y_item->widget = widget;
8304 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8306 gtk_icon_view_set_cell_data (icon_view, item);
8307 gtk_text_buffer_set_text (a11y_item->text_buffer,
8308 get_text (icon_view, item), -1);
8310 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8311 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8319 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8322 GtkIconViewAccessiblePrivate *priv;
8323 GtkIconViewItemAccessibleInfo *info;
8324 GtkIconViewItemAccessible *item;
8327 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8331 gboolean act_on_item;
8333 widget = GTK_ACCESSIBLE (view)->widget;
8337 items = priv->items;
8339 act_on_item = (list == NULL);
8344 info = (GtkIconViewItemAccessibleInfo *)items->data;
8345 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8347 if (act_on_item == FALSE && list == items)
8351 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8353 items = items->next;
8359 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8360 GtkIconView *icon_view)
8363 GtkIconViewAccessible *view;
8366 * The scrollbars have changed
8368 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8369 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8371 gtk_icon_view_accessible_traverse_items (view, NULL);
8375 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8376 GtkAdjustment *hadj,
8377 GtkAdjustment *vadj)
8380 GtkIconViewAccessiblePrivate *priv;
8382 atk_obj = gtk_widget_get_accessible (widget);
8383 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8385 if (priv->old_hadj != hadj)
8389 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8390 (gpointer *)&priv->old_hadj);
8392 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8393 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8396 priv->old_hadj = hadj;
8399 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8400 (gpointer *)&priv->old_hadj);
8401 g_signal_connect (hadj,
8403 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8407 if (priv->old_vadj != vadj)
8411 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8412 (gpointer *)&priv->old_vadj);
8414 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8415 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8418 priv->old_vadj = vadj;
8421 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8422 (gpointer *)&priv->old_vadj);
8423 g_signal_connect (vadj,
8425 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8432 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8439 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8440 g_signal_emit_by_name (atk_obj, "visible_data_changed");
8446 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8451 GtkIconViewAccessiblePrivate *priv;
8452 GtkIconViewItemAccessibleInfo *info;
8453 GtkIconViewAccessible *view;
8454 GtkIconViewItemAccessible *item;
8460 index = gtk_tree_path_get_indices(path)[0];
8461 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8462 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8463 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8465 items = priv->items;
8470 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8471 if (info->index != item->item->index)
8473 if (info->index < index)
8474 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8476 if (tmp_list == NULL)
8479 info->index = item->item->index;
8482 items = items->next;
8484 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8485 g_signal_emit_by_name (atk_obj, "children_changed::add",
8491 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8495 GtkIconViewAccessiblePrivate *priv;
8496 GtkIconViewItemAccessibleInfo *info;
8497 GtkIconViewAccessible *view;
8498 GtkIconViewItemAccessible *item;
8501 GList *deleted_item;
8505 index = gtk_tree_path_get_indices(path)[0];
8506 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8507 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8508 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8510 items = priv->items;
8512 deleted_item = NULL;
8517 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8518 if (info->index == index)
8520 deleted_item = items;
8522 if (info->index != item->item->index)
8524 if (tmp_list == NULL)
8527 info->index = item->item->index;
8530 items = items->next;
8532 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8535 info = deleted_item->data;
8536 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8538 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8542 priv->items = g_list_remove_link (priv->items, deleted_item);
8550 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8551 GtkIconViewItemAccessibleInfo *i2)
8553 return i1->index - i2->index;
8557 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8563 GtkIconViewAccessiblePrivate *priv;
8564 GtkIconViewItemAccessibleInfo *info;
8565 GtkIconView *icon_view;
8566 GtkIconViewItemAccessible *item;
8570 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8571 icon_view = GTK_ICON_VIEW (user_data);
8572 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8574 items = priv->items;
8578 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8579 info->index = new_order[info->index];
8580 item->item = g_list_nth_data (icon_view->priv->items, info->index);
8581 items = items->next;
8583 priv->items = g_list_sort (priv->items,
8584 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8590 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8595 obj = G_OBJECT (model);
8596 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8597 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8598 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8599 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8603 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8607 obj = G_OBJECT (icon_view->priv->model);
8608 g_signal_connect_data (obj, "row_changed",
8609 (GCallback) gtk_icon_view_accessible_model_row_changed,
8610 icon_view, NULL, 0);
8611 g_signal_connect_data (obj, "row_inserted",
8612 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8613 icon_view, NULL, G_CONNECT_AFTER);
8614 g_signal_connect_data (obj, "row_deleted",
8615 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8616 icon_view, NULL, G_CONNECT_AFTER);
8617 g_signal_connect_data (obj, "rows_reordered",
8618 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8619 icon_view, NULL, G_CONNECT_AFTER);
8623 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8625 GtkIconViewItemAccessibleInfo *info;
8628 items = priv->items;
8631 info = (GtkIconViewItemAccessibleInfo *) items->data;
8632 g_object_unref (info->item);
8633 g_free (items->data);
8634 items = items->next;
8636 g_list_free (priv->items);
8641 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8644 GtkIconView *icon_view;
8647 GtkIconViewAccessiblePrivate *priv;
8649 if (strcmp (pspec->name, "model") == 0)
8651 widget = GTK_WIDGET (obj);
8652 atk_obj = gtk_widget_get_accessible (widget);
8653 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8656 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8657 (gpointer *)&priv->model);
8658 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8660 gtk_icon_view_accessible_clear_cache (priv);
8662 icon_view = GTK_ICON_VIEW (obj);
8663 priv->model = icon_view->priv->model;
8664 /* If there is no model the GtkIconView is probably being destroyed */
8667 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8668 gtk_icon_view_accessible_connect_model_signals (icon_view);
8676 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8679 GtkIconViewAccessiblePrivate *priv;
8680 GtkIconView *icon_view;
8682 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8683 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8685 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8686 g_object_set_qdata (G_OBJECT (accessible),
8687 accessible_private_data_quark,
8690 icon_view = GTK_ICON_VIEW (data);
8691 if (icon_view->priv->hadjustment)
8693 priv->old_hadj = icon_view->priv->hadjustment;
8694 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
8695 g_signal_connect (icon_view->priv->hadjustment,
8697 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8700 if (icon_view->priv->vadjustment)
8702 priv->old_vadj = icon_view->priv->vadjustment;
8703 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
8704 g_signal_connect (icon_view->priv->vadjustment,
8706 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8709 g_signal_connect_after (data,
8710 "set_scroll_adjustments",
8711 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
8713 g_signal_connect (data,
8715 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8718 priv->model = icon_view->priv->model;
8721 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8722 gtk_icon_view_accessible_connect_model_signals (icon_view);
8725 accessible->role = ATK_ROLE_LAYERED_PANE;
8729 gtk_icon_view_accessible_finalize (GObject *object)
8731 GtkIconViewAccessiblePrivate *priv;
8733 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8734 gtk_icon_view_accessible_clear_cache (priv);
8738 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8742 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8743 GtkAccessible *accessible)
8746 GtkIconViewAccessiblePrivate *priv;
8748 atk_obj = ATK_OBJECT (accessible);
8749 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8752 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8753 (gpointer *)&priv->old_hadj);
8755 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8756 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8758 priv->old_hadj = NULL;
8762 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8763 (gpointer *)&priv->old_vadj);
8765 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8766 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8768 priv->old_vadj = NULL;
8773 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8775 if (accessible->widget)
8777 g_signal_connect_after (accessible->widget,
8779 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8782 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8786 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8788 GObjectClass *gobject_class;
8789 GtkAccessibleClass *accessible_class;
8791 accessible_parent_class = g_type_class_peek_parent (klass);
8793 gobject_class = (GObjectClass *)klass;
8794 accessible_class = (GtkAccessibleClass *)klass;
8796 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8798 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8799 klass->ref_child = gtk_icon_view_accessible_ref_child;
8800 klass->initialize = gtk_icon_view_accessible_initialize;
8802 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8804 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8808 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8811 AtkCoordType coord_type)
8814 GtkIconView *icon_view;
8815 GtkIconViewItem *item;
8818 widget = GTK_ACCESSIBLE (component)->widget;
8820 /* State is defunct */
8823 icon_view = GTK_ICON_VIEW (widget);
8824 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8825 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8827 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8833 atk_component_interface_init (AtkComponentIface *iface)
8835 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8839 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8843 GtkIconView *icon_view;
8844 GtkIconViewItem *item;
8846 widget = GTK_ACCESSIBLE (selection)->widget;
8850 icon_view = GTK_ICON_VIEW (widget);
8852 item = g_list_nth_data (icon_view->priv->items, i);
8857 gtk_icon_view_select_item (icon_view, item);
8863 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8866 GtkIconView *icon_view;
8868 widget = GTK_ACCESSIBLE (selection)->widget;
8872 icon_view = GTK_ICON_VIEW (widget);
8873 gtk_icon_view_unselect_all (icon_view);
8879 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8884 GtkIconView *icon_view;
8885 GtkIconViewItem *item;
8887 widget = GTK_ACCESSIBLE (selection)->widget;
8891 icon_view = GTK_ICON_VIEW (widget);
8893 l = icon_view->priv->items;
8900 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8911 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8914 GtkIconView *icon_view;
8915 GtkIconViewItem *item;
8919 widget = GTK_ACCESSIBLE (selection)->widget;
8923 icon_view = GTK_ICON_VIEW (widget);
8925 l = icon_view->priv->items;
8941 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
8945 GtkIconView *icon_view;
8946 GtkIconViewItem *item;
8948 widget = GTK_ACCESSIBLE (selection)->widget;
8952 icon_view = GTK_ICON_VIEW (widget);
8954 item = g_list_nth_data (icon_view->priv->items, i);
8958 return item->selected;
8962 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
8966 GtkIconView *icon_view;
8967 GtkIconViewItem *item;
8971 widget = GTK_ACCESSIBLE (selection)->widget;
8975 icon_view = GTK_ICON_VIEW (widget);
8976 l = icon_view->priv->items;
8985 gtk_icon_view_unselect_item (icon_view, item);
8997 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
9000 GtkIconView *icon_view;
9002 widget = GTK_ACCESSIBLE (selection)->widget;
9006 icon_view = GTK_ICON_VIEW (widget);
9007 gtk_icon_view_select_all (icon_view);
9012 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
9014 iface->add_selection = gtk_icon_view_accessible_add_selection;
9015 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
9016 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
9017 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
9018 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
9019 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
9020 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
9024 gtk_icon_view_accessible_get_type (void)
9026 static GType type = 0;
9030 static GTypeInfo tinfo =
9033 (GBaseInitFunc) NULL, /* base init */
9034 (GBaseFinalizeFunc) NULL, /* base finalize */
9035 (GClassInitFunc) gtk_icon_view_accessible_class_init,
9036 (GClassFinalizeFunc) NULL, /* class finalize */
9037 NULL, /* class data */
9038 0, /* instance size */
9039 0, /* nb preallocs */
9040 (GInstanceInitFunc) NULL, /* instance init */
9041 NULL /* value table */
9043 static const GInterfaceInfo atk_component_info =
9045 (GInterfaceInitFunc) atk_component_interface_init,
9046 (GInterfaceFinalizeFunc) NULL,
9049 static const GInterfaceInfo atk_selection_info =
9051 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
9052 (GInterfaceFinalizeFunc) NULL,
9057 * Figure out the size of the class and instance
9058 * we are deriving from
9060 AtkObjectFactory *factory;
9063 GType derived_atk_type;
9065 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9066 factory = atk_registry_get_factory (atk_get_default_registry (),
9068 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9069 g_type_query (derived_atk_type, &query);
9070 tinfo.class_size = query.class_size;
9071 tinfo.instance_size = query.instance_size;
9073 type = g_type_register_static (derived_atk_type,
9074 I_("GtkIconViewAccessible"),
9076 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
9077 &atk_component_info);
9078 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
9079 &atk_selection_info);
9085 gtk_icon_view_accessible_new (GObject *obj)
9087 AtkObject *accessible;
9089 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9091 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9092 atk_object_initialize (accessible, obj);
9098 gtk_icon_view_accessible_factory_get_accessible_type (void)
9100 return gtk_icon_view_accessible_get_type ();
9104 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9106 return gtk_icon_view_accessible_new (obj);
9110 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9112 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9113 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9117 gtk_icon_view_accessible_factory_get_type (void)
9119 static GType type = 0;
9123 const GTypeInfo tinfo =
9125 sizeof (AtkObjectFactoryClass),
9126 NULL, /* base_init */
9127 NULL, /* base_finalize */
9128 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9129 NULL, /* class_finalize */
9130 NULL, /* class_data */
9131 sizeof (AtkObjectFactory),
9132 0, /* n_preallocs */
9136 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9137 I_("GtkIconViewAccessibleFactory"),
9145 gtk_icon_view_get_accessible (GtkWidget *widget)
9147 static gboolean first_time = TRUE;
9151 AtkObjectFactory *factory;
9152 AtkRegistry *registry;
9154 GType derived_atk_type;
9157 * Figure out whether accessibility is enabled by looking at the
9158 * type of the accessible object which would be created for
9159 * the parent type of GtkIconView.
9161 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9163 registry = atk_get_default_registry ();
9164 factory = atk_registry_get_factory (registry,
9166 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9167 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9168 atk_registry_set_factory_type (registry,
9170 gtk_icon_view_accessible_factory_get_type ());
9173 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9176 #define __GTK_ICON_VIEW_C__
9177 #include "gtkaliasdef.c"