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;
79 typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
80 struct _GtkIconViewCellInfo
82 GtkCellRenderer *cell;
92 GtkCellLayoutDataFunc func;
94 GDestroyNotify destroy;
97 typedef struct _GtkIconViewChild GtkIconViewChild;
98 struct _GtkIconViewChild
101 GtkIconViewItem *item;
105 struct _GtkIconViewPrivate
109 GtkSelectionMode selection_mode;
111 GdkWindow *bin_window;
119 GtkAdjustment *hadjustment;
120 GtkAdjustment *vadjustment;
122 guint layout_idle_id;
124 gboolean doing_rubberband;
125 gint rubberband_x1, rubberband_y1;
126 gint rubberband_x2, rubberband_y2;
128 guint scroll_timeout_id;
129 gint scroll_value_diff;
130 gint event_last_x, event_last_y;
132 GtkIconViewItem *anchor_item;
133 GtkIconViewItem *cursor_item;
134 GtkIconViewItem *edited_item;
135 GtkCellEditable *editable;
137 GtkIconViewItem *last_single_clicked;
144 GtkOrientation orientation;
161 GdkModifierType start_button_mask;
166 GtkTargetList *source_targets;
167 GdkDragAction source_actions;
169 GtkTargetList *dest_targets;
170 GdkDragAction dest_actions;
172 GtkTreeRowReference *dest_item;
173 GtkIconViewDropPosition dest_pos;
175 guint source_set : 1;
177 guint reorderable : 1;
178 guint empty_view_drop :1;
180 guint ctrl_pressed : 1;
181 guint shift_pressed : 1;
194 ACTIVATE_CURSOR_ITEM,
218 static void gtk_icon_view_class_init (GtkIconViewClass *klass);
219 static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
220 static void gtk_icon_view_finalize (GObject *object);
221 static void gtk_icon_view_set_property (GObject *object,
225 static void gtk_icon_view_get_property (GObject *object,
230 /* GtkObject vfuncs */
231 static void gtk_icon_view_destroy (GtkObject *object);
233 /* GtkWidget vfuncs */
234 static void gtk_icon_view_realize (GtkWidget *widget);
235 static void gtk_icon_view_unrealize (GtkWidget *widget);
236 static void gtk_icon_view_size_request (GtkWidget *widget,
237 GtkRequisition *requisition);
238 static void gtk_icon_view_size_allocate (GtkWidget *widget,
239 GtkAllocation *allocation);
240 static gboolean gtk_icon_view_expose (GtkWidget *widget,
241 GdkEventExpose *expose);
242 static gboolean gtk_icon_view_motion (GtkWidget *widget,
243 GdkEventMotion *event);
244 static gboolean gtk_icon_view_button_press (GtkWidget *widget,
245 GdkEventButton *event);
246 static gboolean gtk_icon_view_button_release (GtkWidget *widget,
247 GdkEventButton *event);
248 static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
251 /* GtkContainer vfuncs */
252 static void gtk_icon_view_remove (GtkContainer *container,
254 static void gtk_icon_view_forall (GtkContainer *container,
255 gboolean include_internals,
256 GtkCallback callback,
257 gpointer callback_data);
259 /* GtkIconView vfuncs */
260 static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
262 GtkAdjustment *vadj);
263 static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
264 static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
265 static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
266 static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
267 static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
269 /* Internal functions */
270 static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
271 GtkIconView *icon_view);
272 static void gtk_icon_view_layout (GtkIconView *icon_view);
273 static void gtk_icon_view_paint_item (GtkIconView *icon_view,
276 GtkIconViewItem *item,
278 GdkDrawable *drawable,
281 gboolean draw_focus);
282 static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
285 static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
287 static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
288 GtkIconViewItem *item);
289 static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
290 static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
291 GtkIconViewItem *item,
293 static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
296 static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
297 static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
298 static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
299 GtkIconViewItem *item,
304 static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
305 static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
306 GtkIconViewItem *item);
307 static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
308 GtkIconViewItem *item,
310 static void gtk_icon_view_update_rubberband (gpointer data);
311 static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
312 static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
313 static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
316 GtkMovementStep step,
318 static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
319 GtkMovementStep step,
321 static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
323 static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
325 static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
327 static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
329 static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
330 GtkIconViewItem *item);
331 static void gtk_icon_view_select_item (GtkIconView *icon_view,
332 GtkIconViewItem *item);
333 static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
334 GtkIconViewItem *item);
335 static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
336 GtkIconViewItem *anchor,
337 GtkIconViewItem *cursor);
338 static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
341 gboolean only_in_cell,
342 GtkIconViewCellInfo **cell_at_pos);
343 static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
344 GtkIconViewItem *item,
345 GtkIconViewCellInfo *cell_info,
346 GdkRectangle *cell_area);
347 static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
348 GtkIconViewItem *item,
349 GtkIconViewCellInfo *info,
351 static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
352 GtkCellRenderer *renderer);
353 static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
354 GtkIconViewItem *item);
355 static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
356 GtkCellRenderer *renderer,
358 static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
359 GtkCellRenderer *renderer,
361 static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
362 GtkCellRenderer *renderer,
363 const gchar *attribute,
365 static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
366 static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
367 GtkCellRenderer *renderer);
368 static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
369 GtkCellRenderer *cell,
370 GtkCellLayoutDataFunc func,
372 GDestroyNotify destroy);
373 static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
374 GtkCellRenderer *cell,
376 static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
377 GtkIconViewItem *item,
378 GtkIconViewCellInfo *cell_info,
380 static void gtk_icon_view_put (GtkIconView *icon_view,
382 GtkIconViewItem *item,
384 static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
385 GtkIconView *icon_view);
386 static void gtk_icon_view_start_editing (GtkIconView *icon_view,
387 GtkIconViewItem *item,
388 GtkIconViewCellInfo *cell_info,
390 static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
391 gboolean cancel_editing);
393 /* Source side drag signals */
394 static void gtk_icon_view_drag_begin (GtkWidget *widget,
395 GdkDragContext *context);
396 static void gtk_icon_view_drag_end (GtkWidget *widget,
397 GdkDragContext *context);
398 static void gtk_icon_view_drag_data_get (GtkWidget *widget,
399 GdkDragContext *context,
400 GtkSelectionData *selection_data,
403 static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
404 GdkDragContext *context);
406 /* Target side drag signals */
407 static void gtk_icon_view_drag_leave (GtkWidget *widget,
408 GdkDragContext *context,
410 static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
411 GdkDragContext *context,
415 static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
416 GdkDragContext *context,
420 static void gtk_icon_view_drag_data_received (GtkWidget *widget,
421 GdkDragContext *context,
424 GtkSelectionData *selection_data,
427 static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
428 GdkEventMotion *event);
430 static void remove_scroll_timeout (GtkIconView *icon_view);
433 static guint icon_view_signals[LAST_SIGNAL] = { 0 };
435 G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
436 G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
437 gtk_icon_view_cell_layout_init));
440 gtk_icon_view_class_init (GtkIconViewClass *klass)
442 GObjectClass *gobject_class;
443 GtkObjectClass *object_class;
444 GtkWidgetClass *widget_class;
445 GtkContainerClass *container_class;
446 GtkBindingSet *binding_set;
448 binding_set = gtk_binding_set_by_class (klass);
450 g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
452 gobject_class = (GObjectClass *) klass;
453 object_class = (GtkObjectClass *) klass;
454 widget_class = (GtkWidgetClass *) klass;
455 container_class = (GtkContainerClass *) klass;
457 gobject_class->finalize = gtk_icon_view_finalize;
458 gobject_class->set_property = gtk_icon_view_set_property;
459 gobject_class->get_property = gtk_icon_view_get_property;
461 object_class->destroy = gtk_icon_view_destroy;
463 widget_class->realize = gtk_icon_view_realize;
464 widget_class->unrealize = gtk_icon_view_unrealize;
465 widget_class->size_request = gtk_icon_view_size_request;
466 widget_class->size_allocate = gtk_icon_view_size_allocate;
467 widget_class->expose_event = gtk_icon_view_expose;
468 widget_class->motion_notify_event = gtk_icon_view_motion;
469 widget_class->button_press_event = gtk_icon_view_button_press;
470 widget_class->button_release_event = gtk_icon_view_button_release;
471 widget_class->drag_begin = gtk_icon_view_drag_begin;
472 widget_class->drag_end = gtk_icon_view_drag_end;
473 widget_class->drag_data_get = gtk_icon_view_drag_data_get;
474 widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
475 widget_class->drag_leave = gtk_icon_view_drag_leave;
476 widget_class->drag_motion = gtk_icon_view_drag_motion;
477 widget_class->drag_drop = gtk_icon_view_drag_drop;
478 widget_class->drag_data_received = gtk_icon_view_drag_data_received;
479 widget_class->get_accessible = gtk_icon_view_get_accessible;
481 container_class->remove = gtk_icon_view_remove;
482 container_class->forall = gtk_icon_view_forall;
484 klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
485 klass->select_all = gtk_icon_view_real_select_all;
486 klass->unselect_all = gtk_icon_view_real_unselect_all;
487 klass->select_cursor_item = gtk_icon_view_real_select_cursor_item;
488 klass->toggle_cursor_item = gtk_icon_view_real_toggle_cursor_item;
489 klass->activate_cursor_item = gtk_icon_view_real_activate_cursor_item;
490 klass->move_cursor = gtk_icon_view_real_move_cursor;
494 * GtkIconView:selection-mode:
496 * The ::selection-mode property specifies the selection mode of
497 * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection
498 * is enabled, for the other modes, only keyboard selection is possible.
502 g_object_class_install_property (gobject_class,
504 g_param_spec_enum ("selection-mode",
505 P_("Selection mode"),
506 P_("The selection mode"),
507 GTK_TYPE_SELECTION_MODE,
508 GTK_SELECTION_SINGLE,
509 GTK_PARAM_READWRITE));
512 * GtkIconView:pixbuf-column:
514 * The ::pixbuf-column property contains the number of the model column
515 * containing the pixbufs which are displayed. The pixbuf column must be
516 * of type #GDK_TYPE_PIXBUF. Setting this property to -1 turns off the
517 * display of pixbufs.
521 g_object_class_install_property (gobject_class,
523 g_param_spec_int ("pixbuf-column",
525 P_("Model column used to retrieve the icon pixbuf from"),
527 GTK_PARAM_READWRITE));
530 * GtkIconView:text-column:
532 * The ::text-column property contains the number of the model column
533 * containing the texts which are displayed. The text column must be
534 * of type #G_TYPE_STRING. If this property and the :markup-column
535 * property are both set to -1, no texts are displayed.
539 g_object_class_install_property (gobject_class,
541 g_param_spec_int ("text-column",
543 P_("Model column used to retrieve the text from"),
545 GTK_PARAM_READWRITE));
549 * GtkIconView:markup-column:
551 * The ::markup-column property contains the number of the model column
552 * containing markup information to be displayed. The markup column must be
553 * of type #G_TYPE_STRING. If this property and the :text-column property
554 * are both set to column numbers, it overrides the text column.
555 * If both are set to -1, no texts are displayed.
559 g_object_class_install_property (gobject_class,
561 g_param_spec_int ("markup-column",
563 P_("Model column used to retrieve the text if using Pango markup"),
565 GTK_PARAM_READWRITE));
567 g_object_class_install_property (gobject_class,
569 g_param_spec_object ("model",
570 P_("Icon View Model"),
571 P_("The model for the icon view"),
573 GTK_PARAM_READWRITE));
576 * GtkIconView:columns:
578 * The columns property contains the number of the columns in which the
579 * items should be displayed. If it is -1, the number of columns will
580 * be chosen automatically to fill the available area.
584 g_object_class_install_property (gobject_class,
586 g_param_spec_int ("columns",
587 P_("Number of columns"),
588 P_("Number of columns to display"),
590 GTK_PARAM_READWRITE));
594 * GtkIconView::item-width:
596 * The item-width property specifies the width to use for each item.
597 * If it is set to -1, the icon view will automatically determine a
598 * suitable item size.
602 g_object_class_install_property (gobject_class,
604 g_param_spec_int ("item-width",
605 P_("Width for each item"),
606 P_("The width used for each item"),
608 GTK_PARAM_READWRITE));
611 * GtkIconView::spacing:
613 * The spacing property specifies the space which is inserted between
614 * the cells (i.e. the icon and the text) of an item.
618 g_object_class_install_property (gobject_class,
620 g_param_spec_int ("spacing",
622 P_("Space which is inserted between cells of an item"),
624 GTK_PARAM_READWRITE));
627 * GtkIconView::row-spacing:
629 * The row-spacing property specifies the space which is inserted between
630 * the rows of the icon view.
634 g_object_class_install_property (gobject_class,
636 g_param_spec_int ("row-spacing",
638 P_("Space which is inserted between grid rows"),
640 GTK_PARAM_READWRITE));
643 * GtkIconView::column-spacing:
645 * The column-spacing property specifies the space which is inserted between
646 * the columns of the icon view.
650 g_object_class_install_property (gobject_class,
652 g_param_spec_int ("column-spacing",
653 P_("Column Spacing"),
654 P_("Space which is inserted between grid column"),
656 GTK_PARAM_READWRITE));
659 * GtkIconView::margin:
661 * The margin property specifies the space which is inserted
662 * at the edges of the icon view.
666 g_object_class_install_property (gobject_class,
668 g_param_spec_int ("margin",
670 P_("Space which is inserted at the edges of the icon view"),
672 GTK_PARAM_READWRITE));
676 * GtkIconView::orientation:
678 * The orientation property specifies how the cells (i.e. the icon and
679 * the text) of the item are positioned relative to each other.
683 g_object_class_install_property (gobject_class,
685 g_param_spec_enum ("orientation",
687 P_("How the text and icon of each item are positioned relative to each other"),
688 GTK_TYPE_ORIENTATION,
689 GTK_ORIENTATION_VERTICAL,
690 GTK_PARAM_READWRITE));
693 * GtkIconView:orientation:
695 * The reorderable property specifies if the items can be reordered
700 g_object_class_install_property (gobject_class,
702 g_param_spec_boolean ("reorderable",
704 P_("View is reorderable"),
708 /* Style properties */
709 gtk_widget_class_install_style_property (widget_class,
710 g_param_spec_boxed ("selection-box-color",
711 P_("Selection Box Color"),
712 P_("Color of the selection box"),
714 GTK_PARAM_READABLE));
716 gtk_widget_class_install_style_property (widget_class,
717 g_param_spec_uchar ("selection-box-alpha",
718 P_("Selection Box Alpha"),
719 P_("Opacity of the selection box"),
722 GTK_PARAM_READABLE));
725 widget_class->set_scroll_adjustments_signal =
726 g_signal_new ("set_scroll_adjustments",
727 G_TYPE_FROM_CLASS (gobject_class),
729 G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
731 _gtk_marshal_VOID__OBJECT_OBJECT,
733 GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
735 icon_view_signals[ITEM_ACTIVATED] =
736 g_signal_new ("item_activated",
737 G_TYPE_FROM_CLASS (gobject_class),
739 G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
741 g_cclosure_marshal_VOID__BOXED,
745 icon_view_signals[SELECTION_CHANGED] =
746 g_signal_new ("selection_changed",
747 G_TYPE_FROM_CLASS (gobject_class),
749 G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
751 g_cclosure_marshal_VOID__VOID,
754 icon_view_signals[SELECT_ALL] =
755 g_signal_new ("select_all",
756 G_TYPE_FROM_CLASS (gobject_class),
757 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
758 G_STRUCT_OFFSET (GtkIconViewClass, select_all),
760 g_cclosure_marshal_VOID__VOID,
763 icon_view_signals[UNSELECT_ALL] =
764 g_signal_new ("unselect_all",
765 G_TYPE_FROM_CLASS (gobject_class),
766 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
767 G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
769 g_cclosure_marshal_VOID__VOID,
772 icon_view_signals[SELECT_CURSOR_ITEM] =
773 g_signal_new ("select_cursor_item",
774 G_TYPE_FROM_CLASS (gobject_class),
775 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
776 G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
778 g_cclosure_marshal_VOID__VOID,
781 icon_view_signals[TOGGLE_CURSOR_ITEM] =
782 g_signal_new ("toggle_cursor_item",
783 G_TYPE_FROM_CLASS (gobject_class),
784 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
785 G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
787 g_cclosure_marshal_VOID__VOID,
790 icon_view_signals[ACTIVATE_CURSOR_ITEM] =
791 g_signal_new ("activate_cursor_item",
792 G_TYPE_FROM_CLASS (gobject_class),
793 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
794 G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
796 _gtk_marshal_BOOLEAN__VOID,
799 icon_view_signals[MOVE_CURSOR] =
800 g_signal_new ("move_cursor",
801 G_TYPE_FROM_CLASS (gobject_class),
802 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
803 G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
805 _gtk_marshal_BOOLEAN__ENUM_INT,
807 GTK_TYPE_MOVEMENT_STEP,
811 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK, "select_all", 0);
812 gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect_all", 0);
813 gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK, "toggle_cursor_item", 0);
815 gtk_binding_entry_add_signal (binding_set, GDK_space, 0, "activate_cursor_item", 0);
816 gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, "activate_cursor_item", 0);
817 gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0, "activate_cursor_item", 0);
818 gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, "activate_cursor_item", 0);
820 gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
821 GTK_MOVEMENT_DISPLAY_LINES, -1);
822 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Up, 0,
823 GTK_MOVEMENT_DISPLAY_LINES, -1);
825 gtk_icon_view_add_move_binding (binding_set, GDK_Down, 0,
826 GTK_MOVEMENT_DISPLAY_LINES, 1);
827 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Down, 0,
828 GTK_MOVEMENT_DISPLAY_LINES, 1);
830 gtk_icon_view_add_move_binding (binding_set, GDK_p, GDK_CONTROL_MASK,
831 GTK_MOVEMENT_DISPLAY_LINES, -1);
833 gtk_icon_view_add_move_binding (binding_set, GDK_n, GDK_CONTROL_MASK,
834 GTK_MOVEMENT_DISPLAY_LINES, 1);
836 gtk_icon_view_add_move_binding (binding_set, GDK_Home, 0,
837 GTK_MOVEMENT_BUFFER_ENDS, -1);
838 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Home, 0,
839 GTK_MOVEMENT_BUFFER_ENDS, -1);
841 gtk_icon_view_add_move_binding (binding_set, GDK_End, 0,
842 GTK_MOVEMENT_BUFFER_ENDS, 1);
843 gtk_icon_view_add_move_binding (binding_set, GDK_KP_End, 0,
844 GTK_MOVEMENT_BUFFER_ENDS, 1);
846 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Up, 0,
847 GTK_MOVEMENT_PAGES, -1);
848 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Up, 0,
849 GTK_MOVEMENT_PAGES, -1);
851 gtk_icon_view_add_move_binding (binding_set, GDK_Page_Down, 0,
852 GTK_MOVEMENT_PAGES, 1);
853 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Page_Down, 0,
854 GTK_MOVEMENT_PAGES, 1);
856 gtk_icon_view_add_move_binding (binding_set, GDK_Right, 0,
857 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
858 gtk_icon_view_add_move_binding (binding_set, GDK_Left, 0,
859 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
861 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Right, 0,
862 GTK_MOVEMENT_VISUAL_POSITIONS, 1);
863 gtk_icon_view_add_move_binding (binding_set, GDK_KP_Left, 0,
864 GTK_MOVEMENT_VISUAL_POSITIONS, -1);
868 gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
870 iface->pack_start = gtk_icon_view_cell_layout_pack_start;
871 iface->pack_end = gtk_icon_view_cell_layout_pack_end;
872 iface->clear = gtk_icon_view_cell_layout_clear;
873 iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
874 iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
875 iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
876 iface->reorder = gtk_icon_view_cell_layout_reorder;
880 gtk_icon_view_init (GtkIconView *icon_view)
882 icon_view->priv = GTK_ICON_VIEW_GET_PRIVATE (icon_view);
884 icon_view->priv->width = 0;
885 icon_view->priv->height = 0;
886 icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
887 icon_view->priv->pressed_button = -1;
888 icon_view->priv->press_start_x = -1;
889 icon_view->priv->press_start_y = -1;
890 icon_view->priv->text_column = -1;
891 icon_view->priv->markup_column = -1;
892 icon_view->priv->pixbuf_column = -1;
893 icon_view->priv->text_cell = -1;
894 icon_view->priv->pixbuf_cell = -1;
896 GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
898 gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
900 icon_view->priv->cell_list = NULL;
901 icon_view->priv->n_cells = 0;
902 icon_view->priv->cursor_cell = -1;
904 icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
906 icon_view->priv->columns = -1;
907 icon_view->priv->item_width = -1;
908 icon_view->priv->spacing = 0;
909 icon_view->priv->row_spacing = 6;
910 icon_view->priv->column_spacing = 6;
911 icon_view->priv->margin = 6;
915 gtk_icon_view_destroy (GtkObject *object)
917 GtkIconView *icon_view;
919 icon_view = GTK_ICON_VIEW (object);
921 gtk_icon_view_stop_editing (icon_view, TRUE);
923 gtk_icon_view_set_model (icon_view, NULL);
925 if (icon_view->priv->layout_idle_id != 0)
926 g_source_remove (icon_view->priv->layout_idle_id);
928 remove_scroll_timeout (icon_view);
930 (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
933 /* GObject methods */
935 gtk_icon_view_finalize (GObject *object)
937 gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
939 (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
944 gtk_icon_view_set_property (GObject *object,
949 GtkIconView *icon_view;
951 icon_view = GTK_ICON_VIEW (object);
955 case PROP_SELECTION_MODE:
956 gtk_icon_view_set_selection_mode (icon_view, g_value_get_enum (value));
958 case PROP_PIXBUF_COLUMN:
959 gtk_icon_view_set_pixbuf_column (icon_view, g_value_get_int (value));
961 case PROP_TEXT_COLUMN:
962 gtk_icon_view_set_text_column (icon_view, g_value_get_int (value));
964 case PROP_MARKUP_COLUMN:
965 gtk_icon_view_set_markup_column (icon_view, g_value_get_int (value));
968 gtk_icon_view_set_model (icon_view, g_value_get_object (value));
970 case PROP_ORIENTATION:
971 gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
974 gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
976 case PROP_ITEM_WIDTH:
977 gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
980 gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
982 case PROP_ROW_SPACING:
983 gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
985 case PROP_COLUMN_SPACING:
986 gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
989 gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
991 case PROP_REORDERABLE:
992 gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
996 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1002 gtk_icon_view_get_property (GObject *object,
1007 GtkIconView *icon_view;
1009 icon_view = GTK_ICON_VIEW (object);
1013 case PROP_SELECTION_MODE:
1014 g_value_set_enum (value, icon_view->priv->selection_mode);
1016 case PROP_PIXBUF_COLUMN:
1017 g_value_set_int (value, icon_view->priv->pixbuf_column);
1019 case PROP_TEXT_COLUMN:
1020 g_value_set_int (value, icon_view->priv->text_column);
1022 case PROP_MARKUP_COLUMN:
1023 g_value_set_int (value, icon_view->priv->markup_column);
1026 g_value_set_object (value, icon_view->priv->model);
1028 case PROP_ORIENTATION:
1029 g_value_set_enum (value, icon_view->priv->orientation);
1032 g_value_set_int (value, icon_view->priv->columns);
1034 case PROP_ITEM_WIDTH:
1035 g_value_set_int (value, icon_view->priv->item_width);
1038 g_value_set_int (value, icon_view->priv->spacing);
1040 case PROP_ROW_SPACING:
1041 g_value_set_int (value, icon_view->priv->row_spacing);
1043 case PROP_COLUMN_SPACING:
1044 g_value_set_int (value, icon_view->priv->column_spacing);
1047 g_value_set_int (value, icon_view->priv->margin);
1049 case PROP_REORDERABLE:
1050 g_value_set_boolean (value, icon_view->priv->reorderable);
1054 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1059 /* GtkWidget signals */
1061 gtk_icon_view_realize (GtkWidget *widget)
1063 GtkIconView *icon_view;
1064 GdkWindowAttr attributes;
1065 gint attributes_mask;
1067 icon_view = GTK_ICON_VIEW (widget);
1069 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
1071 /* Make the main, clipping window */
1072 attributes.window_type = GDK_WINDOW_CHILD;
1073 attributes.x = widget->allocation.x;
1074 attributes.y = widget->allocation.y;
1075 attributes.width = widget->allocation.width;
1076 attributes.height = widget->allocation.height;
1077 attributes.wclass = GDK_INPUT_OUTPUT;
1078 attributes.visual = gtk_widget_get_visual (widget);
1079 attributes.colormap = gtk_widget_get_colormap (widget);
1080 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1082 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1084 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1085 &attributes, attributes_mask);
1086 gdk_window_set_user_data (widget->window, widget);
1088 /* Make the window for the icon view */
1091 attributes.width = MAX (icon_view->priv->width, widget->allocation.width);
1092 attributes.height = MAX (icon_view->priv->height, widget->allocation.height);
1093 attributes.event_mask = (GDK_EXPOSURE_MASK |
1095 GDK_POINTER_MOTION_MASK |
1096 GDK_BUTTON_PRESS_MASK |
1097 GDK_BUTTON_RELEASE_MASK |
1098 GDK_KEY_PRESS_MASK |
1099 GDK_KEY_RELEASE_MASK) |
1100 gtk_widget_get_events (widget);
1102 icon_view->priv->bin_window = gdk_window_new (widget->window,
1103 &attributes, attributes_mask);
1104 gdk_window_set_user_data (icon_view->priv->bin_window, widget);
1106 widget->style = gtk_style_attach (widget->style, widget->window);
1107 gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
1108 gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
1110 gdk_window_show (icon_view->priv->bin_window);
1114 gtk_icon_view_unrealize (GtkWidget *widget)
1116 GtkIconView *icon_view;
1118 icon_view = GTK_ICON_VIEW (widget);
1120 gdk_window_set_user_data (icon_view->priv->bin_window, NULL);
1121 gdk_window_destroy (icon_view->priv->bin_window);
1122 icon_view->priv->bin_window = NULL;
1124 /* GtkWidget::unrealize destroys children and widget->window */
1125 if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
1126 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
1130 gtk_icon_view_size_request (GtkWidget *widget,
1131 GtkRequisition *requisition)
1133 GtkIconView *icon_view;
1136 icon_view = GTK_ICON_VIEW (widget);
1138 requisition->width = icon_view->priv->width;
1139 requisition->height = icon_view->priv->height;
1141 tmp_list = icon_view->priv->children;
1145 GtkIconViewChild *child = tmp_list->data;
1146 GtkRequisition child_requisition;
1148 tmp_list = tmp_list->next;
1150 if (GTK_WIDGET_VISIBLE (child->widget))
1151 gtk_widget_size_request (child->widget, &child_requisition);
1156 gtk_icon_view_allocate_children (GtkIconView *icon_view)
1160 for (list = icon_view->priv->children; list; list = list->next)
1162 GtkIconViewChild *child = list->data;
1163 GtkAllocation allocation;
1165 /* totally ignore our child's requisition */
1166 if (child->cell < 0)
1168 allocation.x = child->item->x;
1169 allocation.y = child->item->y;
1170 allocation.width = child->item->width;
1171 allocation.height = child->item->height;
1175 GdkRectangle *box = &child->item->box[child->cell];
1177 allocation.x = box->x;
1178 allocation.y = box->y;
1179 allocation.width = box->width;
1180 allocation.height = box->height;
1183 gtk_widget_size_allocate (child->widget, &allocation);
1188 gtk_icon_view_size_allocate (GtkWidget *widget,
1189 GtkAllocation *allocation)
1191 GtkIconView *icon_view = GTK_ICON_VIEW (widget);
1193 GtkAdjustment *hadjustment, *vadjustment;
1195 widget->allocation = *allocation;
1197 if (GTK_WIDGET_REALIZED (widget))
1199 gdk_window_move_resize (widget->window,
1200 allocation->x, allocation->y,
1201 allocation->width, allocation->height);
1202 gdk_window_resize (icon_view->priv->bin_window,
1203 MAX (icon_view->priv->width, allocation->width),
1204 MAX (icon_view->priv->height, allocation->height));
1207 gtk_icon_view_layout (icon_view);
1209 gtk_icon_view_allocate_children (icon_view);
1211 hadjustment = icon_view->priv->hadjustment;
1212 vadjustment = icon_view->priv->vadjustment;
1214 hadjustment->page_size = allocation->width;
1215 hadjustment->page_increment = allocation->width * 0.9;
1216 hadjustment->step_increment = allocation->width * 0.1;
1217 hadjustment->lower = 0;
1218 hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
1220 if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
1221 gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
1223 vadjustment->page_size = allocation->height;
1224 vadjustment->page_increment = allocation->height * 0.9;
1225 vadjustment->step_increment = allocation->height * 0.1;
1226 vadjustment->lower = 0;
1227 vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
1229 if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
1230 gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
1232 gtk_adjustment_changed (hadjustment);
1233 gtk_adjustment_changed (vadjustment);
1237 gtk_icon_view_expose (GtkWidget *widget,
1238 GdkEventExpose *expose)
1240 GtkIconView *icon_view;
1245 GtkIconViewDropPosition dest_pos;
1246 GtkIconViewItem *dest_item = NULL;
1248 icon_view = GTK_ICON_VIEW (widget);
1250 if (expose->window != icon_view->priv->bin_window)
1253 cr = gdk_cairo_create (icon_view->priv->bin_window);
1254 cairo_set_line_width (cr, 1.);
1256 gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
1260 dest_index = gtk_tree_path_get_indices (path)[0];
1261 gtk_tree_path_free (path);
1266 for (icons = icon_view->priv->items; icons; icons = icons->next)
1268 GtkIconViewItem *item = icons->data;
1273 area.width = item->width;
1274 area.height = item->height;
1276 if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
1279 gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
1280 icon_view->priv->bin_window,
1281 item->x, item->y, TRUE);
1283 if (dest_index == item->index)
1291 case GTK_ICON_VIEW_DROP_INTO:
1292 gtk_paint_focus (widget->style,
1293 icon_view->priv->bin_window,
1294 GTK_WIDGET_STATE (widget),
1297 "iconview-drop-indicator",
1298 dest_item->x, dest_item->y,
1299 dest_item->width, dest_item->height);
1301 case GTK_ICON_VIEW_DROP_ABOVE:
1302 gtk_paint_focus (widget->style,
1303 icon_view->priv->bin_window,
1304 GTK_WIDGET_STATE (widget),
1307 "iconview-drop-indicator",
1308 dest_item->x, dest_item->y - 1,
1309 dest_item->width, 2);
1311 case GTK_ICON_VIEW_DROP_LEFT:
1312 gtk_paint_focus (widget->style,
1313 icon_view->priv->bin_window,
1314 GTK_WIDGET_STATE (widget),
1317 "iconview-drop-indicator",
1318 dest_item->x - 1, dest_item->y,
1319 2, dest_item->height);
1321 case GTK_ICON_VIEW_DROP_BELOW:
1322 gtk_paint_focus (widget->style,
1323 icon_view->priv->bin_window,
1324 GTK_WIDGET_STATE (widget),
1327 "iconview-drop-indicator",
1328 dest_item->x, dest_item->y + dest_item->height - 1,
1329 dest_item->width, 2);
1331 case GTK_ICON_VIEW_DROP_RIGHT:
1332 gtk_paint_focus (widget->style,
1333 icon_view->priv->bin_window,
1334 GTK_WIDGET_STATE (widget),
1337 "iconview-drop-indicator",
1338 dest_item->x + dest_item->width - 1, dest_item->y,
1339 2, dest_item->height);
1340 case GTK_ICON_VIEW_NO_DROP: ;
1345 if (icon_view->priv->doing_rubberband)
1347 GdkRectangle *rectangles;
1350 gdk_region_get_rectangles (expose->region,
1354 while (n_rectangles--)
1355 gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
1357 g_free (rectangles);
1362 (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);
1368 rubberband_scroll_timeout (gpointer data)
1370 GtkIconView *icon_view;
1373 GDK_THREADS_ENTER ();
1377 value = MIN (icon_view->priv->vadjustment->value +
1378 icon_view->priv->scroll_value_diff,
1379 icon_view->priv->vadjustment->upper -
1380 icon_view->priv->vadjustment->page_size);
1382 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
1384 gtk_icon_view_update_rubberband (icon_view);
1386 GDK_THREADS_LEAVE ();
1392 gtk_icon_view_motion (GtkWidget *widget,
1393 GdkEventMotion *event)
1395 GtkIconView *icon_view;
1398 icon_view = GTK_ICON_VIEW (widget);
1400 gtk_icon_view_maybe_begin_drag (icon_view, event);
1402 if (icon_view->priv->doing_rubberband)
1404 gtk_icon_view_update_rubberband (widget);
1406 abs_y = event->y - icon_view->priv->height *
1407 (icon_view->priv->vadjustment->value /
1408 (icon_view->priv->vadjustment->upper -
1409 icon_view->priv->vadjustment->lower));
1411 if (abs_y < 0 || abs_y > widget->allocation.height)
1414 icon_view->priv->scroll_value_diff = abs_y;
1416 icon_view->priv->scroll_value_diff = abs_y - widget->allocation.height;
1418 icon_view->priv->event_last_x = event->x;
1419 icon_view->priv->event_last_y = event->y;
1421 if (icon_view->priv->scroll_timeout_id == 0)
1422 icon_view->priv->scroll_timeout_id = g_timeout_add (30, rubberband_scroll_timeout,
1426 remove_scroll_timeout (icon_view);
1433 gtk_icon_view_remove (GtkContainer *container,
1436 GtkIconView *icon_view;
1437 GtkIconViewChild *child = NULL;
1440 icon_view = GTK_ICON_VIEW (container);
1442 tmp_list = icon_view->priv->children;
1445 child = tmp_list->data;
1446 if (child->widget == widget)
1448 gtk_widget_unparent (widget);
1450 icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
1451 g_list_free_1 (tmp_list);
1456 tmp_list = tmp_list->next;
1461 gtk_icon_view_forall (GtkContainer *container,
1462 gboolean include_internals,
1463 GtkCallback callback,
1464 gpointer callback_data)
1466 GtkIconView *icon_view;
1467 GtkIconViewChild *child = NULL;
1470 icon_view = GTK_ICON_VIEW (container);
1472 tmp_list = icon_view->priv->children;
1475 child = tmp_list->data;
1476 tmp_list = tmp_list->next;
1478 (* callback) (child->widget, callback_data);
1483 gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
1484 GtkIconViewItem *item,
1485 GtkIconViewCellInfo *info,
1490 GdkRectangle cell_area;
1491 gboolean visible, mode;
1493 gtk_icon_view_set_cell_data (icon_view, item);
1495 g_object_get (info->cell,
1496 "visible", &visible,
1500 if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1502 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1504 path = gtk_tree_path_new_from_indices (item->index, -1);
1505 path_string = gtk_tree_path_to_string (path);
1506 gtk_tree_path_free (path);
1508 gtk_cell_renderer_activate (info->cell,
1510 GTK_WIDGET (icon_view),
1516 g_free (path_string);
1521 gtk_icon_view_put (GtkIconView *icon_view,
1523 GtkIconViewItem *item,
1526 GtkIconViewChild *child;
1528 child = g_new (GtkIconViewChild, 1);
1530 child->widget = widget;
1534 icon_view->priv->children = g_list_append (icon_view->priv->children, child);
1536 if (GTK_WIDGET_REALIZED (icon_view))
1537 gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
1539 gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
1543 gtk_icon_view_remove_widget (GtkCellEditable *editable,
1544 GtkIconView *icon_view)
1547 GtkIconViewItem *item;
1549 if (icon_view->priv->edited_item == NULL)
1552 item = icon_view->priv->edited_item;
1553 icon_view->priv->edited_item = NULL;
1554 icon_view->priv->editable = NULL;
1555 for (l = icon_view->priv->cell_list; l; l = l->next)
1557 GtkIconViewCellInfo *info = l->data;
1559 info->editing = FALSE;
1562 if (GTK_WIDGET_HAS_FOCUS (editable))
1563 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
1565 g_signal_handlers_disconnect_by_func (editable,
1566 gtk_icon_view_remove_widget,
1569 gtk_container_remove (GTK_CONTAINER (icon_view),
1570 GTK_WIDGET (editable));
1572 gtk_icon_view_queue_draw_item (icon_view, item);
1577 gtk_icon_view_start_editing (GtkIconView *icon_view,
1578 GtkIconViewItem *item,
1579 GtkIconViewCellInfo *info,
1584 GdkRectangle cell_area;
1585 gboolean visible, mode;
1586 GtkCellEditable *editable;
1588 gtk_icon_view_set_cell_data (icon_view, item);
1590 g_object_get (info->cell,
1591 "visible", &visible,
1594 if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1596 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
1598 path = gtk_tree_path_new_from_indices (item->index, -1);
1599 path_string = gtk_tree_path_to_string (path);
1600 gtk_tree_path_free (path);
1602 editable = gtk_cell_renderer_start_editing (info->cell,
1604 GTK_WIDGET (icon_view),
1609 g_free (path_string);
1611 /* FIXME ugly special case */
1612 if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
1613 g_object_set (editable, "has_frame", TRUE, NULL);
1615 /* the rest corresponds to tree_view_real_start_editing... */
1616 icon_view->priv->edited_item = item;
1617 icon_view->priv->editable = editable;
1618 info->editing = TRUE;
1620 gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
1622 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
1624 gtk_widget_grab_focus (GTK_WIDGET (editable));
1625 g_signal_connect (editable, "remove_widget",
1626 G_CALLBACK (gtk_icon_view_remove_widget),
1633 gtk_icon_view_stop_editing (GtkIconView *icon_view,
1634 gboolean cancel_editing)
1636 GtkCellRenderer *cell = NULL;
1637 GtkIconViewItem *item;
1640 if (icon_view->priv->edited_item == NULL)
1644 * This is very evil. We need to do this, because
1645 * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
1646 * later on. If gtk_icon_view_row_changed notices
1647 * icon_view->priv->edited_item != NULL, it'll call
1648 * gtk_icon_view_stop_editing again. Bad things will happen then.
1650 * Please read that again if you intend to modify anything here.
1653 item = icon_view->priv->edited_item;
1654 icon_view->priv->edited_item = NULL;
1656 for (l = icon_view->priv->cell_list; l; l = l->next)
1658 GtkIconViewCellInfo *info = l->data;
1670 gtk_cell_renderer_stop_editing (cell, cancel_editing);
1671 if (!cancel_editing)
1672 gtk_cell_editable_editing_done (icon_view->priv->editable);
1674 icon_view->priv->edited_item = item;
1676 gtk_cell_editable_remove_widget (icon_view->priv->editable);
1680 * gtk_icon_view_set_cursor:
1681 * @icon_view: A #GtkIconView
1682 * @path: A #GtkTreePath
1683 * @cell: A #GtkCellRenderer or %NULL
1684 * @start_editing: %TRUE if the specified cell should start being edited.
1686 * Sets the current keyboard focus to be at @path, and selects it. This is
1687 * useful when you want to focus the user's attention on a particular item.
1688 * If @cell is not %NULL, then focus is given to the cell specified by
1689 * it. Additionally, if @start_editing is %TRUE, then editing should be
1690 * started in the specified cell.
1692 * This function is often followed by <literal>gtk_widget_grab_focus
1693 * (icon_view)</literal> in order to give keyboard focus to the widget.
1694 * Please note that editing can only happen when the widget is realized.
1699 gtk_icon_view_set_cursor (GtkIconView *icon_view,
1701 GtkCellRenderer *cell,
1702 gboolean start_editing)
1704 GtkIconViewItem *item;
1705 GtkIconViewCellInfo *info = NULL;
1709 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
1710 g_return_if_fail (path != NULL);
1711 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
1713 gtk_icon_view_stop_editing (icon_view, TRUE);
1715 item = g_list_nth (icon_view->priv->items,
1716 gtk_tree_path_get_indices(path)[0])->data;
1722 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
1726 if (info->cell == cell)
1735 gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
1736 gtk_icon_view_scroll_to_item (icon_view, item);
1739 gtk_icon_view_start_editing (icon_view, item, info, NULL);
1743 * gtk_icon_view_get_cursor:
1744 * @icon_view: A #GtkIconView
1745 * @path: Return location for the current cursor path, or %NULL
1746 * @cell: Return location the current focus cell, or %NULL
1748 * Fills in @path and @cell with the current cursor path and cell.
1749 * If the cursor isn't currently set, then *@path will be %NULL.
1750 * If no cell currently has focus, then *@cell will be %NULL.
1752 * The returned #GtkTreePath must be freed with gtk_tree_path_free().
1754 * Return value: %TRUE if the cursor is set.
1759 gtk_icon_view_get_cursor (GtkIconView *icon_view,
1761 GtkCellRenderer **cell)
1763 GtkIconViewItem *item;
1764 GtkIconViewCellInfo *info;
1766 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
1768 item = icon_view->priv->cursor_item;
1769 if (icon_view->priv->cursor_cell < 0)
1772 info = g_list_nth_data (icon_view->priv->cell_list,
1773 icon_view->priv->cursor_cell);
1778 *path = gtk_tree_path_new_from_indices (item->index, -1);
1791 return (item != NULL);
1795 gtk_icon_view_button_press (GtkWidget *widget,
1796 GdkEventButton *event)
1798 GtkIconView *icon_view;
1799 GtkIconViewItem *item;
1800 GtkIconViewCellInfo *info = NULL;
1801 gboolean dirty = FALSE;
1802 GtkCellRendererMode mode;
1805 icon_view = GTK_ICON_VIEW (widget);
1807 if (event->window != icon_view->priv->bin_window)
1810 if (!GTK_WIDGET_HAS_FOCUS (widget))
1811 gtk_widget_grab_focus (widget);
1813 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
1815 item = gtk_icon_view_get_item_at_coords (icon_view,
1821 g_object_get (info->cell, "mode", &mode, NULL);
1823 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
1824 mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1825 cursor_cell = g_list_index (icon_view->priv->cell_list, info);
1829 gtk_icon_view_scroll_to_item (icon_view, item);
1831 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
1833 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1835 else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
1836 (event->state & GDK_SHIFT_MASK))
1838 gtk_icon_view_unselect_all_internal (icon_view);
1840 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1841 if (!icon_view->priv->anchor_item)
1842 icon_view->priv->anchor_item = item;
1844 gtk_icon_view_select_all_between (icon_view,
1845 icon_view->priv->anchor_item,
1851 if ((icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE ||
1852 ((icon_view->priv->selection_mode == GTK_SELECTION_SINGLE) && item->selected)) &&
1853 (event->state & GDK_CONTROL_MASK))
1855 item->selected = !item->selected;
1856 gtk_icon_view_queue_draw_item (icon_view, item);
1861 if (!item->selected)
1863 gtk_icon_view_unselect_all_internal (icon_view);
1865 item->selected = TRUE;
1866 gtk_icon_view_queue_draw_item (icon_view, item);
1870 gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
1871 icon_view->priv->anchor_item = item;
1874 /* Save press to possibly begin a drag */
1875 if (icon_view->priv->pressed_button < 0)
1877 icon_view->priv->pressed_button = event->button;
1878 icon_view->priv->press_start_x = event->x;
1879 icon_view->priv->press_start_y = event->y;
1882 if (!icon_view->priv->last_single_clicked)
1883 icon_view->priv->last_single_clicked = item;
1885 /* cancel the current editing, if it exists */
1886 gtk_icon_view_stop_editing (icon_view, TRUE);
1888 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
1889 gtk_icon_view_item_activate_cell (icon_view, item, info,
1891 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
1892 gtk_icon_view_start_editing (icon_view, item, info,
1897 if (icon_view->priv->selection_mode != GTK_SELECTION_BROWSE &&
1898 !(event->state & GDK_CONTROL_MASK))
1900 dirty = gtk_icon_view_unselect_all_internal (icon_view);
1903 if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
1904 gtk_icon_view_start_rubberbanding (icon_view, event->x, event->y);
1909 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
1911 item = gtk_icon_view_get_item_at_coords (icon_view,
1916 if (item && item == icon_view->priv->last_single_clicked)
1920 path = gtk_tree_path_new_from_indices (item->index, -1);
1921 gtk_icon_view_item_activated (icon_view, path);
1922 gtk_tree_path_free (path);
1925 icon_view->priv->last_single_clicked = NULL;
1929 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
1931 return event->button == 1;
1935 gtk_icon_view_button_release (GtkWidget *widget,
1936 GdkEventButton *event)
1938 GtkIconView *icon_view;
1940 icon_view = GTK_ICON_VIEW (widget);
1942 if (icon_view->priv->pressed_button == event->button)
1943 icon_view->priv->pressed_button = -1;
1945 gtk_icon_view_stop_rubberbanding (icon_view);
1947 remove_scroll_timeout (icon_view);
1953 gtk_icon_view_update_rubberband (gpointer data)
1955 GtkIconView *icon_view;
1957 GdkRectangle old_area;
1958 GdkRectangle new_area;
1959 GdkRectangle common;
1960 GdkRegion *invalid_region;
1962 icon_view = GTK_ICON_VIEW (data);
1964 gdk_window_get_pointer (icon_view->priv->bin_window, &x, &y, NULL);
1969 old_area.x = MIN (icon_view->priv->rubberband_x1,
1970 icon_view->priv->rubberband_x2);
1971 old_area.y = MIN (icon_view->priv->rubberband_y1,
1972 icon_view->priv->rubberband_y2);
1973 old_area.width = ABS (icon_view->priv->rubberband_x2 -
1974 icon_view->priv->rubberband_x1) + 1;
1975 old_area.height = ABS (icon_view->priv->rubberband_y2 -
1976 icon_view->priv->rubberband_y1) + 1;
1978 new_area.x = MIN (icon_view->priv->rubberband_x1, x);
1979 new_area.y = MIN (icon_view->priv->rubberband_y1, y);
1980 new_area.width = ABS (x - icon_view->priv->rubberband_x1) + 1;
1981 new_area.height = ABS (y - icon_view->priv->rubberband_y1) + 1;
1983 invalid_region = gdk_region_rectangle (&old_area);
1984 gdk_region_union_with_rect (invalid_region, &new_area);
1986 gdk_rectangle_intersect (&old_area, &new_area, &common);
1987 if (common.width > 2 && common.height > 2)
1989 GdkRegion *common_region;
1991 /* make sure the border is invalidated */
1997 common_region = gdk_region_rectangle (&common);
1999 gdk_region_subtract (invalid_region, common_region);
2000 gdk_region_destroy (common_region);
2003 gdk_window_invalidate_region (icon_view->priv->bin_window, invalid_region, TRUE);
2005 gdk_region_destroy (invalid_region);
2007 icon_view->priv->rubberband_x2 = x;
2008 icon_view->priv->rubberband_y2 = y;
2010 gtk_icon_view_update_rubberband_selection (icon_view);
2014 gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
2020 g_assert (!icon_view->priv->doing_rubberband);
2022 for (items = icon_view->priv->items; items; items = items->next)
2024 GtkIconViewItem *item = items->data;
2026 item->selected_before_rubberbanding = item->selected;
2029 icon_view->priv->rubberband_x1 = x;
2030 icon_view->priv->rubberband_y1 = y;
2031 icon_view->priv->rubberband_x2 = x;
2032 icon_view->priv->rubberband_y2 = y;
2034 icon_view->priv->doing_rubberband = TRUE;
2036 gtk_grab_add (GTK_WIDGET (icon_view));
2040 gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view)
2042 if (!icon_view->priv->doing_rubberband)
2045 icon_view->priv->doing_rubberband = FALSE;
2047 gtk_grab_remove (GTK_WIDGET (icon_view));
2049 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2053 gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view)
2056 gint x, y, width, height;
2057 gboolean dirty = FALSE;
2059 x = MIN (icon_view->priv->rubberband_x1,
2060 icon_view->priv->rubberband_x2);
2061 y = MIN (icon_view->priv->rubberband_y1,
2062 icon_view->priv->rubberband_y2);
2063 width = ABS (icon_view->priv->rubberband_x1 -
2064 icon_view->priv->rubberband_x2);
2065 height = ABS (icon_view->priv->rubberband_y1 -
2066 icon_view->priv->rubberband_y2);
2068 for (items = icon_view->priv->items; items; items = items->next)
2070 GtkIconViewItem *item = items->data;
2074 is_in = gtk_icon_view_item_hit_test (icon_view, item,
2075 x, y, width, height);
2077 selected = is_in ^ item->selected_before_rubberbanding;
2079 if (item->selected != selected)
2081 item->selected = selected;
2083 gtk_icon_view_queue_draw_item (icon_view, item);
2088 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2092 gtk_icon_view_item_hit_test (GtkIconView *icon_view,
2093 GtkIconViewItem *item,
2102 for (l = icon_view->priv->cell_list; l; l = l->next)
2104 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2106 if (!info->cell->visible)
2109 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2111 if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
2112 MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
2120 gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
2122 gboolean dirty = FALSE;
2125 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
2128 for (items = icon_view->priv->items; items; items = items->next)
2130 GtkIconViewItem *item = items->data;
2134 item->selected = FALSE;
2136 gtk_icon_view_queue_draw_item (icon_view, item);
2144 /* GtkIconView signals */
2146 gtk_icon_view_set_adjustments (GtkIconView *icon_view,
2147 GtkAdjustment *hadj,
2148 GtkAdjustment *vadj)
2150 gboolean need_adjust = FALSE;
2153 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
2155 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2157 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
2159 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
2161 if (icon_view->priv->hadjustment && (icon_view->priv->hadjustment != hadj))
2163 g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
2164 0, 0, NULL, NULL, icon_view);
2165 g_object_unref (icon_view->priv->hadjustment);
2168 if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
2170 g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
2171 0, 0, NULL, NULL, icon_view);
2172 g_object_unref (icon_view->priv->vadjustment);
2175 if (icon_view->priv->hadjustment != hadj)
2177 icon_view->priv->hadjustment = hadj;
2178 g_object_ref (icon_view->priv->hadjustment);
2179 gtk_object_sink (GTK_OBJECT (icon_view->priv->hadjustment));
2181 g_signal_connect (icon_view->priv->hadjustment, "value_changed",
2182 G_CALLBACK (gtk_icon_view_adjustment_changed),
2187 if (icon_view->priv->vadjustment != vadj)
2189 icon_view->priv->vadjustment = vadj;
2190 g_object_ref (icon_view->priv->vadjustment);
2191 gtk_object_sink (GTK_OBJECT (icon_view->priv->vadjustment));
2193 g_signal_connect (icon_view->priv->vadjustment, "value_changed",
2194 G_CALLBACK (gtk_icon_view_adjustment_changed),
2200 gtk_icon_view_adjustment_changed (NULL, icon_view);
2204 gtk_icon_view_real_select_all (GtkIconView *icon_view)
2206 gtk_icon_view_select_all (icon_view);
2210 gtk_icon_view_real_unselect_all (GtkIconView *icon_view)
2212 gtk_icon_view_unselect_all (icon_view);
2216 gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view)
2218 gtk_icon_view_unselect_all (icon_view);
2220 if (icon_view->priv->cursor_item != NULL)
2221 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2225 gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
2228 GtkCellRendererMode mode;
2229 GtkIconViewCellInfo *info = NULL;
2231 if (!icon_view->priv->cursor_item)
2234 info = g_list_nth_data (icon_view->priv->cell_list,
2235 icon_view->priv->cursor_cell);
2239 g_object_get (info->cell, "mode", &mode, NULL);
2241 if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
2243 gtk_icon_view_item_activate_cell (icon_view,
2244 icon_view->priv->cursor_item,
2248 else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
2250 gtk_icon_view_start_editing (icon_view,
2251 icon_view->priv->cursor_item,
2257 path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
2258 gtk_icon_view_item_activated (icon_view, path);
2259 gtk_tree_path_free (path);
2265 gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view)
2267 if (!icon_view->priv->cursor_item)
2270 switch (icon_view->priv->selection_mode)
2272 case GTK_SELECTION_NONE:
2274 case GTK_SELECTION_BROWSE:
2275 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2277 case GTK_SELECTION_SINGLE:
2278 if (icon_view->priv->cursor_item->selected)
2279 gtk_icon_view_unselect_item (icon_view, icon_view->priv->cursor_item);
2281 gtk_icon_view_select_item (icon_view, icon_view->priv->cursor_item);
2283 case GTK_SELECTION_MULTIPLE:
2284 icon_view->priv->cursor_item->selected = !icon_view->priv->cursor_item->selected;
2285 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
2287 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
2292 /* Internal functions */
2294 gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
2295 GtkIconView *icon_view)
2297 if (GTK_WIDGET_REALIZED (icon_view))
2299 gdk_window_move (icon_view->priv->bin_window,
2300 - icon_view->priv->hadjustment->value,
2301 - icon_view->priv->vadjustment->value);
2303 if (icon_view->priv->doing_rubberband)
2304 gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
2306 gdk_window_process_updates (icon_view->priv->bin_window, TRUE);
2311 gtk_icon_view_layout_single_row (GtkIconView *icon_view,
2316 gint *maximum_width)
2320 gint x, current_width;
2321 GList *items, *last_item;
2328 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2329 max_height = g_new0 (gint, icon_view->priv->n_cells);
2336 gtk_widget_style_get (GTK_WIDGET (icon_view),
2337 "focus-line-width", &focus_width,
2340 spacing = icon_view->priv->spacing;
2342 x += icon_view->priv->margin + focus_width;
2343 current_width += 2 * (icon_view->priv->margin + focus_width);
2348 GtkIconViewItem *item = items->data;
2350 gtk_icon_view_calculate_item_size (icon_view, item);
2351 colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
2353 item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
2355 current_width += item->width;
2357 if (items != first_item)
2359 if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
2360 (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
2364 current_width += icon_view->priv->column_spacing + 2 * focus_width;
2366 item->y = *y + focus_width;
2367 item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
2369 x = current_width - (icon_view->priv->margin + focus_width);
2371 for (i = 0; i < icon_view->priv->n_cells; i++)
2372 max_height[i] = MAX (max_height[i], item->box[i].height);
2374 if (current_width > *maximum_width)
2375 *maximum_width = current_width;
2381 items = items->next;
2386 /* Now go through the row again and align the icons */
2387 for (items = first_item; items != last_item; items = items->next)
2389 GtkIconViewItem *item = items->data;
2391 gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
2393 /* We may want to readjust the new y coordinate. */
2394 if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
2395 *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
2398 item->col = col - 1 - item->col;
2401 g_free (max_height);
2407 gtk_icon_view_set_adjustment_upper (GtkAdjustment *adj,
2410 if (upper != adj->upper)
2412 gdouble min = MAX (0.0, upper - adj->page_size);
2413 gboolean value_changed = FALSE;
2417 if (adj->value > min)
2420 value_changed = TRUE;
2423 gtk_adjustment_changed (adj);
2426 gtk_adjustment_value_changed (adj);
2431 gtk_icon_view_layout (GtkIconView *icon_view)
2433 gint y = 0, maximum_width = 0;
2439 if (icon_view->priv->model == NULL)
2442 widget = GTK_WIDGET (icon_view);
2444 item_width = icon_view->priv->item_width;
2448 for (icons = icon_view->priv->items; icons; icons = icons->next)
2450 GtkIconViewItem *item = icons->data;
2451 gtk_icon_view_calculate_item_size (icon_view, item);
2452 item_width = MAX (item_width, item->width);
2456 icons = icon_view->priv->items;
2457 y += icon_view->priv->margin;
2462 icons = gtk_icon_view_layout_single_row (icon_view, icons,
2464 &y, &maximum_width);
2467 while (icons != NULL);
2469 if (maximum_width != icon_view->priv->width)
2471 icon_view->priv->width = maximum_width;
2473 y += icon_view->priv->margin;
2475 if (y != icon_view->priv->height)
2477 icon_view->priv->height = y;
2480 gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment, icon_view->priv->width);
2481 gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment, icon_view->priv->height);
2483 if (GTK_WIDGET_REALIZED (icon_view))
2485 gdk_window_resize (icon_view->priv->bin_window,
2486 MAX (icon_view->priv->width, widget->allocation.width),
2487 MAX (icon_view->priv->height, widget->allocation.height));
2490 if (icon_view->priv->layout_idle_id != 0)
2492 g_source_remove (icon_view->priv->layout_idle_id);
2493 icon_view->priv->layout_idle_id = 0;
2496 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
2500 gtk_icon_view_get_cell_area (GtkIconView *icon_view,
2501 GtkIconViewItem *item,
2502 GtkIconViewCellInfo *info,
2503 GdkRectangle *cell_area)
2505 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2507 cell_area->x = item->box[info->position].x - item->before[info->position];
2508 cell_area->y = item->y;
2509 cell_area->width = item->box[info->position].width +
2510 item->before[info->position] + item->after[info->position];
2511 cell_area->height = item->height;
2515 cell_area->x = item->x;
2516 cell_area->y = item->box[info->position].y - item->before[info->position];
2517 cell_area->width = item->width;
2518 cell_area->height = item->box[info->position].height +
2519 item->before[info->position] + item->after[info->position];
2524 gtk_icon_view_get_cell_box (GtkIconView *icon_view,
2525 GtkIconViewItem *item,
2526 GtkIconViewCellInfo *info,
2529 *box = item->box[info->position];
2532 /* try to guess a reasonable wrap width for an implicit text cell renderer
2535 adjust_wrap_width (GtkIconView *icon_view,
2536 GtkIconViewItem *item)
2538 GtkIconViewCellInfo *text_info;
2539 GtkIconViewCellInfo *pixbuf_info;
2540 gint pixbuf_width, wrap_width;
2542 if (icon_view->priv->item_width < 0 &&
2543 icon_view->priv->text_cell != -1 &&
2544 icon_view->priv->pixbuf_cell != -1)
2546 text_info = g_list_nth_data (icon_view->priv->cell_list,
2547 icon_view->priv->text_cell);
2548 pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
2549 icon_view->priv->pixbuf_cell);
2551 gtk_cell_renderer_get_size (pixbuf_info->cell,
2552 GTK_WIDGET (icon_view),
2557 if (item->width == -1)
2558 wrap_width = pixbuf_width;
2559 else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
2560 wrap_width = item->width;
2562 wrap_width = item->width - pixbuf_width - icon_view->priv->spacing;
2564 g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
2569 gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
2570 GtkIconViewItem *item)
2575 if (item->width != -1 && item->height != -1)
2578 if (item->n_cells != icon_view->priv->n_cells)
2580 g_free (item->before);
2581 g_free (item->after);
2584 item->before = g_new0 (gint, icon_view->priv->n_cells);
2585 item->after = g_new0 (gint, icon_view->priv->n_cells);
2586 item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
2588 item->n_cells = icon_view->priv->n_cells;
2591 gtk_icon_view_set_cell_data (icon_view, item);
2593 spacing = icon_view->priv->spacing;
2597 for (l = icon_view->priv->cell_list; l; l = l->next)
2599 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2601 if (!info->cell->visible)
2604 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2606 &item->box[info->position].width,
2607 &item->box[info->position].height);
2609 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2611 item->width += item->box[info->position].width
2612 + (info->position > 0 ? spacing : 0);
2613 item->height = MAX (item->height, item->box[info->position].height);
2617 item->width = MAX (item->width, item->box[info->position].width);
2618 item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
2624 gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
2625 GtkIconViewItem *item,
2628 GdkRectangle cell_area;
2634 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2636 gtk_icon_view_set_cell_data (icon_view, item);
2638 spacing = icon_view->priv->spacing;
2641 for (i = 0; i < icon_view->priv->n_cells; i++)
2643 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2644 item->height = MAX (item->height, max_height[i]);
2646 item->height += max_height[i] + (i > 0 ? spacing : 0);
2649 cell_area.x = item->x;
2650 cell_area.y = item->y;
2652 for (k = 0; k < 2; k++)
2653 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2655 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2657 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
2660 if (!info->cell->visible)
2663 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2665 cell_area.width = item->box[info->position].width;
2666 cell_area.height = item->height;
2670 cell_area.width = item->width;
2671 cell_area.height = max_height[i];
2674 gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
2676 &item->box[info->position].x, &item->box[info->position].y,
2677 &item->box[info->position].width, &item->box[info->position].height);
2679 item->box[info->position].x += cell_area.x;
2680 item->box[info->position].y += cell_area.y;
2681 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2683 item->before[info->position] = item->box[info->position].x - cell_area.x;
2684 item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
2685 cell_area.x += cell_area.width + spacing;
2689 if (item->box[info->position].width > item->width)
2691 item->width = item->box[info->position].width;
2692 cell_area.width = item->width;
2694 item->before[info->position] = item->box[info->position].y - cell_area.y;
2695 item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
2696 cell_area.y += cell_area.height + spacing;
2700 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2702 for (i = 0; i < icon_view->priv->n_cells; i++)
2704 item->box[i].x = item->x + item->width -
2705 (item->box[i].x + item->box[i].width - item->x);
2711 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2713 g_list_foreach (icon_view->priv->items,
2714 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2718 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2725 gtk_icon_view_paint_item (GtkIconView *icon_view,
2727 GtkIconViewItem *item,
2729 GdkDrawable *drawable,
2732 gboolean draw_focus)
2734 gint focus_width, focus_pad;
2735 gint spacing, padding;
2736 GdkRectangle cell_area, box;
2741 GtkCellRendererState flags;
2743 if (icon_view->priv->model == NULL)
2746 gtk_icon_view_set_cell_data (icon_view, item);
2748 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2750 gtk_widget_style_get (GTK_WIDGET (icon_view),
2751 "focus-line-width", &focus_width,
2752 "focus-padding", &focus_pad,
2755 spacing = icon_view->priv->spacing;
2756 padding = focus_width;
2760 flags = GTK_CELL_RENDERER_SELECTED;
2761 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2762 state = GTK_STATE_SELECTED;
2764 state = GTK_STATE_ACTIVE;
2769 state = GTK_STATE_NORMAL;
2772 #ifdef DEBUG_ICON_VIEW
2773 gdk_draw_rectangle (drawable,
2774 GTK_WIDGET (icon_view)->style->black_gc,
2777 item->width, item->height);
2781 for (l = icon_view->priv->cell_list; l; l = l->next)
2783 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2785 if (!info->cell->visible)
2788 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2790 /* FIXME we hardwire background drawing behind text
2791 * cell renderers here
2793 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
2795 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
2796 cairo_rectangle (cr,
2797 x - item->x + box.x,
2798 y - item->y + box.y,
2799 box.width, box.height);
2804 for (l = icon_view->priv->cell_list; l; l = l->next)
2806 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2808 if (!info->cell->visible)
2811 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
2813 #ifdef DEBUG_ICON_VIEW
2814 gdk_draw_rectangle (drawable,
2815 GTK_WIDGET (icon_view)->style->black_gc,
2817 x - item->x + cell_area.x,
2818 y - item->y + cell_area.y,
2819 cell_area.width, cell_area.height);
2821 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2823 gdk_draw_rectangle (drawable,
2824 GTK_WIDGET (icon_view)->style->black_gc,
2826 x - item->x + box.x,
2827 y - item->y + box.y,
2828 box.width, box.height);
2831 cell_area.x = x - item->x + cell_area.x;
2832 cell_area.y = y - item->y + cell_area.y;
2834 gtk_cell_renderer_render (info->cell,
2836 GTK_WIDGET (icon_view),
2837 &cell_area, &cell_area, area, flags);
2841 /* FIXME where to draw the focus with generic cell renderers ? */
2843 GTK_WIDGET_HAS_FOCUS (icon_view) &&
2844 item == icon_view->priv->cursor_item)
2845 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2847 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2849 if (!info->cell->visible)
2852 if (icon_view->priv->cursor_cell < 0 &&
2853 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
2854 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
2855 icon_view->priv->cursor_cell = i;
2857 if (i == icon_view->priv->cursor_cell)
2859 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2861 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
2865 GTK_WIDGET (icon_view),
2867 x - item->x + box.x - padding,
2868 y - item->y + box.y - padding,
2869 box.width + 2 * padding,
2870 box.height + 2 * padding);
2877 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2882 GdkRectangle rubber_rect;
2883 GdkColor *fill_color_gdk;
2884 guchar fill_color_alpha;
2886 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2887 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2888 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2889 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2891 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
2894 gtk_widget_style_get (GTK_WIDGET (icon_view),
2895 "selection-box-color", &fill_color_gdk,
2896 "selection-box-alpha", &fill_color_alpha,
2899 if (!fill_color_gdk)
2900 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
2902 cairo_set_source_rgba (cr,
2903 fill_color_gdk->red / 65535.,
2904 fill_color_gdk->green / 65535.,
2905 fill_color_gdk->blue / 65535.,
2906 fill_color_alpha / 255.);
2909 gdk_cairo_rectangle (cr, &rect);
2913 /* Draw the border without alpha */
2914 cairo_set_source_rgb (cr,
2915 fill_color_gdk->red / 65535.,
2916 fill_color_gdk->green / 65535.,
2917 fill_color_gdk->blue / 65535.);
2918 cairo_rectangle (cr,
2919 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
2920 rubber_rect.width - 1, rubber_rect.height - 1);
2924 gdk_color_free (fill_color_gdk);
2928 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
2934 index = gtk_tree_path_get_indices (path)[0];
2936 for (l = icon_view->priv->items; l; l = l->next)
2938 GtkIconViewItem *item = l->data;
2940 if (item->index == index)
2942 gtk_icon_view_queue_draw_item (icon_view, item);
2949 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
2950 GtkIconViewItem *item)
2955 gtk_widget_style_get (GTK_WIDGET (icon_view),
2956 "focus-line-width", &focus_width,
2959 rect.x = item->x - focus_width;
2960 rect.y = item->y - focus_width;
2961 rect.width = item->width + 2 * focus_width;
2962 rect.height = item->height + 2 * focus_width;
2964 if (icon_view->priv->bin_window)
2965 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
2969 layout_callback (gpointer user_data)
2971 GtkIconView *icon_view;
2973 GDK_THREADS_ENTER ();
2975 icon_view = GTK_ICON_VIEW (user_data);
2977 icon_view->priv->layout_idle_id = 0;
2979 gtk_icon_view_layout (icon_view);
2981 GDK_THREADS_LEAVE();
2987 gtk_icon_view_queue_layout (GtkIconView *icon_view)
2989 if (icon_view->priv->layout_idle_id != 0)
2992 icon_view->priv->layout_idle_id = g_idle_add (layout_callback, icon_view);
2996 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
2997 GtkIconViewItem *item,
3001 AtkObject *item_obj;
3003 if (icon_view->priv->cursor_item == item &&
3004 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3007 if (icon_view->priv->cursor_item != NULL)
3008 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3010 icon_view->priv->cursor_item = item;
3011 if (cursor_cell >= 0)
3012 icon_view->priv->cursor_cell = cursor_cell;
3014 gtk_icon_view_queue_draw_item (icon_view, item);
3016 /* Notify that accessible focus object has changed */
3017 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3018 item_obj = atk_object_ref_accessible_child (obj, item->index);
3020 if (item_obj != NULL)
3022 atk_focus_tracker_notify (item_obj);
3023 g_object_unref (item_obj);
3028 static GtkIconViewItem *
3029 gtk_icon_view_item_new (void)
3031 GtkIconViewItem *item;
3033 item = g_new0 (GtkIconViewItem, 1);
3042 gtk_icon_view_item_free (GtkIconViewItem *item)
3044 g_return_if_fail (item != NULL);
3046 g_free (item->before);
3047 g_free (item->after);
3054 static GtkIconViewItem *
3055 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3058 gboolean only_in_cell,
3059 GtkIconViewCellInfo **cell_at_pos)
3064 for (items = icon_view->priv->items; items; items = items->next)
3066 GtkIconViewItem *item = items->data;
3068 if (x >= item->x - icon_view->priv->row_spacing/2 && x <= item->x + item->width + icon_view->priv->row_spacing/2 &&
3069 y >= item->y - icon_view->priv->column_spacing/2 && y <= item->y + item->height + icon_view->priv->column_spacing/2)
3071 if (only_in_cell || cell_at_pos)
3073 gtk_icon_view_set_cell_data (icon_view, item);
3075 for (l = icon_view->priv->cell_list; l; l = l->next)
3077 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3079 if (!info->cell->visible)
3082 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3084 if ((x >= box.x && x <= box.x + box.width &&
3085 y >= box.y && y <= box.y + box.height) ||
3087 x <= box.x + box.width &&
3089 y <= box.y + box.height))
3092 *cell_at_pos = info;
3102 *cell_at_pos = NULL;
3113 gtk_icon_view_select_item (GtkIconView *icon_view,
3114 GtkIconViewItem *item)
3116 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3117 g_return_if_fail (item != NULL);
3122 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3124 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3125 gtk_icon_view_unselect_all_internal (icon_view);
3127 item->selected = TRUE;
3129 gtk_icon_view_queue_draw_item (icon_view, item);
3131 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3136 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3137 GtkIconViewItem *item)
3139 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3140 g_return_if_fail (item != NULL);
3142 if (!item->selected)
3145 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3146 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3149 item->selected = FALSE;
3151 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3153 gtk_icon_view_queue_draw_item (icon_view, item);
3157 verify_items (GtkIconView *icon_view)
3162 for (items = icon_view->priv->items; items; items = items->next)
3164 GtkIconViewItem *item = items->data;
3166 if (item->index != i)
3167 g_error ("List item does not match its index: "
3168 "item index %d and list index %d\n", item->index, i);
3175 gtk_icon_view_row_changed (GtkTreeModel *model,
3180 GtkIconViewItem *item;
3182 GtkIconView *icon_view;
3184 icon_view = GTK_ICON_VIEW (data);
3186 gtk_icon_view_stop_editing (icon_view, TRUE);
3188 index = gtk_tree_path_get_indices(path)[0];
3189 item = g_list_nth_data (icon_view->priv->items, index);
3191 gtk_icon_view_item_invalidate_size (item);
3192 gtk_icon_view_queue_layout (icon_view);
3194 verify_items (icon_view);
3198 gtk_icon_view_row_inserted (GtkTreeModel *model,
3204 GtkIconViewItem *item;
3205 gboolean iters_persist;
3206 GtkIconView *icon_view;
3209 icon_view = GTK_ICON_VIEW (data);
3211 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3213 length = gtk_tree_model_iter_n_children (model, NULL);
3214 index = gtk_tree_path_get_indices(path)[0];
3216 item = gtk_icon_view_item_new ();
3221 item->index = index;
3223 /* FIXME: We can be more efficient here,
3224 we can store a tail pointer and use that when
3225 appending (which is a rather common operation)
3227 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3230 list = g_list_nth (icon_view->priv->items, index + 1);
3231 for (; list; list = list->next)
3238 verify_items (icon_view);
3242 gtk_icon_view_row_deleted (GtkTreeModel *model,
3247 GtkIconView *icon_view;
3248 GtkIconViewItem *item;
3250 gboolean emit = FALSE;
3252 icon_view = GTK_ICON_VIEW (data);
3254 index = gtk_tree_path_get_indices(path)[0];
3256 list = g_list_nth (icon_view->priv->items, index);
3259 gtk_icon_view_stop_editing (icon_view, TRUE);
3261 if (item == icon_view->priv->anchor_item)
3262 icon_view->priv->anchor_item = NULL;
3264 if (item == icon_view->priv->cursor_item)
3265 icon_view->priv->cursor_item = NULL;
3270 gtk_icon_view_item_free (item);
3272 for (next = list->next; next; next = next->next)
3279 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3281 gtk_icon_view_queue_layout (icon_view);
3283 verify_items (icon_view);
3286 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3290 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3291 GtkTreePath *parent,
3298 GtkIconView *icon_view;
3299 GList *items = NULL, *list;
3300 GtkIconViewItem **item_array;
3303 icon_view = GTK_ICON_VIEW (data);
3305 gtk_icon_view_stop_editing (icon_view, TRUE);
3307 length = gtk_tree_model_iter_n_children (model, NULL);
3309 order = g_new (gint, length);
3310 for (i = 0; i < length; i++)
3311 order [new_order[i]] = i;
3313 item_array = g_new (GtkIconViewItem *, length);
3314 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3315 item_array[order[i]] = list->data;
3318 for (i = length - 1; i >= 0; i--)
3320 item_array[i]->index = i;
3321 items = g_list_prepend (items, item_array[i]);
3324 g_free (item_array);
3325 g_list_free (icon_view->priv->items);
3326 icon_view->priv->items = items;
3328 gtk_icon_view_queue_layout (icon_view);
3330 verify_items (icon_view);
3334 gtk_icon_view_build_items (GtkIconView *icon_view)
3338 gboolean iters_persist;
3339 GList *items = NULL;
3341 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3343 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3351 GtkIconViewItem *item = gtk_icon_view_item_new ();
3360 items = g_list_prepend (items, item);
3362 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3364 icon_view->priv->items = g_list_reverse (items);
3368 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3371 GtkMovementStep step,
3375 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3380 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3385 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3388 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3393 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3400 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3401 GtkMovementStep step,
3404 GdkModifierType state;
3406 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3407 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3408 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3409 step == GTK_MOVEMENT_DISPLAY_LINES ||
3410 step == GTK_MOVEMENT_PAGES ||
3411 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3413 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3416 gtk_icon_view_stop_editing (icon_view, FALSE);
3417 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3419 if (gtk_get_current_event_state (&state))
3421 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3422 icon_view->priv->ctrl_pressed = TRUE;
3423 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3424 icon_view->priv->shift_pressed = TRUE;
3426 /* else we assume not pressed */
3430 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3431 case GTK_MOVEMENT_VISUAL_POSITIONS:
3432 gtk_icon_view_move_cursor_left_right (icon_view, count);
3434 case GTK_MOVEMENT_DISPLAY_LINES:
3435 gtk_icon_view_move_cursor_up_down (icon_view, count);
3437 case GTK_MOVEMENT_PAGES:
3438 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3440 case GTK_MOVEMENT_BUFFER_ENDS:
3441 gtk_icon_view_move_cursor_start_end (icon_view, count);
3444 g_assert_not_reached ();
3447 icon_view->priv->ctrl_pressed = FALSE;
3448 icon_view->priv->shift_pressed = FALSE;
3453 static GtkIconViewItem *
3454 find_item (GtkIconView *icon_view,
3455 GtkIconViewItem *current,
3461 GtkIconViewItem *item;
3463 /* FIXME: this could be more efficient
3465 row = current->row + row_ofs;
3466 col = current->col + col_ofs;
3468 for (items = icon_view->priv->items; items; items = items->next)
3471 if (item->row == row && item->col == col)
3479 find_cell (GtkIconView *icon_view,
3480 GtkIconViewItem *item,
3482 GtkOrientation orientation,
3493 if (icon_view->priv->orientation != orientation)
3496 gtk_icon_view_set_cell_data (icon_view, item);
3498 focusable = g_new0 (gint, icon_view->priv->n_cells);
3503 for (k = 0; k < 2; k++)
3504 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3506 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3508 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3511 if (!info->cell->visible)
3514 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3517 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3520 current = n_focusable;
3522 focusable[n_focusable] = i;
3528 if (n_focusable == 0)
3529 focusable[n_focusable++] = first_text;
3533 current = step > 0 ? 0 : n_focusable - 1;
3534 cell = focusable[current];
3537 if (current + *count < 0)
3540 *count = current + *count;
3542 else if (current + *count > n_focusable - 1)
3545 *count = current + *count - (n_focusable - 1);
3549 cell = focusable[current + *count];
3558 static GtkIconViewItem *
3559 find_item_page_up_down (GtkIconView *icon_view,
3560 GtkIconViewItem *current,
3567 y = current->y + count * icon_view->priv->vadjustment->page_size;
3569 item = g_list_find (icon_view->priv->items, current);
3574 for (next = item->next; next; next = next->next)
3576 if (((GtkIconViewItem *)next->data)->col == col)
3579 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3589 for (next = item->prev; next; next = next->prev)
3591 if (((GtkIconViewItem *)next->data)->col == col)
3594 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3608 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3609 GtkIconViewItem *anchor,
3610 GtkIconViewItem *cursor)
3613 GtkIconViewItem *item;
3614 gint row1, row2, col1, col2;
3615 gboolean dirty = FALSE;
3617 if (anchor->row < cursor->row)
3628 if (anchor->col < cursor->col)
3639 for (items = icon_view->priv->items; items; items = items->next)
3643 if (row1 <= item->row && item->row <= row2 &&
3644 col1 <= item->col && item->col <= col2)
3646 if (!item->selected)
3649 item->selected = TRUE;
3651 gtk_icon_view_queue_draw_item (icon_view, item);
3659 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3662 GtkIconViewItem *item;
3664 gboolean dirty = FALSE;
3667 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3670 if (!icon_view->priv->cursor_item)
3675 list = icon_view->priv->items;
3677 list = g_list_last (icon_view->priv->items);
3679 item = list ? list->data : NULL;
3684 item = icon_view->priv->cursor_item;
3685 cell = icon_view->priv->cursor_cell;
3686 step = count > 0 ? 1 : -1;
3689 cell = find_cell (icon_view, item, cell,
3690 GTK_ORIENTATION_VERTICAL,
3695 item = find_item (icon_view, item, step, 0);
3696 count = count - step;
3703 if (icon_view->priv->ctrl_pressed ||
3704 !icon_view->priv->shift_pressed ||
3705 !icon_view->priv->anchor_item ||
3706 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3707 icon_view->priv->anchor_item = item;
3709 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3711 if (!icon_view->priv->ctrl_pressed &&
3712 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3714 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3715 dirty = gtk_icon_view_select_all_between (icon_view,
3716 icon_view->priv->anchor_item,
3720 gtk_icon_view_scroll_to_item (icon_view, item);
3723 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3727 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3730 GtkIconViewItem *item;
3731 gboolean dirty = FALSE;
3733 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3736 if (!icon_view->priv->cursor_item)
3741 list = icon_view->priv->items;
3743 list = g_list_last (icon_view->priv->items);
3745 item = list ? list->data : NULL;
3748 item = find_item_page_up_down (icon_view,
3749 icon_view->priv->cursor_item,
3755 if (icon_view->priv->ctrl_pressed ||
3756 !icon_view->priv->shift_pressed ||
3757 !icon_view->priv->anchor_item ||
3758 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3759 icon_view->priv->anchor_item = item;
3761 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3763 if (!icon_view->priv->ctrl_pressed &&
3764 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3766 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3767 dirty = gtk_icon_view_select_all_between (icon_view,
3768 icon_view->priv->anchor_item,
3772 gtk_icon_view_scroll_to_item (icon_view, item);
3775 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3779 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3782 GtkIconViewItem *item;
3784 gboolean dirty = FALSE;
3787 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3790 if (!icon_view->priv->cursor_item)
3795 list = icon_view->priv->items;
3797 list = g_list_last (icon_view->priv->items);
3799 item = list ? list->data : NULL;
3803 item = icon_view->priv->cursor_item;
3804 cell = icon_view->priv->cursor_cell;
3805 step = count > 0 ? 1 : -1;
3808 cell = find_cell (icon_view, item, cell,
3809 GTK_ORIENTATION_HORIZONTAL,
3814 item = find_item (icon_view, item, 0, step);
3815 count = count - step;
3822 if (icon_view->priv->ctrl_pressed ||
3823 !icon_view->priv->shift_pressed ||
3824 !icon_view->priv->anchor_item ||
3825 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3826 icon_view->priv->anchor_item = item;
3828 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3830 if (!icon_view->priv->ctrl_pressed &&
3831 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3833 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3834 dirty = gtk_icon_view_select_all_between (icon_view,
3835 icon_view->priv->anchor_item,
3839 gtk_icon_view_scroll_to_item (icon_view, item);
3842 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3846 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3849 GtkIconViewItem *item;
3851 gboolean dirty = FALSE;
3853 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3857 list = icon_view->priv->items;
3859 list = g_list_last (icon_view->priv->items);
3861 item = list ? list->data : NULL;
3866 if (icon_view->priv->ctrl_pressed ||
3867 !icon_view->priv->shift_pressed ||
3868 !icon_view->priv->anchor_item ||
3869 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3870 icon_view->priv->anchor_item = item;
3872 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3874 if (!icon_view->priv->ctrl_pressed &&
3875 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3877 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3878 dirty = gtk_icon_view_select_all_between (icon_view,
3879 icon_view->priv->anchor_item,
3883 gtk_icon_view_scroll_to_item (icon_view, item);
3886 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3890 * gtk_icon_view_scroll_to_path:
3891 * @icon_view: A #GtkIconView.
3892 * @path: The path of the item to move to.
3893 * @use_align: whether to use alignment arguments, or %FALSE.
3894 * @row_align: The vertical alignment of the item specified by @path.
3895 * @col_align: The horizontal alignment of the item specified by @column.
3897 * Moves the alignments of @icon_view to the position specified by @path.
3898 * @row_align determines where the row is placed, and @col_align determines where
3899 * @column is placed. Both are expected to be between 0.0 and 1.0.
3900 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means center.
3902 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3903 * tree does the minimum amount of work to scroll the item onto the screen.
3904 * This means that the item will be scrolled to the edge closest to its current
3905 * position. If the item is currently visible on the screen, nothing is done.
3907 * This function only works if the model is set, and @path is a valid row on the
3908 * model. If the model changes before the @tree_view is realized, the centered
3909 * path will be modified to reflect this change.
3914 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3920 GtkIconViewItem *item;
3922 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3923 g_return_if_fail (path != NULL);
3924 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3925 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3927 item = g_list_nth (icon_view->priv->items,
3928 gtk_tree_path_get_indices(path)[0])->data;
3935 gint x, y, width, height;
3937 gfloat offset, value;
3939 gtk_widget_style_get (GTK_WIDGET (icon_view),
3940 "focus-line-width", &focus_width,
3943 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
3945 offset = y + item->y - focus_width -
3946 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
3947 value = CLAMP (icon_view->priv->vadjustment->value + offset,
3948 icon_view->priv->vadjustment->lower,
3949 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
3950 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
3952 offset = x + item->x - focus_width -
3953 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
3954 value = CLAMP (icon_view->priv->hadjustment->value + offset,
3955 icon_view->priv->hadjustment->lower,
3956 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
3957 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
3959 gtk_adjustment_changed (icon_view->priv->hadjustment);
3960 gtk_adjustment_changed (icon_view->priv->vadjustment);
3963 gtk_icon_view_scroll_to_item (icon_view, item);
3968 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
3969 GtkIconViewItem *item)
3971 gint x, y, width, height;
3974 gtk_widget_style_get (GTK_WIDGET (icon_view),
3975 "focus-line-width", &focus_width,
3978 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
3980 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
3982 if (y + item->y - focus_width < 0)
3983 gtk_adjustment_set_value (icon_view->priv->vadjustment,
3984 icon_view->priv->vadjustment->value + y + item->y - focus_width);
3985 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
3986 gtk_adjustment_set_value (icon_view->priv->vadjustment,
3987 icon_view->priv->vadjustment->value + y + item->y + item->height
3988 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
3990 if (x + item->x - focus_width < 0)
3991 gtk_adjustment_set_value (icon_view->priv->hadjustment,
3992 icon_view->priv->hadjustment->value + x + item->x - focus_width);
3993 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
3994 gtk_adjustment_set_value (icon_view->priv->hadjustment,
3995 icon_view->priv->hadjustment->value + x + item->x + item->width
3996 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
3998 gtk_adjustment_changed (icon_view->priv->hadjustment);
3999 gtk_adjustment_changed (icon_view->priv->vadjustment);
4002 /* GtkCellLayout implementation */
4003 static GtkIconViewCellInfo *
4004 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4005 GtkCellRenderer *renderer)
4009 for (i = icon_view->priv->cell_list; i; i = i->next)
4011 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4013 if (info->cell == renderer)
4021 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4022 GtkIconViewItem *item)
4025 gboolean iters_persist;
4028 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4034 path = gtk_tree_path_new_from_indices (item->index, -1);
4035 gtk_tree_model_get_iter (icon_view->priv->model, &iter, path);
4036 gtk_tree_path_free (path);
4041 for (i = icon_view->priv->cell_list; i; i = i->next)
4044 GtkIconViewCellInfo *info = i->data;
4046 g_object_freeze_notify (G_OBJECT (info->cell));
4048 for (j = info->attributes; j && j->next; j = j->next->next)
4050 gchar *property = j->data;
4051 gint column = GPOINTER_TO_INT (j->next->data);
4052 GValue value = {0, };
4054 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4056 g_object_set_property (G_OBJECT (info->cell),
4058 g_value_unset (&value);
4062 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4064 icon_view->priv->model,
4068 g_object_thaw_notify (G_OBJECT (info->cell));
4071 adjust_wrap_width (icon_view, item);
4075 free_cell_attributes (GtkIconViewCellInfo *info)
4079 list = info->attributes;
4080 while (list && list->next)
4082 g_free (list->data);
4083 list = list->next->next;
4086 g_slist_free (info->attributes);
4087 info->attributes = NULL;
4091 free_cell_info (GtkIconViewCellInfo *info)
4093 free_cell_attributes (info);
4095 g_object_unref (info->cell);
4098 (* info->destroy) (info->func_data);
4104 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4105 GtkCellRenderer *renderer,
4108 GtkIconViewCellInfo *info;
4109 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4111 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4112 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4114 g_object_ref (renderer);
4115 gtk_object_sink (GTK_OBJECT (renderer));
4117 info = g_new0 (GtkIconViewCellInfo, 1);
4118 info->cell = renderer;
4119 info->expand = expand ? TRUE : FALSE;
4120 info->pack = GTK_PACK_START;
4121 info->position = icon_view->priv->n_cells;
4123 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4124 icon_view->priv->n_cells++;
4128 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4129 GtkCellRenderer *renderer,
4132 GtkIconViewCellInfo *info;
4133 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4135 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4136 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4138 g_object_ref (renderer);
4139 gtk_object_sink (GTK_OBJECT (renderer));
4141 info = g_new0 (GtkIconViewCellInfo, 1);
4142 info->cell = renderer;
4143 info->expand = expand ? TRUE : FALSE;
4144 info->pack = GTK_PACK_END;
4145 info->position = icon_view->priv->n_cells;
4147 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4148 icon_view->priv->n_cells++;
4152 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4153 GtkCellRenderer *renderer,
4154 const gchar *attribute,
4157 GtkIconViewCellInfo *info;
4158 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4160 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4161 g_return_if_fail (info != NULL);
4163 info->attributes = g_slist_prepend (info->attributes,
4164 GINT_TO_POINTER (column));
4165 info->attributes = g_slist_prepend (info->attributes,
4166 g_strdup (attribute));
4170 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4172 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4174 while (icon_view->priv->cell_list)
4176 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4177 free_cell_info (info);
4178 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4179 icon_view->priv->cell_list);
4182 icon_view->priv->n_cells = 0;
4186 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4187 GtkCellRenderer *cell,
4188 GtkCellLayoutDataFunc func,
4190 GDestroyNotify destroy)
4192 GtkIconViewCellInfo *info;
4193 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4195 info = gtk_icon_view_get_cell_info (icon_view, cell);
4196 g_return_if_fail (info != NULL);
4200 GDestroyNotify d = info->destroy;
4202 info->destroy = NULL;
4203 d (info->func_data);
4207 info->func_data = func_data;
4208 info->destroy = destroy;
4212 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4213 GtkCellRenderer *renderer)
4215 GtkIconViewCellInfo *info;
4217 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4219 free_cell_attributes (info);
4223 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4224 GtkCellRenderer *cell,
4227 GtkIconView *icon_view;
4229 GtkIconViewCellInfo *info;
4232 icon_view = GTK_ICON_VIEW (layout);
4234 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4236 info = gtk_icon_view_get_cell_info (icon_view, cell);
4238 g_return_if_fail (info != NULL);
4239 g_return_if_fail (position >= 0);
4241 link = g_list_find (icon_view->priv->cell_list, info);
4243 g_return_if_fail (link != NULL);
4245 icon_view->priv->cell_list = g_list_remove_link (icon_view->priv->cell_list,
4247 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4250 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4257 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4264 * gtk_icon_view_new:
4266 * Creates a new #GtkIconView widget
4268 * Return value: A newly created #GtkIconView widget
4273 gtk_icon_view_new (void)
4275 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4279 * gtk_icon_view_new_with_model:
4280 * @model: The model.
4282 * Creates a new #GtkIconView widget with the model @model.
4284 * Return value: A newly created #GtkIconView widget.
4289 gtk_icon_view_new_with_model (GtkTreeModel *model)
4291 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4296 * gtk_icon_view_get_path_at_pos:
4297 * @icon_view: A #GtkIconView.
4298 * @x: The x position to be identified
4299 * @y: The y position to be identified
4301 * Finds the path at the point (@x, @y), relative to widget coordinates.
4302 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4303 * the cell at the specified position.
4305 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4306 * if no icon exists at that position.
4311 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4315 GtkIconViewItem *item;
4318 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4320 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4325 path = gtk_tree_path_new_from_indices (item->index, -1);
4331 * gtk_icon_view_get_item_at_pos:
4332 * @icon_view: A #GtkIconView.
4333 * @x: The x position to be identified
4334 * @y: The y position to be identified
4335 * @path: Return location for the path, or %NULL
4336 * @cell: Return location for the renderer responsible for the cell
4337 * at (@x, @y), or %NULL
4339 * Finds the path at the point (@x, @y), relative to widget coordinates.
4340 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4341 * obtains the cell at the specified position. The returned path should
4342 * be freed with gtk_tree_path_free().
4344 * Return value: %TRUE if an item exists at the specified position
4349 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4353 GtkCellRenderer **cell)
4355 GtkIconViewItem *item;
4356 GtkIconViewCellInfo *info;
4358 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4360 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4365 *path = gtk_tree_path_new_from_indices (item->index, -1);
4378 return (item != NULL);
4383 * gtk_icon_view_get_visible_range:
4384 * @icon_view: A #GtkIconView
4385 * @start_path: Return location for start of region, or %NULL
4386 * @end_path: Return location for end of region, or %NULL
4388 * Sets @start_path and @end_path to be the first and last visible path.
4389 * Note that there may be invisible paths in between.
4391 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4396 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4397 GtkTreePath **start_path,
4398 GtkTreePath **end_path)
4400 gint start_index = -1;
4401 gint end_index = -1;
4402 GtkIconViewItem *item;
4405 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4407 if (icon_view->priv->hadjustment == NULL ||
4408 icon_view->priv->vadjustment == NULL)
4411 if (start_path == NULL && end_path == NULL)
4414 for (icons = icon_view->priv->items; icons; icons = icons->next)
4416 GtkIconViewItem *item = icons->data;
4418 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4419 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4420 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4421 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4423 if (start_index == -1)
4424 start_index = item->index;
4425 end_index = item->index;
4429 if (start_path && start_index != -1)
4430 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4431 if (end_path && end_index != -1)
4432 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4434 return start_index != -1;
4438 * gtk_icon_view_selected_foreach:
4439 * @icon_view: A #GtkIconView.
4440 * @func: The funcion to call for each selected icon.
4441 * @data: User data to pass to the function.
4443 * Calls a function for each selected icon. Note that the model or
4444 * selection cannot be modified from within this function.
4449 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4450 GtkIconViewForeachFunc func,
4455 for (list = icon_view->priv->items; list; list = list->next)
4457 GtkIconViewItem *item = list->data;
4458 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4461 (* func) (icon_view, path, data);
4463 gtk_tree_path_free (path);
4468 * gtk_icon_view_set_selection_mode:
4469 * @icon_view: A #GtkIconView.
4470 * @mode: The selection mode
4472 * Sets the selection mode of the @icon_view.
4477 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4478 GtkSelectionMode mode)
4480 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4482 if (mode == icon_view->priv->selection_mode)
4485 if (mode == GTK_SELECTION_NONE ||
4486 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4487 gtk_icon_view_unselect_all (icon_view);
4489 icon_view->priv->selection_mode = mode;
4491 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4495 * gtk_icon_view_get_selection_mode:
4496 * @icon_view: A #GtkIconView.
4498 * Gets the selection mode of the @icon_view.
4500 * Return value: the current selection mode
4505 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4507 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4509 return icon_view->priv->selection_mode;
4513 * gtk_icon_view_set_model:
4514 * @icon_view: A #GtkIconView.
4515 * @model: The model.
4517 * Sets the model for a #GtkIconView.
4518 * If the @icon_view already has a model set, it will remove
4519 * it before setting the new model. If @model is %NULL, then
4520 * it will unset the old model.
4525 gtk_icon_view_set_model (GtkIconView *icon_view,
4526 GtkTreeModel *model)
4528 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4529 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4531 if (icon_view->priv->model == model)
4534 gtk_icon_view_stop_editing (icon_view, TRUE);
4540 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
4542 if (icon_view->priv->pixbuf_column != -1)
4544 column_type = gtk_tree_model_get_column_type (model,
4545 icon_view->priv->pixbuf_column);
4547 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4550 if (icon_view->priv->text_column != -1)
4552 column_type = gtk_tree_model_get_column_type (model,
4553 icon_view->priv->text_column);
4555 g_return_if_fail (column_type == G_TYPE_STRING);
4558 if (icon_view->priv->markup_column != -1)
4560 column_type = gtk_tree_model_get_column_type (model,
4561 icon_view->priv->markup_column);
4563 g_return_if_fail (column_type == G_TYPE_STRING);
4568 if (icon_view->priv->model)
4570 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4571 gtk_icon_view_row_changed,
4573 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4574 gtk_icon_view_row_inserted,
4576 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4577 gtk_icon_view_row_deleted,
4579 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4580 gtk_icon_view_rows_reordered,
4583 g_object_unref (icon_view->priv->model);
4585 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4586 g_list_free (icon_view->priv->items);
4587 icon_view->priv->items = NULL;
4588 icon_view->priv->anchor_item = NULL;
4589 icon_view->priv->cursor_item = NULL;
4590 icon_view->priv->last_single_clicked = NULL;
4591 icon_view->priv->width = 0;
4592 icon_view->priv->height = 0;
4595 icon_view->priv->model = model;
4597 if (icon_view->priv->model)
4599 g_object_ref (icon_view->priv->model);
4600 g_signal_connect (icon_view->priv->model,
4602 G_CALLBACK (gtk_icon_view_row_changed),
4604 g_signal_connect (icon_view->priv->model,
4606 G_CALLBACK (gtk_icon_view_row_inserted),
4608 g_signal_connect (icon_view->priv->model,
4610 G_CALLBACK (gtk_icon_view_row_deleted),
4612 g_signal_connect (icon_view->priv->model,
4614 G_CALLBACK (gtk_icon_view_rows_reordered),
4617 gtk_icon_view_build_items (icon_view);
4619 gtk_icon_view_queue_layout (icon_view);
4622 g_object_notify (G_OBJECT (icon_view), "model");
4624 if (GTK_WIDGET_REALIZED (icon_view))
4625 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4629 * gtk_icon_view_get_model:
4630 * @icon_view: a #GtkIconView
4632 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4635 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
4640 gtk_icon_view_get_model (GtkIconView *icon_view)
4642 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4644 return icon_view->priv->model;
4648 update_text_cell (GtkIconView *icon_view)
4650 GtkIconViewCellInfo *info;
4654 if (icon_view->priv->text_column == -1 &&
4655 icon_view->priv->markup_column == -1)
4657 if (icon_view->priv->text_cell != -1)
4659 info = g_list_nth_data (icon_view->priv->cell_list,
4660 icon_view->priv->text_cell);
4662 g_list_remove (icon_view->priv->cell_list, info);
4664 free_cell_info (info);
4666 icon_view->priv->n_cells--;
4667 icon_view->priv->text_cell = -1;
4672 if (icon_view->priv->text_cell == -1)
4674 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
4675 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4676 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4679 if (info->cell == cell)
4681 icon_view->priv->text_cell = i;
4687 info = g_list_nth_data (icon_view->priv->cell_list,
4688 icon_view->priv->text_cell);
4690 if (icon_view->priv->markup_column != -1)
4691 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4693 "markup", icon_view->priv->markup_column,
4696 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4698 "text", icon_view->priv->text_column,
4701 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4702 g_object_set (info->cell,
4703 "wrap_mode", PANGO_WRAP_CHAR,
4704 "wrap_width", icon_view->priv->item_width,
4709 g_object_set (info->cell,
4710 "wrap_mode", PANGO_WRAP_CHAR,
4711 "wrap_width", icon_view->priv->item_width,
4719 update_pixbuf_cell (GtkIconView *icon_view)
4721 GtkIconViewCellInfo *info;
4725 if (icon_view->priv->pixbuf_column == -1)
4727 if (icon_view->priv->pixbuf_cell != -1)
4729 info = g_list_nth_data (icon_view->priv->cell_list,
4730 icon_view->priv->pixbuf_cell);
4732 g_list_remove (icon_view->priv->cell_list, info);
4734 free_cell_info (info);
4736 icon_view->priv->n_cells--;
4737 icon_view->priv->pixbuf_cell = -1;
4742 if (icon_view->priv->pixbuf_cell == -1)
4744 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
4746 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4747 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4750 if (info->cell == cell)
4752 icon_view->priv->pixbuf_cell = i;
4758 info = g_list_nth_data (icon_view->priv->cell_list,
4759 icon_view->priv->pixbuf_cell);
4761 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4763 "pixbuf", icon_view->priv->pixbuf_column,
4766 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4767 g_object_set (info->cell,
4768 "follow_state", TRUE,
4773 g_object_set (info->cell,
4774 "follow_state", TRUE,
4782 * gtk_icon_view_set_text_column:
4783 * @icon_view: A #GtkIconView.
4784 * @column: A column in the currently used model.
4786 * Sets the column with text for @icon_view to be @column. The text
4787 * column must be of type #G_TYPE_STRING.
4792 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4795 if (column == icon_view->priv->text_column)
4799 icon_view->priv->text_column = -1;
4802 if (icon_view->priv->model != NULL)
4806 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4808 g_return_if_fail (column_type == G_TYPE_STRING);
4811 icon_view->priv->text_column = column;
4814 gtk_icon_view_stop_editing (icon_view, TRUE);
4816 update_text_cell (icon_view);
4818 gtk_icon_view_invalidate_sizes (icon_view);
4819 gtk_icon_view_queue_layout (icon_view);
4821 g_object_notify (G_OBJECT (icon_view), "text-column");
4825 * gtk_icon_view_get_text_column:
4826 * @icon_view: A #GtkIconView.
4828 * Returns the column with text for @icon_view.
4830 * Returns: the text column, or -1 if it's unset.
4835 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4837 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4839 return icon_view->priv->text_column;
4843 * gtk_icon_view_set_markup_column:
4844 * @icon_view: A #GtkIconView.
4845 * @column: A column in the currently used model.
4847 * Sets the column with markup information for @icon_view to be
4848 * @column. The markup column must be of type #G_TYPE_STRING.
4849 * If the markup column is set to something, it overrides
4850 * the text column set by gtk_icon_view_set_text_column().
4855 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
4858 if (column == icon_view->priv->markup_column)
4862 icon_view->priv->markup_column = -1;
4865 if (icon_view->priv->model != NULL)
4869 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4871 g_return_if_fail (column_type == G_TYPE_STRING);
4874 icon_view->priv->markup_column = column;
4877 gtk_icon_view_stop_editing (icon_view, TRUE);
4879 update_text_cell (icon_view);
4881 gtk_icon_view_invalidate_sizes (icon_view);
4882 gtk_icon_view_queue_layout (icon_view);
4884 g_object_notify (G_OBJECT (icon_view), "markup-column");
4888 * gtk_icon_view_get_markup_column:
4889 * @icon_view: A #GtkIconView.
4891 * Returns the column with markup text for @icon_view.
4893 * Returns: the markup column, or -1 if it's unset.
4898 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
4900 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4902 return icon_view->priv->markup_column;
4906 * gtk_icon_view_set_pixbuf_column:
4907 * @icon_view: A #GtkIconView.
4908 * @column: A column in the currently used model.
4910 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
4911 * column must be of type #GDK_TYPE_PIXBUF
4916 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
4919 if (column == icon_view->priv->pixbuf_column)
4923 icon_view->priv->pixbuf_column = -1;
4926 if (icon_view->priv->model != NULL)
4930 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4932 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4935 icon_view->priv->pixbuf_column = column;
4938 gtk_icon_view_stop_editing (icon_view, TRUE);
4940 update_pixbuf_cell (icon_view);
4942 gtk_icon_view_invalidate_sizes (icon_view);
4943 gtk_icon_view_queue_layout (icon_view);
4945 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
4950 * gtk_icon_view_get_pixbuf_column:
4951 * @icon_view: A #GtkIconView.
4953 * Returns the column with pixbufs for @icon_view.
4955 * Returns: the pixbuf column, or -1 if it's unset.
4960 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
4962 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4964 return icon_view->priv->pixbuf_column;
4968 * gtk_icon_view_select_path:
4969 * @icon_view: A #GtkIconView.
4970 * @path: The #GtkTreePath to be selected.
4972 * Selects the row at @path.
4977 gtk_icon_view_select_path (GtkIconView *icon_view,
4982 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4983 g_return_if_fail (icon_view->priv->model != NULL);
4984 g_return_if_fail (path != NULL);
4986 l = g_list_nth (icon_view->priv->items,
4987 gtk_tree_path_get_indices(path)[0]);
4990 gtk_icon_view_select_item (icon_view, l->data);
4994 * gtk_icon_view_unselect_path:
4995 * @icon_view: A #GtkIconView.
4996 * @path: The #GtkTreePath to be unselected.
4998 * Unselects the row at @path.
5003 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5006 GtkIconViewItem *item;
5008 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5009 g_return_if_fail (icon_view->priv->model != NULL);
5010 g_return_if_fail (path != NULL);
5012 item = g_list_nth (icon_view->priv->items,
5013 gtk_tree_path_get_indices(path)[0])->data;
5018 gtk_icon_view_unselect_item (icon_view, item);
5022 * gtk_icon_view_get_selected_items:
5023 * @icon_view: A #GtkIconView.
5025 * Creates a list of paths of all selected items. Additionally, if you are
5026 * planning on modifying the model after calling this function, you may
5027 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5028 * To do this, you can use gtk_tree_row_reference_new().
5030 * To free the return value, use:
5031 * <informalexample><programlisting>
5032 * g_list_foreach (list, gtk_tree_path_free, NULL);
5033 * g_list_free (list);
5034 * </programlisting></informalexample>
5036 * Return value: A #GList containing a #GtkTreePath for each selected row.
5041 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5044 GList *selected = NULL;
5046 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5048 for (list = icon_view->priv->items; list != NULL; list = list->next)
5050 GtkIconViewItem *item = list->data;
5054 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5056 selected = g_list_prepend (selected, path);
5064 * gtk_icon_view_select_all:
5065 * @icon_view: A #GtkIconView.
5067 * Selects all the icons. @icon_view must has its selection mode set
5068 * to #GTK_SELECTION_MULTIPLE.
5073 gtk_icon_view_select_all (GtkIconView *icon_view)
5076 gboolean dirty = FALSE;
5078 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5080 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5083 for (items = icon_view->priv->items; items; items = items->next)
5085 GtkIconViewItem *item = items->data;
5087 if (!item->selected)
5090 item->selected = TRUE;
5091 gtk_icon_view_queue_draw_item (icon_view, item);
5096 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5100 * gtk_icon_view_unselect_all:
5101 * @icon_view: A #GtkIconView.
5103 * Unselects all the icons.
5108 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5110 gboolean dirty = FALSE;
5112 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5114 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5117 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5120 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5124 * gtk_icon_view_path_is_selected:
5125 * @icon_view: A #GtkIconView.
5126 * @path: A #GtkTreePath to check selection on.
5128 * Returns %TRUE if the icon pointed to by @path is currently
5129 * selected. If @icon does not point to a valid location, %FALSE is returned.
5131 * Return value: %TRUE if @path is selected.
5136 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5139 GtkIconViewItem *item;
5141 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5142 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5143 g_return_val_if_fail (path != NULL, FALSE);
5145 item = g_list_nth (icon_view->priv->items,
5146 gtk_tree_path_get_indices(path)[0])->data;
5151 return item->selected;
5155 * gtk_icon_view_item_activated:
5156 * @icon_view: A #GtkIconView
5157 * @path: The #GtkTreePath to be activated
5159 * Activates the item determined by @path.
5164 gtk_icon_view_item_activated (GtkIconView *icon_view,
5167 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5168 g_return_if_fail (path != NULL);
5170 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5174 * gtk_icon_view_set_orientation:
5175 * @icon_view: a #GtkIconView
5176 * @orientation: the relative position of texts and icons
5178 * Sets the ::orientation property which determines whether the labels
5179 * are drawn beside the icons instead of below.
5184 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5185 GtkOrientation orientation)
5187 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5189 if (icon_view->priv->orientation != orientation)
5191 icon_view->priv->orientation = orientation;
5193 gtk_icon_view_stop_editing (icon_view, TRUE);
5194 gtk_icon_view_invalidate_sizes (icon_view);
5195 gtk_icon_view_queue_layout (icon_view);
5197 update_text_cell (icon_view);
5198 update_pixbuf_cell (icon_view);
5200 g_object_notify (G_OBJECT (icon_view), "orientation");
5205 * gtk_icon_view_get_orientation:
5206 * @icon_view: a #GtkIconView
5208 * Returns the value of the ::orientation property which determines
5209 * whether the labels are drawn beside the icons instead of below.
5211 * Return value: the relative position of texts and icons
5216 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5218 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5219 GTK_ORIENTATION_VERTICAL);
5221 return icon_view->priv->orientation;
5225 * gtk_icon_view_set_columns:
5226 * @icon_view: a #GtkIconView
5227 * @columns: the number of columns
5229 * Sets the ::columns property which determines in how
5230 * many columns the icons are arranged. If @columns is
5231 * -1, the number of columns will be chosen automatically
5232 * to fill the available area.
5237 gtk_icon_view_set_columns (GtkIconView *icon_view,
5240 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5242 if (icon_view->priv->columns != columns)
5244 icon_view->priv->columns = columns;
5246 gtk_icon_view_stop_editing (icon_view, TRUE);
5247 gtk_icon_view_queue_layout (icon_view);
5249 g_object_notify (G_OBJECT (icon_view), "columns");
5254 * gtk_icon_view_get_columns:
5255 * @icon_view: a #GtkIconView
5257 * Returns the value of the ::columns property.
5259 * Return value: the number of columns, or -1
5264 gtk_icon_view_get_columns (GtkIconView *icon_view)
5266 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5268 return icon_view->priv->columns;
5272 * gtk_icon_view_set_item_width:
5273 * @icon_view: a #GtkIconView
5274 * @item_width: the width for each item
5276 * Sets the ::item-width property which specifies the width
5277 * to use for each item. If it is set to -1, the icon view will
5278 * automatically determine a suitable item size.
5283 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5286 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5288 if (icon_view->priv->item_width != item_width)
5290 icon_view->priv->item_width = item_width;
5292 gtk_icon_view_stop_editing (icon_view, TRUE);
5293 gtk_icon_view_invalidate_sizes (icon_view);
5294 gtk_icon_view_queue_layout (icon_view);
5296 update_text_cell (icon_view);
5298 g_object_notify (G_OBJECT (icon_view), "item-width");
5303 * gtk_icon_view_get_item_width:
5304 * @icon_view: a #GtkIconView
5306 * Returns the value of the ::item-width property.
5308 * Return value: the width of a single item, or -1
5313 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5315 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5317 return icon_view->priv->item_width;
5322 * gtk_icon_view_set_spacing:
5323 * @icon_view: a #GtkIconView
5324 * @spacing: the spacing
5326 * Sets the ::spacing property which specifies the space
5327 * which is inserted between the cells (i.e. the icon and
5328 * the text) of an item.
5333 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5336 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5338 if (icon_view->priv->spacing != spacing)
5340 icon_view->priv->spacing = spacing;
5342 gtk_icon_view_stop_editing (icon_view, TRUE);
5343 gtk_icon_view_invalidate_sizes (icon_view);
5344 gtk_icon_view_queue_layout (icon_view);
5346 g_object_notify (G_OBJECT (icon_view), "spacing");
5351 * gtk_icon_view_get_spacing:
5352 * @icon_view: a #GtkIconView
5354 * Returns the value of the ::spacing property.
5356 * Return value: the space between cells
5361 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5363 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5365 return icon_view->priv->spacing;
5369 * gtk_icon_view_set_row_spacing:
5370 * @icon_view: a #GtkIconView
5371 * @row_spacing: the row spacing
5373 * Sets the ::row-spacing property which specifies the space
5374 * which is inserted between the rows of the icon view.
5379 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5382 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5384 if (icon_view->priv->row_spacing != row_spacing)
5386 icon_view->priv->row_spacing = row_spacing;
5388 gtk_icon_view_stop_editing (icon_view, TRUE);
5389 gtk_icon_view_invalidate_sizes (icon_view);
5390 gtk_icon_view_queue_layout (icon_view);
5392 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5397 * gtk_icon_view_get_row_spacing:
5398 * @icon_view: a #GtkIconView
5400 * Returns the value of the ::row-spacing property.
5402 * Return value: the space between rows
5407 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5409 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5411 return icon_view->priv->row_spacing;
5415 * gtk_icon_view_set_column_spacing:
5416 * @icon_view: a #GtkIconView
5417 * @column_spacing: the column spacing
5419 * Sets the ::column-spacing property which specifies the space
5420 * which is inserted between the columns of the icon view.
5425 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5426 gint column_spacing)
5428 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5430 if (icon_view->priv->column_spacing != column_spacing)
5432 icon_view->priv->column_spacing = column_spacing;
5434 gtk_icon_view_stop_editing (icon_view, TRUE);
5435 gtk_icon_view_invalidate_sizes (icon_view);
5436 gtk_icon_view_queue_layout (icon_view);
5438 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5443 * gtk_icon_view_get_column_spacing:
5444 * @icon_view: a #GtkIconView
5446 * Returns the value of the ::column-spacing property.
5448 * Return value: the space between columns
5453 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5455 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5457 return icon_view->priv->column_spacing;
5461 * gtk_icon_view_set_margin:
5462 * @icon_view: a #GtkIconView
5463 * @margin: the margin
5465 * Sets the ::margin property which specifies the space
5466 * which is inserted at the top, bottom, left and right
5472 gtk_icon_view_set_margin (GtkIconView *icon_view,
5475 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5477 if (icon_view->priv->margin != margin)
5479 icon_view->priv->margin = margin;
5481 gtk_icon_view_stop_editing (icon_view, TRUE);
5482 gtk_icon_view_invalidate_sizes (icon_view);
5483 gtk_icon_view_queue_layout (icon_view);
5485 g_object_notify (G_OBJECT (icon_view), "margin");
5490 * gtk_icon_view_get_margin:
5491 * @icon_view: a #GtkIconView
5493 * Returns the value of the ::margin property.
5495 * Return value: the space at the borders
5500 gtk_icon_view_get_margin (GtkIconView *icon_view)
5502 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5504 return icon_view->priv->margin;
5508 /* Get/set whether drag_motion requested the drag data and
5509 * drag_data_received should thus not actually insert the data,
5510 * since the data doesn't result from a drop.
5513 set_status_pending (GdkDragContext *context,
5514 GdkDragAction suggested_action)
5516 g_object_set_data (G_OBJECT (context),
5517 "gtk-icon-view-status-pending",
5518 GINT_TO_POINTER (suggested_action));
5521 static GdkDragAction
5522 get_status_pending (GdkDragContext *context)
5524 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5525 "gtk-icon-view-status-pending"));
5529 unset_reorderable (GtkIconView *icon_view)
5531 if (icon_view->priv->reorderable)
5533 icon_view->priv->reorderable = FALSE;
5534 g_object_notify (G_OBJECT (icon_view), "reorderable");
5539 clear_source_info (GtkIconView *icon_view)
5541 if (icon_view->priv->source_targets)
5542 gtk_target_list_unref (icon_view->priv->source_targets);
5543 icon_view->priv->source_targets = NULL;
5545 icon_view->priv->source_set = FALSE;
5549 clear_dest_info (GtkIconView *icon_view)
5551 if (icon_view->priv->dest_targets)
5552 gtk_target_list_unref (icon_view->priv->dest_targets);
5553 icon_view->priv->dest_targets = NULL;
5555 icon_view->priv->dest_set = FALSE;
5559 set_source_row (GdkDragContext *context,
5560 GtkTreeModel *model,
5561 GtkTreePath *source_row)
5564 g_object_set_data_full (G_OBJECT (context),
5565 "gtk-icon-view-source-row",
5566 gtk_tree_row_reference_new (model, source_row),
5567 (GDestroyNotify) gtk_tree_row_reference_free);
5569 g_object_set_data_full (G_OBJECT (context),
5570 "gtk-icon-view-source-row",
5575 get_source_row (GdkDragContext *context)
5577 GtkTreeRowReference *ref;
5579 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5582 return gtk_tree_row_reference_get_path (ref);
5589 GtkTreeRowReference *dest_row;
5590 gboolean empty_view_drop;
5591 gboolean drop_append_mode;
5595 dest_row_free (gpointer data)
5597 DestRow *dr = (DestRow *)data;
5599 gtk_tree_row_reference_free (dr->dest_row);
5604 set_dest_row (GdkDragContext *context,
5605 GtkTreeModel *model,
5606 GtkTreePath *dest_row,
5607 gboolean empty_view_drop,
5608 gboolean drop_append_mode)
5614 g_object_set_data_full (G_OBJECT (context),
5615 "gtk-icon-view-dest-row",
5620 dr = g_new0 (DestRow, 1);
5622 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5623 dr->empty_view_drop = empty_view_drop;
5624 dr->drop_append_mode = drop_append_mode;
5625 g_object_set_data_full (G_OBJECT (context),
5626 "gtk-icon-view-dest-row",
5627 dr, (GDestroyNotify) dest_row_free);
5631 get_dest_row (GdkDragContext *context)
5635 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5639 GtkTreePath *path = NULL;
5642 path = gtk_tree_row_reference_get_path (dr->dest_row);
5643 else if (dr->empty_view_drop)
5644 path = gtk_tree_path_new_from_indices (0, -1);
5648 if (path && dr->drop_append_mode)
5649 gtk_tree_path_next (path);
5658 check_model_dnd (GtkTreeModel *model,
5659 GType required_iface,
5660 const gchar *signal)
5662 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5664 g_warning ("You must override the default '%s' handler "
5665 "on GtkIconView when using models that don't support "
5666 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5667 "is to connect to '%s' and call "
5668 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5669 "the default handler from running. Look at the source code "
5670 "for the default handler in gtkiconview.c to get an idea what "
5671 "your handler should do. (gtkiconview.c is in the GTK+ source "
5672 "code.) If you're using GTK+ from a language other than C, "
5673 "there may be a more natural way to override default handlers, e.g. via derivation.",
5674 signal, g_type_name (required_iface), signal);
5682 remove_scroll_timeout (GtkIconView *icon_view)
5684 if (icon_view->priv->scroll_timeout_id != 0)
5686 g_source_remove (icon_view->priv->scroll_timeout_id);
5688 icon_view->priv->scroll_timeout_id = 0;
5693 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5695 gint px, py, x, y, width, height;
5696 gint hoffset, voffset;
5699 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
5700 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
5702 /* see if we are near the edge. */
5703 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5705 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5707 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5709 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5713 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
5714 icon_view->priv->vadjustment->lower,
5715 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
5716 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
5720 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
5721 icon_view->priv->hadjustment->lower,
5722 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
5723 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
5729 drag_scroll_timeout (gpointer data)
5731 GtkIconView *icon_view = GTK_ICON_VIEW (data);
5733 GDK_THREADS_ENTER ();
5735 gtk_icon_view_autoscroll (icon_view);
5737 GDK_THREADS_LEAVE ();
5744 set_destination (GtkIconView *icon_view,
5745 GdkDragContext *context,
5748 GdkDragAction *suggested_action,
5752 GtkTreePath *path = NULL;
5753 GtkIconViewDropPosition pos;
5754 GtkIconViewDropPosition old_pos;
5755 GtkTreePath *old_dest_path = NULL;
5756 gboolean can_drop = FALSE;
5758 widget = GTK_WIDGET (icon_view);
5760 *suggested_action = 0;
5763 if (!icon_view->priv->dest_set)
5765 /* someone unset us as a drag dest, note that if
5766 * we return FALSE drag_leave isn't called
5769 gtk_icon_view_set_drag_dest_item (icon_view,
5771 GTK_ICON_VIEW_DROP_LEFT);
5773 remove_scroll_timeout (GTK_ICON_VIEW (widget));
5775 return FALSE; /* no longer a drop site */
5778 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
5779 if (*target == GDK_NONE)
5782 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
5785 GtkTreeModel *model;
5787 /* the row got dropped on empty space, let's setup a special case
5791 gtk_tree_path_free (path);
5793 model = gtk_icon_view_get_model (icon_view);
5795 n_children = gtk_tree_model_iter_n_children (model, NULL);
5798 pos = GTK_ICON_VIEW_DROP_BELOW;
5799 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5803 pos = GTK_ICON_VIEW_DROP_ABOVE;
5804 path = gtk_tree_path_new_from_indices (0, -1);
5814 gtk_icon_view_get_drag_dest_item (icon_view,
5819 gtk_tree_path_free (old_dest_path);
5821 if (TRUE /* FIXME if the location droppable predicate */)
5829 GtkWidget *source_widget;
5831 *suggested_action = context->suggested_action;
5832 source_widget = gtk_drag_get_source_widget (context);
5834 if (source_widget == widget)
5836 /* Default to MOVE, unless the user has
5837 * pressed ctrl or shift to affect available actions
5839 if ((context->actions & GDK_ACTION_MOVE) != 0)
5840 *suggested_action = GDK_ACTION_MOVE;
5843 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5848 /* can't drop here */
5849 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5851 GTK_ICON_VIEW_DROP_LEFT);
5855 gtk_tree_path_free (path);
5861 get_logical_destination (GtkIconView *icon_view,
5862 gboolean *drop_append_mode)
5864 /* adjust path to point to the row the drop goes in front of */
5865 GtkTreePath *path = NULL;
5866 GtkIconViewDropPosition pos;
5868 *drop_append_mode = FALSE;
5870 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
5875 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
5876 pos == GTK_ICON_VIEW_DROP_BELOW)
5879 GtkTreeModel *model = icon_view->priv->model;
5881 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5882 !gtk_tree_model_iter_next (model, &iter))
5883 *drop_append_mode = TRUE;
5886 *drop_append_mode = FALSE;
5887 gtk_tree_path_next (path);
5895 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
5896 GdkEventMotion *event)
5898 GdkDragContext *context;
5899 GtkTreePath *path = NULL;
5901 GtkTreeModel *model;
5902 gboolean retval = FALSE;
5904 if (!icon_view->priv->source_set)
5907 if (icon_view->priv->pressed_button < 0)
5910 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
5911 icon_view->priv->press_start_x,
5912 icon_view->priv->press_start_y,
5913 event->x, event->y))
5916 model = gtk_icon_view_get_model (icon_view);
5921 button = icon_view->priv->pressed_button;
5922 icon_view->priv->pressed_button = -1;
5924 path = gtk_icon_view_get_path_at_pos (icon_view,
5925 icon_view->priv->press_start_x,
5926 icon_view->priv->press_start_y);
5931 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
5932 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
5936 /* FIXME Check whether we're a start button, if not return FALSE and
5940 /* Now we can begin the drag */
5944 context = gtk_drag_begin (GTK_WIDGET (icon_view),
5945 icon_view->priv->source_targets,
5946 icon_view->priv->source_actions,
5950 set_source_row (context, model, path);
5954 gtk_tree_path_free (path);
5959 /* Source side drag signals */
5961 gtk_icon_view_drag_begin (GtkWidget *widget,
5962 GdkDragContext *context)
5964 GtkIconView *icon_view;
5965 GtkIconViewItem *item;
5970 icon_view = GTK_ICON_VIEW (widget);
5972 /* if the user uses a custom DnD impl, we don't set the icon here */
5973 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
5976 item = gtk_icon_view_get_item_at_coords (icon_view,
5977 icon_view->priv->press_start_x,
5978 icon_view->priv->press_start_y,
5982 g_return_if_fail (item != NULL);
5984 x = icon_view->priv->press_start_x - item->x + 1;
5985 y = icon_view->priv->press_start_y - item->y + 1;
5987 path = gtk_tree_path_new_from_indices (item->index, -1);
5988 icon = gtk_icon_view_create_drag_icon (icon_view, path);
5989 gtk_tree_path_free (path);
5991 gtk_drag_set_icon_pixmap (context,
5992 gdk_drawable_get_colormap (icon),
5997 g_object_unref (icon);
6001 gtk_icon_view_drag_end (GtkWidget *widget,
6002 GdkDragContext *context)
6008 gtk_icon_view_drag_data_get (GtkWidget *widget,
6009 GdkDragContext *context,
6010 GtkSelectionData *selection_data,
6014 GtkIconView *icon_view;
6015 GtkTreeModel *model;
6016 GtkTreePath *source_row;
6018 icon_view = GTK_ICON_VIEW (widget);
6019 model = gtk_icon_view_get_model (icon_view);
6024 if (!icon_view->priv->dest_set)
6027 source_row = get_source_row (context);
6029 if (source_row == NULL)
6032 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6033 * any model; for DragSource models there are some other targets
6037 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6038 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6043 /* If drag_data_get does nothing, try providing row data. */
6044 if (selection_data->target == gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE))
6045 gtk_tree_set_row_drag_data (selection_data,
6050 gtk_tree_path_free (source_row);
6054 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6055 GdkDragContext *context)
6057 GtkTreeModel *model;
6058 GtkIconView *icon_view;
6059 GtkTreePath *source_row;
6061 icon_view = GTK_ICON_VIEW (widget);
6062 model = gtk_icon_view_get_model (icon_view);
6064 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6067 if (!icon_view->priv->dest_set)
6070 source_row = get_source_row (context);
6072 if (source_row == NULL)
6075 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6078 gtk_tree_path_free (source_row);
6080 set_source_row (context, NULL, NULL);
6083 /* Target side drag signals */
6085 gtk_icon_view_drag_leave (GtkWidget *widget,
6086 GdkDragContext *context,
6089 GtkIconView *icon_view;
6091 icon_view = GTK_ICON_VIEW (widget);
6093 /* unset any highlight row */
6094 gtk_icon_view_set_drag_dest_item (icon_view,
6096 GTK_ICON_VIEW_DROP_LEFT);
6098 remove_scroll_timeout (icon_view);
6102 gtk_icon_view_drag_motion (GtkWidget *widget,
6103 GdkDragContext *context,
6108 GtkTreePath *path = NULL;
6109 GtkTreeModel *model;
6110 GtkIconViewDropPosition pos;
6111 GtkIconView *icon_view;
6112 GdkDragAction suggested_action = 0;
6116 icon_view = GTK_ICON_VIEW (widget);
6118 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6121 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6123 /* we only know this *after* set_desination_row */
6124 model = gtk_icon_view_get_model (icon_view);
6125 empty = icon_view->priv->empty_view_drop;
6127 if (path == NULL && !empty)
6129 /* Can't drop here. */
6130 gdk_drag_status (context, 0, time);
6134 if (icon_view->priv->scroll_timeout_id == 0)
6136 icon_view->priv->scroll_timeout_id =
6137 g_timeout_add (50, drag_scroll_timeout, icon_view);
6140 if (target == gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE))
6142 /* Request data so we can use the source row when
6143 * determining whether to accept the drop
6145 set_status_pending (context, suggested_action);
6146 gtk_drag_get_data (widget, context, target, time);
6150 set_status_pending (context, 0);
6151 gdk_drag_status (context, suggested_action, time);
6156 gtk_tree_path_free (path);
6162 gtk_icon_view_drag_drop (GtkWidget *widget,
6163 GdkDragContext *context,
6168 GtkIconView *icon_view;
6170 GdkDragAction suggested_action = 0;
6171 GdkAtom target = GDK_NONE;
6172 GtkTreeModel *model;
6173 gboolean drop_append_mode;
6175 icon_view = GTK_ICON_VIEW (widget);
6176 model = gtk_icon_view_get_model (icon_view);
6178 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6180 if (!icon_view->priv->dest_set)
6183 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6186 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6189 path = get_logical_destination (icon_view, &drop_append_mode);
6191 if (target != GDK_NONE && path != NULL)
6193 /* in case a motion had requested drag data, change things so we
6194 * treat drag data receives as a drop.
6196 set_status_pending (context, 0);
6197 set_dest_row (context, model, path,
6198 icon_view->priv->empty_view_drop, drop_append_mode);
6202 gtk_tree_path_free (path);
6204 /* Unset this thing */
6205 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6207 if (target != GDK_NONE)
6209 gtk_drag_get_data (widget, context, target, time);
6217 gtk_icon_view_drag_data_received (GtkWidget *widget,
6218 GdkDragContext *context,
6221 GtkSelectionData *selection_data,
6226 gboolean accepted = FALSE;
6227 GtkTreeModel *model;
6228 GtkIconView *icon_view;
6229 GtkTreePath *dest_row;
6230 GdkDragAction suggested_action;
6231 gboolean drop_append_mode;
6233 icon_view = GTK_ICON_VIEW (widget);
6234 model = gtk_icon_view_get_model (icon_view);
6236 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6239 if (!icon_view->priv->dest_set)
6242 suggested_action = get_status_pending (context);
6244 if (suggested_action)
6246 /* We are getting this data due to a request in drag_motion,
6247 * rather than due to a request in drag_drop, so we are just
6248 * supposed to call drag_status, not actually paste in the
6251 path = get_logical_destination (icon_view, &drop_append_mode);
6254 suggested_action = 0;
6256 if (suggested_action)
6258 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6261 suggested_action = 0;
6264 gdk_drag_status (context, suggested_action, time);
6267 gtk_tree_path_free (path);
6269 /* If you can't drop, remove user drop indicator until the next motion */
6270 if (suggested_action == 0)
6271 gtk_icon_view_set_drag_dest_item (icon_view,
6273 GTK_ICON_VIEW_DROP_LEFT);
6278 dest_row = get_dest_row (context);
6280 if (dest_row == NULL)
6283 if (selection_data->length >= 0)
6285 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6291 gtk_drag_finish (context,
6293 (context->action == GDK_ACTION_MOVE),
6296 gtk_tree_path_free (dest_row);
6299 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6302 /* Drag-and-Drop support */
6304 * gtk_icon_view_enable_model_drag_source:
6305 * @icon_view: a #GtkIconTreeView
6306 * @start_button_mask: Mask of allowed buttons to start drag
6307 * @targets: the table of targets that the drag will support
6308 * @n_targets: the number of items in @targets
6309 * @actions: the bitmask of possible actions for a drag from this
6312 * Turns @icon_view into a drag source for automatic DND.
6317 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6318 GdkModifierType start_button_mask,
6319 const GtkTargetEntry *targets,
6321 GdkDragAction actions)
6323 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6325 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6327 clear_source_info (icon_view);
6328 icon_view->priv->start_button_mask = start_button_mask;
6329 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6330 icon_view->priv->source_actions = actions;
6332 icon_view->priv->source_set = TRUE;
6334 unset_reorderable (icon_view);
6338 * gtk_icon_view_enable_model_drag_dest:
6339 * @icon_view: a #GtkIconView
6340 * @targets: the table of targets that the drag will support
6341 * @n_targets: the number of items in @targets
6342 * @actions: the bitmask of possible actions for a drag from this
6345 * Turns @icon_view into a drop destination for automatic DND.
6350 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6351 const GtkTargetEntry *targets,
6353 GdkDragAction actions)
6355 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6357 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6359 clear_dest_info (icon_view);
6361 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6362 icon_view->priv->dest_actions = actions;
6364 icon_view->priv->dest_set = TRUE;
6366 unset_reorderable (icon_view);
6370 * gtk_icon_view_unset_model_drag_source:
6371 * @icon_view: a #GtkIconView
6373 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6378 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6380 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6382 if (icon_view->priv->source_set)
6384 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6385 clear_source_info (icon_view);
6388 unset_reorderable (icon_view);
6392 * gtk_icon_view_unset_model_drag_dest:
6393 * @icon_view: a #GtkIconView
6395 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6400 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6402 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6404 if (icon_view->priv->dest_set)
6406 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6407 clear_dest_info (icon_view);
6410 unset_reorderable (icon_view);
6413 /* These are useful to implement your own custom stuff. */
6415 * gtk_icon_view_set_drag_dest_item:
6416 * @icon_view: a #GtkIconView
6417 * @path: The path of the item to highlight, or %NULL.
6418 * @pos: Specifies whether to drop, relative to the item
6420 * Sets the item that is highlighted for feedback.
6425 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6427 GtkIconViewDropPosition pos)
6429 /* Note; this function is exported to allow a custom DND
6430 * implementation, so it can't touch TreeViewDragInfo
6433 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6435 if (icon_view->priv->dest_item)
6437 GtkTreePath *current_path;
6438 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6439 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6440 icon_view->priv->dest_item = NULL;
6442 gtk_icon_view_queue_draw_path (icon_view, current_path);
6443 gtk_tree_path_free (current_path);
6446 /* special case a drop on an empty model */
6447 icon_view->priv->empty_view_drop = FALSE;
6448 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
6449 && gtk_tree_path_get_depth (path) == 1
6450 && gtk_tree_path_get_indices (path)[0] == 0)
6454 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6457 if (n_children == 0)
6458 icon_view->priv->empty_view_drop = TRUE;
6461 icon_view->priv->dest_pos = pos;
6465 icon_view->priv->dest_item =
6466 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6467 icon_view->priv->model, path);
6469 gtk_icon_view_queue_draw_path (icon_view, path);
6474 * gtk_icon_view_get_drag_dest_item:
6475 * @icon_view: a #GtkIconView
6476 * @path: Return location for the path of the highlighted item, or %NULL.
6477 * @pos: Return location for the drop position, or %NULL
6479 * Gets information about the item that is highlighted for feedback.
6484 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6486 GtkIconViewDropPosition *pos)
6488 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6492 if (icon_view->priv->dest_item)
6493 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6499 *pos = icon_view->priv->dest_pos;
6503 * gtk_icon_view_get_dest_item_at_pos:
6504 * @icon_view: a #GtkIconView
6505 * @drag_x: the position to determine the destination item for
6506 * @drag_y: the position to determine the destination item for
6507 * @path: Return location for the path of the highlighted item, or %NULL.
6508 * @pos: Return location for the drop position, or %NULL
6510 * Determines the destination item for a given position.
6512 * Return value: whether there is an item at the given position.
6517 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6521 GtkIconViewDropPosition *pos)
6523 GtkIconViewItem *item;
6525 /* Note; this function is exported to allow a custom DND
6526 * implementation, so it can't touch TreeViewDragInfo
6529 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6530 g_return_val_if_fail (drag_x >= 0, FALSE);
6531 g_return_val_if_fail (drag_y >= 0, FALSE);
6532 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6538 item = gtk_icon_view_get_item_at_coords (icon_view,
6539 drag_x + icon_view->priv->hadjustment->value,
6540 drag_y + icon_view->priv->vadjustment->value,
6547 *path = gtk_tree_path_new_from_indices (item->index, -1);
6551 if (drag_x < item->x + item->width / 4)
6552 *pos = GTK_ICON_VIEW_DROP_LEFT;
6553 else if (drag_x > item->x + item->width * 3 / 4)
6554 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6555 else if (drag_y < item->y + item->height / 4)
6556 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6557 else if (drag_y > item->y + item->height * 3 / 4)
6558 *pos = GTK_ICON_VIEW_DROP_BELOW;
6560 *pos = GTK_ICON_VIEW_DROP_INTO;
6567 * gtk_icon_view_create_drag_icon:
6568 * @icon_view: a #GtkIconView
6569 * @path: a #GtkTreePath in @icon_view
6571 * Creates a #GdkPixmap representation of the item at @path.
6572 * This image is used for a drag icon.
6574 * Return value: a newly-allocated pixmap of the drag icon.
6579 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6584 GdkPixmap *drawable;
6589 widget = GTK_WIDGET (icon_view);
6591 index = gtk_tree_path_get_indices (path)[0];
6593 for (l = icon_view->priv->items; l; l = l->next)
6595 GtkIconViewItem *item = l->data;
6597 if (index == item->index)
6599 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
6604 cr = gdk_cairo_create (drawable);
6605 cairo_set_line_width (cr, 1.);
6607 gdk_cairo_set_source_color
6608 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
6609 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
6614 area.width = item->width;
6615 area.height = item->height;
6617 gtk_icon_view_paint_item (icon_view, cr, item, &area,
6618 drawable, 1, 1, FALSE);
6620 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6621 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
6634 * gtk_icon_view_get_reorderable:
6635 * @icon_view: a #GtkIconView
6637 * Retrieves whether the user can reorder the list via drag-and-drop.
6638 * See gtk_icon_view_set_reorderable().
6640 * Return value: %TRUE if the list can be reordered.
6645 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6647 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6649 return icon_view->priv->reorderable;
6652 static const GtkTargetEntry item_targets[] = {
6653 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6658 * gtk_icon_view_set_reorderable:
6659 * @icon_view: A #GtkIconView.
6660 * @reorderable: %TRUE, if the list of items can be reordered.
6662 * This function is a convenience function to allow you to reorder models that
6663 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6664 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6665 * the user can reorder the model by dragging and dropping rows. The
6666 * developer can listen to these changes by connecting to the model's
6667 * row_inserted and row_deleted signals.
6669 * This function does not give you any degree of control over the order -- any
6670 * reordering is allowed. If more control is needed, you should probably
6671 * handle drag and drop manually.
6676 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6677 gboolean reorderable)
6679 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6681 reorderable = reorderable != FALSE;
6683 if (icon_view->priv->reorderable == reorderable)
6688 gtk_icon_view_enable_model_drag_source (icon_view,
6691 G_N_ELEMENTS (item_targets),
6693 gtk_icon_view_enable_model_drag_dest (icon_view,
6695 G_N_ELEMENTS (item_targets),
6700 gtk_icon_view_unset_model_drag_source (icon_view);
6701 gtk_icon_view_unset_model_drag_dest (icon_view);
6704 icon_view->priv->reorderable = reorderable;
6706 g_object_notify (G_OBJECT (icon_view), "reorderable");
6710 /* Accessibility Support */
6712 static gpointer accessible_parent_class;
6713 static gpointer accessible_item_parent_class;
6714 static GQuark accessible_private_data_quark = 0;
6716 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6717 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6718 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6720 static GType gtk_icon_view_item_accessible_get_type (void);
6731 GtkIconViewItem *item;
6735 AtkStateSet *state_set;
6739 GtkTextBuffer *text_buffer;
6741 gchar *action_descriptions[LAST_ACTION];
6742 gchar *image_description;
6743 guint action_idle_handler;
6744 } GtkIconViewItemAccessible;
6746 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
6752 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
6757 typedef struct _GtkIconViewItemAccessibleClass
6759 AtkObjectClass parent_class;
6761 } GtkIconViewItemAccessibleClass;
6763 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
6766 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
6768 GtkIconViewItemAccessible *item;
6769 GtkIconView *icon_view;
6772 GDK_THREADS_ENTER ();
6774 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
6775 item->action_idle_handler = 0;
6777 if (item->widget != NULL)
6779 icon_view = GTK_ICON_VIEW (item->widget);
6780 path = gtk_tree_path_new_from_indices (item->item->index, -1);
6781 gtk_icon_view_item_activated (icon_view, path);
6782 gtk_tree_path_free (path);
6785 GDK_THREADS_LEAVE ();
6791 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
6794 GtkIconViewItemAccessible *item;
6795 GtkIconView *icon_view;
6797 if (i < 0 || i >= LAST_ACTION)
6800 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6802 if (!GTK_IS_ICON_VIEW (item->widget))
6805 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6808 icon_view = GTK_ICON_VIEW (item->widget);
6812 case ACTION_ACTIVATE:
6813 if (!item->action_idle_handler)
6814 item->action_idle_handler = g_idle_add (gtk_icon_view_item_accessible_idle_do_action, item);
6817 g_assert_not_reached ();
6825 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
6830 static const gchar *
6831 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
6834 GtkIconViewItemAccessible *item;
6836 if (i < 0 || i >= LAST_ACTION)
6839 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6841 if (item->action_descriptions[i])
6842 return item->action_descriptions[i];
6844 return gtk_icon_view_item_accessible_action_descriptions[i];
6847 static const gchar *
6848 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
6851 if (i < 0 || i >= LAST_ACTION)
6854 return gtk_icon_view_item_accessible_action_names[i];
6858 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
6860 const gchar *description)
6862 GtkIconViewItemAccessible *item;
6864 if (i < 0 || i >= LAST_ACTION)
6867 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6869 if (item->action_descriptions[i])
6870 g_free (item->action_descriptions[i]);
6872 item->action_descriptions[i] = g_strdup (description);
6878 atk_action_item_interface_init (AtkActionIface *iface)
6880 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
6881 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
6882 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
6883 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
6884 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
6887 static const gchar *
6888 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
6890 GtkIconViewItemAccessible *item;
6892 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6894 return item->image_description;
6898 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
6899 const gchar *description)
6901 GtkIconViewItemAccessible *item;
6903 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6905 g_free (item->image_description);
6906 item->image_description = g_strdup (item->image_description);
6912 get_pixbuf_box (GtkIconView *icon_view,
6913 GtkIconViewItem *item,
6918 for (l = icon_view->priv->cell_list; l; l = l->next)
6920 GtkIconViewCellInfo *info = l->data;
6922 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
6924 gtk_icon_view_get_cell_box (icon_view, item, info, box);
6934 get_text (GtkIconView *icon_view,
6935 GtkIconViewItem *item)
6940 for (l = icon_view->priv->cell_list; l; l = l->next)
6942 GtkIconViewCellInfo *info = l->data;
6944 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
6946 g_object_get (info->cell, "text", &text, NULL);
6956 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
6960 GtkIconViewItemAccessible *item;
6963 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6965 if (!GTK_IS_ICON_VIEW (item->widget))
6968 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6971 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
6974 *height = box.height;
6979 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
6982 AtkCoordType coord_type)
6984 GtkIconViewItemAccessible *item;
6987 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6989 if (!GTK_IS_ICON_VIEW (item->widget))
6992 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6995 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
6997 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
6999 *x+= box.x - item->item->x;
7000 *y+= box.y - item->item->y;
7006 atk_image_item_interface_init (AtkImageIface *iface)
7008 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7009 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7010 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7011 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7015 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7019 GtkIconViewItemAccessible *item;
7020 GtkTextIter start, end;
7021 GtkTextBuffer *buffer;
7023 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7025 if (!GTK_IS_ICON_VIEW (item->widget))
7028 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7031 buffer = item->text_buffer;
7032 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7034 gtk_text_buffer_get_end_iter (buffer, &end);
7036 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7038 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7042 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7045 GtkIconViewItemAccessible *item;
7046 GtkTextIter start, end;
7047 GtkTextBuffer *buffer;
7051 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7053 if (!GTK_IS_ICON_VIEW (item->widget))
7056 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7059 buffer = item->text_buffer;
7060 if (offset >= gtk_text_buffer_get_char_count (buffer))
7063 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7065 gtk_text_iter_forward_char (&end);
7066 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7067 unichar = g_utf8_get_char (string);
7074 get_pango_text_offsets (PangoLayout *layout,
7075 GtkTextBuffer *buffer,
7077 AtkTextBoundary boundary_type,
7081 GtkTextIter *start_iter,
7082 GtkTextIter *end_iter)
7084 PangoLayoutIter *iter;
7085 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7086 gint index, start_index, end_index;
7088 gboolean found = FALSE;
7090 text = pango_layout_get_text (layout);
7091 index = g_utf8_offset_to_pointer (text, offset) - text;
7092 iter = pango_layout_get_iter (layout);
7095 line = pango_layout_iter_get_line (iter);
7096 start_index = line->start_index;
7097 end_index = start_index + line->length;
7099 if (index >= start_index && index <= end_index)
7102 * Found line for offset
7108 * We want the previous line
7112 switch (boundary_type)
7114 case ATK_TEXT_BOUNDARY_LINE_START:
7115 end_index = start_index;
7116 start_index = prev_line->start_index;
7118 case ATK_TEXT_BOUNDARY_LINE_END:
7120 start_index = prev_prev_line->start_index +
7121 prev_prev_line->length;
7122 end_index = prev_line->start_index + prev_line->length;
7125 g_assert_not_reached();
7129 start_index = end_index = 0;
7132 switch (boundary_type)
7134 case ATK_TEXT_BOUNDARY_LINE_START:
7135 if (pango_layout_iter_next_line (iter))
7136 end_index = pango_layout_iter_get_line (iter)->start_index;
7138 case ATK_TEXT_BOUNDARY_LINE_END:
7140 start_index = prev_line->start_index +
7144 g_assert_not_reached();
7149 * We want the next line
7151 if (pango_layout_iter_next_line (iter))
7153 line = pango_layout_iter_get_line (iter);
7154 switch (boundary_type)
7156 case ATK_TEXT_BOUNDARY_LINE_START:
7157 start_index = line->start_index;
7158 if (pango_layout_iter_next_line (iter))
7159 end_index = pango_layout_iter_get_line (iter)->start_index;
7161 end_index = start_index + line->length;
7163 case ATK_TEXT_BOUNDARY_LINE_END:
7164 start_index = end_index;
7165 end_index = line->start_index + line->length;
7168 g_assert_not_reached();
7172 start_index = end_index;
7178 prev_prev_line = prev_line;
7181 while (pango_layout_iter_next_line (iter));
7185 start_index = prev_line->start_index + prev_line->length;
7186 end_index = start_index;
7188 pango_layout_iter_free (iter);
7189 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7190 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7192 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7193 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7197 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7199 AtkTextBoundary boundary_type,
7203 GtkIconViewItemAccessible *item;
7204 GtkTextIter start, end;
7205 GtkTextBuffer *buffer;
7206 GtkIconView *icon_view;
7208 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7210 if (!GTK_IS_ICON_VIEW (item->widget))
7213 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7216 buffer = item->text_buffer;
7218 if (!gtk_text_buffer_get_char_count (buffer))
7222 return g_strdup ("");
7224 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7228 switch (boundary_type)
7230 case ATK_TEXT_BOUNDARY_CHAR:
7231 gtk_text_iter_backward_char(&start);
7233 case ATK_TEXT_BOUNDARY_WORD_START:
7234 if (!gtk_text_iter_starts_word (&start))
7235 gtk_text_iter_backward_word_start (&start);
7237 gtk_text_iter_backward_word_start(&start);
7239 case ATK_TEXT_BOUNDARY_WORD_END:
7240 if (gtk_text_iter_inside_word (&start) &&
7241 !gtk_text_iter_starts_word (&start))
7242 gtk_text_iter_backward_word_start (&start);
7243 while (!gtk_text_iter_ends_word (&start))
7245 if (!gtk_text_iter_backward_char (&start))
7249 gtk_text_iter_backward_word_start(&start);
7250 while (!gtk_text_iter_ends_word (&start))
7252 if (!gtk_text_iter_backward_char (&start))
7256 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7257 if (!gtk_text_iter_starts_sentence (&start))
7258 gtk_text_iter_backward_sentence_start (&start);
7260 gtk_text_iter_backward_sentence_start (&start);
7262 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7263 if (gtk_text_iter_inside_sentence (&start) &&
7264 !gtk_text_iter_starts_sentence (&start))
7265 gtk_text_iter_backward_sentence_start (&start);
7266 while (!gtk_text_iter_ends_sentence (&start))
7268 if (!gtk_text_iter_backward_char (&start))
7272 gtk_text_iter_backward_sentence_start (&start);
7273 while (!gtk_text_iter_ends_sentence (&start))
7275 if (!gtk_text_iter_backward_char (&start))
7279 case ATK_TEXT_BOUNDARY_LINE_START:
7280 case ATK_TEXT_BOUNDARY_LINE_END:
7281 icon_view = GTK_ICON_VIEW (item->widget);
7283 /* FIXME we probably have to use GailTextCell to salvage this */
7284 gtk_icon_view_update_item_text (icon_view, item->item);
7285 get_pango_text_offsets (icon_view->priv->layout,
7298 *start_offset = gtk_text_iter_get_offset (&start);
7299 *end_offset = gtk_text_iter_get_offset (&end);
7301 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7305 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7307 AtkTextBoundary boundary_type,
7311 GtkIconViewItemAccessible *item;
7312 GtkTextIter start, end;
7313 GtkTextBuffer *buffer;
7314 GtkIconView *icon_view;
7316 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7318 if (!GTK_IS_ICON_VIEW (item->widget))
7321 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7324 buffer = item->text_buffer;
7326 if (!gtk_text_buffer_get_char_count (buffer))
7330 return g_strdup ("");
7332 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7336 switch (boundary_type)
7338 case ATK_TEXT_BOUNDARY_CHAR:
7339 gtk_text_iter_forward_char (&end);
7341 case ATK_TEXT_BOUNDARY_WORD_START:
7342 if (!gtk_text_iter_starts_word (&start))
7343 gtk_text_iter_backward_word_start (&start);
7344 if (gtk_text_iter_inside_word (&end))
7345 gtk_text_iter_forward_word_end (&end);
7346 while (!gtk_text_iter_starts_word (&end))
7348 if (!gtk_text_iter_forward_char (&end))
7352 case ATK_TEXT_BOUNDARY_WORD_END:
7353 if (gtk_text_iter_inside_word (&start) &&
7354 !gtk_text_iter_starts_word (&start))
7355 gtk_text_iter_backward_word_start (&start);
7356 while (!gtk_text_iter_ends_word (&start))
7358 if (!gtk_text_iter_backward_char (&start))
7361 gtk_text_iter_forward_word_end (&end);
7363 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7364 if (!gtk_text_iter_starts_sentence (&start))
7365 gtk_text_iter_backward_sentence_start (&start);
7366 if (gtk_text_iter_inside_sentence (&end))
7367 gtk_text_iter_forward_sentence_end (&end);
7368 while (!gtk_text_iter_starts_sentence (&end))
7370 if (!gtk_text_iter_forward_char (&end))
7374 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7375 if (gtk_text_iter_inside_sentence (&start) &&
7376 !gtk_text_iter_starts_sentence (&start))
7377 gtk_text_iter_backward_sentence_start (&start);
7378 while (!gtk_text_iter_ends_sentence (&start))
7380 if (!gtk_text_iter_backward_char (&start))
7383 gtk_text_iter_forward_sentence_end (&end);
7385 case ATK_TEXT_BOUNDARY_LINE_START:
7386 case ATK_TEXT_BOUNDARY_LINE_END:
7387 icon_view = GTK_ICON_VIEW (item->widget);
7389 /* FIXME we probably have to use GailTextCell to salvage this */
7390 gtk_icon_view_update_item_text (icon_view, item->item);
7391 get_pango_text_offsets (icon_view->priv->layout,
7405 *start_offset = gtk_text_iter_get_offset (&start);
7406 *end_offset = gtk_text_iter_get_offset (&end);
7408 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7412 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7414 AtkTextBoundary boundary_type,
7418 GtkIconViewItemAccessible *item;
7419 GtkTextIter start, end;
7420 GtkTextBuffer *buffer;
7421 GtkIconView *icon_view;
7423 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7425 if (!GTK_IS_ICON_VIEW (item->widget))
7428 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7431 buffer = item->text_buffer;
7433 if (!gtk_text_buffer_get_char_count (buffer))
7437 return g_strdup ("");
7439 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7443 switch (boundary_type)
7445 case ATK_TEXT_BOUNDARY_CHAR:
7446 gtk_text_iter_forward_char(&start);
7447 gtk_text_iter_forward_chars(&end, 2);
7449 case ATK_TEXT_BOUNDARY_WORD_START:
7450 if (gtk_text_iter_inside_word (&end))
7451 gtk_text_iter_forward_word_end (&end);
7452 while (!gtk_text_iter_starts_word (&end))
7454 if (!gtk_text_iter_forward_char (&end))
7458 if (!gtk_text_iter_is_end (&end))
7460 gtk_text_iter_forward_word_end (&end);
7461 while (!gtk_text_iter_starts_word (&end))
7463 if (!gtk_text_iter_forward_char (&end))
7468 case ATK_TEXT_BOUNDARY_WORD_END:
7469 gtk_text_iter_forward_word_end (&end);
7471 if (!gtk_text_iter_is_end (&end))
7472 gtk_text_iter_forward_word_end (&end);
7474 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7475 if (gtk_text_iter_inside_sentence (&end))
7476 gtk_text_iter_forward_sentence_end (&end);
7477 while (!gtk_text_iter_starts_sentence (&end))
7479 if (!gtk_text_iter_forward_char (&end))
7483 if (!gtk_text_iter_is_end (&end))
7485 gtk_text_iter_forward_sentence_end (&end);
7486 while (!gtk_text_iter_starts_sentence (&end))
7488 if (!gtk_text_iter_forward_char (&end))
7493 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7494 gtk_text_iter_forward_sentence_end (&end);
7496 if (!gtk_text_iter_is_end (&end))
7497 gtk_text_iter_forward_sentence_end (&end);
7499 case ATK_TEXT_BOUNDARY_LINE_START:
7500 case ATK_TEXT_BOUNDARY_LINE_END:
7501 icon_view = GTK_ICON_VIEW (item->widget);
7503 /* FIXME we probably have to use GailTextCell to salvage this */
7504 gtk_icon_view_update_item_text (icon_view, item->item);
7505 get_pango_text_offsets (icon_view->priv->layout,
7517 *start_offset = gtk_text_iter_get_offset (&start);
7518 *end_offset = gtk_text_iter_get_offset (&end);
7520 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7524 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7526 GtkIconViewItemAccessible *item;
7528 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7530 if (!GTK_IS_ICON_VIEW (item->widget))
7533 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7536 return gtk_text_buffer_get_char_count (item->text_buffer);
7540 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7546 AtkCoordType coord_type)
7548 GtkIconViewItemAccessible *item;
7549 GtkIconView *icon_view;
7550 PangoRectangle char_rect;
7551 const gchar *item_text;
7554 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7556 if (!GTK_IS_ICON_VIEW (item->widget))
7559 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7562 icon_view = GTK_ICON_VIEW (item->widget);
7564 /* FIXME we probably have to use GailTextCell to salvage this */
7565 gtk_icon_view_update_item_text (icon_view, item->item);
7566 item_text = pango_layout_get_text (icon_view->priv->layout);
7567 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7568 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7570 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7571 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7572 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7573 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7574 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7575 *width = char_rect.width / PANGO_SCALE;
7576 *height = char_rect.height / PANGO_SCALE;
7581 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7584 AtkCoordType coord_type)
7586 GtkIconViewItemAccessible *item;
7587 GtkIconView *icon_view;
7588 const gchar *item_text;
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 icon_view = GTK_ICON_VIEW (item->widget);
7603 /* FIXME we probably have to use GailTextCell to salvage this */
7604 gtk_icon_view_update_item_text (icon_view, item->item);
7605 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7606 x -= l_x + item->item->layout_x - item->item->x;
7607 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7608 y -= l_y + item->item->layout_y - item->item->y;
7609 item_text = pango_layout_get_text (icon_view->priv->layout);
7610 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7621 offset = g_utf8_strlen (item_text, -1);
7623 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7629 atk_text_item_interface_init (AtkTextIface *iface)
7631 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7632 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7633 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7634 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7635 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7636 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7637 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7638 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7642 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7647 AtkCoordType coord_type)
7649 GtkIconViewItemAccessible *item;
7650 AtkObject *parent_obj;
7653 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7655 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7656 if (!GTK_IS_WIDGET (item->widget))
7659 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7662 *width = item->item->width;
7663 *height = item->item->height;
7664 if (gtk_icon_view_item_accessible_is_showing (item))
7666 parent_obj = gtk_widget_get_accessible (item->widget);
7667 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7668 *x = l_x + item->item->x;
7669 *y = l_y + item->item->y;
7679 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7681 GtkIconViewItemAccessible *item;
7682 GtkWidget *toplevel;
7684 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7686 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7687 if (!GTK_IS_WIDGET (item->widget))
7690 gtk_widget_grab_focus (item->widget);
7691 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
7692 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7693 if (GTK_WIDGET_TOPLEVEL (toplevel))
7694 gtk_window_present (GTK_WINDOW (toplevel));
7700 atk_component_item_interface_init (AtkComponentIface *iface)
7702 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7703 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7707 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7708 AtkStateType state_type,
7709 gboolean emit_signal)
7713 rc = atk_state_set_add_state (item->state_set, state_type);
7715 * The signal should only be generated if the value changed,
7716 * not when the item is set up. So states that are set
7717 * initially should pass FALSE as the emit_signal argument.
7722 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7723 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7724 if (state_type == ATK_STATE_VISIBLE)
7725 g_signal_emit_by_name (item, "visible_data_changed");
7732 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7733 AtkStateType state_type,
7734 gboolean emit_signal)
7736 if (atk_state_set_contains_state (item->state_set, state_type))
7740 rc = atk_state_set_remove_state (item->state_set, state_type);
7742 * The signal should only be generated if the value changed,
7743 * not when the item is set up. So states that are set
7744 * initially should pass FALSE as the emit_signal argument.
7749 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7750 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7751 if (state_type == ATK_STATE_VISIBLE)
7752 g_signal_emit_by_name (item, "visible_data_changed");
7762 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7764 GtkIconView *icon_view;
7765 GdkRectangle visible_rect;
7766 gboolean is_showing;
7769 * An item is considered "SHOWING" if any part of the item is in the
7770 * visible rectangle.
7773 if (!GTK_IS_ICON_VIEW (item->widget))
7776 if (item->item == NULL)
7779 icon_view = GTK_ICON_VIEW (item->widget);
7781 if (icon_view->priv->hadjustment)
7782 visible_rect.x += icon_view->priv->hadjustment->value;
7784 if (icon_view->priv->hadjustment)
7785 visible_rect.y += icon_view->priv->vadjustment->value;
7786 visible_rect.width = item->widget->allocation.width;
7787 visible_rect.height = item->widget->allocation.height;
7789 if (((item->item->x + item->item->width) < visible_rect.x) ||
7790 ((item->item->y + item->item->height) < (visible_rect.y)) ||
7791 (item->item->x > (visible_rect.x + visible_rect.width)) ||
7792 (item->item->y > (visible_rect.y + visible_rect.height)))
7801 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
7802 gboolean emit_signal)
7804 if (gtk_icon_view_item_accessible_is_showing (item))
7805 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
7808 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
7813 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
7817 item->state_set = atk_state_set_new ();
7819 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
7820 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
7821 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
7822 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
7823 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
7825 for (i = 0; i < LAST_ACTION; i++)
7826 item->action_descriptions[i] = NULL;
7828 item->image_description = NULL;
7830 item->action_idle_handler = 0;
7834 gtk_icon_view_item_accessible_finalize (GObject *object)
7836 GtkIconViewItemAccessible *item;
7839 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
7841 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
7844 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
7846 if (item->state_set)
7847 g_object_unref (item->state_set);
7849 if (item->text_buffer)
7850 g_object_unref (item->text_buffer);
7852 for (i = 0; i < LAST_ACTION; i++)
7853 g_free (item->action_descriptions[i]);
7855 g_free (item->image_description);
7857 if (item->action_idle_handler)
7859 g_source_remove (item->action_idle_handler);
7860 item->action_idle_handler = 0;
7863 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
7866 static G_CONST_RETURN gchar*
7867 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
7873 GtkIconViewItemAccessible *item;
7874 GtkTextIter start_iter;
7875 GtkTextIter end_iter;
7877 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7879 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
7880 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
7882 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
7887 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
7889 GtkIconViewItemAccessible *item;
7891 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
7892 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7895 return gtk_widget_get_accessible (item->widget);
7901 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
7903 GtkIconViewItemAccessible *item;
7905 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
7906 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7908 return item->item->index;
7911 static AtkStateSet *
7912 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
7914 GtkIconViewItemAccessible *item;
7915 GtkIconView *icon_view;
7917 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7918 g_return_val_if_fail (item->state_set, NULL);
7923 icon_view = GTK_ICON_VIEW (item->widget);
7924 if (icon_view->priv->cursor_item == item->item)
7925 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
7927 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
7929 return g_object_ref (item->state_set);
7933 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
7935 GObjectClass *gobject_class;
7937 accessible_item_parent_class = g_type_class_peek_parent (klass);
7939 gobject_class = (GObjectClass *)klass;
7941 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
7943 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
7944 klass->get_name = gtk_icon_view_item_accessible_get_name;
7945 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
7946 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
7950 gtk_icon_view_item_accessible_get_type (void)
7952 static GType type = 0;
7956 static const GTypeInfo tinfo =
7958 sizeof (GtkIconViewItemAccessibleClass),
7959 (GBaseInitFunc) NULL, /* base init */
7960 (GBaseFinalizeFunc) NULL, /* base finalize */
7961 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
7962 (GClassFinalizeFunc) NULL, /* class finalize */
7963 NULL, /* class data */
7964 sizeof (GtkIconViewItemAccessible), /* instance size */
7965 0, /* nb preallocs */
7966 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
7967 NULL /* value table */
7970 static const GInterfaceInfo atk_component_info =
7972 (GInterfaceInitFunc) atk_component_item_interface_init,
7973 (GInterfaceFinalizeFunc) NULL,
7976 static const GInterfaceInfo atk_action_info =
7978 (GInterfaceInitFunc) atk_action_item_interface_init,
7979 (GInterfaceFinalizeFunc) NULL,
7982 static const GInterfaceInfo atk_image_info =
7984 (GInterfaceInitFunc) atk_image_item_interface_init,
7985 (GInterfaceFinalizeFunc) NULL,
7988 static const GInterfaceInfo atk_text_info =
7990 (GInterfaceInitFunc) atk_text_item_interface_init,
7991 (GInterfaceFinalizeFunc) NULL,
7995 type = g_type_register_static (ATK_TYPE_OBJECT,
7996 "GtkIconViewItemAccessible", &tinfo, 0);
7997 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
7998 &atk_component_info);
7999 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8001 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8003 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8010 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8011 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8012 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8014 static GType gtk_icon_view_accessible_get_type (void);
8019 } GtkIconViewAccessible;
8025 } GtkIconViewItemAccessibleInfo;
8031 GtkAdjustment *old_hadj;
8032 GtkAdjustment *old_vadj;
8034 GtkTreeModel *model;
8036 } GtkIconViewAccessiblePrivate;
8038 static GtkIconViewAccessiblePrivate *
8039 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8041 return g_object_get_qdata (G_OBJECT (accessible),
8042 accessible_private_data_quark);
8046 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8050 GtkIconViewItemAccessibleInfo *info;
8051 GtkIconViewItemAccessibleInfo *tmp_info;
8052 GtkIconViewAccessiblePrivate *priv;
8055 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8057 info->index = index;
8059 priv = gtk_icon_view_accessible_get_priv (accessible);
8060 items = priv->items;
8063 tmp_info = items->data;
8064 if (tmp_info->index > index)
8066 items = items->next;
8068 priv->items = g_list_insert_before (priv->items, items, info);
8069 priv->old_hadj = NULL;
8070 priv->old_vadj = NULL;
8074 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8076 GtkIconView *icon_view;
8079 widget = GTK_ACCESSIBLE (accessible)->widget;
8083 icon_view = GTK_ICON_VIEW (widget);
8085 return g_list_length (icon_view->priv->items);
8089 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8092 GtkIconViewAccessiblePrivate *priv;
8093 GtkIconViewItemAccessibleInfo *info;
8096 priv = gtk_icon_view_accessible_get_priv (accessible);
8097 items = priv->items;
8102 if (info->index == index)
8104 items = items->next;
8110 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8113 GtkIconView *icon_view;
8117 GtkIconViewItemAccessible *a11y_item;
8119 widget = GTK_ACCESSIBLE (accessible)->widget;
8123 icon_view = GTK_ICON_VIEW (widget);
8124 icons = g_list_nth (icon_view->priv->items, index);
8128 GtkIconViewItem *item = icons->data;
8130 g_return_val_if_fail (item->index == index, NULL);
8131 obj = gtk_icon_view_accessible_find_child (accessible, index);
8134 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8135 gtk_icon_view_item_accessible_info_new (accessible,
8138 obj->role = ATK_ROLE_ICON;
8139 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8140 a11y_item->item = item;
8141 a11y_item->widget = widget;
8142 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8144 gtk_icon_view_set_cell_data (icon_view, item);
8145 gtk_text_buffer_set_text (a11y_item->text_buffer,
8146 get_text (icon_view, item), -1);
8148 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8149 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8157 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8160 GtkIconViewAccessiblePrivate *priv;
8161 GtkIconViewItemAccessibleInfo *info;
8162 GtkIconViewItemAccessible *item;
8165 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8169 gboolean act_on_item;
8171 widget = GTK_ACCESSIBLE (view)->widget;
8175 items = priv->items;
8177 act_on_item = (list == NULL);
8182 info = (GtkIconViewItemAccessibleInfo *)items->data;
8183 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8185 if (act_on_item == FALSE && list == items)
8189 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8191 items = items->next;
8197 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8198 GtkIconView *icon_view)
8201 GtkIconViewAccessible *view;
8204 * The scrollbars have changed
8206 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8207 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8209 gtk_icon_view_accessible_traverse_items (view, NULL);
8213 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8214 GtkAdjustment *hadj,
8215 GtkAdjustment *vadj)
8218 GtkIconViewAccessiblePrivate *priv;
8220 atk_obj = gtk_widget_get_accessible (widget);
8221 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8223 if (priv->old_hadj != hadj)
8227 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8228 (gpointer *)&priv->old_hadj);
8230 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8231 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8234 priv->old_hadj = hadj;
8237 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8238 (gpointer *)&priv->old_hadj);
8239 g_signal_connect (hadj,
8241 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8245 if (priv->old_vadj != vadj)
8249 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8250 (gpointer *)&priv->old_vadj);
8252 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8253 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8256 priv->old_vadj = vadj;
8259 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8260 (gpointer *)&priv->old_vadj);
8261 g_signal_connect (vadj,
8263 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8270 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8277 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8278 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8284 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8289 GtkIconViewAccessiblePrivate *priv;
8290 GtkIconViewItemAccessibleInfo *info;
8291 GtkIconViewAccessible *view;
8292 GtkIconViewItemAccessible *item;
8298 index = gtk_tree_path_get_indices(path)[0];
8299 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8300 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8301 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8303 items = priv->items;
8308 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8309 if (info->index != item->item->index)
8311 if (info->index < index)
8312 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8314 if (tmp_list == NULL)
8317 info->index = item->item->index;
8320 items = items->next;
8322 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8323 g_signal_emit_by_name (atk_obj, "children_changed::add",
8329 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8333 GtkIconViewAccessiblePrivate *priv;
8334 GtkIconViewItemAccessibleInfo *info;
8335 GtkIconViewAccessible *view;
8336 GtkIconViewItemAccessible *item;
8339 GList *deleted_item;
8343 index = gtk_tree_path_get_indices(path)[0];
8344 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8345 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8346 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8348 items = priv->items;
8350 deleted_item = NULL;
8355 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8356 if (info->index == index)
8358 deleted_item = items;
8360 if (info->index != item->item->index)
8362 if (tmp_list == NULL)
8365 info->index = item->item->index;
8368 items = items->next;
8370 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8373 info = deleted_item->data;
8374 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8376 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8380 priv->items = g_list_remove_link (priv->items, deleted_item);
8388 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8389 GtkIconViewItemAccessibleInfo *i2)
8391 return i1->index - i2->index;
8395 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8401 GtkIconViewAccessiblePrivate *priv;
8402 GtkIconViewItemAccessibleInfo *info;
8403 GtkIconViewAccessible *view;
8404 GtkIconView *icon_view;
8405 GtkIconViewItemAccessible *item;
8410 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8411 icon_view = GTK_ICON_VIEW (user_data);
8412 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8413 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8415 items = priv->items;
8420 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8421 info->index = new_order[info->index];
8422 tmp_list = g_list_nth (icon_view->priv->items, info->index);
8423 item->item = tmp_list->data;
8424 items = items->next;
8426 priv->items = g_list_sort (priv->items,
8427 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8433 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8438 obj = G_OBJECT (model);
8439 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8440 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8441 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8442 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8446 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8450 obj = G_OBJECT (icon_view->priv->model);
8451 g_signal_connect_data (obj, "row-changed",
8452 (GCallback) gtk_icon_view_accessible_model_row_changed,
8453 icon_view, NULL, 0);
8454 g_signal_connect_data (obj, "row-inserted",
8455 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8456 icon_view, NULL, G_CONNECT_AFTER);
8457 g_signal_connect_data (obj, "row-deleted",
8458 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8459 icon_view, NULL, G_CONNECT_AFTER);
8460 g_signal_connect_data (obj, "rows-reordered",
8461 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8462 icon_view, NULL, G_CONNECT_AFTER);
8466 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8468 GtkIconViewItemAccessibleInfo *info;
8471 items = priv->items;
8474 info = (GtkIconViewItemAccessibleInfo *) items->data;
8475 g_object_unref (info->item);
8476 g_free (items->data);
8477 items = items->next;
8479 g_list_free (priv->items);
8484 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8487 GtkIconView *icon_view;
8490 GtkIconViewAccessible *view;
8491 GtkIconViewAccessiblePrivate *priv;
8493 if (strcmp (pspec->name, "model") == 0)
8495 widget = GTK_WIDGET (obj);
8496 atk_obj = gtk_widget_get_accessible (widget);
8497 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8498 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8501 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8502 (gpointer *)&priv->model);
8503 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8505 gtk_icon_view_accessible_clear_cache (priv);
8507 icon_view = GTK_ICON_VIEW (obj);
8508 priv->model = icon_view->priv->model;
8509 /* If there is no model the GtkIconView is probably being destroyed */
8512 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8513 gtk_icon_view_accessible_connect_model_signals (icon_view);
8521 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8524 GtkIconViewAccessiblePrivate *priv;
8525 GtkIconView *icon_view;
8527 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8528 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8530 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8531 g_object_set_qdata (G_OBJECT (accessible),
8532 accessible_private_data_quark,
8535 icon_view = GTK_ICON_VIEW (data);
8536 if (icon_view->priv->hadjustment)
8538 priv->old_hadj = icon_view->priv->hadjustment;
8539 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
8540 g_signal_connect (icon_view->priv->hadjustment,
8542 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8545 if (icon_view->priv->vadjustment)
8547 priv->old_vadj = icon_view->priv->vadjustment;
8548 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
8549 g_signal_connect (icon_view->priv->vadjustment,
8551 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8554 g_signal_connect_after (data,
8555 "set_scroll_adjustments",
8556 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
8558 g_signal_connect (data,
8560 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8563 priv->model = icon_view->priv->model;
8566 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8567 gtk_icon_view_accessible_connect_model_signals (icon_view);
8570 accessible->role = ATK_ROLE_LAYERED_PANE;
8574 gtk_icon_view_accessible_finalize (GObject *object)
8576 GtkIconViewAccessiblePrivate *priv;
8578 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8579 gtk_icon_view_accessible_clear_cache (priv);
8583 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8587 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8588 GtkAccessible *accessible)
8591 GtkIconViewAccessiblePrivate *priv;
8593 atk_obj = ATK_OBJECT (accessible);
8594 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8597 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8598 (gpointer *)&priv->old_hadj);
8600 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8601 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8603 priv->old_hadj = NULL;
8607 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8608 (gpointer *)&priv->old_vadj);
8610 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8611 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8613 priv->old_vadj = NULL;
8618 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8620 if (accessible->widget)
8622 g_signal_connect_after (accessible->widget,
8624 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8627 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8631 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8633 GObjectClass *gobject_class;
8634 GtkAccessibleClass *accessible_class;
8636 accessible_parent_class = g_type_class_peek_parent (klass);
8638 gobject_class = (GObjectClass *)klass;
8639 accessible_class = (GtkAccessibleClass *)klass;
8641 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8643 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8644 klass->ref_child = gtk_icon_view_accessible_ref_child;
8645 klass->initialize = gtk_icon_view_accessible_initialize;
8647 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8649 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8653 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8656 AtkCoordType coord_type)
8659 GtkIconView *icon_view;
8660 GtkIconViewItem *item;
8663 widget = GTK_ACCESSIBLE (component)->widget;
8665 /* State is defunct */
8668 icon_view = GTK_ICON_VIEW (widget);
8669 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8670 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8672 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8678 atk_component_interface_init (AtkComponentIface *iface)
8680 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8684 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8688 GtkIconView *icon_view;
8689 GtkIconViewItem *item;
8692 widget = GTK_ACCESSIBLE (selection)->widget;
8696 icon_view = GTK_ICON_VIEW (widget);
8698 l = g_list_nth (icon_view->priv->items, i);
8703 gtk_icon_view_select_item (icon_view, item);
8709 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8712 GtkIconView *icon_view;
8714 widget = GTK_ACCESSIBLE (selection)->widget;
8718 icon_view = GTK_ICON_VIEW (widget);
8719 gtk_icon_view_unselect_all (icon_view);
8725 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8729 GtkIconView *icon_view;
8730 GtkIconViewItem *item;
8733 widget = GTK_ACCESSIBLE (selection)->widget;
8737 icon_view = GTK_ICON_VIEW (widget);
8739 l = icon_view->priv->items;
8746 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8757 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8760 GtkIconView *icon_view;
8761 GtkIconViewItem *item;
8765 widget = GTK_ACCESSIBLE (selection)->widget;
8769 icon_view = GTK_ICON_VIEW (widget);
8771 l = icon_view->priv->items;
8787 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
8791 GtkIconView *icon_view;
8792 GtkIconViewItem *item;
8795 widget = GTK_ACCESSIBLE (selection)->widget;
8799 icon_view = GTK_ICON_VIEW (widget);
8800 l = g_list_nth (icon_view->priv->items, i);
8806 return item->selected;
8810 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
8814 GtkIconView *icon_view;
8815 GtkIconViewItem *item;
8819 widget = GTK_ACCESSIBLE (selection)->widget;
8823 icon_view = GTK_ICON_VIEW (widget);
8824 l = icon_view->priv->items;
8833 gtk_icon_view_unselect_item (icon_view, item);
8845 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
8848 GtkIconView *icon_view;
8850 widget = GTK_ACCESSIBLE (selection)->widget;
8854 icon_view = GTK_ICON_VIEW (widget);
8855 gtk_icon_view_select_all (icon_view);
8860 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
8862 iface->add_selection = gtk_icon_view_accessible_add_selection;
8863 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
8864 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
8865 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
8866 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
8867 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
8868 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
8872 gtk_icon_view_accessible_get_type (void)
8874 static GType type = 0;
8878 static GTypeInfo tinfo =
8881 (GBaseInitFunc) NULL, /* base init */
8882 (GBaseFinalizeFunc) NULL, /* base finalize */
8883 (GClassInitFunc) gtk_icon_view_accessible_class_init,
8884 (GClassFinalizeFunc) NULL, /* class finalize */
8885 NULL, /* class data */
8886 0, /* instance size */
8887 0, /* nb preallocs */
8888 (GInstanceInitFunc) NULL, /* instance init */
8889 NULL /* value table */
8891 static const GInterfaceInfo atk_component_info =
8893 (GInterfaceInitFunc) atk_component_interface_init,
8894 (GInterfaceFinalizeFunc) NULL,
8897 static const GInterfaceInfo atk_selection_info =
8899 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
8900 (GInterfaceFinalizeFunc) NULL,
8905 * Figure out the size of the class and instance
8906 * we are deriving from
8908 AtkObjectFactory *factory;
8911 GType derived_atk_type;
8913 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
8914 factory = atk_registry_get_factory (atk_get_default_registry (),
8916 derived_atk_type = atk_object_factory_get_accessible_type (factory);
8917 g_type_query (derived_atk_type, &query);
8918 tinfo.class_size = query.class_size;
8919 tinfo.instance_size = query.instance_size;
8921 type = g_type_register_static (derived_atk_type,
8922 "GtkIconViewAccessible",
8924 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8925 &atk_component_info);
8926 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
8927 &atk_selection_info);
8933 gtk_icon_view_accessible_new (GObject *obj)
8935 AtkObject *accessible;
8937 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
8939 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
8940 atk_object_initialize (accessible, obj);
8946 gtk_icon_view_accessible_factory_get_accessible_type (void)
8948 return gtk_icon_view_accessible_get_type ();
8952 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
8954 return gtk_icon_view_accessible_new (obj);
8958 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
8960 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
8961 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
8965 gtk_icon_view_accessible_factory_get_type (void)
8967 static GType type = 0;
8971 static const GTypeInfo tinfo =
8973 sizeof (AtkObjectFactoryClass),
8974 NULL, /* base_init */
8975 NULL, /* base_finalize */
8976 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
8977 NULL, /* class_finalize */
8978 NULL, /* class_data */
8979 sizeof (AtkObjectFactory),
8980 0, /* n_preallocs */
8984 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
8985 "GtkIconViewAccessibleFactory",
8993 gtk_icon_view_get_accessible (GtkWidget *widget)
8995 static gboolean first_time = TRUE;
8999 AtkObjectFactory *factory;
9000 AtkRegistry *registry;
9002 GType derived_atk_type;
9005 * Figure out whether accessibility is enabled by looking at the
9006 * type of the accessible object which would be created for
9007 * the parent type of GtkIconView.
9009 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9011 registry = atk_get_default_registry ();
9012 factory = atk_registry_get_factory (registry,
9014 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9015 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9016 atk_registry_set_factory_type (registry,
9018 gtk_icon_view_accessible_factory_get_type ());
9021 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9024 #define __GTK_ICON_VIEW_C__
9025 #include "gtkaliasdef.c"