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[i].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[i].x, &item->box[i].y,
2677 &item->box[i].width, &item->box[i].height);
2678 item->box[i].x += cell_area.x;
2679 item->box[i].y += cell_area.y;
2681 if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2683 item->before[i] = item->box[i].x - cell_area.x;
2684 item->after[i] = cell_area.width - item->box[i].width - item->before[i];
2685 cell_area.x += cell_area.width + spacing;
2689 item->before[i] = item->box[i].y - cell_area.y;
2690 item->after[i] = cell_area.height - item->box[i].height - item->before[i];
2691 cell_area.y += cell_area.height + spacing;
2695 if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
2697 for (i = 0; i < icon_view->priv->n_cells; i++)
2699 item->box[i].x = item->x + item->width -
2700 (item->box[i].x + item->box[i].width - item->x);
2706 gtk_icon_view_invalidate_sizes (GtkIconView *icon_view)
2708 g_list_foreach (icon_view->priv->items,
2709 (GFunc)gtk_icon_view_item_invalidate_size, NULL);
2713 gtk_icon_view_item_invalidate_size (GtkIconViewItem *item)
2720 gtk_icon_view_paint_item (GtkIconView *icon_view,
2722 GtkIconViewItem *item,
2724 GdkDrawable *drawable,
2727 gboolean draw_focus)
2729 gint focus_width, focus_pad;
2730 gint spacing, padding;
2731 GdkRectangle cell_area, box;
2736 GtkCellRendererState flags;
2738 if (icon_view->priv->model == NULL)
2741 gtk_icon_view_set_cell_data (icon_view, item);
2743 rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
2745 gtk_widget_style_get (GTK_WIDGET (icon_view),
2746 "focus-line-width", &focus_width,
2747 "focus-padding", &focus_pad,
2750 spacing = icon_view->priv->spacing;
2751 padding = focus_width;
2755 flags = GTK_CELL_RENDERER_SELECTED;
2756 if (GTK_WIDGET_HAS_FOCUS (icon_view))
2757 state = GTK_STATE_SELECTED;
2759 state = GTK_STATE_ACTIVE;
2764 state = GTK_STATE_NORMAL;
2767 #ifdef DEBUG_ICON_VIEW
2768 gdk_draw_rectangle (drawable,
2769 GTK_WIDGET (icon_view)->style->black_gc,
2772 item->width, item->height);
2776 for (l = icon_view->priv->cell_list; l; l = l->next)
2778 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2780 if (!info->cell->visible)
2783 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2785 /* FIXME we hardwire background drawing behind text
2786 * cell renderers here
2788 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
2790 gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
2791 cairo_rectangle (cr,
2792 x - item->x + box.x,
2793 y - item->y + box.y,
2794 box.width, box.height);
2799 for (l = icon_view->priv->cell_list; l; l = l->next)
2801 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2803 if (!info->cell->visible)
2806 gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
2808 #ifdef DEBUG_ICON_VIEW
2809 gdk_draw_rectangle (drawable,
2810 GTK_WIDGET (icon_view)->style->black_gc,
2812 x - item->x + cell_area.x,
2813 y - item->y + cell_area.y,
2814 cell_area.width, cell_area.height);
2816 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2818 gdk_draw_rectangle (drawable,
2819 GTK_WIDGET (icon_view)->style->black_gc,
2821 x - item->x + box.x,
2822 y - item->y + box.y,
2823 box.width, box.height);
2826 cell_area.x = x - item->x + cell_area.x;
2827 cell_area.y = y - item->y + cell_area.y;
2829 gtk_cell_renderer_render (info->cell,
2831 GTK_WIDGET (icon_view),
2832 &cell_area, &cell_area, area, flags);
2836 /* FIXME where to draw the focus with generic cell renderers ? */
2838 GTK_WIDGET_HAS_FOCUS (icon_view) &&
2839 item == icon_view->priv->cursor_item)
2840 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
2842 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
2844 if (!info->cell->visible)
2847 if (icon_view->priv->cursor_cell < 0 &&
2848 (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
2849 GTK_IS_CELL_RENDERER_TEXT (info->cell)))
2850 icon_view->priv->cursor_cell = i;
2852 if (i == icon_view->priv->cursor_cell)
2854 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
2856 gtk_paint_focus (GTK_WIDGET (icon_view)->style,
2860 GTK_WIDGET (icon_view),
2862 x - item->x + box.x - padding,
2863 y - item->y + box.y - padding,
2864 box.width + 2 * padding,
2865 box.height + 2 * padding);
2872 gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
2877 GdkRectangle rubber_rect;
2878 GdkColor *fill_color_gdk;
2879 guchar fill_color_alpha;
2881 rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
2882 rubber_rect.y = MIN (icon_view->priv->rubberband_y1, icon_view->priv->rubberband_y2);
2883 rubber_rect.width = ABS (icon_view->priv->rubberband_x1 - icon_view->priv->rubberband_x2) + 1;
2884 rubber_rect.height = ABS (icon_view->priv->rubberband_y1 - icon_view->priv->rubberband_y2) + 1;
2886 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
2889 gtk_widget_style_get (GTK_WIDGET (icon_view),
2890 "selection-box-color", &fill_color_gdk,
2891 "selection-box-alpha", &fill_color_alpha,
2894 if (!fill_color_gdk)
2895 fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
2897 cairo_set_source_rgba (cr,
2898 fill_color_gdk->red / 65535.,
2899 fill_color_gdk->green / 65535.,
2900 fill_color_gdk->blue / 65535.,
2901 fill_color_alpha / 255.);
2904 gdk_cairo_rectangle (cr, &rect);
2908 /* Draw the border without alpha */
2909 cairo_set_source_rgb (cr,
2910 fill_color_gdk->red / 65535.,
2911 fill_color_gdk->green / 65535.,
2912 fill_color_gdk->blue / 65535.);
2913 cairo_rectangle (cr,
2914 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
2915 rubber_rect.width - 1, rubber_rect.height - 1);
2919 gdk_color_free (fill_color_gdk);
2923 gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
2929 index = gtk_tree_path_get_indices (path)[0];
2931 for (l = icon_view->priv->items; l; l = l->next)
2933 GtkIconViewItem *item = l->data;
2935 if (item->index == index)
2937 gtk_icon_view_queue_draw_item (icon_view, item);
2944 gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
2945 GtkIconViewItem *item)
2950 gtk_widget_style_get (GTK_WIDGET (icon_view),
2951 "focus-line-width", &focus_width,
2954 rect.x = item->x - focus_width;
2955 rect.y = item->y - focus_width;
2956 rect.width = item->width + 2 * focus_width;
2957 rect.height = item->height + 2 * focus_width;
2959 if (icon_view->priv->bin_window)
2960 gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
2964 layout_callback (gpointer user_data)
2966 GtkIconView *icon_view;
2968 GDK_THREADS_ENTER ();
2970 icon_view = GTK_ICON_VIEW (user_data);
2972 icon_view->priv->layout_idle_id = 0;
2974 gtk_icon_view_layout (icon_view);
2976 GDK_THREADS_LEAVE();
2982 gtk_icon_view_queue_layout (GtkIconView *icon_view)
2984 if (icon_view->priv->layout_idle_id != 0)
2987 icon_view->priv->layout_idle_id = g_idle_add (layout_callback, icon_view);
2991 gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
2992 GtkIconViewItem *item,
2996 AtkObject *item_obj;
2998 if (icon_view->priv->cursor_item == item &&
2999 (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
3002 if (icon_view->priv->cursor_item != NULL)
3003 gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
3005 icon_view->priv->cursor_item = item;
3006 if (cursor_cell >= 0)
3007 icon_view->priv->cursor_cell = cursor_cell;
3009 gtk_icon_view_queue_draw_item (icon_view, item);
3011 /* Notify that accessible focus object has changed */
3012 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
3013 item_obj = atk_object_ref_accessible_child (obj, item->index);
3015 if (item_obj != NULL)
3017 atk_focus_tracker_notify (item_obj);
3018 g_object_unref (item_obj);
3023 static GtkIconViewItem *
3024 gtk_icon_view_item_new (void)
3026 GtkIconViewItem *item;
3028 item = g_new0 (GtkIconViewItem, 1);
3037 gtk_icon_view_item_free (GtkIconViewItem *item)
3039 g_return_if_fail (item != NULL);
3041 g_free (item->before);
3042 g_free (item->after);
3049 static GtkIconViewItem *
3050 gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
3053 gboolean only_in_cell,
3054 GtkIconViewCellInfo **cell_at_pos)
3059 for (items = icon_view->priv->items; items; items = items->next)
3061 GtkIconViewItem *item = items->data;
3063 if (x >= item->x - icon_view->priv->row_spacing/2 && x <= item->x + item->width + icon_view->priv->row_spacing/2 &&
3064 y >= item->y - icon_view->priv->column_spacing/2 && y <= item->y + item->height + icon_view->priv->column_spacing/2)
3066 if (only_in_cell || cell_at_pos)
3068 gtk_icon_view_set_cell_data (icon_view, item);
3070 for (l = icon_view->priv->cell_list; l; l = l->next)
3072 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3074 if (!info->cell->visible)
3077 gtk_icon_view_get_cell_box (icon_view, item, info, &box);
3079 if ((x >= box.x && x <= box.x + box.width &&
3080 y >= box.y && y <= box.y + box.height) ||
3082 x <= box.x + box.width &&
3084 y <= box.y + box.height))
3087 *cell_at_pos = info;
3097 *cell_at_pos = NULL;
3108 gtk_icon_view_select_item (GtkIconView *icon_view,
3109 GtkIconViewItem *item)
3111 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3112 g_return_if_fail (item != NULL);
3117 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
3119 else if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3120 gtk_icon_view_unselect_all_internal (icon_view);
3122 item->selected = TRUE;
3124 gtk_icon_view_queue_draw_item (icon_view, item);
3126 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3131 gtk_icon_view_unselect_item (GtkIconView *icon_view,
3132 GtkIconViewItem *item)
3134 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3135 g_return_if_fail (item != NULL);
3137 if (!item->selected)
3140 if (icon_view->priv->selection_mode == GTK_SELECTION_NONE ||
3141 icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
3144 item->selected = FALSE;
3146 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3148 gtk_icon_view_queue_draw_item (icon_view, item);
3152 verify_items (GtkIconView *icon_view)
3157 for (items = icon_view->priv->items; items; items = items->next)
3159 GtkIconViewItem *item = items->data;
3161 if (item->index != i)
3162 g_error ("List item does not match its index: "
3163 "item index %d and list index %d\n", item->index, i);
3170 gtk_icon_view_row_changed (GtkTreeModel *model,
3175 GtkIconViewItem *item;
3177 GtkIconView *icon_view;
3179 icon_view = GTK_ICON_VIEW (data);
3181 gtk_icon_view_stop_editing (icon_view, TRUE);
3183 index = gtk_tree_path_get_indices(path)[0];
3184 item = g_list_nth_data (icon_view->priv->items, index);
3186 gtk_icon_view_item_invalidate_size (item);
3187 gtk_icon_view_queue_layout (icon_view);
3189 verify_items (icon_view);
3193 gtk_icon_view_row_inserted (GtkTreeModel *model,
3199 GtkIconViewItem *item;
3200 gboolean iters_persist;
3201 GtkIconView *icon_view;
3204 icon_view = GTK_ICON_VIEW (data);
3206 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3208 length = gtk_tree_model_iter_n_children (model, NULL);
3209 index = gtk_tree_path_get_indices(path)[0];
3211 item = gtk_icon_view_item_new ();
3216 item->index = index;
3218 /* FIXME: We can be more efficient here,
3219 we can store a tail pointer and use that when
3220 appending (which is a rather common operation)
3222 icon_view->priv->items = g_list_insert (icon_view->priv->items,
3225 list = g_list_nth (icon_view->priv->items, index + 1);
3226 for (; list; list = list->next)
3233 verify_items (icon_view);
3237 gtk_icon_view_row_deleted (GtkTreeModel *model,
3242 GtkIconView *icon_view;
3243 GtkIconViewItem *item;
3245 gboolean emit = FALSE;
3247 icon_view = GTK_ICON_VIEW (data);
3249 index = gtk_tree_path_get_indices(path)[0];
3251 list = g_list_nth (icon_view->priv->items, index);
3254 gtk_icon_view_stop_editing (icon_view, TRUE);
3256 if (item == icon_view->priv->anchor_item)
3257 icon_view->priv->anchor_item = NULL;
3259 if (item == icon_view->priv->cursor_item)
3260 icon_view->priv->cursor_item = NULL;
3265 gtk_icon_view_item_free (item);
3267 for (next = list->next; next; next = next->next)
3274 icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
3276 gtk_icon_view_queue_layout (icon_view);
3278 verify_items (icon_view);
3281 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3285 gtk_icon_view_rows_reordered (GtkTreeModel *model,
3286 GtkTreePath *parent,
3293 GtkIconView *icon_view;
3294 GList *items = NULL, *list;
3295 GtkIconViewItem **item_array;
3298 icon_view = GTK_ICON_VIEW (data);
3300 gtk_icon_view_stop_editing (icon_view, TRUE);
3302 length = gtk_tree_model_iter_n_children (model, NULL);
3304 order = g_new (gint, length);
3305 for (i = 0; i < length; i++)
3306 order [new_order[i]] = i;
3308 item_array = g_new (GtkIconViewItem *, length);
3309 for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
3310 item_array[order[i]] = list->data;
3313 for (i = length - 1; i >= 0; i--)
3315 item_array[i]->index = i;
3316 items = g_list_prepend (items, item_array[i]);
3319 g_free (item_array);
3320 g_list_free (icon_view->priv->items);
3321 icon_view->priv->items = items;
3323 gtk_icon_view_queue_layout (icon_view);
3325 verify_items (icon_view);
3329 gtk_icon_view_build_items (GtkIconView *icon_view)
3333 gboolean iters_persist;
3334 GList *items = NULL;
3336 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3338 if (!gtk_tree_model_get_iter_first (icon_view->priv->model,
3346 GtkIconViewItem *item = gtk_icon_view_item_new ();
3355 items = g_list_prepend (items, item);
3357 } while (gtk_tree_model_iter_next (icon_view->priv->model, &iter));
3359 icon_view->priv->items = g_list_reverse (items);
3363 gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
3366 GtkMovementStep step,
3370 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
3375 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
3380 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3383 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
3388 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
3395 gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
3396 GtkMovementStep step,
3399 GdkModifierType state;
3401 g_return_val_if_fail (GTK_ICON_VIEW (icon_view), FALSE);
3402 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
3403 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
3404 step == GTK_MOVEMENT_DISPLAY_LINES ||
3405 step == GTK_MOVEMENT_PAGES ||
3406 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
3408 if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
3411 gtk_icon_view_stop_editing (icon_view, FALSE);
3412 gtk_widget_grab_focus (GTK_WIDGET (icon_view));
3414 if (gtk_get_current_event_state (&state))
3416 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
3417 icon_view->priv->ctrl_pressed = TRUE;
3418 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
3419 icon_view->priv->shift_pressed = TRUE;
3421 /* else we assume not pressed */
3425 case GTK_MOVEMENT_LOGICAL_POSITIONS:
3426 case GTK_MOVEMENT_VISUAL_POSITIONS:
3427 gtk_icon_view_move_cursor_left_right (icon_view, count);
3429 case GTK_MOVEMENT_DISPLAY_LINES:
3430 gtk_icon_view_move_cursor_up_down (icon_view, count);
3432 case GTK_MOVEMENT_PAGES:
3433 gtk_icon_view_move_cursor_page_up_down (icon_view, count);
3435 case GTK_MOVEMENT_BUFFER_ENDS:
3436 gtk_icon_view_move_cursor_start_end (icon_view, count);
3439 g_assert_not_reached ();
3442 icon_view->priv->ctrl_pressed = FALSE;
3443 icon_view->priv->shift_pressed = FALSE;
3448 static GtkIconViewItem *
3449 find_item (GtkIconView *icon_view,
3450 GtkIconViewItem *current,
3456 GtkIconViewItem *item;
3458 /* FIXME: this could be more efficient
3460 row = current->row + row_ofs;
3461 col = current->col + col_ofs;
3463 for (items = icon_view->priv->items; items; items = items->next)
3466 if (item->row == row && item->col == col)
3474 find_cell (GtkIconView *icon_view,
3475 GtkIconViewItem *item,
3477 GtkOrientation orientation,
3488 if (icon_view->priv->orientation != orientation)
3491 gtk_icon_view_set_cell_data (icon_view, item);
3493 focusable = g_new0 (gint, icon_view->priv->n_cells);
3498 for (k = 0; k < 2; k++)
3499 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
3501 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
3503 if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
3506 if (!info->cell->visible)
3509 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
3512 if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
3515 current = n_focusable;
3517 focusable[n_focusable] = i;
3523 if (n_focusable == 0)
3524 focusable[n_focusable++] = first_text;
3528 current = step > 0 ? 0 : n_focusable - 1;
3529 cell = focusable[current];
3532 if (current + *count < 0)
3535 *count = current + *count;
3537 else if (current + *count > n_focusable - 1)
3540 *count = current + *count - (n_focusable - 1);
3544 cell = focusable[current + *count];
3553 static GtkIconViewItem *
3554 find_item_page_up_down (GtkIconView *icon_view,
3555 GtkIconViewItem *current,
3562 y = current->y + count * icon_view->priv->vadjustment->page_size;
3564 item = g_list_find (icon_view->priv->items, current);
3569 for (next = item->next; next; next = next->next)
3571 if (((GtkIconViewItem *)next->data)->col == col)
3574 if (!next || ((GtkIconViewItem *)next->data)->y > y)
3584 for (next = item->prev; next; next = next->prev)
3586 if (((GtkIconViewItem *)next->data)->col == col)
3589 if (!next || ((GtkIconViewItem *)next->data)->y < y)
3603 gtk_icon_view_select_all_between (GtkIconView *icon_view,
3604 GtkIconViewItem *anchor,
3605 GtkIconViewItem *cursor)
3608 GtkIconViewItem *item;
3609 gint row1, row2, col1, col2;
3610 gboolean dirty = FALSE;
3612 if (anchor->row < cursor->row)
3623 if (anchor->col < cursor->col)
3634 for (items = icon_view->priv->items; items; items = items->next)
3638 if (row1 <= item->row && item->row <= row2 &&
3639 col1 <= item->col && item->col <= col2)
3641 if (!item->selected)
3644 item->selected = TRUE;
3646 gtk_icon_view_queue_draw_item (icon_view, item);
3654 gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
3657 GtkIconViewItem *item;
3659 gboolean dirty = FALSE;
3662 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3665 if (!icon_view->priv->cursor_item)
3670 list = icon_view->priv->items;
3672 list = g_list_last (icon_view->priv->items);
3674 item = list ? list->data : NULL;
3679 item = icon_view->priv->cursor_item;
3680 cell = icon_view->priv->cursor_cell;
3681 step = count > 0 ? 1 : -1;
3684 cell = find_cell (icon_view, item, cell,
3685 GTK_ORIENTATION_VERTICAL,
3690 item = find_item (icon_view, item, step, 0);
3691 count = count - step;
3698 if (icon_view->priv->ctrl_pressed ||
3699 !icon_view->priv->shift_pressed ||
3700 !icon_view->priv->anchor_item ||
3701 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3702 icon_view->priv->anchor_item = item;
3704 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3706 if (!icon_view->priv->ctrl_pressed &&
3707 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3709 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3710 dirty = gtk_icon_view_select_all_between (icon_view,
3711 icon_view->priv->anchor_item,
3715 gtk_icon_view_scroll_to_item (icon_view, item);
3718 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3722 gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
3725 GtkIconViewItem *item;
3726 gboolean dirty = FALSE;
3728 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3731 if (!icon_view->priv->cursor_item)
3736 list = icon_view->priv->items;
3738 list = g_list_last (icon_view->priv->items);
3740 item = list ? list->data : NULL;
3743 item = find_item_page_up_down (icon_view,
3744 icon_view->priv->cursor_item,
3750 if (icon_view->priv->ctrl_pressed ||
3751 !icon_view->priv->shift_pressed ||
3752 !icon_view->priv->anchor_item ||
3753 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3754 icon_view->priv->anchor_item = item;
3756 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3758 if (!icon_view->priv->ctrl_pressed &&
3759 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3761 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3762 dirty = gtk_icon_view_select_all_between (icon_view,
3763 icon_view->priv->anchor_item,
3767 gtk_icon_view_scroll_to_item (icon_view, item);
3770 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3774 gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
3777 GtkIconViewItem *item;
3779 gboolean dirty = FALSE;
3782 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3785 if (!icon_view->priv->cursor_item)
3790 list = icon_view->priv->items;
3792 list = g_list_last (icon_view->priv->items);
3794 item = list ? list->data : NULL;
3798 item = icon_view->priv->cursor_item;
3799 cell = icon_view->priv->cursor_cell;
3800 step = count > 0 ? 1 : -1;
3803 cell = find_cell (icon_view, item, cell,
3804 GTK_ORIENTATION_HORIZONTAL,
3809 item = find_item (icon_view, item, 0, step);
3810 count = count - step;
3817 if (icon_view->priv->ctrl_pressed ||
3818 !icon_view->priv->shift_pressed ||
3819 !icon_view->priv->anchor_item ||
3820 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3821 icon_view->priv->anchor_item = item;
3823 gtk_icon_view_set_cursor_item (icon_view, item, cell);
3825 if (!icon_view->priv->ctrl_pressed &&
3826 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3828 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3829 dirty = gtk_icon_view_select_all_between (icon_view,
3830 icon_view->priv->anchor_item,
3834 gtk_icon_view_scroll_to_item (icon_view, item);
3837 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3841 gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
3844 GtkIconViewItem *item;
3846 gboolean dirty = FALSE;
3848 if (!GTK_WIDGET_HAS_FOCUS (icon_view))
3852 list = icon_view->priv->items;
3854 list = g_list_last (icon_view->priv->items);
3856 item = list ? list->data : NULL;
3861 if (icon_view->priv->ctrl_pressed ||
3862 !icon_view->priv->shift_pressed ||
3863 !icon_view->priv->anchor_item ||
3864 icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
3865 icon_view->priv->anchor_item = item;
3867 gtk_icon_view_set_cursor_item (icon_view, item, -1);
3869 if (!icon_view->priv->ctrl_pressed &&
3870 icon_view->priv->selection_mode != GTK_SELECTION_NONE)
3872 dirty = gtk_icon_view_unselect_all_internal (icon_view);
3873 dirty = gtk_icon_view_select_all_between (icon_view,
3874 icon_view->priv->anchor_item,
3878 gtk_icon_view_scroll_to_item (icon_view, item);
3881 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
3885 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
3886 GtkIconViewItem *item)
3888 gint x, y, width, height;
3891 gtk_widget_style_get (GTK_WIDGET (icon_view),
3892 "focus-line-width", &focus_width,
3895 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
3897 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
3899 if (y + item->y - focus_width < 0)
3900 gtk_adjustment_set_value (icon_view->priv->vadjustment,
3901 icon_view->priv->vadjustment->value + y + item->y - focus_width);
3902 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
3903 gtk_adjustment_set_value (icon_view->priv->vadjustment,
3904 icon_view->priv->vadjustment->value + y + item->y + item->height
3905 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
3907 if (x + item->x - focus_width < 0)
3908 gtk_adjustment_set_value (icon_view->priv->hadjustment,
3909 icon_view->priv->hadjustment->value + x + item->x - focus_width);
3910 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
3911 gtk_adjustment_set_value (icon_view->priv->hadjustment,
3912 icon_view->priv->hadjustment->value + x + item->x + item->width
3913 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
3915 gtk_adjustment_changed (icon_view->priv->hadjustment);
3916 gtk_adjustment_changed (icon_view->priv->vadjustment);
3919 /* GtkCellLayout implementation */
3920 static GtkIconViewCellInfo *
3921 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
3922 GtkCellRenderer *renderer)
3926 for (i = icon_view->priv->cell_list; i; i = i->next)
3928 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
3930 if (info->cell == renderer)
3938 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
3939 GtkIconViewItem *item)
3942 gboolean iters_persist;
3945 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
3951 path = gtk_tree_path_new_from_indices (item->index, -1);
3952 gtk_tree_model_get_iter (icon_view->priv->model, &iter, path);
3953 gtk_tree_path_free (path);
3958 for (i = icon_view->priv->cell_list; i; i = i->next)
3961 GtkIconViewCellInfo *info = i->data;
3963 g_object_freeze_notify (G_OBJECT (info->cell));
3965 for (j = info->attributes; j && j->next; j = j->next->next)
3967 gchar *property = j->data;
3968 gint column = GPOINTER_TO_INT (j->next->data);
3969 GValue value = {0, };
3971 gtk_tree_model_get_value (icon_view->priv->model, &iter,
3973 g_object_set_property (G_OBJECT (info->cell),
3975 g_value_unset (&value);
3979 (* info->func) (GTK_CELL_LAYOUT (icon_view),
3981 icon_view->priv->model,
3985 g_object_thaw_notify (G_OBJECT (info->cell));
3988 adjust_wrap_width (icon_view, item);
3992 free_cell_attributes (GtkIconViewCellInfo *info)
3996 list = info->attributes;
3997 while (list && list->next)
3999 g_free (list->data);
4000 list = list->next->next;
4003 g_slist_free (info->attributes);
4004 info->attributes = NULL;
4008 free_cell_info (GtkIconViewCellInfo *info)
4010 free_cell_attributes (info);
4012 g_object_unref (info->cell);
4015 (* info->destroy) (info->func_data);
4021 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4022 GtkCellRenderer *renderer,
4025 GtkIconViewCellInfo *info;
4026 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4028 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4029 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4031 g_object_ref (renderer);
4032 gtk_object_sink (GTK_OBJECT (renderer));
4034 info = g_new0 (GtkIconViewCellInfo, 1);
4035 info->cell = renderer;
4036 info->expand = expand ? TRUE : FALSE;
4037 info->pack = GTK_PACK_START;
4038 info->position = icon_view->priv->n_cells;
4040 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4041 icon_view->priv->n_cells++;
4045 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4046 GtkCellRenderer *renderer,
4049 GtkIconViewCellInfo *info;
4050 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4052 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4053 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4055 g_object_ref (renderer);
4056 gtk_object_sink (GTK_OBJECT (renderer));
4058 info = g_new0 (GtkIconViewCellInfo, 1);
4059 info->cell = renderer;
4060 info->expand = expand ? TRUE : FALSE;
4061 info->pack = GTK_PACK_END;
4062 info->position = icon_view->priv->n_cells;
4064 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4065 icon_view->priv->n_cells++;
4069 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4070 GtkCellRenderer *renderer,
4071 const gchar *attribute,
4074 GtkIconViewCellInfo *info;
4075 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4077 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4078 g_return_if_fail (info != NULL);
4080 info->attributes = g_slist_prepend (info->attributes,
4081 GINT_TO_POINTER (column));
4082 info->attributes = g_slist_prepend (info->attributes,
4083 g_strdup (attribute));
4087 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4089 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4091 while (icon_view->priv->cell_list)
4093 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4094 free_cell_info (info);
4095 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4096 icon_view->priv->cell_list);
4099 icon_view->priv->n_cells = 0;
4103 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4104 GtkCellRenderer *cell,
4105 GtkCellLayoutDataFunc func,
4107 GDestroyNotify destroy)
4109 GtkIconViewCellInfo *info;
4110 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4112 info = gtk_icon_view_get_cell_info (icon_view, cell);
4113 g_return_if_fail (info != NULL);
4117 GDestroyNotify d = info->destroy;
4119 info->destroy = NULL;
4120 d (info->func_data);
4124 info->func_data = func_data;
4125 info->destroy = destroy;
4129 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4130 GtkCellRenderer *renderer)
4132 GtkIconViewCellInfo *info;
4134 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4136 free_cell_attributes (info);
4140 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4141 GtkCellRenderer *cell,
4144 GtkIconView *icon_view;
4146 GtkIconViewCellInfo *info;
4149 icon_view = GTK_ICON_VIEW (layout);
4151 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4153 info = gtk_icon_view_get_cell_info (icon_view, cell);
4155 g_return_if_fail (info != NULL);
4156 g_return_if_fail (position >= 0);
4158 link = g_list_find (icon_view->priv->cell_list, info);
4160 g_return_if_fail (link != NULL);
4162 icon_view->priv->cell_list = g_list_remove_link (icon_view->priv->cell_list,
4164 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4167 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4174 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4181 * gtk_icon_view_new:
4183 * Creates a new #GtkIconView widget
4185 * Return value: A newly created #GtkIconView widget
4190 gtk_icon_view_new (void)
4192 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4196 * gtk_icon_view_new_with_model:
4197 * @model: The model.
4199 * Creates a new #GtkIconView widget with the model @model.
4201 * Return value: A newly created #GtkIconView widget.
4206 gtk_icon_view_new_with_model (GtkTreeModel *model)
4208 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4213 * gtk_icon_view_get_path_at_pos:
4214 * @icon_view: A #GtkIconView.
4215 * @x: The x position to be identified
4216 * @y: The y position to be identified
4218 * Finds the path at the point (@x, @y), relative to widget coordinates.
4219 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4220 * the cell at the specified position.
4222 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4223 * if no icon exists at that position.
4228 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4232 GtkIconViewItem *item;
4235 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4237 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4242 path = gtk_tree_path_new_from_indices (item->index, -1);
4248 * gtk_icon_view_get_item_at_pos:
4249 * @icon_view: A #GtkIconView.
4250 * @x: The x position to be identified
4251 * @y: The y position to be identified
4252 * @path: Return location for the path, or %NULL
4253 * @cell: Return location for the renderer responsible for the cell
4254 * at (@x, @y), or %NULL
4256 * Finds the path at the point (@x, @y), relative to widget coordinates.
4257 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4258 * obtains the cell at the specified position. The returned path should
4259 * be freed with gtk_tree_path_free().
4261 * Return value: %TRUE if an item exists at the specified position
4266 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4270 GtkCellRenderer **cell)
4272 GtkIconViewItem *item;
4273 GtkIconViewCellInfo *info;
4275 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4277 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4282 *path = gtk_tree_path_new_from_indices (item->index, -1);
4295 return (item != NULL);
4299 * gtk_icon_view_selected_foreach:
4300 * @icon_view: A #GtkIconView.
4301 * @func: The funcion to call for each selected icon.
4302 * @data: User data to pass to the function.
4304 * Calls a function for each selected icon. Note that the model or
4305 * selection cannot be modified from within this function.
4310 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4311 GtkIconViewForeachFunc func,
4316 for (list = icon_view->priv->items; list; list = list->next)
4318 GtkIconViewItem *item = list->data;
4319 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4322 (* func) (icon_view, path, data);
4324 gtk_tree_path_free (path);
4329 * gtk_icon_view_set_selection_mode:
4330 * @icon_view: A #GtkIconView.
4331 * @mode: The selection mode
4333 * Sets the selection mode of the @icon_view.
4338 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4339 GtkSelectionMode mode)
4341 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4343 if (mode == icon_view->priv->selection_mode)
4346 if (mode == GTK_SELECTION_NONE ||
4347 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4348 gtk_icon_view_unselect_all (icon_view);
4350 icon_view->priv->selection_mode = mode;
4352 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4356 * gtk_icon_view_get_selection_mode:
4357 * @icon_view: A #GtkIconView.
4359 * Gets the selection mode of the @icon_view.
4361 * Return value: the current selection mode
4366 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4368 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4370 return icon_view->priv->selection_mode;
4374 * gtk_icon_view_set_model:
4375 * @icon_view: A #GtkIconView.
4376 * @model: The model.
4378 * Sets the model for a #GtkIconView.
4379 * If the @icon_view already has a model set, it will remove
4380 * it before setting the new model. If @model is %NULL, then
4381 * it will unset the old model.
4386 gtk_icon_view_set_model (GtkIconView *icon_view,
4387 GtkTreeModel *model)
4389 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4390 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4392 if (icon_view->priv->model == model)
4395 gtk_icon_view_stop_editing (icon_view, TRUE);
4401 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
4403 if (icon_view->priv->pixbuf_column != -1)
4405 column_type = gtk_tree_model_get_column_type (model,
4406 icon_view->priv->pixbuf_column);
4408 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4411 if (icon_view->priv->text_column != -1)
4413 column_type = gtk_tree_model_get_column_type (model,
4414 icon_view->priv->text_column);
4416 g_return_if_fail (column_type == G_TYPE_STRING);
4419 if (icon_view->priv->markup_column != -1)
4421 column_type = gtk_tree_model_get_column_type (model,
4422 icon_view->priv->markup_column);
4424 g_return_if_fail (column_type == G_TYPE_STRING);
4429 if (icon_view->priv->model)
4431 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4432 gtk_icon_view_row_changed,
4434 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4435 gtk_icon_view_row_inserted,
4437 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4438 gtk_icon_view_row_deleted,
4440 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4441 gtk_icon_view_rows_reordered,
4444 g_object_unref (icon_view->priv->model);
4446 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4447 g_list_free (icon_view->priv->items);
4448 icon_view->priv->items = NULL;
4449 icon_view->priv->anchor_item = NULL;
4450 icon_view->priv->cursor_item = NULL;
4451 icon_view->priv->last_single_clicked = NULL;
4452 icon_view->priv->width = 0;
4453 icon_view->priv->height = 0;
4456 icon_view->priv->model = model;
4458 if (icon_view->priv->model)
4460 g_object_ref (icon_view->priv->model);
4461 g_signal_connect (icon_view->priv->model,
4463 G_CALLBACK (gtk_icon_view_row_changed),
4465 g_signal_connect (icon_view->priv->model,
4467 G_CALLBACK (gtk_icon_view_row_inserted),
4469 g_signal_connect (icon_view->priv->model,
4471 G_CALLBACK (gtk_icon_view_row_deleted),
4473 g_signal_connect (icon_view->priv->model,
4475 G_CALLBACK (gtk_icon_view_rows_reordered),
4478 gtk_icon_view_build_items (icon_view);
4480 gtk_icon_view_queue_layout (icon_view);
4483 g_object_notify (G_OBJECT (icon_view), "model");
4485 if (GTK_WIDGET_REALIZED (icon_view))
4486 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4490 * gtk_icon_view_get_model:
4491 * @icon_view: a #GtkIconView
4493 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4496 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
4501 gtk_icon_view_get_model (GtkIconView *icon_view)
4503 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4505 return icon_view->priv->model;
4509 update_text_cell (GtkIconView *icon_view)
4511 GtkIconViewCellInfo *info;
4515 if (icon_view->priv->text_column == -1 &&
4516 icon_view->priv->markup_column == -1)
4518 if (icon_view->priv->text_cell != -1)
4520 info = g_list_nth_data (icon_view->priv->cell_list,
4521 icon_view->priv->text_cell);
4523 g_list_remove (icon_view->priv->cell_list, info);
4525 free_cell_info (info);
4527 icon_view->priv->n_cells--;
4528 icon_view->priv->text_cell = -1;
4533 if (icon_view->priv->text_cell == -1)
4535 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
4536 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4537 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4540 if (info->cell == cell)
4542 icon_view->priv->text_cell = i;
4548 info = g_list_nth_data (icon_view->priv->cell_list,
4549 icon_view->priv->text_cell);
4551 if (icon_view->priv->markup_column != -1)
4552 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4554 "markup", icon_view->priv->markup_column,
4557 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4559 "text", icon_view->priv->text_column,
4562 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4563 g_object_set (info->cell,
4564 "wrap_mode", PANGO_WRAP_CHAR,
4565 "wrap_width", icon_view->priv->item_width,
4570 g_object_set (info->cell,
4571 "wrap_mode", PANGO_WRAP_CHAR,
4572 "wrap_width", icon_view->priv->item_width,
4580 update_pixbuf_cell (GtkIconView *icon_view)
4582 GtkIconViewCellInfo *info;
4586 if (icon_view->priv->pixbuf_column == -1)
4588 if (icon_view->priv->pixbuf_cell != -1)
4590 info = g_list_nth_data (icon_view->priv->cell_list,
4591 icon_view->priv->pixbuf_cell);
4593 g_list_remove (icon_view->priv->cell_list, info);
4595 free_cell_info (info);
4597 icon_view->priv->n_cells--;
4598 icon_view->priv->pixbuf_cell = -1;
4603 if (icon_view->priv->pixbuf_cell == -1)
4605 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
4607 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4608 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4611 if (info->cell == cell)
4613 icon_view->priv->pixbuf_cell = i;
4619 info = g_list_nth_data (icon_view->priv->cell_list,
4620 icon_view->priv->pixbuf_cell);
4622 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4624 "pixbuf", icon_view->priv->pixbuf_column,
4627 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4628 g_object_set (info->cell,
4629 "follow_state", TRUE,
4634 g_object_set (info->cell,
4635 "follow_state", TRUE,
4643 * gtk_icon_view_set_text_column:
4644 * @icon_view: A #GtkIconView.
4645 * @column: A column in the currently used model.
4647 * Sets the column with text for @icon_view to be @column. The text
4648 * column must be of type #G_TYPE_STRING.
4653 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4656 if (column == icon_view->priv->text_column)
4660 icon_view->priv->text_column = -1;
4663 if (icon_view->priv->model != NULL)
4667 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4669 g_return_if_fail (column_type == G_TYPE_STRING);
4672 icon_view->priv->text_column = column;
4675 gtk_icon_view_stop_editing (icon_view, TRUE);
4677 update_text_cell (icon_view);
4679 gtk_icon_view_invalidate_sizes (icon_view);
4680 gtk_icon_view_queue_layout (icon_view);
4682 g_object_notify (G_OBJECT (icon_view), "text-column");
4686 * gtk_icon_view_get_text_column:
4687 * @icon_view: A #GtkIconView.
4689 * Returns the column with text for @icon_view.
4691 * Returns: the text column, or -1 if it's unset.
4696 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4698 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4700 return icon_view->priv->text_column;
4704 * gtk_icon_view_set_markup_column:
4705 * @icon_view: A #GtkIconView.
4706 * @column: A column in the currently used model.
4708 * Sets the column with markup information for @icon_view to be
4709 * @column. The markup column must be of type #G_TYPE_STRING.
4710 * If the markup column is set to something, it overrides
4711 * the text column set by gtk_icon_view_set_text_column().
4716 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
4719 if (column == icon_view->priv->markup_column)
4723 icon_view->priv->markup_column = -1;
4726 if (icon_view->priv->model != NULL)
4730 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4732 g_return_if_fail (column_type == G_TYPE_STRING);
4735 icon_view->priv->markup_column = column;
4738 gtk_icon_view_stop_editing (icon_view, TRUE);
4740 update_text_cell (icon_view);
4742 gtk_icon_view_invalidate_sizes (icon_view);
4743 gtk_icon_view_queue_layout (icon_view);
4745 g_object_notify (G_OBJECT (icon_view), "markup-column");
4749 * gtk_icon_view_get_markup_column:
4750 * @icon_view: A #GtkIconView.
4752 * Returns the column with markup text for @icon_view.
4754 * Returns: the markup column, or -1 if it's unset.
4759 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
4761 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4763 return icon_view->priv->markup_column;
4767 * gtk_icon_view_set_pixbuf_column:
4768 * @icon_view: A #GtkIconView.
4769 * @column: A column in the currently used model.
4771 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
4772 * column must be of type #GDK_TYPE_PIXBUF
4777 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
4780 if (column == icon_view->priv->pixbuf_column)
4784 icon_view->priv->pixbuf_column = -1;
4787 if (icon_view->priv->model != NULL)
4791 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4793 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4796 icon_view->priv->pixbuf_column = column;
4799 gtk_icon_view_stop_editing (icon_view, TRUE);
4801 update_pixbuf_cell (icon_view);
4803 gtk_icon_view_invalidate_sizes (icon_view);
4804 gtk_icon_view_queue_layout (icon_view);
4806 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
4811 * gtk_icon_view_get_pixbuf_column:
4812 * @icon_view: A #GtkIconView.
4814 * Returns the column with pixbufs for @icon_view.
4816 * Returns: the pixbuf column, or -1 if it's unset.
4821 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
4823 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4825 return icon_view->priv->pixbuf_column;
4829 * gtk_icon_view_select_path:
4830 * @icon_view: A #GtkIconView.
4831 * @path: The #GtkTreePath to be selected.
4833 * Selects the row at @path.
4838 gtk_icon_view_select_path (GtkIconView *icon_view,
4843 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4844 g_return_if_fail (icon_view->priv->model != NULL);
4845 g_return_if_fail (path != NULL);
4847 l = g_list_nth (icon_view->priv->items,
4848 gtk_tree_path_get_indices(path)[0]);
4851 gtk_icon_view_select_item (icon_view, l->data);
4855 * gtk_icon_view_unselect_path:
4856 * @icon_view: A #GtkIconView.
4857 * @path: The #GtkTreePath to be unselected.
4859 * Unselects the row at @path.
4864 gtk_icon_view_unselect_path (GtkIconView *icon_view,
4867 GtkIconViewItem *item;
4869 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4870 g_return_if_fail (icon_view->priv->model != NULL);
4871 g_return_if_fail (path != NULL);
4873 item = g_list_nth (icon_view->priv->items,
4874 gtk_tree_path_get_indices(path)[0])->data;
4879 gtk_icon_view_unselect_item (icon_view, item);
4883 * gtk_icon_view_get_selected_items:
4884 * @icon_view: A #GtkIconView.
4886 * Creates a list of paths of all selected items. Additionally, if you are
4887 * planning on modifying the model after calling this function, you may
4888 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
4889 * To do this, you can use gtk_tree_row_reference_new().
4891 * To free the return value, use:
4892 * <informalexample><programlisting>
4893 * g_list_foreach (list, gtk_tree_path_free, NULL);
4894 * g_list_free (list);
4895 * </programlisting></informalexample>
4897 * Return value: A #GList containing a #GtkTreePath for each selected row.
4902 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
4905 GList *selected = NULL;
4907 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4909 for (list = icon_view->priv->items; list != NULL; list = list->next)
4911 GtkIconViewItem *item = list->data;
4915 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4917 selected = g_list_prepend (selected, path);
4925 * gtk_icon_view_select_all:
4926 * @icon_view: A #GtkIconView.
4928 * Selects all the icons. @icon_view must has its selection mode set
4929 * to #GTK_SELECTION_MULTIPLE.
4934 gtk_icon_view_select_all (GtkIconView *icon_view)
4937 gboolean dirty = FALSE;
4939 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4941 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
4944 for (items = icon_view->priv->items; items; items = items->next)
4946 GtkIconViewItem *item = items->data;
4948 if (!item->selected)
4951 item->selected = TRUE;
4952 gtk_icon_view_queue_draw_item (icon_view, item);
4957 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4961 * gtk_icon_view_unselect_all:
4962 * @icon_view: A #GtkIconView.
4964 * Unselects all the icons.
4969 gtk_icon_view_unselect_all (GtkIconView *icon_view)
4971 gboolean dirty = FALSE;
4973 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4975 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
4978 dirty = gtk_icon_view_unselect_all_internal (icon_view);
4981 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
4985 * gtk_icon_view_path_is_selected:
4986 * @icon_view: A #GtkIconView.
4987 * @path: A #GtkTreePath to check selection on.
4989 * Returns %TRUE if the icon pointed to by @path is currently
4990 * selected. If @icon does not point to a valid location, %FALSE is returned.
4992 * Return value: %TRUE if @path is selected.
4997 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5000 GtkIconViewItem *item;
5002 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5003 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5004 g_return_val_if_fail (path != NULL, FALSE);
5006 item = g_list_nth (icon_view->priv->items,
5007 gtk_tree_path_get_indices(path)[0])->data;
5012 return item->selected;
5016 * gtk_icon_view_item_activated:
5017 * @icon_view: A #GtkIconView
5018 * @path: The #GtkTreePath to be activated
5020 * Activates the item determined by @path.
5025 gtk_icon_view_item_activated (GtkIconView *icon_view,
5028 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5029 g_return_if_fail (path != NULL);
5031 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5035 * gtk_icon_view_set_orientation:
5036 * @icon_view: a #GtkIconView
5037 * @orientation: the relative position of texts and icons
5039 * Sets the ::orientation property which determines whether the labels
5040 * are drawn beside the icons instead of below.
5045 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5046 GtkOrientation orientation)
5048 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5050 if (icon_view->priv->orientation != orientation)
5052 icon_view->priv->orientation = orientation;
5054 gtk_icon_view_stop_editing (icon_view, TRUE);
5055 gtk_icon_view_invalidate_sizes (icon_view);
5056 gtk_icon_view_queue_layout (icon_view);
5058 update_text_cell (icon_view);
5059 update_pixbuf_cell (icon_view);
5061 g_object_notify (G_OBJECT (icon_view), "orientation");
5066 * gtk_icon_view_get_orientation:
5067 * @icon_view: a #GtkIconView
5069 * Returns the value of the ::orientation property which determines
5070 * whether the labels are drawn beside the icons instead of below.
5072 * Return value: the relative position of texts and icons
5077 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5079 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5080 GTK_ORIENTATION_VERTICAL);
5082 return icon_view->priv->orientation;
5086 * gtk_icon_view_set_columns:
5087 * @icon_view: a #GtkIconView
5088 * @columns: the number of columns
5090 * Sets the ::columns property which determines in how
5091 * many columns the icons are arranged. If @columns is
5092 * -1, the number of columns will be chosen automatically
5093 * to fill the available area.
5098 gtk_icon_view_set_columns (GtkIconView *icon_view,
5101 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5103 if (icon_view->priv->columns != columns)
5105 icon_view->priv->columns = columns;
5107 gtk_icon_view_stop_editing (icon_view, TRUE);
5108 gtk_icon_view_queue_layout (icon_view);
5110 g_object_notify (G_OBJECT (icon_view), "columns");
5115 * gtk_icon_view_get_columns:
5116 * @icon_view: a #GtkIconView
5118 * Returns the value of the ::columns property.
5120 * Return value: the number of columns, or -1
5125 gtk_icon_view_get_columns (GtkIconView *icon_view)
5127 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5129 return icon_view->priv->columns;
5133 * gtk_icon_view_set_item_width:
5134 * @icon_view: a #GtkIconView
5135 * @item_width: the width for each item
5137 * Sets the ::item-width property which specifies the width
5138 * to use for each item. If it is set to -1, the icon view will
5139 * automatically determine a suitable item size.
5144 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5147 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5149 if (icon_view->priv->item_width != item_width)
5151 icon_view->priv->item_width = item_width;
5153 gtk_icon_view_stop_editing (icon_view, TRUE);
5154 gtk_icon_view_invalidate_sizes (icon_view);
5155 gtk_icon_view_queue_layout (icon_view);
5157 update_text_cell (icon_view);
5159 g_object_notify (G_OBJECT (icon_view), "item-width");
5164 * gtk_icon_view_get_item_width:
5165 * @icon_view: a #GtkIconView
5167 * Returns the value of the ::item-width property.
5169 * Return value: the width of a single item, or -1
5174 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5176 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5178 return icon_view->priv->item_width;
5183 * gtk_icon_view_set_spacing:
5184 * @icon_view: a #GtkIconView
5185 * @spacing: the spacing
5187 * Sets the ::spacing property which specifies the space
5188 * which is inserted between the cells (i.e. the icon and
5189 * the text) of an item.
5194 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5197 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5199 if (icon_view->priv->spacing != spacing)
5201 icon_view->priv->spacing = spacing;
5203 gtk_icon_view_stop_editing (icon_view, TRUE);
5204 gtk_icon_view_invalidate_sizes (icon_view);
5205 gtk_icon_view_queue_layout (icon_view);
5207 g_object_notify (G_OBJECT (icon_view), "spacing");
5212 * gtk_icon_view_get_spacing:
5213 * @icon_view: a #GtkIconView
5215 * Returns the value of the ::spacing property.
5217 * Return value: the space between cells
5222 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5224 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5226 return icon_view->priv->spacing;
5230 * gtk_icon_view_set_row_spacing:
5231 * @icon_view: a #GtkIconView
5232 * @row_spacing: the row spacing
5234 * Sets the ::row-spacing property which specifies the space
5235 * which is inserted between the rows of the icon view.
5240 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5243 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5245 if (icon_view->priv->row_spacing != row_spacing)
5247 icon_view->priv->row_spacing = row_spacing;
5249 gtk_icon_view_stop_editing (icon_view, TRUE);
5250 gtk_icon_view_invalidate_sizes (icon_view);
5251 gtk_icon_view_queue_layout (icon_view);
5253 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5258 * gtk_icon_view_get_row_spacing:
5259 * @icon_view: a #GtkIconView
5261 * Returns the value of the ::row-spacing property.
5263 * Return value: the space between rows
5268 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5270 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5272 return icon_view->priv->row_spacing;
5276 * gtk_icon_view_set_column_spacing:
5277 * @icon_view: a #GtkIconView
5278 * @column_spacing: the column spacing
5280 * Sets the ::column-spacing property which specifies the space
5281 * which is inserted between the columns of the icon view.
5286 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5287 gint column_spacing)
5289 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5291 if (icon_view->priv->column_spacing != column_spacing)
5293 icon_view->priv->column_spacing = column_spacing;
5295 gtk_icon_view_stop_editing (icon_view, TRUE);
5296 gtk_icon_view_invalidate_sizes (icon_view);
5297 gtk_icon_view_queue_layout (icon_view);
5299 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5304 * gtk_icon_view_get_column_spacing:
5305 * @icon_view: a #GtkIconView
5307 * Returns the value of the ::column-spacing property.
5309 * Return value: the space between columns
5314 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5316 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5318 return icon_view->priv->column_spacing;
5322 * gtk_icon_view_set_marging:
5323 * @icon_view: a #GtkIconView
5324 * @spacing: the margin
5326 * Sets the ::margin property which specifies the space
5327 * which is inserted at the top, bottom, left and right
5333 gtk_icon_view_set_margin (GtkIconView *icon_view,
5336 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5338 if (icon_view->priv->margin != margin)
5340 icon_view->priv->margin = margin;
5342 gtk_icon_view_stop_editing (icon_view, TRUE);
5343 gtk_icon_view_invalidate_sizes (icon_view);
5344 gtk_icon_view_queue_layout (icon_view);
5346 g_object_notify (G_OBJECT (icon_view), "margin");
5351 * gtk_icon_view_get_margin:
5352 * @icon_view: a #GtkIconView
5354 * Returns the value of the ::margin property.
5356 * Return value: the space at the borders
5361 gtk_icon_view_get_margin (GtkIconView *icon_view)
5363 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5365 return icon_view->priv->margin;
5369 /* Get/set whether drag_motion requested the drag data and
5370 * drag_data_received should thus not actually insert the data,
5371 * since the data doesn't result from a drop.
5374 set_status_pending (GdkDragContext *context,
5375 GdkDragAction suggested_action)
5377 g_object_set_data (G_OBJECT (context),
5378 "gtk-icon-view-status-pending",
5379 GINT_TO_POINTER (suggested_action));
5382 static GdkDragAction
5383 get_status_pending (GdkDragContext *context)
5385 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5386 "gtk-icon-view-status-pending"));
5390 unset_reorderable (GtkIconView *icon_view)
5392 if (icon_view->priv->reorderable)
5394 icon_view->priv->reorderable = FALSE;
5395 g_object_notify (G_OBJECT (icon_view), "reorderable");
5400 clear_source_info (GtkIconView *icon_view)
5402 if (icon_view->priv->source_targets)
5403 gtk_target_list_unref (icon_view->priv->source_targets);
5404 icon_view->priv->source_targets = NULL;
5406 icon_view->priv->source_set = FALSE;
5410 clear_dest_info (GtkIconView *icon_view)
5412 if (icon_view->priv->dest_targets)
5413 gtk_target_list_unref (icon_view->priv->dest_targets);
5414 icon_view->priv->dest_targets = NULL;
5416 icon_view->priv->dest_set = FALSE;
5420 set_source_row (GdkDragContext *context,
5421 GtkTreeModel *model,
5422 GtkTreePath *source_row)
5425 g_object_set_data_full (G_OBJECT (context),
5426 "gtk-icon-view-source-row",
5427 gtk_tree_row_reference_new (model, source_row),
5428 (GDestroyNotify) gtk_tree_row_reference_free);
5430 g_object_set_data_full (G_OBJECT (context),
5431 "gtk-icon-view-source-row",
5436 get_source_row (GdkDragContext *context)
5438 GtkTreeRowReference *ref;
5440 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5443 return gtk_tree_row_reference_get_path (ref);
5450 GtkTreeRowReference *dest_row;
5451 gboolean empty_view_drop;
5452 gboolean drop_append_mode;
5456 dest_row_free (gpointer data)
5458 DestRow *dr = (DestRow *)data;
5460 gtk_tree_row_reference_free (dr->dest_row);
5465 set_dest_row (GdkDragContext *context,
5466 GtkTreeModel *model,
5467 GtkTreePath *dest_row,
5468 gboolean empty_view_drop,
5469 gboolean drop_append_mode)
5475 g_object_set_data_full (G_OBJECT (context),
5476 "gtk-icon-view-dest-row",
5481 dr = g_new0 (DestRow, 1);
5483 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5484 dr->empty_view_drop = empty_view_drop;
5485 dr->drop_append_mode = drop_append_mode;
5486 g_object_set_data_full (G_OBJECT (context),
5487 "gtk-icon-view-dest-row",
5488 dr, (GDestroyNotify) dest_row_free);
5492 get_dest_row (GdkDragContext *context)
5496 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5500 GtkTreePath *path = NULL;
5503 path = gtk_tree_row_reference_get_path (dr->dest_row);
5504 else if (dr->empty_view_drop)
5505 path = gtk_tree_path_new_from_indices (0, -1);
5509 if (path && dr->drop_append_mode)
5510 gtk_tree_path_next (path);
5519 check_model_dnd (GtkTreeModel *model,
5520 GType required_iface,
5521 const gchar *signal)
5523 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5525 g_warning ("You must override the default '%s' handler "
5526 "on GtkIconView when using models that don't support "
5527 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5528 "is to connect to '%s' and call "
5529 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5530 "the default handler from running. Look at the source code "
5531 "for the default handler in gtkiconview.c to get an idea what "
5532 "your handler should do. (gtkiconview.c is in the GTK+ source "
5533 "code.) If you're using GTK+ from a language other than C, "
5534 "there may be a more natural way to override default handlers, e.g. via derivation.",
5535 signal, g_type_name (required_iface), signal);
5543 remove_scroll_timeout (GtkIconView *icon_view)
5545 if (icon_view->priv->scroll_timeout_id != 0)
5547 g_source_remove (icon_view->priv->scroll_timeout_id);
5549 icon_view->priv->scroll_timeout_id = 0;
5554 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5556 gint px, py, x, y, width, height;
5557 gint hoffset, voffset;
5560 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
5561 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
5563 /* see if we are near the edge. */
5564 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5566 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5568 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5570 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5574 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
5575 icon_view->priv->vadjustment->lower,
5576 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
5577 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
5581 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
5582 icon_view->priv->hadjustment->lower,
5583 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
5584 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
5590 drag_scroll_timeout (gpointer data)
5592 GtkIconView *icon_view = GTK_ICON_VIEW (data);
5594 GDK_THREADS_ENTER ();
5596 gtk_icon_view_autoscroll (icon_view);
5598 GDK_THREADS_LEAVE ();
5605 set_destination (GtkIconView *icon_view,
5606 GdkDragContext *context,
5609 GdkDragAction *suggested_action,
5613 GtkTreePath *path = NULL;
5614 GtkIconViewDropPosition pos;
5615 GtkIconViewDropPosition old_pos;
5616 GtkTreePath *old_dest_path = NULL;
5617 gboolean can_drop = FALSE;
5619 widget = GTK_WIDGET (icon_view);
5621 *suggested_action = 0;
5624 if (!icon_view->priv->dest_set)
5626 /* someone unset us as a drag dest, note that if
5627 * we return FALSE drag_leave isn't called
5630 gtk_icon_view_set_drag_dest_item (icon_view,
5632 GTK_ICON_VIEW_DROP_LEFT);
5634 remove_scroll_timeout (GTK_ICON_VIEW (widget));
5636 return FALSE; /* no longer a drop site */
5639 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
5640 if (*target == GDK_NONE)
5643 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
5646 GtkTreeModel *model;
5648 /* the row got dropped on empty space, let's setup a special case
5652 gtk_tree_path_free (path);
5654 model = gtk_icon_view_get_model (icon_view);
5656 n_children = gtk_tree_model_iter_n_children (model, NULL);
5659 pos = GTK_ICON_VIEW_DROP_BELOW;
5660 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5664 pos = GTK_ICON_VIEW_DROP_ABOVE;
5665 path = gtk_tree_path_new_from_indices (0, -1);
5675 gtk_icon_view_get_drag_dest_item (icon_view,
5680 gtk_tree_path_free (old_dest_path);
5682 if (TRUE /* FIXME if the location droppable predicate */)
5690 GtkWidget *source_widget;
5692 *suggested_action = context->suggested_action;
5693 source_widget = gtk_drag_get_source_widget (context);
5695 if (source_widget == widget)
5697 /* Default to MOVE, unless the user has
5698 * pressed ctrl or shift to affect available actions
5700 if ((context->actions & GDK_ACTION_MOVE) != 0)
5701 *suggested_action = GDK_ACTION_MOVE;
5704 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5709 /* can't drop here */
5710 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5712 GTK_ICON_VIEW_DROP_LEFT);
5716 gtk_tree_path_free (path);
5722 get_logical_destination (GtkIconView *icon_view,
5723 gboolean *drop_append_mode)
5725 /* adjust path to point to the row the drop goes in front of */
5726 GtkTreePath *path = NULL;
5727 GtkIconViewDropPosition pos;
5729 *drop_append_mode = FALSE;
5731 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
5736 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
5737 pos == GTK_ICON_VIEW_DROP_BELOW)
5740 GtkTreeModel *model = icon_view->priv->model;
5742 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5743 !gtk_tree_model_iter_next (model, &iter))
5744 *drop_append_mode = TRUE;
5747 *drop_append_mode = FALSE;
5748 gtk_tree_path_next (path);
5756 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
5757 GdkEventMotion *event)
5759 GdkDragContext *context;
5760 GtkTreePath *path = NULL;
5762 GtkTreeModel *model;
5763 gboolean retval = FALSE;
5765 if (!icon_view->priv->source_set)
5768 if (icon_view->priv->pressed_button < 0)
5771 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
5772 icon_view->priv->press_start_x,
5773 icon_view->priv->press_start_y,
5774 event->x, event->y))
5777 model = gtk_icon_view_get_model (icon_view);
5782 button = icon_view->priv->pressed_button;
5783 icon_view->priv->pressed_button = -1;
5785 path = gtk_icon_view_get_path_at_pos (icon_view,
5786 icon_view->priv->press_start_x,
5787 icon_view->priv->press_start_y);
5792 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
5793 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
5797 /* FIXME Check whether we're a start button, if not return FALSE and
5801 /* Now we can begin the drag */
5805 context = gtk_drag_begin (GTK_WIDGET (icon_view),
5806 icon_view->priv->source_targets,
5807 icon_view->priv->source_actions,
5811 set_source_row (context, model, path);
5815 gtk_tree_path_free (path);
5820 /* Source side drag signals */
5822 gtk_icon_view_drag_begin (GtkWidget *widget,
5823 GdkDragContext *context)
5825 GtkIconView *icon_view;
5826 GtkIconViewItem *item;
5831 icon_view = GTK_ICON_VIEW (widget);
5833 /* if the user uses a custom DnD impl, we don't set the icon here */
5834 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
5837 item = gtk_icon_view_get_item_at_coords (icon_view,
5838 icon_view->priv->press_start_x,
5839 icon_view->priv->press_start_y,
5843 g_return_if_fail (item != NULL);
5845 x = icon_view->priv->press_start_x - item->x + 1;
5846 y = icon_view->priv->press_start_y - item->y + 1;
5848 path = gtk_tree_path_new_from_indices (item->index, -1);
5849 icon = gtk_icon_view_create_drag_icon (icon_view, path);
5850 gtk_tree_path_free (path);
5852 gtk_drag_set_icon_pixmap (context,
5853 gdk_drawable_get_colormap (icon),
5858 g_object_unref (icon);
5862 gtk_icon_view_drag_end (GtkWidget *widget,
5863 GdkDragContext *context)
5869 gtk_icon_view_drag_data_get (GtkWidget *widget,
5870 GdkDragContext *context,
5871 GtkSelectionData *selection_data,
5875 GtkIconView *icon_view;
5876 GtkTreeModel *model;
5877 GtkTreePath *source_row;
5879 icon_view = GTK_ICON_VIEW (widget);
5880 model = gtk_icon_view_get_model (icon_view);
5885 if (!icon_view->priv->dest_set)
5888 source_row = get_source_row (context);
5890 if (source_row == NULL)
5893 /* We can implement the GTK_TREE_MODEL_ROW target generically for
5894 * any model; for DragSource models there are some other targets
5898 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
5899 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
5904 /* If drag_data_get does nothing, try providing row data. */
5905 if (selection_data->target == gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE))
5906 gtk_tree_set_row_drag_data (selection_data,
5911 gtk_tree_path_free (source_row);
5915 gtk_icon_view_drag_data_delete (GtkWidget *widget,
5916 GdkDragContext *context)
5918 GtkTreeModel *model;
5919 GtkIconView *icon_view;
5920 GtkTreePath *source_row;
5922 icon_view = GTK_ICON_VIEW (widget);
5923 model = gtk_icon_view_get_model (icon_view);
5925 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
5928 if (!icon_view->priv->dest_set)
5931 source_row = get_source_row (context);
5933 if (source_row == NULL)
5936 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
5939 gtk_tree_path_free (source_row);
5941 set_source_row (context, NULL, NULL);
5944 /* Target side drag signals */
5946 gtk_icon_view_drag_leave (GtkWidget *widget,
5947 GdkDragContext *context,
5950 GtkIconView *icon_view;
5952 icon_view = GTK_ICON_VIEW (widget);
5954 /* unset any highlight row */
5955 gtk_icon_view_set_drag_dest_item (icon_view,
5957 GTK_ICON_VIEW_DROP_LEFT);
5959 remove_scroll_timeout (icon_view);
5963 gtk_icon_view_drag_motion (GtkWidget *widget,
5964 GdkDragContext *context,
5969 GtkTreePath *path = NULL;
5970 GtkTreeModel *model;
5971 GtkIconViewDropPosition pos;
5972 GtkIconView *icon_view;
5973 GdkDragAction suggested_action = 0;
5977 icon_view = GTK_ICON_VIEW (widget);
5979 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
5982 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
5984 /* we only know this *after* set_desination_row */
5985 model = gtk_icon_view_get_model (icon_view);
5986 empty = icon_view->priv->empty_view_drop;
5988 if (path == NULL && !empty)
5990 /* Can't drop here. */
5991 gdk_drag_status (context, 0, time);
5995 if (icon_view->priv->scroll_timeout_id == 0)
5997 icon_view->priv->scroll_timeout_id =
5998 g_timeout_add (50, drag_scroll_timeout, icon_view);
6001 if (target == gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE))
6003 /* Request data so we can use the source row when
6004 * determining whether to accept the drop
6006 set_status_pending (context, suggested_action);
6007 gtk_drag_get_data (widget, context, target, time);
6011 set_status_pending (context, 0);
6012 gdk_drag_status (context, suggested_action, time);
6017 gtk_tree_path_free (path);
6023 gtk_icon_view_drag_drop (GtkWidget *widget,
6024 GdkDragContext *context,
6029 GtkIconView *icon_view;
6031 GdkDragAction suggested_action = 0;
6032 GdkAtom target = GDK_NONE;
6033 GtkTreeModel *model;
6034 gboolean drop_append_mode;
6036 icon_view = GTK_ICON_VIEW (widget);
6037 model = gtk_icon_view_get_model (icon_view);
6039 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6041 if (!icon_view->priv->dest_set)
6044 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6047 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6050 path = get_logical_destination (icon_view, &drop_append_mode);
6052 if (target != GDK_NONE && path != NULL)
6054 /* in case a motion had requested drag data, change things so we
6055 * treat drag data receives as a drop.
6057 set_status_pending (context, 0);
6058 set_dest_row (context, model, path,
6059 icon_view->priv->empty_view_drop, drop_append_mode);
6063 gtk_tree_path_free (path);
6065 /* Unset this thing */
6066 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6068 if (target != GDK_NONE)
6070 gtk_drag_get_data (widget, context, target, time);
6078 gtk_icon_view_drag_data_received (GtkWidget *widget,
6079 GdkDragContext *context,
6082 GtkSelectionData *selection_data,
6087 gboolean accepted = FALSE;
6088 GtkTreeModel *model;
6089 GtkIconView *icon_view;
6090 GtkTreePath *dest_row;
6091 GdkDragAction suggested_action;
6092 gboolean drop_append_mode;
6094 icon_view = GTK_ICON_VIEW (widget);
6095 model = gtk_icon_view_get_model (icon_view);
6097 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6100 if (!icon_view->priv->dest_set)
6103 suggested_action = get_status_pending (context);
6105 if (suggested_action)
6107 /* We are getting this data due to a request in drag_motion,
6108 * rather than due to a request in drag_drop, so we are just
6109 * supposed to call drag_status, not actually paste in the
6112 path = get_logical_destination (icon_view, &drop_append_mode);
6115 suggested_action = 0;
6117 if (suggested_action)
6119 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6122 suggested_action = 0;
6125 gdk_drag_status (context, suggested_action, time);
6128 gtk_tree_path_free (path);
6130 /* If you can't drop, remove user drop indicator until the next motion */
6131 if (suggested_action == 0)
6132 gtk_icon_view_set_drag_dest_item (icon_view,
6134 GTK_ICON_VIEW_DROP_LEFT);
6139 dest_row = get_dest_row (context);
6141 if (dest_row == NULL)
6144 if (selection_data->length >= 0)
6146 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6152 gtk_drag_finish (context,
6154 (context->action == GDK_ACTION_MOVE),
6157 gtk_tree_path_free (dest_row);
6160 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6163 /* Drag-and-Drop support */
6165 * gtk_icon_view_enable_model_drag_source:
6166 * @icon_view: a #GtkIconTreeView
6167 * @start_button_mask: Mask of allowed buttons to start drag
6168 * @targets: the table of targets that the drag will support
6169 * @n_targets: the number of items in @targets
6170 * @actions: the bitmask of possible actions for a drag from this
6173 * Turns @icon_view into a drag source for automatic DND.
6178 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6179 GdkModifierType start_button_mask,
6180 const GtkTargetEntry *targets,
6182 GdkDragAction actions)
6184 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6186 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6188 clear_source_info (icon_view);
6189 icon_view->priv->start_button_mask = start_button_mask;
6190 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6191 icon_view->priv->source_actions = actions;
6193 icon_view->priv->source_set = TRUE;
6195 unset_reorderable (icon_view);
6199 * gtk_icon_view_enable_model_drag_dest:
6200 * @icon_view: a #GtkIconView
6201 * @targets: the table of targets that the drag will support
6202 * @n_targets: the number of items in @targets
6203 * @actions: the bitmask of possible actions for a drag from this
6206 * Turns @icon_view into a drop destination for automatic DND.
6211 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6212 const GtkTargetEntry *targets,
6214 GdkDragAction actions)
6216 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6218 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6220 clear_dest_info (icon_view);
6222 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6223 icon_view->priv->dest_actions = actions;
6225 icon_view->priv->dest_set = TRUE;
6227 unset_reorderable (icon_view);
6231 * gtk_icon_view_unset_model_drag_source:
6232 * @icon_view: a #GtkIconView
6234 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6239 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6241 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6243 if (icon_view->priv->source_set)
6245 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6246 clear_source_info (icon_view);
6249 unset_reorderable (icon_view);
6253 * gtk_icon_view_unset_model_drag_dest:
6254 * @icon_view: a #GtkIconView
6256 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6261 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6263 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6265 if (icon_view->priv->dest_set)
6267 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6268 clear_dest_info (icon_view);
6271 unset_reorderable (icon_view);
6274 /* These are useful to implement your own custom stuff. */
6276 * gtk_icon_view_set_drag_dest_item:
6277 * @icon_view: a #GtkIconView
6278 * @path: The path of the item to highlight, or %NULL.
6279 * @pos: Specifies whether to drop, relative to the item
6281 * Sets the item that is highlighted for feedback.
6286 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6288 GtkIconViewDropPosition pos)
6290 /* Note; this function is exported to allow a custom DND
6291 * implementation, so it can't touch TreeViewDragInfo
6294 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6296 if (icon_view->priv->dest_item)
6298 GtkTreePath *current_path;
6299 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6300 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6301 icon_view->priv->dest_item = NULL;
6303 gtk_icon_view_queue_draw_path (icon_view, current_path);
6304 gtk_tree_path_free (current_path);
6307 /* special case a drop on an empty model */
6308 icon_view->priv->empty_view_drop = FALSE;
6309 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
6310 && gtk_tree_path_get_depth (path) == 1
6311 && gtk_tree_path_get_indices (path)[0] == 0)
6315 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6318 if (n_children == 0)
6319 icon_view->priv->empty_view_drop = TRUE;
6322 icon_view->priv->dest_pos = pos;
6326 icon_view->priv->dest_item =
6327 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6328 icon_view->priv->model, path);
6330 gtk_icon_view_queue_draw_path (icon_view, path);
6335 * gtk_icon_view_get_drag_dest_item:
6336 * @icon_view: a #GtkIconView
6337 * @path: Return location for the path of the highlighted item, or %NULL.
6338 * @pos: Return location for the drop position, or %NULL
6340 * Gets information about the item that is highlighted for feedback.
6345 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6347 GtkIconViewDropPosition *pos)
6349 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6353 if (icon_view->priv->dest_item)
6354 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6360 *pos = icon_view->priv->dest_pos;
6364 * gtk_icon_view_get_dest_item_at_pos:
6365 * @icon_view: a #GtkIconView
6366 * @drag_x: the position to determine the destination item for
6367 * @drag_y: the position to determine the destination item for
6368 * @path: Return location for the path of the highlighted item, or %NULL.
6369 * @pos: Return location for the drop position, or %NULL
6371 * Determines the destination item for a given position.
6373 * Return value: whether there is an item at the given position.
6378 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6382 GtkIconViewDropPosition *pos)
6384 GtkIconViewItem *item;
6386 /* Note; this function is exported to allow a custom DND
6387 * implementation, so it can't touch TreeViewDragInfo
6390 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6391 g_return_val_if_fail (drag_x >= 0, FALSE);
6392 g_return_val_if_fail (drag_y >= 0, FALSE);
6393 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6399 item = gtk_icon_view_get_item_at_coords (icon_view,
6400 drag_x + icon_view->priv->hadjustment->value,
6401 drag_y + icon_view->priv->vadjustment->value,
6408 *path = gtk_tree_path_new_from_indices (item->index, -1);
6412 if (drag_x < item->x + item->width / 4)
6413 *pos = GTK_ICON_VIEW_DROP_LEFT;
6414 else if (drag_x > item->x + item->width * 3 / 4)
6415 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6416 else if (drag_y < item->y + item->height / 4)
6417 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6418 else if (drag_y > item->y + item->height * 3 / 4)
6419 *pos = GTK_ICON_VIEW_DROP_BELOW;
6421 *pos = GTK_ICON_VIEW_DROP_INTO;
6428 * gtk_icon_view_create_drag_icon:
6429 * @icon_view: a #GtkIconView
6430 * @path: a #GtkTreePath in @icon_view
6432 * Creates a #GdkPixmap representation of the item at @path.
6433 * This image is used for a drag icon.
6435 * Return value: a newly-allocated pixmap of the drag icon.
6440 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6445 GdkPixmap *drawable;
6450 widget = GTK_WIDGET (icon_view);
6452 index = gtk_tree_path_get_indices (path)[0];
6454 for (l = icon_view->priv->items; l; l = l->next)
6456 GtkIconViewItem *item = l->data;
6458 if (index == item->index)
6460 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
6465 cr = gdk_cairo_create (drawable);
6466 cairo_set_line_width (cr, 1.);
6468 gdk_cairo_set_source_color
6469 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
6470 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
6475 area.width = item->width;
6476 area.height = item->height;
6478 gtk_icon_view_paint_item (icon_view, cr, item, &area,
6479 drawable, 1, 1, FALSE);
6481 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6482 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
6495 * gtk_icon_view_get_reorderable:
6496 * @icon_view: a #GtkIconView
6498 * Retrieves whether the user can reorder the list via drag-and-drop.
6499 * See gtk_icon_view_set_reorderable().
6501 * Return value: %TRUE if the list can be reordered.
6506 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6508 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6510 return icon_view->priv->reorderable;
6513 static const GtkTargetEntry item_targets[] = {
6514 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6519 * gtk_icon_view_set_reorderable:
6520 * @icon_view: A #GtkIconView.
6521 * @reorderable: %TRUE, if the list of items can be reordered.
6523 * This function is a convenience function to allow you to reorder models that
6524 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6525 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6526 * the user can reorder the model by dragging and dropping rows. The
6527 * developer can listen to these changes by connecting to the model's
6528 * row_inserted and row_deleted signals.
6530 * This function does not give you any degree of control over the order -- any
6531 * reordering is allowed. If more control is needed, you should probably
6532 * handle drag and drop manually.
6537 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6538 gboolean reorderable)
6540 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6542 reorderable = reorderable != FALSE;
6544 if (icon_view->priv->reorderable == reorderable)
6549 gtk_icon_view_enable_model_drag_source (icon_view,
6552 G_N_ELEMENTS (item_targets),
6554 gtk_icon_view_enable_model_drag_dest (icon_view,
6556 G_N_ELEMENTS (item_targets),
6561 gtk_icon_view_unset_model_drag_source (icon_view);
6562 gtk_icon_view_unset_model_drag_dest (icon_view);
6565 icon_view->priv->reorderable = reorderable;
6567 g_object_notify (G_OBJECT (icon_view), "reorderable");
6571 /* Accessibility Support */
6573 static gpointer accessible_parent_class;
6574 static gpointer accessible_item_parent_class;
6575 static GQuark accessible_private_data_quark = 0;
6577 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6578 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6579 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6581 static GType gtk_icon_view_item_accessible_get_type (void);
6592 GtkIconViewItem *item;
6596 AtkStateSet *state_set;
6600 GtkTextBuffer *text_buffer;
6602 gchar *action_descriptions[LAST_ACTION];
6603 gchar *image_description;
6604 guint action_idle_handler;
6605 } GtkIconViewItemAccessible;
6607 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
6613 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
6618 typedef struct _GtkIconViewItemAccessibleClass
6620 AtkObjectClass parent_class;
6622 } GtkIconViewItemAccessibleClass;
6624 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
6627 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
6629 GtkIconViewItemAccessible *item;
6630 GtkIconView *icon_view;
6633 GDK_THREADS_ENTER ();
6635 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
6636 item->action_idle_handler = 0;
6638 if (item->widget != NULL)
6640 icon_view = GTK_ICON_VIEW (item->widget);
6641 path = gtk_tree_path_new_from_indices (item->item->index, -1);
6642 gtk_icon_view_item_activated (icon_view, path);
6643 gtk_tree_path_free (path);
6646 GDK_THREADS_LEAVE ();
6652 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
6655 GtkIconViewItemAccessible *item;
6656 GtkIconView *icon_view;
6658 if (i < 0 || i >= LAST_ACTION)
6661 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6663 if (!GTK_IS_ICON_VIEW (item->widget))
6666 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6669 icon_view = GTK_ICON_VIEW (item->widget);
6673 case ACTION_ACTIVATE:
6674 if (!item->action_idle_handler)
6675 item->action_idle_handler = g_idle_add (gtk_icon_view_item_accessible_idle_do_action, item);
6678 g_assert_not_reached ();
6686 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
6691 static const gchar *
6692 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
6695 GtkIconViewItemAccessible *item;
6697 if (i < 0 || i >= LAST_ACTION)
6700 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6702 if (item->action_descriptions[i])
6703 return item->action_descriptions[i];
6705 return gtk_icon_view_item_accessible_action_descriptions[i];
6708 static const gchar *
6709 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
6712 if (i < 0 || i >= LAST_ACTION)
6715 return gtk_icon_view_item_accessible_action_names[i];
6719 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
6721 const gchar *description)
6723 GtkIconViewItemAccessible *item;
6725 if (i < 0 || i >= LAST_ACTION)
6728 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6730 if (item->action_descriptions[i])
6731 g_free (item->action_descriptions[i]);
6733 item->action_descriptions[i] = g_strdup (description);
6739 atk_action_item_interface_init (AtkActionIface *iface)
6741 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
6742 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
6743 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
6744 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
6745 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
6748 static const gchar *
6749 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
6751 GtkIconViewItemAccessible *item;
6753 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6755 return item->image_description;
6759 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
6760 const gchar *description)
6762 GtkIconViewItemAccessible *item;
6764 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6766 g_free (item->image_description);
6767 item->image_description = g_strdup (item->image_description);
6773 get_pixbuf_box (GtkIconView *icon_view,
6774 GtkIconViewItem *item,
6779 for (l = icon_view->priv->cell_list; l; l = l->next)
6781 GtkIconViewCellInfo *info = l->data;
6783 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
6785 gtk_icon_view_get_cell_box (icon_view, item, info, box);
6795 get_text (GtkIconView *icon_view,
6796 GtkIconViewItem *item)
6801 for (l = icon_view->priv->cell_list; l; l = l->next)
6803 GtkIconViewCellInfo *info = l->data;
6805 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
6807 g_object_get (info->cell, "text", &text, NULL);
6817 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
6821 GtkIconViewItemAccessible *item;
6824 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6826 if (!GTK_IS_ICON_VIEW (item->widget))
6829 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6832 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
6835 *height = box.height;
6840 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
6843 AtkCoordType coord_type)
6845 GtkIconViewItemAccessible *item;
6848 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6850 if (!GTK_IS_ICON_VIEW (item->widget))
6853 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6856 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
6858 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
6860 *x+= box.x - item->item->x;
6861 *y+= box.y - item->item->y;
6867 atk_image_item_interface_init (AtkImageIface *iface)
6869 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
6870 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
6871 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
6872 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
6876 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
6880 GtkIconViewItemAccessible *item;
6881 GtkTextIter start, end;
6882 GtkTextBuffer *buffer;
6884 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
6886 if (!GTK_IS_ICON_VIEW (item->widget))
6889 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6892 buffer = item->text_buffer;
6893 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
6895 gtk_text_buffer_get_end_iter (buffer, &end);
6897 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
6899 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
6903 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
6906 GtkIconViewItemAccessible *item;
6907 GtkTextIter start, end;
6908 GtkTextBuffer *buffer;
6912 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
6914 if (!GTK_IS_ICON_VIEW (item->widget))
6917 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6920 buffer = item->text_buffer;
6921 if (offset >= gtk_text_buffer_get_char_count (buffer))
6924 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
6926 gtk_text_iter_forward_char (&end);
6927 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
6928 unichar = g_utf8_get_char (string);
6935 get_pango_text_offsets (PangoLayout *layout,
6936 GtkTextBuffer *buffer,
6938 AtkTextBoundary boundary_type,
6942 GtkTextIter *start_iter,
6943 GtkTextIter *end_iter)
6945 PangoLayoutIter *iter;
6946 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
6947 gint index, start_index, end_index;
6949 gboolean found = FALSE;
6951 text = pango_layout_get_text (layout);
6952 index = g_utf8_offset_to_pointer (text, offset) - text;
6953 iter = pango_layout_get_iter (layout);
6956 line = pango_layout_iter_get_line (iter);
6957 start_index = line->start_index;
6958 end_index = start_index + line->length;
6960 if (index >= start_index && index <= end_index)
6963 * Found line for offset
6969 * We want the previous line
6973 switch (boundary_type)
6975 case ATK_TEXT_BOUNDARY_LINE_START:
6976 end_index = start_index;
6977 start_index = prev_line->start_index;
6979 case ATK_TEXT_BOUNDARY_LINE_END:
6981 start_index = prev_prev_line->start_index +
6982 prev_prev_line->length;
6983 end_index = prev_line->start_index + prev_line->length;
6986 g_assert_not_reached();
6990 start_index = end_index = 0;
6993 switch (boundary_type)
6995 case ATK_TEXT_BOUNDARY_LINE_START:
6996 if (pango_layout_iter_next_line (iter))
6997 end_index = pango_layout_iter_get_line (iter)->start_index;
6999 case ATK_TEXT_BOUNDARY_LINE_END:
7001 start_index = prev_line->start_index +
7005 g_assert_not_reached();
7010 * We want the next line
7012 if (pango_layout_iter_next_line (iter))
7014 line = pango_layout_iter_get_line (iter);
7015 switch (boundary_type)
7017 case ATK_TEXT_BOUNDARY_LINE_START:
7018 start_index = line->start_index;
7019 if (pango_layout_iter_next_line (iter))
7020 end_index = pango_layout_iter_get_line (iter)->start_index;
7022 end_index = start_index + line->length;
7024 case ATK_TEXT_BOUNDARY_LINE_END:
7025 start_index = end_index;
7026 end_index = line->start_index + line->length;
7029 g_assert_not_reached();
7033 start_index = end_index;
7039 prev_prev_line = prev_line;
7042 while (pango_layout_iter_next_line (iter));
7046 start_index = prev_line->start_index + prev_line->length;
7047 end_index = start_index;
7049 pango_layout_iter_free (iter);
7050 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7051 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7053 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7054 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7058 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7060 AtkTextBoundary boundary_type,
7064 GtkIconViewItemAccessible *item;
7065 GtkTextIter start, end;
7066 GtkTextBuffer *buffer;
7067 GtkIconView *icon_view;
7069 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7071 if (!GTK_IS_ICON_VIEW (item->widget))
7074 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7077 buffer = item->text_buffer;
7079 if (!gtk_text_buffer_get_char_count (buffer))
7083 return g_strdup ("");
7085 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7089 switch (boundary_type)
7091 case ATK_TEXT_BOUNDARY_CHAR:
7092 gtk_text_iter_backward_char(&start);
7094 case ATK_TEXT_BOUNDARY_WORD_START:
7095 if (!gtk_text_iter_starts_word (&start))
7096 gtk_text_iter_backward_word_start (&start);
7098 gtk_text_iter_backward_word_start(&start);
7100 case ATK_TEXT_BOUNDARY_WORD_END:
7101 if (gtk_text_iter_inside_word (&start) &&
7102 !gtk_text_iter_starts_word (&start))
7103 gtk_text_iter_backward_word_start (&start);
7104 while (!gtk_text_iter_ends_word (&start))
7106 if (!gtk_text_iter_backward_char (&start))
7110 gtk_text_iter_backward_word_start(&start);
7111 while (!gtk_text_iter_ends_word (&start))
7113 if (!gtk_text_iter_backward_char (&start))
7117 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7118 if (!gtk_text_iter_starts_sentence (&start))
7119 gtk_text_iter_backward_sentence_start (&start);
7121 gtk_text_iter_backward_sentence_start (&start);
7123 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7124 if (gtk_text_iter_inside_sentence (&start) &&
7125 !gtk_text_iter_starts_sentence (&start))
7126 gtk_text_iter_backward_sentence_start (&start);
7127 while (!gtk_text_iter_ends_sentence (&start))
7129 if (!gtk_text_iter_backward_char (&start))
7133 gtk_text_iter_backward_sentence_start (&start);
7134 while (!gtk_text_iter_ends_sentence (&start))
7136 if (!gtk_text_iter_backward_char (&start))
7140 case ATK_TEXT_BOUNDARY_LINE_START:
7141 case ATK_TEXT_BOUNDARY_LINE_END:
7142 icon_view = GTK_ICON_VIEW (item->widget);
7144 /* FIXME we probably have to use GailTextCell to salvage this */
7145 gtk_icon_view_update_item_text (icon_view, item->item);
7146 get_pango_text_offsets (icon_view->priv->layout,
7159 *start_offset = gtk_text_iter_get_offset (&start);
7160 *end_offset = gtk_text_iter_get_offset (&end);
7162 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7166 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7168 AtkTextBoundary boundary_type,
7172 GtkIconViewItemAccessible *item;
7173 GtkTextIter start, end;
7174 GtkTextBuffer *buffer;
7175 GtkIconView *icon_view;
7177 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7179 if (!GTK_IS_ICON_VIEW (item->widget))
7182 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7185 buffer = item->text_buffer;
7187 if (!gtk_text_buffer_get_char_count (buffer))
7191 return g_strdup ("");
7193 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7197 switch (boundary_type)
7199 case ATK_TEXT_BOUNDARY_CHAR:
7200 gtk_text_iter_forward_char (&end);
7202 case ATK_TEXT_BOUNDARY_WORD_START:
7203 if (!gtk_text_iter_starts_word (&start))
7204 gtk_text_iter_backward_word_start (&start);
7205 if (gtk_text_iter_inside_word (&end))
7206 gtk_text_iter_forward_word_end (&end);
7207 while (!gtk_text_iter_starts_word (&end))
7209 if (!gtk_text_iter_forward_char (&end))
7213 case ATK_TEXT_BOUNDARY_WORD_END:
7214 if (gtk_text_iter_inside_word (&start) &&
7215 !gtk_text_iter_starts_word (&start))
7216 gtk_text_iter_backward_word_start (&start);
7217 while (!gtk_text_iter_ends_word (&start))
7219 if (!gtk_text_iter_backward_char (&start))
7222 gtk_text_iter_forward_word_end (&end);
7224 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7225 if (!gtk_text_iter_starts_sentence (&start))
7226 gtk_text_iter_backward_sentence_start (&start);
7227 if (gtk_text_iter_inside_sentence (&end))
7228 gtk_text_iter_forward_sentence_end (&end);
7229 while (!gtk_text_iter_starts_sentence (&end))
7231 if (!gtk_text_iter_forward_char (&end))
7235 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7236 if (gtk_text_iter_inside_sentence (&start) &&
7237 !gtk_text_iter_starts_sentence (&start))
7238 gtk_text_iter_backward_sentence_start (&start);
7239 while (!gtk_text_iter_ends_sentence (&start))
7241 if (!gtk_text_iter_backward_char (&start))
7244 gtk_text_iter_forward_sentence_end (&end);
7246 case ATK_TEXT_BOUNDARY_LINE_START:
7247 case ATK_TEXT_BOUNDARY_LINE_END:
7248 icon_view = GTK_ICON_VIEW (item->widget);
7250 /* FIXME we probably have to use GailTextCell to salvage this */
7251 gtk_icon_view_update_item_text (icon_view, item->item);
7252 get_pango_text_offsets (icon_view->priv->layout,
7266 *start_offset = gtk_text_iter_get_offset (&start);
7267 *end_offset = gtk_text_iter_get_offset (&end);
7269 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7273 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7275 AtkTextBoundary boundary_type,
7279 GtkIconViewItemAccessible *item;
7280 GtkTextIter start, end;
7281 GtkTextBuffer *buffer;
7282 GtkIconView *icon_view;
7284 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7286 if (!GTK_IS_ICON_VIEW (item->widget))
7289 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7292 buffer = item->text_buffer;
7294 if (!gtk_text_buffer_get_char_count (buffer))
7298 return g_strdup ("");
7300 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7304 switch (boundary_type)
7306 case ATK_TEXT_BOUNDARY_CHAR:
7307 gtk_text_iter_forward_char(&start);
7308 gtk_text_iter_forward_chars(&end, 2);
7310 case ATK_TEXT_BOUNDARY_WORD_START:
7311 if (gtk_text_iter_inside_word (&end))
7312 gtk_text_iter_forward_word_end (&end);
7313 while (!gtk_text_iter_starts_word (&end))
7315 if (!gtk_text_iter_forward_char (&end))
7319 if (!gtk_text_iter_is_end (&end))
7321 gtk_text_iter_forward_word_end (&end);
7322 while (!gtk_text_iter_starts_word (&end))
7324 if (!gtk_text_iter_forward_char (&end))
7329 case ATK_TEXT_BOUNDARY_WORD_END:
7330 gtk_text_iter_forward_word_end (&end);
7332 if (!gtk_text_iter_is_end (&end))
7333 gtk_text_iter_forward_word_end (&end);
7335 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7336 if (gtk_text_iter_inside_sentence (&end))
7337 gtk_text_iter_forward_sentence_end (&end);
7338 while (!gtk_text_iter_starts_sentence (&end))
7340 if (!gtk_text_iter_forward_char (&end))
7344 if (!gtk_text_iter_is_end (&end))
7346 gtk_text_iter_forward_sentence_end (&end);
7347 while (!gtk_text_iter_starts_sentence (&end))
7349 if (!gtk_text_iter_forward_char (&end))
7354 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7355 gtk_text_iter_forward_sentence_end (&end);
7357 if (!gtk_text_iter_is_end (&end))
7358 gtk_text_iter_forward_sentence_end (&end);
7360 case ATK_TEXT_BOUNDARY_LINE_START:
7361 case ATK_TEXT_BOUNDARY_LINE_END:
7362 icon_view = GTK_ICON_VIEW (item->widget);
7364 /* FIXME we probably have to use GailTextCell to salvage this */
7365 gtk_icon_view_update_item_text (icon_view, item->item);
7366 get_pango_text_offsets (icon_view->priv->layout,
7378 *start_offset = gtk_text_iter_get_offset (&start);
7379 *end_offset = gtk_text_iter_get_offset (&end);
7381 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7385 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7387 GtkIconViewItemAccessible *item;
7389 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7391 if (!GTK_IS_ICON_VIEW (item->widget))
7394 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7397 return gtk_text_buffer_get_char_count (item->text_buffer);
7401 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7407 AtkCoordType coord_type)
7409 GtkIconViewItemAccessible *item;
7410 GtkIconView *icon_view;
7411 PangoRectangle char_rect;
7412 const gchar *item_text;
7415 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7417 if (!GTK_IS_ICON_VIEW (item->widget))
7420 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7423 icon_view = GTK_ICON_VIEW (item->widget);
7425 /* FIXME we probably have to use GailTextCell to salvage this */
7426 gtk_icon_view_update_item_text (icon_view, item->item);
7427 item_text = pango_layout_get_text (icon_view->priv->layout);
7428 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7429 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7431 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7432 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7433 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7434 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7435 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7436 *width = char_rect.width / PANGO_SCALE;
7437 *height = char_rect.height / PANGO_SCALE;
7442 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7445 AtkCoordType coord_type)
7447 GtkIconViewItemAccessible *item;
7448 GtkIconView *icon_view;
7449 const gchar *item_text;
7454 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7456 if (!GTK_IS_ICON_VIEW (item->widget))
7459 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7462 icon_view = GTK_ICON_VIEW (item->widget);
7464 /* FIXME we probably have to use GailTextCell to salvage this */
7465 gtk_icon_view_update_item_text (icon_view, item->item);
7466 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7467 x -= l_x + item->item->layout_x - item->item->x;
7468 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7469 y -= l_y + item->item->layout_y - item->item->y;
7470 item_text = pango_layout_get_text (icon_view->priv->layout);
7471 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7482 offset = g_utf8_strlen (item_text, -1);
7484 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7490 atk_text_item_interface_init (AtkTextIface *iface)
7492 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7493 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7494 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7495 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7496 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7497 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7498 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7499 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7503 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7508 AtkCoordType coord_type)
7510 GtkIconViewItemAccessible *item;
7511 AtkObject *parent_obj;
7514 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7516 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7517 if (!GTK_IS_WIDGET (item->widget))
7520 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7523 *width = item->item->width;
7524 *height = item->item->height;
7525 if (gtk_icon_view_item_accessible_is_showing (item))
7527 parent_obj = gtk_widget_get_accessible (item->widget);
7528 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7529 *x = l_x + item->item->x;
7530 *y = l_y + item->item->y;
7540 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7542 GtkIconViewItemAccessible *item;
7543 GtkWidget *toplevel;
7545 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7547 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7548 if (!GTK_IS_WIDGET (item->widget))
7551 gtk_widget_grab_focus (item->widget);
7552 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
7553 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7554 if (GTK_WIDGET_TOPLEVEL (toplevel))
7555 gtk_window_present (GTK_WINDOW (toplevel));
7561 atk_component_item_interface_init (AtkComponentIface *iface)
7563 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7564 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7568 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7569 AtkStateType state_type,
7570 gboolean emit_signal)
7574 rc = atk_state_set_add_state (item->state_set, state_type);
7576 * The signal should only be generated if the value changed,
7577 * not when the item is set up. So states that are set
7578 * initially should pass FALSE as the emit_signal argument.
7583 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7584 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7585 if (state_type == ATK_STATE_VISIBLE)
7586 g_signal_emit_by_name (item, "visible_data_changed");
7593 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7594 AtkStateType state_type,
7595 gboolean emit_signal)
7597 if (atk_state_set_contains_state (item->state_set, state_type))
7601 rc = atk_state_set_remove_state (item->state_set, state_type);
7603 * The signal should only be generated if the value changed,
7604 * not when the item is set up. So states that are set
7605 * initially should pass FALSE as the emit_signal argument.
7610 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7611 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7612 if (state_type == ATK_STATE_VISIBLE)
7613 g_signal_emit_by_name (item, "visible_data_changed");
7623 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7625 GtkIconView *icon_view;
7626 GdkRectangle visible_rect;
7627 gboolean is_showing;
7630 * An item is considered "SHOWING" if any part of the item is in the
7631 * visible rectangle.
7634 if (!GTK_IS_ICON_VIEW (item->widget))
7637 if (item->item == NULL)
7640 icon_view = GTK_ICON_VIEW (item->widget);
7642 if (icon_view->priv->hadjustment)
7643 visible_rect.x += icon_view->priv->hadjustment->value;
7645 if (icon_view->priv->hadjustment)
7646 visible_rect.y += icon_view->priv->vadjustment->value;
7647 visible_rect.width = item->widget->allocation.width;
7648 visible_rect.height = item->widget->allocation.height;
7650 if (((item->item->x + item->item->width) < visible_rect.x) ||
7651 ((item->item->y + item->item->height) < (visible_rect.y)) ||
7652 (item->item->x > (visible_rect.x + visible_rect.width)) ||
7653 (item->item->y > (visible_rect.y + visible_rect.height)))
7662 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
7663 gboolean emit_signal)
7665 if (gtk_icon_view_item_accessible_is_showing (item))
7666 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
7669 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
7674 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
7678 item->state_set = atk_state_set_new ();
7680 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
7681 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
7682 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
7683 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
7684 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
7686 for (i = 0; i < LAST_ACTION; i++)
7687 item->action_descriptions[i] = NULL;
7689 item->image_description = NULL;
7691 item->action_idle_handler = 0;
7695 gtk_icon_view_item_accessible_finalize (GObject *object)
7697 GtkIconViewItemAccessible *item;
7700 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
7702 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
7705 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
7707 if (item->state_set)
7708 g_object_unref (item->state_set);
7710 if (item->text_buffer)
7711 g_object_unref (item->text_buffer);
7713 for (i = 0; i < LAST_ACTION; i++)
7714 g_free (item->action_descriptions[i]);
7716 g_free (item->image_description);
7718 if (item->action_idle_handler)
7720 g_source_remove (item->action_idle_handler);
7721 item->action_idle_handler = 0;
7724 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
7727 static G_CONST_RETURN gchar*
7728 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
7734 GtkIconViewItemAccessible *item;
7735 GtkTextIter start_iter;
7736 GtkTextIter end_iter;
7738 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7740 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
7741 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
7743 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
7748 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
7750 GtkIconViewItemAccessible *item;
7752 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
7753 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7756 return gtk_widget_get_accessible (item->widget);
7762 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
7764 GtkIconViewItemAccessible *item;
7766 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
7767 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7769 return item->item->index;
7772 static AtkStateSet *
7773 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
7775 GtkIconViewItemAccessible *item;
7776 GtkIconView *icon_view;
7778 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7779 g_return_val_if_fail (item->state_set, NULL);
7784 icon_view = GTK_ICON_VIEW (item->widget);
7785 if (icon_view->priv->cursor_item == item->item)
7786 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
7788 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
7790 return g_object_ref (item->state_set);
7794 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
7796 GObjectClass *gobject_class;
7798 accessible_item_parent_class = g_type_class_peek_parent (klass);
7800 gobject_class = (GObjectClass *)klass;
7802 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
7804 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
7805 klass->get_name = gtk_icon_view_item_accessible_get_name;
7806 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
7807 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
7811 gtk_icon_view_item_accessible_get_type (void)
7813 static GType type = 0;
7817 static const GTypeInfo tinfo =
7819 sizeof (GtkIconViewItemAccessibleClass),
7820 (GBaseInitFunc) NULL, /* base init */
7821 (GBaseFinalizeFunc) NULL, /* base finalize */
7822 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
7823 (GClassFinalizeFunc) NULL, /* class finalize */
7824 NULL, /* class data */
7825 sizeof (GtkIconViewItemAccessible), /* instance size */
7826 0, /* nb preallocs */
7827 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
7828 NULL /* value table */
7831 static const GInterfaceInfo atk_component_info =
7833 (GInterfaceInitFunc) atk_component_item_interface_init,
7834 (GInterfaceFinalizeFunc) NULL,
7837 static const GInterfaceInfo atk_action_info =
7839 (GInterfaceInitFunc) atk_action_item_interface_init,
7840 (GInterfaceFinalizeFunc) NULL,
7843 static const GInterfaceInfo atk_image_info =
7845 (GInterfaceInitFunc) atk_image_item_interface_init,
7846 (GInterfaceFinalizeFunc) NULL,
7849 static const GInterfaceInfo atk_text_info =
7851 (GInterfaceInitFunc) atk_text_item_interface_init,
7852 (GInterfaceFinalizeFunc) NULL,
7856 type = g_type_register_static (ATK_TYPE_OBJECT,
7857 "GtkIconViewItemAccessible", &tinfo, 0);
7858 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
7859 &atk_component_info);
7860 g_type_add_interface_static (type, ATK_TYPE_ACTION,
7862 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
7864 g_type_add_interface_static (type, ATK_TYPE_TEXT,
7871 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
7872 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
7873 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
7875 static GType gtk_icon_view_accessible_get_type (void);
7880 } GtkIconViewAccessible;
7886 } GtkIconViewItemAccessibleInfo;
7892 GtkAdjustment *old_hadj;
7893 GtkAdjustment *old_vadj;
7895 GtkTreeModel *model;
7897 } GtkIconViewAccessiblePrivate;
7899 static GtkIconViewAccessiblePrivate *
7900 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
7902 return g_object_get_qdata (G_OBJECT (accessible),
7903 accessible_private_data_quark);
7907 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
7911 GtkIconViewItemAccessibleInfo *info;
7912 GtkIconViewItemAccessibleInfo *tmp_info;
7913 GtkIconViewAccessiblePrivate *priv;
7916 info = g_new (GtkIconViewItemAccessibleInfo, 1);
7918 info->index = index;
7920 priv = gtk_icon_view_accessible_get_priv (accessible);
7921 items = priv->items;
7924 tmp_info = items->data;
7925 if (tmp_info->index > index)
7927 items = items->next;
7929 priv->items = g_list_insert_before (priv->items, items, info);
7930 priv->old_hadj = NULL;
7931 priv->old_vadj = NULL;
7935 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
7937 GtkIconView *icon_view;
7940 widget = GTK_ACCESSIBLE (accessible)->widget;
7944 icon_view = GTK_ICON_VIEW (widget);
7946 return g_list_length (icon_view->priv->items);
7950 gtk_icon_view_accessible_find_child (AtkObject *accessible,
7953 GtkIconViewAccessiblePrivate *priv;
7954 GtkIconViewItemAccessibleInfo *info;
7957 priv = gtk_icon_view_accessible_get_priv (accessible);
7958 items = priv->items;
7963 if (info->index == index)
7965 items = items->next;
7971 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
7974 GtkIconView *icon_view;
7978 GtkIconViewItemAccessible *a11y_item;
7980 widget = GTK_ACCESSIBLE (accessible)->widget;
7984 icon_view = GTK_ICON_VIEW (widget);
7985 icons = g_list_nth (icon_view->priv->items, index);
7989 GtkIconViewItem *item = icons->data;
7991 g_return_val_if_fail (item->index == index, NULL);
7992 obj = gtk_icon_view_accessible_find_child (accessible, index);
7995 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
7996 gtk_icon_view_item_accessible_info_new (accessible,
7999 obj->role = ATK_ROLE_ICON;
8000 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8001 a11y_item->item = item;
8002 a11y_item->widget = widget;
8003 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8005 gtk_icon_view_set_cell_data (icon_view, item);
8006 gtk_text_buffer_set_text (a11y_item->text_buffer,
8007 get_text (icon_view, item), -1);
8009 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8010 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8018 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8021 GtkIconViewAccessiblePrivate *priv;
8022 GtkIconViewItemAccessibleInfo *info;
8023 GtkIconViewItemAccessible *item;
8026 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8030 gboolean act_on_item;
8032 widget = GTK_ACCESSIBLE (view)->widget;
8036 items = priv->items;
8038 act_on_item = (list == NULL);
8043 info = (GtkIconViewItemAccessibleInfo *)items->data;
8044 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8046 if (act_on_item == FALSE && list == items)
8050 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8052 items = items->next;
8058 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8059 GtkIconView *icon_view)
8062 GtkIconViewAccessible *view;
8065 * The scrollbars have changed
8067 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8068 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8070 gtk_icon_view_accessible_traverse_items (view, NULL);
8074 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8075 GtkAdjustment *hadj,
8076 GtkAdjustment *vadj)
8079 GtkIconViewAccessiblePrivate *priv;
8081 atk_obj = gtk_widget_get_accessible (widget);
8082 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8084 if (priv->old_hadj != hadj)
8088 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8089 (gpointer *)&priv->old_hadj);
8091 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8092 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8095 priv->old_hadj = hadj;
8098 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8099 (gpointer *)&priv->old_hadj);
8100 g_signal_connect (hadj,
8102 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8106 if (priv->old_vadj != vadj)
8110 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8111 (gpointer *)&priv->old_vadj);
8113 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8114 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8117 priv->old_vadj = vadj;
8120 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8121 (gpointer *)&priv->old_vadj);
8122 g_signal_connect (vadj,
8124 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8131 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8138 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8139 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8145 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8150 GtkIconViewAccessiblePrivate *priv;
8151 GtkIconViewItemAccessibleInfo *info;
8152 GtkIconViewAccessible *view;
8153 GtkIconViewItemAccessible *item;
8159 index = gtk_tree_path_get_indices(path)[0];
8160 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8161 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8162 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8164 items = priv->items;
8169 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8170 if (info->index != item->item->index)
8172 if (info->index < index)
8173 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8175 if (tmp_list == NULL)
8178 info->index = item->item->index;
8181 items = items->next;
8183 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8184 g_signal_emit_by_name (atk_obj, "children_changed::add",
8190 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8194 GtkIconViewAccessiblePrivate *priv;
8195 GtkIconViewItemAccessibleInfo *info;
8196 GtkIconViewAccessible *view;
8197 GtkIconViewItemAccessible *item;
8200 GList *deleted_item;
8204 index = gtk_tree_path_get_indices(path)[0];
8205 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8206 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8207 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8209 items = priv->items;
8211 deleted_item = NULL;
8216 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8217 if (info->index == index)
8219 deleted_item = items;
8221 if (info->index != item->item->index)
8223 if (tmp_list == NULL)
8226 info->index = item->item->index;
8229 items = items->next;
8231 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8234 info = deleted_item->data;
8235 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8237 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8241 priv->items = g_list_remove_link (priv->items, deleted_item);
8249 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8250 GtkIconViewItemAccessibleInfo *i2)
8252 return i1->index - i2->index;
8256 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8262 GtkIconViewAccessiblePrivate *priv;
8263 GtkIconViewItemAccessibleInfo *info;
8264 GtkIconViewAccessible *view;
8265 GtkIconView *icon_view;
8266 GtkIconViewItemAccessible *item;
8271 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8272 icon_view = GTK_ICON_VIEW (user_data);
8273 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8274 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8276 items = priv->items;
8281 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8282 info->index = new_order[info->index];
8283 tmp_list = g_list_nth (icon_view->priv->items, info->index);
8284 item->item = tmp_list->data;
8285 items = items->next;
8287 priv->items = g_list_sort (priv->items,
8288 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8294 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8299 obj = G_OBJECT (model);
8300 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8301 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8302 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8303 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8307 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8311 obj = G_OBJECT (icon_view->priv->model);
8312 g_signal_connect_data (obj, "row-changed",
8313 (GCallback) gtk_icon_view_accessible_model_row_changed,
8314 icon_view, NULL, 0);
8315 g_signal_connect_data (obj, "row-inserted",
8316 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8317 icon_view, NULL, G_CONNECT_AFTER);
8318 g_signal_connect_data (obj, "row-deleted",
8319 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8320 icon_view, NULL, G_CONNECT_AFTER);
8321 g_signal_connect_data (obj, "rows-reordered",
8322 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8323 icon_view, NULL, G_CONNECT_AFTER);
8327 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8329 GtkIconViewItemAccessibleInfo *info;
8332 items = priv->items;
8335 info = (GtkIconViewItemAccessibleInfo *) items->data;
8336 g_object_unref (info->item);
8337 g_free (items->data);
8338 items = items->next;
8340 g_list_free (priv->items);
8345 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8348 GtkIconView *icon_view;
8351 GtkIconViewAccessible *view;
8352 GtkIconViewAccessiblePrivate *priv;
8354 if (strcmp (pspec->name, "model") == 0)
8356 widget = GTK_WIDGET (obj);
8357 atk_obj = gtk_widget_get_accessible (widget);
8358 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8359 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8362 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8363 (gpointer *)&priv->model);
8364 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8366 gtk_icon_view_accessible_clear_cache (priv);
8368 icon_view = GTK_ICON_VIEW (obj);
8369 priv->model = icon_view->priv->model;
8370 /* If there is no model the GtkIconView is probably being destroyed */
8373 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8374 gtk_icon_view_accessible_connect_model_signals (icon_view);
8382 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8385 GtkIconViewAccessiblePrivate *priv;
8386 GtkIconView *icon_view;
8388 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8389 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8391 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8392 g_object_set_qdata (G_OBJECT (accessible),
8393 accessible_private_data_quark,
8396 icon_view = GTK_ICON_VIEW (data);
8397 if (icon_view->priv->hadjustment)
8399 priv->old_hadj = icon_view->priv->hadjustment;
8400 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
8401 g_signal_connect (icon_view->priv->hadjustment,
8403 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8406 if (icon_view->priv->vadjustment)
8408 priv->old_vadj = icon_view->priv->vadjustment;
8409 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
8410 g_signal_connect (icon_view->priv->vadjustment,
8412 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8415 g_signal_connect_after (data,
8416 "set_scroll_adjustments",
8417 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
8419 g_signal_connect (data,
8421 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8424 priv->model = icon_view->priv->model;
8427 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8428 gtk_icon_view_accessible_connect_model_signals (icon_view);
8431 accessible->role = ATK_ROLE_LAYERED_PANE;
8435 gtk_icon_view_accessible_finalize (GObject *object)
8437 GtkIconViewAccessiblePrivate *priv;
8439 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8440 gtk_icon_view_accessible_clear_cache (priv);
8444 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8448 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8449 GtkAccessible *accessible)
8452 GtkIconViewAccessiblePrivate *priv;
8454 atk_obj = ATK_OBJECT (accessible);
8455 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8458 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8459 (gpointer *)&priv->old_hadj);
8461 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8462 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8464 priv->old_hadj = NULL;
8468 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8469 (gpointer *)&priv->old_vadj);
8471 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8472 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8474 priv->old_vadj = NULL;
8479 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8481 if (accessible->widget)
8483 g_signal_connect_after (accessible->widget,
8485 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8488 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8492 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8494 GObjectClass *gobject_class;
8495 GtkAccessibleClass *accessible_class;
8497 accessible_parent_class = g_type_class_peek_parent (klass);
8499 gobject_class = (GObjectClass *)klass;
8500 accessible_class = (GtkAccessibleClass *)klass;
8502 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8504 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8505 klass->ref_child = gtk_icon_view_accessible_ref_child;
8506 klass->initialize = gtk_icon_view_accessible_initialize;
8508 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8510 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8514 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8517 AtkCoordType coord_type)
8520 GtkIconView *icon_view;
8521 GtkIconViewItem *item;
8524 widget = GTK_ACCESSIBLE (component)->widget;
8526 /* State is defunct */
8529 icon_view = GTK_ICON_VIEW (widget);
8530 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8531 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8533 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8539 atk_component_interface_init (AtkComponentIface *iface)
8541 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8545 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8549 GtkIconView *icon_view;
8550 GtkIconViewItem *item;
8553 widget = GTK_ACCESSIBLE (selection)->widget;
8557 icon_view = GTK_ICON_VIEW (widget);
8559 l = g_list_nth (icon_view->priv->items, i);
8564 gtk_icon_view_select_item (icon_view, item);
8570 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8573 GtkIconView *icon_view;
8575 widget = GTK_ACCESSIBLE (selection)->widget;
8579 icon_view = GTK_ICON_VIEW (widget);
8580 gtk_icon_view_unselect_all (icon_view);
8586 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8590 GtkIconView *icon_view;
8591 GtkIconViewItem *item;
8594 widget = GTK_ACCESSIBLE (selection)->widget;
8598 icon_view = GTK_ICON_VIEW (widget);
8600 l = icon_view->priv->items;
8607 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8618 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8621 GtkIconView *icon_view;
8622 GtkIconViewItem *item;
8626 widget = GTK_ACCESSIBLE (selection)->widget;
8630 icon_view = GTK_ICON_VIEW (widget);
8632 l = icon_view->priv->items;
8648 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
8652 GtkIconView *icon_view;
8653 GtkIconViewItem *item;
8656 widget = GTK_ACCESSIBLE (selection)->widget;
8660 icon_view = GTK_ICON_VIEW (widget);
8661 l = g_list_nth (icon_view->priv->items, i);
8667 return item->selected;
8671 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
8675 GtkIconView *icon_view;
8676 GtkIconViewItem *item;
8680 widget = GTK_ACCESSIBLE (selection)->widget;
8684 icon_view = GTK_ICON_VIEW (widget);
8685 l = icon_view->priv->items;
8694 gtk_icon_view_unselect_item (icon_view, item);
8706 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
8709 GtkIconView *icon_view;
8711 widget = GTK_ACCESSIBLE (selection)->widget;
8715 icon_view = GTK_ICON_VIEW (widget);
8716 gtk_icon_view_select_all (icon_view);
8721 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
8723 iface->add_selection = gtk_icon_view_accessible_add_selection;
8724 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
8725 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
8726 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
8727 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
8728 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
8729 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
8733 gtk_icon_view_accessible_get_type (void)
8735 static GType type = 0;
8739 static GTypeInfo tinfo =
8742 (GBaseInitFunc) NULL, /* base init */
8743 (GBaseFinalizeFunc) NULL, /* base finalize */
8744 (GClassInitFunc) gtk_icon_view_accessible_class_init,
8745 (GClassFinalizeFunc) NULL, /* class finalize */
8746 NULL, /* class data */
8747 0, /* instance size */
8748 0, /* nb preallocs */
8749 (GInstanceInitFunc) NULL, /* instance init */
8750 NULL /* value table */
8752 static const GInterfaceInfo atk_component_info =
8754 (GInterfaceInitFunc) atk_component_interface_init,
8755 (GInterfaceFinalizeFunc) NULL,
8758 static const GInterfaceInfo atk_selection_info =
8760 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
8761 (GInterfaceFinalizeFunc) NULL,
8766 * Figure out the size of the class and instance
8767 * we are deriving from
8769 AtkObjectFactory *factory;
8772 GType derived_atk_type;
8774 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
8775 factory = atk_registry_get_factory (atk_get_default_registry (),
8777 derived_atk_type = atk_object_factory_get_accessible_type (factory);
8778 g_type_query (derived_atk_type, &query);
8779 tinfo.class_size = query.class_size;
8780 tinfo.instance_size = query.instance_size;
8782 type = g_type_register_static (derived_atk_type,
8783 "GtkIconViewAccessible",
8785 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8786 &atk_component_info);
8787 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
8788 &atk_selection_info);
8794 gtk_icon_view_accessible_new (GObject *obj)
8796 AtkObject *accessible;
8798 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
8800 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
8801 atk_object_initialize (accessible, obj);
8807 gtk_icon_view_accessible_factory_get_accessible_type (void)
8809 return gtk_icon_view_accessible_get_type ();
8813 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
8815 return gtk_icon_view_accessible_new (obj);
8819 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
8821 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
8822 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
8826 gtk_icon_view_accessible_factory_get_type (void)
8828 static GType type = 0;
8832 static const GTypeInfo tinfo =
8834 sizeof (AtkObjectFactoryClass),
8835 NULL, /* base_init */
8836 NULL, /* base_finalize */
8837 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
8838 NULL, /* class_finalize */
8839 NULL, /* class_data */
8840 sizeof (AtkObjectFactory),
8841 0, /* n_preallocs */
8845 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
8846 "GtkIconViewAccessibleFactory",
8854 gtk_icon_view_get_accessible (GtkWidget *widget)
8856 static gboolean first_time = TRUE;
8860 AtkObjectFactory *factory;
8861 AtkRegistry *registry;
8863 GType derived_atk_type;
8866 * Figure out whether accessibility is enabled by looking at the
8867 * type of the accessible object which would be created for
8868 * the parent type of GtkIconView.
8870 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
8872 registry = atk_get_default_registry ();
8873 factory = atk_registry_get_factory (registry,
8875 derived_atk_type = atk_object_factory_get_accessible_type (factory);
8876 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
8877 atk_registry_set_factory_type (registry,
8879 gtk_icon_view_accessible_factory_get_type ());
8882 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
8885 #define __GTK_ICON_VIEW_C__
8886 #include "gtkaliasdef.c"