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_path:
3886 * @icon_view: A #GtkIconView.
3887 * @path: The path of the item to move to.
3888 * @use_align: whether to use alignment arguments, or %FALSE.
3889 * @row_align: The vertical alignment of the item specified by @path.
3890 * @col_align: The horizontal alignment of the item specified by @column.
3892 * Moves the alignments of @icon_view to the position specified by @path.
3893 * @row_align determines where the row is placed, and @col_align determines where
3894 * @column is placed. Both are expected to be between 0.0 and 1.0.
3895 * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means center.
3897 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
3898 * tree does the minimum amount of work to scroll the item onto the screen.
3899 * This means that the item will be scrolled to the edge closest to its current
3900 * position. If the item is currently visible on the screen, nothing is done.
3902 * This function only works if the model is set, and @path is a valid row on the
3903 * model. If the model changes before the @tree_view is realized, the centered
3904 * path will be modified to reflect this change.
3909 gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
3915 GtkIconViewItem *item;
3917 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
3918 g_return_if_fail (path != NULL);
3919 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
3920 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
3922 item = g_list_nth (icon_view->priv->items,
3923 gtk_tree_path_get_indices(path)[0])->data;
3930 gint x, y, width, height;
3932 gfloat offset, value;
3934 gtk_widget_style_get (GTK_WIDGET (icon_view),
3935 "focus-line-width", &focus_width,
3938 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
3940 offset = y + item->y - focus_width -
3941 row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
3942 value = CLAMP (icon_view->priv->vadjustment->value + offset,
3943 icon_view->priv->vadjustment->lower,
3944 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
3945 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
3947 offset = x + item->x - focus_width -
3948 col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
3949 value = CLAMP (icon_view->priv->hadjustment->value + offset,
3950 icon_view->priv->hadjustment->lower,
3951 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
3952 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
3954 gtk_adjustment_changed (icon_view->priv->hadjustment);
3955 gtk_adjustment_changed (icon_view->priv->vadjustment);
3958 gtk_icon_view_scroll_to_item (icon_view, item);
3963 gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
3964 GtkIconViewItem *item)
3966 gint x, y, width, height;
3969 gtk_widget_style_get (GTK_WIDGET (icon_view),
3970 "focus-line-width", &focus_width,
3973 gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
3975 gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
3977 if (y + item->y - focus_width < 0)
3978 gtk_adjustment_set_value (icon_view->priv->vadjustment,
3979 icon_view->priv->vadjustment->value + y + item->y - focus_width);
3980 else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
3981 gtk_adjustment_set_value (icon_view->priv->vadjustment,
3982 icon_view->priv->vadjustment->value + y + item->y + item->height
3983 + focus_width - GTK_WIDGET (icon_view)->allocation.height);
3985 if (x + item->x - focus_width < 0)
3986 gtk_adjustment_set_value (icon_view->priv->hadjustment,
3987 icon_view->priv->hadjustment->value + x + item->x - focus_width);
3988 else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
3989 gtk_adjustment_set_value (icon_view->priv->hadjustment,
3990 icon_view->priv->hadjustment->value + x + item->x + item->width
3991 + focus_width - GTK_WIDGET (icon_view)->allocation.width);
3993 gtk_adjustment_changed (icon_view->priv->hadjustment);
3994 gtk_adjustment_changed (icon_view->priv->vadjustment);
3997 /* GtkCellLayout implementation */
3998 static GtkIconViewCellInfo *
3999 gtk_icon_view_get_cell_info (GtkIconView *icon_view,
4000 GtkCellRenderer *renderer)
4004 for (i = icon_view->priv->cell_list; i; i = i->next)
4006 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
4008 if (info->cell == renderer)
4016 gtk_icon_view_set_cell_data (GtkIconView *icon_view,
4017 GtkIconViewItem *item)
4020 gboolean iters_persist;
4023 iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
4029 path = gtk_tree_path_new_from_indices (item->index, -1);
4030 gtk_tree_model_get_iter (icon_view->priv->model, &iter, path);
4031 gtk_tree_path_free (path);
4036 for (i = icon_view->priv->cell_list; i; i = i->next)
4039 GtkIconViewCellInfo *info = i->data;
4041 g_object_freeze_notify (G_OBJECT (info->cell));
4043 for (j = info->attributes; j && j->next; j = j->next->next)
4045 gchar *property = j->data;
4046 gint column = GPOINTER_TO_INT (j->next->data);
4047 GValue value = {0, };
4049 gtk_tree_model_get_value (icon_view->priv->model, &iter,
4051 g_object_set_property (G_OBJECT (info->cell),
4053 g_value_unset (&value);
4057 (* info->func) (GTK_CELL_LAYOUT (icon_view),
4059 icon_view->priv->model,
4063 g_object_thaw_notify (G_OBJECT (info->cell));
4066 adjust_wrap_width (icon_view, item);
4070 free_cell_attributes (GtkIconViewCellInfo *info)
4074 list = info->attributes;
4075 while (list && list->next)
4077 g_free (list->data);
4078 list = list->next->next;
4081 g_slist_free (info->attributes);
4082 info->attributes = NULL;
4086 free_cell_info (GtkIconViewCellInfo *info)
4088 free_cell_attributes (info);
4090 g_object_unref (info->cell);
4093 (* info->destroy) (info->func_data);
4099 gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
4100 GtkCellRenderer *renderer,
4103 GtkIconViewCellInfo *info;
4104 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4106 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4107 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4109 g_object_ref (renderer);
4110 gtk_object_sink (GTK_OBJECT (renderer));
4112 info = g_new0 (GtkIconViewCellInfo, 1);
4113 info->cell = renderer;
4114 info->expand = expand ? TRUE : FALSE;
4115 info->pack = GTK_PACK_START;
4116 info->position = icon_view->priv->n_cells;
4118 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4119 icon_view->priv->n_cells++;
4123 gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
4124 GtkCellRenderer *renderer,
4127 GtkIconViewCellInfo *info;
4128 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4130 g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
4131 g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
4133 g_object_ref (renderer);
4134 gtk_object_sink (GTK_OBJECT (renderer));
4136 info = g_new0 (GtkIconViewCellInfo, 1);
4137 info->cell = renderer;
4138 info->expand = expand ? TRUE : FALSE;
4139 info->pack = GTK_PACK_END;
4140 info->position = icon_view->priv->n_cells;
4142 icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
4143 icon_view->priv->n_cells++;
4147 gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
4148 GtkCellRenderer *renderer,
4149 const gchar *attribute,
4152 GtkIconViewCellInfo *info;
4153 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4155 info = gtk_icon_view_get_cell_info (icon_view, renderer);
4156 g_return_if_fail (info != NULL);
4158 info->attributes = g_slist_prepend (info->attributes,
4159 GINT_TO_POINTER (column));
4160 info->attributes = g_slist_prepend (info->attributes,
4161 g_strdup (attribute));
4165 gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
4167 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4169 while (icon_view->priv->cell_list)
4171 GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
4172 free_cell_info (info);
4173 icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
4174 icon_view->priv->cell_list);
4177 icon_view->priv->n_cells = 0;
4181 gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
4182 GtkCellRenderer *cell,
4183 GtkCellLayoutDataFunc func,
4185 GDestroyNotify destroy)
4187 GtkIconViewCellInfo *info;
4188 GtkIconView *icon_view = GTK_ICON_VIEW (layout);
4190 info = gtk_icon_view_get_cell_info (icon_view, cell);
4191 g_return_if_fail (info != NULL);
4195 GDestroyNotify d = info->destroy;
4197 info->destroy = NULL;
4198 d (info->func_data);
4202 info->func_data = func_data;
4203 info->destroy = destroy;
4207 gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
4208 GtkCellRenderer *renderer)
4210 GtkIconViewCellInfo *info;
4212 info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
4214 free_cell_attributes (info);
4218 gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
4219 GtkCellRenderer *cell,
4222 GtkIconView *icon_view;
4224 GtkIconViewCellInfo *info;
4227 icon_view = GTK_ICON_VIEW (layout);
4229 g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
4231 info = gtk_icon_view_get_cell_info (icon_view, cell);
4233 g_return_if_fail (info != NULL);
4234 g_return_if_fail (position >= 0);
4236 link = g_list_find (icon_view->priv->cell_list, info);
4238 g_return_if_fail (link != NULL);
4240 icon_view->priv->cell_list = g_list_remove_link (icon_view->priv->cell_list,
4242 icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
4245 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4252 gtk_widget_queue_draw (GTK_WIDGET (icon_view));
4259 * gtk_icon_view_new:
4261 * Creates a new #GtkIconView widget
4263 * Return value: A newly created #GtkIconView widget
4268 gtk_icon_view_new (void)
4270 return g_object_new (GTK_TYPE_ICON_VIEW, NULL);
4274 * gtk_icon_view_new_with_model:
4275 * @model: The model.
4277 * Creates a new #GtkIconView widget with the model @model.
4279 * Return value: A newly created #GtkIconView widget.
4284 gtk_icon_view_new_with_model (GtkTreeModel *model)
4286 return g_object_new (GTK_TYPE_ICON_VIEW, "model", model, NULL);
4291 * gtk_icon_view_get_path_at_pos:
4292 * @icon_view: A #GtkIconView.
4293 * @x: The x position to be identified
4294 * @y: The y position to be identified
4296 * Finds the path at the point (@x, @y), relative to widget coordinates.
4297 * See gtk_icon_view_get_item_at_pos(), if you are also interested in
4298 * the cell at the specified position.
4300 * Return value: The #GtkTreePath corresponding to the icon or %NULL
4301 * if no icon exists at that position.
4306 gtk_icon_view_get_path_at_pos (GtkIconView *icon_view,
4310 GtkIconViewItem *item;
4313 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4315 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
4320 path = gtk_tree_path_new_from_indices (item->index, -1);
4326 * gtk_icon_view_get_item_at_pos:
4327 * @icon_view: A #GtkIconView.
4328 * @x: The x position to be identified
4329 * @y: The y position to be identified
4330 * @path: Return location for the path, or %NULL
4331 * @cell: Return location for the renderer responsible for the cell
4332 * at (@x, @y), or %NULL
4334 * Finds the path at the point (@x, @y), relative to widget coordinates.
4335 * In contrast to gtk_icon_view_get_path_at_pos(), this function also
4336 * obtains the cell at the specified position. The returned path should
4337 * be freed with gtk_tree_path_free().
4339 * Return value: %TRUE if an item exists at the specified position
4344 gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
4348 GtkCellRenderer **cell)
4350 GtkIconViewItem *item;
4351 GtkIconViewCellInfo *info;
4353 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
4355 item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
4360 *path = gtk_tree_path_new_from_indices (item->index, -1);
4373 return (item != NULL);
4377 * gtk_icon_view_selected_foreach:
4378 * @icon_view: A #GtkIconView.
4379 * @func: The funcion to call for each selected icon.
4380 * @data: User data to pass to the function.
4382 * Calls a function for each selected icon. Note that the model or
4383 * selection cannot be modified from within this function.
4388 gtk_icon_view_selected_foreach (GtkIconView *icon_view,
4389 GtkIconViewForeachFunc func,
4394 for (list = icon_view->priv->items; list; list = list->next)
4396 GtkIconViewItem *item = list->data;
4397 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4400 (* func) (icon_view, path, data);
4402 gtk_tree_path_free (path);
4407 * gtk_icon_view_set_selection_mode:
4408 * @icon_view: A #GtkIconView.
4409 * @mode: The selection mode
4411 * Sets the selection mode of the @icon_view.
4416 gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
4417 GtkSelectionMode mode)
4419 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4421 if (mode == icon_view->priv->selection_mode)
4424 if (mode == GTK_SELECTION_NONE ||
4425 icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE)
4426 gtk_icon_view_unselect_all (icon_view);
4428 icon_view->priv->selection_mode = mode;
4430 g_object_notify (G_OBJECT (icon_view), "selection-mode");
4434 * gtk_icon_view_get_selection_mode:
4435 * @icon_view: A #GtkIconView.
4437 * Gets the selection mode of the @icon_view.
4439 * Return value: the current selection mode
4444 gtk_icon_view_get_selection_mode (GtkIconView *icon_view)
4446 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), GTK_SELECTION_SINGLE);
4448 return icon_view->priv->selection_mode;
4452 * gtk_icon_view_set_model:
4453 * @icon_view: A #GtkIconView.
4454 * @model: The model.
4456 * Sets the model for a #GtkIconView.
4457 * If the @icon_view already has a model set, it will remove
4458 * it before setting the new model. If @model is %NULL, then
4459 * it will unset the old model.
4464 gtk_icon_view_set_model (GtkIconView *icon_view,
4465 GtkTreeModel *model)
4467 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4468 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
4470 if (icon_view->priv->model == model)
4473 gtk_icon_view_stop_editing (icon_view, TRUE);
4479 g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
4481 if (icon_view->priv->pixbuf_column != -1)
4483 column_type = gtk_tree_model_get_column_type (model,
4484 icon_view->priv->pixbuf_column);
4486 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4489 if (icon_view->priv->text_column != -1)
4491 column_type = gtk_tree_model_get_column_type (model,
4492 icon_view->priv->text_column);
4494 g_return_if_fail (column_type == G_TYPE_STRING);
4497 if (icon_view->priv->markup_column != -1)
4499 column_type = gtk_tree_model_get_column_type (model,
4500 icon_view->priv->markup_column);
4502 g_return_if_fail (column_type == G_TYPE_STRING);
4507 if (icon_view->priv->model)
4509 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4510 gtk_icon_view_row_changed,
4512 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4513 gtk_icon_view_row_inserted,
4515 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4516 gtk_icon_view_row_deleted,
4518 g_signal_handlers_disconnect_by_func (icon_view->priv->model,
4519 gtk_icon_view_rows_reordered,
4522 g_object_unref (icon_view->priv->model);
4524 g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
4525 g_list_free (icon_view->priv->items);
4526 icon_view->priv->items = NULL;
4527 icon_view->priv->anchor_item = NULL;
4528 icon_view->priv->cursor_item = NULL;
4529 icon_view->priv->last_single_clicked = NULL;
4530 icon_view->priv->width = 0;
4531 icon_view->priv->height = 0;
4534 icon_view->priv->model = model;
4536 if (icon_view->priv->model)
4538 g_object_ref (icon_view->priv->model);
4539 g_signal_connect (icon_view->priv->model,
4541 G_CALLBACK (gtk_icon_view_row_changed),
4543 g_signal_connect (icon_view->priv->model,
4545 G_CALLBACK (gtk_icon_view_row_inserted),
4547 g_signal_connect (icon_view->priv->model,
4549 G_CALLBACK (gtk_icon_view_row_deleted),
4551 g_signal_connect (icon_view->priv->model,
4553 G_CALLBACK (gtk_icon_view_rows_reordered),
4556 gtk_icon_view_build_items (icon_view);
4558 gtk_icon_view_queue_layout (icon_view);
4561 g_object_notify (G_OBJECT (icon_view), "model");
4563 if (GTK_WIDGET_REALIZED (icon_view))
4564 gtk_widget_queue_resize (GTK_WIDGET (icon_view));
4568 * gtk_icon_view_get_model:
4569 * @icon_view: a #GtkIconView
4571 * Returns the model the #GtkIconView is based on. Returns %NULL if the
4574 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
4579 gtk_icon_view_get_model (GtkIconView *icon_view)
4581 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4583 return icon_view->priv->model;
4587 update_text_cell (GtkIconView *icon_view)
4589 GtkIconViewCellInfo *info;
4593 if (icon_view->priv->text_column == -1 &&
4594 icon_view->priv->markup_column == -1)
4596 if (icon_view->priv->text_cell != -1)
4598 info = g_list_nth_data (icon_view->priv->cell_list,
4599 icon_view->priv->text_cell);
4601 g_list_remove (icon_view->priv->cell_list, info);
4603 free_cell_info (info);
4605 icon_view->priv->n_cells--;
4606 icon_view->priv->text_cell = -1;
4611 if (icon_view->priv->text_cell == -1)
4613 GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
4614 gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4615 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4618 if (info->cell == cell)
4620 icon_view->priv->text_cell = i;
4626 info = g_list_nth_data (icon_view->priv->cell_list,
4627 icon_view->priv->text_cell);
4629 if (icon_view->priv->markup_column != -1)
4630 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4632 "markup", icon_view->priv->markup_column,
4635 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4637 "text", icon_view->priv->text_column,
4640 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4641 g_object_set (info->cell,
4642 "wrap_mode", PANGO_WRAP_CHAR,
4643 "wrap_width", icon_view->priv->item_width,
4648 g_object_set (info->cell,
4649 "wrap_mode", PANGO_WRAP_CHAR,
4650 "wrap_width", icon_view->priv->item_width,
4658 update_pixbuf_cell (GtkIconView *icon_view)
4660 GtkIconViewCellInfo *info;
4664 if (icon_view->priv->pixbuf_column == -1)
4666 if (icon_view->priv->pixbuf_cell != -1)
4668 info = g_list_nth_data (icon_view->priv->cell_list,
4669 icon_view->priv->pixbuf_cell);
4671 g_list_remove (icon_view->priv->cell_list, info);
4673 free_cell_info (info);
4675 icon_view->priv->n_cells--;
4676 icon_view->priv->pixbuf_cell = -1;
4681 if (icon_view->priv->pixbuf_cell == -1)
4683 GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
4685 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
4686 for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
4689 if (info->cell == cell)
4691 icon_view->priv->pixbuf_cell = i;
4697 info = g_list_nth_data (icon_view->priv->cell_list,
4698 icon_view->priv->pixbuf_cell);
4700 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
4702 "pixbuf", icon_view->priv->pixbuf_column,
4705 if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
4706 g_object_set (info->cell,
4707 "follow_state", TRUE,
4712 g_object_set (info->cell,
4713 "follow_state", TRUE,
4721 * gtk_icon_view_set_text_column:
4722 * @icon_view: A #GtkIconView.
4723 * @column: A column in the currently used model.
4725 * Sets the column with text for @icon_view to be @column. The text
4726 * column must be of type #G_TYPE_STRING.
4731 gtk_icon_view_set_text_column (GtkIconView *icon_view,
4734 if (column == icon_view->priv->text_column)
4738 icon_view->priv->text_column = -1;
4741 if (icon_view->priv->model != NULL)
4745 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4747 g_return_if_fail (column_type == G_TYPE_STRING);
4750 icon_view->priv->text_column = column;
4753 gtk_icon_view_stop_editing (icon_view, TRUE);
4755 update_text_cell (icon_view);
4757 gtk_icon_view_invalidate_sizes (icon_view);
4758 gtk_icon_view_queue_layout (icon_view);
4760 g_object_notify (G_OBJECT (icon_view), "text-column");
4764 * gtk_icon_view_get_text_column:
4765 * @icon_view: A #GtkIconView.
4767 * Returns the column with text for @icon_view.
4769 * Returns: the text column, or -1 if it's unset.
4774 gtk_icon_view_get_text_column (GtkIconView *icon_view)
4776 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4778 return icon_view->priv->text_column;
4782 * gtk_icon_view_set_markup_column:
4783 * @icon_view: A #GtkIconView.
4784 * @column: A column in the currently used model.
4786 * Sets the column with markup information for @icon_view to be
4787 * @column. The markup column must be of type #G_TYPE_STRING.
4788 * If the markup column is set to something, it overrides
4789 * the text column set by gtk_icon_view_set_text_column().
4794 gtk_icon_view_set_markup_column (GtkIconView *icon_view,
4797 if (column == icon_view->priv->markup_column)
4801 icon_view->priv->markup_column = -1;
4804 if (icon_view->priv->model != NULL)
4808 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4810 g_return_if_fail (column_type == G_TYPE_STRING);
4813 icon_view->priv->markup_column = column;
4816 gtk_icon_view_stop_editing (icon_view, TRUE);
4818 update_text_cell (icon_view);
4820 gtk_icon_view_invalidate_sizes (icon_view);
4821 gtk_icon_view_queue_layout (icon_view);
4823 g_object_notify (G_OBJECT (icon_view), "markup-column");
4827 * gtk_icon_view_get_markup_column:
4828 * @icon_view: A #GtkIconView.
4830 * Returns the column with markup text for @icon_view.
4832 * Returns: the markup column, or -1 if it's unset.
4837 gtk_icon_view_get_markup_column (GtkIconView *icon_view)
4839 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4841 return icon_view->priv->markup_column;
4845 * gtk_icon_view_set_pixbuf_column:
4846 * @icon_view: A #GtkIconView.
4847 * @column: A column in the currently used model.
4849 * Sets the column with pixbufs for @icon_view to be @column. The pixbuf
4850 * column must be of type #GDK_TYPE_PIXBUF
4855 gtk_icon_view_set_pixbuf_column (GtkIconView *icon_view,
4858 if (column == icon_view->priv->pixbuf_column)
4862 icon_view->priv->pixbuf_column = -1;
4865 if (icon_view->priv->model != NULL)
4869 column_type = gtk_tree_model_get_column_type (icon_view->priv->model, column);
4871 g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
4874 icon_view->priv->pixbuf_column = column;
4877 gtk_icon_view_stop_editing (icon_view, TRUE);
4879 update_pixbuf_cell (icon_view);
4881 gtk_icon_view_invalidate_sizes (icon_view);
4882 gtk_icon_view_queue_layout (icon_view);
4884 g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
4889 * gtk_icon_view_get_pixbuf_column:
4890 * @icon_view: A #GtkIconView.
4892 * Returns the column with pixbufs for @icon_view.
4894 * Returns: the pixbuf column, or -1 if it's unset.
4899 gtk_icon_view_get_pixbuf_column (GtkIconView *icon_view)
4901 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
4903 return icon_view->priv->pixbuf_column;
4907 * gtk_icon_view_select_path:
4908 * @icon_view: A #GtkIconView.
4909 * @path: The #GtkTreePath to be selected.
4911 * Selects the row at @path.
4916 gtk_icon_view_select_path (GtkIconView *icon_view,
4921 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4922 g_return_if_fail (icon_view->priv->model != NULL);
4923 g_return_if_fail (path != NULL);
4925 l = g_list_nth (icon_view->priv->items,
4926 gtk_tree_path_get_indices(path)[0]);
4929 gtk_icon_view_select_item (icon_view, l->data);
4933 * gtk_icon_view_unselect_path:
4934 * @icon_view: A #GtkIconView.
4935 * @path: The #GtkTreePath to be unselected.
4937 * Unselects the row at @path.
4942 gtk_icon_view_unselect_path (GtkIconView *icon_view,
4945 GtkIconViewItem *item;
4947 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
4948 g_return_if_fail (icon_view->priv->model != NULL);
4949 g_return_if_fail (path != NULL);
4951 item = g_list_nth (icon_view->priv->items,
4952 gtk_tree_path_get_indices(path)[0])->data;
4957 gtk_icon_view_unselect_item (icon_view, item);
4961 * gtk_icon_view_get_selected_items:
4962 * @icon_view: A #GtkIconView.
4964 * Creates a list of paths of all selected items. Additionally, if you are
4965 * planning on modifying the model after calling this function, you may
4966 * want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
4967 * To do this, you can use gtk_tree_row_reference_new().
4969 * To free the return value, use:
4970 * <informalexample><programlisting>
4971 * g_list_foreach (list, gtk_tree_path_free, NULL);
4972 * g_list_free (list);
4973 * </programlisting></informalexample>
4975 * Return value: A #GList containing a #GtkTreePath for each selected row.
4980 gtk_icon_view_get_selected_items (GtkIconView *icon_view)
4983 GList *selected = NULL;
4985 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
4987 for (list = icon_view->priv->items; list != NULL; list = list->next)
4989 GtkIconViewItem *item = list->data;
4993 GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
4995 selected = g_list_prepend (selected, path);
5003 * gtk_icon_view_select_all:
5004 * @icon_view: A #GtkIconView.
5006 * Selects all the icons. @icon_view must has its selection mode set
5007 * to #GTK_SELECTION_MULTIPLE.
5012 gtk_icon_view_select_all (GtkIconView *icon_view)
5015 gboolean dirty = FALSE;
5017 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5019 if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
5022 for (items = icon_view->priv->items; items; items = items->next)
5024 GtkIconViewItem *item = items->data;
5026 if (!item->selected)
5029 item->selected = TRUE;
5030 gtk_icon_view_queue_draw_item (icon_view, item);
5035 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5039 * gtk_icon_view_unselect_all:
5040 * @icon_view: A #GtkIconView.
5042 * Unselects all the icons.
5047 gtk_icon_view_unselect_all (GtkIconView *icon_view)
5049 gboolean dirty = FALSE;
5051 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5053 if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
5056 dirty = gtk_icon_view_unselect_all_internal (icon_view);
5059 g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
5063 * gtk_icon_view_path_is_selected:
5064 * @icon_view: A #GtkIconView.
5065 * @path: A #GtkTreePath to check selection on.
5067 * Returns %TRUE if the icon pointed to by @path is currently
5068 * selected. If @icon does not point to a valid location, %FALSE is returned.
5070 * Return value: %TRUE if @path is selected.
5075 gtk_icon_view_path_is_selected (GtkIconView *icon_view,
5078 GtkIconViewItem *item;
5080 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
5081 g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
5082 g_return_val_if_fail (path != NULL, FALSE);
5084 item = g_list_nth (icon_view->priv->items,
5085 gtk_tree_path_get_indices(path)[0])->data;
5090 return item->selected;
5094 * gtk_icon_view_item_activated:
5095 * @icon_view: A #GtkIconView
5096 * @path: The #GtkTreePath to be activated
5098 * Activates the item determined by @path.
5103 gtk_icon_view_item_activated (GtkIconView *icon_view,
5106 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5107 g_return_if_fail (path != NULL);
5109 g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
5113 * gtk_icon_view_set_orientation:
5114 * @icon_view: a #GtkIconView
5115 * @orientation: the relative position of texts and icons
5117 * Sets the ::orientation property which determines whether the labels
5118 * are drawn beside the icons instead of below.
5123 gtk_icon_view_set_orientation (GtkIconView *icon_view,
5124 GtkOrientation orientation)
5126 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5128 if (icon_view->priv->orientation != orientation)
5130 icon_view->priv->orientation = orientation;
5132 gtk_icon_view_stop_editing (icon_view, TRUE);
5133 gtk_icon_view_invalidate_sizes (icon_view);
5134 gtk_icon_view_queue_layout (icon_view);
5136 update_text_cell (icon_view);
5137 update_pixbuf_cell (icon_view);
5139 g_object_notify (G_OBJECT (icon_view), "orientation");
5144 * gtk_icon_view_get_orientation:
5145 * @icon_view: a #GtkIconView
5147 * Returns the value of the ::orientation property which determines
5148 * whether the labels are drawn beside the icons instead of below.
5150 * Return value: the relative position of texts and icons
5155 gtk_icon_view_get_orientation (GtkIconView *icon_view)
5157 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
5158 GTK_ORIENTATION_VERTICAL);
5160 return icon_view->priv->orientation;
5164 * gtk_icon_view_set_columns:
5165 * @icon_view: a #GtkIconView
5166 * @columns: the number of columns
5168 * Sets the ::columns property which determines in how
5169 * many columns the icons are arranged. If @columns is
5170 * -1, the number of columns will be chosen automatically
5171 * to fill the available area.
5176 gtk_icon_view_set_columns (GtkIconView *icon_view,
5179 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5181 if (icon_view->priv->columns != columns)
5183 icon_view->priv->columns = columns;
5185 gtk_icon_view_stop_editing (icon_view, TRUE);
5186 gtk_icon_view_queue_layout (icon_view);
5188 g_object_notify (G_OBJECT (icon_view), "columns");
5193 * gtk_icon_view_get_columns:
5194 * @icon_view: a #GtkIconView
5196 * Returns the value of the ::columns property.
5198 * Return value: the number of columns, or -1
5203 gtk_icon_view_get_columns (GtkIconView *icon_view)
5205 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5207 return icon_view->priv->columns;
5211 * gtk_icon_view_set_item_width:
5212 * @icon_view: a #GtkIconView
5213 * @item_width: the width for each item
5215 * Sets the ::item-width property which specifies the width
5216 * to use for each item. If it is set to -1, the icon view will
5217 * automatically determine a suitable item size.
5222 gtk_icon_view_set_item_width (GtkIconView *icon_view,
5225 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5227 if (icon_view->priv->item_width != item_width)
5229 icon_view->priv->item_width = item_width;
5231 gtk_icon_view_stop_editing (icon_view, TRUE);
5232 gtk_icon_view_invalidate_sizes (icon_view);
5233 gtk_icon_view_queue_layout (icon_view);
5235 update_text_cell (icon_view);
5237 g_object_notify (G_OBJECT (icon_view), "item-width");
5242 * gtk_icon_view_get_item_width:
5243 * @icon_view: a #GtkIconView
5245 * Returns the value of the ::item-width property.
5247 * Return value: the width of a single item, or -1
5252 gtk_icon_view_get_item_width (GtkIconView *icon_view)
5254 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5256 return icon_view->priv->item_width;
5261 * gtk_icon_view_set_spacing:
5262 * @icon_view: a #GtkIconView
5263 * @spacing: the spacing
5265 * Sets the ::spacing property which specifies the space
5266 * which is inserted between the cells (i.e. the icon and
5267 * the text) of an item.
5272 gtk_icon_view_set_spacing (GtkIconView *icon_view,
5275 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5277 if (icon_view->priv->spacing != spacing)
5279 icon_view->priv->spacing = spacing;
5281 gtk_icon_view_stop_editing (icon_view, TRUE);
5282 gtk_icon_view_invalidate_sizes (icon_view);
5283 gtk_icon_view_queue_layout (icon_view);
5285 g_object_notify (G_OBJECT (icon_view), "spacing");
5290 * gtk_icon_view_get_spacing:
5291 * @icon_view: a #GtkIconView
5293 * Returns the value of the ::spacing property.
5295 * Return value: the space between cells
5300 gtk_icon_view_get_spacing (GtkIconView *icon_view)
5302 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5304 return icon_view->priv->spacing;
5308 * gtk_icon_view_set_row_spacing:
5309 * @icon_view: a #GtkIconView
5310 * @row_spacing: the row spacing
5312 * Sets the ::row-spacing property which specifies the space
5313 * which is inserted between the rows of the icon view.
5318 gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
5321 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5323 if (icon_view->priv->row_spacing != row_spacing)
5325 icon_view->priv->row_spacing = row_spacing;
5327 gtk_icon_view_stop_editing (icon_view, TRUE);
5328 gtk_icon_view_invalidate_sizes (icon_view);
5329 gtk_icon_view_queue_layout (icon_view);
5331 g_object_notify (G_OBJECT (icon_view), "row-spacing");
5336 * gtk_icon_view_get_row_spacing:
5337 * @icon_view: a #GtkIconView
5339 * Returns the value of the ::row-spacing property.
5341 * Return value: the space between rows
5346 gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
5348 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5350 return icon_view->priv->row_spacing;
5354 * gtk_icon_view_set_column_spacing:
5355 * @icon_view: a #GtkIconView
5356 * @column_spacing: the column spacing
5358 * Sets the ::column-spacing property which specifies the space
5359 * which is inserted between the columns of the icon view.
5364 gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
5365 gint column_spacing)
5367 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5369 if (icon_view->priv->column_spacing != column_spacing)
5371 icon_view->priv->column_spacing = column_spacing;
5373 gtk_icon_view_stop_editing (icon_view, TRUE);
5374 gtk_icon_view_invalidate_sizes (icon_view);
5375 gtk_icon_view_queue_layout (icon_view);
5377 g_object_notify (G_OBJECT (icon_view), "column-spacing");
5382 * gtk_icon_view_get_column_spacing:
5383 * @icon_view: a #GtkIconView
5385 * Returns the value of the ::column-spacing property.
5387 * Return value: the space between columns
5392 gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
5394 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5396 return icon_view->priv->column_spacing;
5400 * gtk_icon_view_set_margin:
5401 * @icon_view: a #GtkIconView
5402 * @spacing: the margin
5404 * Sets the ::margin property which specifies the space
5405 * which is inserted at the top, bottom, left and right
5411 gtk_icon_view_set_margin (GtkIconView *icon_view,
5414 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
5416 if (icon_view->priv->margin != margin)
5418 icon_view->priv->margin = margin;
5420 gtk_icon_view_stop_editing (icon_view, TRUE);
5421 gtk_icon_view_invalidate_sizes (icon_view);
5422 gtk_icon_view_queue_layout (icon_view);
5424 g_object_notify (G_OBJECT (icon_view), "margin");
5429 * gtk_icon_view_get_margin:
5430 * @icon_view: a #GtkIconView
5432 * Returns the value of the ::margin property.
5434 * Return value: the space at the borders
5439 gtk_icon_view_get_margin (GtkIconView *icon_view)
5441 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
5443 return icon_view->priv->margin;
5447 /* Get/set whether drag_motion requested the drag data and
5448 * drag_data_received should thus not actually insert the data,
5449 * since the data doesn't result from a drop.
5452 set_status_pending (GdkDragContext *context,
5453 GdkDragAction suggested_action)
5455 g_object_set_data (G_OBJECT (context),
5456 "gtk-icon-view-status-pending",
5457 GINT_TO_POINTER (suggested_action));
5460 static GdkDragAction
5461 get_status_pending (GdkDragContext *context)
5463 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5464 "gtk-icon-view-status-pending"));
5468 unset_reorderable (GtkIconView *icon_view)
5470 if (icon_view->priv->reorderable)
5472 icon_view->priv->reorderable = FALSE;
5473 g_object_notify (G_OBJECT (icon_view), "reorderable");
5478 clear_source_info (GtkIconView *icon_view)
5480 if (icon_view->priv->source_targets)
5481 gtk_target_list_unref (icon_view->priv->source_targets);
5482 icon_view->priv->source_targets = NULL;
5484 icon_view->priv->source_set = FALSE;
5488 clear_dest_info (GtkIconView *icon_view)
5490 if (icon_view->priv->dest_targets)
5491 gtk_target_list_unref (icon_view->priv->dest_targets);
5492 icon_view->priv->dest_targets = NULL;
5494 icon_view->priv->dest_set = FALSE;
5498 set_source_row (GdkDragContext *context,
5499 GtkTreeModel *model,
5500 GtkTreePath *source_row)
5503 g_object_set_data_full (G_OBJECT (context),
5504 "gtk-icon-view-source-row",
5505 gtk_tree_row_reference_new (model, source_row),
5506 (GDestroyNotify) gtk_tree_row_reference_free);
5508 g_object_set_data_full (G_OBJECT (context),
5509 "gtk-icon-view-source-row",
5514 get_source_row (GdkDragContext *context)
5516 GtkTreeRowReference *ref;
5518 ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
5521 return gtk_tree_row_reference_get_path (ref);
5528 GtkTreeRowReference *dest_row;
5529 gboolean empty_view_drop;
5530 gboolean drop_append_mode;
5534 dest_row_free (gpointer data)
5536 DestRow *dr = (DestRow *)data;
5538 gtk_tree_row_reference_free (dr->dest_row);
5543 set_dest_row (GdkDragContext *context,
5544 GtkTreeModel *model,
5545 GtkTreePath *dest_row,
5546 gboolean empty_view_drop,
5547 gboolean drop_append_mode)
5553 g_object_set_data_full (G_OBJECT (context),
5554 "gtk-icon-view-dest-row",
5559 dr = g_new0 (DestRow, 1);
5561 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5562 dr->empty_view_drop = empty_view_drop;
5563 dr->drop_append_mode = drop_append_mode;
5564 g_object_set_data_full (G_OBJECT (context),
5565 "gtk-icon-view-dest-row",
5566 dr, (GDestroyNotify) dest_row_free);
5570 get_dest_row (GdkDragContext *context)
5574 dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
5578 GtkTreePath *path = NULL;
5581 path = gtk_tree_row_reference_get_path (dr->dest_row);
5582 else if (dr->empty_view_drop)
5583 path = gtk_tree_path_new_from_indices (0, -1);
5587 if (path && dr->drop_append_mode)
5588 gtk_tree_path_next (path);
5597 check_model_dnd (GtkTreeModel *model,
5598 GType required_iface,
5599 const gchar *signal)
5601 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5603 g_warning ("You must override the default '%s' handler "
5604 "on GtkIconView when using models that don't support "
5605 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5606 "is to connect to '%s' and call "
5607 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5608 "the default handler from running. Look at the source code "
5609 "for the default handler in gtkiconview.c to get an idea what "
5610 "your handler should do. (gtkiconview.c is in the GTK+ source "
5611 "code.) If you're using GTK+ from a language other than C, "
5612 "there may be a more natural way to override default handlers, e.g. via derivation.",
5613 signal, g_type_name (required_iface), signal);
5621 remove_scroll_timeout (GtkIconView *icon_view)
5623 if (icon_view->priv->scroll_timeout_id != 0)
5625 g_source_remove (icon_view->priv->scroll_timeout_id);
5627 icon_view->priv->scroll_timeout_id = 0;
5632 gtk_icon_view_autoscroll (GtkIconView *icon_view)
5634 gint px, py, x, y, width, height;
5635 gint hoffset, voffset;
5638 gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
5639 gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
5641 /* see if we are near the edge. */
5642 voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
5644 voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
5646 hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
5648 hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
5652 value = CLAMP (icon_view->priv->vadjustment->value + voffset,
5653 icon_view->priv->vadjustment->lower,
5654 icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
5655 gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
5659 value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
5660 icon_view->priv->hadjustment->lower,
5661 icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
5662 gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
5668 drag_scroll_timeout (gpointer data)
5670 GtkIconView *icon_view = GTK_ICON_VIEW (data);
5672 GDK_THREADS_ENTER ();
5674 gtk_icon_view_autoscroll (icon_view);
5676 GDK_THREADS_LEAVE ();
5683 set_destination (GtkIconView *icon_view,
5684 GdkDragContext *context,
5687 GdkDragAction *suggested_action,
5691 GtkTreePath *path = NULL;
5692 GtkIconViewDropPosition pos;
5693 GtkIconViewDropPosition old_pos;
5694 GtkTreePath *old_dest_path = NULL;
5695 gboolean can_drop = FALSE;
5697 widget = GTK_WIDGET (icon_view);
5699 *suggested_action = 0;
5702 if (!icon_view->priv->dest_set)
5704 /* someone unset us as a drag dest, note that if
5705 * we return FALSE drag_leave isn't called
5708 gtk_icon_view_set_drag_dest_item (icon_view,
5710 GTK_ICON_VIEW_DROP_LEFT);
5712 remove_scroll_timeout (GTK_ICON_VIEW (widget));
5714 return FALSE; /* no longer a drop site */
5717 *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
5718 if (*target == GDK_NONE)
5721 if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
5724 GtkTreeModel *model;
5726 /* the row got dropped on empty space, let's setup a special case
5730 gtk_tree_path_free (path);
5732 model = gtk_icon_view_get_model (icon_view);
5734 n_children = gtk_tree_model_iter_n_children (model, NULL);
5737 pos = GTK_ICON_VIEW_DROP_BELOW;
5738 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5742 pos = GTK_ICON_VIEW_DROP_ABOVE;
5743 path = gtk_tree_path_new_from_indices (0, -1);
5753 gtk_icon_view_get_drag_dest_item (icon_view,
5758 gtk_tree_path_free (old_dest_path);
5760 if (TRUE /* FIXME if the location droppable predicate */)
5768 GtkWidget *source_widget;
5770 *suggested_action = context->suggested_action;
5771 source_widget = gtk_drag_get_source_widget (context);
5773 if (source_widget == widget)
5775 /* Default to MOVE, unless the user has
5776 * pressed ctrl or shift to affect available actions
5778 if ((context->actions & GDK_ACTION_MOVE) != 0)
5779 *suggested_action = GDK_ACTION_MOVE;
5782 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5787 /* can't drop here */
5788 gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
5790 GTK_ICON_VIEW_DROP_LEFT);
5794 gtk_tree_path_free (path);
5800 get_logical_destination (GtkIconView *icon_view,
5801 gboolean *drop_append_mode)
5803 /* adjust path to point to the row the drop goes in front of */
5804 GtkTreePath *path = NULL;
5805 GtkIconViewDropPosition pos;
5807 *drop_append_mode = FALSE;
5809 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
5814 if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
5815 pos == GTK_ICON_VIEW_DROP_BELOW)
5818 GtkTreeModel *model = icon_view->priv->model;
5820 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5821 !gtk_tree_model_iter_next (model, &iter))
5822 *drop_append_mode = TRUE;
5825 *drop_append_mode = FALSE;
5826 gtk_tree_path_next (path);
5834 gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
5835 GdkEventMotion *event)
5837 GdkDragContext *context;
5838 GtkTreePath *path = NULL;
5840 GtkTreeModel *model;
5841 gboolean retval = FALSE;
5843 if (!icon_view->priv->source_set)
5846 if (icon_view->priv->pressed_button < 0)
5849 if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
5850 icon_view->priv->press_start_x,
5851 icon_view->priv->press_start_y,
5852 event->x, event->y))
5855 model = gtk_icon_view_get_model (icon_view);
5860 button = icon_view->priv->pressed_button;
5861 icon_view->priv->pressed_button = -1;
5863 path = gtk_icon_view_get_path_at_pos (icon_view,
5864 icon_view->priv->press_start_x,
5865 icon_view->priv->press_start_y);
5870 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
5871 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
5875 /* FIXME Check whether we're a start button, if not return FALSE and
5879 /* Now we can begin the drag */
5883 context = gtk_drag_begin (GTK_WIDGET (icon_view),
5884 icon_view->priv->source_targets,
5885 icon_view->priv->source_actions,
5889 set_source_row (context, model, path);
5893 gtk_tree_path_free (path);
5898 /* Source side drag signals */
5900 gtk_icon_view_drag_begin (GtkWidget *widget,
5901 GdkDragContext *context)
5903 GtkIconView *icon_view;
5904 GtkIconViewItem *item;
5909 icon_view = GTK_ICON_VIEW (widget);
5911 /* if the user uses a custom DnD impl, we don't set the icon here */
5912 if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
5915 item = gtk_icon_view_get_item_at_coords (icon_view,
5916 icon_view->priv->press_start_x,
5917 icon_view->priv->press_start_y,
5921 g_return_if_fail (item != NULL);
5923 x = icon_view->priv->press_start_x - item->x + 1;
5924 y = icon_view->priv->press_start_y - item->y + 1;
5926 path = gtk_tree_path_new_from_indices (item->index, -1);
5927 icon = gtk_icon_view_create_drag_icon (icon_view, path);
5928 gtk_tree_path_free (path);
5930 gtk_drag_set_icon_pixmap (context,
5931 gdk_drawable_get_colormap (icon),
5936 g_object_unref (icon);
5940 gtk_icon_view_drag_end (GtkWidget *widget,
5941 GdkDragContext *context)
5947 gtk_icon_view_drag_data_get (GtkWidget *widget,
5948 GdkDragContext *context,
5949 GtkSelectionData *selection_data,
5953 GtkIconView *icon_view;
5954 GtkTreeModel *model;
5955 GtkTreePath *source_row;
5957 icon_view = GTK_ICON_VIEW (widget);
5958 model = gtk_icon_view_get_model (icon_view);
5963 if (!icon_view->priv->dest_set)
5966 source_row = get_source_row (context);
5968 if (source_row == NULL)
5971 /* We can implement the GTK_TREE_MODEL_ROW target generically for
5972 * any model; for DragSource models there are some other targets
5976 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
5977 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
5982 /* If drag_data_get does nothing, try providing row data. */
5983 if (selection_data->target == gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE))
5984 gtk_tree_set_row_drag_data (selection_data,
5989 gtk_tree_path_free (source_row);
5993 gtk_icon_view_drag_data_delete (GtkWidget *widget,
5994 GdkDragContext *context)
5996 GtkTreeModel *model;
5997 GtkIconView *icon_view;
5998 GtkTreePath *source_row;
6000 icon_view = GTK_ICON_VIEW (widget);
6001 model = gtk_icon_view_get_model (icon_view);
6003 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6006 if (!icon_view->priv->dest_set)
6009 source_row = get_source_row (context);
6011 if (source_row == NULL)
6014 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6017 gtk_tree_path_free (source_row);
6019 set_source_row (context, NULL, NULL);
6022 /* Target side drag signals */
6024 gtk_icon_view_drag_leave (GtkWidget *widget,
6025 GdkDragContext *context,
6028 GtkIconView *icon_view;
6030 icon_view = GTK_ICON_VIEW (widget);
6032 /* unset any highlight row */
6033 gtk_icon_view_set_drag_dest_item (icon_view,
6035 GTK_ICON_VIEW_DROP_LEFT);
6037 remove_scroll_timeout (icon_view);
6041 gtk_icon_view_drag_motion (GtkWidget *widget,
6042 GdkDragContext *context,
6047 GtkTreePath *path = NULL;
6048 GtkTreeModel *model;
6049 GtkIconViewDropPosition pos;
6050 GtkIconView *icon_view;
6051 GdkDragAction suggested_action = 0;
6055 icon_view = GTK_ICON_VIEW (widget);
6057 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6060 gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
6062 /* we only know this *after* set_desination_row */
6063 model = gtk_icon_view_get_model (icon_view);
6064 empty = icon_view->priv->empty_view_drop;
6066 if (path == NULL && !empty)
6068 /* Can't drop here. */
6069 gdk_drag_status (context, 0, time);
6073 if (icon_view->priv->scroll_timeout_id == 0)
6075 icon_view->priv->scroll_timeout_id =
6076 g_timeout_add (50, drag_scroll_timeout, icon_view);
6079 if (target == gdk_atom_intern ("GTK_TREE_MODEL_ROW", FALSE))
6081 /* Request data so we can use the source row when
6082 * determining whether to accept the drop
6084 set_status_pending (context, suggested_action);
6085 gtk_drag_get_data (widget, context, target, time);
6089 set_status_pending (context, 0);
6090 gdk_drag_status (context, suggested_action, time);
6095 gtk_tree_path_free (path);
6101 gtk_icon_view_drag_drop (GtkWidget *widget,
6102 GdkDragContext *context,
6107 GtkIconView *icon_view;
6109 GdkDragAction suggested_action = 0;
6110 GdkAtom target = GDK_NONE;
6111 GtkTreeModel *model;
6112 gboolean drop_append_mode;
6114 icon_view = GTK_ICON_VIEW (widget);
6115 model = gtk_icon_view_get_model (icon_view);
6117 remove_scroll_timeout (GTK_ICON_VIEW (widget));
6119 if (!icon_view->priv->dest_set)
6122 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6125 if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
6128 path = get_logical_destination (icon_view, &drop_append_mode);
6130 if (target != GDK_NONE && path != NULL)
6132 /* in case a motion had requested drag data, change things so we
6133 * treat drag data receives as a drop.
6135 set_status_pending (context, 0);
6136 set_dest_row (context, model, path,
6137 icon_view->priv->empty_view_drop, drop_append_mode);
6141 gtk_tree_path_free (path);
6143 /* Unset this thing */
6144 gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
6146 if (target != GDK_NONE)
6148 gtk_drag_get_data (widget, context, target, time);
6156 gtk_icon_view_drag_data_received (GtkWidget *widget,
6157 GdkDragContext *context,
6160 GtkSelectionData *selection_data,
6165 gboolean accepted = FALSE;
6166 GtkTreeModel *model;
6167 GtkIconView *icon_view;
6168 GtkTreePath *dest_row;
6169 GdkDragAction suggested_action;
6170 gboolean drop_append_mode;
6172 icon_view = GTK_ICON_VIEW (widget);
6173 model = gtk_icon_view_get_model (icon_view);
6175 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6178 if (!icon_view->priv->dest_set)
6181 suggested_action = get_status_pending (context);
6183 if (suggested_action)
6185 /* We are getting this data due to a request in drag_motion,
6186 * rather than due to a request in drag_drop, so we are just
6187 * supposed to call drag_status, not actually paste in the
6190 path = get_logical_destination (icon_view, &drop_append_mode);
6193 suggested_action = 0;
6195 if (suggested_action)
6197 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6200 suggested_action = 0;
6203 gdk_drag_status (context, suggested_action, time);
6206 gtk_tree_path_free (path);
6208 /* If you can't drop, remove user drop indicator until the next motion */
6209 if (suggested_action == 0)
6210 gtk_icon_view_set_drag_dest_item (icon_view,
6212 GTK_ICON_VIEW_DROP_LEFT);
6217 dest_row = get_dest_row (context);
6219 if (dest_row == NULL)
6222 if (selection_data->length >= 0)
6224 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6230 gtk_drag_finish (context,
6232 (context->action == GDK_ACTION_MOVE),
6235 gtk_tree_path_free (dest_row);
6238 set_dest_row (context, NULL, NULL, FALSE, FALSE);
6241 /* Drag-and-Drop support */
6243 * gtk_icon_view_enable_model_drag_source:
6244 * @icon_view: a #GtkIconTreeView
6245 * @start_button_mask: Mask of allowed buttons to start drag
6246 * @targets: the table of targets that the drag will support
6247 * @n_targets: the number of items in @targets
6248 * @actions: the bitmask of possible actions for a drag from this
6251 * Turns @icon_view into a drag source for automatic DND.
6256 gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
6257 GdkModifierType start_button_mask,
6258 const GtkTargetEntry *targets,
6260 GdkDragAction actions)
6262 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6264 gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6266 clear_source_info (icon_view);
6267 icon_view->priv->start_button_mask = start_button_mask;
6268 icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
6269 icon_view->priv->source_actions = actions;
6271 icon_view->priv->source_set = TRUE;
6273 unset_reorderable (icon_view);
6277 * gtk_icon_view_enable_model_drag_dest:
6278 * @icon_view: a #GtkIconView
6279 * @targets: the table of targets that the drag will support
6280 * @n_targets: the number of items in @targets
6281 * @actions: the bitmask of possible actions for a drag from this
6284 * Turns @icon_view into a drop destination for automatic DND.
6289 gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
6290 const GtkTargetEntry *targets,
6292 GdkDragAction actions)
6294 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6296 gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
6298 clear_dest_info (icon_view);
6300 icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
6301 icon_view->priv->dest_actions = actions;
6303 icon_view->priv->dest_set = TRUE;
6305 unset_reorderable (icon_view);
6309 * gtk_icon_view_unset_model_drag_source:
6310 * @icon_view: a #GtkIconView
6312 * Undoes the effect of gtk_icon_view_enable_model_drag_source().
6317 gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
6319 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6321 if (icon_view->priv->source_set)
6323 gtk_drag_source_unset (GTK_WIDGET (icon_view));
6324 clear_source_info (icon_view);
6327 unset_reorderable (icon_view);
6331 * gtk_icon_view_unset_model_drag_dest:
6332 * @icon_view: a #GtkIconView
6334 * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
6339 gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
6341 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6343 if (icon_view->priv->dest_set)
6345 gtk_drag_dest_unset (GTK_WIDGET (icon_view));
6346 clear_dest_info (icon_view);
6349 unset_reorderable (icon_view);
6352 /* These are useful to implement your own custom stuff. */
6354 * gtk_icon_view_set_drag_dest_item:
6355 * @icon_view: a #GtkIconView
6356 * @path: The path of the item to highlight, or %NULL.
6357 * @pos: Specifies whether to drop, relative to the item
6359 * Sets the item that is highlighted for feedback.
6364 gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
6366 GtkIconViewDropPosition pos)
6368 /* Note; this function is exported to allow a custom DND
6369 * implementation, so it can't touch TreeViewDragInfo
6372 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6374 if (icon_view->priv->dest_item)
6376 GtkTreePath *current_path;
6377 current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6378 gtk_tree_row_reference_free (icon_view->priv->dest_item);
6379 icon_view->priv->dest_item = NULL;
6381 gtk_icon_view_queue_draw_path (icon_view, current_path);
6382 gtk_tree_path_free (current_path);
6385 /* special case a drop on an empty model */
6386 icon_view->priv->empty_view_drop = FALSE;
6387 if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
6388 && gtk_tree_path_get_depth (path) == 1
6389 && gtk_tree_path_get_indices (path)[0] == 0)
6393 n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
6396 if (n_children == 0)
6397 icon_view->priv->empty_view_drop = TRUE;
6400 icon_view->priv->dest_pos = pos;
6404 icon_view->priv->dest_item =
6405 gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
6406 icon_view->priv->model, path);
6408 gtk_icon_view_queue_draw_path (icon_view, path);
6413 * gtk_icon_view_get_drag_dest_item:
6414 * @icon_view: a #GtkIconView
6415 * @path: Return location for the path of the highlighted item, or %NULL.
6416 * @pos: Return location for the drop position, or %NULL
6418 * Gets information about the item that is highlighted for feedback.
6423 gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
6425 GtkIconViewDropPosition *pos)
6427 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6431 if (icon_view->priv->dest_item)
6432 *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
6438 *pos = icon_view->priv->dest_pos;
6442 * gtk_icon_view_get_dest_item_at_pos:
6443 * @icon_view: a #GtkIconView
6444 * @drag_x: the position to determine the destination item for
6445 * @drag_y: the position to determine the destination item for
6446 * @path: Return location for the path of the highlighted item, or %NULL.
6447 * @pos: Return location for the drop position, or %NULL
6449 * Determines the destination item for a given position.
6451 * Return value: whether there is an item at the given position.
6456 gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
6460 GtkIconViewDropPosition *pos)
6462 GtkIconViewItem *item;
6464 /* Note; this function is exported to allow a custom DND
6465 * implementation, so it can't touch TreeViewDragInfo
6468 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6469 g_return_val_if_fail (drag_x >= 0, FALSE);
6470 g_return_val_if_fail (drag_y >= 0, FALSE);
6471 g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
6477 item = gtk_icon_view_get_item_at_coords (icon_view,
6478 drag_x + icon_view->priv->hadjustment->value,
6479 drag_y + icon_view->priv->vadjustment->value,
6486 *path = gtk_tree_path_new_from_indices (item->index, -1);
6490 if (drag_x < item->x + item->width / 4)
6491 *pos = GTK_ICON_VIEW_DROP_LEFT;
6492 else if (drag_x > item->x + item->width * 3 / 4)
6493 *pos = GTK_ICON_VIEW_DROP_RIGHT;
6494 else if (drag_y < item->y + item->height / 4)
6495 *pos = GTK_ICON_VIEW_DROP_ABOVE;
6496 else if (drag_y > item->y + item->height * 3 / 4)
6497 *pos = GTK_ICON_VIEW_DROP_BELOW;
6499 *pos = GTK_ICON_VIEW_DROP_INTO;
6506 * gtk_icon_view_create_drag_icon:
6507 * @icon_view: a #GtkIconView
6508 * @path: a #GtkTreePath in @icon_view
6510 * Creates a #GdkPixmap representation of the item at @path.
6511 * This image is used for a drag icon.
6513 * Return value: a newly-allocated pixmap of the drag icon.
6518 gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
6523 GdkPixmap *drawable;
6528 widget = GTK_WIDGET (icon_view);
6530 index = gtk_tree_path_get_indices (path)[0];
6532 for (l = icon_view->priv->items; l; l = l->next)
6534 GtkIconViewItem *item = l->data;
6536 if (index == item->index)
6538 drawable = gdk_pixmap_new (icon_view->priv->bin_window,
6543 cr = gdk_cairo_create (drawable);
6544 cairo_set_line_width (cr, 1.);
6546 gdk_cairo_set_source_color
6547 (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
6548 cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
6553 area.width = item->width;
6554 area.height = item->height;
6556 gtk_icon_view_paint_item (icon_view, cr, item, &area,
6557 drawable, 1, 1, FALSE);
6559 cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
6560 cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
6573 * gtk_icon_view_get_reorderable:
6574 * @icon_view: a #GtkIconView
6576 * Retrieves whether the user can reorder the list via drag-and-drop.
6577 * See gtk_icon_view_set_reorderable().
6579 * Return value: %TRUE if the list can be reordered.
6584 gtk_icon_view_get_reorderable (GtkIconView *icon_view)
6586 g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
6588 return icon_view->priv->reorderable;
6591 static const GtkTargetEntry item_targets[] = {
6592 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
6597 * gtk_icon_view_set_reorderable:
6598 * @icon_view: A #GtkIconView.
6599 * @reorderable: %TRUE, if the list of items can be reordered.
6601 * This function is a convenience function to allow you to reorder models that
6602 * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
6603 * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
6604 * the user can reorder the model by dragging and dropping rows. The
6605 * developer can listen to these changes by connecting to the model's
6606 * row_inserted and row_deleted signals.
6608 * This function does not give you any degree of control over the order -- any
6609 * reordering is allowed. If more control is needed, you should probably
6610 * handle drag and drop manually.
6615 gtk_icon_view_set_reorderable (GtkIconView *icon_view,
6616 gboolean reorderable)
6618 g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
6620 reorderable = reorderable != FALSE;
6622 if (icon_view->priv->reorderable == reorderable)
6627 gtk_icon_view_enable_model_drag_source (icon_view,
6630 G_N_ELEMENTS (item_targets),
6632 gtk_icon_view_enable_model_drag_dest (icon_view,
6634 G_N_ELEMENTS (item_targets),
6639 gtk_icon_view_unset_model_drag_source (icon_view);
6640 gtk_icon_view_unset_model_drag_dest (icon_view);
6643 icon_view->priv->reorderable = reorderable;
6645 g_object_notify (G_OBJECT (icon_view), "reorderable");
6649 /* Accessibility Support */
6651 static gpointer accessible_parent_class;
6652 static gpointer accessible_item_parent_class;
6653 static GQuark accessible_private_data_quark = 0;
6655 #define GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE (gtk_icon_view_item_accessible_get_type ())
6656 #define GTK_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE, GtkIconViewItemAccessible))
6657 #define GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ITEM_ACCESSIBLE))
6659 static GType gtk_icon_view_item_accessible_get_type (void);
6670 GtkIconViewItem *item;
6674 AtkStateSet *state_set;
6678 GtkTextBuffer *text_buffer;
6680 gchar *action_descriptions[LAST_ACTION];
6681 gchar *image_description;
6682 guint action_idle_handler;
6683 } GtkIconViewItemAccessible;
6685 static const gchar *const gtk_icon_view_item_accessible_action_names[] =
6691 static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
6696 typedef struct _GtkIconViewItemAccessibleClass
6698 AtkObjectClass parent_class;
6700 } GtkIconViewItemAccessibleClass;
6702 static gboolean gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item);
6705 gtk_icon_view_item_accessible_idle_do_action (gpointer data)
6707 GtkIconViewItemAccessible *item;
6708 GtkIconView *icon_view;
6711 GDK_THREADS_ENTER ();
6713 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
6714 item->action_idle_handler = 0;
6716 if (item->widget != NULL)
6718 icon_view = GTK_ICON_VIEW (item->widget);
6719 path = gtk_tree_path_new_from_indices (item->item->index, -1);
6720 gtk_icon_view_item_activated (icon_view, path);
6721 gtk_tree_path_free (path);
6724 GDK_THREADS_LEAVE ();
6730 gtk_icon_view_item_accessible_action_do_action (AtkAction *action,
6733 GtkIconViewItemAccessible *item;
6734 GtkIconView *icon_view;
6736 if (i < 0 || i >= LAST_ACTION)
6739 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6741 if (!GTK_IS_ICON_VIEW (item->widget))
6744 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6747 icon_view = GTK_ICON_VIEW (item->widget);
6751 case ACTION_ACTIVATE:
6752 if (!item->action_idle_handler)
6753 item->action_idle_handler = g_idle_add (gtk_icon_view_item_accessible_idle_do_action, item);
6756 g_assert_not_reached ();
6764 gtk_icon_view_item_accessible_action_get_n_actions (AtkAction *action)
6769 static const gchar *
6770 gtk_icon_view_item_accessible_action_get_description (AtkAction *action,
6773 GtkIconViewItemAccessible *item;
6775 if (i < 0 || i >= LAST_ACTION)
6778 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6780 if (item->action_descriptions[i])
6781 return item->action_descriptions[i];
6783 return gtk_icon_view_item_accessible_action_descriptions[i];
6786 static const gchar *
6787 gtk_icon_view_item_accessible_action_get_name (AtkAction *action,
6790 if (i < 0 || i >= LAST_ACTION)
6793 return gtk_icon_view_item_accessible_action_names[i];
6797 gtk_icon_view_item_accessible_action_set_description (AtkAction *action,
6799 const gchar *description)
6801 GtkIconViewItemAccessible *item;
6803 if (i < 0 || i >= LAST_ACTION)
6806 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (action);
6808 if (item->action_descriptions[i])
6809 g_free (item->action_descriptions[i]);
6811 item->action_descriptions[i] = g_strdup (description);
6817 atk_action_item_interface_init (AtkActionIface *iface)
6819 iface->do_action = gtk_icon_view_item_accessible_action_do_action;
6820 iface->get_n_actions = gtk_icon_view_item_accessible_action_get_n_actions;
6821 iface->get_description = gtk_icon_view_item_accessible_action_get_description;
6822 iface->get_name = gtk_icon_view_item_accessible_action_get_name;
6823 iface->set_description = gtk_icon_view_item_accessible_action_set_description;
6826 static const gchar *
6827 gtk_icon_view_item_accessible_image_get_image_description (AtkImage *image)
6829 GtkIconViewItemAccessible *item;
6831 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6833 return item->image_description;
6837 gtk_icon_view_item_accessible_image_set_image_description (AtkImage *image,
6838 const gchar *description)
6840 GtkIconViewItemAccessible *item;
6842 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6844 g_free (item->image_description);
6845 item->image_description = g_strdup (item->image_description);
6851 get_pixbuf_box (GtkIconView *icon_view,
6852 GtkIconViewItem *item,
6857 for (l = icon_view->priv->cell_list; l; l = l->next)
6859 GtkIconViewCellInfo *info = l->data;
6861 if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
6863 gtk_icon_view_get_cell_box (icon_view, item, info, box);
6873 get_text (GtkIconView *icon_view,
6874 GtkIconViewItem *item)
6879 for (l = icon_view->priv->cell_list; l; l = l->next)
6881 GtkIconViewCellInfo *info = l->data;
6883 if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
6885 g_object_get (info->cell, "text", &text, NULL);
6895 gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
6899 GtkIconViewItemAccessible *item;
6902 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6904 if (!GTK_IS_ICON_VIEW (item->widget))
6907 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6910 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
6913 *height = box.height;
6918 gtk_icon_view_item_accessible_image_get_image_position (AtkImage *image,
6921 AtkCoordType coord_type)
6923 GtkIconViewItemAccessible *item;
6926 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
6928 if (!GTK_IS_ICON_VIEW (item->widget))
6931 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6934 atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
6936 if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
6938 *x+= box.x - item->item->x;
6939 *y+= box.y - item->item->y;
6945 atk_image_item_interface_init (AtkImageIface *iface)
6947 iface->get_image_description = gtk_icon_view_item_accessible_image_get_image_description;
6948 iface->set_image_description = gtk_icon_view_item_accessible_image_set_image_description;
6949 iface->get_image_size = gtk_icon_view_item_accessible_image_get_image_size;
6950 iface->get_image_position = gtk_icon_view_item_accessible_image_get_image_position;
6954 gtk_icon_view_item_accessible_text_get_text (AtkText *text,
6958 GtkIconViewItemAccessible *item;
6959 GtkTextIter start, end;
6960 GtkTextBuffer *buffer;
6962 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
6964 if (!GTK_IS_ICON_VIEW (item->widget))
6967 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6970 buffer = item->text_buffer;
6971 gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
6973 gtk_text_buffer_get_end_iter (buffer, &end);
6975 gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
6977 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
6981 gtk_icon_view_item_accessible_text_get_character_at_offset (AtkText *text,
6984 GtkIconViewItemAccessible *item;
6985 GtkTextIter start, end;
6986 GtkTextBuffer *buffer;
6990 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
6992 if (!GTK_IS_ICON_VIEW (item->widget))
6995 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
6998 buffer = item->text_buffer;
6999 if (offset >= gtk_text_buffer_get_char_count (buffer))
7002 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7004 gtk_text_iter_forward_char (&end);
7005 string = gtk_text_buffer_get_slice (buffer, &start, &end, FALSE);
7006 unichar = g_utf8_get_char (string);
7013 get_pango_text_offsets (PangoLayout *layout,
7014 GtkTextBuffer *buffer,
7016 AtkTextBoundary boundary_type,
7020 GtkTextIter *start_iter,
7021 GtkTextIter *end_iter)
7023 PangoLayoutIter *iter;
7024 PangoLayoutLine *line, *prev_line = NULL, *prev_prev_line = NULL;
7025 gint index, start_index, end_index;
7027 gboolean found = FALSE;
7029 text = pango_layout_get_text (layout);
7030 index = g_utf8_offset_to_pointer (text, offset) - text;
7031 iter = pango_layout_get_iter (layout);
7034 line = pango_layout_iter_get_line (iter);
7035 start_index = line->start_index;
7036 end_index = start_index + line->length;
7038 if (index >= start_index && index <= end_index)
7041 * Found line for offset
7047 * We want the previous line
7051 switch (boundary_type)
7053 case ATK_TEXT_BOUNDARY_LINE_START:
7054 end_index = start_index;
7055 start_index = prev_line->start_index;
7057 case ATK_TEXT_BOUNDARY_LINE_END:
7059 start_index = prev_prev_line->start_index +
7060 prev_prev_line->length;
7061 end_index = prev_line->start_index + prev_line->length;
7064 g_assert_not_reached();
7068 start_index = end_index = 0;
7071 switch (boundary_type)
7073 case ATK_TEXT_BOUNDARY_LINE_START:
7074 if (pango_layout_iter_next_line (iter))
7075 end_index = pango_layout_iter_get_line (iter)->start_index;
7077 case ATK_TEXT_BOUNDARY_LINE_END:
7079 start_index = prev_line->start_index +
7083 g_assert_not_reached();
7088 * We want the next line
7090 if (pango_layout_iter_next_line (iter))
7092 line = pango_layout_iter_get_line (iter);
7093 switch (boundary_type)
7095 case ATK_TEXT_BOUNDARY_LINE_START:
7096 start_index = line->start_index;
7097 if (pango_layout_iter_next_line (iter))
7098 end_index = pango_layout_iter_get_line (iter)->start_index;
7100 end_index = start_index + line->length;
7102 case ATK_TEXT_BOUNDARY_LINE_END:
7103 start_index = end_index;
7104 end_index = line->start_index + line->length;
7107 g_assert_not_reached();
7111 start_index = end_index;
7117 prev_prev_line = prev_line;
7120 while (pango_layout_iter_next_line (iter));
7124 start_index = prev_line->start_index + prev_line->length;
7125 end_index = start_index;
7127 pango_layout_iter_free (iter);
7128 *start_offset = g_utf8_pointer_to_offset (text, text + start_index);
7129 *end_offset = g_utf8_pointer_to_offset (text, text + end_index);
7131 gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
7132 gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
7136 gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
7138 AtkTextBoundary boundary_type,
7142 GtkIconViewItemAccessible *item;
7143 GtkTextIter start, end;
7144 GtkTextBuffer *buffer;
7145 GtkIconView *icon_view;
7147 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7149 if (!GTK_IS_ICON_VIEW (item->widget))
7152 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7155 buffer = item->text_buffer;
7157 if (!gtk_text_buffer_get_char_count (buffer))
7161 return g_strdup ("");
7163 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7167 switch (boundary_type)
7169 case ATK_TEXT_BOUNDARY_CHAR:
7170 gtk_text_iter_backward_char(&start);
7172 case ATK_TEXT_BOUNDARY_WORD_START:
7173 if (!gtk_text_iter_starts_word (&start))
7174 gtk_text_iter_backward_word_start (&start);
7176 gtk_text_iter_backward_word_start(&start);
7178 case ATK_TEXT_BOUNDARY_WORD_END:
7179 if (gtk_text_iter_inside_word (&start) &&
7180 !gtk_text_iter_starts_word (&start))
7181 gtk_text_iter_backward_word_start (&start);
7182 while (!gtk_text_iter_ends_word (&start))
7184 if (!gtk_text_iter_backward_char (&start))
7188 gtk_text_iter_backward_word_start(&start);
7189 while (!gtk_text_iter_ends_word (&start))
7191 if (!gtk_text_iter_backward_char (&start))
7195 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7196 if (!gtk_text_iter_starts_sentence (&start))
7197 gtk_text_iter_backward_sentence_start (&start);
7199 gtk_text_iter_backward_sentence_start (&start);
7201 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7202 if (gtk_text_iter_inside_sentence (&start) &&
7203 !gtk_text_iter_starts_sentence (&start))
7204 gtk_text_iter_backward_sentence_start (&start);
7205 while (!gtk_text_iter_ends_sentence (&start))
7207 if (!gtk_text_iter_backward_char (&start))
7211 gtk_text_iter_backward_sentence_start (&start);
7212 while (!gtk_text_iter_ends_sentence (&start))
7214 if (!gtk_text_iter_backward_char (&start))
7218 case ATK_TEXT_BOUNDARY_LINE_START:
7219 case ATK_TEXT_BOUNDARY_LINE_END:
7220 icon_view = GTK_ICON_VIEW (item->widget);
7222 /* FIXME we probably have to use GailTextCell to salvage this */
7223 gtk_icon_view_update_item_text (icon_view, item->item);
7224 get_pango_text_offsets (icon_view->priv->layout,
7237 *start_offset = gtk_text_iter_get_offset (&start);
7238 *end_offset = gtk_text_iter_get_offset (&end);
7240 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7244 gtk_icon_view_item_accessible_text_get_text_at_offset (AtkText *text,
7246 AtkTextBoundary boundary_type,
7250 GtkIconViewItemAccessible *item;
7251 GtkTextIter start, end;
7252 GtkTextBuffer *buffer;
7253 GtkIconView *icon_view;
7255 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7257 if (!GTK_IS_ICON_VIEW (item->widget))
7260 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7263 buffer = item->text_buffer;
7265 if (!gtk_text_buffer_get_char_count (buffer))
7269 return g_strdup ("");
7271 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7275 switch (boundary_type)
7277 case ATK_TEXT_BOUNDARY_CHAR:
7278 gtk_text_iter_forward_char (&end);
7280 case ATK_TEXT_BOUNDARY_WORD_START:
7281 if (!gtk_text_iter_starts_word (&start))
7282 gtk_text_iter_backward_word_start (&start);
7283 if (gtk_text_iter_inside_word (&end))
7284 gtk_text_iter_forward_word_end (&end);
7285 while (!gtk_text_iter_starts_word (&end))
7287 if (!gtk_text_iter_forward_char (&end))
7291 case ATK_TEXT_BOUNDARY_WORD_END:
7292 if (gtk_text_iter_inside_word (&start) &&
7293 !gtk_text_iter_starts_word (&start))
7294 gtk_text_iter_backward_word_start (&start);
7295 while (!gtk_text_iter_ends_word (&start))
7297 if (!gtk_text_iter_backward_char (&start))
7300 gtk_text_iter_forward_word_end (&end);
7302 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7303 if (!gtk_text_iter_starts_sentence (&start))
7304 gtk_text_iter_backward_sentence_start (&start);
7305 if (gtk_text_iter_inside_sentence (&end))
7306 gtk_text_iter_forward_sentence_end (&end);
7307 while (!gtk_text_iter_starts_sentence (&end))
7309 if (!gtk_text_iter_forward_char (&end))
7313 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7314 if (gtk_text_iter_inside_sentence (&start) &&
7315 !gtk_text_iter_starts_sentence (&start))
7316 gtk_text_iter_backward_sentence_start (&start);
7317 while (!gtk_text_iter_ends_sentence (&start))
7319 if (!gtk_text_iter_backward_char (&start))
7322 gtk_text_iter_forward_sentence_end (&end);
7324 case ATK_TEXT_BOUNDARY_LINE_START:
7325 case ATK_TEXT_BOUNDARY_LINE_END:
7326 icon_view = GTK_ICON_VIEW (item->widget);
7328 /* FIXME we probably have to use GailTextCell to salvage this */
7329 gtk_icon_view_update_item_text (icon_view, item->item);
7330 get_pango_text_offsets (icon_view->priv->layout,
7344 *start_offset = gtk_text_iter_get_offset (&start);
7345 *end_offset = gtk_text_iter_get_offset (&end);
7347 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7351 gtk_icon_view_item_accessible_text_get_text_after_offset (AtkText *text,
7353 AtkTextBoundary boundary_type,
7357 GtkIconViewItemAccessible *item;
7358 GtkTextIter start, end;
7359 GtkTextBuffer *buffer;
7360 GtkIconView *icon_view;
7362 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7364 if (!GTK_IS_ICON_VIEW (item->widget))
7367 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7370 buffer = item->text_buffer;
7372 if (!gtk_text_buffer_get_char_count (buffer))
7376 return g_strdup ("");
7378 gtk_text_buffer_get_iter_at_offset (buffer, &start, offset);
7382 switch (boundary_type)
7384 case ATK_TEXT_BOUNDARY_CHAR:
7385 gtk_text_iter_forward_char(&start);
7386 gtk_text_iter_forward_chars(&end, 2);
7388 case ATK_TEXT_BOUNDARY_WORD_START:
7389 if (gtk_text_iter_inside_word (&end))
7390 gtk_text_iter_forward_word_end (&end);
7391 while (!gtk_text_iter_starts_word (&end))
7393 if (!gtk_text_iter_forward_char (&end))
7397 if (!gtk_text_iter_is_end (&end))
7399 gtk_text_iter_forward_word_end (&end);
7400 while (!gtk_text_iter_starts_word (&end))
7402 if (!gtk_text_iter_forward_char (&end))
7407 case ATK_TEXT_BOUNDARY_WORD_END:
7408 gtk_text_iter_forward_word_end (&end);
7410 if (!gtk_text_iter_is_end (&end))
7411 gtk_text_iter_forward_word_end (&end);
7413 case ATK_TEXT_BOUNDARY_SENTENCE_START:
7414 if (gtk_text_iter_inside_sentence (&end))
7415 gtk_text_iter_forward_sentence_end (&end);
7416 while (!gtk_text_iter_starts_sentence (&end))
7418 if (!gtk_text_iter_forward_char (&end))
7422 if (!gtk_text_iter_is_end (&end))
7424 gtk_text_iter_forward_sentence_end (&end);
7425 while (!gtk_text_iter_starts_sentence (&end))
7427 if (!gtk_text_iter_forward_char (&end))
7432 case ATK_TEXT_BOUNDARY_SENTENCE_END:
7433 gtk_text_iter_forward_sentence_end (&end);
7435 if (!gtk_text_iter_is_end (&end))
7436 gtk_text_iter_forward_sentence_end (&end);
7438 case ATK_TEXT_BOUNDARY_LINE_START:
7439 case ATK_TEXT_BOUNDARY_LINE_END:
7440 icon_view = GTK_ICON_VIEW (item->widget);
7442 /* FIXME we probably have to use GailTextCell to salvage this */
7443 gtk_icon_view_update_item_text (icon_view, item->item);
7444 get_pango_text_offsets (icon_view->priv->layout,
7456 *start_offset = gtk_text_iter_get_offset (&start);
7457 *end_offset = gtk_text_iter_get_offset (&end);
7459 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
7463 gtk_icon_view_item_accessible_text_get_character_count (AtkText *text)
7465 GtkIconViewItemAccessible *item;
7467 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7469 if (!GTK_IS_ICON_VIEW (item->widget))
7472 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7475 return gtk_text_buffer_get_char_count (item->text_buffer);
7479 gtk_icon_view_item_accessible_text_get_character_extents (AtkText *text,
7485 AtkCoordType coord_type)
7487 GtkIconViewItemAccessible *item;
7488 GtkIconView *icon_view;
7489 PangoRectangle char_rect;
7490 const gchar *item_text;
7493 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7495 if (!GTK_IS_ICON_VIEW (item->widget))
7498 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7501 icon_view = GTK_ICON_VIEW (item->widget);
7503 /* FIXME we probably have to use GailTextCell to salvage this */
7504 gtk_icon_view_update_item_text (icon_view, item->item);
7505 item_text = pango_layout_get_text (icon_view->priv->layout);
7506 index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
7507 pango_layout_index_to_pos (icon_view->priv->layout, index, &char_rect);
7509 atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
7510 *x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
7511 /* Look at gtk_icon_view_paint_item() to see where the text is. */
7512 *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7513 *y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
7514 *width = char_rect.width / PANGO_SCALE;
7515 *height = char_rect.height / PANGO_SCALE;
7520 gtk_icon_view_item_accessible_text_get_offset_at_point (AtkText *text,
7523 AtkCoordType coord_type)
7525 GtkIconViewItemAccessible *item;
7526 GtkIconView *icon_view;
7527 const gchar *item_text;
7532 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
7534 if (!GTK_IS_ICON_VIEW (item->widget))
7537 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7540 icon_view = GTK_ICON_VIEW (item->widget);
7542 /* FIXME we probably have to use GailTextCell to salvage this */
7543 gtk_icon_view_update_item_text (icon_view, item->item);
7544 atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
7545 x -= l_x + item->item->layout_x - item->item->x;
7546 x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
7547 y -= l_y + item->item->layout_y - item->item->y;
7548 item_text = pango_layout_get_text (icon_view->priv->layout);
7549 if (!pango_layout_xy_to_index (icon_view->priv->layout,
7560 offset = g_utf8_strlen (item_text, -1);
7562 offset = g_utf8_pointer_to_offset (item_text, item_text + index);
7568 atk_text_item_interface_init (AtkTextIface *iface)
7570 iface->get_text = gtk_icon_view_item_accessible_text_get_text;
7571 iface->get_character_at_offset = gtk_icon_view_item_accessible_text_get_character_at_offset;
7572 iface->get_text_before_offset = gtk_icon_view_item_accessible_text_get_text_before_offset;
7573 iface->get_text_at_offset = gtk_icon_view_item_accessible_text_get_text_at_offset;
7574 iface->get_text_after_offset = gtk_icon_view_item_accessible_text_get_text_after_offset;
7575 iface->get_character_count = gtk_icon_view_item_accessible_text_get_character_count;
7576 iface->get_character_extents = gtk_icon_view_item_accessible_text_get_character_extents;
7577 iface->get_offset_at_point = gtk_icon_view_item_accessible_text_get_offset_at_point;
7581 gtk_icon_view_item_accessible_get_extents (AtkComponent *component,
7586 AtkCoordType coord_type)
7588 GtkIconViewItemAccessible *item;
7589 AtkObject *parent_obj;
7592 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component));
7594 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7595 if (!GTK_IS_WIDGET (item->widget))
7598 if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
7601 *width = item->item->width;
7602 *height = item->item->height;
7603 if (gtk_icon_view_item_accessible_is_showing (item))
7605 parent_obj = gtk_widget_get_accessible (item->widget);
7606 atk_component_get_position (ATK_COMPONENT (parent_obj), &l_x, &l_y, coord_type);
7607 *x = l_x + item->item->x;
7608 *y = l_y + item->item->y;
7618 gtk_icon_view_item_accessible_grab_focus (AtkComponent *component)
7620 GtkIconViewItemAccessible *item;
7621 GtkWidget *toplevel;
7623 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (component), FALSE);
7625 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (component);
7626 if (!GTK_IS_WIDGET (item->widget))
7629 gtk_widget_grab_focus (item->widget);
7630 gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
7631 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
7632 if (GTK_WIDGET_TOPLEVEL (toplevel))
7633 gtk_window_present (GTK_WINDOW (toplevel));
7639 atk_component_item_interface_init (AtkComponentIface *iface)
7641 iface->get_extents = gtk_icon_view_item_accessible_get_extents;
7642 iface->grab_focus = gtk_icon_view_item_accessible_grab_focus;
7646 gtk_icon_view_item_accessible_add_state (GtkIconViewItemAccessible *item,
7647 AtkStateType state_type,
7648 gboolean emit_signal)
7652 rc = atk_state_set_add_state (item->state_set, state_type);
7654 * The signal should only be generated if the value changed,
7655 * not when the item is set up. So states that are set
7656 * initially should pass FALSE as the emit_signal argument.
7661 atk_object_notify_state_change (ATK_OBJECT (item), state_type, TRUE);
7662 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7663 if (state_type == ATK_STATE_VISIBLE)
7664 g_signal_emit_by_name (item, "visible_data_changed");
7671 gtk_icon_view_item_accessible_remove_state (GtkIconViewItemAccessible *item,
7672 AtkStateType state_type,
7673 gboolean emit_signal)
7675 if (atk_state_set_contains_state (item->state_set, state_type))
7679 rc = atk_state_set_remove_state (item->state_set, state_type);
7681 * The signal should only be generated if the value changed,
7682 * not when the item is set up. So states that are set
7683 * initially should pass FALSE as the emit_signal argument.
7688 atk_object_notify_state_change (ATK_OBJECT (item), state_type, FALSE);
7689 /* If state_type is ATK_STATE_VISIBLE, additional notification */
7690 if (state_type == ATK_STATE_VISIBLE)
7691 g_signal_emit_by_name (item, "visible_data_changed");
7701 gtk_icon_view_item_accessible_is_showing (GtkIconViewItemAccessible *item)
7703 GtkIconView *icon_view;
7704 GdkRectangle visible_rect;
7705 gboolean is_showing;
7708 * An item is considered "SHOWING" if any part of the item is in the
7709 * visible rectangle.
7712 if (!GTK_IS_ICON_VIEW (item->widget))
7715 if (item->item == NULL)
7718 icon_view = GTK_ICON_VIEW (item->widget);
7720 if (icon_view->priv->hadjustment)
7721 visible_rect.x += icon_view->priv->hadjustment->value;
7723 if (icon_view->priv->hadjustment)
7724 visible_rect.y += icon_view->priv->vadjustment->value;
7725 visible_rect.width = item->widget->allocation.width;
7726 visible_rect.height = item->widget->allocation.height;
7728 if (((item->item->x + item->item->width) < visible_rect.x) ||
7729 ((item->item->y + item->item->height) < (visible_rect.y)) ||
7730 (item->item->x > (visible_rect.x + visible_rect.width)) ||
7731 (item->item->y > (visible_rect.y + visible_rect.height)))
7740 gtk_icon_view_item_accessible_set_visibility (GtkIconViewItemAccessible *item,
7741 gboolean emit_signal)
7743 if (gtk_icon_view_item_accessible_is_showing (item))
7744 return gtk_icon_view_item_accessible_add_state (item, ATK_STATE_SHOWING,
7747 return gtk_icon_view_item_accessible_remove_state (item, ATK_STATE_SHOWING,
7752 gtk_icon_view_item_accessible_object_init (GtkIconViewItemAccessible *item)
7756 item->state_set = atk_state_set_new ();
7758 atk_state_set_add_state (item->state_set, ATK_STATE_ENABLED);
7759 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSABLE);
7760 atk_state_set_add_state (item->state_set, ATK_STATE_SENSITIVE);
7761 atk_state_set_add_state (item->state_set, ATK_STATE_SELECTABLE);
7762 atk_state_set_add_state (item->state_set, ATK_STATE_VISIBLE);
7764 for (i = 0; i < LAST_ACTION; i++)
7765 item->action_descriptions[i] = NULL;
7767 item->image_description = NULL;
7769 item->action_idle_handler = 0;
7773 gtk_icon_view_item_accessible_finalize (GObject *object)
7775 GtkIconViewItemAccessible *item;
7778 g_return_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (object));
7780 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (object);
7783 g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
7785 if (item->state_set)
7786 g_object_unref (item->state_set);
7788 if (item->text_buffer)
7789 g_object_unref (item->text_buffer);
7791 for (i = 0; i < LAST_ACTION; i++)
7792 g_free (item->action_descriptions[i]);
7794 g_free (item->image_description);
7796 if (item->action_idle_handler)
7798 g_source_remove (item->action_idle_handler);
7799 item->action_idle_handler = 0;
7802 G_OBJECT_CLASS (accessible_item_parent_class)->finalize (object);
7805 static G_CONST_RETURN gchar*
7806 gtk_icon_view_item_accessible_get_name (AtkObject *obj)
7812 GtkIconViewItemAccessible *item;
7813 GtkTextIter start_iter;
7814 GtkTextIter end_iter;
7816 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7818 gtk_text_buffer_get_start_iter (item->text_buffer, &start_iter);
7819 gtk_text_buffer_get_end_iter (item->text_buffer, &end_iter);
7821 return gtk_text_buffer_get_text (item->text_buffer, &start_iter, &end_iter, FALSE);
7826 gtk_icon_view_item_accessible_get_parent (AtkObject *obj)
7828 GtkIconViewItemAccessible *item;
7830 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), NULL);
7831 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7834 return gtk_widget_get_accessible (item->widget);
7840 gtk_icon_view_item_accessible_get_index_in_parent (AtkObject *obj)
7842 GtkIconViewItemAccessible *item;
7844 g_return_val_if_fail (GTK_IS_ICON_VIEW_ITEM_ACCESSIBLE (obj), 0);
7845 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7847 return item->item->index;
7850 static AtkStateSet *
7851 gtk_icon_view_item_accessible_ref_state_set (AtkObject *obj)
7853 GtkIconViewItemAccessible *item;
7854 GtkIconView *icon_view;
7856 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
7857 g_return_val_if_fail (item->state_set, NULL);
7862 icon_view = GTK_ICON_VIEW (item->widget);
7863 if (icon_view->priv->cursor_item == item->item)
7864 atk_state_set_add_state (item->state_set, ATK_STATE_FOCUSED);
7866 atk_state_set_remove_state (item->state_set, ATK_STATE_FOCUSED);
7868 return g_object_ref (item->state_set);
7872 gtk_icon_view_item_accessible_class_init (AtkObjectClass *klass)
7874 GObjectClass *gobject_class;
7876 accessible_item_parent_class = g_type_class_peek_parent (klass);
7878 gobject_class = (GObjectClass *)klass;
7880 gobject_class->finalize = gtk_icon_view_item_accessible_finalize;
7882 klass->get_index_in_parent = gtk_icon_view_item_accessible_get_index_in_parent;
7883 klass->get_name = gtk_icon_view_item_accessible_get_name;
7884 klass->get_parent = gtk_icon_view_item_accessible_get_parent;
7885 klass->ref_state_set = gtk_icon_view_item_accessible_ref_state_set;
7889 gtk_icon_view_item_accessible_get_type (void)
7891 static GType type = 0;
7895 static const GTypeInfo tinfo =
7897 sizeof (GtkIconViewItemAccessibleClass),
7898 (GBaseInitFunc) NULL, /* base init */
7899 (GBaseFinalizeFunc) NULL, /* base finalize */
7900 (GClassInitFunc) gtk_icon_view_item_accessible_class_init, /* class init */
7901 (GClassFinalizeFunc) NULL, /* class finalize */
7902 NULL, /* class data */
7903 sizeof (GtkIconViewItemAccessible), /* instance size */
7904 0, /* nb preallocs */
7905 (GInstanceInitFunc) gtk_icon_view_item_accessible_object_init, /* instance init */
7906 NULL /* value table */
7909 static const GInterfaceInfo atk_component_info =
7911 (GInterfaceInitFunc) atk_component_item_interface_init,
7912 (GInterfaceFinalizeFunc) NULL,
7915 static const GInterfaceInfo atk_action_info =
7917 (GInterfaceInitFunc) atk_action_item_interface_init,
7918 (GInterfaceFinalizeFunc) NULL,
7921 static const GInterfaceInfo atk_image_info =
7923 (GInterfaceInitFunc) atk_image_item_interface_init,
7924 (GInterfaceFinalizeFunc) NULL,
7927 static const GInterfaceInfo atk_text_info =
7929 (GInterfaceInitFunc) atk_text_item_interface_init,
7930 (GInterfaceFinalizeFunc) NULL,
7934 type = g_type_register_static (ATK_TYPE_OBJECT,
7935 "GtkIconViewItemAccessible", &tinfo, 0);
7936 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
7937 &atk_component_info);
7938 g_type_add_interface_static (type, ATK_TYPE_ACTION,
7940 g_type_add_interface_static (type, ATK_TYPE_IMAGE,
7942 g_type_add_interface_static (type, ATK_TYPE_TEXT,
7949 #define GTK_TYPE_ICON_VIEW_ACCESSIBLE (gtk_icon_view_accessible_get_type ())
7950 #define GTK_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE, GtkIconViewAccessible))
7951 #define GTK_IS_ICON_VIEW_ACCESSIBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_VIEW_ACCESSIBLE))
7953 static GType gtk_icon_view_accessible_get_type (void);
7958 } GtkIconViewAccessible;
7964 } GtkIconViewItemAccessibleInfo;
7970 GtkAdjustment *old_hadj;
7971 GtkAdjustment *old_vadj;
7973 GtkTreeModel *model;
7975 } GtkIconViewAccessiblePrivate;
7977 static GtkIconViewAccessiblePrivate *
7978 gtk_icon_view_accessible_get_priv (AtkObject *accessible)
7980 return g_object_get_qdata (G_OBJECT (accessible),
7981 accessible_private_data_quark);
7985 gtk_icon_view_item_accessible_info_new (AtkObject *accessible,
7989 GtkIconViewItemAccessibleInfo *info;
7990 GtkIconViewItemAccessibleInfo *tmp_info;
7991 GtkIconViewAccessiblePrivate *priv;
7994 info = g_new (GtkIconViewItemAccessibleInfo, 1);
7996 info->index = index;
7998 priv = gtk_icon_view_accessible_get_priv (accessible);
7999 items = priv->items;
8002 tmp_info = items->data;
8003 if (tmp_info->index > index)
8005 items = items->next;
8007 priv->items = g_list_insert_before (priv->items, items, info);
8008 priv->old_hadj = NULL;
8009 priv->old_vadj = NULL;
8013 gtk_icon_view_accessible_get_n_children (AtkObject *accessible)
8015 GtkIconView *icon_view;
8018 widget = GTK_ACCESSIBLE (accessible)->widget;
8022 icon_view = GTK_ICON_VIEW (widget);
8024 return g_list_length (icon_view->priv->items);
8028 gtk_icon_view_accessible_find_child (AtkObject *accessible,
8031 GtkIconViewAccessiblePrivate *priv;
8032 GtkIconViewItemAccessibleInfo *info;
8035 priv = gtk_icon_view_accessible_get_priv (accessible);
8036 items = priv->items;
8041 if (info->index == index)
8043 items = items->next;
8049 gtk_icon_view_accessible_ref_child (AtkObject *accessible,
8052 GtkIconView *icon_view;
8056 GtkIconViewItemAccessible *a11y_item;
8058 widget = GTK_ACCESSIBLE (accessible)->widget;
8062 icon_view = GTK_ICON_VIEW (widget);
8063 icons = g_list_nth (icon_view->priv->items, index);
8067 GtkIconViewItem *item = icons->data;
8069 g_return_val_if_fail (item->index == index, NULL);
8070 obj = gtk_icon_view_accessible_find_child (accessible, index);
8073 obj = g_object_new (gtk_icon_view_item_accessible_get_type (), NULL);
8074 gtk_icon_view_item_accessible_info_new (accessible,
8077 obj->role = ATK_ROLE_ICON;
8078 a11y_item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (obj);
8079 a11y_item->item = item;
8080 a11y_item->widget = widget;
8081 a11y_item->text_buffer = gtk_text_buffer_new (NULL);
8083 gtk_icon_view_set_cell_data (icon_view, item);
8084 gtk_text_buffer_set_text (a11y_item->text_buffer,
8085 get_text (icon_view, item), -1);
8087 gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
8088 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
8096 gtk_icon_view_accessible_traverse_items (GtkIconViewAccessible *view,
8099 GtkIconViewAccessiblePrivate *priv;
8100 GtkIconViewItemAccessibleInfo *info;
8101 GtkIconViewItemAccessible *item;
8104 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (view));
8108 gboolean act_on_item;
8110 widget = GTK_ACCESSIBLE (view)->widget;
8114 items = priv->items;
8116 act_on_item = (list == NULL);
8121 info = (GtkIconViewItemAccessibleInfo *)items->data;
8122 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8124 if (act_on_item == FALSE && list == items)
8128 gtk_icon_view_item_accessible_set_visibility (item, TRUE);
8130 items = items->next;
8136 gtk_icon_view_accessible_adjustment_changed (GtkAdjustment *adjustment,
8137 GtkIconView *icon_view)
8140 GtkIconViewAccessible *view;
8143 * The scrollbars have changed
8145 obj = gtk_widget_get_accessible (GTK_WIDGET (icon_view));
8146 view = GTK_ICON_VIEW_ACCESSIBLE (obj);
8148 gtk_icon_view_accessible_traverse_items (view, NULL);
8152 gtk_icon_view_accessible_set_scroll_adjustments (GtkWidget *widget,
8153 GtkAdjustment *hadj,
8154 GtkAdjustment *vadj)
8157 GtkIconViewAccessiblePrivate *priv;
8159 atk_obj = gtk_widget_get_accessible (widget);
8160 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8162 if (priv->old_hadj != hadj)
8166 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8167 (gpointer *)&priv->old_hadj);
8169 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8170 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8173 priv->old_hadj = hadj;
8176 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj),
8177 (gpointer *)&priv->old_hadj);
8178 g_signal_connect (hadj,
8180 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8184 if (priv->old_vadj != vadj)
8188 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8189 (gpointer *)&priv->old_vadj);
8191 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8192 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8195 priv->old_vadj = vadj;
8198 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj),
8199 (gpointer *)&priv->old_vadj);
8200 g_signal_connect (vadj,
8202 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8209 gtk_icon_view_accessible_model_row_changed (GtkTreeModel *tree_model,
8216 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8217 g_signal_emit_by_name (atk_obj, "visible-data-changed");
8223 gtk_icon_view_accessible_model_row_inserted (GtkTreeModel *tree_model,
8228 GtkIconViewAccessiblePrivate *priv;
8229 GtkIconViewItemAccessibleInfo *info;
8230 GtkIconViewAccessible *view;
8231 GtkIconViewItemAccessible *item;
8237 index = gtk_tree_path_get_indices(path)[0];
8238 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8239 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8240 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8242 items = priv->items;
8247 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8248 if (info->index != item->item->index)
8250 if (info->index < index)
8251 g_warning ("Unexpected index value on insertion %d %d", index, info->index);
8253 if (tmp_list == NULL)
8256 info->index = item->item->index;
8259 items = items->next;
8261 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8262 g_signal_emit_by_name (atk_obj, "children_changed::add",
8268 gtk_icon_view_accessible_model_row_deleted (GtkTreeModel *tree_model,
8272 GtkIconViewAccessiblePrivate *priv;
8273 GtkIconViewItemAccessibleInfo *info;
8274 GtkIconViewAccessible *view;
8275 GtkIconViewItemAccessible *item;
8278 GList *deleted_item;
8282 index = gtk_tree_path_get_indices(path)[0];
8283 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8284 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8285 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8287 items = priv->items;
8289 deleted_item = NULL;
8294 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8295 if (info->index == index)
8297 deleted_item = items;
8299 if (info->index != item->item->index)
8301 if (tmp_list == NULL)
8304 info->index = item->item->index;
8307 items = items->next;
8309 gtk_icon_view_accessible_traverse_items (view, tmp_list);
8312 info = deleted_item->data;
8313 gtk_icon_view_item_accessible_add_state (GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item), ATK_STATE_DEFUNCT, TRUE);
8315 g_signal_emit_by_name (atk_obj, "children_changed::remove",
8319 priv->items = g_list_remove_link (priv->items, deleted_item);
8327 gtk_icon_view_accessible_item_compare (GtkIconViewItemAccessibleInfo *i1,
8328 GtkIconViewItemAccessibleInfo *i2)
8330 return i1->index - i2->index;
8334 gtk_icon_view_accessible_model_rows_reordered (GtkTreeModel *tree_model,
8340 GtkIconViewAccessiblePrivate *priv;
8341 GtkIconViewItemAccessibleInfo *info;
8342 GtkIconViewAccessible *view;
8343 GtkIconView *icon_view;
8344 GtkIconViewItemAccessible *item;
8349 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
8350 icon_view = GTK_ICON_VIEW (user_data);
8351 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8352 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8354 items = priv->items;
8359 item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
8360 info->index = new_order[info->index];
8361 tmp_list = g_list_nth (icon_view->priv->items, info->index);
8362 item->item = tmp_list->data;
8363 items = items->next;
8365 priv->items = g_list_sort (priv->items,
8366 (GCompareFunc)gtk_icon_view_accessible_item_compare);
8372 gtk_icon_view_accessible_disconnect_model_signals (GtkTreeModel *model,
8377 obj = G_OBJECT (model);
8378 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_changed, widget);
8379 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_inserted, widget);
8380 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_row_deleted, widget);
8381 g_signal_handlers_disconnect_by_func (obj, (gpointer) gtk_icon_view_accessible_model_rows_reordered, widget);
8385 gtk_icon_view_accessible_connect_model_signals (GtkIconView *icon_view)
8389 obj = G_OBJECT (icon_view->priv->model);
8390 g_signal_connect_data (obj, "row-changed",
8391 (GCallback) gtk_icon_view_accessible_model_row_changed,
8392 icon_view, NULL, 0);
8393 g_signal_connect_data (obj, "row-inserted",
8394 (GCallback) gtk_icon_view_accessible_model_row_inserted,
8395 icon_view, NULL, G_CONNECT_AFTER);
8396 g_signal_connect_data (obj, "row-deleted",
8397 (GCallback) gtk_icon_view_accessible_model_row_deleted,
8398 icon_view, NULL, G_CONNECT_AFTER);
8399 g_signal_connect_data (obj, "rows-reordered",
8400 (GCallback) gtk_icon_view_accessible_model_rows_reordered,
8401 icon_view, NULL, G_CONNECT_AFTER);
8405 gtk_icon_view_accessible_clear_cache (GtkIconViewAccessiblePrivate *priv)
8407 GtkIconViewItemAccessibleInfo *info;
8410 items = priv->items;
8413 info = (GtkIconViewItemAccessibleInfo *) items->data;
8414 g_object_unref (info->item);
8415 g_free (items->data);
8416 items = items->next;
8418 g_list_free (priv->items);
8423 gtk_icon_view_accessible_notify_gtk (GObject *obj,
8426 GtkIconView *icon_view;
8429 GtkIconViewAccessible *view;
8430 GtkIconViewAccessiblePrivate *priv;
8432 if (strcmp (pspec->name, "model") == 0)
8434 widget = GTK_WIDGET (obj);
8435 atk_obj = gtk_widget_get_accessible (widget);
8436 view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
8437 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8440 g_object_remove_weak_pointer (G_OBJECT (priv->model),
8441 (gpointer *)&priv->model);
8442 gtk_icon_view_accessible_disconnect_model_signals (priv->model, widget);
8444 gtk_icon_view_accessible_clear_cache (priv);
8446 icon_view = GTK_ICON_VIEW (obj);
8447 priv->model = icon_view->priv->model;
8448 /* If there is no model the GtkIconView is probably being destroyed */
8451 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8452 gtk_icon_view_accessible_connect_model_signals (icon_view);
8460 gtk_icon_view_accessible_initialize (AtkObject *accessible,
8463 GtkIconViewAccessiblePrivate *priv;
8464 GtkIconView *icon_view;
8466 if (ATK_OBJECT_CLASS (accessible_parent_class)->initialize)
8467 ATK_OBJECT_CLASS (accessible_parent_class)->initialize (accessible, data);
8469 priv = g_new0 (GtkIconViewAccessiblePrivate, 1);
8470 g_object_set_qdata (G_OBJECT (accessible),
8471 accessible_private_data_quark,
8474 icon_view = GTK_ICON_VIEW (data);
8475 if (icon_view->priv->hadjustment)
8477 priv->old_hadj = icon_view->priv->hadjustment;
8478 g_object_add_weak_pointer (G_OBJECT (priv->old_hadj), (gpointer *)&priv->old_hadj);
8479 g_signal_connect (icon_view->priv->hadjustment,
8481 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8484 if (icon_view->priv->vadjustment)
8486 priv->old_vadj = icon_view->priv->vadjustment;
8487 g_object_add_weak_pointer (G_OBJECT (priv->old_vadj), (gpointer *)&priv->old_vadj);
8488 g_signal_connect (icon_view->priv->vadjustment,
8490 G_CALLBACK (gtk_icon_view_accessible_adjustment_changed),
8493 g_signal_connect_after (data,
8494 "set_scroll_adjustments",
8495 G_CALLBACK (gtk_icon_view_accessible_set_scroll_adjustments),
8497 g_signal_connect (data,
8499 G_CALLBACK (gtk_icon_view_accessible_notify_gtk),
8502 priv->model = icon_view->priv->model;
8505 g_object_add_weak_pointer (G_OBJECT (priv->model), (gpointer *)&priv->model);
8506 gtk_icon_view_accessible_connect_model_signals (icon_view);
8509 accessible->role = ATK_ROLE_LAYERED_PANE;
8513 gtk_icon_view_accessible_finalize (GObject *object)
8515 GtkIconViewAccessiblePrivate *priv;
8517 priv = gtk_icon_view_accessible_get_priv (ATK_OBJECT (object));
8518 gtk_icon_view_accessible_clear_cache (priv);
8522 G_OBJECT_CLASS (accessible_parent_class)->finalize (object);
8526 gtk_icon_view_accessible_destroyed (GtkWidget *widget,
8527 GtkAccessible *accessible)
8530 GtkIconViewAccessiblePrivate *priv;
8532 atk_obj = ATK_OBJECT (accessible);
8533 priv = gtk_icon_view_accessible_get_priv (atk_obj);
8536 g_object_remove_weak_pointer (G_OBJECT (priv->old_hadj),
8537 (gpointer *)&priv->old_hadj);
8539 g_signal_handlers_disconnect_by_func (priv->old_hadj,
8540 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8542 priv->old_hadj = NULL;
8546 g_object_remove_weak_pointer (G_OBJECT (priv->old_vadj),
8547 (gpointer *)&priv->old_vadj);
8549 g_signal_handlers_disconnect_by_func (priv->old_vadj,
8550 (gpointer) gtk_icon_view_accessible_adjustment_changed,
8552 priv->old_vadj = NULL;
8557 gtk_icon_view_accessible_connect_widget_destroyed (GtkAccessible *accessible)
8559 if (accessible->widget)
8561 g_signal_connect_after (accessible->widget,
8563 G_CALLBACK (gtk_icon_view_accessible_destroyed),
8566 GTK_ACCESSIBLE_CLASS (accessible_parent_class)->connect_widget_destroyed (accessible);
8570 gtk_icon_view_accessible_class_init (AtkObjectClass *klass)
8572 GObjectClass *gobject_class;
8573 GtkAccessibleClass *accessible_class;
8575 accessible_parent_class = g_type_class_peek_parent (klass);
8577 gobject_class = (GObjectClass *)klass;
8578 accessible_class = (GtkAccessibleClass *)klass;
8580 gobject_class->finalize = gtk_icon_view_accessible_finalize;
8582 klass->get_n_children = gtk_icon_view_accessible_get_n_children;
8583 klass->ref_child = gtk_icon_view_accessible_ref_child;
8584 klass->initialize = gtk_icon_view_accessible_initialize;
8586 accessible_class->connect_widget_destroyed = gtk_icon_view_accessible_connect_widget_destroyed;
8588 accessible_private_data_quark = g_quark_from_static_string ("icon_view-accessible-private-data");
8592 gtk_icon_view_accessible_ref_accessible_at_point (AtkComponent *component,
8595 AtkCoordType coord_type)
8598 GtkIconView *icon_view;
8599 GtkIconViewItem *item;
8602 widget = GTK_ACCESSIBLE (component)->widget;
8604 /* State is defunct */
8607 icon_view = GTK_ICON_VIEW (widget);
8608 atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
8609 item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
8611 return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
8617 atk_component_interface_init (AtkComponentIface *iface)
8619 iface->ref_accessible_at_point = gtk_icon_view_accessible_ref_accessible_at_point;
8623 gtk_icon_view_accessible_add_selection (AtkSelection *selection,
8627 GtkIconView *icon_view;
8628 GtkIconViewItem *item;
8631 widget = GTK_ACCESSIBLE (selection)->widget;
8635 icon_view = GTK_ICON_VIEW (widget);
8637 l = g_list_nth (icon_view->priv->items, i);
8642 gtk_icon_view_select_item (icon_view, item);
8648 gtk_icon_view_accessible_clear_selection (AtkSelection *selection)
8651 GtkIconView *icon_view;
8653 widget = GTK_ACCESSIBLE (selection)->widget;
8657 icon_view = GTK_ICON_VIEW (widget);
8658 gtk_icon_view_unselect_all (icon_view);
8664 gtk_icon_view_accessible_ref_selection (AtkSelection *selection,
8668 GtkIconView *icon_view;
8669 GtkIconViewItem *item;
8672 widget = GTK_ACCESSIBLE (selection)->widget;
8676 icon_view = GTK_ICON_VIEW (widget);
8678 l = icon_view->priv->items;
8685 return atk_object_ref_accessible_child (gtk_widget_get_accessible (widget), item->index);
8696 gtk_icon_view_accessible_get_selection_count (AtkSelection *selection)
8699 GtkIconView *icon_view;
8700 GtkIconViewItem *item;
8704 widget = GTK_ACCESSIBLE (selection)->widget;
8708 icon_view = GTK_ICON_VIEW (widget);
8710 l = icon_view->priv->items;
8726 gtk_icon_view_accessible_is_child_selected (AtkSelection *selection,
8730 GtkIconView *icon_view;
8731 GtkIconViewItem *item;
8734 widget = GTK_ACCESSIBLE (selection)->widget;
8738 icon_view = GTK_ICON_VIEW (widget);
8739 l = g_list_nth (icon_view->priv->items, i);
8745 return item->selected;
8749 gtk_icon_view_accessible_remove_selection (AtkSelection *selection,
8753 GtkIconView *icon_view;
8754 GtkIconViewItem *item;
8758 widget = GTK_ACCESSIBLE (selection)->widget;
8762 icon_view = GTK_ICON_VIEW (widget);
8763 l = icon_view->priv->items;
8772 gtk_icon_view_unselect_item (icon_view, item);
8784 gtk_icon_view_accessible_select_all_selection (AtkSelection *selection)
8787 GtkIconView *icon_view;
8789 widget = GTK_ACCESSIBLE (selection)->widget;
8793 icon_view = GTK_ICON_VIEW (widget);
8794 gtk_icon_view_select_all (icon_view);
8799 gtk_icon_view_accessible_selection_interface_init (AtkSelectionIface *iface)
8801 iface->add_selection = gtk_icon_view_accessible_add_selection;
8802 iface->clear_selection = gtk_icon_view_accessible_clear_selection;
8803 iface->ref_selection = gtk_icon_view_accessible_ref_selection;
8804 iface->get_selection_count = gtk_icon_view_accessible_get_selection_count;
8805 iface->is_child_selected = gtk_icon_view_accessible_is_child_selected;
8806 iface->remove_selection = gtk_icon_view_accessible_remove_selection;
8807 iface->select_all_selection = gtk_icon_view_accessible_select_all_selection;
8811 gtk_icon_view_accessible_get_type (void)
8813 static GType type = 0;
8817 static GTypeInfo tinfo =
8820 (GBaseInitFunc) NULL, /* base init */
8821 (GBaseFinalizeFunc) NULL, /* base finalize */
8822 (GClassInitFunc) gtk_icon_view_accessible_class_init,
8823 (GClassFinalizeFunc) NULL, /* class finalize */
8824 NULL, /* class data */
8825 0, /* instance size */
8826 0, /* nb preallocs */
8827 (GInstanceInitFunc) NULL, /* instance init */
8828 NULL /* value table */
8830 static const GInterfaceInfo atk_component_info =
8832 (GInterfaceInitFunc) atk_component_interface_init,
8833 (GInterfaceFinalizeFunc) NULL,
8836 static const GInterfaceInfo atk_selection_info =
8838 (GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
8839 (GInterfaceFinalizeFunc) NULL,
8844 * Figure out the size of the class and instance
8845 * we are deriving from
8847 AtkObjectFactory *factory;
8850 GType derived_atk_type;
8852 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
8853 factory = atk_registry_get_factory (atk_get_default_registry (),
8855 derived_atk_type = atk_object_factory_get_accessible_type (factory);
8856 g_type_query (derived_atk_type, &query);
8857 tinfo.class_size = query.class_size;
8858 tinfo.instance_size = query.instance_size;
8860 type = g_type_register_static (derived_atk_type,
8861 "GtkIconViewAccessible",
8863 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
8864 &atk_component_info);
8865 g_type_add_interface_static (type, ATK_TYPE_SELECTION,
8866 &atk_selection_info);
8872 gtk_icon_view_accessible_new (GObject *obj)
8874 AtkObject *accessible;
8876 g_return_val_if_fail (GTK_IS_WIDGET (obj), NULL);
8878 accessible = g_object_new (gtk_icon_view_accessible_get_type (), NULL);
8879 atk_object_initialize (accessible, obj);
8885 gtk_icon_view_accessible_factory_get_accessible_type (void)
8887 return gtk_icon_view_accessible_get_type ();
8891 gtk_icon_view_accessible_factory_create_accessible (GObject *obj)
8893 return gtk_icon_view_accessible_new (obj);
8897 gtk_icon_view_accessible_factory_class_init (AtkObjectFactoryClass *klass)
8899 klass->create_accessible = gtk_icon_view_accessible_factory_create_accessible;
8900 klass->get_accessible_type = gtk_icon_view_accessible_factory_get_accessible_type;
8904 gtk_icon_view_accessible_factory_get_type (void)
8906 static GType type = 0;
8910 static const GTypeInfo tinfo =
8912 sizeof (AtkObjectFactoryClass),
8913 NULL, /* base_init */
8914 NULL, /* base_finalize */
8915 (GClassInitFunc) gtk_icon_view_accessible_factory_class_init,
8916 NULL, /* class_finalize */
8917 NULL, /* class_data */
8918 sizeof (AtkObjectFactory),
8919 0, /* n_preallocs */
8923 type = g_type_register_static (ATK_TYPE_OBJECT_FACTORY,
8924 "GtkIconViewAccessibleFactory",
8932 gtk_icon_view_get_accessible (GtkWidget *widget)
8934 static gboolean first_time = TRUE;
8938 AtkObjectFactory *factory;
8939 AtkRegistry *registry;
8941 GType derived_atk_type;
8944 * Figure out whether accessibility is enabled by looking at the
8945 * type of the accessible object which would be created for
8946 * the parent type of GtkIconView.
8948 derived_type = g_type_parent (GTK_TYPE_ICON_VIEW);
8950 registry = atk_get_default_registry ();
8951 factory = atk_registry_get_factory (registry,
8953 derived_atk_type = atk_object_factory_get_accessible_type (factory);
8954 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
8955 atk_registry_set_factory_type (registry,
8957 gtk_icon_view_accessible_factory_get_type ());
8960 return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
8963 #define __GTK_ICON_VIEW_C__
8964 #include "gtkaliasdef.c"