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_class_init (GtkIconViewClass *klass);
226 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
227 static void gtk_icon_view_finalize (GObject *object);
228 static void gtk_icon_view_set_property (GObject *object,
232 static void gtk_icon_view_get_property (GObject *object,
237 /* GtkObject vfuncs */
238 static void gtk_icon_view_destroy (GtkObject *object);
240 /* GtkWidget vfuncs */
241 static void gtk_icon_view_realize (GtkWidget *widget);
242 static void gtk_icon_view_unrealize (GtkWidget *widget);
243 static void gtk_icon_view_size_request (GtkWidget *widget,
244 GtkRequisition *requisition);
245 static void gtk_icon_view_size_allocate (GtkWidget *widget,
246 GtkAllocation *allocation);
247 static gboolean gtk_icon_view_expose (GtkWidget *widget,
248 GdkEventExpose *expose);
249 static gboolean gtk_icon_view_motion (GtkWidget *widget,
250 GdkEventMotion *event);
251 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
252 GdkEventButton *event);
253 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
254 GdkEventButton *event);
255 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
258 /* GtkContainer vfuncs */
259 static void gtk_icon_view_remove (GtkContainer *container,
261 static void gtk_icon_view_forall (GtkContainer *container,
262 gboolean include_internals,
263 GtkCallback callback,
264 gpointer callback_data);
266 /* GtkIconView vfuncs */
267 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
269 GtkAdjustment *vadj);
270 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
271 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
272 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
273 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
274 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
276 /* Internal functions */
277 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
278 GtkIconView *icon_view);
279 static void gtk_icon_view_layout (GtkIconView *icon_view);
280 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
283 GtkIconViewItem *item,
285 GdkDrawable *drawable,
288 gboolean draw_focus);
289 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
292 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
294 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
295 GtkIconViewItem *item);
296 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
297 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
298 GtkIconViewItem *item,
300 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
303 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
304 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
305 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
306 GtkIconViewItem *item,
311 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
312 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
313 GtkIconViewItem *item);
314 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
315 GtkIconViewItem *item,
317 static void gtk_icon_view_update_rubberband (gpointer data);
318 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
319 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
320 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
323 GtkMovementStep step,
325 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
326 GtkMovementStep step,
328 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
330 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
332 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
334 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
336 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
337 GtkIconViewItem *item);
338 static void gtk_icon_view_select_item (GtkIconView *icon_view,
339 GtkIconViewItem *item);
340 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
341 GtkIconViewItem *item);
342 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
343 GtkIconViewItem *anchor,
344 GtkIconViewItem *cursor);
345 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
348 gboolean only_in_cell,
349 GtkIconViewCellInfo **cell_at_pos);
350 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
351 GtkIconViewItem *item,
352 GtkIconViewCellInfo *cell_info,
353 GdkRectangle *cell_area);
354 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
355 GtkIconViewItem *item,
356 GtkIconViewCellInfo *info,
358 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
359 GtkCellRenderer *renderer);
360 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
361 GtkIconViewItem *item);
362 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
363 GtkCellRenderer *renderer,
365 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
366 GtkCellRenderer *renderer,
368 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
369 GtkCellRenderer *renderer,
370 const gchar *attribute,
372 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
373 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
374 GtkCellRenderer *renderer);
375 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
376 GtkCellRenderer *cell,
377 GtkCellLayoutDataFunc func,
379 GDestroyNotify destroy);
380 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
381 GtkCellRenderer *cell,
383 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
384 GtkIconViewItem *item,
385 GtkIconViewCellInfo *cell_info,
387 static void gtk_icon_view_put (GtkIconView *icon_view,
389 GtkIconViewItem *item,
391 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
392 GtkIconView *icon_view);
393 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
394 GtkIconViewItem *item,
395 GtkIconViewCellInfo *cell_info,
397 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
398 gboolean cancel_editing);
400 /* Source side drag signals */
401 static void gtk_icon_view_drag_begin (GtkWidget *widget,
402 GdkDragContext *context);
403 static void gtk_icon_view_drag_end (GtkWidget *widget,
404 GdkDragContext *context);
405 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
406 GdkDragContext *context,
407 GtkSelectionData *selection_data,
410 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
411 GdkDragContext *context);
413 /* Target side drag signals */
414 static void gtk_icon_view_drag_leave (GtkWidget *widget,
415 GdkDragContext *context,
417 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
418 GdkDragContext *context,
422 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
423 GdkDragContext *context,
427 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
428 GdkDragContext *context,
431 GtkSelectionData *selection_data,
434 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
435 GdkEventMotion *event);
437 static void remove_scroll_timeout (GtkIconView *icon_view);
440 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
442 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
443 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
444 gtk_icon_view_cell_layout_init));
447 gtk_icon_view_class_init (GtkIconViewClass *klass)
449 GObjectClass *gobject_class;
450 GtkObjectClass *object_class;
451 GtkWidgetClass *widget_class;
452 GtkContainerClass *container_class;
453 GtkBindingSet *binding_set;
455 binding_set = gtk_binding_set_by_class (klass);
457 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
459 gobject_class = (GObjectClass *) klass;
460 object_class = (GtkObjectClass *) klass;
461 widget_class = (GtkWidgetClass *) klass;
462 container_class = (GtkContainerClass *) klass;
464 gobject_class->finalize = gtk_icon_view_finalize;
465 gobject_class->set_property = gtk_icon_view_set_property;
466 gobject_class->get_property = gtk_icon_view_get_property;
468 object_class->destroy = gtk_icon_view_destroy;
470 widget_class->realize = gtk_icon_view_realize;
471 widget_class->unrealize = gtk_icon_view_unrealize;
472 widget_class->size_request = gtk_icon_view_size_request;
473 widget_class->size_allocate = gtk_icon_view_size_allocate;
474 widget_class->expose_event = gtk_icon_view_expose;
475 widget_class->motion_notify_event = gtk_icon_view_motion;
476 widget_class->button_press_event = gtk_icon_view_button_press;
477 widget_class->button_release_event = gtk_icon_view_button_release;
478 widget_class->drag_begin = gtk_icon_view_drag_begin;
479 widget_class->drag_end = gtk_icon_view_drag_end;
480 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
481 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
482 widget_class->drag_leave = gtk_icon_view_drag_leave;
483 widget_class->drag_motion = gtk_icon_view_drag_motion;
484 widget_class->drag_drop = gtk_icon_view_drag_drop;
485 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
486 widget_class->get_accessible = gtk_icon_view_get_accessible;
488 container_class->remove = gtk_icon_view_remove;
489 container_class->forall = gtk_icon_view_forall;
491 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
492 klass->select_all = gtk_icon_view_real_select_all;
493 klass->unselect_all = gtk_icon_view_real_unselect_all;
494 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
495 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
496 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
497 klass->move_cursor = gtk_icon_view_real_move_cursor;
501 * GtkIconView:selection-mode:
503 * The ::selection-mode property specifies the selection mode of
504 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
505 * is enabled, for the other modes, only keyboard selection is possible.
509 g_object_class_install_property (gobject_class,
511 g_param_spec_enum ("selection-mode",
512 P_("Selection mode"),
513 P_("The selection mode"),
514 GTK_TYPE_SELECTION_MODE,
515 GTK_SELECTION_SINGLE,
516 GTK_PARAM_READWRITE));
519 * GtkIconView:pixbuf-column:
521 * The ::pixbuf-column property contains the number of the model column
522 * containing the pixbufs which are displayed. The pixbuf column must be
523 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
524 * display of pixbufs.
528 g_object_class_install_property (gobject_class,
530 g_param_spec_int ("pixbuf-column",
532 P_("Model column used to retrieve the icon pixbuf from"),
534 GTK_PARAM_READWRITE));
537 * GtkIconView:text-column:
539 * The ::text-column property contains the number of the model column
540 * containing the texts which are displayed. The text column must be
541 * of type #G_TYPE_STRING. If this property and the :markup-column
542 * property are both set to -1, no texts are displayed.
546 g_object_class_install_property (gobject_class,
548 g_param_spec_int ("text-column",
550 P_("Model column used to retrieve the text from"),
552 GTK_PARAM_READWRITE));
556 * GtkIconView:markup-column:
558 * The ::markup-column property contains the number of the model column
559 * containing markup information to be displayed. The markup column must be
560 * of type #G_TYPE_STRING. If this property and the :text-column property
561 * are both set to column numbers, it overrides the text column.
562 * If both are set to -1, no texts are displayed.
566 g_object_class_install_property (gobject_class,
568 g_param_spec_int ("markup-column",
570 P_("Model column used to retrieve the text if using Pango markup"),
572 GTK_PARAM_READWRITE));
574 g_object_class_install_property (gobject_class,
576 g_param_spec_object ("model",
577 P_("Icon View Model"),
578 P_("The model for the icon view"),
580 GTK_PARAM_READWRITE));
583 * GtkIconView:columns:
585 * The columns property contains the number of the columns in which the
586 * items should be displayed. If it is -1, the number of columns will
587 * be chosen automatically to fill the available area.
591 g_object_class_install_property (gobject_class,
593 g_param_spec_int ("columns",
594 P_("Number of columns"),
595 P_("Number of columns to display"),
597 GTK_PARAM_READWRITE));
601 * GtkIconView::item-width:
603 * The item-width property specifies the width to use for each item.
604 * If it is set to -1, the icon view will automatically determine a
605 * suitable item size.
609 g_object_class_install_property (gobject_class,
611 g_param_spec_int ("item-width",
612 P_("Width for each item"),
613 P_("The width used for each item"),
615 GTK_PARAM_READWRITE));
618 * GtkIconView::spacing:
620 * The spacing property specifies the space which is inserted between
621 * the cells (i.e. the icon and the text) of an item.
625 g_object_class_install_property (gobject_class,
627 g_param_spec_int ("spacing",
629 P_("Space which is inserted between cells of an item"),
631 GTK_PARAM_READWRITE));
634 * GtkIconView::row-spacing:
636 * The row-spacing property specifies the space which is inserted between
637 * the rows of the icon view.
641 g_object_class_install_property (gobject_class,
643 g_param_spec_int ("row-spacing",
645 P_("Space which is inserted between grid rows"),
647 GTK_PARAM_READWRITE));
650 * GtkIconView::column-spacing:
652 * The column-spacing property specifies the space which is inserted between
653 * the columns of the icon view.
657 g_object_class_install_property (gobject_class,
659 g_param_spec_int ("column-spacing",
660 P_("Column Spacing"),
661 P_("Space which is inserted between grid column"),
663 GTK_PARAM_READWRITE));
666 * GtkIconView::margin:
668 * The margin property specifies the space which is inserted
669 * at the edges of the icon view.
673 g_object_class_install_property (gobject_class,
675 g_param_spec_int ("margin",
677 P_("Space which is inserted at the edges of the icon view"),
679 GTK_PARAM_READWRITE));
683 * GtkIconView::orientation:
685 * The orientation property specifies how the cells (i.e. the icon and
686 * the text) of the item are positioned relative to each other.
690 g_object_class_install_property (gobject_class,
692 g_param_spec_enum ("orientation",
694 P_("How the text and icon of each item are positioned relative to each other"),
695 GTK_TYPE_ORIENTATION,
696 GTK_ORIENTATION_VERTICAL,
697 GTK_PARAM_READWRITE));
700 * GtkIconView:orientation:
702 * The reorderable property specifies if the items can be reordered
707 g_object_class_install_property (gobject_class,
709 g_param_spec_boolean ("reorderable",
711 P_("View is reorderable"),
715 /* Style properties */
716 gtk_widget_class_install_style_property (widget_class,
717 g_param_spec_boxed ("selection-box-color",
718 P_("Selection Box Color"),
719 P_("Color of the selection box"),
721 GTK_PARAM_READABLE));
723 gtk_widget_class_install_style_property (widget_class,
724 g_param_spec_uchar ("selection-box-alpha",
725 P_("Selection Box Alpha"),
726 P_("Opacity of the selection box"),
729 GTK_PARAM_READABLE));
732 widget_class->set_scroll_adjustments_signal =
733 g_signal_new ("set_scroll_adjustments",
734 G_TYPE_FROM_CLASS (gobject_class),
736 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
738 _gtk_marshal_VOID__OBJECT_OBJECT,
740 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
742 icon_view_signals[ITEM_ACTIVATED] =
743 g_signal_new ("item_activated",
744 G_TYPE_FROM_CLASS (gobject_class),
746 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
748 g_cclosure_marshal_VOID__BOXED,
752 icon_view_signals[SELECTION_CHANGED] =
753 g_signal_new ("selection_changed",
754 G_TYPE_FROM_CLASS (gobject_class),
756 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
758 g_cclosure_marshal_VOID__VOID,
761 icon_view_signals[SELECT_ALL] =
762 g_signal_new ("select_all",
763 G_TYPE_FROM_CLASS (gobject_class),
764 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
765 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
767 g_cclosure_marshal_VOID__VOID,
770 icon_view_signals[UNSELECT_ALL] =
771 g_signal_new ("unselect_all",
772 G_TYPE_FROM_CLASS (gobject_class),
773 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
774 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
776 g_cclosure_marshal_VOID__VOID,
779 icon_view_signals[SELECT_CURSOR_ITEM] =
780 g_signal_new ("select_cursor_item",
781 G_TYPE_FROM_CLASS (gobject_class),
782 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
783 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
785 g_cclosure_marshal_VOID__VOID,
788 icon_view_signals[TOGGLE_CURSOR_ITEM] =
789 g_signal_new ("toggle_cursor_item",
790 G_TYPE_FROM_CLASS (gobject_class),
791 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
792 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
794 g_cclosure_marshal_VOID__VOID,
797 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
798 g_signal_new ("activate_cursor_item",
799 G_TYPE_FROM_CLASS (gobject_class),
800 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
801 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
803 _gtk_marshal_BOOLEAN__VOID,
806 icon_view_signals[MOVE_CURSOR] =
807 g_signal_new ("move_cursor",
808 G_TYPE_FROM_CLASS (gobject_class),
809 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
810 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
812 _gtk_marshal_BOOLEAN__ENUM_INT,
814 GTK_TYPE_MOVEMENT_STEP,
818 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK, "select_all", 0);
819 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect_all", 0);
820 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK, "toggle_cursor_item", 0);
822 gtk_binding_entry_add_signal (binding_set, GDK_space, 0, "activate_cursor_item", 0);
823 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, "activate_cursor_item", 0);
824 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0, "activate_cursor_item", 0);
825 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, "activate_cursor_item", 0);
827 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
828 GTK_MOVEMENT_DISPLAY_LINES, -1);
829 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
830 GTK_MOVEMENT_DISPLAY_LINES, -1);
832 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
833 GTK_MOVEMENT_DISPLAY_LINES, 1);
834 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
835 GTK_MOVEMENT_DISPLAY_LINES, 1);
837 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
838 GTK_MOVEMENT_DISPLAY_LINES, -1);
840 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
841 GTK_MOVEMENT_DISPLAY_LINES, 1);
843 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
844 GTK_MOVEMENT_BUFFER_ENDS, -1);
845 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
846 GTK_MOVEMENT_BUFFER_ENDS, -1);
848 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
849 GTK_MOVEMENT_BUFFER_ENDS, 1);
850 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
851 GTK_MOVEMENT_BUFFER_ENDS, 1);
853 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
854 GTK_MOVEMENT_PAGES, -1);
855 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
856 GTK_MOVEMENT_PAGES, -1);
858 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
859 GTK_MOVEMENT_PAGES, 1);
860 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
861 GTK_MOVEMENT_PAGES, 1);
863 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
864 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
865 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
866 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
868 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
869 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
870 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
871 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
875 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
877 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
878 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
879 iface->clear = gtk_icon_view_cell_layout_clear;
880 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
881 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
882 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
883 iface->reorder = gtk_icon_view_cell_layout_reorder;
887 gtk_icon_view_init (GtkIconView *icon_view)
889 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
891 icon_view->priv->width = 0;
892 icon_view->priv->height = 0;
893 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
894 icon_view->priv->pressed_button = -1;
895 icon_view->priv->press_start_x = -1;
896 icon_view->priv->press_start_y = -1;
897 icon_view->priv->text_column = -1;
898 icon_view->priv->markup_column = -1;
899 icon_view->priv->pixbuf_column = -1;
900 icon_view->priv->text_cell = -1;
901 icon_view->priv->pixbuf_cell = -1;
903 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
905 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
907 icon_view->priv->cell_list = NULL;
908 icon_view->priv->n_cells = 0;
909 icon_view->priv->cursor_cell = -1;
911 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
913 icon_view->priv->columns = -1;
914 icon_view->priv->item_width = -1;
915 icon_view->priv->spacing = 0;
916 icon_view->priv->row_spacing = 6;
917 icon_view->priv->column_spacing = 6;
918 icon_view->priv->margin = 6;
922 gtk_icon_view_destroy (GtkObject *object)
924 GtkIconView *icon_view;
926 icon_view = GTK_ICON_VIEW (object);
928 gtk_icon_view_stop_editing (icon_view, TRUE);
930 gtk_icon_view_set_model (icon_view, NULL);
932 if (icon_view->priv->layout_idle_id != 0)
934 g_source_remove (icon_view->priv->layout_idle_id);
935 icon_view->priv->layout_idle_id = 0;
938 if (icon_view->priv->scroll_to_path != NULL)
940 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
941 icon_view->priv->scroll_to_path = NULL;
944 remove_scroll_timeout (icon_view);
946 (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
949 /* GObject methods */
951 gtk_icon_view_finalize (GObject *object)
953 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
955 (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
960 gtk_icon_view_set_property (GObject *object,
965 GtkIconView *icon_view;
967 icon_view = GTK_ICON_VIEW (object);
971 case PROP_SELECTION_MODE:
972 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
974 case PROP_PIXBUF_COLUMN:
975 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
977 case PROP_TEXT_COLUMN:
978 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
980 case PROP_MARKUP_COLUMN:
981 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
984 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
986 case PROP_ORIENTATION:
987 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
990 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
992 case PROP_ITEM_WIDTH:
993 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
996 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
998 case PROP_ROW_SPACING:
999 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
1001 case PROP_COLUMN_SPACING:
1002 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
1005 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
1007 case PROP_REORDERABLE:
1008 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
1012 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1018 gtk_icon_view_get_property (GObject *object,
1023 GtkIconView *icon_view;
1025 icon_view = GTK_ICON_VIEW (object);
1029 case PROP_SELECTION_MODE:
1030 g_value_set_enum (value, icon_view->priv->selection_mode);
1032 case PROP_PIXBUF_COLUMN:
1033 g_value_set_int (value, icon_view->priv->pixbuf_column);
1035 case PROP_TEXT_COLUMN:
1036 g_value_set_int (value, icon_view->priv->text_column);
1038 case PROP_MARKUP_COLUMN:
1039 g_value_set_int (value, icon_view->priv->markup_column);
1042 g_value_set_object (value, icon_view->priv->model);
1044 case PROP_ORIENTATION:
1045 g_value_set_enum (value, icon_view->priv->orientation);
1048 g_value_set_int (value, icon_view->priv->columns);
1050 case PROP_ITEM_WIDTH:
1051 g_value_set_int (value, icon_view->priv->item_width);
1054 g_value_set_int (value, icon_view->priv->spacing);
1056 case PROP_ROW_SPACING:
1057 g_value_set_int (value, icon_view->priv->row_spacing);
1059 case PROP_COLUMN_SPACING:
1060 g_value_set_int (value, icon_view->priv->column_spacing);
1063 g_value_set_int (value, icon_view->priv->margin);
1065 case PROP_REORDERABLE:
1066 g_value_set_boolean (value, icon_view->priv->reorderable);
1070 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1075 /* GtkWidget signals */
1077 gtk_icon_view_realize (GtkWidget *widget)
1079 GtkIconView *icon_view;
1080 GdkWindowAttr attributes;
1081 gint attributes_mask;
1083 icon_view = GTK_ICON_VIEW (widget);
1085 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1087 /* Make the main, clipping window */
1088 attributes.window_type = GDK_WINDOW_CHILD;
1089 attributes.x = widget->allocation.x;
1090 attributes.y = widget->allocation.y;
1091 attributes.width = widget->allocation.width;
1092 attributes.height = widget->allocation.height;
1093 attributes.wclass = GDK_INPUT_OUTPUT;
1094 attributes.visual = gtk_widget_get_visual (widget);
1095 attributes.colormap = gtk_widget_get_colormap (widget);
1096 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1098 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1100 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1101 &attributes, attributes_mask);
1102 gdk_window_set_user_data (widget->window, widget);
1104 /* Make the window for the icon view */
1107 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1108 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1109 attributes.event_mask = (GDK_EXPOSURE_MASK |
1111 GDK_POINTER_MOTION_MASK |
1112 GDK_BUTTON_PRESS_MASK |
1113 GDK_BUTTON_RELEASE_MASK |
1114 GDK_KEY_PRESS_MASK |
1115 GDK_KEY_RELEASE_MASK) |
1116 gtk_widget_get_events (widget);
1118 icon_view->priv->bin_window = gdk_window_new (widget->window,
1119 &attributes, attributes_mask);
1120 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1122 widget->style = gtk_style_attach (widget->style, widget->window);
1123 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1124 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1126 gdk_window_show (icon_view->priv->bin_window);
1130 gtk_icon_view_unrealize (GtkWidget *widget)
1132 GtkIconView *icon_view;
1134 icon_view = GTK_ICON_VIEW (widget);
1136 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1137 gdk_window_destroy (icon_view->priv->bin_window);
1138 icon_view->priv->bin_window = NULL;
1140 /* GtkWidget::unrealize destroys children and widget->window */
1141 if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
1142 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
1146 gtk_icon_view_size_request (GtkWidget *widget,
1147 GtkRequisition *requisition)
1149 GtkIconView *icon_view;
1152 icon_view = GTK_ICON_VIEW (widget);
1154 requisition->width = icon_view->priv->width;
1155 requisition->height = icon_view->priv->height;
1157 tmp_list = icon_view->priv->children;
1161 GtkIconViewChild *child = tmp_list->data;
1162 GtkRequisition child_requisition;
1164 tmp_list = tmp_list->next;
1166 if (GTK_WIDGET_VISIBLE (child->widget))
1167 gtk_widget_size_request (child->widget, &child_requisition);
1172 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1176 for (list = icon_view->priv->children; list; list = list->next)
1178 GtkIconViewChild *child = list->data;
1179 GtkAllocation allocation;
1181 /* totally ignore our child's requisition */
1182 if (child->cell < 0)
1184 allocation.x = child->item->x;
1185 allocation.y = child->item->y;
1186 allocation.width = child->item->width;
1187 allocation.height = child->item->height;
1191 GdkRectangle *box = &child->item->box[child->cell];
1193 allocation.x = box->x;
1194 allocation.y = box->y;
1195 allocation.width = box->width;
1196 allocation.height = box->height;
1199 gtk_widget_size_allocate (child->widget, &allocation);
1204 gtk_icon_view_size_allocate (GtkWidget *widget,
1205 GtkAllocation *allocation)
1207 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1209 GtkAdjustment *hadjustment, *vadjustment;
1211 widget->allocation = *allocation;
1213 if (GTK_WIDGET_REALIZED (widget))
1215 gdk_window_move_resize (widget->window,
1216 allocation->x, allocation->y,
1217 allocation->width, allocation->height);
1218 gdk_window_resize (icon_view->priv->bin_window,
1219 MAX (icon_view->priv->width, allocation->width),
1220 MAX (icon_view->priv->height, allocation->height));
1223 gtk_icon_view_layout (icon_view);
1225 gtk_icon_view_allocate_children (icon_view);
1227 hadjustment = icon_view->priv->hadjustment;
1228 vadjustment = icon_view->priv->vadjustment;
1230 hadjustment->page_size = allocation->width;
1231 hadjustment->page_increment = allocation->width * 0.9;
1232 hadjustment->step_increment = allocation->width * 0.1;
1233 hadjustment->lower = 0;
1234 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1236 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1237 gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
1239 vadjustment->page_size = allocation->height;
1240 vadjustment->page_increment = allocation->height * 0.9;
1241 vadjustment->step_increment = allocation->height * 0.1;
1242 vadjustment->lower = 0;
1243 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1245 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1246 gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
1248 if (GTK_WIDGET_REALIZED (widget) &&
1249 icon_view->priv->scroll_to_path)
1252 path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
1253 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
1254 icon_view->priv->scroll_to_path = NULL;
1256 gtk_icon_view_scroll_to_path (icon_view, path,
1257 icon_view->priv->scroll_to_use_align,
1258 icon_view->priv->scroll_to_row_align,
1259 icon_view->priv->scroll_to_col_align);
1260 gtk_tree_path_free (path);
1264 gtk_adjustment_changed (hadjustment);
1265 gtk_adjustment_changed (vadjustment);
1270 gtk_icon_view_expose (GtkWidget *widget,
1271 GdkEventExpose *expose)
1273 GtkIconView *icon_view;
1278 GtkIconViewDropPosition dest_pos;
1279 GtkIconViewItem *dest_item = NULL;
1281 icon_view = GTK_ICON_VIEW (widget);
1283 if (expose->window != icon_view->priv->bin_window)
1286 cr = gdk_cairo_create (icon_view->priv->bin_window);
1287 cairo_set_line_width (cr, 1.);
1289 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1293 dest_index = gtk_tree_path_get_indices (path)[0];
1294 gtk_tree_path_free (path);
1299 for (icons = icon_view->priv->items; icons; icons = icons->next)
1301 GtkIconViewItem *item = icons->data;
1306 area.width = item->width;
1307 area.height = item->height;
1309 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1312 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1313 icon_view->priv->bin_window,
1314 item->x, item->y, TRUE);
1316 if (dest_index == item->index)
1324 case GTK_ICON_VIEW_DROP_INTO:
1325 gtk_paint_focus (widget->style,
1326 icon_view->priv->bin_window,
1327 GTK_WIDGET_STATE (widget),
1330 "iconview-drop-indicator",
1331 dest_item->x, dest_item->y,
1332 dest_item->width, dest_item->height);
1334 case GTK_ICON_VIEW_DROP_ABOVE:
1335 gtk_paint_focus (widget->style,
1336 icon_view->priv->bin_window,
1337 GTK_WIDGET_STATE (widget),
1340 "iconview-drop-indicator",
1341 dest_item->x, dest_item->y - 1,
1342 dest_item->width, 2);
1344 case GTK_ICON_VIEW_DROP_LEFT:
1345 gtk_paint_focus (widget->style,
1346 icon_view->priv->bin_window,
1347 GTK_WIDGET_STATE (widget),
1350 "iconview-drop-indicator",
1351 dest_item->x - 1, dest_item->y,
1352 2, dest_item->height);
1354 case GTK_ICON_VIEW_DROP_BELOW:
1355 gtk_paint_focus (widget->style,
1356 icon_view->priv->bin_window,
1357 GTK_WIDGET_STATE (widget),
1360 "iconview-drop-indicator",
1361 dest_item->x, dest_item->y + dest_item->height - 1,
1362 dest_item->width, 2);
1364 case GTK_ICON_VIEW_DROP_RIGHT:
1365 gtk_paint_focus (widget->style,
1366 icon_view->priv->bin_window,
1367 GTK_WIDGET_STATE (widget),
1370 "iconview-drop-indicator",
1371 dest_item->x + dest_item->width - 1, dest_item->y,
1372 2, dest_item->height);
1373 case GTK_ICON_VIEW_NO_DROP: ;
1378 if (icon_view->priv->doing_rubberband)
1380 GdkRectangle *rectangles;
1383 gdk_region_get_rectangles (expose->region,
1387 while (n_rectangles--)
1388 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1390 g_free (rectangles);
1395 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);
1401 rubberband_scroll_timeout (gpointer data)
1403 GtkIconView *icon_view;
1406 GDK_THREADS_ENTER ();
1410 value = MIN (icon_view->priv->vadjustment->value +
1411 icon_view->priv->scroll_value_diff,
1412 icon_view->priv->vadjustment->upper -
1413 icon_view->priv->vadjustment->page_size);
1415 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1417 gtk_icon_view_update_rubberband (icon_view);
1419 GDK_THREADS_LEAVE ();
1425 gtk_icon_view_motion (GtkWidget *widget,
1426 GdkEventMotion *event)
1428 GtkIconView *icon_view;
1431 icon_view = GTK_ICON_VIEW (widget);
1433 gtk_icon_view_maybe_begin_drag (icon_view, event);
1435 if (icon_view->priv->doing_rubberband)
1437 gtk_icon_view_update_rubberband (widget);
1439 abs_y = event->y - icon_view->priv->height *
1440 (icon_view->priv->vadjustment->value /
1441 (icon_view->priv->vadjustment->upper -
1442 icon_view->priv->vadjustment->lower));
1444 if (abs_y < 0 || abs_y > widget->allocation.height)
1447 icon_view->priv->scroll_value_diff = abs_y;
1449 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1451 icon_view->priv->event_last_x = event->x;
1452 icon_view->priv->event_last_y = event->y;
1454 if (icon_view->priv->scroll_timeout_id == 0)
1455 icon_view->priv->scroll_timeout_id = g_timeout_add (30, rubberband_scroll_timeout,
1459 remove_scroll_timeout (icon_view);
1466 gtk_icon_view_remove (GtkContainer *container,
1469 GtkIconView *icon_view;
1470 GtkIconViewChild *child = NULL;
1473 icon_view = GTK_ICON_VIEW (container);
1475 tmp_list = icon_view->priv->children;
1478 child = tmp_list->data;
1479 if (child->widget == widget)
1481 gtk_widget_unparent (widget);
1483 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1484 g_list_free_1 (tmp_list);
1489 tmp_list = tmp_list->next;
1494 gtk_icon_view_forall (GtkContainer *container,
1495 gboolean include_internals,
1496 GtkCallback callback,
1497 gpointer callback_data)
1499 GtkIconView *icon_view;
1500 GtkIconViewChild *child = NULL;
1503 icon_view = GTK_ICON_VIEW (container);
1505 tmp_list = icon_view->priv->children;
1508 child = tmp_list->data;
1509 tmp_list = tmp_list->next;
1511 (* callback) (child->widget, callback_data);
1516 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1517 GtkIconViewItem *item,
1518 GtkIconViewCellInfo *info,
1523 GdkRectangle cell_area;
1524 gboolean visible, mode;
1526 gtk_icon_view_set_cell_data (icon_view, item);
1528 g_object_get (info->cell,
1529 "visible", &visible,
1533 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1535 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1537 path = gtk_tree_path_new_from_indices (item->index, -1);
1538 path_string = gtk_tree_path_to_string (path);
1539 gtk_tree_path_free (path);
1541 gtk_cell_renderer_activate (info->cell,
1543 GTK_WIDGET (icon_view),
1549 g_free (path_string);
1554 gtk_icon_view_put (GtkIconView *icon_view,
1556 GtkIconViewItem *item,
1559 GtkIconViewChild *child;
1561 child = g_new (GtkIconViewChild, 1);
1563 child->widget = widget;
1567 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1569 if (GTK_WIDGET_REALIZED (icon_view))
1570 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1572 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1576 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1577 GtkIconView *icon_view)
1580 GtkIconViewItem *item;
1582 if (icon_view->priv->edited_item == NULL)
1585 item = icon_view->priv->edited_item;
1586 icon_view->priv->edited_item = NULL;
1587 icon_view->priv->editable = NULL;
1588 for (l = icon_view->priv->cell_list; l; l = l->next)
1590 GtkIconViewCellInfo *info = l->data;
1592 info->editing = FALSE;
1595 if (GTK_WIDGET_HAS_FOCUS (editable))
1596 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1598 g_signal_handlers_disconnect_by_func (editable,
1599 gtk_icon_view_remove_widget,
1602 gtk_container_remove (GTK_CONTAINER (icon_view),
1603 GTK_WIDGET (editable));
1605 gtk_icon_view_queue_draw_item (icon_view, item);
1610 gtk_icon_view_start_editing (GtkIconView *icon_view,
1611 GtkIconViewItem *item,
1612 GtkIconViewCellInfo *info,
1617 GdkRectangle cell_area;
1618 gboolean visible, mode;
1619 GtkCellEditable *editable;
1621 gtk_icon_view_set_cell_data (icon_view, item);
1623 g_object_get (info->cell,
1624 "visible", &visible,
1627 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1629 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1631 path = gtk_tree_path_new_from_indices (item->index, -1);
1632 path_string = gtk_tree_path_to_string (path);
1633 gtk_tree_path_free (path);
1635 editable = gtk_cell_renderer_start_editing (info->cell,
1637 GTK_WIDGET (icon_view),
1642 g_free (path_string);
1644 /* FIXME ugly special case */
1645 if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
1646 g_object_set (editable, "has_frame", TRUE, NULL);
1648 /* the rest corresponds to tree_view_real_start_editing... */
1649 icon_view->priv->edited_item = item;
1650 icon_view->priv->editable = editable;
1651 info->editing = TRUE;
1653 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1655 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1657 gtk_widget_grab_focus (GTK_WIDGET (editable));
1658 g_signal_connect (editable, "remove_widget",
1659 G_CALLBACK (gtk_icon_view_remove_widget),
1666 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1667 gboolean cancel_editing)
1669 GtkCellRenderer *cell = NULL;
1670 GtkIconViewItem *item;
1673 if (icon_view->priv->edited_item == NULL)
1677 * This is very evil. We need to do this, because
1678 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1679 * later on. If gtk_icon_view_row_changed notices
1680 * icon_view->priv->edited_item != NULL, it'll call
1681 * gtk_icon_view_stop_editing again. Bad things will happen then.
1683 * Please read that again if you intend to modify anything here.
1686 item = icon_view->priv->edited_item;
1687 icon_view->priv->edited_item = NULL;
1689 for (l = icon_view->priv->cell_list; l; l = l->next)
1691 GtkIconViewCellInfo *info = l->data;
1703 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1704 if (!cancel_editing)
1705 gtk_cell_editable_editing_done (icon_view->priv->editable);
1707 icon_view->priv->edited_item = item;
1709 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1713 * gtk_icon_view_set_cursor:
1714 * @icon_view: A #GtkIconView
1715 * @path: A #GtkTreePath
1716 * @cell: A #GtkCellRenderer or %NULL
1717 * @start_editing: %TRUE if the specified cell should start being edited.
1719 * Sets the current keyboard focus to be at @path, and selects it. This is
1720 * useful when you want to focus the user's attention on a particular item.
1721 * If @cell is not %NULL, then focus is given to the cell specified by
1722 * it. Additionally, if @start_editing is %TRUE, then editing should be
1723 * started in the specified cell.
1725 * This function is often followed by <literal>gtk_widget_grab_focus
1726 * (icon_view)</literal> in order to give keyboard focus to the widget.
1727 * Please note that editing can only happen when the widget is realized.
1732 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1734 GtkCellRenderer *cell,
1735 gboolean start_editing)
1737 GtkIconViewItem *item;
1738 GtkIconViewCellInfo *info = NULL;
1742 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1743 g_return_if_fail (path != NULL);
1744 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1746 gtk_icon_view_stop_editing (icon_view, TRUE);
1748 if (gtk_tree_path_get_depth (path) == 1)
1749 item = g_list_nth (icon_view->priv->items,
1750 gtk_tree_path_get_indices(path)[0])->data;
1756 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1760 if (info->cell == cell)
1769 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1770 if (FALSE && GTK_WIDGET_REALIZED (icon_view))
1771 gtk_icon_view_scroll_to_item (icon_view, item);
1773 gtk_icon_view_scroll_to_path (icon_view, path,
1777 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1781 * gtk_icon_view_get_cursor:
1782 * @icon_view: A #GtkIconView
1783 * @path: Return location for the current cursor path, or %NULL
1784 * @cell: Return location the current focus cell, or %NULL
1786 * Fills in @path and @cell with the current cursor path and cell.
1787 * If the cursor isn't currently set, then *@path will be %NULL.
1788 * If no cell currently has focus, then *@cell will be %NULL.
1790 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1792 * Return value: %TRUE if the cursor is set.
1797 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1799 GtkCellRenderer **cell)
1801 GtkIconViewItem *item;
1802 GtkIconViewCellInfo *info;
1804 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1806 item = icon_view->priv->cursor_item;
1807 if (icon_view->priv->cursor_cell < 0)
1810 info = g_list_nth_data (icon_view->priv->cell_list,
1811 icon_view->priv->cursor_cell);
1816 *path = gtk_tree_path_new_from_indices (item->index, -1);
1829 return (item != NULL);
1833 gtk_icon_view_button_press (GtkWidget *widget,
1834 GdkEventButton *event)
1836 GtkIconView *icon_view;
1837 GtkIconViewItem *item;
1838 GtkIconViewCellInfo *info = NULL;
1839 gboolean dirty = FALSE;
1840 GtkCellRendererMode mode;
1843 icon_view = GTK_ICON_VIEW (widget);
1845 if (event->window != icon_view->priv->bin_window)
1848 if (!GTK_WIDGET_HAS_FOCUS (widget))
1849 gtk_widget_grab_focus (widget);
1851 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1853 item = gtk_icon_view_get_item_at_coords (icon_view,
1859 g_object_get (info->cell, "mode", &mode, NULL);
1861 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
1862 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1863 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
1867 gtk_icon_view_scroll_to_item (icon_view, item);
1869 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1871 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1873 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1874 (event->state & GDK_SHIFT_MASK))
1876 gtk_icon_view_unselect_all_internal (icon_view);
1878 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1879 if (!icon_view->priv->anchor_item)
1880 icon_view->priv->anchor_item = item;
1882 gtk_icon_view_select_all_between (icon_view,
1883 icon_view->priv->anchor_item,
1889 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
1890 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
1891 (event->state & GDK_CONTROL_MASK))
1893 item->selected = !item->selected;
1894 gtk_icon_view_queue_draw_item (icon_view, item);
1899 if (!item->selected)
1901 gtk_icon_view_unselect_all_internal (icon_view);
1903 item->selected = TRUE;
1904 gtk_icon_view_queue_draw_item (icon_view, item);
1908 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1909 icon_view->priv->anchor_item = item;
1912 /* Save press to possibly begin a drag */
1913 if (icon_view->priv->pressed_button < 0)
1915 icon_view->priv->pressed_button = event->button;
1916 icon_view->priv->press_start_x = event->x;
1917 icon_view->priv->press_start_y = event->y;
1920 if (!icon_view->priv->last_single_clicked)
1921 icon_view->priv->last_single_clicked = item;
1923 /* cancel the current editing, if it exists */
1924 gtk_icon_view_stop_editing (icon_view, TRUE);
1926 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1927 gtk_icon_view_item_activate_cell (icon_view, item, info,
1929 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1930 gtk_icon_view_start_editing (icon_view, item, info,
1935 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
1936 !(event->state & GDK_CONTROL_MASK))
1938 dirty = gtk_icon_view_unselect_all_internal (icon_view);
1941 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
1942 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
1947 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
1949 item = gtk_icon_view_get_item_at_coords (icon_view,
1954 if (item && item == icon_view->priv->last_single_clicked)
1958 path = gtk_tree_path_new_from_indices (item->index, -1);
1959 gtk_icon_view_item_activated (icon_view, path);
1960 gtk_tree_path_free (path);
1963 icon_view->priv->last_single_clicked = NULL;
1967 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
1969 return event->button == 1;
1973 gtk_icon_view_button_release (GtkWidget *widget,
1974 GdkEventButton *event)
1976 GtkIconView *icon_view;
1978 icon_view = GTK_ICON_VIEW (widget);
1980 if (icon_view->priv->pressed_button == event->button)
1981 icon_view->priv->pressed_button = -1;
1983 gtk_icon_view_stop_rubberbanding (icon_view);
1985 remove_scroll_timeout (icon_view);
1991 gtk_icon_view_update_rubberband (gpointer data)
1993 GtkIconView *icon_view;
1995 GdkRectangle old_area;
1996 GdkRectangle new_area;
1997 GdkRectangle common;
1998 GdkRegion *invalid_region;
2000 icon_view = GTK_ICON_VIEW (data);
2002 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
2007 old_area.x = MIN (icon_view->priv->rubberband_x1,
2008 icon_view->priv->rubberband_x2);
2009 old_area.y = MIN (icon_view->priv->rubberband_y1,
2010 icon_view->priv->rubberband_y2);
2011 old_area.width = ABS (icon_view->priv->rubberband_x2 -
2012 icon_view->priv->rubberband_x1) + 1;
2013 old_area.height = ABS (icon_view->priv->rubberband_y2 -
2014 icon_view->priv->rubberband_y1) + 1;
2016 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
2017 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
2018 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
2019 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
2021 invalid_region = gdk_region_rectangle (&old_area);
2022 gdk_region_union_with_rect (invalid_region, &new_area);
2024 gdk_rectangle_intersect (&old_area, &new_area, &common);
2025 if (common.width > 2 && common.height > 2)
2027 GdkRegion *common_region;
2029 /* make sure the border is invalidated */
2035 common_region = gdk_region_rectangle (&common);
2037 gdk_region_subtract (invalid_region, common_region);
2038 gdk_region_destroy (common_region);
2041 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2043 gdk_region_destroy (invalid_region);
2045 icon_view->priv->rubberband_x2 = x;
2046 icon_view->priv->rubberband_y2 = y;
2048 gtk_icon_view_update_rubberband_selection (icon_view);
2052 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2058 g_assert (!icon_view->priv->doing_rubberband);
2060 for (items = icon_view->priv->items; items; items = items->next)
2062 GtkIconViewItem *item = items->data;
2064 item->selected_before_rubberbanding = item->selected;
2067 icon_view->priv->rubberband_x1 = x;
2068 icon_view->priv->rubberband_y1 = y;
2069 icon_view->priv->rubberband_x2 = x;
2070 icon_view->priv->rubberband_y2 = y;
2072 icon_view->priv->doing_rubberband = TRUE;
2074 gtk_grab_add (GTK_WIDGET (icon_view));
2078 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2080 if (!icon_view->priv->doing_rubberband)
2083 icon_view->priv->doing_rubberband = FALSE;
2085 gtk_grab_remove (GTK_WIDGET (icon_view));
2087 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2091 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2094 gint x, y, width, height;
2095 gboolean dirty = FALSE;
2097 x = MIN (icon_view->priv->rubberband_x1,
2098 icon_view->priv->rubberband_x2);
2099 y = MIN (icon_view->priv->rubberband_y1,
2100 icon_view->priv->rubberband_y2);
2101 width = ABS (icon_view->priv->rubberband_x1 -
2102 icon_view->priv->rubberband_x2);
2103 height = ABS (icon_view->priv->rubberband_y1 -
2104 icon_view->priv->rubberband_y2);
2106 for (items = icon_view->priv->items; items; items = items->next)
2108 GtkIconViewItem *item = items->data;
2112 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2113 x, y, width, height);
2115 selected = is_in ^ item->selected_before_rubberbanding;
2117 if (item->selected != selected)
2119 item->selected = selected;
2121 gtk_icon_view_queue_draw_item (icon_view, item);
2126 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2130 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2131 GtkIconViewItem *item,
2140 for (l = icon_view->priv->cell_list; l; l = l->next)
2142 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2144 if (!info->cell->visible)
2147 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2149 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2150 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2158 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2160 gboolean dirty = FALSE;
2163 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2166 for (items = icon_view->priv->items; items; items = items->next)
2168 GtkIconViewItem *item = items->data;
2172 item->selected = FALSE;
2174 gtk_icon_view_queue_draw_item (icon_view, item);
2182 /* GtkIconView signals */
2184 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2185 GtkAdjustment *hadj,
2186 GtkAdjustment *vadj)
2188 gboolean need_adjust = FALSE;
2191 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2193 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2195 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2197 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2199 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2201 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2202 0, 0, NULL, NULL, icon_view);
2203 g_object_unref (icon_view->priv->hadjustment);
2206 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2208 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2209 0, 0, NULL, NULL, icon_view);
2210 g_object_unref (icon_view->priv->vadjustment);
2213 if (icon_view->priv->hadjustment != hadj)
2215 icon_view->priv->hadjustment = hadj;
2216 g_object_ref (icon_view->priv->hadjustment);
2217 gtk_object_sink (GTK_OBJECT (icon_view->priv->hadjustment));
2219 g_signal_connect (icon_view->priv->hadjustment, "value_changed",
2220 G_CALLBACK (gtk_icon_view_adjustment_changed),
2225 if (icon_view->priv->vadjustment != vadj)
2227 icon_view->priv->vadjustment = vadj;
2228 g_object_ref (icon_view->priv->vadjustment);
2229 gtk_object_sink (GTK_OBJECT (icon_view->priv->vadjustment));
2231 g_signal_connect (icon_view->priv->vadjustment, "value_changed",
2232 G_CALLBACK (gtk_icon_view_adjustment_changed),
2238 gtk_icon_view_adjustment_changed (NULL, icon_view);
2242 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2244 gtk_icon_view_select_all (icon_view);
2248 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2250 gtk_icon_view_unselect_all (icon_view);
2254 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2256 gtk_icon_view_unselect_all (icon_view);
2258 if (icon_view->priv->cursor_item != NULL)
2259 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2263 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2266 GtkCellRendererMode mode;
2267 GtkIconViewCellInfo *info = NULL;
2269 if (!icon_view->priv->cursor_item)
2272 info = g_list_nth_data (icon_view->priv->cell_list,
2273 icon_view->priv->cursor_cell);
2277 g_object_get (info->cell, "mode", &mode, NULL);
2279 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2281 gtk_icon_view_item_activate_cell (icon_view,
2282 icon_view->priv->cursor_item,
2286 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2288 gtk_icon_view_start_editing (icon_view,
2289 icon_view->priv->cursor_item,
2295 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2296 gtk_icon_view_item_activated (icon_view, path);
2297 gtk_tree_path_free (path);
2303 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2305 if (!icon_view->priv->cursor_item)
2308 switch (icon_view->priv->selection_mode)
2310 case GTK_SELECTION_NONE:
2312 case GTK_SELECTION_BROWSE:
2313 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2315 case GTK_SELECTION_SINGLE:
2316 if (icon_view->priv->cursor_item->selected)
2317 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2319 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2321 case GTK_SELECTION_MULTIPLE:
2322 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2323 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2325 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2330 /* Internal functions */
2332 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2333 GtkIconView *icon_view)
2335 if (GTK_WIDGET_REALIZED (icon_view))
2337 gdk_window_move (icon_view->priv->bin_window,
2338 - icon_view->priv->hadjustment->value,
2339 - icon_view->priv->vadjustment->value);
2341 if (icon_view->priv->doing_rubberband)
2342 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2344 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2349 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2354 gint *maximum_width)
2358 gint x, current_width;
2359 GList *items, *last_item;
2366 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2367 max_height = g_new0 (gint, icon_view->priv->n_cells);
2374 gtk_widget_style_get (GTK_WIDGET (icon_view),
2375 "focus-line-width", &focus_width,
2378 spacing = icon_view->priv->spacing;
2380 x += icon_view->priv->margin + focus_width;
2381 current_width += 2 * (icon_view->priv->margin + focus_width);
2386 GtkIconViewItem *item = items->data;
2388 gtk_icon_view_calculate_item_size (icon_view, item);
2389 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2391 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2393 current_width += item->width;
2395 if (items != first_item)
2397 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2398 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2402 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2404 item->y = *y + focus_width;
2405 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2407 x = current_width - (icon_view->priv->margin + focus_width);
2409 for (i = 0; i < icon_view->priv->n_cells; i++)
2410 max_height[i] = MAX (max_height[i], item->box[i].height);
2412 if (current_width > *maximum_width)
2413 *maximum_width = current_width;
2419 items = items->next;
2424 /* Now go through the row again and align the icons */
2425 for (items = first_item; items != last_item; items = items->next)
2427 GtkIconViewItem *item = items->data;
2429 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2431 /* We may want to readjust the new y coordinate. */
2432 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2433 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2436 item->col = col - 1 - item->col;
2439 g_free (max_height);
2445 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2448 if (upper != adj->upper)
2450 gdouble min = MAX (0.0, upper - adj->page_size);
2451 gboolean value_changed = FALSE;
2455 if (adj->value > min)
2458 value_changed = TRUE;
2461 gtk_adjustment_changed (adj);
2464 gtk_adjustment_value_changed (adj);
2469 gtk_icon_view_layout (GtkIconView *icon_view)
2471 gint y = 0, maximum_width = 0;
2477 if (icon_view->priv->model == NULL)
2480 widget = GTK_WIDGET (icon_view);
2482 item_width = icon_view->priv->item_width;
2486 for (icons = icon_view->priv->items; icons; icons = icons->next)
2488 GtkIconViewItem *item = icons->data;
2489 gtk_icon_view_calculate_item_size (icon_view, item);
2490 item_width = MAX (item_width, item->width);
2494 icons = icon_view->priv->items;
2495 y += icon_view->priv->margin;
2500 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2502 &y, &maximum_width);
2505 while (icons != NULL);
2507 if (maximum_width != icon_view->priv->width)
2509 icon_view->priv->width = maximum_width;
2511 y += icon_view->priv->margin;
2513 if (y != icon_view->priv->height)
2515 icon_view->priv->height = y;
2518 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment, icon_view->priv->width);
2519 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment, icon_view->priv->height);
2521 if (GTK_WIDGET_REALIZED (icon_view))
2523 gdk_window_resize (icon_view->priv->bin_window,
2524 MAX (icon_view->priv->width, widget->allocation.width),
2525 MAX (icon_view->priv->height, widget->allocation.height));
2528 if (icon_view->priv->layout_idle_id != 0)
2530 g_source_remove (icon_view->priv->layout_idle_id);
2531 icon_view->priv->layout_idle_id = 0;
2534 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2538 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2539 GtkIconViewItem *item,
2540 GtkIconViewCellInfo *info,
2541 GdkRectangle *cell_area)
2543 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2545 cell_area->x = item->box[info->position].x - item->before[info->position];
2546 cell_area->y = item->y;
2547 cell_area->width = item->box[info->position].width +
2548 item->before[info->position] + item->after[info->position];
2549 cell_area->height = item->height;
2553 cell_area->x = item->x;
2554 cell_area->y = item->box[info->position].y - item->before[info->position];
2555 cell_area->width = item->width;
2556 cell_area->height = item->box[info->position].height +
2557 item->before[info->position] + item->after[info->position];
2562 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2563 GtkIconViewItem *item,
2564 GtkIconViewCellInfo *info,
2567 *box = item->box[info->position];
2570 /* try to guess a reasonable wrap width for an implicit text cell renderer
2573 adjust_wrap_width (GtkIconView *icon_view,
2574 GtkIconViewItem *item)
2576 GtkIconViewCellInfo *text_info;
2577 GtkIconViewCellInfo *pixbuf_info;
2578 gint pixbuf_width, wrap_width;
2580 if (icon_view->priv->item_width < 0 &&
2581 icon_view->priv->text_cell != -1 &&
2582 icon_view->priv->pixbuf_cell != -1)
2584 text_info = g_list_nth_data (icon_view->priv->cell_list,
2585 icon_view->priv->text_cell);
2586 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2587 icon_view->priv->pixbuf_cell);
2589 gtk_cell_renderer_get_size (pixbuf_info->cell,
2590 GTK_WIDGET (icon_view),
2595 if (item->width == -1)
2596 wrap_width = pixbuf_width;
2597 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2598 wrap_width = item->width;
2600 wrap_width = item->width - pixbuf_width - icon_view->priv->spacing;
2602 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2607 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2608 GtkIconViewItem *item)
2613 if (item->width != -1 && item->height != -1)
2616 if (item->n_cells != icon_view->priv->n_cells)
2618 g_free (item->before);
2619 g_free (item->after);
2622 item->before = g_new0 (gint, icon_view->priv->n_cells);
2623 item->after = g_new0 (gint, icon_view->priv->n_cells);
2624 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2626 item->n_cells = icon_view->priv->n_cells;
2629 gtk_icon_view_set_cell_data (icon_view, item);
2631 spacing = icon_view->priv->spacing;
2635 for (l = icon_view->priv->cell_list; l; l = l->next)
2637 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2639 if (!info->cell->visible)
2642 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2644 &item->box[info->position].width,
2645 &item->box[info->position].height);
2647 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2649 item->width += item->box[info->position].width
2650 + (info->position > 0 ? spacing : 0);
2651 item->height = MAX (item->height, item->box[info->position].height);
2655 item->width = MAX (item->width, item->box[info->position].width);
2656 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2662 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2663 GtkIconViewItem *item,
2666 GdkRectangle cell_area;
2672 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2674 gtk_icon_view_set_cell_data (icon_view, item);
2676 spacing = icon_view->priv->spacing;
2679 for (i = 0; i < icon_view->priv->n_cells; i++)
2681 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2682 item->height = MAX (item->height, max_height[i]);
2684 item->height += max_height[i] + (i > 0 ? spacing : 0);
2687 cell_area.x = item->x;
2688 cell_area.y = item->y;
2690 for (k = 0; k < 2; k++)
2691 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2693 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2695 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2698 if (!info->cell->visible)
2701 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2703 cell_area.width = item->box[info->position].width;
2704 cell_area.height = item->height;
2708 cell_area.width = item->width;
2709 cell_area.height = max_height[i];
2712 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2714 &item->box[info->position].x, &item->box[info->position].y,
2715 &item->box[info->position].width, &item->box[info->position].height);
2717 item->box[info->position].x += cell_area.x;
2718 item->box[info->position].y += cell_area.y;
2719 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2721 item->before[info->position] = item->box[info->position].x - cell_area.x;
2722 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2723 cell_area.x += cell_area.width + spacing;
2727 if (item->box[info->position].width > item->width)
2729 item->width = item->box[info->position].width;
2730 cell_area.width = item->width;
2732 item->before[info->position] = item->box[info->position].y - cell_area.y;
2733 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2734 cell_area.y += cell_area.height + spacing;
2738 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2740 for (i = 0; i < icon_view->priv->n_cells; i++)
2742 item->box[i].x = item->x + item->width -
2743 (item->box[i].x + item->box[i].width - item->x);
2749 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2751 g_list_foreach (icon_view->priv->items,
2752 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2756 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2763 gtk_icon_view_paint_item (GtkIconView *icon_view,
2765 GtkIconViewItem *item,
2767 GdkDrawable *drawable,
2770 gboolean draw_focus)
2772 gint focus_width, focus_pad;
2773 gint spacing, padding;
2774 GdkRectangle cell_area, box;
2779 GtkCellRendererState flags;
2781 if (icon_view->priv->model == NULL)
2784 gtk_icon_view_set_cell_data (icon_view, item);
2786 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2788 gtk_widget_style_get (GTK_WIDGET (icon_view),
2789 "focus-line-width", &focus_width,
2790 "focus-padding", &focus_pad,
2793 spacing = icon_view->priv->spacing;
2794 padding = focus_width;
2798 flags = GTK_CELL_RENDERER_SELECTED;
2799 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2800 state = GTK_STATE_SELECTED;
2802 state = GTK_STATE_ACTIVE;
2807 state = GTK_STATE_NORMAL;
2810 #ifdef DEBUG_ICON_VIEW
2811 gdk_draw_rectangle (drawable,
2812 GTK_WIDGET (icon_view)->style->black_gc,
2815 item->width, item->height);
2819 for (l = icon_view->priv->cell_list; l; l = l->next)
2821 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2823 if (!info->cell->visible)
2826 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2828 /* FIXME we hardwire background drawing behind text
2829 * cell renderers here
2831 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
2833 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
2834 cairo_rectangle (cr,
2835 x - item->x + box.x,
2836 y - item->y + box.y,
2837 box.width, box.height);
2842 for (l = icon_view->priv->cell_list; l; l = l->next)
2844 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2846 if (!info->cell->visible)
2849 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
2851 #ifdef DEBUG_ICON_VIEW
2852 gdk_draw_rectangle (drawable,
2853 GTK_WIDGET (icon_view)->style->black_gc,
2855 x - item->x + cell_area.x,
2856 y - item->y + cell_area.y,
2857 cell_area.width, cell_area.height);
2859 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2861 gdk_draw_rectangle (drawable,
2862 GTK_WIDGET (icon_view)->style->black_gc,
2864 x - item->x + box.x,
2865 y - item->y + box.y,
2866 box.width, box.height);
2869 cell_area.x = x - item->x + cell_area.x;
2870 cell_area.y = y - item->y + cell_area.y;
2872 gtk_cell_renderer_render (info->cell,
2874 GTK_WIDGET (icon_view),
2875 &cell_area, &cell_area, area, flags);
2879 /* FIXME where to draw the focus with generic cell renderers ? */
2881 GTK_WIDGET_HAS_FOCUS (icon_view) &&
2882 item == icon_view->priv->cursor_item)
2883 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2885 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2887 if (!info->cell->visible)
2890 if (icon_view->priv->cursor_cell < 0 &&
2891 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
2892 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
2893 icon_view->priv->cursor_cell = i;
2895 if (i == icon_view->priv->cursor_cell)
2897 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2899 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
2903 GTK_WIDGET (icon_view),
2905 x - item->x + box.x - padding,
2906 y - item->y + box.y - padding,
2907 box.width + 2 * padding,
2908 box.height + 2 * padding);
2915 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2920 GdkRectangle rubber_rect;
2921 GdkColor *fill_color_gdk;
2922 guchar fill_color_alpha;
2924 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2925 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2926 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2927 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2929 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
2932 gtk_widget_style_get (GTK_WIDGET (icon_view),
2933 "selection-box-color", &fill_color_gdk,
2934 "selection-box-alpha", &fill_color_alpha,
2937 if (!fill_color_gdk)
2938 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
2940 cairo_set_source_rgba (cr,
2941 fill_color_gdk->red / 65535.,
2942 fill_color_gdk->green / 65535.,
2943 fill_color_gdk->blue / 65535.,
2944 fill_color_alpha / 255.);
2947 gdk_cairo_rectangle (cr, &rect);
2951 /* Draw the border without alpha */
2952 cairo_set_source_rgb (cr,
2953 fill_color_gdk->red / 65535.,
2954 fill_color_gdk->green / 65535.,
2955 fill_color_gdk->blue / 65535.);
2956 cairo_rectangle (cr,
2957 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
2958 rubber_rect.width - 1, rubber_rect.height - 1);
2962 gdk_color_free (fill_color_gdk);
2966 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
2972 index = gtk_tree_path_get_indices (path)[0];
2974 for (l = icon_view->priv->items; l; l = l->next)
2976 GtkIconViewItem *item = l->data;
2978 if (item->index == index)
2980 gtk_icon_view_queue_draw_item (icon_view, item);
2987 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
2988 GtkIconViewItem *item)
2993 gtk_widget_style_get (GTK_WIDGET (icon_view),
2994 "focus-line-width", &focus_width,
2997 rect.x = item->x - focus_width;
2998 rect.y = item->y - focus_width;
2999 rect.width = item->width + 2 * focus_width;
3000 rect.height = item->height + 2 * focus_width;
3002 if (icon_view->priv->bin_window)
3003 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
3007 layout_callback (gpointer user_data)
3009 GtkIconView *icon_view;
3011 GDK_THREADS_ENTER ();
3013 icon_view = GTK_ICON_VIEW (user_data);
3015 icon_view->priv->layout_idle_id = 0;
3017 gtk_icon_view_layout (icon_view);
3019 GDK_THREADS_LEAVE();
3025 gtk_icon_view_queue_layout (GtkIconView *icon_view)
3027 if (icon_view->priv->layout_idle_id != 0)
3030 icon_view->priv->layout_idle_id = g_idle_add (layout_callback, icon_view);
3034 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
3035 GtkIconViewItem *item,
3039 AtkObject *item_obj;
3041 if (icon_view->priv->cursor_item == item &&
3042 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3045 if (icon_view->priv->cursor_item != NULL)
3046 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3048 icon_view->priv->cursor_item = item;
3049 if (cursor_cell >= 0)
3050 icon_view->priv->cursor_cell = cursor_cell;
3052 gtk_icon_view_queue_draw_item (icon_view, item);
3054 /* Notify that accessible focus object has changed */
3055 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3056 item_obj = atk_object_ref_accessible_child (obj, item->index);
3058 if (item_obj != NULL)
3060 atk_focus_tracker_notify (item_obj);
3061 g_object_unref (item_obj);
3066 static GtkIconViewItem *
3067 gtk_icon_view_item_new (void)
3069 GtkIconViewItem *item;
3071 item = g_new0 (GtkIconViewItem, 1);
3080 gtk_icon_view_item_free (GtkIconViewItem *item)
3082 g_return_if_fail (item != NULL);
3084 g_free (item->before);
3085 g_free (item->after);
3092 static GtkIconViewItem *
3093 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3096 gboolean only_in_cell,
3097 GtkIconViewCellInfo **cell_at_pos)
3102 for (items = icon_view->priv->items; items; items = items->next)
3104 GtkIconViewItem *item = items->data;
3106 if (x >= item->x - icon_view->priv->row_spacing/2 && x <= item->x + item->width + icon_view->priv->row_spacing/2 &&
3107 y >= item->y - icon_view->priv->column_spacing/2 && y <= item->y + item->height + icon_view->priv->column_spacing/2)
3109 if (only_in_cell || cell_at_pos)
3111 gtk_icon_view_set_cell_data (icon_view, item);
3113 for (l = icon_view->priv->cell_list; l; l = l->next)
3115 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3117 if (!info->cell->visible)
3120 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3122 if ((x >= box.x && x <= box.x + box.width &&
3123 y >= box.y && y <= box.y + box.height) ||
3125 x <= box.x + box.width &&
3127 y <= box.y + box.height))
3130 *cell_at_pos = info;
3140 *cell_at_pos = NULL;
3151 gtk_icon_view_select_item (GtkIconView *icon_view,
3152 GtkIconViewItem *item)
3154 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3155 g_return_if_fail (item != NULL);
3160 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3162 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3163 gtk_icon_view_unselect_all_internal (icon_view);
3165 item->selected = TRUE;
3167 gtk_icon_view_queue_draw_item (icon_view, item);
3169 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3174 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3175 GtkIconViewItem *item)
3177 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3178 g_return_if_fail (item != NULL);
3180 if (!item->selected)
3183 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3184 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3187 item->selected = FALSE;
3189 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3191 gtk_icon_view_queue_draw_item (icon_view, item);
3195 verify_items (GtkIconView *icon_view)
3200 for (items = icon_view->priv->items; items; items = items->next)
3202 GtkIconViewItem *item = items->data;
3204 if (item->index != i)
3205 g_error ("List item does not match its index: "
3206 "item index %d and list index %d\n", item->index, i);
3213 gtk_icon_view_row_changed (GtkTreeModel *model,
3218 GtkIconViewItem *item;
3220 GtkIconView *icon_view;
3222 icon_view = GTK_ICON_VIEW (data);
3224 gtk_icon_view_stop_editing (icon_view, TRUE);
3226 index = gtk_tree_path_get_indices(path)[0];
3227 item = g_list_nth_data (icon_view->priv->items, index);
3229 gtk_icon_view_item_invalidate_size (item);
3230 gtk_icon_view_queue_layout (icon_view);
3232 verify_items (icon_view);
3236 gtk_icon_view_row_inserted (GtkTreeModel *model,
3242 GtkIconViewItem *item;
3243 gboolean iters_persist;
3244 GtkIconView *icon_view;
3247 icon_view = GTK_ICON_VIEW (data);
3249 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3251 length = gtk_tree_model_iter_n_children (model, NULL);
3252 index = gtk_tree_path_get_indices(path)[0];
3254 item = gtk_icon_view_item_new ();
3259 item->index = index;
3261 /* FIXME: We can be more efficient here,
3262 we can store a tail pointer and use that when
3263 appending (which is a rather common operation)
3265 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3268 list = g_list_nth (icon_view->priv->items, index + 1);
3269 for (; list; list = list->next)
3276 verify_items (icon_view);
3280 gtk_icon_view_row_deleted (GtkTreeModel *model,
3285 GtkIconView *icon_view;
3286 GtkIconViewItem *item;
3288 gboolean emit = FALSE;
3290 icon_view = GTK_ICON_VIEW (data);
3292 index = gtk_tree_path_get_indices(path)[0];
3294 list = g_list_nth (icon_view->priv->items, index);
3297 gtk_icon_view_stop_editing (icon_view, TRUE);
3299 if (item == icon_view->priv->anchor_item)
3300 icon_view->priv->anchor_item = NULL;
3302 if (item == icon_view->priv->cursor_item)
3303 icon_view->priv->cursor_item = NULL;
3308 gtk_icon_view_item_free (item);
3310 for (next = list->next; next; next = next->next)
3317 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3319 gtk_icon_view_queue_layout (icon_view);
3321 verify_items (icon_view);
3324 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3328 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3329 GtkTreePath *parent,
3336 GtkIconView *icon_view;
3337 GList *items = NULL, *list;
3338 GtkIconViewItem **item_array;
3341 icon_view = GTK_ICON_VIEW (data);
3343 gtk_icon_view_stop_editing (icon_view, TRUE);
3345 length = gtk_tree_model_iter_n_children (model, NULL);
3347 order = g_new (gint, length);
3348 for (i = 0; i < length; i++)
3349 order [new_order[i]] = i;
3351 item_array = g_new (GtkIconViewItem *, length);
3352 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3353 item_array[order[i]] = list->data;
3356 for (i = length - 1; i >= 0; i--)
3358 item_array[i]->index = i;
3359 items = g_list_prepend (items, item_array[i]);
3362 g_free (item_array);
3363 g_list_free (icon_view->priv->items);
3364 icon_view->priv->items = items;
3366 gtk_icon_view_queue_layout (icon_view);
3368 verify_items (icon_view);
3372 gtk_icon_view_build_items (GtkIconView *icon_view)
3376 gboolean iters_persist;
3377 GList *items = NULL;
3379 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3381 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3389 GtkIconViewItem *item = gtk_icon_view_item_new ();
3398 items = g_list_prepend (items, item);
3400 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3402 icon_view->priv->items = g_list_reverse (items);
3406 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3409 GtkMovementStep step,
3413 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3418 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3423 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3426 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3431 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3438 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3439 GtkMovementStep step,
3442 GdkModifierType state;
3444 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3445 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3446 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3447 step == GTK_MOVEMENT_DISPLAY_LINES ||
3448 step == GTK_MOVEMENT_PAGES ||
3449 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3451 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3454 gtk_icon_view_stop_editing (icon_view, FALSE);
3455 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3457 if (gtk_get_current_event_state (&state))
3459 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3460 icon_view->priv->ctrl_pressed = TRUE;
3461 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3462 icon_view->priv->shift_pressed = TRUE;
3464 /* else we assume not pressed */
3468 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3469 case GTK_MOVEMENT_VISUAL_POSITIONS:
3470 gtk_icon_view_move_cursor_left_right (icon_view, count);
3472 case GTK_MOVEMENT_DISPLAY_LINES:
3473 gtk_icon_view_move_cursor_up_down (icon_view, count);
3475 case GTK_MOVEMENT_PAGES:
3476 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3478 case GTK_MOVEMENT_BUFFER_ENDS:
3479 gtk_icon_view_move_cursor_start_end (icon_view, count);
3482 g_assert_not_reached ();
3485 icon_view->priv->ctrl_pressed = FALSE;
3486 icon_view->priv->shift_pressed = FALSE;
3491 static GtkIconViewItem *
3492 find_item (GtkIconView *icon_view,
3493 GtkIconViewItem *current,
3499 GtkIconViewItem *item;
3501 /* FIXME: this could be more efficient
3503 row = current->row + row_ofs;
3504 col = current->col + col_ofs;
3506 for (items = icon_view->priv->items; items; items = items->next)
3509 if (item->row == row && item->col == col)
3517 find_cell (GtkIconView *icon_view,
3518 GtkIconViewItem *item,
3520 GtkOrientation orientation,
3531 if (icon_view->priv->orientation != orientation)
3534 gtk_icon_view_set_cell_data (icon_view, item);
3536 focusable = g_new0 (gint, icon_view->priv->n_cells);
3541 for (k = 0; k < 2; k++)
3542 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3544 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3546 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3549 if (!info->cell->visible)
3552 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3555 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3558 current = n_focusable;
3560 focusable[n_focusable] = i;
3566 if (n_focusable == 0)
3567 focusable[n_focusable++] = first_text;
3571 current = step > 0 ? 0 : n_focusable - 1;
3572 cell = focusable[current];
3575 if (current + *count < 0)
3578 *count = current + *count;
3580 else if (current + *count > n_focusable - 1)
3583 *count = current + *count - (n_focusable - 1);
3587 cell = focusable[current + *count];
3596 static GtkIconViewItem *
3597 find_item_page_up_down (GtkIconView *icon_view,
3598 GtkIconViewItem *current,
3605 y = current->y + count * icon_view->priv->vadjustment->page_size;
3607 item = g_list_find (icon_view->priv->items, current);
3612 for (next = item->next; next; next = next->next)
3614 if (((GtkIconViewItem *)next->data)->col == col)
3617 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3627 for (next = item->prev; next; next = next->prev)
3629 if (((GtkIconViewItem *)next->data)->col == col)
3632 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3646 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3647 GtkIconViewItem *anchor,
3648 GtkIconViewItem *cursor)
3651 GtkIconViewItem *item;
3652 gint row1, row2, col1, col2;
3653 gboolean dirty = FALSE;
3655 if (anchor->row < cursor->row)
3666 if (anchor->col < cursor->col)
3677 for (items = icon_view->priv->items; items; items = items->next)
3681 if (row1 <= item->row && item->row <= row2 &&
3682 col1 <= item->col && item->col <= col2)
3684 if (!item->selected)
3687 item->selected = TRUE;
3689 gtk_icon_view_queue_draw_item (icon_view, item);
3697 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3700 GtkIconViewItem *item;
3702 gboolean dirty = FALSE;
3705 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3708 if (!icon_view->priv->cursor_item)
3713 list = icon_view->priv->items;
3715 list = g_list_last (icon_view->priv->items);
3717 item = list ? list->data : NULL;
3722 item = icon_view->priv->cursor_item;
3723 cell = icon_view->priv->cursor_cell;
3724 step = count > 0 ? 1 : -1;
3727 cell = find_cell (icon_view, item, cell,
3728 GTK_ORIENTATION_VERTICAL,
3733 item = find_item (icon_view, item, step, 0);
3734 count = count - step;
3741 if (icon_view->priv->ctrl_pressed ||
3742 !icon_view->priv->shift_pressed ||
3743 !icon_view->priv->anchor_item ||
3744 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3745 icon_view->priv->anchor_item = item;
3747 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3749 if (!icon_view->priv->ctrl_pressed &&
3750 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3752 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3753 dirty = gtk_icon_view_select_all_between (icon_view,
3754 icon_view->priv->anchor_item,
3758 gtk_icon_view_scroll_to_item (icon_view, item);
3761 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3765 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3768 GtkIconViewItem *item;
3769 gboolean dirty = FALSE;
3771 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3774 if (!icon_view->priv->cursor_item)
3779 list = icon_view->priv->items;
3781 list = g_list_last (icon_view->priv->items);
3783 item = list ? list->data : NULL;
3786 item = find_item_page_up_down (icon_view,
3787 icon_view->priv->cursor_item,
3793 if (icon_view->priv->ctrl_pressed ||
3794 !icon_view->priv->shift_pressed ||
3795 !icon_view->priv->anchor_item ||
3796 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3797 icon_view->priv->anchor_item = item;
3799 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3801 if (!icon_view->priv->ctrl_pressed &&
3802 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3804 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3805 dirty = gtk_icon_view_select_all_between (icon_view,
3806 icon_view->priv->anchor_item,
3810 gtk_icon_view_scroll_to_item (icon_view, item);
3813 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3817 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3820 GtkIconViewItem *item;
3822 gboolean dirty = FALSE;
3825 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3828 if (!icon_view->priv->cursor_item)
3833 list = icon_view->priv->items;
3835 list = g_list_last (icon_view->priv->items);
3837 item = list ? list->data : NULL;
3841 item = icon_view->priv->cursor_item;
3842 cell = icon_view->priv->cursor_cell;
3843 step = count > 0 ? 1 : -1;
3846 cell = find_cell (icon_view, item, cell,
3847 GTK_ORIENTATION_HORIZONTAL,
3852 item = find_item (icon_view, item, 0, step);
3853 count = count - step;
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, cell);
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_start_end (GtkIconView *icon_view,
3887 GtkIconViewItem *item;
3889 gboolean dirty = FALSE;
3891 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3895 list = icon_view->priv->items;
3897 list = g_list_last (icon_view->priv->items);
3899 item = list ? list->data : NULL;
3904 if (icon_view->priv->ctrl_pressed ||
3905 !icon_view->priv->shift_pressed ||
3906 !icon_view->priv->anchor_item ||
3907 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3908 icon_view->priv->anchor_item = item;
3910 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3912 if (!icon_view->priv->ctrl_pressed &&
3913 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3915 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3916 dirty = gtk_icon_view_select_all_between (icon_view,
3917 icon_view->priv->anchor_item,
3921 gtk_icon_view_scroll_to_item (icon_view, item);
3924 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3928 * gtk_icon_view_scroll_to_path:
3929 * @icon_view: A #GtkIconView.
3930 * @path: The path of the item to move to.
3931 * @use_align: whether to use alignment arguments, or %FALSE.
3932 * @row_align: The vertical alignment of the item specified by @path.
3933 * @col_align: The horizontal alignment of the item specified by @column.
3935 * Moves the alignments of @icon_view to the position specified by @path.
3936 * @row_align determines where the row is placed, and @col_align determines where
3937 * @column is placed. Both are expected to be between 0.0 and 1.0.
3938 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means center.
3940 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3941 * tree does the minimum amount of work to scroll the item onto the screen.
3942 * This means that the item will be scrolled to the edge closest to its current
3943 * position. If the item is currently visible on the screen, nothing is done.
3945 * This function only works if the model is set, and @path is a valid row on the
3946 * model. If the model changes before the @icon_view is realized, the centered
3947 * path will be modified to reflect this change.
3952 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3958 GtkIconViewItem *item = NULL;
3960 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3961 g_return_if_fail (path != NULL);
3962 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3963 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3965 if (! GTK_WIDGET_REALIZED (icon_view))
3967 if (icon_view->priv->scroll_to_path)
3968 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
3970 icon_view->priv->scroll_to_path = NULL;
3973 icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
3975 icon_view->priv->scroll_to_use_align = use_align;
3976 icon_view->priv->scroll_to_row_align = row_align;
3977 icon_view->priv->scroll_to_col_align = col_align;
3982 if (gtk_tree_path_get_depth (path) > 0)
3983 item = g_list_nth_data (icon_view->priv->items,
3984 gtk_tree_path_get_indices(path)[0]);
3991 gint x, y, width, height;
3993 gfloat offset, value;
3995 gtk_widget_style_get (GTK_WIDGET (icon_view),
3996 "focus-line-width", &focus_width,
3999 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4001 offset = y + item->y - focus_width -
4002 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
4003 value = CLAMP (icon_view->priv->vadjustment->value + offset,
4004 icon_view->priv->vadjustment->lower,
4005 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
4006 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
4008 offset = x + item->x - focus_width -
4009 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
4010 value = CLAMP (icon_view->priv->hadjustment->value + offset,
4011 icon_view->priv->hadjustment->lower,
4012 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
4013 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
4015 gtk_adjustment_changed (icon_view->priv->hadjustment);
4016 gtk_adjustment_changed (icon_view->priv->vadjustment);
4019 gtk_icon_view_scroll_to_item (icon_view, item);
4024 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
4025 GtkIconViewItem *item)
4027 gint x, y, width, height;
4030 gtk_widget_style_get (GTK_WIDGET (icon_view),
4031 "focus-line-width", &focus_width,
4034 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
4036 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
4038 if (y + item->y - focus_width < 0)
4039 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4040 icon_view->priv->vadjustment->value + y + item->y - focus_width);
4041 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
4042 gtk_adjustment_set_value (icon_view->priv->vadjustment,
4043 icon_view->priv->vadjustment->value + y + item->y + item->height
4044 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
4046 if (x + item->x - focus_width < 0)
4047 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4048 icon_view->priv->hadjustment->value + x + item->x - focus_width);
4049 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
4050 gtk_adjustment_set_value (icon_view->priv->hadjustment,
4051 icon_view->priv->hadjustment->value + x + item->x + item->width
4052 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
4054 gtk_adjustment_changed (icon_view->priv->hadjustment);
4055 gtk_adjustment_changed (icon_view->priv->vadjustment);
4058 /* GtkCellLayout implementation */
4059 static GtkIconViewCellInfo *
4060 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4061 GtkCellRenderer *renderer)
4065 for (i = icon_view->priv->cell_list; i; i = i->next)
4067 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4069 if (info->cell == renderer)
4077 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4078 GtkIconViewItem *item)
4081 gboolean iters_persist;
4084 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4090 path = gtk_tree_path_new_from_indices (item->index, -1);
4091 gtk_tree_model_get_iter (icon_view->priv->model, &iter, path);
4092 gtk_tree_path_free (path);
4097 for (i = icon_view->priv->cell_list; i; i = i->next)
4100 GtkIconViewCellInfo *info = i->data;
4102 g_object_freeze_notify (G_OBJECT (info->cell));
4104 for (j = info->attributes; j && j->next; j = j->next->next)
4106 gchar *property = j->data;
4107 gint column = GPOINTER_TO_INT (j->next->data);
4108 GValue value = {0, };
4110 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4112 g_object_set_property (G_OBJECT (info->cell),
4114 g_value_unset (&value);
4118 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4120 icon_view->priv->model,
4124 g_object_thaw_notify (G_OBJECT (info->cell));
4127 adjust_wrap_width (icon_view, item);
4131 free_cell_attributes (GtkIconViewCellInfo *info)
4135 list = info->attributes;
4136 while (list && list->next)
4138 g_free (list->data);
4139 list = list->next->next;
4142 g_slist_free (info->attributes);
4143 info->attributes = NULL;
4147 free_cell_info (GtkIconViewCellInfo *info)
4149 free_cell_attributes (info);
4151 g_object_unref (info->cell);
4154 (* info->destroy) (info->func_data);
4160 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4161 GtkCellRenderer *renderer,
4164 GtkIconViewCellInfo *info;
4165 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4167 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4168 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4170 g_object_ref (renderer);
4171 gtk_object_sink (GTK_OBJECT (renderer));
4173 info = g_new0 (GtkIconViewCellInfo, 1);
4174 info->cell = renderer;
4175 info->expand = expand ? TRUE : FALSE;
4176 info->pack = GTK_PACK_START;
4177 info->position = icon_view->priv->n_cells;
4179 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4180 icon_view->priv->n_cells++;
4184 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4185 GtkCellRenderer *renderer,
4188 GtkIconViewCellInfo *info;
4189 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4191 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4192 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4194 g_object_ref (renderer);
4195 gtk_object_sink (GTK_OBJECT (renderer));
4197 info = g_new0 (GtkIconViewCellInfo, 1);
4198 info->cell = renderer;
4199 info->expand = expand ? TRUE : FALSE;
4200 info->pack = GTK_PACK_END;
4201 info->position = icon_view->priv->n_cells;
4203 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4204 icon_view->priv->n_cells++;
4208 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4209 GtkCellRenderer *renderer,
4210 const gchar *attribute,
4213 GtkIconViewCellInfo *info;
4214 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4216 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4217 g_return_if_fail (info != NULL);
4219 info->attributes = g_slist_prepend (info->attributes,
4220 GINT_TO_POINTER (column));
4221 info->attributes = g_slist_prepend (info->attributes,
4222 g_strdup (attribute));
4226 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4228 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4230 while (icon_view->priv->cell_list)
4232 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4233 free_cell_info (info);
4234 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4235 icon_view->priv->cell_list);
4238 icon_view->priv->n_cells = 0;
4242 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4243 GtkCellRenderer *cell,
4244 GtkCellLayoutDataFunc func,
4246 GDestroyNotify destroy)
4248 GtkIconViewCellInfo *info;
4249 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4251 info = gtk_icon_view_get_cell_info (icon_view, cell);
4252 g_return_if_fail (info != NULL);
4256 GDestroyNotify d = info->destroy;
4258 info->destroy = NULL;
4259 d (info->func_data);
4263 info->func_data = func_data;
4264 info->destroy = destroy;
4268 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4269 GtkCellRenderer *renderer)
4271 GtkIconViewCellInfo *info;
4273 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4275 free_cell_attributes (info);
4279 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4280 GtkCellRenderer *cell,
4283 GtkIconView *icon_view;
4285 GtkIconViewCellInfo *info;
4288 icon_view = GTK_ICON_VIEW (layout);
4290 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4292 info = gtk_icon_view_get_cell_info (icon_view, cell);
4294 g_return_if_fail (info != NULL);
4295 g_return_if_fail (position >= 0);
4297 link = g_list_find (icon_view->priv->cell_list, info);
4299 g_return_if_fail (link != NULL);
4301 icon_view->priv->cell_list = g_list_remove_link (icon_view->priv->cell_list,
4303 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4306 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4313 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4320 * gtk_icon_view_new:
4322 * Creates a new #GtkIconView widget
4324 * Return value: A newly created #GtkIconView widget
4329 gtk_icon_view_new (void)
4331 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4335 * gtk_icon_view_new_with_model:
4336 * @model: The model.
4338 * Creates a new #GtkIconView widget with the model @model.
4340 * Return value: A newly created #GtkIconView widget.
4345 gtk_icon_view_new_with_model (GtkTreeModel *model)
4347 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4352 * gtk_icon_view_get_path_at_pos:
4353 * @icon_view: A #GtkIconView.
4354 * @x: The x position to be identified
4355 * @y: The y position to be identified
4357 * Finds the path at the point (@x, @y), relative to widget coordinates.
4358 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4359 * the cell at the specified position.
4361 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4362 * if no icon exists at that position.
4367 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4371 GtkIconViewItem *item;
4374 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4376 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4381 path = gtk_tree_path_new_from_indices (item->index, -1);
4387 * gtk_icon_view_get_item_at_pos:
4388 * @icon_view: A #GtkIconView.
4389 * @x: The x position to be identified
4390 * @y: The y position to be identified
4391 * @path: Return location for the path, or %NULL
4392 * @cell: Return location for the renderer responsible for the cell
4393 * at (@x, @y), or %NULL
4395 * Finds the path at the point (@x, @y), relative to widget coordinates.
4396 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4397 * obtains the cell at the specified position. The returned path should
4398 * be freed with gtk_tree_path_free().
4400 * Return value: %TRUE if an item exists at the specified position
4405 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4409 GtkCellRenderer **cell)
4411 GtkIconViewItem *item;
4412 GtkIconViewCellInfo *info;
4414 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4416 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4421 *path = gtk_tree_path_new_from_indices (item->index, -1);
4434 return (item != NULL);
4439 * gtk_icon_view_get_visible_range:
4440 * @icon_view: A #GtkIconView
4441 * @start_path: Return location for start of region, or %NULL
4442 * @end_path: Return location for end of region, or %NULL
4444 * Sets @start_path and @end_path to be the first and last visible path.
4445 * Note that there may be invisible paths in between.
4447 * Both paths should be freed with gtk_tree_path_free() after use.
4449 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4454 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4455 GtkTreePath **start_path,
4456 GtkTreePath **end_path)
4458 gint start_index = -1;
4459 gint end_index = -1;
4460 GtkIconViewItem *item;
4463 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4465 if (icon_view->priv->hadjustment == NULL ||
4466 icon_view->priv->vadjustment == NULL)
4469 if (start_path == NULL && end_path == NULL)
4472 for (icons = icon_view->priv->items; icons; icons = icons->next)
4474 GtkIconViewItem *item = icons->data;
4476 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4477 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4478 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4479 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4481 if (start_index == -1)
4482 start_index = item->index;
4483 end_index = item->index;
4487 if (start_path && start_index != -1)
4488 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4489 if (end_path && end_index != -1)
4490 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4492 return start_index != -1;
4496 * gtk_icon_view_selected_foreach:
4497 * @icon_view: A #GtkIconView.
4498 * @func: The funcion to call for each selected icon.
4499 * @data: User data to pass to the function.
4501 * Calls a function for each selected icon. Note that the model or
4502 * selection cannot be modified from within this function.
4507 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4508 GtkIconViewForeachFunc func,
4513 for (list = icon_view->priv->items; list; list = list->next)
4515 GtkIconViewItem *item = list->data;
4516 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4519 (* func) (icon_view, path, data);
4521 gtk_tree_path_free (path);
4526 * gtk_icon_view_set_selection_mode:
4527 * @icon_view: A #GtkIconView.
4528 * @mode: The selection mode
4530 * Sets the selection mode of the @icon_view.
4535 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4536 GtkSelectionMode mode)
4538 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4540 if (mode == icon_view->priv->selection_mode)
4543 if (mode == GTK_SELECTION_NONE ||
4544 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4545 gtk_icon_view_unselect_all (icon_view);
4547 icon_view->priv->selection_mode = mode;
4549 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4553 * gtk_icon_view_get_selection_mode:
4554 * @icon_view: A #GtkIconView.
4556 * Gets the selection mode of the @icon_view.
4558 * Return value: the current selection mode
4563 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4565 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4567 return icon_view->priv->selection_mode;
4571 * gtk_icon_view_set_model:
4572 * @icon_view: A #GtkIconView.
4573 * @model: The model.
4575 * Sets the model for a #GtkIconView.
4576 * If the @icon_view already has a model set, it will remove
4577 * it before setting the new model. If @model is %NULL, then
4578 * it will unset the old model.
4583 gtk_icon_view_set_model (GtkIconView *icon_view,
4584 GtkTreeModel *model)
4586 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4587 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4589 if (icon_view->priv->model == model)
4592 if (icon_view->priv->scroll_to_path)
4594 gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
4595 icon_view->priv->scroll_to_path = NULL;
4598 gtk_icon_view_stop_editing (icon_view, TRUE);
4604 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
4606 if (icon_view->priv->pixbuf_column != -1)
4608 column_type = gtk_tree_model_get_column_type (model,
4609 icon_view->priv->pixbuf_column);
4611 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4614 if (icon_view->priv->text_column != -1)
4616 column_type = gtk_tree_model_get_column_type (model,
4617 icon_view->priv->text_column);
4619 g_return_if_fail (column_type == G_TYPE_STRING);
4622 if (icon_view->priv->markup_column != -1)
4624 column_type = gtk_tree_model_get_column_type (model,
4625 icon_view->priv->markup_column);
4627 g_return_if_fail (column_type == G_TYPE_STRING);
4632 if (icon_view->priv->model)
4634 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4635 gtk_icon_view_row_changed,
4637 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4638 gtk_icon_view_row_inserted,
4640 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4641 gtk_icon_view_row_deleted,
4643 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4644 gtk_icon_view_rows_reordered,
4647 g_object_unref (icon_view->priv->model);
4649 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4650 g_list_free (icon_view->priv->items);
4651 icon_view->priv->items = NULL;
4652 icon_view->priv->anchor_item = NULL;
4653 icon_view->priv->cursor_item = NULL;
4654 icon_view->priv->last_single_clicked = NULL;
4655 icon_view->priv->width = 0;
4656 icon_view->priv->height = 0;
4659 icon_view->priv->model = model;
4661 if (icon_view->priv->model)
4663 g_object_ref (icon_view->priv->model);
4664 g_signal_connect (icon_view->priv->model,
4666 G_CALLBACK (gtk_icon_view_row_changed),
4668 g_signal_connect (icon_view->priv->model,
4670 G_CALLBACK (gtk_icon_view_row_inserted),
4672 g_signal_connect (icon_view->priv->model,
4674 G_CALLBACK (gtk_icon_view_row_deleted),
4676 g_signal_connect (icon_view->priv->model,
4678 G_CALLBACK (gtk_icon_view_rows_reordered),
4681 gtk_icon_view_build_items (icon_view);
4683 gtk_icon_view_queue_layout (icon_view);
4686 g_object_notify (G_OBJECT (icon_view), "model");
4688 if (GTK_WIDGET_REALIZED (icon_view))
4689 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4693 * gtk_icon_view_get_model:
4694 * @icon_view: a #GtkIconView
4696 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4699 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
4704 gtk_icon_view_get_model (GtkIconView *icon_view)
4706 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4708 return icon_view->priv->model;
4712 update_text_cell (GtkIconView *icon_view)
4714 GtkIconViewCellInfo *info;
4718 if (icon_view->priv->text_column == -1 &&
4719 icon_view->priv->markup_column == -1)
4721 if (icon_view->priv->text_cell != -1)
4723 info = g_list_nth_data (icon_view->priv->cell_list,
4724 icon_view->priv->text_cell);
4726 g_list_remove (icon_view->priv->cell_list, info);
4728 free_cell_info (info);
4730 icon_view->priv->n_cells--;
4731 icon_view->priv->text_cell = -1;
4736 if (icon_view->priv->text_cell == -1)
4738 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
4739 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4740 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4743 if (info->cell == cell)
4745 icon_view->priv->text_cell = i;
4751 info = g_list_nth_data (icon_view->priv->cell_list,
4752 icon_view->priv->text_cell);
4754 if (icon_view->priv->markup_column != -1)
4755 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4757 "markup", icon_view->priv->markup_column,
4760 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4762 "text", icon_view->priv->text_column,
4765 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4766 g_object_set (info->cell,
4767 "wrap_mode", PANGO_WRAP_CHAR,
4768 "wrap_width", icon_view->priv->item_width,
4773 g_object_set (info->cell,
4774 "wrap_mode", PANGO_WRAP_CHAR,
4775 "wrap_width", icon_view->priv->item_width,
4783 update_pixbuf_cell (GtkIconView *icon_view)
4785 GtkIconViewCellInfo *info;
4789 if (icon_view->priv->pixbuf_column == -1)
4791 if (icon_view->priv->pixbuf_cell != -1)
4793 info = g_list_nth_data (icon_view->priv->cell_list,
4794 icon_view->priv->pixbuf_cell);
4796 g_list_remove (icon_view->priv->cell_list, info);
4798 free_cell_info (info);
4800 icon_view->priv->n_cells--;
4801 icon_view->priv->pixbuf_cell = -1;
4806 if (icon_view->priv->pixbuf_cell == -1)
4808 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
4810 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4811 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4814 if (info->cell == cell)
4816 icon_view->priv->pixbuf_cell = i;
4822 info = g_list_nth_data (icon_view->priv->cell_list,
4823 icon_view->priv->pixbuf_cell);
4825 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4827 "pixbuf", icon_view->priv->pixbuf_column,
4830 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4831 g_object_set (info->cell,
4832 "follow_state", TRUE,
4837 g_object_set (info->cell,
4838 "follow_state", TRUE,
4846 * gtk_icon_view_set_text_column:
4847 * @icon_view: A #GtkIconView.
4848 * @column: A column in the currently used model.
4850 * Sets the column with text for @icon_view to be @column. The text
4851 * column must be of type #G_TYPE_STRING.
4856 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4859 if (column == icon_view->priv->text_column)
4863 icon_view->priv->text_column = -1;
4866 if (icon_view->priv->model != NULL)
4870 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4872 g_return_if_fail (column_type == G_TYPE_STRING);
4875 icon_view->priv->text_column = column;
4878 gtk_icon_view_stop_editing (icon_view, TRUE);
4880 update_text_cell (icon_view);
4882 gtk_icon_view_invalidate_sizes (icon_view);
4883 gtk_icon_view_queue_layout (icon_view);
4885 g_object_notify (G_OBJECT (icon_view), "text-column");
4889 * gtk_icon_view_get_text_column:
4890 * @icon_view: A #GtkIconView.
4892 * Returns the column with text for @icon_view.
4894 * Returns: the text column, or -1 if it's unset.
4899 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4901 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4903 return icon_view->priv->text_column;
4907 * gtk_icon_view_set_markup_column:
4908 * @icon_view: A #GtkIconView.
4909 * @column: A column in the currently used model.
4911 * Sets the column with markup information for @icon_view to be
4912 * @column. The markup column must be of type #G_TYPE_STRING.
4913 * If the markup column is set to something, it overrides
4914 * the text column set by gtk_icon_view_set_text_column().
4919 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
4922 if (column == icon_view->priv->markup_column)
4926 icon_view->priv->markup_column = -1;
4929 if (icon_view->priv->model != NULL)
4933 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4935 g_return_if_fail (column_type == G_TYPE_STRING);
4938 icon_view->priv->markup_column = column;
4941 gtk_icon_view_stop_editing (icon_view, TRUE);
4943 update_text_cell (icon_view);
4945 gtk_icon_view_invalidate_sizes (icon_view);
4946 gtk_icon_view_queue_layout (icon_view);
4948 g_object_notify (G_OBJECT (icon_view), "markup-column");
4952 * gtk_icon_view_get_markup_column:
4953 * @icon_view: A #GtkIconView.
4955 * Returns the column with markup text for @icon_view.
4957 * Returns: the markup column, or -1 if it's unset.
4962 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
4964 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4966 return icon_view->priv->markup_column;
4970 * gtk_icon_view_set_pixbuf_column:
4971 * @icon_view: A #GtkIconView.
4972 * @column: A column in the currently used model.
4974 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
4975 * column must be of type #GDK_TYPE_PIXBUF
4980 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
4983 if (column == icon_view->priv->pixbuf_column)
4987 icon_view->priv->pixbuf_column = -1;
4990 if (icon_view->priv->model != NULL)
4994 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4996 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4999 icon_view->priv->pixbuf_column = column;
5002 gtk_icon_view_stop_editing (icon_view, TRUE);
5004 update_pixbuf_cell (icon_view);
5006 gtk_icon_view_invalidate_sizes (icon_view);
5007 gtk_icon_view_queue_layout (icon_view);
5009 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
5014 * gtk_icon_view_get_pixbuf_column:
5015 * @icon_view: A #GtkIconView.
5017 * Returns the column with pixbufs for @icon_view.
5019 * Returns: the pixbuf column, or -1 if it's unset.
5024 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
5026 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5028 return icon_view->priv->pixbuf_column;
5032 * gtk_icon_view_select_path:
5033 * @icon_view: A #GtkIconView.
5034 * @path: The #GtkTreePath to be selected.
5036 * Selects the row at @path.
5041 gtk_icon_view_select_path (GtkIconView *icon_view,
5044 GtkIconViewItem *item = NULL;
5046 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5047 g_return_if_fail (icon_view->priv->model != NULL);
5048 g_return_if_fail (path != NULL);
5050 if (gtk_tree_path_get_depth (path) > 0)
5051 item = g_list_nth_data (icon_view->priv->items,
5052 gtk_tree_path_get_indices(path)[0]);
5055 gtk_icon_view_select_item (icon_view, item);
5059 * gtk_icon_view_unselect_path:
5060 * @icon_view: A #GtkIconView.
5061 * @path: The #GtkTreePath to be unselected.
5063 * Unselects the row at @path.
5068 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5071 GtkIconViewItem *item;
5073 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5074 g_return_if_fail (icon_view->priv->model != NULL);
5075 g_return_if_fail (path != NULL);
5077 item = g_list_nth (icon_view->priv->items,
5078 gtk_tree_path_get_indices(path)[0])->data;
5083 gtk_icon_view_unselect_item (icon_view, item);
5087 * gtk_icon_view_get_selected_items:
5088 * @icon_view: A #GtkIconView.
5090 * Creates a list of paths of all selected items. Additionally, if you are
5091 * planning on modifying the model after calling this function, you may
5092 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5093 * To do this, you can use gtk_tree_row_reference_new().
5095 * To free the return value, use:
5096 * <informalexample><programlisting>
5097 * g_list_foreach (list, gtk_tree_path_free, NULL);
5098 * g_list_free (list);
5099 * </programlisting></informalexample>
5101 * Return value: A #GList containing a #GtkTreePath for each selected row.
5106 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5109 GList *selected = NULL;
5111 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5113 for (list = icon_view->priv->items; list != NULL; list = list->next)
5115 GtkIconViewItem *item = list->data;
5119 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5121 selected = g_list_prepend (selected, path);
5129 * gtk_icon_view_select_all:
5130 * @icon_view: A #GtkIconView.
5132 * Selects all the icons. @icon_view must has its selection mode set
5133 * to #GTK_SELECTION_MULTIPLE.
5138 gtk_icon_view_select_all (GtkIconView *icon_view)
5141 gboolean dirty = FALSE;
5143 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5145 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5148 for (items = icon_view->priv->items; items; items = items->next)
5150 GtkIconViewItem *item = items->data;
5152 if (!item->selected)
5155 item->selected = TRUE;
5156 gtk_icon_view_queue_draw_item (icon_view, item);
5161 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5165 * gtk_icon_view_unselect_all:
5166 * @icon_view: A #GtkIconView.
5168 * Unselects all the icons.
5173 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5175 gboolean dirty = FALSE;
5177 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5179 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5182 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5185 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5189 * gtk_icon_view_path_is_selected:
5190 * @icon_view: A #GtkIconView.
5191 * @path: A #GtkTreePath to check selection on.
5193 * Returns %TRUE if the icon pointed to by @path is currently
5194 * selected. If @icon does not point to a valid location, %FALSE is returned.
5196 * Return value: %TRUE if @path is selected.
5201 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5204 GtkIconViewItem *item;
5206 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5207 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5208 g_return_val_if_fail (path != NULL, FALSE);
5210 item = g_list_nth (icon_view->priv->items,
5211 gtk_tree_path_get_indices(path)[0])->data;
5216 return item->selected;
5220 * gtk_icon_view_item_activated:
5221 * @icon_view: A #GtkIconView
5222 * @path: The #GtkTreePath to be activated
5224 * Activates the item determined by @path.
5229 gtk_icon_view_item_activated (GtkIconView *icon_view,
5232 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5233 g_return_if_fail (path != NULL);
5235 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5239 * gtk_icon_view_set_orientation:
5240 * @icon_view: a #GtkIconView
5241 * @orientation: the relative position of texts and icons
5243 * Sets the ::orientation property which determines whether the labels
5244 * are drawn beside the icons instead of below.
5249 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5250 GtkOrientation orientation)
5252 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5254 if (icon_view->priv->orientation != orientation)
5256 icon_view->priv->orientation = orientation;
5258 gtk_icon_view_stop_editing (icon_view, TRUE);
5259 gtk_icon_view_invalidate_sizes (icon_view);
5260 gtk_icon_view_queue_layout (icon_view);
5262 update_text_cell (icon_view);
5263 update_pixbuf_cell (icon_view);
5265 g_object_notify (G_OBJECT (icon_view), "orientation");
5270 * gtk_icon_view_get_orientation:
5271 * @icon_view: a #GtkIconView
5273 * Returns the value of the ::orientation property which determines
5274 * whether the labels are drawn beside the icons instead of below.
5276 * Return value: the relative position of texts and icons
5281 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5283 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5284 GTK_ORIENTATION_VERTICAL);
5286 return icon_view->priv->orientation;
5290 * gtk_icon_view_set_columns:
5291 * @icon_view: a #GtkIconView
5292 * @columns: the number of columns
5294 * Sets the ::columns property which determines in how
5295 * many columns the icons are arranged. If @columns is
5296 * -1, the number of columns will be chosen automatically
5297 * to fill the available area.
5302 gtk_icon_view_set_columns (GtkIconView *icon_view,
5305 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5307 if (icon_view->priv->columns != columns)
5309 icon_view->priv->columns = columns;
5311 gtk_icon_view_stop_editing (icon_view, TRUE);
5312 gtk_icon_view_queue_layout (icon_view);
5314 g_object_notify (G_OBJECT (icon_view), "columns");
5319 * gtk_icon_view_get_columns:
5320 * @icon_view: a #GtkIconView
5322 * Returns the value of the ::columns property.
5324 * Return value: the number of columns, or -1
5329 gtk_icon_view_get_columns (GtkIconView *icon_view)
5331 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5333 return icon_view->priv->columns;
5337 * gtk_icon_view_set_item_width:
5338 * @icon_view: a #GtkIconView
5339 * @item_width: the width for each item
5341 * Sets the ::item-width property which specifies the width
5342 * to use for each item. If it is set to -1, the icon view will
5343 * automatically determine a suitable item size.
5348 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5351 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5353 if (icon_view->priv->item_width != item_width)
5355 icon_view->priv->item_width = item_width;
5357 gtk_icon_view_stop_editing (icon_view, TRUE);
5358 gtk_icon_view_invalidate_sizes (icon_view);
5359 gtk_icon_view_queue_layout (icon_view);
5361 update_text_cell (icon_view);
5363 g_object_notify (G_OBJECT (icon_view), "item-width");
5368 * gtk_icon_view_get_item_width:
5369 * @icon_view: a #GtkIconView
5371 * Returns the value of the ::item-width property.
5373 * Return value: the width of a single item, or -1
5378 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5380 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5382 return icon_view->priv->item_width;
5387 * gtk_icon_view_set_spacing:
5388 * @icon_view: a #GtkIconView
5389 * @spacing: the spacing
5391 * Sets the ::spacing property which specifies the space
5392 * which is inserted between the cells (i.e. the icon and
5393 * the text) of an item.
5398 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5401 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5403 if (icon_view->priv->spacing != spacing)
5405 icon_view->priv->spacing = spacing;
5407 gtk_icon_view_stop_editing (icon_view, TRUE);
5408 gtk_icon_view_invalidate_sizes (icon_view);
5409 gtk_icon_view_queue_layout (icon_view);
5411 g_object_notify (G_OBJECT (icon_view), "spacing");
5416 * gtk_icon_view_get_spacing:
5417 * @icon_view: a #GtkIconView
5419 * Returns the value of the ::spacing property.
5421 * Return value: the space between cells
5426 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5428 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5430 return icon_view->priv->spacing;
5434 * gtk_icon_view_set_row_spacing:
5435 * @icon_view: a #GtkIconView
5436 * @row_spacing: the row spacing
5438 * Sets the ::row-spacing property which specifies the space
5439 * which is inserted between the rows of the icon view.
5444 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5447 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5449 if (icon_view->priv->row_spacing != row_spacing)
5451 icon_view->priv->row_spacing = row_spacing;
5453 gtk_icon_view_stop_editing (icon_view, TRUE);
5454 gtk_icon_view_invalidate_sizes (icon_view);
5455 gtk_icon_view_queue_layout (icon_view);
5457 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5462 * gtk_icon_view_get_row_spacing:
5463 * @icon_view: a #GtkIconView
5465 * Returns the value of the ::row-spacing property.
5467 * Return value: the space between rows
5472 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5474 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5476 return icon_view->priv->row_spacing;
5480 * gtk_icon_view_set_column_spacing:
5481 * @icon_view: a #GtkIconView
5482 * @column_spacing: the column spacing
5484 * Sets the ::column-spacing property which specifies the space
5485 * which is inserted between the columns of the icon view.
5490 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5491 gint column_spacing)
5493 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5495 if (icon_view->priv->column_spacing != column_spacing)
5497 icon_view->priv->column_spacing = column_spacing;
5499 gtk_icon_view_stop_editing (icon_view, TRUE);
5500 gtk_icon_view_invalidate_sizes (icon_view);
5501 gtk_icon_view_queue_layout (icon_view);
5503 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5508 * gtk_icon_view_get_column_spacing:
5509 * @icon_view: a #GtkIconView
5511 * Returns the value of the ::column-spacing property.
5513 * Return value: the space between columns
5518 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5520 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5522 return icon_view->priv->column_spacing;
5526 * gtk_icon_view_set_margin:
5527 * @icon_view: a #GtkIconView
5528 * @margin: the margin
5530 * Sets the ::margin property which specifies the space
5531 * which is inserted at the top, bottom, left and right
5537 gtk_icon_view_set_margin (GtkIconView *icon_view,
5540 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5542 if (icon_view->priv->margin != margin)
5544 icon_view->priv->margin = margin;
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), "margin");
5555 * gtk_icon_view_get_margin:
5556 * @icon_view: a #GtkIconView
5558 * Returns the value of the ::margin property.
5560 * Return value: the space at the borders
5565 gtk_icon_view_get_margin (GtkIconView *icon_view)
5567 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5569 return icon_view->priv->margin;
5573 /* Get/set whether drag_motion requested the drag data and
5574 * drag_data_received should thus not actually insert the data,
5575 * since the data doesn't result from a drop.
5578 set_status_pending (GdkDragContext *context,
5579 GdkDragAction suggested_action)
5581 g_object_set_data (G_OBJECT (context),
5582 "gtk-icon-view-status-pending",
5583 GINT_TO_POINTER (suggested_action));
5586 static GdkDragAction
5587 get_status_pending (GdkDragContext *context)
5589 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5590 "gtk-icon-view-status-pending"));
5594 unset_reorderable (GtkIconView *icon_view)
5596 if (icon_view->priv->reorderable)
5598 icon_view->priv->reorderable = FALSE;
5599 g_object_notify (G_OBJECT (icon_view), "reorderable");
5604 clear_source_info (GtkIconView *icon_view)
5606 if (icon_view->priv->source_targets)
5607 gtk_target_list_unref (icon_view->priv->source_targets);
5608 icon_view->priv->source_targets = NULL;
5610 icon_view->priv->source_set = FALSE;
5614 clear_dest_info (GtkIconView *icon_view)
5616 if (icon_view->priv->dest_targets)
5617 gtk_target_list_unref (icon_view->priv->dest_targets);
5618 icon_view->priv->dest_targets = NULL;
5620 icon_view->priv->dest_set = FALSE;
5624 set_source_row (GdkDragContext *context,
5625 GtkTreeModel *model,
5626 GtkTreePath *source_row)
5629 g_object_set_data_full (G_OBJECT (context),
5630 "gtk-icon-view-source-row",
5631 gtk_tree_row_reference_new (model, source_row),
5632 (GDestroyNotify) gtk_tree_row_reference_free);
5634 g_object_set_data_full (G_OBJECT (context),
5635 "gtk-icon-view-source-row",
5640 get_source_row (GdkDragContext *context)
5642 GtkTreeRowReference *ref;
5644 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5647 return gtk_tree_row_reference_get_path (ref);
5654 GtkTreeRowReference *dest_row;
5655 gboolean empty_view_drop;
5656 gboolean drop_append_mode;
5660 dest_row_free (gpointer data)
5662 DestRow *dr = (DestRow *)data;
5664 gtk_tree_row_reference_free (dr->dest_row);
5669 set_dest_row (GdkDragContext *context,
5670 GtkTreeModel *model,
5671 GtkTreePath *dest_row,
5672 gboolean empty_view_drop,
5673 gboolean drop_append_mode)
5679 g_object_set_data_full (G_OBJECT (context),
5680 "gtk-icon-view-dest-row",
5685 dr = g_new0 (DestRow, 1);
5687 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5688 dr->empty_view_drop = empty_view_drop;
5689 dr->drop_append_mode = drop_append_mode;
5690 g_object_set_data_full (G_OBJECT (context),
5691 "gtk-icon-view-dest-row",
5692 dr, (GDestroyNotify) dest_row_free);
5696 get_dest_row (GdkDragContext *context)
5700 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5704 GtkTreePath *path = NULL;
5707 path = gtk_tree_row_reference_get_path (dr->dest_row);
5708 else if (dr->empty_view_drop)
5709 path = gtk_tree_path_new_from_indices (0, -1);
5713 if (path && dr->drop_append_mode)
5714 gtk_tree_path_next (path);
5723 check_model_dnd (GtkTreeModel *model,
5724 GType required_iface,
5725 const gchar *signal)
5727 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5729 g_warning ("You must override the default '%s' handler "
5730 "on GtkIconView when using models that don't support "
5731 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5732 "is to connect to '%s' and call "
5733 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5734 "the default handler from running. Look at the source code "
5735 "for the default handler in gtkiconview.c to get an idea what "
5736 "your handler should do. (gtkiconview.c is in the GTK+ source "
5737 "code.) If you're using GTK+ from a language other than C, "
5738 "there may be a more natural way to override default handlers, e.g. via derivation.",
5739 signal, g_type_name (required_iface), signal);
5747 remove_scroll_timeout (GtkIconView *icon_view)
5749 if (icon_view->priv->scroll_timeout_id != 0)
5751 g_source_remove (icon_view->priv->scroll_timeout_id);
5753 icon_view->priv->scroll_timeout_id = 0;
5758 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5760 gint px, py, x, y, width, height;
5761 gint hoffset, voffset;
5764 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
5765 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
5767 /* see if we are near the edge. */
5768 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5770 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5772 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5774 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5778 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
5779 icon_view->priv->vadjustment->lower,
5780 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
5781 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
5785 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
5786 icon_view->priv->hadjustment->lower,
5787 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
5788 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
5794 drag_scroll_timeout (gpointer data)
5796 GtkIconView *icon_view = GTK_ICON_VIEW (data);
5798 GDK_THREADS_ENTER ();
5800 gtk_icon_view_autoscroll (icon_view);
5802 GDK_THREADS_LEAVE ();
5809 set_destination (GtkIconView *icon_view,
5810 GdkDragContext *context,
5813 GdkDragAction *suggested_action,
5817 GtkTreePath *path = NULL;
5818 GtkIconViewDropPosition pos;
5819 GtkIconViewDropPosition old_pos;
5820 GtkTreePath *old_dest_path = NULL;
5821 gboolean can_drop = FALSE;
5823 widget = GTK_WIDGET (icon_view);
5825 *suggested_action = 0;
5828 if (!icon_view->priv->dest_set)
5830 /* someone unset us as a drag dest, note that if
5831 * we return FALSE drag_leave isn't called
5834 gtk_icon_view_set_drag_dest_item (icon_view,
5836 GTK_ICON_VIEW_DROP_LEFT);
5838 remove_scroll_timeout (GTK_ICON_VIEW (widget));
5840 return FALSE; /* no longer a drop site */
5843 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
5844 if (*target == GDK_NONE)
5847 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
5850 GtkTreeModel *model;
5852 /* the row got dropped on empty space, let's setup a special case
5856 gtk_tree_path_free (path);
5858 model = gtk_icon_view_get_model (icon_view);
5860 n_children = gtk_tree_model_iter_n_children (model, NULL);
5863 pos = GTK_ICON_VIEW_DROP_BELOW;
5864 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5868 pos = GTK_ICON_VIEW_DROP_ABOVE;
5869 path = gtk_tree_path_new_from_indices (0, -1);
5879 gtk_icon_view_get_drag_dest_item (icon_view,
5884 gtk_tree_path_free (old_dest_path);
5886 if (TRUE /* FIXME if the location droppable predicate */)
5894 GtkWidget *source_widget;
5896 *suggested_action = context->suggested_action;
5897 source_widget = gtk_drag_get_source_widget (context);
5899 if (source_widget == widget)
5901 /* Default to MOVE, unless the user has
5902 * pressed ctrl or shift to affect available actions
5904 if ((context->actions & GDK_ACTION_MOVE) != 0)
5905 *suggested_action = GDK_ACTION_MOVE;
5908 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5913 /* can't drop here */
5914 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5916 GTK_ICON_VIEW_DROP_LEFT);
5920 gtk_tree_path_free (path);
5926 get_logical_destination (GtkIconView *icon_view,
5927 gboolean *drop_append_mode)
5929 /* adjust path to point to the row the drop goes in front of */
5930 GtkTreePath *path = NULL;
5931 GtkIconViewDropPosition pos;
5933 *drop_append_mode = FALSE;
5935 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
5940 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
5941 pos == GTK_ICON_VIEW_DROP_BELOW)
5944 GtkTreeModel *model = icon_view->priv->model;
5946 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5947 !gtk_tree_model_iter_next (model, &iter))
5948 *drop_append_mode = TRUE;
5951 *drop_append_mode = FALSE;
5952 gtk_tree_path_next (path);
5960 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
5961 GdkEventMotion *event)
5963 GdkDragContext *context;
5964 GtkTreePath *path = NULL;
5966 GtkTreeModel *model;
5967 gboolean retval = FALSE;
5969 if (!icon_view->priv->source_set)
5972 if (icon_view->priv->pressed_button < 0)
5975 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
5976 icon_view->priv->press_start_x,
5977 icon_view->priv->press_start_y,
5978 event->x, event->y))
5981 model = gtk_icon_view_get_model (icon_view);
5986 button = icon_view->priv->pressed_button;
5987 icon_view->priv->pressed_button = -1;
5989 path = gtk_icon_view_get_path_at_pos (icon_view,
5990 icon_view->priv->press_start_x,
5991 icon_view->priv->press_start_y);
5996 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
5997 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6001 /* FIXME Check whether we're a start button, if not return FALSE and
6005 /* Now we can begin the drag */
6009 context = gtk_drag_begin (GTK_WIDGET (icon_view),
6010 icon_view->priv->source_targets,
6011 icon_view->priv->source_actions,
6015 set_source_row (context, model, path);
6019 gtk_tree_path_free (path);
6024 /* Source side drag signals */
6026 gtk_icon_view_drag_begin (GtkWidget *widget,
6027 GdkDragContext *context)
6029 GtkIconView *icon_view;
6030 GtkIconViewItem *item;
6035 icon_view = GTK_ICON_VIEW (widget);
6037 /* if the user uses a custom DnD impl, we don't set the icon here */
6038 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
6041 item = gtk_icon_view_get_item_at_coords (icon_view,
6042 icon_view->priv->press_start_x,
6043 icon_view->priv->press_start_y,
6047 g_return_if_fail (item != NULL);
6049 x = icon_view->priv->press_start_x - item->x + 1;
6050 y = icon_view->priv->press_start_y - item->y + 1;
6052 path = gtk_tree_path_new_from_indices (item->index, -1);
6053 icon = gtk_icon_view_create_drag_icon (icon_view, path);
6054 gtk_tree_path_free (path);
6056 gtk_drag_set_icon_pixmap (context,
6057 gdk_drawable_get_colormap (icon),
6062 g_object_unref (icon);
6066 gtk_icon_view_drag_end (GtkWidget *widget,
6067 GdkDragContext *context)
6073 gtk_icon_view_drag_data_get (GtkWidget *widget,
6074 GdkDragContext *context,
6075 GtkSelectionData *selection_data,
6079 GtkIconView *icon_view;
6080 GtkTreeModel *model;
6081 GtkTreePath *source_row;
6083 icon_view = GTK_ICON_VIEW (widget);
6084 model = gtk_icon_view_get_model (icon_view);
6089 if (!icon_view->priv->dest_set)
6092 source_row = get_source_row (context);
6094 if (source_row == NULL)
6097 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6098 * any model; for DragSource models there are some other targets
6102 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6103 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6108 /* If drag_data_get does nothing, try providing row data. */
6109 if (selection_data->target == gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE))
6110 gtk_tree_set_row_drag_data (selection_data,
6115 gtk_tree_path_free (source_row);
6119 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6120 GdkDragContext *context)
6122 GtkTreeModel *model;
6123 GtkIconView *icon_view;
6124 GtkTreePath *source_row;
6126 icon_view = GTK_ICON_VIEW (widget);
6127 model = gtk_icon_view_get_model (icon_view);
6129 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6132 if (!icon_view->priv->dest_set)
6135 source_row = get_source_row (context);
6137 if (source_row == NULL)
6140 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6143 gtk_tree_path_free (source_row);
6145 set_source_row (context, NULL, NULL);
6148 /* Target side drag signals */
6150 gtk_icon_view_drag_leave (GtkWidget *widget,
6151 GdkDragContext *context,
6154 GtkIconView *icon_view;
6156 icon_view = GTK_ICON_VIEW (widget);
6158 /* unset any highlight row */
6159 gtk_icon_view_set_drag_dest_item (icon_view,
6161 GTK_ICON_VIEW_DROP_LEFT);
6163 remove_scroll_timeout (icon_view);
6167 gtk_icon_view_drag_motion (GtkWidget *widget,
6168 GdkDragContext *context,
6173 GtkTreePath *path = NULL;
6174 GtkTreeModel *model;
6175 GtkIconViewDropPosition pos;
6176 GtkIconView *icon_view;
6177 GdkDragAction suggested_action = 0;
6181 icon_view = GTK_ICON_VIEW (widget);
6183 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6186 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6188 /* we only know this *after* set_desination_row */
6189 model = gtk_icon_view_get_model (icon_view);
6190 empty = icon_view->priv->empty_view_drop;
6192 if (path == NULL && !empty)
6194 /* Can't drop here. */
6195 gdk_drag_status (context, 0, time);
6199 if (icon_view->priv->scroll_timeout_id == 0)
6201 icon_view->priv->scroll_timeout_id =
6202 g_timeout_add (50, drag_scroll_timeout, icon_view);
6205 if (target == gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE))
6207 /* Request data so we can use the source row when
6208 * determining whether to accept the drop
6210 set_status_pending (context, suggested_action);
6211 gtk_drag_get_data (widget, context, target, time);
6215 set_status_pending (context, 0);
6216 gdk_drag_status (context, suggested_action, time);
6221 gtk_tree_path_free (path);
6227 gtk_icon_view_drag_drop (GtkWidget *widget,
6228 GdkDragContext *context,
6233 GtkIconView *icon_view;
6235 GdkDragAction suggested_action = 0;
6236 GdkAtom target = GDK_NONE;
6237 GtkTreeModel *model;
6238 gboolean drop_append_mode;
6240 icon_view = GTK_ICON_VIEW (widget);
6241 model = gtk_icon_view_get_model (icon_view);
6243 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6245 if (!icon_view->priv->dest_set)
6248 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6251 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6254 path = get_logical_destination (icon_view, &drop_append_mode);
6256 if (target != GDK_NONE && path != NULL)
6258 /* in case a motion had requested drag data, change things so we
6259 * treat drag data receives as a drop.
6261 set_status_pending (context, 0);
6262 set_dest_row (context, model, path,
6263 icon_view->priv->empty_view_drop, drop_append_mode);
6267 gtk_tree_path_free (path);
6269 /* Unset this thing */
6270 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6272 if (target != GDK_NONE)
6274 gtk_drag_get_data (widget, context, target, time);
6282 gtk_icon_view_drag_data_received (GtkWidget *widget,
6283 GdkDragContext *context,
6286 GtkSelectionData *selection_data,
6291 gboolean accepted = FALSE;
6292 GtkTreeModel *model;
6293 GtkIconView *icon_view;
6294 GtkTreePath *dest_row;
6295 GdkDragAction suggested_action;
6296 gboolean drop_append_mode;
6298 icon_view = GTK_ICON_VIEW (widget);
6299 model = gtk_icon_view_get_model (icon_view);
6301 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6304 if (!icon_view->priv->dest_set)
6307 suggested_action = get_status_pending (context);
6309 if (suggested_action)
6311 /* We are getting this data due to a request in drag_motion,
6312 * rather than due to a request in drag_drop, so we are just
6313 * supposed to call drag_status, not actually paste in the
6316 path = get_logical_destination (icon_view, &drop_append_mode);
6319 suggested_action = 0;
6321 if (suggested_action)
6323 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6326 suggested_action = 0;
6329 gdk_drag_status (context, suggested_action, time);
6332 gtk_tree_path_free (path);
6334 /* If you can't drop, remove user drop indicator until the next motion */
6335 if (suggested_action == 0)
6336 gtk_icon_view_set_drag_dest_item (icon_view,
6338 GTK_ICON_VIEW_DROP_LEFT);
6343 dest_row = get_dest_row (context);
6345 if (dest_row == NULL)
6348 if (selection_data->length >= 0)
6350 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6356 gtk_drag_finish (context,
6358 (context->action == GDK_ACTION_MOVE),
6361 gtk_tree_path_free (dest_row);
6364 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6367 /* Drag-and-Drop support */
6369 * gtk_icon_view_enable_model_drag_source:
6370 * @icon_view: a #GtkIconTreeView
6371 * @start_button_mask: Mask of allowed buttons to start drag
6372 * @targets: the table of targets that the drag will support
6373 * @n_targets: the number of items in @targets
6374 * @actions: the bitmask of possible actions for a drag from this
6377 * Turns @icon_view into a drag source for automatic DND.
6382 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6383 GdkModifierType start_button_mask,
6384 const GtkTargetEntry *targets,
6386 GdkDragAction actions)
6388 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6390 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6392 clear_source_info (icon_view);
6393 icon_view->priv->start_button_mask = start_button_mask;
6394 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6395 icon_view->priv->source_actions = actions;
6397 icon_view->priv->source_set = TRUE;
6399 unset_reorderable (icon_view);
6403 * gtk_icon_view_enable_model_drag_dest:
6404 * @icon_view: a #GtkIconView
6405 * @targets: the table of targets that the drag will support
6406 * @n_targets: the number of items in @targets
6407 * @actions: the bitmask of possible actions for a drag from this
6410 * Turns @icon_view into a drop destination for automatic DND.
6415 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6416 const GtkTargetEntry *targets,
6418 GdkDragAction actions)
6420 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6422 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6424 clear_dest_info (icon_view);
6426 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6427 icon_view->priv->dest_actions = actions;
6429 icon_view->priv->dest_set = TRUE;
6431 unset_reorderable (icon_view);
6435 * gtk_icon_view_unset_model_drag_source:
6436 * @icon_view: a #GtkIconView
6438 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6443 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6445 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6447 if (icon_view->priv->source_set)
6449 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6450 clear_source_info (icon_view);
6453 unset_reorderable (icon_view);
6457 * gtk_icon_view_unset_model_drag_dest:
6458 * @icon_view: a #GtkIconView
6460 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6465 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6467 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6469 if (icon_view->priv->dest_set)
6471 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6472 clear_dest_info (icon_view);
6475 unset_reorderable (icon_view);
6478 /* These are useful to implement your own custom stuff. */
6480 * gtk_icon_view_set_drag_dest_item:
6481 * @icon_view: a #GtkIconView
6482 * @path: The path of the item to highlight, or %NULL.
6483 * @pos: Specifies whether to drop, relative to the item
6485 * Sets the item that is highlighted for feedback.
6490 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6492 GtkIconViewDropPosition pos)
6494 /* Note; this function is exported to allow a custom DND
6495 * implementation, so it can't touch TreeViewDragInfo
6498 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6500 if (icon_view->priv->dest_item)
6502 GtkTreePath *current_path;
6503 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6504 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6505 icon_view->priv->dest_item = NULL;
6507 gtk_icon_view_queue_draw_path (icon_view, current_path);
6508 gtk_tree_path_free (current_path);
6511 /* special case a drop on an empty model */
6512 icon_view->priv->empty_view_drop = FALSE;
6513 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
6514 && gtk_tree_path_get_depth (path) == 1
6515 && gtk_tree_path_get_indices (path)[0] == 0)
6519 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6522 if (n_children == 0)
6523 icon_view->priv->empty_view_drop = TRUE;
6526 icon_view->priv->dest_pos = pos;
6530 icon_view->priv->dest_item =
6531 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6532 icon_view->priv->model, path);
6534 gtk_icon_view_queue_draw_path (icon_view, path);
6539 * gtk_icon_view_get_drag_dest_item:
6540 * @icon_view: a #GtkIconView
6541 * @path: Return location for the path of the highlighted item, or %NULL.
6542 * @pos: Return location for the drop position, or %NULL
6544 * Gets information about the item that is highlighted for feedback.
6549 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6551 GtkIconViewDropPosition *pos)
6553 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6557 if (icon_view->priv->dest_item)
6558 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6564 *pos = icon_view->priv->dest_pos;
6568 * gtk_icon_view_get_dest_item_at_pos:
6569 * @icon_view: a #GtkIconView
6570 * @drag_x: the position to determine the destination item for
6571 * @drag_y: the position to determine the destination item for
6572 * @path: Return location for the path of the highlighted item, or %NULL.
6573 * @pos: Return location for the drop position, or %NULL
6575 * Determines the destination item for a given position.
6577 * Return value: whether there is an item at the given position.
6582 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6586 GtkIconViewDropPosition *pos)
6588 GtkIconViewItem *item;
6590 /* Note; this function is exported to allow a custom DND
6591 * implementation, so it can't touch TreeViewDragInfo
6594 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6595 g_return_val_if_fail (drag_x >= 0, FALSE);
6596 g_return_val_if_fail (drag_y >= 0, FALSE);
6597 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6603 item = gtk_icon_view_get_item_at_coords (icon_view,
6604 drag_x + icon_view->priv->hadjustment->value,
6605 drag_y + icon_view->priv->vadjustment->value,
6612 *path = gtk_tree_path_new_from_indices (item->index, -1);
6616 if (drag_x < item->x + item->width / 4)
6617 *pos = GTK_ICON_VIEW_DROP_LEFT;
6618 else if (drag_x > item->x + item->width * 3 / 4)
6619 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6620 else if (drag_y < item->y + item->height / 4)
6621 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6622 else if (drag_y > item->y + item->height * 3 / 4)
6623 *pos = GTK_ICON_VIEW_DROP_BELOW;
6625 *pos = GTK_ICON_VIEW_DROP_INTO;
6632 * gtk_icon_view_create_drag_icon:
6633 * @icon_view: a #GtkIconView
6634 * @path: a #GtkTreePath in @icon_view
6636 * Creates a #GdkPixmap representation of the item at @path.
6637 * This image is used for a drag icon.
6639 * Return value: a newly-allocated pixmap of the drag icon.
6644 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6649 GdkPixmap *drawable;
6654 widget = GTK_WIDGET (icon_view);
6656 index = gtk_tree_path_get_indices (path)[0];
6658 for (l = icon_view->priv->items; l; l = l->next)
6660 GtkIconViewItem *item = l->data;
6662 if (index == item->index)
6664 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
6669 cr = gdk_cairo_create (drawable);
6670 cairo_set_line_width (cr, 1.);
6672 gdk_cairo_set_source_color
6673 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
6674 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
6679 area.width = item->width;
6680 area.height = item->height;
6682 gtk_icon_view_paint_item (icon_view, cr, item, &area,
6683 drawable, 1, 1, FALSE);
6685 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6686 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
6699 * gtk_icon_view_get_reorderable:
6700 * @icon_view: a #GtkIconView
6702 * Retrieves whether the user can reorder the list via drag-and-drop.
6703 * See gtk_icon_view_set_reorderable().
6705 * Return value: %TRUE if the list can be reordered.
6710 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6712 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6714 return icon_view->priv->reorderable;
6717 static const GtkTargetEntry item_targets[] = {
6718 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6723 * gtk_icon_view_set_reorderable:
6724 * @icon_view: A #GtkIconView.
6725 * @reorderable: %TRUE, if the list of items can be reordered.
6727 * This function is a convenience function to allow you to reorder models that
6728 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6729 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6730 * the user can reorder the model by dragging and dropping rows. The
6731 * developer can listen to these changes by connecting to the model's
6732 * row_inserted and row_deleted signals.
6734 * This function does not give you any degree of control over the order -- any
6735 * reordering is allowed. If more control is needed, you should probably
6736 * handle drag and drop manually.
6741 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6742 gboolean reorderable)
6744 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6746 reorderable = reorderable != FALSE;
6748 if (icon_view->priv->reorderable == reorderable)
6753 gtk_icon_view_enable_model_drag_source (icon_view,
6756 G_N_ELEMENTS (item_targets),
6758 gtk_icon_view_enable_model_drag_dest (icon_view,
6760 G_N_ELEMENTS (item_targets),
6765 gtk_icon_view_unset_model_drag_source (icon_view);
6766 gtk_icon_view_unset_model_drag_dest (icon_view);
6769 icon_view->priv->reorderable = reorderable;
6771 g_object_notify (G_OBJECT (icon_view), "reorderable");
6775 /* Accessibility Support */
6777 static gpointer accessible_parent_class;
6778 static gpointer accessible_item_parent_class;
6779 static GQuark accessible_private_data_quark = 0;
6781 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6782 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6783 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6785 static GType gtk_icon_view_item_accessible_get_type (void);
6796 GtkIconViewItem *item;
6800 AtkStateSet *state_set;
6804 GtkTextBuffer *text_buffer;
6806 gchar *action_descriptions[LAST_ACTION];
6807 gchar *image_description;
6808 guint action_idle_handler;
6809 } GtkIconViewItemAccessible;
6811 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
6817 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
6822 typedef struct _GtkIconViewItemAccessibleClass
6824 AtkObjectClass parent_class;
6826 } GtkIconViewItemAccessibleClass;
6828 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
6831 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
6833 GtkIconViewItemAccessible *item;
6834 GtkIconView *icon_view;
6837 GDK_THREADS_ENTER ();
6839 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
6840 item->action_idle_handler = 0;
6842 if (item->widget != NULL)
6844 icon_view = GTK_ICON_VIEW (item->widget);
6845 path = gtk_tree_path_new_from_indices (item->item->index, -1);
6846 gtk_icon_view_item_activated (icon_view, path);
6847 gtk_tree_path_free (path);
6850 GDK_THREADS_LEAVE ();
6856 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
6859 GtkIconViewItemAccessible *item;
6860 GtkIconView *icon_view;
6862 if (i < 0 || i >= LAST_ACTION)
6865 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6867 if (!GTK_IS_ICON_VIEW (item->widget))
6870 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6873 icon_view = GTK_ICON_VIEW (item->widget);
6877 case ACTION_ACTIVATE:
6878 if (!item->action_idle_handler)
6879 item->action_idle_handler = g_idle_add (gtk_icon_view_item_accessible_idle_do_action, item);
6882 g_assert_not_reached ();
6890 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
6895 static const gchar *
6896 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
6899 GtkIconViewItemAccessible *item;
6901 if (i < 0 || i >= LAST_ACTION)
6904 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6906 if (item->action_descriptions[i])
6907 return item->action_descriptions[i];
6909 return gtk_icon_view_item_accessible_action_descriptions[i];
6912 static const gchar *
6913 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
6916 if (i < 0 || i >= LAST_ACTION)
6919 return gtk_icon_view_item_accessible_action_names[i];
6923 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
6925 const gchar *description)
6927 GtkIconViewItemAccessible *item;
6929 if (i < 0 || i >= LAST_ACTION)
6932 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6934 if (item->action_descriptions[i])
6935 g_free (item->action_descriptions[i]);
6937 item->action_descriptions[i] = g_strdup (description);
6943 atk_action_item_interface_init (AtkActionIface *iface)
6945 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
6946 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
6947 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
6948 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
6949 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
6952 static const gchar *
6953 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
6955 GtkIconViewItemAccessible *item;
6957 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6959 return item->image_description;
6963 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
6964 const gchar *description)
6966 GtkIconViewItemAccessible *item;
6968 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6970 g_free (item->image_description);
6971 item->image_description = g_strdup (item->image_description);
6977 get_pixbuf_box (GtkIconView *icon_view,
6978 GtkIconViewItem *item,
6983 for (l = icon_view->priv->cell_list; l; l = l->next)
6985 GtkIconViewCellInfo *info = l->data;
6987 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
6989 gtk_icon_view_get_cell_box (icon_view, item, info, box);
6999 get_text (GtkIconView *icon_view,
7000 GtkIconViewItem *item)
7005 for (l = icon_view->priv->cell_list; l; l = l->next)
7007 GtkIconViewCellInfo *info = l->data;
7009 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
7011 g_object_get (info->cell, "text", &text, NULL);
7021 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
7025 GtkIconViewItemAccessible *item;
7028 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7030 if (!GTK_IS_ICON_VIEW (item->widget))
7033 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7036 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7039 *height = box.height;
7044 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
7047 AtkCoordType coord_type)
7049 GtkIconViewItemAccessible *item;
7052 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
7054 if (!GTK_IS_ICON_VIEW (item->widget))
7057 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7060 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
7062 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7064 *x+= box.x - item->item->x;
7065 *y+= box.y - item->item->y;
7071 atk_image_item_interface_init (AtkImageIface *iface)
7073 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7074 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7075 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7076 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7080 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7084 GtkIconViewItemAccessible *item;
7085 GtkTextIter start, end;
7086 GtkTextBuffer *buffer;
7088 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7090 if (!GTK_IS_ICON_VIEW (item->widget))
7093 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7096 buffer = item->text_buffer;
7097 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7099 gtk_text_buffer_get_end_iter (buffer, &end);
7101 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7103 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7107 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7110 GtkIconViewItemAccessible *item;
7111 GtkTextIter start, end;
7112 GtkTextBuffer *buffer;
7116 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7118 if (!GTK_IS_ICON_VIEW (item->widget))
7121 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7124 buffer = item->text_buffer;
7125 if (offset >= gtk_text_buffer_get_char_count (buffer))
7128 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7130 gtk_text_iter_forward_char (&end);
7131 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7132 unichar = g_utf8_get_char (string);
7139 get_pango_text_offsets (PangoLayout *layout,
7140 GtkTextBuffer *buffer,
7142 AtkTextBoundary boundary_type,
7146 GtkTextIter *start_iter,
7147 GtkTextIter *end_iter)
7149 PangoLayoutIter *iter;
7150 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7151 gint index, start_index, end_index;
7153 gboolean found = FALSE;
7155 text = pango_layout_get_text (layout);
7156 index = g_utf8_offset_to_pointer (text, offset) - text;
7157 iter = pango_layout_get_iter (layout);
7160 line = pango_layout_iter_get_line (iter);
7161 start_index = line->start_index;
7162 end_index = start_index + line->length;
7164 if (index >= start_index && index <= end_index)
7167 * Found line for offset
7173 * We want the previous line
7177 switch (boundary_type)
7179 case ATK_TEXT_BOUNDARY_LINE_START:
7180 end_index = start_index;
7181 start_index = prev_line->start_index;
7183 case ATK_TEXT_BOUNDARY_LINE_END:
7185 start_index = prev_prev_line->start_index +
7186 prev_prev_line->length;
7187 end_index = prev_line->start_index + prev_line->length;
7190 g_assert_not_reached();
7194 start_index = end_index = 0;
7197 switch (boundary_type)
7199 case ATK_TEXT_BOUNDARY_LINE_START:
7200 if (pango_layout_iter_next_line (iter))
7201 end_index = pango_layout_iter_get_line (iter)->start_index;
7203 case ATK_TEXT_BOUNDARY_LINE_END:
7205 start_index = prev_line->start_index +
7209 g_assert_not_reached();
7214 * We want the next line
7216 if (pango_layout_iter_next_line (iter))
7218 line = pango_layout_iter_get_line (iter);
7219 switch (boundary_type)
7221 case ATK_TEXT_BOUNDARY_LINE_START:
7222 start_index = line->start_index;
7223 if (pango_layout_iter_next_line (iter))
7224 end_index = pango_layout_iter_get_line (iter)->start_index;
7226 end_index = start_index + line->length;
7228 case ATK_TEXT_BOUNDARY_LINE_END:
7229 start_index = end_index;
7230 end_index = line->start_index + line->length;
7233 g_assert_not_reached();
7237 start_index = end_index;
7243 prev_prev_line = prev_line;
7246 while (pango_layout_iter_next_line (iter));
7250 start_index = prev_line->start_index + prev_line->length;
7251 end_index = start_index;
7253 pango_layout_iter_free (iter);
7254 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7255 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7257 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7258 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7262 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7264 AtkTextBoundary boundary_type,
7268 GtkIconViewItemAccessible *item;
7269 GtkTextIter start, end;
7270 GtkTextBuffer *buffer;
7271 GtkIconView *icon_view;
7273 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7275 if (!GTK_IS_ICON_VIEW (item->widget))
7278 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7281 buffer = item->text_buffer;
7283 if (!gtk_text_buffer_get_char_count (buffer))
7287 return g_strdup ("");
7289 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7293 switch (boundary_type)
7295 case ATK_TEXT_BOUNDARY_CHAR:
7296 gtk_text_iter_backward_char(&start);
7298 case ATK_TEXT_BOUNDARY_WORD_START:
7299 if (!gtk_text_iter_starts_word (&start))
7300 gtk_text_iter_backward_word_start (&start);
7302 gtk_text_iter_backward_word_start(&start);
7304 case ATK_TEXT_BOUNDARY_WORD_END:
7305 if (gtk_text_iter_inside_word (&start) &&
7306 !gtk_text_iter_starts_word (&start))
7307 gtk_text_iter_backward_word_start (&start);
7308 while (!gtk_text_iter_ends_word (&start))
7310 if (!gtk_text_iter_backward_char (&start))
7314 gtk_text_iter_backward_word_start(&start);
7315 while (!gtk_text_iter_ends_word (&start))
7317 if (!gtk_text_iter_backward_char (&start))
7321 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7322 if (!gtk_text_iter_starts_sentence (&start))
7323 gtk_text_iter_backward_sentence_start (&start);
7325 gtk_text_iter_backward_sentence_start (&start);
7327 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7328 if (gtk_text_iter_inside_sentence (&start) &&
7329 !gtk_text_iter_starts_sentence (&start))
7330 gtk_text_iter_backward_sentence_start (&start);
7331 while (!gtk_text_iter_ends_sentence (&start))
7333 if (!gtk_text_iter_backward_char (&start))
7337 gtk_text_iter_backward_sentence_start (&start);
7338 while (!gtk_text_iter_ends_sentence (&start))
7340 if (!gtk_text_iter_backward_char (&start))
7344 case ATK_TEXT_BOUNDARY_LINE_START:
7345 case ATK_TEXT_BOUNDARY_LINE_END:
7346 icon_view = GTK_ICON_VIEW (item->widget);
7348 /* FIXME we probably have to use GailTextCell to salvage this */
7349 gtk_icon_view_update_item_text (icon_view, item->item);
7350 get_pango_text_offsets (icon_view->priv->layout,
7363 *start_offset = gtk_text_iter_get_offset (&start);
7364 *end_offset = gtk_text_iter_get_offset (&end);
7366 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7370 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7372 AtkTextBoundary boundary_type,
7376 GtkIconViewItemAccessible *item;
7377 GtkTextIter start, end;
7378 GtkTextBuffer *buffer;
7379 GtkIconView *icon_view;
7381 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7383 if (!GTK_IS_ICON_VIEW (item->widget))
7386 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7389 buffer = item->text_buffer;
7391 if (!gtk_text_buffer_get_char_count (buffer))
7395 return g_strdup ("");
7397 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7401 switch (boundary_type)
7403 case ATK_TEXT_BOUNDARY_CHAR:
7404 gtk_text_iter_forward_char (&end);
7406 case ATK_TEXT_BOUNDARY_WORD_START:
7407 if (!gtk_text_iter_starts_word (&start))
7408 gtk_text_iter_backward_word_start (&start);
7409 if (gtk_text_iter_inside_word (&end))
7410 gtk_text_iter_forward_word_end (&end);
7411 while (!gtk_text_iter_starts_word (&end))
7413 if (!gtk_text_iter_forward_char (&end))
7417 case ATK_TEXT_BOUNDARY_WORD_END:
7418 if (gtk_text_iter_inside_word (&start) &&
7419 !gtk_text_iter_starts_word (&start))
7420 gtk_text_iter_backward_word_start (&start);
7421 while (!gtk_text_iter_ends_word (&start))
7423 if (!gtk_text_iter_backward_char (&start))
7426 gtk_text_iter_forward_word_end (&end);
7428 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7429 if (!gtk_text_iter_starts_sentence (&start))
7430 gtk_text_iter_backward_sentence_start (&start);
7431 if (gtk_text_iter_inside_sentence (&end))
7432 gtk_text_iter_forward_sentence_end (&end);
7433 while (!gtk_text_iter_starts_sentence (&end))
7435 if (!gtk_text_iter_forward_char (&end))
7439 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7440 if (gtk_text_iter_inside_sentence (&start) &&
7441 !gtk_text_iter_starts_sentence (&start))
7442 gtk_text_iter_backward_sentence_start (&start);
7443 while (!gtk_text_iter_ends_sentence (&start))
7445 if (!gtk_text_iter_backward_char (&start))
7448 gtk_text_iter_forward_sentence_end (&end);
7450 case ATK_TEXT_BOUNDARY_LINE_START:
7451 case ATK_TEXT_BOUNDARY_LINE_END:
7452 icon_view = GTK_ICON_VIEW (item->widget);
7454 /* FIXME we probably have to use GailTextCell to salvage this */
7455 gtk_icon_view_update_item_text (icon_view, item->item);
7456 get_pango_text_offsets (icon_view->priv->layout,
7470 *start_offset = gtk_text_iter_get_offset (&start);
7471 *end_offset = gtk_text_iter_get_offset (&end);
7473 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7477 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7479 AtkTextBoundary boundary_type,
7483 GtkIconViewItemAccessible *item;
7484 GtkTextIter start, end;
7485 GtkTextBuffer *buffer;
7486 GtkIconView *icon_view;
7488 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7490 if (!GTK_IS_ICON_VIEW (item->widget))
7493 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7496 buffer = item->text_buffer;
7498 if (!gtk_text_buffer_get_char_count (buffer))
7502 return g_strdup ("");
7504 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7508 switch (boundary_type)
7510 case ATK_TEXT_BOUNDARY_CHAR:
7511 gtk_text_iter_forward_char(&start);
7512 gtk_text_iter_forward_chars(&end, 2);
7514 case ATK_TEXT_BOUNDARY_WORD_START:
7515 if (gtk_text_iter_inside_word (&end))
7516 gtk_text_iter_forward_word_end (&end);
7517 while (!gtk_text_iter_starts_word (&end))
7519 if (!gtk_text_iter_forward_char (&end))
7523 if (!gtk_text_iter_is_end (&end))
7525 gtk_text_iter_forward_word_end (&end);
7526 while (!gtk_text_iter_starts_word (&end))
7528 if (!gtk_text_iter_forward_char (&end))
7533 case ATK_TEXT_BOUNDARY_WORD_END:
7534 gtk_text_iter_forward_word_end (&end);
7536 if (!gtk_text_iter_is_end (&end))
7537 gtk_text_iter_forward_word_end (&end);
7539 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7540 if (gtk_text_iter_inside_sentence (&end))
7541 gtk_text_iter_forward_sentence_end (&end);
7542 while (!gtk_text_iter_starts_sentence (&end))
7544 if (!gtk_text_iter_forward_char (&end))
7548 if (!gtk_text_iter_is_end (&end))
7550 gtk_text_iter_forward_sentence_end (&end);
7551 while (!gtk_text_iter_starts_sentence (&end))
7553 if (!gtk_text_iter_forward_char (&end))
7558 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7559 gtk_text_iter_forward_sentence_end (&end);
7561 if (!gtk_text_iter_is_end (&end))
7562 gtk_text_iter_forward_sentence_end (&end);
7564 case ATK_TEXT_BOUNDARY_LINE_START:
7565 case ATK_TEXT_BOUNDARY_LINE_END:
7566 icon_view = GTK_ICON_VIEW (item->widget);
7568 /* FIXME we probably have to use GailTextCell to salvage this */
7569 gtk_icon_view_update_item_text (icon_view, item->item);
7570 get_pango_text_offsets (icon_view->priv->layout,
7582 *start_offset = gtk_text_iter_get_offset (&start);
7583 *end_offset = gtk_text_iter_get_offset (&end);
7585 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7589 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7591 GtkIconViewItemAccessible *item;
7593 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7595 if (!GTK_IS_ICON_VIEW (item->widget))
7598 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7601 return gtk_text_buffer_get_char_count (item->text_buffer);
7605 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7611 AtkCoordType coord_type)
7613 GtkIconViewItemAccessible *item;
7614 GtkIconView *icon_view;
7615 PangoRectangle char_rect;
7616 const gchar *item_text;
7619 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7621 if (!GTK_IS_ICON_VIEW (item->widget))
7624 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7627 icon_view = GTK_ICON_VIEW (item->widget);
7629 /* FIXME we probably have to use GailTextCell to salvage this */
7630 gtk_icon_view_update_item_text (icon_view, item->item);
7631 item_text = pango_layout_get_text (icon_view->priv->layout);
7632 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7633 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7635 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7636 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7637 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7638 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7639 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7640 *width = char_rect.width / PANGO_SCALE;
7641 *height = char_rect.height / PANGO_SCALE;
7646 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7649 AtkCoordType coord_type)
7651 GtkIconViewItemAccessible *item;
7652 GtkIconView *icon_view;
7653 const gchar *item_text;
7658 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7660 if (!GTK_IS_ICON_VIEW (item->widget))
7663 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7666 icon_view = GTK_ICON_VIEW (item->widget);
7668 /* FIXME we probably have to use GailTextCell to salvage this */
7669 gtk_icon_view_update_item_text (icon_view, item->item);
7670 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7671 x -= l_x + item->item->layout_x - item->item->x;
7672 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7673 y -= l_y + item->item->layout_y - item->item->y;
7674 item_text = pango_layout_get_text (icon_view->priv->layout);
7675 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7686 offset = g_utf8_strlen (item_text, -1);
7688 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7694 atk_text_item_interface_init (AtkTextIface *iface)
7696 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7697 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7698 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7699 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7700 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7701 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7702 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7703 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7707 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7712 AtkCoordType coord_type)
7714 GtkIconViewItemAccessible *item;
7715 AtkObject *parent_obj;
7718 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7720 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7721 if (!GTK_IS_WIDGET (item->widget))
7724 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7727 *width = item->item->width;
7728 *height = item->item->height;
7729 if (gtk_icon_view_item_accessible_is_showing (item))
7731 parent_obj = gtk_widget_get_accessible (item->widget);
7732 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7733 *x = l_x + item->item->x;
7734 *y = l_y + item->item->y;
7744 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7746 GtkIconViewItemAccessible *item;
7747 GtkWidget *toplevel;
7749 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7751 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7752 if (!GTK_IS_WIDGET (item->widget))
7755 gtk_widget_grab_focus (item->widget);
7756 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
7757 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7758 if (GTK_WIDGET_TOPLEVEL (toplevel))
7759 gtk_window_present (GTK_WINDOW (toplevel));
7765 atk_component_item_interface_init (AtkComponentIface *iface)
7767 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7768 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7772 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7773 AtkStateType state_type,
7774 gboolean emit_signal)
7778 rc = atk_state_set_add_state (item->state_set, state_type);
7780 * The signal should only be generated if the value changed,
7781 * not when the item is set up. So states that are set
7782 * initially should pass FALSE as the emit_signal argument.
7787 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7788 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7789 if (state_type == ATK_STATE_VISIBLE)
7790 g_signal_emit_by_name (item, "visible_data_changed");
7797 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7798 AtkStateType state_type,
7799 gboolean emit_signal)
7801 if (atk_state_set_contains_state (item->state_set, state_type))
7805 rc = atk_state_set_remove_state (item->state_set, state_type);
7807 * The signal should only be generated if the value changed,
7808 * not when the item is set up. So states that are set
7809 * initially should pass FALSE as the emit_signal argument.
7814 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7815 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7816 if (state_type == ATK_STATE_VISIBLE)
7817 g_signal_emit_by_name (item, "visible_data_changed");
7827 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7829 GtkIconView *icon_view;
7830 GdkRectangle visible_rect;
7831 gboolean is_showing;
7834 * An item is considered "SHOWING" if any part of the item is in the
7835 * visible rectangle.
7838 if (!GTK_IS_ICON_VIEW (item->widget))
7841 if (item->item == NULL)
7844 icon_view = GTK_ICON_VIEW (item->widget);
7846 if (icon_view->priv->hadjustment)
7847 visible_rect.x += icon_view->priv->hadjustment->value;
7849 if (icon_view->priv->hadjustment)
7850 visible_rect.y += icon_view->priv->vadjustment->value;
7851 visible_rect.width = item->widget->allocation.width;
7852 visible_rect.height = item->widget->allocation.height;
7854 if (((item->item->x + item->item->width) < visible_rect.x) ||
7855 ((item->item->y + item->item->height) < (visible_rect.y)) ||
7856 (item->item->x > (visible_rect.x + visible_rect.width)) ||
7857 (item->item->y > (visible_rect.y + visible_rect.height)))
7866 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
7867 gboolean emit_signal)
7869 if (gtk_icon_view_item_accessible_is_showing (item))
7870 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
7873 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
7878 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
7882 item->state_set = atk_state_set_new ();
7884 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
7885 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
7886 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
7887 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
7888 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
7890 for (i = 0; i < LAST_ACTION; i++)
7891 item->action_descriptions[i] = NULL;
7893 item->image_description = NULL;
7895 item->action_idle_handler = 0;
7899 gtk_icon_view_item_accessible_finalize (GObject *object)
7901 GtkIconViewItemAccessible *item;
7904 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
7906 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
7909 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
7911 if (item->state_set)
7912 g_object_unref (item->state_set);
7914 if (item->text_buffer)
7915 g_object_unref (item->text_buffer);
7917 for (i = 0; i < LAST_ACTION; i++)
7918 g_free (item->action_descriptions[i]);
7920 g_free (item->image_description);
7922 if (item->action_idle_handler)
7924 g_source_remove (item->action_idle_handler);
7925 item->action_idle_handler = 0;
7928 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
7931 static G_CONST_RETURN gchar*
7932 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
7938 GtkIconViewItemAccessible *item;
7939 GtkTextIter start_iter;
7940 GtkTextIter end_iter;
7942 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7944 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
7945 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
7947 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
7952 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
7954 GtkIconViewItemAccessible *item;
7956 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
7957 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7960 return gtk_widget_get_accessible (item->widget);
7966 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
7968 GtkIconViewItemAccessible *item;
7970 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
7971 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7973 return item->item->index;
7976 static AtkStateSet *
7977 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
7979 GtkIconViewItemAccessible *item;
7980 GtkIconView *icon_view;
7982 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7983 g_return_val_if_fail (item->state_set, NULL);
7988 icon_view = GTK_ICON_VIEW (item->widget);
7989 if (icon_view->priv->cursor_item == item->item)
7990 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
7992 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
7994 return g_object_ref (item->state_set);
7998 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
8000 GObjectClass *gobject_class;
8002 accessible_item_parent_class = g_type_class_peek_parent (klass);
8004 gobject_class = (GObjectClass *)klass;
8006 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
8008 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
8009 klass->get_name = gtk_icon_view_item_accessible_get_name;
8010 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
8011 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
8015 gtk_icon_view_item_accessible_get_type (void)
8017 static GType type = 0;
8021 static const GTypeInfo tinfo =
8023 sizeof (GtkIconViewItemAccessibleClass),
8024 (GBaseInitFunc) NULL, /* base init */
8025 (GBaseFinalizeFunc) NULL, /* base finalize */
8026 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
8027 (GClassFinalizeFunc) NULL, /* class finalize */
8028 NULL, /* class data */
8029 sizeof (GtkIconViewItemAccessible), /* instance size */
8030 0, /* nb preallocs */
8031 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
8032 NULL /* value table */
8035 static const GInterfaceInfo atk_component_info =
8037 (GInterfaceInitFunc) atk_component_item_interface_init,
8038 (GInterfaceFinalizeFunc) NULL,
8041 static const GInterfaceInfo atk_action_info =
8043 (GInterfaceInitFunc) atk_action_item_interface_init,
8044 (GInterfaceFinalizeFunc) NULL,
8047 static const GInterfaceInfo atk_image_info =
8049 (GInterfaceInitFunc) atk_image_item_interface_init,
8050 (GInterfaceFinalizeFunc) NULL,
8053 static const GInterfaceInfo atk_text_info =
8055 (GInterfaceInitFunc) atk_text_item_interface_init,
8056 (GInterfaceFinalizeFunc) NULL,
8060 type = g_type_register_static (ATK_TYPE_OBJECT,
8061 g_intern_static_string ("GtkIconViewItemAccessible"), &tinfo, 0);
8062 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8063 &atk_component_info);
8064 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8066 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8068 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8075 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8076 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8077 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8079 static GType gtk_icon_view_accessible_get_type (void);
8084 } GtkIconViewAccessible;
8090 } GtkIconViewItemAccessibleInfo;
8096 GtkAdjustment *old_hadj;
8097 GtkAdjustment *old_vadj;
8099 GtkTreeModel *model;
8101 } GtkIconViewAccessiblePrivate;
8103 static GtkIconViewAccessiblePrivate *
8104 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8106 return g_object_get_qdata (G_OBJECT (accessible),
8107 accessible_private_data_quark);
8111 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8115 GtkIconViewItemAccessibleInfo *info;
8116 GtkIconViewItemAccessibleInfo *tmp_info;
8117 GtkIconViewAccessiblePrivate *priv;
8120 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8122 info->index = index;
8124 priv = gtk_icon_view_accessible_get_priv (accessible);
8125 items = priv->items;
8128 tmp_info = items->data;
8129 if (tmp_info->index > index)
8131 items = items->next;
8133 priv->items = g_list_insert_before (priv->items, items, info);
8134 priv->old_hadj = NULL;
8135 priv->old_vadj = NULL;
8139 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8141 GtkIconView *icon_view;
8144 widget = GTK_ACCESSIBLE (accessible)->widget;
8148 icon_view = GTK_ICON_VIEW (widget);
8150 return g_list_length (icon_view->priv->items);
8154 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8157 GtkIconViewAccessiblePrivate *priv;
8158 GtkIconViewItemAccessibleInfo *info;
8161 priv = gtk_icon_view_accessible_get_priv (accessible);
8162 items = priv->items;
8167 if (info->index == index)
8169 items = items->next;
8175 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8178 GtkIconView *icon_view;
8182 GtkIconViewItemAccessible *a11y_item;
8184 widget = GTK_ACCESSIBLE (accessible)->widget;
8188 icon_view = GTK_ICON_VIEW (widget);
8189 icons = g_list_nth (icon_view->priv->items, index);
8193 GtkIconViewItem *item = icons->data;
8195 g_return_val_if_fail (item->index == index, NULL);
8196 obj = gtk_icon_view_accessible_find_child (accessible, index);
8199 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8200 gtk_icon_view_item_accessible_info_new (accessible,
8203 obj->role = ATK_ROLE_ICON;
8204 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8205 a11y_item->item = item;
8206 a11y_item->widget = widget;
8207 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8209 gtk_icon_view_set_cell_data (icon_view, item);
8210 gtk_text_buffer_set_text (a11y_item->text_buffer,
8211 get_text (icon_view, item), -1);
8213 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8214 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8222 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8225 GtkIconViewAccessiblePrivate *priv;
8226 GtkIconViewItemAccessibleInfo *info;
8227 GtkIconViewItemAccessible *item;
8230 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8234 gboolean act_on_item;
8236 widget = GTK_ACCESSIBLE (view)->widget;
8240 items = priv->items;
8242 act_on_item = (list == NULL);
8247 info = (GtkIconViewItemAccessibleInfo *)items->data;
8248 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8250 if (act_on_item == FALSE && list == items)
8254 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8256 items = items->next;
8262 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8263 GtkIconView *icon_view)
8266 GtkIconViewAccessible *view;
8269 * The scrollbars have changed
8271 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8272 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8274 gtk_icon_view_accessible_traverse_items (view, NULL);
8278 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8279 GtkAdjustment *hadj,
8280 GtkAdjustment *vadj)
8283 GtkIconViewAccessiblePrivate *priv;
8285 atk_obj = gtk_widget_get_accessible (widget);
8286 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8288 if (priv->old_hadj != hadj)
8292 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8293 (gpointer *)&priv->old_hadj);
8295 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8296 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8299 priv->old_hadj = hadj;
8302 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8303 (gpointer *)&priv->old_hadj);
8304 g_signal_connect (hadj,
8306 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8310 if (priv->old_vadj != vadj)
8314 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8315 (gpointer *)&priv->old_vadj);
8317 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8318 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8321 priv->old_vadj = vadj;
8324 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8325 (gpointer *)&priv->old_vadj);
8326 g_signal_connect (vadj,
8328 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8335 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8342 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8343 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8349 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8354 GtkIconViewAccessiblePrivate *priv;
8355 GtkIconViewItemAccessibleInfo *info;
8356 GtkIconViewAccessible *view;
8357 GtkIconViewItemAccessible *item;
8363 index = gtk_tree_path_get_indices(path)[0];
8364 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8365 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8366 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8368 items = priv->items;
8373 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8374 if (info->index != item->item->index)
8376 if (info->index < index)
8377 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8379 if (tmp_list == NULL)
8382 info->index = item->item->index;
8385 items = items->next;
8387 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8388 g_signal_emit_by_name (atk_obj, "children_changed::add",
8394 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8398 GtkIconViewAccessiblePrivate *priv;
8399 GtkIconViewItemAccessibleInfo *info;
8400 GtkIconViewAccessible *view;
8401 GtkIconViewItemAccessible *item;
8404 GList *deleted_item;
8408 index = gtk_tree_path_get_indices(path)[0];
8409 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8410 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8411 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8413 items = priv->items;
8415 deleted_item = NULL;
8420 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8421 if (info->index == index)
8423 deleted_item = items;
8425 if (info->index != item->item->index)
8427 if (tmp_list == NULL)
8430 info->index = item->item->index;
8433 items = items->next;
8435 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8438 info = deleted_item->data;
8439 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8441 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8445 priv->items = g_list_remove_link (priv->items, deleted_item);
8453 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8454 GtkIconViewItemAccessibleInfo *i2)
8456 return i1->index - i2->index;
8460 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8466 GtkIconViewAccessiblePrivate *priv;
8467 GtkIconViewItemAccessibleInfo *info;
8468 GtkIconViewAccessible *view;
8469 GtkIconView *icon_view;
8470 GtkIconViewItemAccessible *item;
8475 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8476 icon_view = GTK_ICON_VIEW (user_data);
8477 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8478 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8480 items = priv->items;
8485 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8486 info->index = new_order[info->index];
8487 tmp_list = g_list_nth (icon_view->priv->items, info->index);
8488 item->item = tmp_list->data;
8489 items = items->next;
8491 priv->items = g_list_sort (priv->items,
8492 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8498 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8503 obj = G_OBJECT (model);
8504 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8505 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8506 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8507 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8511 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8515 obj = G_OBJECT (icon_view->priv->model);
8516 g_signal_connect_data (obj, "row-changed",
8517 (GCallback) gtk_icon_view_accessible_model_row_changed,
8518 icon_view, NULL, 0);
8519 g_signal_connect_data (obj, "row-inserted",
8520 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8521 icon_view, NULL, G_CONNECT_AFTER);
8522 g_signal_connect_data (obj, "row-deleted",
8523 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8524 icon_view, NULL, G_CONNECT_AFTER);
8525 g_signal_connect_data (obj, "rows-reordered",
8526 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8527 icon_view, NULL, G_CONNECT_AFTER);
8531 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8533 GtkIconViewItemAccessibleInfo *info;
8536 items = priv->items;
8539 info = (GtkIconViewItemAccessibleInfo *) items->data;
8540 g_object_unref (info->item);
8541 g_free (items->data);
8542 items = items->next;
8544 g_list_free (priv->items);
8549 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8552 GtkIconView *icon_view;
8555 GtkIconViewAccessible *view;
8556 GtkIconViewAccessiblePrivate *priv;
8558 if (strcmp (pspec->name, "model") == 0)
8560 widget = GTK_WIDGET (obj);
8561 atk_obj = gtk_widget_get_accessible (widget);
8562 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8563 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8566 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8567 (gpointer *)&priv->model);
8568 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8570 gtk_icon_view_accessible_clear_cache (priv);
8572 icon_view = GTK_ICON_VIEW (obj);
8573 priv->model = icon_view->priv->model;
8574 /* If there is no model the GtkIconView is probably being destroyed */
8577 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8578 gtk_icon_view_accessible_connect_model_signals (icon_view);
8586 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8589 GtkIconViewAccessiblePrivate *priv;
8590 GtkIconView *icon_view;
8592 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8593 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8595 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8596 g_object_set_qdata (G_OBJECT (accessible),
8597 accessible_private_data_quark,
8600 icon_view = GTK_ICON_VIEW (data);
8601 if (icon_view->priv->hadjustment)
8603 priv->old_hadj = icon_view->priv->hadjustment;
8604 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
8605 g_signal_connect (icon_view->priv->hadjustment,
8607 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8610 if (icon_view->priv->vadjustment)
8612 priv->old_vadj = icon_view->priv->vadjustment;
8613 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
8614 g_signal_connect (icon_view->priv->vadjustment,
8616 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8619 g_signal_connect_after (data,
8620 "set_scroll_adjustments",
8621 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
8623 g_signal_connect (data,
8625 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8628 priv->model = icon_view->priv->model;
8631 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8632 gtk_icon_view_accessible_connect_model_signals (icon_view);
8635 accessible->role = ATK_ROLE_LAYERED_PANE;
8639 gtk_icon_view_accessible_finalize (GObject *object)
8641 GtkIconViewAccessiblePrivate *priv;
8643 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8644 gtk_icon_view_accessible_clear_cache (priv);
8648 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8652 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8653 GtkAccessible *accessible)
8656 GtkIconViewAccessiblePrivate *priv;
8658 atk_obj = ATK_OBJECT (accessible);
8659 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8662 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8663 (gpointer *)&priv->old_hadj);
8665 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8666 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8668 priv->old_hadj = NULL;
8672 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8673 (gpointer *)&priv->old_vadj);
8675 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8676 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8678 priv->old_vadj = NULL;
8683 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8685 if (accessible->widget)
8687 g_signal_connect_after (accessible->widget,
8689 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8692 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8696 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8698 GObjectClass *gobject_class;
8699 GtkAccessibleClass *accessible_class;
8701 accessible_parent_class = g_type_class_peek_parent (klass);
8703 gobject_class = (GObjectClass *)klass;
8704 accessible_class = (GtkAccessibleClass *)klass;
8706 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8708 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8709 klass->ref_child = gtk_icon_view_accessible_ref_child;
8710 klass->initialize = gtk_icon_view_accessible_initialize;
8712 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8714 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8718 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8721 AtkCoordType coord_type)
8724 GtkIconView *icon_view;
8725 GtkIconViewItem *item;
8728 widget = GTK_ACCESSIBLE (component)->widget;
8730 /* State is defunct */
8733 icon_view = GTK_ICON_VIEW (widget);
8734 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8735 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8737 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8743 atk_component_interface_init (AtkComponentIface *iface)
8745 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8749 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8753 GtkIconView *icon_view;
8754 GtkIconViewItem *item;
8757 widget = GTK_ACCESSIBLE (selection)->widget;
8761 icon_view = GTK_ICON_VIEW (widget);
8763 l = g_list_nth (icon_view->priv->items, i);
8768 gtk_icon_view_select_item (icon_view, item);
8774 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8777 GtkIconView *icon_view;
8779 widget = GTK_ACCESSIBLE (selection)->widget;
8783 icon_view = GTK_ICON_VIEW (widget);
8784 gtk_icon_view_unselect_all (icon_view);
8790 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8794 GtkIconView *icon_view;
8795 GtkIconViewItem *item;
8798 widget = GTK_ACCESSIBLE (selection)->widget;
8802 icon_view = GTK_ICON_VIEW (widget);
8804 l = icon_view->priv->items;
8811 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8822 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8825 GtkIconView *icon_view;
8826 GtkIconViewItem *item;
8830 widget = GTK_ACCESSIBLE (selection)->widget;
8834 icon_view = GTK_ICON_VIEW (widget);
8836 l = icon_view->priv->items;
8852 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
8856 GtkIconView *icon_view;
8857 GtkIconViewItem *item;
8860 widget = GTK_ACCESSIBLE (selection)->widget;
8864 icon_view = GTK_ICON_VIEW (widget);
8865 l = g_list_nth (icon_view->priv->items, i);
8871 return item->selected;
8875 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
8879 GtkIconView *icon_view;
8880 GtkIconViewItem *item;
8884 widget = GTK_ACCESSIBLE (selection)->widget;
8888 icon_view = GTK_ICON_VIEW (widget);
8889 l = icon_view->priv->items;
8898 gtk_icon_view_unselect_item (icon_view, item);
8910 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
8913 GtkIconView *icon_view;
8915 widget = GTK_ACCESSIBLE (selection)->widget;
8919 icon_view = GTK_ICON_VIEW (widget);
8920 gtk_icon_view_select_all (icon_view);
8925 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
8927 iface->add_selection = gtk_icon_view_accessible_add_selection;
8928 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
8929 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
8930 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
8931 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
8932 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
8933 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
8937 gtk_icon_view_accessible_get_type (void)
8939 static GType type = 0;
8943 static GTypeInfo tinfo =
8946 (GBaseInitFunc) NULL, /* base init */
8947 (GBaseFinalizeFunc) NULL, /* base finalize */
8948 (GClassInitFunc) gtk_icon_view_accessible_class_init,
8949 (GClassFinalizeFunc) NULL, /* class finalize */
8950 NULL, /* class data */
8951 0, /* instance size */
8952 0, /* nb preallocs */
8953 (GInstanceInitFunc) NULL, /* instance init */
8954 NULL /* value table */
8956 static const GInterfaceInfo atk_component_info =
8958 (GInterfaceInitFunc) atk_component_interface_init,
8959 (GInterfaceFinalizeFunc) NULL,
8962 static const GInterfaceInfo atk_selection_info =
8964 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
8965 (GInterfaceFinalizeFunc) NULL,
8970 * Figure out the size of the class and instance
8971 * we are deriving from
8973 AtkObjectFactory *factory;
8976 GType derived_atk_type;
8978 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
8979 factory = atk_registry_get_factory (atk_get_default_registry (),
8981 derived_atk_type = atk_object_factory_get_accessible_type (factory);
8982 g_type_query (derived_atk_type, &query);
8983 tinfo.class_size = query.class_size;
8984 tinfo.instance_size = query.instance_size;
8986 type = g_type_register_static (derived_atk_type,
8987 "GtkIconViewAccessible",
8989 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8990 &atk_component_info);
8991 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
8992 &atk_selection_info);
8998 gtk_icon_view_accessible_new (GObject *obj)
9000 AtkObject *accessible;
9002 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
9004 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
9005 atk_object_initialize (accessible, obj);
9011 gtk_icon_view_accessible_factory_get_accessible_type (void)
9013 return gtk_icon_view_accessible_get_type ();
9017 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
9019 return gtk_icon_view_accessible_new (obj);
9023 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
9025 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
9026 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
9030 gtk_icon_view_accessible_factory_get_type (void)
9032 static GType type = 0;
9036 static const GTypeInfo tinfo =
9038 sizeof (AtkObjectFactoryClass),
9039 NULL, /* base_init */
9040 NULL, /* base_finalize */
9041 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
9042 NULL, /* class_finalize */
9043 NULL, /* class_data */
9044 sizeof (AtkObjectFactory),
9045 0, /* n_preallocs */
9049 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
9050 "GtkIconViewAccessibleFactory",
9058 gtk_icon_view_get_accessible (GtkWidget *widget)
9060 static gboolean first_time = TRUE;
9064 AtkObjectFactory *factory;
9065 AtkRegistry *registry;
9067 GType derived_atk_type;
9070 * Figure out whether accessibility is enabled by looking at the
9071 * type of the accessible object which would be created for
9072 * the parent type of GtkIconView.
9074 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9076 registry = atk_get_default_registry ();
9077 factory = atk_registry_get_factory (registry,
9079 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9080 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9081 atk_registry_set_factory_type (registry,
9083 gtk_icon_view_accessible_factory_get_type ());
9086 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9089 #define __GTK_ICON_VIEW_C__
9090 #include "gtkaliasdef.c"