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 * Both paths should be freed with gtk_tree_path_free() after use.
4393 * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
4398 gtk_icon_view_get_visible_range (GtkIconView *icon_view,
4399 GtkTreePath **start_path,
4400 GtkTreePath **end_path)
4402 gint start_index = -1;
4403 gint end_index = -1;
4404 GtkIconViewItem *item;
4407 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4409 if (icon_view->priv->hadjustment == NULL ||
4410 icon_view->priv->vadjustment == NULL)
4413 if (start_path == NULL && end_path == NULL)
4416 for (icons = icon_view->priv->items; icons; icons = icons->next)
4418 GtkIconViewItem *item = icons->data;
4420 if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
4421 (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
4422 (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
4423 (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
4425 if (start_index == -1)
4426 start_index = item->index;
4427 end_index = item->index;
4431 if (start_path && start_index != -1)
4432 *start_path = gtk_tree_path_new_from_indices (start_index, -1);
4433 if (end_path && end_index != -1)
4434 *end_path = gtk_tree_path_new_from_indices (end_index, -1);
4436 return start_index != -1;
4440 * gtk_icon_view_selected_foreach:
4441 * @icon_view: A #GtkIconView.
4442 * @func: The funcion to call for each selected icon.
4443 * @data: User data to pass to the function.
4445 * Calls a function for each selected icon. Note that the model or
4446 * selection cannot be modified from within this function.
4451 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4452 GtkIconViewForeachFunc func,
4457 for (list = icon_view->priv->items; list; list = list->next)
4459 GtkIconViewItem *item = list->data;
4460 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4463 (* func) (icon_view, path, data);
4465 gtk_tree_path_free (path);
4470 * gtk_icon_view_set_selection_mode:
4471 * @icon_view: A #GtkIconView.
4472 * @mode: The selection mode
4474 * Sets the selection mode of the @icon_view.
4479 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4480 GtkSelectionMode mode)
4482 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4484 if (mode == icon_view->priv->selection_mode)
4487 if (mode == GTK_SELECTION_NONE ||
4488 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4489 gtk_icon_view_unselect_all (icon_view);
4491 icon_view->priv->selection_mode = mode;
4493 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4497 * gtk_icon_view_get_selection_mode:
4498 * @icon_view: A #GtkIconView.
4500 * Gets the selection mode of the @icon_view.
4502 * Return value: the current selection mode
4507 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4509 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4511 return icon_view->priv->selection_mode;
4515 * gtk_icon_view_set_model:
4516 * @icon_view: A #GtkIconView.
4517 * @model: The model.
4519 * Sets the model for a #GtkIconView.
4520 * If the @icon_view already has a model set, it will remove
4521 * it before setting the new model. If @model is %NULL, then
4522 * it will unset the old model.
4527 gtk_icon_view_set_model (GtkIconView *icon_view,
4528 GtkTreeModel *model)
4530 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4531 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4533 if (icon_view->priv->model == model)
4536 gtk_icon_view_stop_editing (icon_view, TRUE);
4542 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
4544 if (icon_view->priv->pixbuf_column != -1)
4546 column_type = gtk_tree_model_get_column_type (model,
4547 icon_view->priv->pixbuf_column);
4549 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4552 if (icon_view->priv->text_column != -1)
4554 column_type = gtk_tree_model_get_column_type (model,
4555 icon_view->priv->text_column);
4557 g_return_if_fail (column_type == G_TYPE_STRING);
4560 if (icon_view->priv->markup_column != -1)
4562 column_type = gtk_tree_model_get_column_type (model,
4563 icon_view->priv->markup_column);
4565 g_return_if_fail (column_type == G_TYPE_STRING);
4570 if (icon_view->priv->model)
4572 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4573 gtk_icon_view_row_changed,
4575 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4576 gtk_icon_view_row_inserted,
4578 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4579 gtk_icon_view_row_deleted,
4581 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4582 gtk_icon_view_rows_reordered,
4585 g_object_unref (icon_view->priv->model);
4587 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4588 g_list_free (icon_view->priv->items);
4589 icon_view->priv->items = NULL;
4590 icon_view->priv->anchor_item = NULL;
4591 icon_view->priv->cursor_item = NULL;
4592 icon_view->priv->last_single_clicked = NULL;
4593 icon_view->priv->width = 0;
4594 icon_view->priv->height = 0;
4597 icon_view->priv->model = model;
4599 if (icon_view->priv->model)
4601 g_object_ref (icon_view->priv->model);
4602 g_signal_connect (icon_view->priv->model,
4604 G_CALLBACK (gtk_icon_view_row_changed),
4606 g_signal_connect (icon_view->priv->model,
4608 G_CALLBACK (gtk_icon_view_row_inserted),
4610 g_signal_connect (icon_view->priv->model,
4612 G_CALLBACK (gtk_icon_view_row_deleted),
4614 g_signal_connect (icon_view->priv->model,
4616 G_CALLBACK (gtk_icon_view_rows_reordered),
4619 gtk_icon_view_build_items (icon_view);
4621 gtk_icon_view_queue_layout (icon_view);
4624 g_object_notify (G_OBJECT (icon_view), "model");
4626 if (GTK_WIDGET_REALIZED (icon_view))
4627 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4631 * gtk_icon_view_get_model:
4632 * @icon_view: a #GtkIconView
4634 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4637 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
4642 gtk_icon_view_get_model (GtkIconView *icon_view)
4644 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4646 return icon_view->priv->model;
4650 update_text_cell (GtkIconView *icon_view)
4652 GtkIconViewCellInfo *info;
4656 if (icon_view->priv->text_column == -1 &&
4657 icon_view->priv->markup_column == -1)
4659 if (icon_view->priv->text_cell != -1)
4661 info = g_list_nth_data (icon_view->priv->cell_list,
4662 icon_view->priv->text_cell);
4664 g_list_remove (icon_view->priv->cell_list, info);
4666 free_cell_info (info);
4668 icon_view->priv->n_cells--;
4669 icon_view->priv->text_cell = -1;
4674 if (icon_view->priv->text_cell == -1)
4676 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
4677 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4678 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4681 if (info->cell == cell)
4683 icon_view->priv->text_cell = i;
4689 info = g_list_nth_data (icon_view->priv->cell_list,
4690 icon_view->priv->text_cell);
4692 if (icon_view->priv->markup_column != -1)
4693 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4695 "markup", icon_view->priv->markup_column,
4698 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4700 "text", icon_view->priv->text_column,
4703 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4704 g_object_set (info->cell,
4705 "wrap_mode", PANGO_WRAP_CHAR,
4706 "wrap_width", icon_view->priv->item_width,
4711 g_object_set (info->cell,
4712 "wrap_mode", PANGO_WRAP_CHAR,
4713 "wrap_width", icon_view->priv->item_width,
4721 update_pixbuf_cell (GtkIconView *icon_view)
4723 GtkIconViewCellInfo *info;
4727 if (icon_view->priv->pixbuf_column == -1)
4729 if (icon_view->priv->pixbuf_cell != -1)
4731 info = g_list_nth_data (icon_view->priv->cell_list,
4732 icon_view->priv->pixbuf_cell);
4734 g_list_remove (icon_view->priv->cell_list, info);
4736 free_cell_info (info);
4738 icon_view->priv->n_cells--;
4739 icon_view->priv->pixbuf_cell = -1;
4744 if (icon_view->priv->pixbuf_cell == -1)
4746 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
4748 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4749 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4752 if (info->cell == cell)
4754 icon_view->priv->pixbuf_cell = i;
4760 info = g_list_nth_data (icon_view->priv->cell_list,
4761 icon_view->priv->pixbuf_cell);
4763 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4765 "pixbuf", icon_view->priv->pixbuf_column,
4768 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4769 g_object_set (info->cell,
4770 "follow_state", TRUE,
4775 g_object_set (info->cell,
4776 "follow_state", TRUE,
4784 * gtk_icon_view_set_text_column:
4785 * @icon_view: A #GtkIconView.
4786 * @column: A column in the currently used model.
4788 * Sets the column with text for @icon_view to be @column. The text
4789 * column must be of type #G_TYPE_STRING.
4794 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4797 if (column == icon_view->priv->text_column)
4801 icon_view->priv->text_column = -1;
4804 if (icon_view->priv->model != NULL)
4808 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4810 g_return_if_fail (column_type == G_TYPE_STRING);
4813 icon_view->priv->text_column = column;
4816 gtk_icon_view_stop_editing (icon_view, TRUE);
4818 update_text_cell (icon_view);
4820 gtk_icon_view_invalidate_sizes (icon_view);
4821 gtk_icon_view_queue_layout (icon_view);
4823 g_object_notify (G_OBJECT (icon_view), "text-column");
4827 * gtk_icon_view_get_text_column:
4828 * @icon_view: A #GtkIconView.
4830 * Returns the column with text for @icon_view.
4832 * Returns: the text column, or -1 if it's unset.
4837 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4839 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4841 return icon_view->priv->text_column;
4845 * gtk_icon_view_set_markup_column:
4846 * @icon_view: A #GtkIconView.
4847 * @column: A column in the currently used model.
4849 * Sets the column with markup information for @icon_view to be
4850 * @column. The markup column must be of type #G_TYPE_STRING.
4851 * If the markup column is set to something, it overrides
4852 * the text column set by gtk_icon_view_set_text_column().
4857 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
4860 if (column == icon_view->priv->markup_column)
4864 icon_view->priv->markup_column = -1;
4867 if (icon_view->priv->model != NULL)
4871 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4873 g_return_if_fail (column_type == G_TYPE_STRING);
4876 icon_view->priv->markup_column = column;
4879 gtk_icon_view_stop_editing (icon_view, TRUE);
4881 update_text_cell (icon_view);
4883 gtk_icon_view_invalidate_sizes (icon_view);
4884 gtk_icon_view_queue_layout (icon_view);
4886 g_object_notify (G_OBJECT (icon_view), "markup-column");
4890 * gtk_icon_view_get_markup_column:
4891 * @icon_view: A #GtkIconView.
4893 * Returns the column with markup text for @icon_view.
4895 * Returns: the markup column, or -1 if it's unset.
4900 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
4902 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4904 return icon_view->priv->markup_column;
4908 * gtk_icon_view_set_pixbuf_column:
4909 * @icon_view: A #GtkIconView.
4910 * @column: A column in the currently used model.
4912 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
4913 * column must be of type #GDK_TYPE_PIXBUF
4918 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
4921 if (column == icon_view->priv->pixbuf_column)
4925 icon_view->priv->pixbuf_column = -1;
4928 if (icon_view->priv->model != NULL)
4932 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4934 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4937 icon_view->priv->pixbuf_column = column;
4940 gtk_icon_view_stop_editing (icon_view, TRUE);
4942 update_pixbuf_cell (icon_view);
4944 gtk_icon_view_invalidate_sizes (icon_view);
4945 gtk_icon_view_queue_layout (icon_view);
4947 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
4952 * gtk_icon_view_get_pixbuf_column:
4953 * @icon_view: A #GtkIconView.
4955 * Returns the column with pixbufs for @icon_view.
4957 * Returns: the pixbuf column, or -1 if it's unset.
4962 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
4964 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4966 return icon_view->priv->pixbuf_column;
4970 * gtk_icon_view_select_path:
4971 * @icon_view: A #GtkIconView.
4972 * @path: The #GtkTreePath to be selected.
4974 * Selects the row at @path.
4979 gtk_icon_view_select_path (GtkIconView *icon_view,
4984 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4985 g_return_if_fail (icon_view->priv->model != NULL);
4986 g_return_if_fail (path != NULL);
4988 l = g_list_nth (icon_view->priv->items,
4989 gtk_tree_path_get_indices(path)[0]);
4992 gtk_icon_view_select_item (icon_view, l->data);
4996 * gtk_icon_view_unselect_path:
4997 * @icon_view: A #GtkIconView.
4998 * @path: The #GtkTreePath to be unselected.
5000 * Unselects the row at @path.
5005 gtk_icon_view_unselect_path (GtkIconView *icon_view,
5008 GtkIconViewItem *item;
5010 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5011 g_return_if_fail (icon_view->priv->model != NULL);
5012 g_return_if_fail (path != NULL);
5014 item = g_list_nth (icon_view->priv->items,
5015 gtk_tree_path_get_indices(path)[0])->data;
5020 gtk_icon_view_unselect_item (icon_view, item);
5024 * gtk_icon_view_get_selected_items:
5025 * @icon_view: A #GtkIconView.
5027 * Creates a list of paths of all selected items. Additionally, if you are
5028 * planning on modifying the model after calling this function, you may
5029 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
5030 * To do this, you can use gtk_tree_row_reference_new().
5032 * To free the return value, use:
5033 * <informalexample><programlisting>
5034 * g_list_foreach (list, gtk_tree_path_free, NULL);
5035 * g_list_free (list);
5036 * </programlisting></informalexample>
5038 * Return value: A #GList containing a #GtkTreePath for each selected row.
5043 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
5046 GList *selected = NULL;
5048 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
5050 for (list = icon_view->priv->items; list != NULL; list = list->next)
5052 GtkIconViewItem *item = list->data;
5056 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
5058 selected = g_list_prepend (selected, path);
5066 * gtk_icon_view_select_all:
5067 * @icon_view: A #GtkIconView.
5069 * Selects all the icons. @icon_view must has its selection mode set
5070 * to #GTK_SELECTION_MULTIPLE.
5075 gtk_icon_view_select_all (GtkIconView *icon_view)
5078 gboolean dirty = FALSE;
5080 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5082 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5085 for (items = icon_view->priv->items; items; items = items->next)
5087 GtkIconViewItem *item = items->data;
5089 if (!item->selected)
5092 item->selected = TRUE;
5093 gtk_icon_view_queue_draw_item (icon_view, item);
5098 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5102 * gtk_icon_view_unselect_all:
5103 * @icon_view: A #GtkIconView.
5105 * Unselects all the icons.
5110 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5112 gboolean dirty = FALSE;
5114 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5116 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5119 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5122 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5126 * gtk_icon_view_path_is_selected:
5127 * @icon_view: A #GtkIconView.
5128 * @path: A #GtkTreePath to check selection on.
5130 * Returns %TRUE if the icon pointed to by @path is currently
5131 * selected. If @icon does not point to a valid location, %FALSE is returned.
5133 * Return value: %TRUE if @path is selected.
5138 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5141 GtkIconViewItem *item;
5143 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5144 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5145 g_return_val_if_fail (path != NULL, FALSE);
5147 item = g_list_nth (icon_view->priv->items,
5148 gtk_tree_path_get_indices(path)[0])->data;
5153 return item->selected;
5157 * gtk_icon_view_item_activated:
5158 * @icon_view: A #GtkIconView
5159 * @path: The #GtkTreePath to be activated
5161 * Activates the item determined by @path.
5166 gtk_icon_view_item_activated (GtkIconView *icon_view,
5169 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5170 g_return_if_fail (path != NULL);
5172 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5176 * gtk_icon_view_set_orientation:
5177 * @icon_view: a #GtkIconView
5178 * @orientation: the relative position of texts and icons
5180 * Sets the ::orientation property which determines whether the labels
5181 * are drawn beside the icons instead of below.
5186 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5187 GtkOrientation orientation)
5189 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5191 if (icon_view->priv->orientation != orientation)
5193 icon_view->priv->orientation = orientation;
5195 gtk_icon_view_stop_editing (icon_view, TRUE);
5196 gtk_icon_view_invalidate_sizes (icon_view);
5197 gtk_icon_view_queue_layout (icon_view);
5199 update_text_cell (icon_view);
5200 update_pixbuf_cell (icon_view);
5202 g_object_notify (G_OBJECT (icon_view), "orientation");
5207 * gtk_icon_view_get_orientation:
5208 * @icon_view: a #GtkIconView
5210 * Returns the value of the ::orientation property which determines
5211 * whether the labels are drawn beside the icons instead of below.
5213 * Return value: the relative position of texts and icons
5218 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5220 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5221 GTK_ORIENTATION_VERTICAL);
5223 return icon_view->priv->orientation;
5227 * gtk_icon_view_set_columns:
5228 * @icon_view: a #GtkIconView
5229 * @columns: the number of columns
5231 * Sets the ::columns property which determines in how
5232 * many columns the icons are arranged. If @columns is
5233 * -1, the number of columns will be chosen automatically
5234 * to fill the available area.
5239 gtk_icon_view_set_columns (GtkIconView *icon_view,
5242 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5244 if (icon_view->priv->columns != columns)
5246 icon_view->priv->columns = columns;
5248 gtk_icon_view_stop_editing (icon_view, TRUE);
5249 gtk_icon_view_queue_layout (icon_view);
5251 g_object_notify (G_OBJECT (icon_view), "columns");
5256 * gtk_icon_view_get_columns:
5257 * @icon_view: a #GtkIconView
5259 * Returns the value of the ::columns property.
5261 * Return value: the number of columns, or -1
5266 gtk_icon_view_get_columns (GtkIconView *icon_view)
5268 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5270 return icon_view->priv->columns;
5274 * gtk_icon_view_set_item_width:
5275 * @icon_view: a #GtkIconView
5276 * @item_width: the width for each item
5278 * Sets the ::item-width property which specifies the width
5279 * to use for each item. If it is set to -1, the icon view will
5280 * automatically determine a suitable item size.
5285 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5288 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5290 if (icon_view->priv->item_width != item_width)
5292 icon_view->priv->item_width = item_width;
5294 gtk_icon_view_stop_editing (icon_view, TRUE);
5295 gtk_icon_view_invalidate_sizes (icon_view);
5296 gtk_icon_view_queue_layout (icon_view);
5298 update_text_cell (icon_view);
5300 g_object_notify (G_OBJECT (icon_view), "item-width");
5305 * gtk_icon_view_get_item_width:
5306 * @icon_view: a #GtkIconView
5308 * Returns the value of the ::item-width property.
5310 * Return value: the width of a single item, or -1
5315 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5317 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5319 return icon_view->priv->item_width;
5324 * gtk_icon_view_set_spacing:
5325 * @icon_view: a #GtkIconView
5326 * @spacing: the spacing
5328 * Sets the ::spacing property which specifies the space
5329 * which is inserted between the cells (i.e. the icon and
5330 * the text) of an item.
5335 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5338 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5340 if (icon_view->priv->spacing != spacing)
5342 icon_view->priv->spacing = spacing;
5344 gtk_icon_view_stop_editing (icon_view, TRUE);
5345 gtk_icon_view_invalidate_sizes (icon_view);
5346 gtk_icon_view_queue_layout (icon_view);
5348 g_object_notify (G_OBJECT (icon_view), "spacing");
5353 * gtk_icon_view_get_spacing:
5354 * @icon_view: a #GtkIconView
5356 * Returns the value of the ::spacing property.
5358 * Return value: the space between cells
5363 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5365 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5367 return icon_view->priv->spacing;
5371 * gtk_icon_view_set_row_spacing:
5372 * @icon_view: a #GtkIconView
5373 * @row_spacing: the row spacing
5375 * Sets the ::row-spacing property which specifies the space
5376 * which is inserted between the rows of the icon view.
5381 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5384 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5386 if (icon_view->priv->row_spacing != row_spacing)
5388 icon_view->priv->row_spacing = row_spacing;
5390 gtk_icon_view_stop_editing (icon_view, TRUE);
5391 gtk_icon_view_invalidate_sizes (icon_view);
5392 gtk_icon_view_queue_layout (icon_view);
5394 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5399 * gtk_icon_view_get_row_spacing:
5400 * @icon_view: a #GtkIconView
5402 * Returns the value of the ::row-spacing property.
5404 * Return value: the space between rows
5409 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5411 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5413 return icon_view->priv->row_spacing;
5417 * gtk_icon_view_set_column_spacing:
5418 * @icon_view: a #GtkIconView
5419 * @column_spacing: the column spacing
5421 * Sets the ::column-spacing property which specifies the space
5422 * which is inserted between the columns of the icon view.
5427 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5428 gint column_spacing)
5430 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5432 if (icon_view->priv->column_spacing != column_spacing)
5434 icon_view->priv->column_spacing = column_spacing;
5436 gtk_icon_view_stop_editing (icon_view, TRUE);
5437 gtk_icon_view_invalidate_sizes (icon_view);
5438 gtk_icon_view_queue_layout (icon_view);
5440 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5445 * gtk_icon_view_get_column_spacing:
5446 * @icon_view: a #GtkIconView
5448 * Returns the value of the ::column-spacing property.
5450 * Return value: the space between columns
5455 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5457 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5459 return icon_view->priv->column_spacing;
5463 * gtk_icon_view_set_margin:
5464 * @icon_view: a #GtkIconView
5465 * @margin: the margin
5467 * Sets the ::margin property which specifies the space
5468 * which is inserted at the top, bottom, left and right
5474 gtk_icon_view_set_margin (GtkIconView *icon_view,
5477 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5479 if (icon_view->priv->margin != margin)
5481 icon_view->priv->margin = margin;
5483 gtk_icon_view_stop_editing (icon_view, TRUE);
5484 gtk_icon_view_invalidate_sizes (icon_view);
5485 gtk_icon_view_queue_layout (icon_view);
5487 g_object_notify (G_OBJECT (icon_view), "margin");
5492 * gtk_icon_view_get_margin:
5493 * @icon_view: a #GtkIconView
5495 * Returns the value of the ::margin property.
5497 * Return value: the space at the borders
5502 gtk_icon_view_get_margin (GtkIconView *icon_view)
5504 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5506 return icon_view->priv->margin;
5510 /* Get/set whether drag_motion requested the drag data and
5511 * drag_data_received should thus not actually insert the data,
5512 * since the data doesn't result from a drop.
5515 set_status_pending (GdkDragContext *context,
5516 GdkDragAction suggested_action)
5518 g_object_set_data (G_OBJECT (context),
5519 "gtk-icon-view-status-pending",
5520 GINT_TO_POINTER (suggested_action));
5523 static GdkDragAction
5524 get_status_pending (GdkDragContext *context)
5526 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5527 "gtk-icon-view-status-pending"));
5531 unset_reorderable (GtkIconView *icon_view)
5533 if (icon_view->priv->reorderable)
5535 icon_view->priv->reorderable = FALSE;
5536 g_object_notify (G_OBJECT (icon_view), "reorderable");
5541 clear_source_info (GtkIconView *icon_view)
5543 if (icon_view->priv->source_targets)
5544 gtk_target_list_unref (icon_view->priv->source_targets);
5545 icon_view->priv->source_targets = NULL;
5547 icon_view->priv->source_set = FALSE;
5551 clear_dest_info (GtkIconView *icon_view)
5553 if (icon_view->priv->dest_targets)
5554 gtk_target_list_unref (icon_view->priv->dest_targets);
5555 icon_view->priv->dest_targets = NULL;
5557 icon_view->priv->dest_set = FALSE;
5561 set_source_row (GdkDragContext *context,
5562 GtkTreeModel *model,
5563 GtkTreePath *source_row)
5566 g_object_set_data_full (G_OBJECT (context),
5567 "gtk-icon-view-source-row",
5568 gtk_tree_row_reference_new (model, source_row),
5569 (GDestroyNotify) gtk_tree_row_reference_free);
5571 g_object_set_data_full (G_OBJECT (context),
5572 "gtk-icon-view-source-row",
5577 get_source_row (GdkDragContext *context)
5579 GtkTreeRowReference *ref;
5581 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5584 return gtk_tree_row_reference_get_path (ref);
5591 GtkTreeRowReference *dest_row;
5592 gboolean empty_view_drop;
5593 gboolean drop_append_mode;
5597 dest_row_free (gpointer data)
5599 DestRow *dr = (DestRow *)data;
5601 gtk_tree_row_reference_free (dr->dest_row);
5606 set_dest_row (GdkDragContext *context,
5607 GtkTreeModel *model,
5608 GtkTreePath *dest_row,
5609 gboolean empty_view_drop,
5610 gboolean drop_append_mode)
5616 g_object_set_data_full (G_OBJECT (context),
5617 "gtk-icon-view-dest-row",
5622 dr = g_new0 (DestRow, 1);
5624 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5625 dr->empty_view_drop = empty_view_drop;
5626 dr->drop_append_mode = drop_append_mode;
5627 g_object_set_data_full (G_OBJECT (context),
5628 "gtk-icon-view-dest-row",
5629 dr, (GDestroyNotify) dest_row_free);
5633 get_dest_row (GdkDragContext *context)
5637 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5641 GtkTreePath *path = NULL;
5644 path = gtk_tree_row_reference_get_path (dr->dest_row);
5645 else if (dr->empty_view_drop)
5646 path = gtk_tree_path_new_from_indices (0, -1);
5650 if (path && dr->drop_append_mode)
5651 gtk_tree_path_next (path);
5660 check_model_dnd (GtkTreeModel *model,
5661 GType required_iface,
5662 const gchar *signal)
5664 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5666 g_warning ("You must override the default '%s' handler "
5667 "on GtkIconView when using models that don't support "
5668 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5669 "is to connect to '%s' and call "
5670 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5671 "the default handler from running. Look at the source code "
5672 "for the default handler in gtkiconview.c to get an idea what "
5673 "your handler should do. (gtkiconview.c is in the GTK+ source "
5674 "code.) If you're using GTK+ from a language other than C, "
5675 "there may be a more natural way to override default handlers, e.g. via derivation.",
5676 signal, g_type_name (required_iface), signal);
5684 remove_scroll_timeout (GtkIconView *icon_view)
5686 if (icon_view->priv->scroll_timeout_id != 0)
5688 g_source_remove (icon_view->priv->scroll_timeout_id);
5690 icon_view->priv->scroll_timeout_id = 0;
5695 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5697 gint px, py, x, y, width, height;
5698 gint hoffset, voffset;
5701 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
5702 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
5704 /* see if we are near the edge. */
5705 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5707 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5709 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5711 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5715 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
5716 icon_view->priv->vadjustment->lower,
5717 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
5718 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
5722 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
5723 icon_view->priv->hadjustment->lower,
5724 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
5725 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
5731 drag_scroll_timeout (gpointer data)
5733 GtkIconView *icon_view = GTK_ICON_VIEW (data);
5735 GDK_THREADS_ENTER ();
5737 gtk_icon_view_autoscroll (icon_view);
5739 GDK_THREADS_LEAVE ();
5746 set_destination (GtkIconView *icon_view,
5747 GdkDragContext *context,
5750 GdkDragAction *suggested_action,
5754 GtkTreePath *path = NULL;
5755 GtkIconViewDropPosition pos;
5756 GtkIconViewDropPosition old_pos;
5757 GtkTreePath *old_dest_path = NULL;
5758 gboolean can_drop = FALSE;
5760 widget = GTK_WIDGET (icon_view);
5762 *suggested_action = 0;
5765 if (!icon_view->priv->dest_set)
5767 /* someone unset us as a drag dest, note that if
5768 * we return FALSE drag_leave isn't called
5771 gtk_icon_view_set_drag_dest_item (icon_view,
5773 GTK_ICON_VIEW_DROP_LEFT);
5775 remove_scroll_timeout (GTK_ICON_VIEW (widget));
5777 return FALSE; /* no longer a drop site */
5780 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
5781 if (*target == GDK_NONE)
5784 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
5787 GtkTreeModel *model;
5789 /* the row got dropped on empty space, let's setup a special case
5793 gtk_tree_path_free (path);
5795 model = gtk_icon_view_get_model (icon_view);
5797 n_children = gtk_tree_model_iter_n_children (model, NULL);
5800 pos = GTK_ICON_VIEW_DROP_BELOW;
5801 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5805 pos = GTK_ICON_VIEW_DROP_ABOVE;
5806 path = gtk_tree_path_new_from_indices (0, -1);
5816 gtk_icon_view_get_drag_dest_item (icon_view,
5821 gtk_tree_path_free (old_dest_path);
5823 if (TRUE /* FIXME if the location droppable predicate */)
5831 GtkWidget *source_widget;
5833 *suggested_action = context->suggested_action;
5834 source_widget = gtk_drag_get_source_widget (context);
5836 if (source_widget == widget)
5838 /* Default to MOVE, unless the user has
5839 * pressed ctrl or shift to affect available actions
5841 if ((context->actions & GDK_ACTION_MOVE) != 0)
5842 *suggested_action = GDK_ACTION_MOVE;
5845 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5850 /* can't drop here */
5851 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5853 GTK_ICON_VIEW_DROP_LEFT);
5857 gtk_tree_path_free (path);
5863 get_logical_destination (GtkIconView *icon_view,
5864 gboolean *drop_append_mode)
5866 /* adjust path to point to the row the drop goes in front of */
5867 GtkTreePath *path = NULL;
5868 GtkIconViewDropPosition pos;
5870 *drop_append_mode = FALSE;
5872 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
5877 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
5878 pos == GTK_ICON_VIEW_DROP_BELOW)
5881 GtkTreeModel *model = icon_view->priv->model;
5883 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5884 !gtk_tree_model_iter_next (model, &iter))
5885 *drop_append_mode = TRUE;
5888 *drop_append_mode = FALSE;
5889 gtk_tree_path_next (path);
5897 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
5898 GdkEventMotion *event)
5900 GdkDragContext *context;
5901 GtkTreePath *path = NULL;
5903 GtkTreeModel *model;
5904 gboolean retval = FALSE;
5906 if (!icon_view->priv->source_set)
5909 if (icon_view->priv->pressed_button < 0)
5912 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
5913 icon_view->priv->press_start_x,
5914 icon_view->priv->press_start_y,
5915 event->x, event->y))
5918 model = gtk_icon_view_get_model (icon_view);
5923 button = icon_view->priv->pressed_button;
5924 icon_view->priv->pressed_button = -1;
5926 path = gtk_icon_view_get_path_at_pos (icon_view,
5927 icon_view->priv->press_start_x,
5928 icon_view->priv->press_start_y);
5933 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
5934 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
5938 /* FIXME Check whether we're a start button, if not return FALSE and
5942 /* Now we can begin the drag */
5946 context = gtk_drag_begin (GTK_WIDGET (icon_view),
5947 icon_view->priv->source_targets,
5948 icon_view->priv->source_actions,
5952 set_source_row (context, model, path);
5956 gtk_tree_path_free (path);
5961 /* Source side drag signals */
5963 gtk_icon_view_drag_begin (GtkWidget *widget,
5964 GdkDragContext *context)
5966 GtkIconView *icon_view;
5967 GtkIconViewItem *item;
5972 icon_view = GTK_ICON_VIEW (widget);
5974 /* if the user uses a custom DnD impl, we don't set the icon here */
5975 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
5978 item = gtk_icon_view_get_item_at_coords (icon_view,
5979 icon_view->priv->press_start_x,
5980 icon_view->priv->press_start_y,
5984 g_return_if_fail (item != NULL);
5986 x = icon_view->priv->press_start_x - item->x + 1;
5987 y = icon_view->priv->press_start_y - item->y + 1;
5989 path = gtk_tree_path_new_from_indices (item->index, -1);
5990 icon = gtk_icon_view_create_drag_icon (icon_view, path);
5991 gtk_tree_path_free (path);
5993 gtk_drag_set_icon_pixmap (context,
5994 gdk_drawable_get_colormap (icon),
5999 g_object_unref (icon);
6003 gtk_icon_view_drag_end (GtkWidget *widget,
6004 GdkDragContext *context)
6010 gtk_icon_view_drag_data_get (GtkWidget *widget,
6011 GdkDragContext *context,
6012 GtkSelectionData *selection_data,
6016 GtkIconView *icon_view;
6017 GtkTreeModel *model;
6018 GtkTreePath *source_row;
6020 icon_view = GTK_ICON_VIEW (widget);
6021 model = gtk_icon_view_get_model (icon_view);
6026 if (!icon_view->priv->dest_set)
6029 source_row = get_source_row (context);
6031 if (source_row == NULL)
6034 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6035 * any model; for DragSource models there are some other targets
6039 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6040 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6045 /* If drag_data_get does nothing, try providing row data. */
6046 if (selection_data->target == gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE))
6047 gtk_tree_set_row_drag_data (selection_data,
6052 gtk_tree_path_free (source_row);
6056 gtk_icon_view_drag_data_delete (GtkWidget *widget,
6057 GdkDragContext *context)
6059 GtkTreeModel *model;
6060 GtkIconView *icon_view;
6061 GtkTreePath *source_row;
6063 icon_view = GTK_ICON_VIEW (widget);
6064 model = gtk_icon_view_get_model (icon_view);
6066 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6069 if (!icon_view->priv->dest_set)
6072 source_row = get_source_row (context);
6074 if (source_row == NULL)
6077 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6080 gtk_tree_path_free (source_row);
6082 set_source_row (context, NULL, NULL);
6085 /* Target side drag signals */
6087 gtk_icon_view_drag_leave (GtkWidget *widget,
6088 GdkDragContext *context,
6091 GtkIconView *icon_view;
6093 icon_view = GTK_ICON_VIEW (widget);
6095 /* unset any highlight row */
6096 gtk_icon_view_set_drag_dest_item (icon_view,
6098 GTK_ICON_VIEW_DROP_LEFT);
6100 remove_scroll_timeout (icon_view);
6104 gtk_icon_view_drag_motion (GtkWidget *widget,
6105 GdkDragContext *context,
6110 GtkTreePath *path = NULL;
6111 GtkTreeModel *model;
6112 GtkIconViewDropPosition pos;
6113 GtkIconView *icon_view;
6114 GdkDragAction suggested_action = 0;
6118 icon_view = GTK_ICON_VIEW (widget);
6120 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6123 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6125 /* we only know this *after* set_desination_row */
6126 model = gtk_icon_view_get_model (icon_view);
6127 empty = icon_view->priv->empty_view_drop;
6129 if (path == NULL && !empty)
6131 /* Can't drop here. */
6132 gdk_drag_status (context, 0, time);
6136 if (icon_view->priv->scroll_timeout_id == 0)
6138 icon_view->priv->scroll_timeout_id =
6139 g_timeout_add (50, drag_scroll_timeout, icon_view);
6142 if (target == gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE))
6144 /* Request data so we can use the source row when
6145 * determining whether to accept the drop
6147 set_status_pending (context, suggested_action);
6148 gtk_drag_get_data (widget, context, target, time);
6152 set_status_pending (context, 0);
6153 gdk_drag_status (context, suggested_action, time);
6158 gtk_tree_path_free (path);
6164 gtk_icon_view_drag_drop (GtkWidget *widget,
6165 GdkDragContext *context,
6170 GtkIconView *icon_view;
6172 GdkDragAction suggested_action = 0;
6173 GdkAtom target = GDK_NONE;
6174 GtkTreeModel *model;
6175 gboolean drop_append_mode;
6177 icon_view = GTK_ICON_VIEW (widget);
6178 model = gtk_icon_view_get_model (icon_view);
6180 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6182 if (!icon_view->priv->dest_set)
6185 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6188 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6191 path = get_logical_destination (icon_view, &drop_append_mode);
6193 if (target != GDK_NONE && path != NULL)
6195 /* in case a motion had requested drag data, change things so we
6196 * treat drag data receives as a drop.
6198 set_status_pending (context, 0);
6199 set_dest_row (context, model, path,
6200 icon_view->priv->empty_view_drop, drop_append_mode);
6204 gtk_tree_path_free (path);
6206 /* Unset this thing */
6207 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6209 if (target != GDK_NONE)
6211 gtk_drag_get_data (widget, context, target, time);
6219 gtk_icon_view_drag_data_received (GtkWidget *widget,
6220 GdkDragContext *context,
6223 GtkSelectionData *selection_data,
6228 gboolean accepted = FALSE;
6229 GtkTreeModel *model;
6230 GtkIconView *icon_view;
6231 GtkTreePath *dest_row;
6232 GdkDragAction suggested_action;
6233 gboolean drop_append_mode;
6235 icon_view = GTK_ICON_VIEW (widget);
6236 model = gtk_icon_view_get_model (icon_view);
6238 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6241 if (!icon_view->priv->dest_set)
6244 suggested_action = get_status_pending (context);
6246 if (suggested_action)
6248 /* We are getting this data due to a request in drag_motion,
6249 * rather than due to a request in drag_drop, so we are just
6250 * supposed to call drag_status, not actually paste in the
6253 path = get_logical_destination (icon_view, &drop_append_mode);
6256 suggested_action = 0;
6258 if (suggested_action)
6260 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6263 suggested_action = 0;
6266 gdk_drag_status (context, suggested_action, time);
6269 gtk_tree_path_free (path);
6271 /* If you can't drop, remove user drop indicator until the next motion */
6272 if (suggested_action == 0)
6273 gtk_icon_view_set_drag_dest_item (icon_view,
6275 GTK_ICON_VIEW_DROP_LEFT);
6280 dest_row = get_dest_row (context);
6282 if (dest_row == NULL)
6285 if (selection_data->length >= 0)
6287 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6293 gtk_drag_finish (context,
6295 (context->action == GDK_ACTION_MOVE),
6298 gtk_tree_path_free (dest_row);
6301 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6304 /* Drag-and-Drop support */
6306 * gtk_icon_view_enable_model_drag_source:
6307 * @icon_view: a #GtkIconTreeView
6308 * @start_button_mask: Mask of allowed buttons to start drag
6309 * @targets: the table of targets that the drag will support
6310 * @n_targets: the number of items in @targets
6311 * @actions: the bitmask of possible actions for a drag from this
6314 * Turns @icon_view into a drag source for automatic DND.
6319 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6320 GdkModifierType start_button_mask,
6321 const GtkTargetEntry *targets,
6323 GdkDragAction actions)
6325 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6327 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6329 clear_source_info (icon_view);
6330 icon_view->priv->start_button_mask = start_button_mask;
6331 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6332 icon_view->priv->source_actions = actions;
6334 icon_view->priv->source_set = TRUE;
6336 unset_reorderable (icon_view);
6340 * gtk_icon_view_enable_model_drag_dest:
6341 * @icon_view: a #GtkIconView
6342 * @targets: the table of targets that the drag will support
6343 * @n_targets: the number of items in @targets
6344 * @actions: the bitmask of possible actions for a drag from this
6347 * Turns @icon_view into a drop destination for automatic DND.
6352 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6353 const GtkTargetEntry *targets,
6355 GdkDragAction actions)
6357 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6359 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6361 clear_dest_info (icon_view);
6363 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6364 icon_view->priv->dest_actions = actions;
6366 icon_view->priv->dest_set = TRUE;
6368 unset_reorderable (icon_view);
6372 * gtk_icon_view_unset_model_drag_source:
6373 * @icon_view: a #GtkIconView
6375 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6380 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6382 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6384 if (icon_view->priv->source_set)
6386 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6387 clear_source_info (icon_view);
6390 unset_reorderable (icon_view);
6394 * gtk_icon_view_unset_model_drag_dest:
6395 * @icon_view: a #GtkIconView
6397 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6402 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6404 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6406 if (icon_view->priv->dest_set)
6408 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6409 clear_dest_info (icon_view);
6412 unset_reorderable (icon_view);
6415 /* These are useful to implement your own custom stuff. */
6417 * gtk_icon_view_set_drag_dest_item:
6418 * @icon_view: a #GtkIconView
6419 * @path: The path of the item to highlight, or %NULL.
6420 * @pos: Specifies whether to drop, relative to the item
6422 * Sets the item that is highlighted for feedback.
6427 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6429 GtkIconViewDropPosition pos)
6431 /* Note; this function is exported to allow a custom DND
6432 * implementation, so it can't touch TreeViewDragInfo
6435 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6437 if (icon_view->priv->dest_item)
6439 GtkTreePath *current_path;
6440 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6441 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6442 icon_view->priv->dest_item = NULL;
6444 gtk_icon_view_queue_draw_path (icon_view, current_path);
6445 gtk_tree_path_free (current_path);
6448 /* special case a drop on an empty model */
6449 icon_view->priv->empty_view_drop = FALSE;
6450 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
6451 && gtk_tree_path_get_depth (path) == 1
6452 && gtk_tree_path_get_indices (path)[0] == 0)
6456 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6459 if (n_children == 0)
6460 icon_view->priv->empty_view_drop = TRUE;
6463 icon_view->priv->dest_pos = pos;
6467 icon_view->priv->dest_item =
6468 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6469 icon_view->priv->model, path);
6471 gtk_icon_view_queue_draw_path (icon_view, path);
6476 * gtk_icon_view_get_drag_dest_item:
6477 * @icon_view: a #GtkIconView
6478 * @path: Return location for the path of the highlighted item, or %NULL.
6479 * @pos: Return location for the drop position, or %NULL
6481 * Gets information about the item that is highlighted for feedback.
6486 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6488 GtkIconViewDropPosition *pos)
6490 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6494 if (icon_view->priv->dest_item)
6495 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6501 *pos = icon_view->priv->dest_pos;
6505 * gtk_icon_view_get_dest_item_at_pos:
6506 * @icon_view: a #GtkIconView
6507 * @drag_x: the position to determine the destination item for
6508 * @drag_y: the position to determine the destination item for
6509 * @path: Return location for the path of the highlighted item, or %NULL.
6510 * @pos: Return location for the drop position, or %NULL
6512 * Determines the destination item for a given position.
6514 * Return value: whether there is an item at the given position.
6519 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6523 GtkIconViewDropPosition *pos)
6525 GtkIconViewItem *item;
6527 /* Note; this function is exported to allow a custom DND
6528 * implementation, so it can't touch TreeViewDragInfo
6531 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6532 g_return_val_if_fail (drag_x >= 0, FALSE);
6533 g_return_val_if_fail (drag_y >= 0, FALSE);
6534 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6540 item = gtk_icon_view_get_item_at_coords (icon_view,
6541 drag_x + icon_view->priv->hadjustment->value,
6542 drag_y + icon_view->priv->vadjustment->value,
6549 *path = gtk_tree_path_new_from_indices (item->index, -1);
6553 if (drag_x < item->x + item->width / 4)
6554 *pos = GTK_ICON_VIEW_DROP_LEFT;
6555 else if (drag_x > item->x + item->width * 3 / 4)
6556 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6557 else if (drag_y < item->y + item->height / 4)
6558 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6559 else if (drag_y > item->y + item->height * 3 / 4)
6560 *pos = GTK_ICON_VIEW_DROP_BELOW;
6562 *pos = GTK_ICON_VIEW_DROP_INTO;
6569 * gtk_icon_view_create_drag_icon:
6570 * @icon_view: a #GtkIconView
6571 * @path: a #GtkTreePath in @icon_view
6573 * Creates a #GdkPixmap representation of the item at @path.
6574 * This image is used for a drag icon.
6576 * Return value: a newly-allocated pixmap of the drag icon.
6581 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6586 GdkPixmap *drawable;
6591 widget = GTK_WIDGET (icon_view);
6593 index = gtk_tree_path_get_indices (path)[0];
6595 for (l = icon_view->priv->items; l; l = l->next)
6597 GtkIconViewItem *item = l->data;
6599 if (index == item->index)
6601 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
6606 cr = gdk_cairo_create (drawable);
6607 cairo_set_line_width (cr, 1.);
6609 gdk_cairo_set_source_color
6610 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
6611 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
6616 area.width = item->width;
6617 area.height = item->height;
6619 gtk_icon_view_paint_item (icon_view, cr, item, &area,
6620 drawable, 1, 1, FALSE);
6622 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6623 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
6636 * gtk_icon_view_get_reorderable:
6637 * @icon_view: a #GtkIconView
6639 * Retrieves whether the user can reorder the list via drag-and-drop.
6640 * See gtk_icon_view_set_reorderable().
6642 * Return value: %TRUE if the list can be reordered.
6647 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6649 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6651 return icon_view->priv->reorderable;
6654 static const GtkTargetEntry item_targets[] = {
6655 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6660 * gtk_icon_view_set_reorderable:
6661 * @icon_view: A #GtkIconView.
6662 * @reorderable: %TRUE, if the list of items can be reordered.
6664 * This function is a convenience function to allow you to reorder models that
6665 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6666 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6667 * the user can reorder the model by dragging and dropping rows. The
6668 * developer can listen to these changes by connecting to the model's
6669 * row_inserted and row_deleted signals.
6671 * This function does not give you any degree of control over the order -- any
6672 * reordering is allowed. If more control is needed, you should probably
6673 * handle drag and drop manually.
6678 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6679 gboolean reorderable)
6681 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6683 reorderable = reorderable != FALSE;
6685 if (icon_view->priv->reorderable == reorderable)
6690 gtk_icon_view_enable_model_drag_source (icon_view,
6693 G_N_ELEMENTS (item_targets),
6695 gtk_icon_view_enable_model_drag_dest (icon_view,
6697 G_N_ELEMENTS (item_targets),
6702 gtk_icon_view_unset_model_drag_source (icon_view);
6703 gtk_icon_view_unset_model_drag_dest (icon_view);
6706 icon_view->priv->reorderable = reorderable;
6708 g_object_notify (G_OBJECT (icon_view), "reorderable");
6712 /* Accessibility Support */
6714 static gpointer accessible_parent_class;
6715 static gpointer accessible_item_parent_class;
6716 static GQuark accessible_private_data_quark = 0;
6718 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6719 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6720 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6722 static GType gtk_icon_view_item_accessible_get_type (void);
6733 GtkIconViewItem *item;
6737 AtkStateSet *state_set;
6741 GtkTextBuffer *text_buffer;
6743 gchar *action_descriptions[LAST_ACTION];
6744 gchar *image_description;
6745 guint action_idle_handler;
6746 } GtkIconViewItemAccessible;
6748 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
6754 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
6759 typedef struct _GtkIconViewItemAccessibleClass
6761 AtkObjectClass parent_class;
6763 } GtkIconViewItemAccessibleClass;
6765 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
6768 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
6770 GtkIconViewItemAccessible *item;
6771 GtkIconView *icon_view;
6774 GDK_THREADS_ENTER ();
6776 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
6777 item->action_idle_handler = 0;
6779 if (item->widget != NULL)
6781 icon_view = GTK_ICON_VIEW (item->widget);
6782 path = gtk_tree_path_new_from_indices (item->item->index, -1);
6783 gtk_icon_view_item_activated (icon_view, path);
6784 gtk_tree_path_free (path);
6787 GDK_THREADS_LEAVE ();
6793 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
6796 GtkIconViewItemAccessible *item;
6797 GtkIconView *icon_view;
6799 if (i < 0 || i >= LAST_ACTION)
6802 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6804 if (!GTK_IS_ICON_VIEW (item->widget))
6807 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6810 icon_view = GTK_ICON_VIEW (item->widget);
6814 case ACTION_ACTIVATE:
6815 if (!item->action_idle_handler)
6816 item->action_idle_handler = g_idle_add (gtk_icon_view_item_accessible_idle_do_action, item);
6819 g_assert_not_reached ();
6827 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
6832 static const gchar *
6833 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
6836 GtkIconViewItemAccessible *item;
6838 if (i < 0 || i >= LAST_ACTION)
6841 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6843 if (item->action_descriptions[i])
6844 return item->action_descriptions[i];
6846 return gtk_icon_view_item_accessible_action_descriptions[i];
6849 static const gchar *
6850 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
6853 if (i < 0 || i >= LAST_ACTION)
6856 return gtk_icon_view_item_accessible_action_names[i];
6860 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
6862 const gchar *description)
6864 GtkIconViewItemAccessible *item;
6866 if (i < 0 || i >= LAST_ACTION)
6869 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6871 if (item->action_descriptions[i])
6872 g_free (item->action_descriptions[i]);
6874 item->action_descriptions[i] = g_strdup (description);
6880 atk_action_item_interface_init (AtkActionIface *iface)
6882 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
6883 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
6884 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
6885 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
6886 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
6889 static const gchar *
6890 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
6892 GtkIconViewItemAccessible *item;
6894 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6896 return item->image_description;
6900 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
6901 const gchar *description)
6903 GtkIconViewItemAccessible *item;
6905 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6907 g_free (item->image_description);
6908 item->image_description = g_strdup (item->image_description);
6914 get_pixbuf_box (GtkIconView *icon_view,
6915 GtkIconViewItem *item,
6920 for (l = icon_view->priv->cell_list; l; l = l->next)
6922 GtkIconViewCellInfo *info = l->data;
6924 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
6926 gtk_icon_view_get_cell_box (icon_view, item, info, box);
6936 get_text (GtkIconView *icon_view,
6937 GtkIconViewItem *item)
6942 for (l = icon_view->priv->cell_list; l; l = l->next)
6944 GtkIconViewCellInfo *info = l->data;
6946 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
6948 g_object_get (info->cell, "text", &text, NULL);
6958 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
6962 GtkIconViewItemAccessible *item;
6965 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6967 if (!GTK_IS_ICON_VIEW (item->widget))
6970 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6973 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
6976 *height = box.height;
6981 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
6984 AtkCoordType coord_type)
6986 GtkIconViewItemAccessible *item;
6989 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6991 if (!GTK_IS_ICON_VIEW (item->widget))
6994 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6997 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
6999 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
7001 *x+= box.x - item->item->x;
7002 *y+= box.y - item->item->y;
7008 atk_image_item_interface_init (AtkImageIface *iface)
7010 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
7011 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
7012 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
7013 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
7017 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
7021 GtkIconViewItemAccessible *item;
7022 GtkTextIter start, end;
7023 GtkTextBuffer *buffer;
7025 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7027 if (!GTK_IS_ICON_VIEW (item->widget))
7030 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7033 buffer = item->text_buffer;
7034 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
7036 gtk_text_buffer_get_end_iter (buffer, &end);
7038 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
7040 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7044 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
7047 GtkIconViewItemAccessible *item;
7048 GtkTextIter start, end;
7049 GtkTextBuffer *buffer;
7053 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7055 if (!GTK_IS_ICON_VIEW (item->widget))
7058 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7061 buffer = item->text_buffer;
7062 if (offset >= gtk_text_buffer_get_char_count (buffer))
7065 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7067 gtk_text_iter_forward_char (&end);
7068 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7069 unichar = g_utf8_get_char (string);
7076 get_pango_text_offsets (PangoLayout *layout,
7077 GtkTextBuffer *buffer,
7079 AtkTextBoundary boundary_type,
7083 GtkTextIter *start_iter,
7084 GtkTextIter *end_iter)
7086 PangoLayoutIter *iter;
7087 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7088 gint index, start_index, end_index;
7090 gboolean found = FALSE;
7092 text = pango_layout_get_text (layout);
7093 index = g_utf8_offset_to_pointer (text, offset) - text;
7094 iter = pango_layout_get_iter (layout);
7097 line = pango_layout_iter_get_line (iter);
7098 start_index = line->start_index;
7099 end_index = start_index + line->length;
7101 if (index >= start_index && index <= end_index)
7104 * Found line for offset
7110 * We want the previous line
7114 switch (boundary_type)
7116 case ATK_TEXT_BOUNDARY_LINE_START:
7117 end_index = start_index;
7118 start_index = prev_line->start_index;
7120 case ATK_TEXT_BOUNDARY_LINE_END:
7122 start_index = prev_prev_line->start_index +
7123 prev_prev_line->length;
7124 end_index = prev_line->start_index + prev_line->length;
7127 g_assert_not_reached();
7131 start_index = end_index = 0;
7134 switch (boundary_type)
7136 case ATK_TEXT_BOUNDARY_LINE_START:
7137 if (pango_layout_iter_next_line (iter))
7138 end_index = pango_layout_iter_get_line (iter)->start_index;
7140 case ATK_TEXT_BOUNDARY_LINE_END:
7142 start_index = prev_line->start_index +
7146 g_assert_not_reached();
7151 * We want the next line
7153 if (pango_layout_iter_next_line (iter))
7155 line = pango_layout_iter_get_line (iter);
7156 switch (boundary_type)
7158 case ATK_TEXT_BOUNDARY_LINE_START:
7159 start_index = line->start_index;
7160 if (pango_layout_iter_next_line (iter))
7161 end_index = pango_layout_iter_get_line (iter)->start_index;
7163 end_index = start_index + line->length;
7165 case ATK_TEXT_BOUNDARY_LINE_END:
7166 start_index = end_index;
7167 end_index = line->start_index + line->length;
7170 g_assert_not_reached();
7174 start_index = end_index;
7180 prev_prev_line = prev_line;
7183 while (pango_layout_iter_next_line (iter));
7187 start_index = prev_line->start_index + prev_line->length;
7188 end_index = start_index;
7190 pango_layout_iter_free (iter);
7191 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7192 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7194 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7195 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7199 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7201 AtkTextBoundary boundary_type,
7205 GtkIconViewItemAccessible *item;
7206 GtkTextIter start, end;
7207 GtkTextBuffer *buffer;
7208 GtkIconView *icon_view;
7210 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7212 if (!GTK_IS_ICON_VIEW (item->widget))
7215 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7218 buffer = item->text_buffer;
7220 if (!gtk_text_buffer_get_char_count (buffer))
7224 return g_strdup ("");
7226 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7230 switch (boundary_type)
7232 case ATK_TEXT_BOUNDARY_CHAR:
7233 gtk_text_iter_backward_char(&start);
7235 case ATK_TEXT_BOUNDARY_WORD_START:
7236 if (!gtk_text_iter_starts_word (&start))
7237 gtk_text_iter_backward_word_start (&start);
7239 gtk_text_iter_backward_word_start(&start);
7241 case ATK_TEXT_BOUNDARY_WORD_END:
7242 if (gtk_text_iter_inside_word (&start) &&
7243 !gtk_text_iter_starts_word (&start))
7244 gtk_text_iter_backward_word_start (&start);
7245 while (!gtk_text_iter_ends_word (&start))
7247 if (!gtk_text_iter_backward_char (&start))
7251 gtk_text_iter_backward_word_start(&start);
7252 while (!gtk_text_iter_ends_word (&start))
7254 if (!gtk_text_iter_backward_char (&start))
7258 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7259 if (!gtk_text_iter_starts_sentence (&start))
7260 gtk_text_iter_backward_sentence_start (&start);
7262 gtk_text_iter_backward_sentence_start (&start);
7264 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7265 if (gtk_text_iter_inside_sentence (&start) &&
7266 !gtk_text_iter_starts_sentence (&start))
7267 gtk_text_iter_backward_sentence_start (&start);
7268 while (!gtk_text_iter_ends_sentence (&start))
7270 if (!gtk_text_iter_backward_char (&start))
7274 gtk_text_iter_backward_sentence_start (&start);
7275 while (!gtk_text_iter_ends_sentence (&start))
7277 if (!gtk_text_iter_backward_char (&start))
7281 case ATK_TEXT_BOUNDARY_LINE_START:
7282 case ATK_TEXT_BOUNDARY_LINE_END:
7283 icon_view = GTK_ICON_VIEW (item->widget);
7285 /* FIXME we probably have to use GailTextCell to salvage this */
7286 gtk_icon_view_update_item_text (icon_view, item->item);
7287 get_pango_text_offsets (icon_view->priv->layout,
7300 *start_offset = gtk_text_iter_get_offset (&start);
7301 *end_offset = gtk_text_iter_get_offset (&end);
7303 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7307 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7309 AtkTextBoundary boundary_type,
7313 GtkIconViewItemAccessible *item;
7314 GtkTextIter start, end;
7315 GtkTextBuffer *buffer;
7316 GtkIconView *icon_view;
7318 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7320 if (!GTK_IS_ICON_VIEW (item->widget))
7323 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7326 buffer = item->text_buffer;
7328 if (!gtk_text_buffer_get_char_count (buffer))
7332 return g_strdup ("");
7334 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7338 switch (boundary_type)
7340 case ATK_TEXT_BOUNDARY_CHAR:
7341 gtk_text_iter_forward_char (&end);
7343 case ATK_TEXT_BOUNDARY_WORD_START:
7344 if (!gtk_text_iter_starts_word (&start))
7345 gtk_text_iter_backward_word_start (&start);
7346 if (gtk_text_iter_inside_word (&end))
7347 gtk_text_iter_forward_word_end (&end);
7348 while (!gtk_text_iter_starts_word (&end))
7350 if (!gtk_text_iter_forward_char (&end))
7354 case ATK_TEXT_BOUNDARY_WORD_END:
7355 if (gtk_text_iter_inside_word (&start) &&
7356 !gtk_text_iter_starts_word (&start))
7357 gtk_text_iter_backward_word_start (&start);
7358 while (!gtk_text_iter_ends_word (&start))
7360 if (!gtk_text_iter_backward_char (&start))
7363 gtk_text_iter_forward_word_end (&end);
7365 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7366 if (!gtk_text_iter_starts_sentence (&start))
7367 gtk_text_iter_backward_sentence_start (&start);
7368 if (gtk_text_iter_inside_sentence (&end))
7369 gtk_text_iter_forward_sentence_end (&end);
7370 while (!gtk_text_iter_starts_sentence (&end))
7372 if (!gtk_text_iter_forward_char (&end))
7376 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7377 if (gtk_text_iter_inside_sentence (&start) &&
7378 !gtk_text_iter_starts_sentence (&start))
7379 gtk_text_iter_backward_sentence_start (&start);
7380 while (!gtk_text_iter_ends_sentence (&start))
7382 if (!gtk_text_iter_backward_char (&start))
7385 gtk_text_iter_forward_sentence_end (&end);
7387 case ATK_TEXT_BOUNDARY_LINE_START:
7388 case ATK_TEXT_BOUNDARY_LINE_END:
7389 icon_view = GTK_ICON_VIEW (item->widget);
7391 /* FIXME we probably have to use GailTextCell to salvage this */
7392 gtk_icon_view_update_item_text (icon_view, item->item);
7393 get_pango_text_offsets (icon_view->priv->layout,
7407 *start_offset = gtk_text_iter_get_offset (&start);
7408 *end_offset = gtk_text_iter_get_offset (&end);
7410 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7414 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7416 AtkTextBoundary boundary_type,
7420 GtkIconViewItemAccessible *item;
7421 GtkTextIter start, end;
7422 GtkTextBuffer *buffer;
7423 GtkIconView *icon_view;
7425 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7427 if (!GTK_IS_ICON_VIEW (item->widget))
7430 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7433 buffer = item->text_buffer;
7435 if (!gtk_text_buffer_get_char_count (buffer))
7439 return g_strdup ("");
7441 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7445 switch (boundary_type)
7447 case ATK_TEXT_BOUNDARY_CHAR:
7448 gtk_text_iter_forward_char(&start);
7449 gtk_text_iter_forward_chars(&end, 2);
7451 case ATK_TEXT_BOUNDARY_WORD_START:
7452 if (gtk_text_iter_inside_word (&end))
7453 gtk_text_iter_forward_word_end (&end);
7454 while (!gtk_text_iter_starts_word (&end))
7456 if (!gtk_text_iter_forward_char (&end))
7460 if (!gtk_text_iter_is_end (&end))
7462 gtk_text_iter_forward_word_end (&end);
7463 while (!gtk_text_iter_starts_word (&end))
7465 if (!gtk_text_iter_forward_char (&end))
7470 case ATK_TEXT_BOUNDARY_WORD_END:
7471 gtk_text_iter_forward_word_end (&end);
7473 if (!gtk_text_iter_is_end (&end))
7474 gtk_text_iter_forward_word_end (&end);
7476 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7477 if (gtk_text_iter_inside_sentence (&end))
7478 gtk_text_iter_forward_sentence_end (&end);
7479 while (!gtk_text_iter_starts_sentence (&end))
7481 if (!gtk_text_iter_forward_char (&end))
7485 if (!gtk_text_iter_is_end (&end))
7487 gtk_text_iter_forward_sentence_end (&end);
7488 while (!gtk_text_iter_starts_sentence (&end))
7490 if (!gtk_text_iter_forward_char (&end))
7495 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7496 gtk_text_iter_forward_sentence_end (&end);
7498 if (!gtk_text_iter_is_end (&end))
7499 gtk_text_iter_forward_sentence_end (&end);
7501 case ATK_TEXT_BOUNDARY_LINE_START:
7502 case ATK_TEXT_BOUNDARY_LINE_END:
7503 icon_view = GTK_ICON_VIEW (item->widget);
7505 /* FIXME we probably have to use GailTextCell to salvage this */
7506 gtk_icon_view_update_item_text (icon_view, item->item);
7507 get_pango_text_offsets (icon_view->priv->layout,
7519 *start_offset = gtk_text_iter_get_offset (&start);
7520 *end_offset = gtk_text_iter_get_offset (&end);
7522 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7526 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7528 GtkIconViewItemAccessible *item;
7530 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7532 if (!GTK_IS_ICON_VIEW (item->widget))
7535 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7538 return gtk_text_buffer_get_char_count (item->text_buffer);
7542 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7548 AtkCoordType coord_type)
7550 GtkIconViewItemAccessible *item;
7551 GtkIconView *icon_view;
7552 PangoRectangle char_rect;
7553 const gchar *item_text;
7556 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7558 if (!GTK_IS_ICON_VIEW (item->widget))
7561 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7564 icon_view = GTK_ICON_VIEW (item->widget);
7566 /* FIXME we probably have to use GailTextCell to salvage this */
7567 gtk_icon_view_update_item_text (icon_view, item->item);
7568 item_text = pango_layout_get_text (icon_view->priv->layout);
7569 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7570 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7572 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7573 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7574 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7575 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7576 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7577 *width = char_rect.width / PANGO_SCALE;
7578 *height = char_rect.height / PANGO_SCALE;
7583 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7586 AtkCoordType coord_type)
7588 GtkIconViewItemAccessible *item;
7589 GtkIconView *icon_view;
7590 const gchar *item_text;
7595 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7597 if (!GTK_IS_ICON_VIEW (item->widget))
7600 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7603 icon_view = GTK_ICON_VIEW (item->widget);
7605 /* FIXME we probably have to use GailTextCell to salvage this */
7606 gtk_icon_view_update_item_text (icon_view, item->item);
7607 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7608 x -= l_x + item->item->layout_x - item->item->x;
7609 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7610 y -= l_y + item->item->layout_y - item->item->y;
7611 item_text = pango_layout_get_text (icon_view->priv->layout);
7612 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7623 offset = g_utf8_strlen (item_text, -1);
7625 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7631 atk_text_item_interface_init (AtkTextIface *iface)
7633 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7634 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7635 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7636 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7637 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7638 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7639 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7640 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7644 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7649 AtkCoordType coord_type)
7651 GtkIconViewItemAccessible *item;
7652 AtkObject *parent_obj;
7655 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7657 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7658 if (!GTK_IS_WIDGET (item->widget))
7661 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7664 *width = item->item->width;
7665 *height = item->item->height;
7666 if (gtk_icon_view_item_accessible_is_showing (item))
7668 parent_obj = gtk_widget_get_accessible (item->widget);
7669 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7670 *x = l_x + item->item->x;
7671 *y = l_y + item->item->y;
7681 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7683 GtkIconViewItemAccessible *item;
7684 GtkWidget *toplevel;
7686 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7688 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7689 if (!GTK_IS_WIDGET (item->widget))
7692 gtk_widget_grab_focus (item->widget);
7693 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
7694 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7695 if (GTK_WIDGET_TOPLEVEL (toplevel))
7696 gtk_window_present (GTK_WINDOW (toplevel));
7702 atk_component_item_interface_init (AtkComponentIface *iface)
7704 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7705 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7709 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7710 AtkStateType state_type,
7711 gboolean emit_signal)
7715 rc = atk_state_set_add_state (item->state_set, state_type);
7717 * The signal should only be generated if the value changed,
7718 * not when the item is set up. So states that are set
7719 * initially should pass FALSE as the emit_signal argument.
7724 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7725 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7726 if (state_type == ATK_STATE_VISIBLE)
7727 g_signal_emit_by_name (item, "visible_data_changed");
7734 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7735 AtkStateType state_type,
7736 gboolean emit_signal)
7738 if (atk_state_set_contains_state (item->state_set, state_type))
7742 rc = atk_state_set_remove_state (item->state_set, state_type);
7744 * The signal should only be generated if the value changed,
7745 * not when the item is set up. So states that are set
7746 * initially should pass FALSE as the emit_signal argument.
7751 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7752 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7753 if (state_type == ATK_STATE_VISIBLE)
7754 g_signal_emit_by_name (item, "visible_data_changed");
7764 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7766 GtkIconView *icon_view;
7767 GdkRectangle visible_rect;
7768 gboolean is_showing;
7771 * An item is considered "SHOWING" if any part of the item is in the
7772 * visible rectangle.
7775 if (!GTK_IS_ICON_VIEW (item->widget))
7778 if (item->item == NULL)
7781 icon_view = GTK_ICON_VIEW (item->widget);
7783 if (icon_view->priv->hadjustment)
7784 visible_rect.x += icon_view->priv->hadjustment->value;
7786 if (icon_view->priv->hadjustment)
7787 visible_rect.y += icon_view->priv->vadjustment->value;
7788 visible_rect.width = item->widget->allocation.width;
7789 visible_rect.height = item->widget->allocation.height;
7791 if (((item->item->x + item->item->width) < visible_rect.x) ||
7792 ((item->item->y + item->item->height) < (visible_rect.y)) ||
7793 (item->item->x > (visible_rect.x + visible_rect.width)) ||
7794 (item->item->y > (visible_rect.y + visible_rect.height)))
7803 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
7804 gboolean emit_signal)
7806 if (gtk_icon_view_item_accessible_is_showing (item))
7807 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
7810 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
7815 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
7819 item->state_set = atk_state_set_new ();
7821 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
7822 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
7823 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
7824 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
7825 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
7827 for (i = 0; i < LAST_ACTION; i++)
7828 item->action_descriptions[i] = NULL;
7830 item->image_description = NULL;
7832 item->action_idle_handler = 0;
7836 gtk_icon_view_item_accessible_finalize (GObject *object)
7838 GtkIconViewItemAccessible *item;
7841 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
7843 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
7846 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
7848 if (item->state_set)
7849 g_object_unref (item->state_set);
7851 if (item->text_buffer)
7852 g_object_unref (item->text_buffer);
7854 for (i = 0; i < LAST_ACTION; i++)
7855 g_free (item->action_descriptions[i]);
7857 g_free (item->image_description);
7859 if (item->action_idle_handler)
7861 g_source_remove (item->action_idle_handler);
7862 item->action_idle_handler = 0;
7865 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
7868 static G_CONST_RETURN gchar*
7869 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
7875 GtkIconViewItemAccessible *item;
7876 GtkTextIter start_iter;
7877 GtkTextIter end_iter;
7879 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7881 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
7882 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
7884 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
7889 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
7891 GtkIconViewItemAccessible *item;
7893 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
7894 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7897 return gtk_widget_get_accessible (item->widget);
7903 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
7905 GtkIconViewItemAccessible *item;
7907 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
7908 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7910 return item->item->index;
7913 static AtkStateSet *
7914 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
7916 GtkIconViewItemAccessible *item;
7917 GtkIconView *icon_view;
7919 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7920 g_return_val_if_fail (item->state_set, NULL);
7925 icon_view = GTK_ICON_VIEW (item->widget);
7926 if (icon_view->priv->cursor_item == item->item)
7927 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
7929 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
7931 return g_object_ref (item->state_set);
7935 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
7937 GObjectClass *gobject_class;
7939 accessible_item_parent_class = g_type_class_peek_parent (klass);
7941 gobject_class = (GObjectClass *)klass;
7943 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
7945 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
7946 klass->get_name = gtk_icon_view_item_accessible_get_name;
7947 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
7948 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
7952 gtk_icon_view_item_accessible_get_type (void)
7954 static GType type = 0;
7958 static const GTypeInfo tinfo =
7960 sizeof (GtkIconViewItemAccessibleClass),
7961 (GBaseInitFunc) NULL, /* base init */
7962 (GBaseFinalizeFunc) NULL, /* base finalize */
7963 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
7964 (GClassFinalizeFunc) NULL, /* class finalize */
7965 NULL, /* class data */
7966 sizeof (GtkIconViewItemAccessible), /* instance size */
7967 0, /* nb preallocs */
7968 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
7969 NULL /* value table */
7972 static const GInterfaceInfo atk_component_info =
7974 (GInterfaceInitFunc) atk_component_item_interface_init,
7975 (GInterfaceFinalizeFunc) NULL,
7978 static const GInterfaceInfo atk_action_info =
7980 (GInterfaceInitFunc) atk_action_item_interface_init,
7981 (GInterfaceFinalizeFunc) NULL,
7984 static const GInterfaceInfo atk_image_info =
7986 (GInterfaceInitFunc) atk_image_item_interface_init,
7987 (GInterfaceFinalizeFunc) NULL,
7990 static const GInterfaceInfo atk_text_info =
7992 (GInterfaceInitFunc) atk_text_item_interface_init,
7993 (GInterfaceFinalizeFunc) NULL,
7997 type = g_type_register_static (ATK_TYPE_OBJECT,
7998 "GtkIconViewItemAccessible", &tinfo, 0);
7999 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8000 &atk_component_info);
8001 g_type_add_interface_static (type, ATK_TYPE_ACTION,
8003 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
8005 g_type_add_interface_static (type, ATK_TYPE_TEXT,
8012 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
8013 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
8014 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
8016 static GType gtk_icon_view_accessible_get_type (void);
8021 } GtkIconViewAccessible;
8027 } GtkIconViewItemAccessibleInfo;
8033 GtkAdjustment *old_hadj;
8034 GtkAdjustment *old_vadj;
8036 GtkTreeModel *model;
8038 } GtkIconViewAccessiblePrivate;
8040 static GtkIconViewAccessiblePrivate *
8041 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
8043 return g_object_get_qdata (G_OBJECT (accessible),
8044 accessible_private_data_quark);
8048 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
8052 GtkIconViewItemAccessibleInfo *info;
8053 GtkIconViewItemAccessibleInfo *tmp_info;
8054 GtkIconViewAccessiblePrivate *priv;
8057 info = g_new (GtkIconViewItemAccessibleInfo, 1);
8059 info->index = index;
8061 priv = gtk_icon_view_accessible_get_priv (accessible);
8062 items = priv->items;
8065 tmp_info = items->data;
8066 if (tmp_info->index > index)
8068 items = items->next;
8070 priv->items = g_list_insert_before (priv->items, items, info);
8071 priv->old_hadj = NULL;
8072 priv->old_vadj = NULL;
8076 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8078 GtkIconView *icon_view;
8081 widget = GTK_ACCESSIBLE (accessible)->widget;
8085 icon_view = GTK_ICON_VIEW (widget);
8087 return g_list_length (icon_view->priv->items);
8091 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8094 GtkIconViewAccessiblePrivate *priv;
8095 GtkIconViewItemAccessibleInfo *info;
8098 priv = gtk_icon_view_accessible_get_priv (accessible);
8099 items = priv->items;
8104 if (info->index == index)
8106 items = items->next;
8112 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8115 GtkIconView *icon_view;
8119 GtkIconViewItemAccessible *a11y_item;
8121 widget = GTK_ACCESSIBLE (accessible)->widget;
8125 icon_view = GTK_ICON_VIEW (widget);
8126 icons = g_list_nth (icon_view->priv->items, index);
8130 GtkIconViewItem *item = icons->data;
8132 g_return_val_if_fail (item->index == index, NULL);
8133 obj = gtk_icon_view_accessible_find_child (accessible, index);
8136 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8137 gtk_icon_view_item_accessible_info_new (accessible,
8140 obj->role = ATK_ROLE_ICON;
8141 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8142 a11y_item->item = item;
8143 a11y_item->widget = widget;
8144 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8146 gtk_icon_view_set_cell_data (icon_view, item);
8147 gtk_text_buffer_set_text (a11y_item->text_buffer,
8148 get_text (icon_view, item), -1);
8150 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8151 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8159 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8162 GtkIconViewAccessiblePrivate *priv;
8163 GtkIconViewItemAccessibleInfo *info;
8164 GtkIconViewItemAccessible *item;
8167 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8171 gboolean act_on_item;
8173 widget = GTK_ACCESSIBLE (view)->widget;
8177 items = priv->items;
8179 act_on_item = (list == NULL);
8184 info = (GtkIconViewItemAccessibleInfo *)items->data;
8185 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8187 if (act_on_item == FALSE && list == items)
8191 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8193 items = items->next;
8199 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8200 GtkIconView *icon_view)
8203 GtkIconViewAccessible *view;
8206 * The scrollbars have changed
8208 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8209 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8211 gtk_icon_view_accessible_traverse_items (view, NULL);
8215 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8216 GtkAdjustment *hadj,
8217 GtkAdjustment *vadj)
8220 GtkIconViewAccessiblePrivate *priv;
8222 atk_obj = gtk_widget_get_accessible (widget);
8223 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8225 if (priv->old_hadj != hadj)
8229 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8230 (gpointer *)&priv->old_hadj);
8232 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8233 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8236 priv->old_hadj = hadj;
8239 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8240 (gpointer *)&priv->old_hadj);
8241 g_signal_connect (hadj,
8243 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8247 if (priv->old_vadj != vadj)
8251 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8252 (gpointer *)&priv->old_vadj);
8254 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8255 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8258 priv->old_vadj = vadj;
8261 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8262 (gpointer *)&priv->old_vadj);
8263 g_signal_connect (vadj,
8265 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8272 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8279 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8280 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8286 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8291 GtkIconViewAccessiblePrivate *priv;
8292 GtkIconViewItemAccessibleInfo *info;
8293 GtkIconViewAccessible *view;
8294 GtkIconViewItemAccessible *item;
8300 index = gtk_tree_path_get_indices(path)[0];
8301 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8302 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8303 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8305 items = priv->items;
8310 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8311 if (info->index != item->item->index)
8313 if (info->index < index)
8314 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8316 if (tmp_list == NULL)
8319 info->index = item->item->index;
8322 items = items->next;
8324 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8325 g_signal_emit_by_name (atk_obj, "children_changed::add",
8331 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8335 GtkIconViewAccessiblePrivate *priv;
8336 GtkIconViewItemAccessibleInfo *info;
8337 GtkIconViewAccessible *view;
8338 GtkIconViewItemAccessible *item;
8341 GList *deleted_item;
8345 index = gtk_tree_path_get_indices(path)[0];
8346 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8347 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8348 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8350 items = priv->items;
8352 deleted_item = NULL;
8357 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8358 if (info->index == index)
8360 deleted_item = items;
8362 if (info->index != item->item->index)
8364 if (tmp_list == NULL)
8367 info->index = item->item->index;
8370 items = items->next;
8372 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8375 info = deleted_item->data;
8376 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8378 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8382 priv->items = g_list_remove_link (priv->items, deleted_item);
8390 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8391 GtkIconViewItemAccessibleInfo *i2)
8393 return i1->index - i2->index;
8397 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8403 GtkIconViewAccessiblePrivate *priv;
8404 GtkIconViewItemAccessibleInfo *info;
8405 GtkIconViewAccessible *view;
8406 GtkIconView *icon_view;
8407 GtkIconViewItemAccessible *item;
8412 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8413 icon_view = GTK_ICON_VIEW (user_data);
8414 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8415 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8417 items = priv->items;
8422 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8423 info->index = new_order[info->index];
8424 tmp_list = g_list_nth (icon_view->priv->items, info->index);
8425 item->item = tmp_list->data;
8426 items = items->next;
8428 priv->items = g_list_sort (priv->items,
8429 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8435 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8440 obj = G_OBJECT (model);
8441 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8442 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8443 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8444 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8448 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8452 obj = G_OBJECT (icon_view->priv->model);
8453 g_signal_connect_data (obj, "row-changed",
8454 (GCallback) gtk_icon_view_accessible_model_row_changed,
8455 icon_view, NULL, 0);
8456 g_signal_connect_data (obj, "row-inserted",
8457 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8458 icon_view, NULL, G_CONNECT_AFTER);
8459 g_signal_connect_data (obj, "row-deleted",
8460 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8461 icon_view, NULL, G_CONNECT_AFTER);
8462 g_signal_connect_data (obj, "rows-reordered",
8463 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8464 icon_view, NULL, G_CONNECT_AFTER);
8468 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8470 GtkIconViewItemAccessibleInfo *info;
8473 items = priv->items;
8476 info = (GtkIconViewItemAccessibleInfo *) items->data;
8477 g_object_unref (info->item);
8478 g_free (items->data);
8479 items = items->next;
8481 g_list_free (priv->items);
8486 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8489 GtkIconView *icon_view;
8492 GtkIconViewAccessible *view;
8493 GtkIconViewAccessiblePrivate *priv;
8495 if (strcmp (pspec->name, "model") == 0)
8497 widget = GTK_WIDGET (obj);
8498 atk_obj = gtk_widget_get_accessible (widget);
8499 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8500 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8503 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8504 (gpointer *)&priv->model);
8505 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8507 gtk_icon_view_accessible_clear_cache (priv);
8509 icon_view = GTK_ICON_VIEW (obj);
8510 priv->model = icon_view->priv->model;
8511 /* If there is no model the GtkIconView is probably being destroyed */
8514 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8515 gtk_icon_view_accessible_connect_model_signals (icon_view);
8523 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8526 GtkIconViewAccessiblePrivate *priv;
8527 GtkIconView *icon_view;
8529 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8530 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8532 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8533 g_object_set_qdata (G_OBJECT (accessible),
8534 accessible_private_data_quark,
8537 icon_view = GTK_ICON_VIEW (data);
8538 if (icon_view->priv->hadjustment)
8540 priv->old_hadj = icon_view->priv->hadjustment;
8541 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
8542 g_signal_connect (icon_view->priv->hadjustment,
8544 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8547 if (icon_view->priv->vadjustment)
8549 priv->old_vadj = icon_view->priv->vadjustment;
8550 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
8551 g_signal_connect (icon_view->priv->vadjustment,
8553 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8556 g_signal_connect_after (data,
8557 "set_scroll_adjustments",
8558 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
8560 g_signal_connect (data,
8562 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8565 priv->model = icon_view->priv->model;
8568 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8569 gtk_icon_view_accessible_connect_model_signals (icon_view);
8572 accessible->role = ATK_ROLE_LAYERED_PANE;
8576 gtk_icon_view_accessible_finalize (GObject *object)
8578 GtkIconViewAccessiblePrivate *priv;
8580 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8581 gtk_icon_view_accessible_clear_cache (priv);
8585 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8589 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8590 GtkAccessible *accessible)
8593 GtkIconViewAccessiblePrivate *priv;
8595 atk_obj = ATK_OBJECT (accessible);
8596 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8599 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8600 (gpointer *)&priv->old_hadj);
8602 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8603 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8605 priv->old_hadj = NULL;
8609 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8610 (gpointer *)&priv->old_vadj);
8612 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8613 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8615 priv->old_vadj = NULL;
8620 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8622 if (accessible->widget)
8624 g_signal_connect_after (accessible->widget,
8626 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8629 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8633 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8635 GObjectClass *gobject_class;
8636 GtkAccessibleClass *accessible_class;
8638 accessible_parent_class = g_type_class_peek_parent (klass);
8640 gobject_class = (GObjectClass *)klass;
8641 accessible_class = (GtkAccessibleClass *)klass;
8643 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8645 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8646 klass->ref_child = gtk_icon_view_accessible_ref_child;
8647 klass->initialize = gtk_icon_view_accessible_initialize;
8649 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8651 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8655 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8658 AtkCoordType coord_type)
8661 GtkIconView *icon_view;
8662 GtkIconViewItem *item;
8665 widget = GTK_ACCESSIBLE (component)->widget;
8667 /* State is defunct */
8670 icon_view = GTK_ICON_VIEW (widget);
8671 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8672 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8674 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8680 atk_component_interface_init (AtkComponentIface *iface)
8682 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8686 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8690 GtkIconView *icon_view;
8691 GtkIconViewItem *item;
8694 widget = GTK_ACCESSIBLE (selection)->widget;
8698 icon_view = GTK_ICON_VIEW (widget);
8700 l = g_list_nth (icon_view->priv->items, i);
8705 gtk_icon_view_select_item (icon_view, item);
8711 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8714 GtkIconView *icon_view;
8716 widget = GTK_ACCESSIBLE (selection)->widget;
8720 icon_view = GTK_ICON_VIEW (widget);
8721 gtk_icon_view_unselect_all (icon_view);
8727 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8731 GtkIconView *icon_view;
8732 GtkIconViewItem *item;
8735 widget = GTK_ACCESSIBLE (selection)->widget;
8739 icon_view = GTK_ICON_VIEW (widget);
8741 l = icon_view->priv->items;
8748 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8759 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8762 GtkIconView *icon_view;
8763 GtkIconViewItem *item;
8767 widget = GTK_ACCESSIBLE (selection)->widget;
8771 icon_view = GTK_ICON_VIEW (widget);
8773 l = icon_view->priv->items;
8789 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
8793 GtkIconView *icon_view;
8794 GtkIconViewItem *item;
8797 widget = GTK_ACCESSIBLE (selection)->widget;
8801 icon_view = GTK_ICON_VIEW (widget);
8802 l = g_list_nth (icon_view->priv->items, i);
8808 return item->selected;
8812 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
8816 GtkIconView *icon_view;
8817 GtkIconViewItem *item;
8821 widget = GTK_ACCESSIBLE (selection)->widget;
8825 icon_view = GTK_ICON_VIEW (widget);
8826 l = icon_view->priv->items;
8835 gtk_icon_view_unselect_item (icon_view, item);
8847 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
8850 GtkIconView *icon_view;
8852 widget = GTK_ACCESSIBLE (selection)->widget;
8856 icon_view = GTK_ICON_VIEW (widget);
8857 gtk_icon_view_select_all (icon_view);
8862 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
8864 iface->add_selection = gtk_icon_view_accessible_add_selection;
8865 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
8866 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
8867 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
8868 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
8869 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
8870 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
8874 gtk_icon_view_accessible_get_type (void)
8876 static GType type = 0;
8880 static GTypeInfo tinfo =
8883 (GBaseInitFunc) NULL, /* base init */
8884 (GBaseFinalizeFunc) NULL, /* base finalize */
8885 (GClassInitFunc) gtk_icon_view_accessible_class_init,
8886 (GClassFinalizeFunc) NULL, /* class finalize */
8887 NULL, /* class data */
8888 0, /* instance size */
8889 0, /* nb preallocs */
8890 (GInstanceInitFunc) NULL, /* instance init */
8891 NULL /* value table */
8893 static const GInterfaceInfo atk_component_info =
8895 (GInterfaceInitFunc) atk_component_interface_init,
8896 (GInterfaceFinalizeFunc) NULL,
8899 static const GInterfaceInfo atk_selection_info =
8901 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
8902 (GInterfaceFinalizeFunc) NULL,
8907 * Figure out the size of the class and instance
8908 * we are deriving from
8910 AtkObjectFactory *factory;
8913 GType derived_atk_type;
8915 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
8916 factory = atk_registry_get_factory (atk_get_default_registry (),
8918 derived_atk_type = atk_object_factory_get_accessible_type (factory);
8919 g_type_query (derived_atk_type, &query);
8920 tinfo.class_size = query.class_size;
8921 tinfo.instance_size = query.instance_size;
8923 type = g_type_register_static (derived_atk_type,
8924 "GtkIconViewAccessible",
8926 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8927 &atk_component_info);
8928 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
8929 &atk_selection_info);
8935 gtk_icon_view_accessible_new (GObject *obj)
8937 AtkObject *accessible;
8939 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
8941 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
8942 atk_object_initialize (accessible, obj);
8948 gtk_icon_view_accessible_factory_get_accessible_type (void)
8950 return gtk_icon_view_accessible_get_type ();
8954 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
8956 return gtk_icon_view_accessible_new (obj);
8960 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
8962 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
8963 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
8967 gtk_icon_view_accessible_factory_get_type (void)
8969 static GType type = 0;
8973 static const GTypeInfo tinfo =
8975 sizeof (AtkObjectFactoryClass),
8976 NULL, /* base_init */
8977 NULL, /* base_finalize */
8978 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
8979 NULL, /* class_finalize */
8980 NULL, /* class_data */
8981 sizeof (AtkObjectFactory),
8982 0, /* n_preallocs */
8986 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
8987 "GtkIconViewAccessibleFactory",
8995 gtk_icon_view_get_accessible (GtkWidget *widget)
8997 static gboolean first_time = TRUE;
9001 AtkObjectFactory *factory;
9002 AtkRegistry *registry;
9004 GType derived_atk_type;
9007 * Figure out whether accessibility is enabled by looking at the
9008 * type of the accessible object which would be created for
9009 * the parent type of GtkIconView.
9011 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
9013 registry = atk_get_default_registry ();
9014 factory = atk_registry_get_factory (registry,
9016 derived_atk_type = atk_object_factory_get_accessible_type (factory);
9017 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
9018 atk_registry_set_factory_type (registry,
9020 gtk_icon_view_accessible_factory_get_type ());
9023 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
9026 #define __GTK_ICON_VIEW_C__
9027 #include "gtkaliasdef.c"