#include <gdk/gdkkeysyms.h>
-#include "gtkalias.h"
#include "gtkiconview.h"
+#include "gtkcelllayout.h"
+#include "gtkcellrenderer.h"
+#include "gtkcellrenderertext.h"
+#include "gtkcellrendererpixbuf.h"
#include "gtkmarshalers.h"
#include "gtkbindings.h"
#include "gtkdnd.h"
#include "gtkintl.h"
#include "gtkaccessible.h"
#include "gtkwindow.h"
+#include "gtkentry.h"
+#include "gtkcombobox.h"
#include "gtktextbuffer.h"
+#include "gtktreednd.h"
+#include "gtkprivate.h"
+#include "gtkalias.h"
-#define MINIMUM_ICON_ITEM_WIDTH 100
-#define ICON_TEXT_PADDING 3
+#undef DEBUG_ICON_VIEW
-#define ICON_VIEW_TOP_MARGIN 6
-#define ICON_VIEW_BOTTOM_MARGIN 6
-#define ICON_VIEW_LEFT_MARGIN 6
-#define ICON_VIEW_RIGHT_MARGIN 6
-#define ICON_VIEW_ICON_PADDING 6
+#define SCROLL_EDGE_SIZE 15
#define GTK_ICON_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ICON_VIEW, GtkIconViewPrivate))
-#define VALID_MODEL_AND_COLUMNS(obj) ((obj)->priv->model != NULL && \
- ((obj)->priv->pixbuf_column != -1 || \
- (obj)->priv->text_column != -1 || \
- (obj)->priv->markup_column != -1))
-typedef struct
+typedef struct _GtkIconViewItem GtkIconViewItem;
+struct _GtkIconViewItem
{
GtkTreeIter iter;
- int index;
+ gint index;
gint row, col;
- /* Bounding boxes */
- gint x, y;
- gint width, height;
-
- gint pixbuf_x, pixbuf_y;
- gint pixbuf_height, pixbuf_width;
+ /* Bounding box */
+ gint x, y, width, height;
- gint layout_x, layout_y;
- gint layout_width, layout_height;
+ /* Individual cells.
+ * box[i] is the actual area occupied by cell i,
+ * before, after are used to calculate the cell
+ * area relative to the box.
+ * See gtk_icon_view_get_cell_area().
+ */
+ gint n_cells;
+ GdkRectangle *box;
+ gint *before;
+ gint *after;
guint selected : 1;
guint selected_before_rubberbanding : 1;
-} GtkIconViewItem;
+
+};
+
+typedef struct _GtkIconViewCellInfo GtkIconViewCellInfo;
+struct _GtkIconViewCellInfo
+{
+ GtkCellRenderer *cell;
+
+ guint expand : 1;
+ guint pack : 1;
+ guint editing : 1;
+
+ gint position;
+
+ GSList *attributes;
+
+ GtkCellLayoutDataFunc func;
+ gpointer func_data;
+ GDestroyNotify destroy;
+};
+
+typedef struct _GtkIconViewChild GtkIconViewChild;
+struct _GtkIconViewChild
+{
+ GtkWidget *widget;
+ GtkIconViewItem *item;
+ gint cell;
+};
struct _GtkIconViewPrivate
{
gint width, height;
- gint text_column;
- gint markup_column;
- gint pixbuf_column;
-
GtkSelectionMode selection_mode;
GdkWindow *bin_window;
+ GList *children;
+
GtkTreeModel *model;
GList *items;
GtkIconViewItem *anchor_item;
GtkIconViewItem *cursor_item;
+ GtkIconViewItem *edited_item;
+ GtkCellEditable *editable;
- guint ctrl_pressed : 1;
- guint shift_pressed : 1;
-
GtkIconViewItem *last_single_clicked;
-#ifdef DND_WORKS
+ GList *cell_list;
+ guint n_cells;
+
+ gint cursor_cell;
+
+ GtkOrientation orientation;
+
+ gint columns;
+ gint item_width;
+ gint spacing;
+ gint row_spacing;
+ gint column_spacing;
+ gint margin;
+
+ gint text_column;
+ gint markup_column;
+ gint pixbuf_column;
+
+ gint pixbuf_cell;
+ gint text_cell;
+
/* Drag-and-drop. */
+ GdkModifierType start_button_mask;
gint pressed_button;
gint press_start_x;
gint press_start_y;
-#endif
- /* Layout used to draw icon text */
- PangoLayout *layout;
-
- GtkOrientation orientation;
+ GtkTargetList *source_targets;
+ GdkDragAction source_actions;
+
+ GtkTargetList *dest_targets;
+ GdkDragAction dest_actions;
+
+ GtkTreeRowReference *dest_item;
+ GtkIconViewDropPosition dest_pos;
+
+ /* scroll to */
+ GtkTreeRowReference *scroll_to_path;
+ gfloat scroll_to_row_align;
+ gfloat scroll_to_col_align;
+ guint scroll_to_use_align : 1;
+
+ guint source_set : 1;
+ guint dest_set : 1;
+ guint reorderable : 1;
+ guint empty_view_drop :1;
+
+ guint ctrl_pressed : 1;
+ guint shift_pressed : 1;
};
/* Signals */
PROP_SELECTION_MODE,
PROP_ORIENTATION,
PROP_MODEL,
+ PROP_COLUMNS,
+ PROP_ITEM_WIDTH,
+ PROP_SPACING,
+ PROP_ROW_SPACING,
+ PROP_COLUMN_SPACING,
+ PROP_MARGIN,
+ PROP_REORDERABLE
};
-/* GObject signals */
-static void gtk_icon_view_finalize (GObject *object);
-static void gtk_icon_view_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_icon_view_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
+/* GObject vfuncs */
+static void gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface);
+static void gtk_icon_view_finalize (GObject *object);
+static void gtk_icon_view_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void gtk_icon_view_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+/* GtkObject vfuncs */
+static void gtk_icon_view_destroy (GtkObject *object);
+
+/* GtkWidget vfuncs */
+static void gtk_icon_view_realize (GtkWidget *widget);
+static void gtk_icon_view_unrealize (GtkWidget *widget);
+static void gtk_icon_view_style_set (GtkWidget *widget,
+ GtkStyle *previous_style);
+static void gtk_icon_view_state_changed (GtkWidget *widget,
+ GtkStateType previous_state);
+static void gtk_icon_view_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static void gtk_icon_view_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+static gboolean gtk_icon_view_expose (GtkWidget *widget,
+ GdkEventExpose *expose);
+static gboolean gtk_icon_view_motion (GtkWidget *widget,
+ GdkEventMotion *event);
+static gboolean gtk_icon_view_button_press (GtkWidget *widget,
+ GdkEventButton *event);
+static gboolean gtk_icon_view_button_release (GtkWidget *widget,
+ GdkEventButton *event);
+static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
+
+
+/* GtkContainer vfuncs */
+static void gtk_icon_view_remove (GtkContainer *container,
+ GtkWidget *widget);
+static void gtk_icon_view_forall (GtkContainer *container,
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data);
+
+/* GtkIconView vfuncs */
+static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
+ GtkAdjustment *hadj,
+ GtkAdjustment *vadj);
+static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
+static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
+static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
+static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
+static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
+
+ /* Internal functions */
+static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
+ GtkIconView *icon_view);
+static void gtk_icon_view_layout (GtkIconView *icon_view);
+static void gtk_icon_view_paint_item (GtkIconView *icon_view,
+ cairo_t *cr,
+
+ GtkIconViewItem *item,
+ GdkRectangle *area,
+ GdkDrawable *drawable,
+ gint x,
+ gint y,
+ gboolean draw_focus);
+static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
+ cairo_t *cr,
+ GdkRectangle *area);
+static void gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
+ GtkTreePath *path);
+static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
+ GtkIconViewItem *item);
+static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
+static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
+ GtkIconViewItem *item,
+ gint cursor_cell);
+static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
+ gint x,
+ gint y);
+static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
+static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
+static gboolean gtk_icon_view_item_hit_test (GtkIconView *icon_view,
+ GtkIconViewItem *item,
+ gint x,
+ gint y,
+ gint width,
+ gint height);
+static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
+static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
+ GtkIconViewItem *item);
+static void gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
+ GtkIconViewItem *item,
+ gint *max_height);
+static void gtk_icon_view_update_rubberband (gpointer data);
+static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
+static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
+static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
+ guint keyval,
+ guint modmask,
+ GtkMovementStep step,
+ gint count);
+static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
+ GtkMovementStep step,
+ gint count);
+static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
+ gint count);
+static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
+ gint count);
+static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
+ gint count);
+static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
+ gint count);
+static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
+ GtkIconViewItem *item);
+static void gtk_icon_view_select_item (GtkIconView *icon_view,
+ GtkIconViewItem *item);
+static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
+ GtkIconViewItem *item);
+static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
+ GtkIconViewItem *anchor,
+ GtkIconViewItem *cursor);
+static GtkIconViewItem * gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
+ gint x,
+ gint y,
+ gboolean only_in_cell,
+ GtkIconViewCellInfo **cell_at_pos);
+static void gtk_icon_view_get_cell_area (GtkIconView *icon_view,
+ GtkIconViewItem *item,
+ GtkIconViewCellInfo *cell_info,
+ GdkRectangle *cell_area);
+static void gtk_icon_view_get_cell_box (GtkIconView *icon_view,
+ GtkIconViewItem *item,
+ GtkIconViewCellInfo *info,
+ GdkRectangle *box);
+static GtkIconViewCellInfo *gtk_icon_view_get_cell_info (GtkIconView *icon_view,
+ GtkCellRenderer *renderer);
+static void gtk_icon_view_set_cell_data (GtkIconView *icon_view,
+ GtkIconViewItem *item);
+static void gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
+ GtkCellRenderer *renderer,
+ gboolean expand);
+static void gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
+ GtkCellRenderer *renderer,
+ gboolean expand);
+static void gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
+ GtkCellRenderer *renderer,
+ const gchar *attribute,
+ gint column);
+static void gtk_icon_view_cell_layout_clear (GtkCellLayout *layout);
+static void gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
+ GtkCellRenderer *renderer);
+static void gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
+ GtkCellRenderer *cell,
+ GtkCellLayoutDataFunc func,
+ gpointer func_data,
+ GDestroyNotify destroy);
+static void gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
+ GtkCellRenderer *cell,
+ gint position);
+static void gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
+ GtkIconViewItem *item,
+ GtkIconViewCellInfo *cell_info,
+ GdkEvent *event);
+static void gtk_icon_view_put (GtkIconView *icon_view,
+ GtkWidget *widget,
+ GtkIconViewItem *item,
+ gint cell);
+static void gtk_icon_view_remove_widget (GtkCellEditable *editable,
+ GtkIconView *icon_view);
+static void gtk_icon_view_start_editing (GtkIconView *icon_view,
+ GtkIconViewItem *item,
+ GtkIconViewCellInfo *cell_info,
+ GdkEvent *event);
+static void gtk_icon_view_stop_editing (GtkIconView *icon_view,
+ gboolean cancel_editing);
+
+/* Source side drag signals */
+static void gtk_icon_view_drag_begin (GtkWidget *widget,
+ GdkDragContext *context);
+static void gtk_icon_view_drag_end (GtkWidget *widget,
+ GdkDragContext *context);
+static void gtk_icon_view_drag_data_get (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time);
+static void gtk_icon_view_drag_data_delete (GtkWidget *widget,
+ GdkDragContext *context);
+
+/* Target side drag signals */
+static void gtk_icon_view_drag_leave (GtkWidget *widget,
+ GdkDragContext *context,
+ guint time);
+static gboolean gtk_icon_view_drag_motion (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time);
+static gboolean gtk_icon_view_drag_drop (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time);
+static void gtk_icon_view_drag_data_received (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time);
+static gboolean gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
+ GdkEventMotion *event);
+
+static void remove_scroll_timeout (GtkIconView *icon_view);
-/* GtkObject signals */
-static void gtk_icon_view_destroy (GtkObject *object);
-
-/* GtkWidget signals */
-static void gtk_icon_view_realize (GtkWidget *widget);
-static void gtk_icon_view_unrealize (GtkWidget *widget);
-static void gtk_icon_view_map (GtkWidget *widget);
-static void gtk_icon_view_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static void gtk_icon_view_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-static gboolean gtk_icon_view_expose (GtkWidget *widget,
- GdkEventExpose *expose);
-static gboolean gtk_icon_view_motion (GtkWidget *widget,
- GdkEventMotion *event);
-static gboolean gtk_icon_view_button_press (GtkWidget *widget,
- GdkEventButton *event);
-static gboolean gtk_icon_view_button_release (GtkWidget *widget,
- GdkEventButton *event);
-/* GtkIconView signals */
-static void gtk_icon_view_set_adjustments (GtkIconView *icon_view,
- GtkAdjustment *hadj,
- GtkAdjustment *vadj);
-static void gtk_icon_view_real_select_all (GtkIconView *icon_view);
-static void gtk_icon_view_real_unselect_all (GtkIconView *icon_view);
-static void gtk_icon_view_real_select_cursor_item (GtkIconView *icon_view);
-static void gtk_icon_view_real_toggle_cursor_item (GtkIconView *icon_view);
-static gboolean gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view);
-
-/* Internal functions */
-static void gtk_icon_view_adjustment_changed (GtkAdjustment *adjustment,
- GtkIconView *icon_view);
-static void gtk_icon_view_layout (GtkIconView *icon_view);
-static void gtk_icon_view_paint_item (GtkIconView *icon_view,
- GtkIconViewItem *item,
- GdkRectangle *area);
-static void gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
- GdkRectangle *area);
-static void gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
- GtkIconViewItem *item);
-static void gtk_icon_view_queue_layout (GtkIconView *icon_view);
-static void gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
- GtkIconViewItem *item);
-static void gtk_icon_view_start_rubberbanding (GtkIconView *icon_view,
- gint x,
- gint y);
-static void gtk_icon_view_stop_rubberbanding (GtkIconView *icon_view);
-static void gtk_icon_view_update_rubberband_selection (GtkIconView *icon_view);
-static gboolean gtk_icon_view_item_hit_test (GtkIconViewItem *item,
- gint x,
- gint y,
- gint width,
- gint height);
-#ifdef DND_WORKS
-static gboolean gtk_icon_view_maybe_begin_dragging_items (GtkIconView *icon_view,
- GdkEventMotion *event);
-#endif
-static gboolean gtk_icon_view_unselect_all_internal (GtkIconView *icon_view);
-static void gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
- GtkIconViewItem *item);
-static void gtk_icon_view_update_rubberband (gpointer data);
-static void gtk_icon_view_item_invalidate_size (GtkIconViewItem *item);
-static void gtk_icon_view_invalidate_sizes (GtkIconView *icon_view);
-static void gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
- guint keyval,
- guint modmask,
- GtkMovementStep step,
- gint count);
-static gboolean gtk_icon_view_real_move_cursor (GtkIconView *icon_view,
- GtkMovementStep step,
- gint count);
-static void gtk_icon_view_move_cursor_up_down (GtkIconView *icon_view,
- gint count);
-static void gtk_icon_view_move_cursor_page_up_down (GtkIconView *icon_view,
- gint count);
-static void gtk_icon_view_move_cursor_left_right (GtkIconView *icon_view,
- gint count);
-static void gtk_icon_view_move_cursor_start_end (GtkIconView *icon_view,
- gint count);
-static void gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
- GtkIconViewItem *item);
-static GdkPixbuf *gtk_icon_view_get_item_icon (GtkIconView *icon_view,
- GtkIconViewItem *item);
-static void gtk_icon_view_update_item_text (GtkIconView *icon_view,
- GtkIconViewItem *item);
-static void gtk_icon_view_select_item (GtkIconView *icon_view,
- GtkIconViewItem *item);
-static void gtk_icon_view_unselect_item (GtkIconView *icon_view,
- GtkIconViewItem *item);
-static gboolean gtk_icon_view_select_all_between (GtkIconView *icon_view,
- GtkIconViewItem *anchor,
- GtkIconViewItem *cursor);
-
-static GtkIconViewItem *gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
- gint x,
- gint y);
-
-
-/* Accessibility Support */
-static AtkObject *gtk_icon_view_get_accessible (GtkWidget *widget);
-
-static GtkContainerClass *parent_class = NULL;
static guint icon_view_signals[LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER);
+G_DEFINE_TYPE_WITH_CODE (GtkIconView, gtk_icon_view, GTK_TYPE_CONTAINER,
+ G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_LAYOUT,
+ gtk_icon_view_cell_layout_init))
static void
gtk_icon_view_class_init (GtkIconViewClass *klass)
GObjectClass *gobject_class;
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
+ GtkContainerClass *container_class;
GtkBindingSet *binding_set;
- parent_class = g_type_class_peek_parent (klass);
binding_set = gtk_binding_set_by_class (klass);
g_type_class_add_private (klass, sizeof (GtkIconViewPrivate));
gobject_class = (GObjectClass *) klass;
object_class = (GtkObjectClass *) klass;
widget_class = (GtkWidgetClass *) klass;
+ container_class = (GtkContainerClass *) klass;
gobject_class->finalize = gtk_icon_view_finalize;
gobject_class->set_property = gtk_icon_view_set_property;
widget_class->realize = gtk_icon_view_realize;
widget_class->unrealize = gtk_icon_view_unrealize;
- widget_class->map = gtk_icon_view_map;
+ widget_class->style_set = gtk_icon_view_style_set;
+ widget_class->get_accessible = gtk_icon_view_get_accessible;
widget_class->size_request = gtk_icon_view_size_request;
widget_class->size_allocate = gtk_icon_view_size_allocate;
widget_class->expose_event = gtk_icon_view_expose;
widget_class->motion_notify_event = gtk_icon_view_motion;
widget_class->button_press_event = gtk_icon_view_button_press;
widget_class->button_release_event = gtk_icon_view_button_release;
- widget_class->get_accessible = gtk_icon_view_get_accessible;
+ widget_class->drag_begin = gtk_icon_view_drag_begin;
+ widget_class->drag_end = gtk_icon_view_drag_end;
+ widget_class->drag_data_get = gtk_icon_view_drag_data_get;
+ widget_class->drag_data_delete = gtk_icon_view_drag_data_delete;
+ widget_class->drag_leave = gtk_icon_view_drag_leave;
+ widget_class->drag_motion = gtk_icon_view_drag_motion;
+ widget_class->drag_drop = gtk_icon_view_drag_drop;
+ widget_class->drag_data_received = gtk_icon_view_drag_data_received;
+ widget_class->state_changed = gtk_icon_view_state_changed;
+
+ container_class->remove = gtk_icon_view_remove;
+ container_class->forall = gtk_icon_view_forall;
klass->set_scroll_adjustments = gtk_icon_view_set_adjustments;
klass->select_all = gtk_icon_view_real_select_all;
*/
g_object_class_install_property (gobject_class,
PROP_SELECTION_MODE,
- g_param_spec_enum ("selection_mode",
+ g_param_spec_enum ("selection-mode",
P_("Selection mode"),
P_("The selection mode"),
GTK_TYPE_SELECTION_MODE,
GTK_SELECTION_SINGLE,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
/**
* GtkIconView:pixbuf-column:
*/
g_object_class_install_property (gobject_class,
PROP_PIXBUF_COLUMN,
- g_param_spec_int ("pixbuf_column",
+ g_param_spec_int ("pixbuf-column",
P_("Pixbuf column"),
P_("Model column used to retrieve the icon pixbuf from"),
-1, G_MAXINT, -1,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
/**
* GtkIconView:text-column:
*/
g_object_class_install_property (gobject_class,
PROP_TEXT_COLUMN,
- g_param_spec_int ("text_column",
+ g_param_spec_int ("text-column",
P_("Text column"),
P_("Model column used to retrieve the text from"),
-1, G_MAXINT, -1,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
/**
*/
g_object_class_install_property (gobject_class,
PROP_MARKUP_COLUMN,
- g_param_spec_int ("markup_column",
+ g_param_spec_int ("markup-column",
P_("Markup column"),
P_("Model column used to retrieve the text if using Pango markup"),
-1, G_MAXINT, -1,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_MODEL,
P_("Icon View Model"),
P_("The model for the icon view"),
GTK_TYPE_TREE_MODEL,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkIconView:columns:
+ *
+ * The columns property contains the number of the columns in which the
+ * items should be displayed. If it is -1, the number of columns will
+ * be chosen automatically to fill the available area.
+ *
+ * Since: 2.6
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_COLUMNS,
+ g_param_spec_int ("columns",
+ P_("Number of columns"),
+ P_("Number of columns to display"),
+ -1, G_MAXINT, -1,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkIconView:item-width:
+ *
+ * The item-width property specifies the width to use for each item.
+ * If it is set to -1, the icon view will automatically determine a
+ * suitable item size.
+ *
+ * Since: 2.6
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_ITEM_WIDTH,
+ g_param_spec_int ("item-width",
+ P_("Width for each item"),
+ P_("The width used for each item"),
+ -1, G_MAXINT, -1,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkIconView:spacing:
+ *
+ * The spacing property specifies the space which is inserted between
+ * the cells (i.e. the icon and the text) of an item.
+ *
+ * Since: 2.6
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_SPACING,
+ g_param_spec_int ("spacing",
+ P_("Spacing"),
+ P_("Space which is inserted between cells of an item"),
+ 0, G_MAXINT, 0,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkIconView:row-spacing:
+ *
+ * The row-spacing property specifies the space which is inserted between
+ * the rows of the icon view.
+ *
+ * Since: 2.6
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_ROW_SPACING,
+ g_param_spec_int ("row-spacing",
+ P_("Row Spacing"),
+ P_("Space which is inserted between grid rows"),
+ 0, G_MAXINT, 6,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkIconView:column-spacing:
+ *
+ * The column-spacing property specifies the space which is inserted between
+ * the columns of the icon view.
+ *
+ * Since: 2.6
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_COLUMN_SPACING,
+ g_param_spec_int ("column-spacing",
+ P_("Column Spacing"),
+ P_("Space which is inserted between grid columns"),
+ 0, G_MAXINT, 6,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkIconView:margin:
+ *
+ * The margin property specifies the space which is inserted
+ * at the edges of the icon view.
+ *
+ * Since: 2.6
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_MARGIN,
+ g_param_spec_int ("margin",
+ P_("Margin"),
+ P_("Space which is inserted at the edges of the icon view"),
+ 0, G_MAXINT, 6,
+ GTK_PARAM_READWRITE));
+
+
+ /**
+ * GtkIconView:orientation:
+ *
+ * The orientation property specifies how the cells (i.e. the icon and
+ * the text) of the item are positioned relative to each other.
+ *
+ * Since: 2.6
+ */
g_object_class_install_property (gobject_class,
PROP_ORIENTATION,
g_param_spec_enum ("orientation",
P_("How the text and icon of each item are positioned relative to each other"),
GTK_TYPE_ORIENTATION,
GTK_ORIENTATION_VERTICAL,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkIconView:reorderable:
+ *
+ * The reorderable property specifies if the items can be reordered
+ * by DND.
+ *
+ * Since: 2.8
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_REORDERABLE,
+ g_param_spec_boolean ("reorderable",
+ P_("Reorderable"),
+ P_("View is reorderable"),
+ FALSE,
+ G_PARAM_READWRITE));
/* Style properties */
gtk_widget_class_install_style_property (widget_class,
- g_param_spec_boxed ("selection_box_color",
+ g_param_spec_boxed ("selection-box-color",
P_("Selection Box Color"),
P_("Color of the selection box"),
GDK_TYPE_COLOR,
- G_PARAM_READABLE));
+ GTK_PARAM_READABLE));
gtk_widget_class_install_style_property (widget_class,
- g_param_spec_uchar ("selection_box_alpha",
+ g_param_spec_uchar ("selection-box-alpha",
P_("Selection Box Alpha"),
P_("Opacity of the selection box"),
0, 0xff,
0x40,
- G_PARAM_READABLE));
+ GTK_PARAM_READABLE));
/* Signals */
widget_class->set_scroll_adjustments_signal =
- g_signal_new ("set_scroll_adjustments",
+ g_signal_new (I_("set_scroll_adjustments"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkIconViewClass, set_scroll_adjustments),
GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
icon_view_signals[ITEM_ACTIVATED] =
- g_signal_new ("item_activated",
+ g_signal_new (I_("item_activated"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkIconViewClass, item_activated),
GTK_TYPE_TREE_PATH);
icon_view_signals[SELECTION_CHANGED] =
- g_signal_new ("selection_changed",
+ g_signal_new (I_("selection-changed"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkIconViewClass, selection_changed),
G_TYPE_NONE, 0);
icon_view_signals[SELECT_ALL] =
- g_signal_new ("select_all",
+ g_signal_new (I_("select_all"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkIconViewClass, select_all),
G_TYPE_NONE, 0);
icon_view_signals[UNSELECT_ALL] =
- g_signal_new ("unselect_all",
+ g_signal_new (I_("unselect_all"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkIconViewClass, unselect_all),
G_TYPE_NONE, 0);
icon_view_signals[SELECT_CURSOR_ITEM] =
- g_signal_new ("select_cursor_item",
+ g_signal_new (I_("select_cursor_item"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkIconViewClass, select_cursor_item),
G_TYPE_NONE, 0);
icon_view_signals[TOGGLE_CURSOR_ITEM] =
- g_signal_new ("toggle_cursor_item",
+ g_signal_new (I_("toggle_cursor_item"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkIconViewClass, toggle_cursor_item),
G_TYPE_NONE, 0);
icon_view_signals[ACTIVATE_CURSOR_ITEM] =
- g_signal_new ("activate_cursor_item",
+ g_signal_new (I_("activate_cursor_item"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkIconViewClass, activate_cursor_item),
G_TYPE_BOOLEAN, 0);
icon_view_signals[MOVE_CURSOR] =
- g_signal_new ("move_cursor",
+ g_signal_new (I_("move_cursor"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkIconViewClass, move_cursor),
G_TYPE_INT);
/* Key bindings */
- gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK, "select_all", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect_all", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_space, 0, "select_cursor_item", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK, "toggle_cursor_item", 0);
-
- gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, "activate_cursor_item", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0, "activate_cursor_item", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, "activate_cursor_item", 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK,
+ "select_all", 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
+ "unselect_all", 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_space, GDK_CONTROL_MASK,
+ "toggle_cursor_item", 0);
+
+ gtk_binding_entry_add_signal (binding_set, GDK_space, 0,
+ "activate_cursor_item", 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_Return, 0,
+ "activate_cursor_item", 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_ISO_Enter, 0,
+ "activate_cursor_item", 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0,
+ "activate_cursor_item", 0);
gtk_icon_view_add_move_binding (binding_set, GDK_Up, 0,
GTK_MOVEMENT_DISPLAY_LINES, -1);
GTK_MOVEMENT_VISUAL_POSITIONS, -1);
}
+static void
+gtk_icon_view_cell_layout_init (GtkCellLayoutIface *iface)
+{
+ iface->pack_start = gtk_icon_view_cell_layout_pack_start;
+ iface->pack_end = gtk_icon_view_cell_layout_pack_end;
+ iface->clear = gtk_icon_view_cell_layout_clear;
+ iface->add_attribute = gtk_icon_view_cell_layout_add_attribute;
+ iface->set_cell_data_func = gtk_icon_view_cell_layout_set_cell_data_func;
+ iface->clear_attributes = gtk_icon_view_cell_layout_clear_attributes;
+ iface->reorder = gtk_icon_view_cell_layout_reorder;
+}
+
static void
gtk_icon_view_init (GtkIconView *icon_view)
{
icon_view->priv->width = 0;
icon_view->priv->height = 0;
icon_view->priv->selection_mode = GTK_SELECTION_SINGLE;
-#ifdef DND_WORKS
icon_view->priv->pressed_button = -1;
icon_view->priv->press_start_x = -1;
icon_view->priv->press_start_y = -1;
-#endif
icon_view->priv->text_column = -1;
icon_view->priv->markup_column = -1;
icon_view->priv->pixbuf_column = -1;
-
- icon_view->priv->layout = gtk_widget_create_pango_layout (GTK_WIDGET (icon_view), NULL);
-
- pango_layout_set_wrap (icon_view->priv->layout, PANGO_WRAP_WORD_CHAR);
+ icon_view->priv->text_cell = -1;
+ icon_view->priv->pixbuf_cell = -1;
GTK_WIDGET_SET_FLAGS (icon_view, GTK_CAN_FOCUS);
gtk_icon_view_set_adjustments (icon_view, NULL, NULL);
+ icon_view->priv->cell_list = NULL;
+ icon_view->priv->n_cells = 0;
+ icon_view->priv->cursor_cell = -1;
+
icon_view->priv->orientation = GTK_ORIENTATION_VERTICAL;
+
+ icon_view->priv->columns = -1;
+ icon_view->priv->item_width = -1;
+ icon_view->priv->spacing = 0;
+ icon_view->priv->row_spacing = 6;
+ icon_view->priv->column_spacing = 6;
+ icon_view->priv->margin = 6;
}
static void
icon_view = GTK_ICON_VIEW (object);
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+
gtk_icon_view_set_model (icon_view, NULL);
if (icon_view->priv->layout_idle_id != 0)
- g_source_remove (icon_view->priv->layout_idle_id);
+ {
+ g_source_remove (icon_view->priv->layout_idle_id);
+ icon_view->priv->layout_idle_id = 0;
+ }
- if (icon_view->priv->scroll_timeout_id != 0)
- g_source_remove (icon_view->priv->scroll_timeout_id);
+ if (icon_view->priv->scroll_to_path != NULL)
+ {
+ gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
+ icon_view->priv->scroll_to_path = NULL;
+ }
+
+ remove_scroll_timeout (icon_view);
+
+ if (icon_view->priv->hadjustment != NULL)
+ {
+ g_object_unref (icon_view->priv->hadjustment);
+ icon_view->priv->hadjustment = NULL;
+ }
+
+ if (icon_view->priv->vadjustment != NULL)
+ {
+ g_object_unref (icon_view->priv->vadjustment);
+ icon_view->priv->vadjustment = NULL;
+ }
- (GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+ (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
}
/* GObject methods */
static void
gtk_icon_view_finalize (GObject *object)
{
- GtkIconView *icon_view;
-
- icon_view = GTK_ICON_VIEW (object);
+ gtk_icon_view_cell_layout_clear (GTK_CELL_LAYOUT (object));
- g_object_unref (icon_view->priv->layout);
-
- (G_OBJECT_CLASS (parent_class)->finalize) (object);
+ (* G_OBJECT_CLASS (gtk_icon_view_parent_class)->finalize) (object);
}
case PROP_ORIENTATION:
gtk_icon_view_set_orientation (icon_view, g_value_get_enum (value));
break;
+ case PROP_COLUMNS:
+ gtk_icon_view_set_columns (icon_view, g_value_get_int (value));
+ break;
+ case PROP_ITEM_WIDTH:
+ gtk_icon_view_set_item_width (icon_view, g_value_get_int (value));
+ break;
+ case PROP_SPACING:
+ gtk_icon_view_set_spacing (icon_view, g_value_get_int (value));
+ break;
+ case PROP_ROW_SPACING:
+ gtk_icon_view_set_row_spacing (icon_view, g_value_get_int (value));
+ break;
+ case PROP_COLUMN_SPACING:
+ gtk_icon_view_set_column_spacing (icon_view, g_value_get_int (value));
+ break;
+ case PROP_MARGIN:
+ gtk_icon_view_set_margin (icon_view, g_value_get_int (value));
+ break;
+ case PROP_REORDERABLE:
+ gtk_icon_view_set_reorderable (icon_view, g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
case PROP_ORIENTATION:
g_value_set_enum (value, icon_view->priv->orientation);
break;
+ case PROP_COLUMNS:
+ g_value_set_int (value, icon_view->priv->columns);
+ break;
+ case PROP_ITEM_WIDTH:
+ g_value_set_int (value, icon_view->priv->item_width);
+ break;
+ case PROP_SPACING:
+ g_value_set_int (value, icon_view->priv->spacing);
+ break;
+ case PROP_ROW_SPACING:
+ g_value_set_int (value, icon_view->priv->row_spacing);
+ break;
+ case PROP_COLUMN_SPACING:
+ g_value_set_int (value, icon_view->priv->column_spacing);
+ break;
+ case PROP_MARGIN:
+ g_value_set_int (value, icon_view->priv->margin);
+ break;
+ case PROP_REORDERABLE:
+ g_value_set_boolean (value, icon_view->priv->reorderable);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes, attributes_mask);
+ gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
gdk_window_set_user_data (widget->window, widget);
/* Make the window for the icon view */
gtk_widget_get_events (widget);
icon_view->priv->bin_window = gdk_window_new (widget->window,
- &attributes, attributes_mask);
+ &attributes, attributes_mask);
gdk_window_set_user_data (icon_view->priv->bin_window, widget);
widget->style = gtk_style_attach (widget->style, widget->window);
gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
- gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
+
+ gdk_window_show (icon_view->priv->bin_window);
}
static void
icon_view->priv->bin_window = NULL;
/* GtkWidget::unrealize destroys children and widget->window */
- if (GTK_WIDGET_CLASS (parent_class)->unrealize)
- (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+ if (GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize)
+ (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize) (widget);
+}
+
+static void
+gtk_icon_view_state_changed (GtkWidget *widget,
+ GtkStateType previous_state)
+{
+ GtkIconView *icon_view = GTK_ICON_VIEW (widget);
+
+ if (GTK_WIDGET_REALIZED (widget))
+ {
+ gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
+ gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
+ }
+
+ gtk_widget_queue_draw (widget);
}
static void
-gtk_icon_view_map (GtkWidget *widget)
+gtk_icon_view_style_set (GtkWidget *widget,
+ GtkStyle *previous_style)
{
GtkIconView *icon_view;
+ g_return_if_fail (GTK_IS_ICON_VIEW (widget));
+
icon_view = GTK_ICON_VIEW (widget);
- GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
+ if (GTK_WIDGET_REALIZED (widget))
+ {
+ gdk_window_set_background (widget->window, &widget->style->base[widget->state]);
+ gdk_window_set_background (icon_view->priv->bin_window, &widget->style->base[widget->state]);
+ }
- gdk_window_show (icon_view->priv->bin_window);
- gdk_window_show (widget->window);
+ gtk_widget_queue_resize (widget);
}
static void
GtkRequisition *requisition)
{
GtkIconView *icon_view;
+ GList *tmp_list;
icon_view = GTK_ICON_VIEW (widget);
requisition->width = icon_view->priv->width;
requisition->height = icon_view->priv->height;
+
+ tmp_list = icon_view->priv->children;
+
+ while (tmp_list)
+ {
+ GtkIconViewChild *child = tmp_list->data;
+ GtkRequisition child_requisition;
+
+ tmp_list = tmp_list->next;
+
+ if (GTK_WIDGET_VISIBLE (child->widget))
+ gtk_widget_size_request (child->widget, &child_requisition);
+ }
+}
+
+static void
+gtk_icon_view_allocate_children (GtkIconView *icon_view)
+{
+ GList *list;
+
+ for (list = icon_view->priv->children; list; list = list->next)
+ {
+ GtkIconViewChild *child = list->data;
+ GtkAllocation allocation;
+
+ /* totally ignore our child's requisition */
+ if (child->cell < 0)
+ {
+ allocation.x = child->item->x;
+ allocation.y = child->item->y;
+ allocation.width = child->item->width;
+ allocation.height = child->item->height;
+ }
+ else
+ {
+ GdkRectangle *box = &child->item->box[child->cell];
+
+ allocation.x = box->x;
+ allocation.y = box->y;
+ allocation.width = box->width;
+ allocation.height = box->height;
+ }
+
+ gtk_widget_size_allocate (child->widget, &allocation);
+ }
}
static void
gtk_icon_view_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
- GtkIconView *icon_view;
+ GtkIconView *icon_view = GTK_ICON_VIEW (widget);
+
+ GtkAdjustment *hadjustment, *vadjustment;
widget->allocation = *allocation;
- icon_view = GTK_ICON_VIEW (widget);
-
if (GTK_WIDGET_REALIZED (widget))
{
gdk_window_move_resize (widget->window,
MAX (icon_view->priv->height, allocation->height));
}
- icon_view->priv->hadjustment->page_size = allocation->width;
- icon_view->priv->hadjustment->page_increment = allocation->width * 0.9;
- icon_view->priv->hadjustment->step_increment = allocation->width * 0.1;
- icon_view->priv->hadjustment->lower = 0;
- icon_view->priv->hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
- gtk_adjustment_changed (icon_view->priv->hadjustment);
+ gtk_icon_view_layout (icon_view);
+
+ gtk_icon_view_allocate_children (icon_view);
- icon_view->priv->vadjustment->page_size = allocation->height;
- icon_view->priv->vadjustment->page_increment = allocation->height * 0.9;
- icon_view->priv->vadjustment->step_increment = allocation->width * 0.1;
- icon_view->priv->vadjustment->lower = 0;
- icon_view->priv->vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
- gtk_adjustment_changed (icon_view->priv->vadjustment);
+ hadjustment = icon_view->priv->hadjustment;
+ vadjustment = icon_view->priv->vadjustment;
- gtk_icon_view_layout (icon_view);
+ hadjustment->page_size = allocation->width;
+ hadjustment->page_increment = allocation->width * 0.9;
+ hadjustment->step_increment = allocation->width * 0.1;
+ hadjustment->lower = 0;
+ hadjustment->upper = MAX (allocation->width, icon_view->priv->width);
+
+ if (hadjustment->value > hadjustment->upper - hadjustment->page_size)
+ gtk_adjustment_set_value (hadjustment, MAX (0, hadjustment->upper - hadjustment->page_size));
+
+ vadjustment->page_size = allocation->height;
+ vadjustment->page_increment = allocation->height * 0.9;
+ vadjustment->step_increment = allocation->height * 0.1;
+ vadjustment->lower = 0;
+ vadjustment->upper = MAX (allocation->height, icon_view->priv->height);
+
+ if (vadjustment->value > vadjustment->upper - vadjustment->page_size)
+ gtk_adjustment_set_value (vadjustment, MAX (0, vadjustment->upper - vadjustment->page_size));
+
+ if (GTK_WIDGET_REALIZED (widget) &&
+ icon_view->priv->scroll_to_path)
+ {
+ GtkTreePath *path;
+ path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
+ gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
+ icon_view->priv->scroll_to_path = NULL;
+
+ gtk_icon_view_scroll_to_path (icon_view, path,
+ icon_view->priv->scroll_to_use_align,
+ icon_view->priv->scroll_to_row_align,
+ icon_view->priv->scroll_to_col_align);
+ gtk_tree_path_free (path);
+ }
+ else
+ {
+ gtk_adjustment_changed (hadjustment);
+ gtk_adjustment_changed (vadjustment);
+ }
}
static gboolean
{
GtkIconView *icon_view;
GList *icons;
+ cairo_t *cr;
+ GtkTreePath *path;
+ gint dest_index;
+ GtkIconViewDropPosition dest_pos;
+ GtkIconViewItem *dest_item = NULL;
icon_view = GTK_ICON_VIEW (widget);
if (expose->window != icon_view->priv->bin_window)
return FALSE;
- for (icons = icon_view->priv->items; icons; icons = icons->next) {
- GtkIconViewItem *item = icons->data;
- GdkRectangle item_rectangle;
+ cr = gdk_cairo_create (icon_view->priv->bin_window);
+ cairo_set_line_width (cr, 1.);
- item_rectangle.x = item->x;
- item_rectangle.y = item->y;
- item_rectangle.width = item->width;
- item_rectangle.height = item->height;
+ gtk_icon_view_get_drag_dest_item (icon_view, &path, &dest_pos);
- if (gdk_region_rect_in (expose->region, &item_rectangle) == GDK_OVERLAP_RECTANGLE_OUT)
- continue;
+ if (path)
+ {
+ dest_index = gtk_tree_path_get_indices (path)[0];
+ gtk_tree_path_free (path);
+ }
+ else
+ dest_index = -1;
- gtk_icon_view_paint_item (icon_view, item, &expose->area);
- }
+ for (icons = icon_view->priv->items; icons; icons = icons->next)
+ {
+ GtkIconViewItem *item = icons->data;
+ GdkRectangle area;
+
+ area.x = item->x;
+ area.y = item->y;
+ area.width = item->width;
+ area.height = item->height;
+
+ if (gdk_region_rect_in (expose->region, &area) == GDK_OVERLAP_RECTANGLE_OUT)
+ continue;
+
+ gtk_icon_view_paint_item (icon_view, cr, item, &expose->area,
+ icon_view->priv->bin_window,
+ item->x, item->y, TRUE);
+
+ if (dest_index == item->index)
+ dest_item = item;
+ }
+ if (dest_item)
+ {
+ switch (dest_pos)
+ {
+ case GTK_ICON_VIEW_DROP_INTO:
+ gtk_paint_focus (widget->style,
+ icon_view->priv->bin_window,
+ GTK_WIDGET_STATE (widget),
+ NULL,
+ widget,
+ "iconview-drop-indicator",
+ dest_item->x, dest_item->y,
+ dest_item->width, dest_item->height);
+ break;
+ case GTK_ICON_VIEW_DROP_ABOVE:
+ gtk_paint_focus (widget->style,
+ icon_view->priv->bin_window,
+ GTK_WIDGET_STATE (widget),
+ NULL,
+ widget,
+ "iconview-drop-indicator",
+ dest_item->x, dest_item->y - 1,
+ dest_item->width, 2);
+ break;
+ case GTK_ICON_VIEW_DROP_LEFT:
+ gtk_paint_focus (widget->style,
+ icon_view->priv->bin_window,
+ GTK_WIDGET_STATE (widget),
+ NULL,
+ widget,
+ "iconview-drop-indicator",
+ dest_item->x - 1, dest_item->y,
+ 2, dest_item->height);
+ break;
+ case GTK_ICON_VIEW_DROP_BELOW:
+ gtk_paint_focus (widget->style,
+ icon_view->priv->bin_window,
+ GTK_WIDGET_STATE (widget),
+ NULL,
+ widget,
+ "iconview-drop-indicator",
+ dest_item->x, dest_item->y + dest_item->height - 1,
+ dest_item->width, 2);
+ break;
+ case GTK_ICON_VIEW_DROP_RIGHT:
+ gtk_paint_focus (widget->style,
+ icon_view->priv->bin_window,
+ GTK_WIDGET_STATE (widget),
+ NULL,
+ widget,
+ "iconview-drop-indicator",
+ dest_item->x + dest_item->width - 1, dest_item->y,
+ 2, dest_item->height);
+ case GTK_ICON_VIEW_NO_DROP: ;
+ break;
+ }
+ }
+
if (icon_view->priv->doing_rubberband)
{
GdkRectangle *rectangles;
&n_rectangles);
while (n_rectangles--)
- gtk_icon_view_paint_rubberband (icon_view, &rectangles[n_rectangles]);
+ gtk_icon_view_paint_rubberband (icon_view, cr, &rectangles[n_rectangles]);
g_free (rectangles);
}
+ cairo_destroy (cr);
+
+ (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->expose_event) (widget, expose);
+
return TRUE;
}
static gboolean
-scroll_timeout (gpointer data)
+rubberband_scroll_timeout (gpointer data)
{
GtkIconView *icon_view;
gdouble value;
- GDK_THREADS_ENTER ();
-
icon_view = data;
value = MIN (icon_view->priv->vadjustment->value +
icon_view->priv->vadjustment->upper -
icon_view->priv->vadjustment->page_size);
- gtk_adjustment_set_value (icon_view->priv->vadjustment,
- value);
+ gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
gtk_icon_view_update_rubberband (icon_view);
- GDK_THREADS_LEAVE ();
-
return TRUE;
}
gint abs_y;
icon_view = GTK_ICON_VIEW (widget);
-#ifdef DND_WORKS
- gtk_icon_view_maybe_begin_dragging_items (icon_view, event);
-#endif
+
+ gtk_icon_view_maybe_begin_drag (icon_view, event);
+
if (icon_view->priv->doing_rubberband)
{
gtk_icon_view_update_rubberband (widget);
if (abs_y < 0 || abs_y > widget->allocation.height)
{
- if (icon_view->priv->scroll_timeout_id == 0)
- icon_view->priv->scroll_timeout_id = g_timeout_add (30, scroll_timeout, icon_view);
-
if (abs_y < 0)
icon_view->priv->scroll_value_diff = abs_y;
else
icon_view->priv->event_last_x = event->x;
icon_view->priv->event_last_y = event->y;
- }
- else if (icon_view->priv->scroll_timeout_id != 0)
- {
- g_source_remove (icon_view->priv->scroll_timeout_id);
- icon_view->priv->scroll_timeout_id = 0;
- }
+ if (icon_view->priv->scroll_timeout_id == 0)
+ icon_view->priv->scroll_timeout_id = gdk_threads_add_timeout (30, rubberband_scroll_timeout,
+ icon_view);
+ }
+ else
+ remove_scroll_timeout (icon_view);
}
return TRUE;
}
-static gboolean
-gtk_icon_view_button_press (GtkWidget *widget,
- GdkEventButton *event)
+static void
+gtk_icon_view_remove (GtkContainer *container,
+ GtkWidget *widget)
{
GtkIconView *icon_view;
- GtkIconViewItem *item;
+ GtkIconViewChild *child = NULL;
+ GList *tmp_list;
+
+ icon_view = GTK_ICON_VIEW (container);
+
+ tmp_list = icon_view->priv->children;
+ while (tmp_list)
+ {
+ child = tmp_list->data;
+ if (child->widget == widget)
+ {
+ gtk_widget_unparent (widget);
+
+ icon_view->priv->children = g_list_remove_link (icon_view->priv->children, tmp_list);
+ g_list_free_1 (tmp_list);
+ g_free (child);
+ return;
+ }
+
+ tmp_list = tmp_list->next;
+ }
+}
+
+static void
+gtk_icon_view_forall (GtkContainer *container,
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data)
+{
+ GtkIconView *icon_view;
+ GtkIconViewChild *child = NULL;
+ GList *tmp_list;
+
+ icon_view = GTK_ICON_VIEW (container);
+
+ tmp_list = icon_view->priv->children;
+ while (tmp_list)
+ {
+ child = tmp_list->data;
+ tmp_list = tmp_list->next;
+
+ (* callback) (child->widget, callback_data);
+ }
+}
+
+static void
+gtk_icon_view_item_activate_cell (GtkIconView *icon_view,
+ GtkIconViewItem *item,
+ GtkIconViewCellInfo *info,
+ GdkEvent *event)
+{
+ GtkTreePath *path;
+ gchar *path_string;
+ GdkRectangle cell_area;
+ gboolean visible, mode;
+
+ gtk_icon_view_set_cell_data (icon_view, item);
+
+ g_object_get (info->cell,
+ "visible", &visible,
+ "mode", &mode,
+ NULL);
+
+ if (visible && mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
+ {
+ gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
+
+ path = gtk_tree_path_new_from_indices (item->index, -1);
+ path_string = gtk_tree_path_to_string (path);
+ gtk_tree_path_free (path);
+
+ gtk_cell_renderer_activate (info->cell,
+ event,
+ GTK_WIDGET (icon_view),
+ path_string,
+ &cell_area,
+ &cell_area,
+ 0);
+
+ g_free (path_string);
+ }
+}
+
+static void
+gtk_icon_view_put (GtkIconView *icon_view,
+ GtkWidget *widget,
+ GtkIconViewItem *item,
+ gint cell)
+{
+ GtkIconViewChild *child;
+
+ child = g_new (GtkIconViewChild, 1);
+
+ child->widget = widget;
+ child->item = item;
+ child->cell = cell;
+
+ icon_view->priv->children = g_list_append (icon_view->priv->children, child);
+
+ if (GTK_WIDGET_REALIZED (icon_view))
+ gtk_widget_set_parent_window (child->widget, icon_view->priv->bin_window);
+
+ gtk_widget_set_parent (widget, GTK_WIDGET (icon_view));
+}
+
+static void
+gtk_icon_view_remove_widget (GtkCellEditable *editable,
+ GtkIconView *icon_view)
+{
+ GList *l;
+ GtkIconViewItem *item;
+
+ if (icon_view->priv->edited_item == NULL)
+ return;
+
+ item = icon_view->priv->edited_item;
+ icon_view->priv->edited_item = NULL;
+ icon_view->priv->editable = NULL;
+ for (l = icon_view->priv->cell_list; l; l = l->next)
+ {
+ GtkIconViewCellInfo *info = l->data;
+
+ info->editing = FALSE;
+ }
+
+ if (GTK_WIDGET_HAS_FOCUS (editable))
+ gtk_widget_grab_focus (GTK_WIDGET (icon_view));
+
+ g_signal_handlers_disconnect_by_func (editable,
+ gtk_icon_view_remove_widget,
+ icon_view);
+
+ gtk_container_remove (GTK_CONTAINER (icon_view),
+ GTK_WIDGET (editable));
+
+ gtk_icon_view_queue_draw_item (icon_view, item);
+}
+
+
+static void
+gtk_icon_view_start_editing (GtkIconView *icon_view,
+ GtkIconViewItem *item,
+ GtkIconViewCellInfo *info,
+ GdkEvent *event)
+{
+ GtkTreePath *path;
+ gchar *path_string;
+ GdkRectangle cell_area;
+ gboolean visible, mode;
+ GtkCellEditable *editable;
+
+ gtk_icon_view_set_cell_data (icon_view, item);
+
+ g_object_get (info->cell,
+ "visible", &visible,
+ "mode", &mode,
+ NULL);
+ if (visible && mode == GTK_CELL_RENDERER_MODE_EDITABLE)
+ {
+ gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
+
+ path = gtk_tree_path_new_from_indices (item->index, -1);
+ path_string = gtk_tree_path_to_string (path);
+ gtk_tree_path_free (path);
+
+ editable = gtk_cell_renderer_start_editing (info->cell,
+ event,
+ GTK_WIDGET (icon_view),
+ path_string,
+ &cell_area,
+ &cell_area,
+ 0);
+ g_free (path_string);
+
+ /* FIXME ugly special case */
+ if (GTK_IS_ENTRY (editable) || GTK_IS_COMBO_BOX (editable))
+ g_object_set (editable, "has-frame", TRUE, NULL);
+
+ /* the rest corresponds to tree_view_real_start_editing... */
+ icon_view->priv->edited_item = item;
+ icon_view->priv->editable = editable;
+ info->editing = TRUE;
+
+ gtk_icon_view_put (icon_view, GTK_WIDGET (editable), item,
+ info->position);
+ gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (editable),
+ (GdkEvent *)event);
+ gtk_widget_grab_focus (GTK_WIDGET (editable));
+ g_signal_connect (editable, "remove_widget",
+ G_CALLBACK (gtk_icon_view_remove_widget),
+ icon_view);
+
+ }
+}
+
+static void
+gtk_icon_view_stop_editing (GtkIconView *icon_view,
+ gboolean cancel_editing)
+{
+ GtkCellRenderer *cell = NULL;
+ GtkIconViewItem *item;
+ GList *l;
+
+ if (icon_view->priv->edited_item == NULL)
+ return;
+
+ /*
+ * This is very evil. We need to do this, because
+ * gtk_cell_editable_editing_done may trigger gtk_icon_view_row_changed
+ * later on. If gtk_icon_view_row_changed notices
+ * icon_view->priv->edited_item != NULL, it'll call
+ * gtk_icon_view_stop_editing again. Bad things will happen then.
+ *
+ * Please read that again if you intend to modify anything here.
+ */
+
+ item = icon_view->priv->edited_item;
+ icon_view->priv->edited_item = NULL;
+
+ for (l = icon_view->priv->cell_list; l; l = l->next)
+ {
+ GtkIconViewCellInfo *info = l->data;
+
+ if (info->editing)
+ {
+ cell = info->cell;
+ break;
+ }
+ }
+
+ if (cell == NULL)
+ return;
+
+ gtk_cell_renderer_stop_editing (cell, cancel_editing);
+ if (!cancel_editing)
+ gtk_cell_editable_editing_done (icon_view->priv->editable);
+
+ icon_view->priv->edited_item = item;
+
+ gtk_cell_editable_remove_widget (icon_view->priv->editable);
+}
+
+/**
+ * gtk_icon_view_set_cursor:
+ * @icon_view: A #GtkIconView
+ * @path: A #GtkTreePath
+ * @cell: One of the cell renderers of @icon_view, or %NULL
+ * @start_editing: %TRUE if the specified cell should start being edited.
+ *
+ * Sets the current keyboard focus to be at @path, and selects it. This is
+ * useful when you want to focus the user's attention on a particular item.
+ * If @cell is not %NULL, then focus is given to the cell specified by
+ * it. Additionally, if @start_editing is %TRUE, then editing should be
+ * started in the specified cell.
+ *
+ * This function is often followed by <literal>gtk_widget_grab_focus
+ * (icon_view)</literal> in order to give keyboard focus to the widget.
+ * Please note that editing can only happen when the widget is realized.
+ *
+ * Since: 2.8
+ **/
+void
+gtk_icon_view_set_cursor (GtkIconView *icon_view,
+ GtkTreePath *path,
+ GtkCellRenderer *cell,
+ gboolean start_editing)
+{
+ GtkIconViewItem *item = NULL;
+ GtkIconViewCellInfo *info = NULL;
+ GList *l;
+ gint i, cell_pos;
+
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+ g_return_if_fail (path != NULL);
+ g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
+
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+
+ if (gtk_tree_path_get_depth (path) == 1)
+ item = g_list_nth_data (icon_view->priv->items,
+ gtk_tree_path_get_indices(path)[0]);
+
+ if (!item)
+ return;
+
+ cell_pos = -1;
+ for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
+ {
+ info = l->data;
+
+ if (info->cell == cell)
+ {
+ cell_pos = i;
+ break;
+ }
+
+ info = NULL;
+ }
+
+ g_return_if_fail (cell == NULL || info != NULL);
+
+ gtk_icon_view_set_cursor_item (icon_view, item, cell_pos);
+ gtk_icon_view_scroll_to_path (icon_view, path, FALSE, 0.0, 0.0);
+
+ if (info && start_editing)
+ gtk_icon_view_start_editing (icon_view, item, info, NULL);
+}
+
+/**
+ * gtk_icon_view_get_cursor:
+ * @icon_view: A #GtkIconView
+ * @path: Return location for the current cursor path, or %NULL
+ * @cell: Return location the current focus cell, or %NULL
+ *
+ * Fills in @path and @cell with the current cursor path and cell.
+ * If the cursor isn't currently set, then *@path will be %NULL.
+ * If no cell currently has focus, then *@cell will be %NULL.
+ *
+ * The returned #GtkTreePath must be freed with gtk_tree_path_free().
+ *
+ * Return value: %TRUE if the cursor is set.
+ *
+ * Since: 2.8
+ **/
+gboolean
+gtk_icon_view_get_cursor (GtkIconView *icon_view,
+ GtkTreePath **path,
+ GtkCellRenderer **cell)
+{
+ GtkIconViewItem *item;
+ GtkIconViewCellInfo *info;
+
+ g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
+
+ item = icon_view->priv->cursor_item;
+ if (icon_view->priv->cursor_cell < 0)
+ info = NULL;
+ else
+ info = g_list_nth_data (icon_view->priv->cell_list,
+ icon_view->priv->cursor_cell);
+
+ if (path != NULL)
+ {
+ if (item != NULL)
+ *path = gtk_tree_path_new_from_indices (item->index, -1);
+ else
+ *path = NULL;
+ }
+
+ if (cell != NULL)
+ {
+ if (info != NULL)
+ *cell = info->cell;
+ else
+ *cell = NULL;
+ }
+
+ return (item != NULL);
+}
+
+static gboolean
+gtk_icon_view_button_press (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ GtkIconView *icon_view;
+ GtkIconViewItem *item;
+ GtkIconViewCellInfo *info = NULL;
gboolean dirty = FALSE;
+ GtkCellRendererMode mode;
+ gint cursor_cell;
icon_view = GTK_ICON_VIEW (widget);
if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
{
-
- item = gtk_icon_view_get_item_at_pos (icon_view,
- event->x, event->y);
-
+ item = gtk_icon_view_get_item_at_coords (icon_view,
+ event->x, event->y,
+ TRUE,
+ &info);
if (item != NULL)
{
+ g_object_get (info->cell, "mode", &mode, NULL);
+
+ if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE ||
+ mode == GTK_CELL_RENDERER_MODE_EDITABLE)
+ cursor_cell = g_list_index (icon_view->priv->cell_list, info);
+ else
+ cursor_cell = -1;
+
gtk_icon_view_scroll_to_item (icon_view, item);
if (icon_view->priv->selection_mode == GTK_SELECTION_NONE)
{
- gtk_icon_view_set_cursor_item (icon_view, item);
+ gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
}
else if (icon_view->priv->selection_mode == GTK_SELECTION_MULTIPLE &&
(event->state & GDK_SHIFT_MASK))
{
gtk_icon_view_unselect_all_internal (icon_view);
- gtk_icon_view_set_cursor_item (icon_view, item);
+ gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
if (!icon_view->priv->anchor_item)
icon_view->priv->anchor_item = item;
else
dirty = TRUE;
}
}
- gtk_icon_view_set_cursor_item (icon_view, item);
+ gtk_icon_view_set_cursor_item (icon_view, item, cursor_cell);
icon_view->priv->anchor_item = item;
}
-#ifdef DND_WORKS
+
/* Save press to possibly begin a drag */
if (icon_view->priv->pressed_button < 0)
{
icon_view->priv->press_start_x = event->x;
icon_view->priv->press_start_y = event->y;
}
-#endif
+
if (!icon_view->priv->last_single_clicked)
icon_view->priv->last_single_clicked = item;
+
+ /* cancel the current editing, if it exists */
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+
+ if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
+ gtk_icon_view_item_activate_cell (icon_view, item, info,
+ (GdkEvent *)event);
+ else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
+ gtk_icon_view_start_editing (icon_view, item, info,
+ (GdkEvent *)event);
}
else
{
if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
{
- item = gtk_icon_view_get_item_at_pos (icon_view,
- event->x, event->y);
+ item = gtk_icon_view_get_item_at_coords (icon_view,
+ event->x, event->y,
+ TRUE,
+ NULL);
if (item && item == icon_view->priv->last_single_clicked)
{
}
icon_view->priv->last_single_clicked = NULL;
+ icon_view->priv->pressed_button = -1;
}
if (dirty)
icon_view = GTK_ICON_VIEW (widget);
-#ifdef DND_WORKS
if (icon_view->priv->pressed_button == event->button)
icon_view->priv->pressed_button = -1;
-#endif
+
gtk_icon_view_stop_rubberbanding (icon_view);
- if (icon_view->priv->scroll_timeout_id != 0)
- {
- g_source_remove (icon_view->priv->scroll_timeout_id);
- icon_view->priv->scroll_timeout_id = 0;
- }
+ remove_scroll_timeout (icon_view);
return TRUE;
}
gboolean is_in;
gboolean selected;
- is_in = gtk_icon_view_item_hit_test (item, x, y, width, height);
+ is_in = gtk_icon_view_item_hit_test (icon_view, item,
+ x, y, width, height);
selected = is_in ^ item->selected_before_rubberbanding;
}
static gboolean
-gtk_icon_view_item_hit_test (GtkIconViewItem *item,
+gtk_icon_view_item_hit_test (GtkIconView *icon_view,
+ GtkIconViewItem *item,
gint x,
gint y,
gint width,
gint height)
{
- /* First try the pixbuf */
- if (MIN (x + width, item->pixbuf_x + item->pixbuf_width) - MAX (x, item->pixbuf_x) > 0 &&
- MIN (y + height, item->pixbuf_y + item->pixbuf_height) - MAX (y, item->pixbuf_y) > 0)
- return TRUE;
-
- /* Then try the text */
- if (MIN (x + width, item->layout_x + item->layout_width) - MAX (x, item->layout_x) > 0 &&
- MIN (y + height, item->layout_y + item->layout_height) - MAX (y, item->layout_y) > 0)
- return TRUE;
-
- return FALSE;
-}
-
-#ifdef DND_WORKS
-static gboolean
-gtk_icon_view_maybe_begin_dragging_items (GtkIconView *icon_view,
- GdkEventMotion *event)
-{
- gboolean retval = FALSE;
- gint button;
- if (icon_view->priv->pressed_button < 0)
- return retval;
+ GList *l;
+ GdkRectangle box;
+
+ for (l = icon_view->priv->cell_list; l; l = l->next)
+ {
+ GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
+
+ if (!info->cell->visible)
+ continue;
+
+ gtk_icon_view_get_cell_box (icon_view, item, info, &box);
- if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
- icon_view->priv->press_start_x,
- icon_view->priv->press_start_y,
- event->x, event->y))
- return retval;
+ if (MIN (x + width, box.x + box.width) - MAX (x, box.x) > 0 &&
+ MIN (y + height, box.y + box.height) - MAX (y, box.y) > 0)
+ return TRUE;
+ }
- button = icon_view->priv->pressed_button;
- icon_view->priv->pressed_button = -1;
-
- {
- static GtkTargetEntry row_targets[] = {
- { "GTK_ICON_VIEW_ITEMS", GTK_TARGET_SAME_APP, 0 }
- };
- GtkTargetList *target_list;
- GdkDragContext *context;
- GtkIconViewItem *item;
-
- retval = TRUE;
-
- target_list = gtk_target_list_new (row_targets, G_N_ELEMENTS (row_targets));
-
- context = gtk_drag_begin (GTK_WIDGET (icon_view),
- target_list, GDK_ACTION_MOVE,
- button,
- (GdkEvent *)event);
-
- item = gtk_icon_view_get_item_at_pos (icon_view,
- icon_view->priv->press_start_x,
- icon_view->priv->press_start_y);
- g_assert (item != NULL);
- gtk_drag_set_icon_pixbuf (context, gtk_icon_view_get_item_icon (icon_view, item),
- event->x - item->x,
- event->y - item->y);
- }
-
- return retval;
+ return FALSE;
}
-#endif
static gboolean
gtk_icon_view_unselect_all_internal (GtkIconView *icon_view)
if (icon_view->priv->hadjustment != hadj)
{
icon_view->priv->hadjustment = hadj;
- g_object_ref (icon_view->priv->hadjustment);
- gtk_object_sink (GTK_OBJECT (icon_view->priv->hadjustment));
+ g_object_ref_sink (icon_view->priv->hadjustment);
g_signal_connect (icon_view->priv->hadjustment, "value_changed",
G_CALLBACK (gtk_icon_view_adjustment_changed),
if (icon_view->priv->vadjustment != vadj)
{
icon_view->priv->vadjustment = vadj;
- g_object_ref (icon_view->priv->vadjustment);
- gtk_object_sink (GTK_OBJECT (icon_view->priv->vadjustment));
+ g_object_ref_sink (icon_view->priv->vadjustment);
g_signal_connect (icon_view->priv->vadjustment, "value_changed",
G_CALLBACK (gtk_icon_view_adjustment_changed),
gtk_icon_view_real_activate_cursor_item (GtkIconView *icon_view)
{
GtkTreePath *path;
+ GtkCellRendererMode mode;
+ GtkIconViewCellInfo *info = NULL;
if (!icon_view->priv->cursor_item)
return FALSE;
- path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
+ info = g_list_nth_data (icon_view->priv->cell_list,
+ icon_view->priv->cursor_cell);
+
+ if (info)
+ {
+ g_object_get (info->cell, "mode", &mode, NULL);
+
+ if (mode == GTK_CELL_RENDERER_MODE_ACTIVATABLE)
+ {
+ gtk_icon_view_item_activate_cell (icon_view,
+ icon_view->priv->cursor_item,
+ info, NULL);
+ return TRUE;
+ }
+ else if (mode == GTK_CELL_RENDERER_MODE_EDITABLE)
+ {
+ gtk_icon_view_start_editing (icon_view,
+ icon_view->priv->cursor_item,
+ info, NULL);
+ return TRUE;
+ }
+ }
+ path = gtk_tree_path_new_from_indices (icon_view->priv->cursor_item->index, -1);
gtk_icon_view_item_activated (icon_view, path);
-
gtk_tree_path_free (path);
return TRUE;
}
static GList *
-gtk_icon_view_layout_single_row (GtkIconView *icon_view, GList *first_item, gint *y, gint *maximum_width, gint row)
-{
- gint focus_width, focus_pad;
- gint x, current_width, max_height, max_pixbuf_height;
+gtk_icon_view_layout_single_row (GtkIconView *icon_view,
+ GList *first_item,
+ gint item_width,
+ gint row,
+ gint *y,
+ gint *maximum_width)
+{
+ gint focus_width;
+ gint x, current_width;
GList *items, *last_item;
- gint maximum_layout_width;
gint col;
- gboolean rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
+ gint colspan;
+ gint *max_height;
+ gint i;
+ gboolean rtl;
+
+ rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
+ max_height = g_new0 (gint, icon_view->priv->n_cells);
x = 0;
col = 0;
- max_height = 0;
- max_pixbuf_height = 0;
items = first_item;
current_width = 0;
gtk_widget_style_get (GTK_WIDGET (icon_view),
"focus-line-width", &focus_width,
- "focus-padding", &focus_pad,
NULL);
- x += ICON_VIEW_LEFT_MARGIN;
- current_width += ICON_VIEW_LEFT_MARGIN + ICON_VIEW_RIGHT_MARGIN;
- items = first_item;
+ x += icon_view->priv->margin + focus_width;
+ current_width += 2 * (icon_view->priv->margin + focus_width);
+ items = first_item;
while (items)
{
GtkIconViewItem *item = items->data;
gtk_icon_view_calculate_item_size (icon_view, item);
+ colspan = 1 + (item->width - 1) / (item_width + icon_view->priv->column_spacing);
- current_width += MAX (item->width, MINIMUM_ICON_ITEM_WIDTH);
-
- /* Don't add padding to the first or last icon */
-
- if (current_width > GTK_WIDGET (icon_view)->allocation.width &&
- items != first_item)
- break;
-
- maximum_layout_width = MAX (item->pixbuf_width, MINIMUM_ICON_ITEM_WIDTH);
+ item->width = colspan * item_width + (colspan - 1) * icon_view->priv->column_spacing;
- item->y = *y;
- item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
- if (item->width < MINIMUM_ICON_ITEM_WIDTH) {
- if (rtl)
- item->x -= (MINIMUM_ICON_ITEM_WIDTH - item->width) / 2;
- else
- item->x += (MINIMUM_ICON_ITEM_WIDTH - item->width) / 2;
- x += (MINIMUM_ICON_ITEM_WIDTH - item->width);
- }
+ current_width += item->width;
- if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- if (gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL)
- {
- item->layout_x = item->x + ICON_TEXT_PADDING + focus_width + focus_pad;
- item->pixbuf_x = item->x + 2 * (ICON_TEXT_PADDING + focus_width + focus_pad) + item->layout_width;
- }
- else
- {
- item->pixbuf_x = item->x;
- item->layout_x = item->x + item->pixbuf_width + ICON_TEXT_PADDING + focus_width + focus_pad;
- }
- }
- else
+ if (items != first_item)
{
- item->pixbuf_x = item->x + (item->width - item->pixbuf_width) / 2;
- item->layout_x = item->x + (item->width - item->layout_width) / 2;
+ if ((icon_view->priv->columns <= 0 && current_width > GTK_WIDGET (icon_view)->allocation.width) ||
+ (icon_view->priv->columns > 0 && col >= icon_view->priv->columns))
+ break;
}
- x += item->width;
+ current_width += icon_view->priv->column_spacing + 2 * focus_width;
- max_height = MAX (max_height, item->height);
- max_pixbuf_height = MAX (max_pixbuf_height, item->pixbuf_height);
-
+ item->y = *y + focus_width;
+ item->x = rtl ? GTK_WIDGET (icon_view)->allocation.width - item->width - x : x;
+
+ x = current_width - (icon_view->priv->margin + focus_width);
+
+ for (i = 0; i < icon_view->priv->n_cells; i++)
+ max_height[i] = MAX (max_height[i], item->box[i].height);
+
if (current_width > *maximum_width)
*maximum_width = current_width;
item->row = row;
item->col = col;
- col++;
+ col += colspan;
items = items->next;
}
last_item = items;
- *y += max_height + ICON_VIEW_ICON_PADDING;
-
/* Now go through the row again and align the icons */
for (items = first_item; items != last_item; items = items->next)
{
GtkIconViewItem *item = items->data;
- if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- item->pixbuf_y = item->y;
- item->layout_y = item->y + ICON_TEXT_PADDING + focus_width + focus_pad;
- }
- else
- {
- item->pixbuf_y = item->y + (max_pixbuf_height - item->pixbuf_height);
- item->layout_y = item->pixbuf_y + item->pixbuf_height + ICON_TEXT_PADDING + focus_width + focus_pad;
- }
- /* Update the bounding box */
- item->y = item->pixbuf_y;
+ gtk_icon_view_calculate_item_size2 (icon_view, item, max_height);
/* We may want to readjust the new y coordinate. */
- if (item->y + item->height > *y)
- *y = item->y + item->height;
+ if (item->y + item->height + focus_width + icon_view->priv->row_spacing > *y)
+ *y = item->y + item->height + focus_width + icon_view->priv->row_spacing;
if (rtl)
item->col = col - 1 - item->col;
}
+
+ g_free (max_height);
return last_item;
}
GList *icons;
GtkWidget *widget;
gint row;
+ gint item_width;
- if (!VALID_MODEL_AND_COLUMNS (icon_view))
+ if (icon_view->priv->layout_idle_id != 0)
+ {
+ g_source_remove (icon_view->priv->layout_idle_id);
+ icon_view->priv->layout_idle_id = 0;
+ }
+
+ if (icon_view->priv->model == NULL)
return;
widget = GTK_WIDGET (icon_view);
- icons = icon_view->priv->items;
- y += ICON_VIEW_TOP_MARGIN;
- row = 0;
+ item_width = icon_view->priv->item_width;
+
+ if (item_width < 0)
+ {
+ for (icons = icon_view->priv->items; icons; icons = icons->next)
+ {
+ GtkIconViewItem *item = icons->data;
+ gtk_icon_view_calculate_item_size (icon_view, item);
+ item_width = MAX (item_width, item->width);
+ }
+ }
+ icons = icon_view->priv->items;
+ y += icon_view->priv->margin;
+ row = 0;
+
do
{
- icons = gtk_icon_view_layout_single_row (icon_view, icons, &y, &maximum_width, row);
+ icons = gtk_icon_view_layout_single_row (icon_view, icons,
+ item_width, row,
+ &y, &maximum_width);
row++;
}
while (icons != NULL);
if (maximum_width != icon_view->priv->width)
- {
- icon_view->priv->width = maximum_width;
- }
- y += ICON_VIEW_BOTTOM_MARGIN;
+ icon_view->priv->width = maximum_width;
+
+ y += icon_view->priv->margin;
if (y != icon_view->priv->height)
- {
- icon_view->priv->height = y;
- }
+ icon_view->priv->height = y;
- gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment, icon_view->priv->width);
- gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment, icon_view->priv->height);
+ gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment,
+ icon_view->priv->width);
+ gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment,
+ icon_view->priv->height);
if (GTK_WIDGET_REALIZED (icon_view))
- {
- gdk_window_resize (icon_view->priv->bin_window,
- MAX (icon_view->priv->width, widget->allocation.width),
- MAX (icon_view->priv->height, widget->allocation.height));
- }
+ gdk_window_resize (icon_view->priv->bin_window,
+ MAX (icon_view->priv->width, widget->allocation.width),
+ MAX (icon_view->priv->height, widget->allocation.height));
- if (icon_view->priv->layout_idle_id != 0)
+ if (icon_view->priv->scroll_to_path)
{
- g_source_remove (icon_view->priv->layout_idle_id);
- icon_view->priv->layout_idle_id = 0;
- }
+ GtkTreePath *path;
+ path = gtk_tree_row_reference_get_path (icon_view->priv->scroll_to_path);
+ gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
+ icon_view->priv->scroll_to_path = NULL;
+
+ gtk_icon_view_scroll_to_path (icon_view, path,
+ icon_view->priv->scroll_to_use_align,
+ icon_view->priv->scroll_to_row_align,
+ icon_view->priv->scroll_to_col_align);
+ gtk_tree_path_free (path);
+ }
+
gtk_widget_queue_draw (GTK_WIDGET (icon_view));
}
-/* Updates the pango layout and calculates the size */
-static void
-gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
- GtkIconViewItem *item)
+static void
+gtk_icon_view_get_cell_area (GtkIconView *icon_view,
+ GtkIconViewItem *item,
+ GtkIconViewCellInfo *info,
+ GdkRectangle *cell_area)
{
- gint focus_width, focus_pad;
- gint layout_width, layout_height;
- gint maximum_layout_width;
- GdkPixbuf *pixbuf;
-
- if (item->width != -1 && item->width != -1)
- return;
-
- gtk_widget_style_get (GTK_WIDGET (icon_view),
- "focus-line-width", &focus_width,
- "focus-padding", &focus_pad,
- NULL);
-
- if (icon_view->priv->pixbuf_column != -1)
+ if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
- pixbuf = gtk_icon_view_get_item_icon (icon_view, item);
- item->pixbuf_width = gdk_pixbuf_get_width (pixbuf);
- item->pixbuf_height = gdk_pixbuf_get_height (pixbuf);
- g_object_unref (pixbuf);
+ cell_area->x = item->box[info->position].x - item->before[info->position];
+ cell_area->y = item->y;
+ cell_area->width = item->box[info->position].width +
+ item->before[info->position] + item->after[info->position];
+ cell_area->height = item->height;
}
else
{
- item->pixbuf_width = 0;
- item->pixbuf_height = 0;
+ cell_area->x = item->x;
+ cell_area->y = item->box[info->position].y - item->before[info->position];
+ cell_area->width = item->width;
+ cell_area->height = item->box[info->position].height +
+ item->before[info->position] + item->after[info->position];
}
-
- maximum_layout_width = MAX (item->pixbuf_width, MINIMUM_ICON_ITEM_WIDTH);
+}
- if (icon_view->priv->markup_column != 1 ||
- icon_view->priv->text_column != -1)
- {
- gtk_icon_view_update_item_text (icon_view, item);
+static void
+gtk_icon_view_get_cell_box (GtkIconView *icon_view,
+ GtkIconViewItem *item,
+ GtkIconViewCellInfo *info,
+ GdkRectangle *box)
+{
+ *box = item->box[info->position];
+}
- pango_layout_set_alignment (icon_view->priv->layout, PANGO_ALIGN_CENTER);
- pango_layout_set_width (icon_view->priv->layout, maximum_layout_width * PANGO_SCALE);
+/* try to guess a reasonable wrap width for an implicit text cell renderer
+ */
+static void
+adjust_wrap_width (GtkIconView *icon_view,
+ GtkIconViewItem *item)
+{
+ GtkIconViewCellInfo *text_info;
+ GtkIconViewCellInfo *pixbuf_info;
+ gint pixbuf_width, wrap_width;
- pango_layout_get_pixel_size (icon_view->priv->layout, &layout_width, &layout_height);
+ if (icon_view->priv->text_cell != -1 &&
+ icon_view->priv->pixbuf_cell != -1)
+ {
+ text_info = g_list_nth_data (icon_view->priv->cell_list,
+ icon_view->priv->text_cell);
+ pixbuf_info = g_list_nth_data (icon_view->priv->cell_list,
+ icon_view->priv->pixbuf_cell);
- item->layout_width = layout_width;
- item->layout_height = layout_height;
+ gtk_cell_renderer_get_size (pixbuf_info->cell,
+ GTK_WIDGET (icon_view),
+ NULL, NULL, NULL,
+ &pixbuf_width,
+ NULL);
+
+ if (item->width == -1)
+ wrap_width = MAX (2 * pixbuf_width, 50);
+ else if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
+ wrap_width = item->width;
+ else
+ wrap_width = item->width - pixbuf_width - icon_view->priv->spacing;
+
+ g_object_set (text_info->cell, "wrap-width", wrap_width, NULL);
}
- else
+}
+
+static void
+gtk_icon_view_calculate_item_size (GtkIconView *icon_view,
+ GtkIconViewItem *item)
+{
+ gint spacing;
+ GList *l;
+
+ if (item->width != -1 && item->height != -1)
+ return;
+
+ if (item->n_cells != icon_view->priv->n_cells)
{
- item->layout_width = 0;
- item->layout_height = 0;
+ g_free (item->before);
+ g_free (item->after);
+ g_free (item->box);
+
+ item->before = g_new0 (gint, icon_view->priv->n_cells);
+ item->after = g_new0 (gint, icon_view->priv->n_cells);
+ item->box = g_new0 (GdkRectangle, icon_view->priv->n_cells);
+
+ item->n_cells = icon_view->priv->n_cells;
}
- if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ gtk_icon_view_set_cell_data (icon_view, item);
+
+ spacing = icon_view->priv->spacing;
+
+ item->width = 0;
+ item->height = 0;
+ for (l = icon_view->priv->cell_list; l; l = l->next)
{
- item->width = layout_width + 2 * (ICON_TEXT_PADDING + focus_width + focus_pad) + item->pixbuf_width;
- item->height = MAX (layout_height + 2 * (ICON_TEXT_PADDING + focus_width + focus_pad), item->pixbuf_height);
+ GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
+
+ if (!info->cell->visible)
+ continue;
+
+ gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
+ NULL, NULL, NULL,
+ &item->box[info->position].width,
+ &item->box[info->position].height);
+
+ if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ item->width += item->box[info->position].width
+ + (info->position > 0 ? spacing : 0);
+ item->height = MAX (item->height, item->box[info->position].height);
+ }
+ else
+ {
+ item->width = MAX (item->width, item->box[info->position].width);
+ item->height += item->box[info->position].height + (info->position > 0 ? spacing : 0);
+ }
}
- else
+}
+
+static void
+gtk_icon_view_calculate_item_size2 (GtkIconView *icon_view,
+ GtkIconViewItem *item,
+ gint *max_height)
+{
+ GdkRectangle cell_area;
+ gint spacing;
+ GList *l;
+ gint i, k;
+ gboolean rtl;
+
+ rtl = gtk_widget_get_direction (GTK_WIDGET (icon_view)) == GTK_TEXT_DIR_RTL;
+
+ gtk_icon_view_set_cell_data (icon_view, item);
+
+ spacing = icon_view->priv->spacing;
+
+ item->height = 0;
+ for (i = 0; i < icon_view->priv->n_cells; i++)
{
- item->width = MAX (layout_width + 2 * (ICON_TEXT_PADDING + focus_width + focus_pad), item->pixbuf_width);
- item->height = layout_height + 2 * (ICON_TEXT_PADDING + focus_width + focus_pad) + item->pixbuf_height;
+ if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ item->height = MAX (item->height, max_height[i]);
+ else
+ item->height += max_height[i] + (i > 0 ? spacing : 0);
}
+
+ cell_area.x = item->x;
+ cell_area.y = item->y;
+
+ for (k = 0; k < 2; k++)
+ for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
+ {
+ GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
+
+ if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
+ continue;
+
+ if (!info->cell->visible)
+ continue;
+
+ if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ cell_area.width = item->box[info->position].width;
+ cell_area.height = item->height;
+ }
+ else
+ {
+ cell_area.width = item->width;
+ cell_area.height = max_height[i];
+ }
+
+ gtk_cell_renderer_get_size (info->cell, GTK_WIDGET (icon_view),
+ &cell_area,
+ &item->box[info->position].x, &item->box[info->position].y,
+ &item->box[info->position].width, &item->box[info->position].height);
+
+ item->box[info->position].x += cell_area.x;
+ item->box[info->position].y += cell_area.y;
+ if (icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ item->before[info->position] = item->box[info->position].x - cell_area.x;
+ item->after[info->position] = cell_area.width - item->box[info->position].width - item->before[info->position];
+ cell_area.x += cell_area.width + spacing;
+ }
+ else
+ {
+ if (item->box[info->position].width > item->width)
+ {
+ item->width = item->box[info->position].width;
+ cell_area.width = item->width;
+ }
+ item->before[info->position] = item->box[info->position].y - cell_area.y;
+ item->after[info->position] = cell_area.height - item->box[info->position].height - item->before[info->position];
+ cell_area.y += cell_area.height + spacing;
+ }
+ }
+
+ if (rtl && icon_view->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ for (i = 0; i < icon_view->priv->n_cells; i++)
+ {
+ item->box[i].x = item->x + item->width -
+ (item->box[i].x + item->box[i].width - item->x);
+ }
+ }
}
static void
item->height = -1;
}
-static GdkPixbuf *
-create_colorized_pixbuf (GdkPixbuf *src, GdkColor *new_color)
-{
- gint i, j;
- gint width, height, has_alpha, src_row_stride, dst_row_stride;
- gint red_value, green_value, blue_value;
- guchar *target_pixels;
- guchar *original_pixels;
- guchar *pixsrc;
- guchar *pixdest;
- GdkPixbuf *dest;
-
- red_value = new_color->red / 255.0;
- green_value = new_color->green / 255.0;
- blue_value = new_color->blue / 255.0;
-
- dest = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
- gdk_pixbuf_get_has_alpha (src),
- gdk_pixbuf_get_bits_per_sample (src),
- gdk_pixbuf_get_width (src),
- gdk_pixbuf_get_height (src));
-
- has_alpha = gdk_pixbuf_get_has_alpha (src);
- width = gdk_pixbuf_get_width (src);
- height = gdk_pixbuf_get_height (src);
- src_row_stride = gdk_pixbuf_get_rowstride (src);
- dst_row_stride = gdk_pixbuf_get_rowstride (dest);
- target_pixels = gdk_pixbuf_get_pixels (dest);
- original_pixels = gdk_pixbuf_get_pixels (src);
-
- for (i = 0; i < height; i++) {
- pixdest = target_pixels + i*dst_row_stride;
- pixsrc = original_pixels + i*src_row_stride;
- for (j = 0; j < width; j++) {
- *pixdest++ = (*pixsrc++ * red_value) >> 8;
- *pixdest++ = (*pixsrc++ * green_value) >> 8;
- *pixdest++ = (*pixsrc++ * blue_value) >> 8;
- if (has_alpha) {
- *pixdest++ = *pixsrc++;
- }
- }
- }
- return dest;
-}
-
static void
gtk_icon_view_paint_item (GtkIconView *icon_view,
+ cairo_t *cr,
GtkIconViewItem *item,
- GdkRectangle *area)
+ GdkRectangle *area,
+ GdkDrawable *drawable,
+ gint x,
+ gint y,
+ gboolean draw_focus)
{
gint focus_width, focus_pad;
- GdkPixbuf *pixbuf, *tmp;
+ gint padding;
+ GdkRectangle cell_area, box;
+ GList *l;
+ gint i;
GtkStateType state;
-
- if (!VALID_MODEL_AND_COLUMNS (icon_view))
+ GtkCellRendererState flags;
+
+ if (icon_view->priv->model == NULL)
return;
+ gtk_icon_view_set_cell_data (icon_view, item);
+
gtk_widget_style_get (GTK_WIDGET (icon_view),
"focus-line-width", &focus_width,
"focus-padding", &focus_pad,
NULL);
-
- if (GTK_WIDGET_HAS_FOCUS (icon_view))
- state = GTK_STATE_SELECTED;
- else
- state = GTK_STATE_ACTIVE;
-
- if (icon_view->priv->pixbuf_column != -1)
+
+ padding = focus_width;
+
+ if (item->selected)
{
- tmp = gtk_icon_view_get_item_icon (icon_view, item);
- if (item->selected)
- {
- pixbuf = create_colorized_pixbuf (tmp,
- >K_WIDGET (icon_view)->style->base[state]);
- g_object_unref (tmp);
- }
+ flags = GTK_CELL_RENDERER_SELECTED;
+ if (GTK_WIDGET_HAS_FOCUS (icon_view))
+ state = GTK_STATE_SELECTED;
else
- pixbuf = tmp;
-
- gdk_draw_pixbuf (icon_view->priv->bin_window, NULL, pixbuf,
- 0, 0,
- item->pixbuf_x, item->pixbuf_y,
- item->pixbuf_width, item->pixbuf_height,
- GDK_RGB_DITHER_NORMAL,
- item->pixbuf_width, item->pixbuf_height);
- g_object_unref (pixbuf);
+ state = GTK_STATE_ACTIVE;
+ }
+ else
+ {
+ flags = 0;
+ state = GTK_STATE_NORMAL;
}
+
+#ifdef DEBUG_ICON_VIEW
+ gdk_draw_rectangle (drawable,
+ GTK_WIDGET (icon_view)->style->black_gc,
+ FALSE,
+ x, y,
+ item->width, item->height);
+#endif
- if (icon_view->priv->text_column != -1)
+ if (item->selected)
+ for (l = icon_view->priv->cell_list; l; l = l->next)
+ {
+ GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
+
+ if (!info->cell->visible)
+ continue;
+
+ gtk_icon_view_get_cell_box (icon_view, item, info, &box);
+
+ /* FIXME we hardwire background drawing behind text
+ * cell renderers here
+ */
+ if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
+ {
+ gdk_cairo_set_source_color (cr, >K_WIDGET (icon_view)->style->base[state]);
+ cairo_rectangle (cr,
+ x - item->x + box.x,
+ y - item->y + box.y,
+ box.width, box.height);
+ cairo_fill (cr);
+ }
+ }
+
+ for (l = icon_view->priv->cell_list; l; l = l->next)
{
- if (item->selected)
- {
- gdk_draw_rectangle (icon_view->priv->bin_window,
- GTK_WIDGET (icon_view)->style->base_gc[state],
- TRUE,
- item->layout_x - ICON_TEXT_PADDING,
- item->layout_y - ICON_TEXT_PADDING,
- item->layout_width + 2 * ICON_TEXT_PADDING,
- item->layout_height + 2 * ICON_TEXT_PADDING);
- }
+ GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
+
+ if (!info->cell->visible)
+ continue;
+
+ gtk_icon_view_get_cell_area (icon_view, item, info, &cell_area);
+
+#ifdef DEBUG_ICON_VIEW
+ gdk_draw_rectangle (drawable,
+ GTK_WIDGET (icon_view)->style->black_gc,
+ FALSE,
+ x - item->x + cell_area.x,
+ y - item->y + cell_area.y,
+ cell_area.width, cell_area.height);
+
+ gtk_icon_view_get_cell_box (icon_view, item, info, &box);
+
+ gdk_draw_rectangle (drawable,
+ GTK_WIDGET (icon_view)->style->black_gc,
+ FALSE,
+ x - item->x + box.x,
+ y - item->y + box.y,
+ box.width, box.height);
+#endif
- gtk_icon_view_update_item_text (icon_view, item);
- gtk_paint_layout (GTK_WIDGET (icon_view)->style,
- icon_view->priv->bin_window,
- item->selected ? state : GTK_STATE_NORMAL,
- TRUE, area, GTK_WIDGET (icon_view), "icon_view",
- item->layout_x - ((item->width - item->layout_width) / 2) - (MAX (item->pixbuf_width, MINIMUM_ICON_ITEM_WIDTH) - item->width) / 2,
- item->layout_y,
- icon_view->priv->layout);
+ cell_area.x = x - item->x + cell_area.x;
+ cell_area.y = y - item->y + cell_area.y;
- if (GTK_WIDGET_HAS_FOCUS (icon_view) &&
- item == icon_view->priv->cursor_item)
- gtk_paint_focus (GTK_WIDGET (icon_view)->style,
- icon_view->priv->bin_window,
- GTK_STATE_NORMAL,
- area,
- GTK_WIDGET (icon_view),
- "icon_view",
- item->layout_x - ICON_TEXT_PADDING - focus_width - focus_pad,
- item->layout_y - ICON_TEXT_PADDING - focus_width - focus_pad,
- item->layout_width + 2 * (ICON_TEXT_PADDING + focus_width + focus_pad),
- item->layout_height + 2 * (ICON_TEXT_PADDING + focus_width + focus_pad));
+ gtk_cell_renderer_render (info->cell,
+ drawable,
+ GTK_WIDGET (icon_view),
+ &cell_area, &cell_area, area, flags);
+
}
-}
-static guint32
-gtk_gdk_color_to_rgb (const GdkColor *color)
-{
- guint32 result;
- result = (0xff0000 | (color->red & 0xff00));
- result <<= 8;
- result |= ((color->green & 0xff00) | (color->blue >> 8));
- return result;
+ /* FIXME where to draw the focus with generic cell renderers ? */
+ if (draw_focus &&
+ GTK_WIDGET_HAS_FOCUS (icon_view) &&
+ item == icon_view->priv->cursor_item)
+ for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
+ {
+ GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
+
+ if (!info->cell->visible)
+ continue;
+
+ if (icon_view->priv->cursor_cell < 0 &&
+ (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT ||
+ GTK_IS_CELL_RENDERER_TEXT (info->cell)))
+ icon_view->priv->cursor_cell = i;
+
+ if (i == icon_view->priv->cursor_cell)
+ {
+ gtk_icon_view_get_cell_box (icon_view, item, info, &box);
+
+ gtk_paint_focus (GTK_WIDGET (icon_view)->style,
+ drawable,
+ GTK_STATE_NORMAL,
+ area,
+ GTK_WIDGET (icon_view),
+ "icon_view",
+ x - item->x + box.x - padding,
+ y - item->y + box.y - padding,
+ box.width + 2 * padding,
+ box.height + 2 * padding);
+ break;
+ }
+ }
}
static void
gtk_icon_view_paint_rubberband (GtkIconView *icon_view,
+ cairo_t *cr,
GdkRectangle *area)
{
GdkRectangle rect;
- GdkPixbuf *pixbuf;
- GdkGC *gc;
GdkRectangle rubber_rect;
GdkColor *fill_color_gdk;
- guint fill_color;
guchar fill_color_alpha;
rubber_rect.x = MIN (icon_view->priv->rubberband_x1, icon_view->priv->rubberband_x2);
return;
gtk_widget_style_get (GTK_WIDGET (icon_view),
- "selection_box_color", &fill_color_gdk,
- "selection_box_alpha", &fill_color_alpha,
+ "selection-box-color", &fill_color_gdk,
+ "selection-box-alpha", &fill_color_alpha,
NULL);
- if (!fill_color_gdk) {
+ if (!fill_color_gdk)
fill_color_gdk = gdk_color_copy (>K_WIDGET (icon_view)->style->base[GTK_STATE_SELECTED]);
- }
- fill_color = gtk_gdk_color_to_rgb (fill_color_gdk) << 8 | fill_color_alpha;
+ cairo_set_source_rgba (cr,
+ fill_color_gdk->red / 65535.,
+ fill_color_gdk->green / 65535.,
+ fill_color_gdk->blue / 65535.,
+ fill_color_alpha / 255.);
+
+ cairo_save (cr);
+ gdk_cairo_rectangle (cr, &rect);
+ cairo_clip (cr);
+ cairo_paint (cr);
+
+ /* Draw the border without alpha */
+ cairo_set_source_rgb (cr,
+ fill_color_gdk->red / 65535.,
+ fill_color_gdk->green / 65535.,
+ fill_color_gdk->blue / 65535.);
+ cairo_rectangle (cr,
+ rubber_rect.x + 0.5, rubber_rect.y + 0.5,
+ rubber_rect.width - 1, rubber_rect.height - 1);
+ cairo_stroke (cr);
+ cairo_restore (cr);
- if (!gdk_draw_rectangle_alpha_libgtk_only (icon_view->priv->bin_window,
- rect.x, rect.y, rect.width, rect.height,
- fill_color_gdk,
- fill_color_alpha << 8 | fill_color_alpha))
- {
- pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, rect.width, rect.height);
- gdk_pixbuf_fill (pixbuf, fill_color);
-
- gdk_draw_pixbuf (icon_view->priv->bin_window, NULL, pixbuf,
- 0, 0,
- rect.x,rect.y,
- rect.width, rect.height,
- GDK_RGB_DITHER_NONE,
- 0, 0);
- g_object_unref (pixbuf);
- }
-
- gc = gdk_gc_new (icon_view->priv->bin_window);
- gdk_gc_set_rgb_fg_color (gc, fill_color_gdk);
- gdk_gc_set_clip_rectangle (gc, &rect);
- gdk_draw_rectangle (icon_view->priv->bin_window,
- gc, FALSE,
- rubber_rect.x, rubber_rect.y,
- rubber_rect.width - 1, rubber_rect.height - 1);
gdk_color_free (fill_color_gdk);
- g_object_unref (gc);
+}
+
+static void
+gtk_icon_view_queue_draw_path (GtkIconView *icon_view,
+ GtkTreePath *path)
+{
+ GList *l;
+ gint index;
+
+ index = gtk_tree_path_get_indices (path)[0];
+
+ for (l = icon_view->priv->items; l; l = l->next)
+ {
+ GtkIconViewItem *item = l->data;
+
+ if (item->index == index)
+ {
+ gtk_icon_view_queue_draw_item (icon_view, item);
+ break;
+ }
+ }
}
static void
gtk_icon_view_queue_draw_item (GtkIconView *icon_view,
GtkIconViewItem *item)
{
+ gint focus_width;
GdkRectangle rect;
- rect.x = item->x;
- rect.y = item->y;
- rect.width = item->width;
- rect.height = item->height;
+ gtk_widget_style_get (GTK_WIDGET (icon_view),
+ "focus-line-width", &focus_width,
+ NULL);
+
+ rect.x = item->x - focus_width;
+ rect.y = item->y - focus_width;
+ rect.width = item->width + 2 * focus_width;
+ rect.height = item->height + 2 * focus_width;
if (icon_view->priv->bin_window)
gdk_window_invalidate_rect (icon_view->priv->bin_window, &rect, TRUE);
{
GtkIconView *icon_view;
- GDK_THREADS_ENTER ();
-
icon_view = GTK_ICON_VIEW (user_data);
icon_view->priv->layout_idle_id = 0;
gtk_icon_view_layout (icon_view);
- GDK_THREADS_LEAVE();
-
return FALSE;
}
if (icon_view->priv->layout_idle_id != 0)
return;
- icon_view->priv->layout_idle_id = g_idle_add (layout_callback, icon_view);
+ icon_view->priv->layout_idle_id = gdk_threads_add_idle (layout_callback, icon_view);
}
static void
gtk_icon_view_set_cursor_item (GtkIconView *icon_view,
- GtkIconViewItem *item)
+ GtkIconViewItem *item,
+ gint cursor_cell)
{
AtkObject *obj;
AtkObject *item_obj;
- if (icon_view->priv->cursor_item == item)
+ if (icon_view->priv->cursor_item == item &&
+ (cursor_cell < 0 || cursor_cell == icon_view->priv->cursor_cell))
return;
if (icon_view->priv->cursor_item != NULL)
gtk_icon_view_queue_draw_item (icon_view, icon_view->priv->cursor_item);
icon_view->priv->cursor_item = item;
+ if (cursor_cell >= 0)
+ icon_view->priv->cursor_cell = cursor_cell;
+
gtk_icon_view_queue_draw_item (icon_view, item);
/* Notify that accessible focus object has changed */
{
g_return_if_fail (item != NULL);
- g_free (item);
-}
-
-static void
-gtk_icon_view_update_item_text (GtkIconView *icon_view,
- GtkIconViewItem *item)
-{
- gboolean iters_persist;
- GtkTreeIter iter;
- GtkTreePath *path;
- gchar *text;
-
- iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
-
- if (!iters_persist)
- {
- path = gtk_tree_path_new_from_indices (item->index, -1);
- gtk_tree_model_get_iter (icon_view->priv->model, &iter, path);
- gtk_tree_path_free (path);
- }
- else
- iter = item->iter;
-
- if (icon_view->priv->markup_column != -1)
- {
- gtk_tree_model_get (icon_view->priv->model, &iter,
- icon_view->priv->markup_column, &text,
- -1);
- pango_layout_set_markup (icon_view->priv->layout, text, -1);
- }
- else
- {
- gtk_tree_model_get (icon_view->priv->model, &iter,
- icon_view->priv->text_column, &text,
- -1);
- pango_layout_set_text (icon_view->priv->layout, text, -1);
- }
-
- g_free (text);
-}
-
-static GdkPixbuf *
-gtk_icon_view_get_item_icon (GtkIconView *icon_view,
- GtkIconViewItem *item)
-{
- gboolean iters_persist;
- GtkTreeIter iter;
- GtkTreePath *path;
- GdkPixbuf *pixbuf;
-
- g_return_val_if_fail (item != NULL, NULL);
-
- iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
-
- if (!iters_persist)
- {
- path = gtk_tree_path_new_from_indices (item->index, -1);
- gtk_tree_model_get_iter (icon_view->priv->model, &iter, path);
- gtk_tree_path_free (path);
- }
- else
- iter = item->iter;
-
- gtk_tree_model_get (icon_view->priv->model, &iter,
- icon_view->priv->pixbuf_column, &pixbuf,
- -1);
+ g_free (item->before);
+ g_free (item->after);
+ g_free (item->box);
- return pixbuf;
+ g_free (item);
}
static GtkIconViewItem *
-gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
- gint x,
- gint y)
+gtk_icon_view_get_item_at_coords (GtkIconView *icon_view,
+ gint x,
+ gint y,
+ gboolean only_in_cell,
+ GtkIconViewCellInfo **cell_at_pos)
{
- GList *items;
-
+ GList *items, *l;
+ GdkRectangle box;
+
for (items = icon_view->priv->items; items; items = items->next)
{
GtkIconViewItem *item = items->data;
-
- if (x > item->x && x < item->x + item->width &&
- y > item->y && y < item->y + item->height)
+
+ if (x >= item->x - icon_view->priv->column_spacing/2 && x <= item->x + item->width + icon_view->priv->column_spacing/2 &&
+ y >= item->y - icon_view->priv->row_spacing/2 && y <= item->y + item->height + icon_view->priv->row_spacing/2)
{
- gint layout_x = item->x + (item->width - item->layout_width) / 2;
- /* Check if the mouse is inside the icon or the label */
- if ((x > item->pixbuf_x && x < item->pixbuf_x + item->pixbuf_width &&
- y > item->pixbuf_y && y < item->pixbuf_y + item->pixbuf_height) ||
- (x > layout_x - ICON_TEXT_PADDING &&
- x < layout_x + item->layout_width + ICON_TEXT_PADDING * 2 &&
- y > item->layout_y - ICON_TEXT_PADDING
- && y < item->layout_y + item->layout_height + ICON_TEXT_PADDING * 2))
- return item;
+ if (only_in_cell || cell_at_pos)
+ {
+ gtk_icon_view_set_cell_data (icon_view, item);
+
+ for (l = icon_view->priv->cell_list; l; l = l->next)
+ {
+ GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
+
+ if (!info->cell->visible)
+ continue;
+
+ gtk_icon_view_get_cell_box (icon_view, item, info, &box);
+
+ if ((x >= box.x && x <= box.x + box.width &&
+ y >= box.y && y <= box.y + box.height) ||
+ (x >= box.x &&
+ x <= box.x + box.width &&
+ y >= box.y &&
+ y <= box.y + box.height))
+ {
+ if (cell_at_pos)
+ *cell_at_pos = info;
+
+ return item;
+ }
+ }
+
+ if (only_in_cell)
+ return NULL;
+
+ if (cell_at_pos)
+ *cell_at_pos = NULL;
+ }
+
+ return item;
}
}
GtkIconViewItem *item = items->data;
if (item->index != i)
- g_error ("List item does not match its index: item index %d and list index %d\n", item->index, i);
+ g_error ("List item does not match its index: "
+ "item index %d and list index %d\n", item->index, i);
i++;
}
GtkIconView *icon_view;
icon_view = GTK_ICON_VIEW (data);
+
+ gtk_icon_view_stop_editing (icon_view, TRUE);
index = gtk_tree_path_get_indices(path)[0];
- item = g_list_nth (icon_view->priv->items, index)->data;
+ item = g_list_nth_data (icon_view->priv->items, index);
gtk_icon_view_item_invalidate_size (item);
gtk_icon_view_queue_layout (icon_view);
GtkTreeIter *iter,
gpointer data)
{
- gint length, index;
+ gint index;
GtkIconViewItem *item;
gboolean iters_persist;
GtkIconView *icon_view;
GList *list;
icon_view = GTK_ICON_VIEW (data);
+
iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
- length = gtk_tree_model_iter_n_children (model, NULL);
index = gtk_tree_path_get_indices(path)[0];
item = gtk_icon_view_item_new ();
}
verify_items (icon_view);
+
+ gtk_icon_view_queue_layout (icon_view);
}
static void
list = g_list_nth (icon_view->priv->items, index);
item = list->data;
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+
if (item == icon_view->priv->anchor_item)
icon_view->priv->anchor_item = NULL;
icon_view->priv->items = g_list_delete_link (icon_view->priv->items, list);
- gtk_icon_view_queue_layout (icon_view);
-
verify_items (icon_view);
+ gtk_icon_view_queue_layout (icon_view);
+
if (emit)
g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
}
int length;
GtkIconView *icon_view;
GList *items = NULL, *list;
- gint *inverted_order;
GtkIconViewItem **item_array;
+ gint *order;
icon_view = GTK_ICON_VIEW (data);
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+
length = gtk_tree_model_iter_n_children (model, NULL);
- inverted_order = g_new (gint, length);
- /* Invert the array */
+ order = g_new (gint, length);
for (i = 0; i < length; i++)
- inverted_order[new_order[i]] = i;
+ order [new_order[i]] = i;
item_array = g_new (GtkIconViewItem *, length);
for (i = 0, list = icon_view->priv->items; list != NULL; list = list->next, i++)
- item_array[inverted_order[i]] = list->data;
+ item_array[order[i]] = list->data;
+ g_free (order);
- g_free (inverted_order);
- for (i = 0; i < length; i++)
+ for (i = length - 1; i >= 0; i--)
{
item_array[i]->index = i;
items = g_list_prepend (items, item_array[i]);
g_free (item_array);
g_list_free (icon_view->priv->items);
- icon_view->priv->items = g_list_reverse (items);
+ icon_view->priv->items = items;
+
+ gtk_icon_view_queue_layout (icon_view);
verify_items (icon_view);
}
{
gtk_binding_entry_add_signal (binding_set, keyval, modmask,
- "move_cursor", 2,
+ I_("move_cursor"), 2,
G_TYPE_ENUM, step,
G_TYPE_INT, count);
if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (icon_view)))
return FALSE;
+ gtk_icon_view_stop_editing (icon_view, FALSE);
gtk_widget_grab_focus (GTK_WIDGET (icon_view));
if (gtk_get_current_event_state (&state))
return NULL;
}
+static gint
+find_cell (GtkIconView *icon_view,
+ GtkIconViewItem *item,
+ gint cell,
+ GtkOrientation orientation,
+ gint step,
+ gint *count)
+{
+ gint n_focusable;
+ gint *focusable;
+ gint first_text;
+ gint current;
+ gint i, k;
+ GList *l;
+
+ if (icon_view->priv->orientation != orientation)
+ return cell;
+
+ gtk_icon_view_set_cell_data (icon_view, item);
+
+ focusable = g_new0 (gint, icon_view->priv->n_cells);
+ n_focusable = 0;
+
+ first_text = 0;
+ current = 0;
+ for (k = 0; k < 2; k++)
+ for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
+ {
+ GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)l->data;
+
+ if (info->pack == (k ? GTK_PACK_START : GTK_PACK_END))
+ continue;
+
+ if (!info->cell->visible)
+ continue;
+
+ if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
+ first_text = i;
+
+ if (info->cell->mode != GTK_CELL_RENDERER_MODE_INERT)
+ {
+ if (cell == i)
+ current = n_focusable;
+
+ focusable[n_focusable] = i;
+
+ n_focusable++;
+ }
+ }
+
+ if (n_focusable == 0)
+ focusable[n_focusable++] = first_text;
+
+ if (cell < 0)
+ {
+ current = step > 0 ? 0 : n_focusable - 1;
+ cell = focusable[current];
+ }
+
+ if (current + *count < 0)
+ {
+ cell = -1;
+ *count = current + *count;
+ }
+ else if (current + *count > n_focusable - 1)
+ {
+ cell = -1;
+ *count = current + *count - (n_focusable - 1);
+ }
+ else
+ {
+ cell = focusable[current + *count];
+ *count = 0;
+ }
+
+ g_free (focusable);
+
+ return cell;
+}
static GtkIconViewItem *
find_item_page_up_down (GtkIconView *icon_view,
gint count)
{
GtkIconViewItem *item;
+ gint cell;
gboolean dirty = FALSE;
+ gint step;
if (!GTK_WIDGET_HAS_FOCUS (icon_view))
return;
list = g_list_last (icon_view->priv->items);
item = list ? list->data : NULL;
+ cell = -1;
}
else
- item = find_item (icon_view,
- icon_view->priv->cursor_item,
- count, 0);
+ {
+ item = icon_view->priv->cursor_item;
+ cell = icon_view->priv->cursor_cell;
+ step = count > 0 ? 1 : -1;
+ while (item)
+ {
+ cell = find_cell (icon_view, item, cell,
+ GTK_ORIENTATION_VERTICAL,
+ step, &count);
+ if (count == 0)
+ break;
+
+ item = find_item (icon_view, item, step, 0);
+ count = count - step;
+ }
+ }
if (!item)
- return;
+ {
+ gtk_widget_error_bell (GTK_WIDGET (icon_view));
+ return;
+ }
if (icon_view->priv->ctrl_pressed ||
!icon_view->priv->shift_pressed ||
icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
icon_view->priv->anchor_item = item;
- gtk_icon_view_set_cursor_item (icon_view, item);
+ gtk_icon_view_set_cursor_item (icon_view, item, cell);
if (!icon_view->priv->ctrl_pressed &&
icon_view->priv->selection_mode != GTK_SELECTION_NONE)
{
- gtk_icon_view_unselect_all_internal (icon_view);
+ dirty = gtk_icon_view_unselect_all_internal (icon_view);
dirty = gtk_icon_view_select_all_between (icon_view,
icon_view->priv->anchor_item,
- item);
+ item) || dirty;
}
gtk_icon_view_scroll_to_item (icon_view, item);
icon_view->priv->cursor_item,
count);
+ if (item == icon_view->priv->cursor_item)
+ gtk_widget_error_bell (GTK_WIDGET (icon_view));
+
if (!item)
return;
icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
icon_view->priv->anchor_item = item;
- gtk_icon_view_set_cursor_item (icon_view, item);
+ gtk_icon_view_set_cursor_item (icon_view, item, -1);
if (!icon_view->priv->ctrl_pressed &&
icon_view->priv->selection_mode != GTK_SELECTION_NONE)
{
- gtk_icon_view_unselect_all_internal (icon_view);
+ dirty = gtk_icon_view_unselect_all_internal (icon_view);
dirty = gtk_icon_view_select_all_between (icon_view,
icon_view->priv->anchor_item,
- item);
+ item) || dirty;
}
gtk_icon_view_scroll_to_item (icon_view, item);
gint count)
{
GtkIconViewItem *item;
+ gint cell = -1;
gboolean dirty = FALSE;
+ gint step;
if (!GTK_WIDGET_HAS_FOCUS (icon_view))
return;
item = list ? list->data : NULL;
}
else
- item = find_item (icon_view,
- icon_view->priv->cursor_item,
- 0, count);
+ {
+ item = icon_view->priv->cursor_item;
+ cell = icon_view->priv->cursor_cell;
+ step = count > 0 ? 1 : -1;
+ while (item)
+ {
+ cell = find_cell (icon_view, item, cell,
+ GTK_ORIENTATION_HORIZONTAL,
+ step, &count);
+ if (count == 0)
+ break;
+
+ item = find_item (icon_view, item, 0, step);
+ count = count - step;
+ }
+ }
if (!item)
- return;
+ {
+ gtk_widget_error_bell (GTK_WIDGET (icon_view));
+ return;
+ }
if (icon_view->priv->ctrl_pressed ||
!icon_view->priv->shift_pressed ||
icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
icon_view->priv->anchor_item = item;
- gtk_icon_view_set_cursor_item (icon_view, item);
+ gtk_icon_view_set_cursor_item (icon_view, item, cell);
if (!icon_view->priv->ctrl_pressed &&
icon_view->priv->selection_mode != GTK_SELECTION_NONE)
{
- gtk_icon_view_unselect_all_internal (icon_view);
+ dirty = gtk_icon_view_unselect_all_internal (icon_view);
dirty = gtk_icon_view_select_all_between (icon_view,
icon_view->priv->anchor_item,
- item);
+ item) || dirty;
}
gtk_icon_view_scroll_to_item (icon_view, item);
item = list ? list->data : NULL;
+ if (item == icon_view->priv->cursor_item)
+ gtk_widget_error_bell (GTK_WIDGET (icon_view));
+
if (!item)
return;
icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
icon_view->priv->anchor_item = item;
- gtk_icon_view_set_cursor_item (icon_view, item);
+ gtk_icon_view_set_cursor_item (icon_view, item, -1);
if (!icon_view->priv->ctrl_pressed &&
icon_view->priv->selection_mode != GTK_SELECTION_NONE)
{
- gtk_icon_view_unselect_all (icon_view);
+ dirty = gtk_icon_view_unselect_all_internal (icon_view);
dirty = gtk_icon_view_select_all_between (icon_view,
icon_view->priv->anchor_item,
- item);
+ item) || dirty;
}
gtk_icon_view_scroll_to_item (icon_view, item);
g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
}
+/**
+ * gtk_icon_view_scroll_to_path:
+ * @icon_view: A #GtkIconView.
+ * @path: The path of the item to move to.
+ * @use_align: whether to use alignment arguments, or %FALSE.
+ * @row_align: The vertical alignment of the item specified by @path.
+ * @col_align: The horizontal alignment of the item specified by @path.
+ *
+ * Moves the alignments of @icon_view to the position specified by @path.
+ * @row_align determines where the row is placed, and @col_align determines
+ * where @column is placed. Both are expected to be between 0.0 and 1.0.
+ * 0.0 means left/top alignment, 1.0 means right/bottom alignment, 0.5 means
+ * center.
+ *
+ * If @use_align is %FALSE, then the alignment arguments are ignored, and the
+ * tree does the minimum amount of work to scroll the item onto the screen.
+ * This means that the item will be scrolled to the edge closest to its current
+ * position. If the item is currently visible on the screen, nothing is done.
+ *
+ * This function only works if the model is set, and @path is a valid row on
+ * the model. If the model changes before the @icon_view is realized, the
+ * centered path will be modified to reflect this change.
+ *
+ * Since: 2.8
+ **/
+void
+gtk_icon_view_scroll_to_path (GtkIconView *icon_view,
+ GtkTreePath *path,
+ gboolean use_align,
+ gfloat row_align,
+ gfloat col_align)
+{
+ GtkIconViewItem *item = NULL;
+
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+ g_return_if_fail (path != NULL);
+ g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
+ g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
+
+ if (gtk_tree_path_get_depth (path) > 0)
+ item = g_list_nth_data (icon_view->priv->items,
+ gtk_tree_path_get_indices(path)[0]);
+
+ if (!GTK_WIDGET_REALIZED (icon_view) || !item || item->width < 0)
+ {
+ if (icon_view->priv->scroll_to_path)
+ gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
+
+ icon_view->priv->scroll_to_path = NULL;
+
+ if (path)
+ icon_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view), icon_view->priv->model, path);
+
+ icon_view->priv->scroll_to_use_align = use_align;
+ icon_view->priv->scroll_to_row_align = row_align;
+ icon_view->priv->scroll_to_col_align = col_align;
+
+ return;
+ }
+
+ if (use_align)
+ {
+ gint x, y;
+ gint focus_width;
+ gfloat offset, value;
+
+ gtk_widget_style_get (GTK_WIDGET (icon_view),
+ "focus-line-width", &focus_width,
+ NULL);
+
+ gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
+
+ offset = y + item->y - focus_width -
+ row_align * (GTK_WIDGET (icon_view)->allocation.height - item->height);
+ value = CLAMP (icon_view->priv->vadjustment->value + offset,
+ icon_view->priv->vadjustment->lower,
+ icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
+ gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
+
+ offset = x + item->x - focus_width -
+ col_align * (GTK_WIDGET (icon_view)->allocation.width - item->width);
+ value = CLAMP (icon_view->priv->hadjustment->value + offset,
+ icon_view->priv->hadjustment->lower,
+ icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
+ gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
+
+ gtk_adjustment_changed (icon_view->priv->hadjustment);
+ gtk_adjustment_changed (icon_view->priv->vadjustment);
+ }
+ else
+ gtk_icon_view_scroll_to_item (icon_view, item);
+}
+
+
static void
gtk_icon_view_scroll_to_item (GtkIconView *icon_view,
GtkIconViewItem *item)
{
- gint y, height;
- gdouble value;
+ gint x, y, width, height;
+ gint focus_width;
+
+ gtk_widget_style_get (GTK_WIDGET (icon_view),
+ "focus-line-width", &focus_width,
+ NULL);
- gdk_window_get_geometry (icon_view->priv->bin_window, NULL, &y, NULL, &height, NULL);
+ gdk_drawable_get_size (GDK_DRAWABLE (icon_view->priv->bin_window),
+ &width, &height);
+ gdk_window_get_position (icon_view->priv->bin_window, &x, &y);
+
+ if (y + item->y - focus_width < 0)
+ gtk_adjustment_set_value (icon_view->priv->vadjustment,
+ icon_view->priv->vadjustment->value + y + item->y - focus_width);
+ else if (y + item->y + item->height + focus_width > GTK_WIDGET (icon_view)->allocation.height)
+ gtk_adjustment_set_value (icon_view->priv->vadjustment,
+ icon_view->priv->vadjustment->value + y + item->y + item->height
+ + focus_width - GTK_WIDGET (icon_view)->allocation.height);
+
+ if (x + item->x - focus_width < 0)
+ gtk_adjustment_set_value (icon_view->priv->hadjustment,
+ icon_view->priv->hadjustment->value + x + item->x - focus_width);
+ else if (x + item->x + item->width + focus_width > GTK_WIDGET (icon_view)->allocation.width)
+ gtk_adjustment_set_value (icon_view->priv->hadjustment,
+ icon_view->priv->hadjustment->value + x + item->x + item->width
+ + focus_width - GTK_WIDGET (icon_view)->allocation.width);
+
+ gtk_adjustment_changed (icon_view->priv->hadjustment);
+ gtk_adjustment_changed (icon_view->priv->vadjustment);
+}
+
+/* GtkCellLayout implementation */
+static GtkIconViewCellInfo *
+gtk_icon_view_get_cell_info (GtkIconView *icon_view,
+ GtkCellRenderer *renderer)
+{
+ GList *i;
- if (y + item->y < 0)
+ for (i = icon_view->priv->cell_list; i; i = i->next)
{
- value = icon_view->priv->vadjustment->value + y + item->y;
- gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
+ GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)i->data;
+
+ if (info->cell == renderer)
+ return info;
+ }
+
+ return NULL;
+}
+
+static void
+gtk_icon_view_set_cell_data (GtkIconView *icon_view,
+ GtkIconViewItem *item)
+{
+ GList *i;
+ gboolean iters_persist;
+ GtkTreeIter iter;
+
+ iters_persist = gtk_tree_model_get_flags (icon_view->priv->model) & GTK_TREE_MODEL_ITERS_PERSIST;
+
+ if (!iters_persist)
+ {
+ GtkTreePath *path;
+
+ path = gtk_tree_path_new_from_indices (item->index, -1);
+ gtk_tree_model_get_iter (icon_view->priv->model, &iter, path);
+ gtk_tree_path_free (path);
}
- else if (y + item->y + item->height > GTK_WIDGET (icon_view)->allocation.height)
+ else
+ iter = item->iter;
+
+ for (i = icon_view->priv->cell_list; i; i = i->next)
{
- value = icon_view->priv->vadjustment->value + y + item->y + item->height
- - GTK_WIDGET (icon_view)->allocation.height;
- gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
+ GSList *j;
+ GtkIconViewCellInfo *info = i->data;
+
+ g_object_freeze_notify (G_OBJECT (info->cell));
+
+ for (j = info->attributes; j && j->next; j = j->next->next)
+ {
+ gchar *property = j->data;
+ gint column = GPOINTER_TO_INT (j->next->data);
+ GValue value = {0, };
+
+ gtk_tree_model_get_value (icon_view->priv->model, &iter,
+ column, &value);
+ g_object_set_property (G_OBJECT (info->cell),
+ property, &value);
+ g_value_unset (&value);
+ }
+
+ if (info->func)
+ (* info->func) (GTK_CELL_LAYOUT (icon_view),
+ info->cell,
+ icon_view->priv->model,
+ &iter,
+ info->func_data);
+
+ g_object_thaw_notify (G_OBJECT (info->cell));
+ }
+
+ adjust_wrap_width (icon_view, item);
+}
+
+static void
+free_cell_attributes (GtkIconViewCellInfo *info)
+{
+ GSList *list;
+
+ list = info->attributes;
+ while (list && list->next)
+ {
+ g_free (list->data);
+ list = list->next->next;
+ }
+
+ g_slist_free (info->attributes);
+ info->attributes = NULL;
+}
+
+static void
+free_cell_info (GtkIconViewCellInfo *info)
+{
+ free_cell_attributes (info);
+
+ g_object_unref (info->cell);
+
+ if (info->destroy)
+ (* info->destroy) (info->func_data);
+
+ g_free (info);
+}
+
+static void
+gtk_icon_view_cell_layout_pack_start (GtkCellLayout *layout,
+ GtkCellRenderer *renderer,
+ gboolean expand)
+{
+ GtkIconViewCellInfo *info;
+ GtkIconView *icon_view = GTK_ICON_VIEW (layout);
+
+ g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
+ g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
+
+ g_object_ref_sink (renderer);
+
+ info = g_new0 (GtkIconViewCellInfo, 1);
+ info->cell = renderer;
+ info->expand = expand ? TRUE : FALSE;
+ info->pack = GTK_PACK_START;
+ info->position = icon_view->priv->n_cells;
+
+ icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
+ icon_view->priv->n_cells++;
+}
+
+static void
+gtk_icon_view_cell_layout_pack_end (GtkCellLayout *layout,
+ GtkCellRenderer *renderer,
+ gboolean expand)
+{
+ GtkIconViewCellInfo *info;
+ GtkIconView *icon_view = GTK_ICON_VIEW (layout);
+
+ g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
+ g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
+
+ g_object_ref_sink (renderer);
+
+ info = g_new0 (GtkIconViewCellInfo, 1);
+ info->cell = renderer;
+ info->expand = expand ? TRUE : FALSE;
+ info->pack = GTK_PACK_END;
+ info->position = icon_view->priv->n_cells;
+
+ icon_view->priv->cell_list = g_list_append (icon_view->priv->cell_list, info);
+ icon_view->priv->n_cells++;
+}
+
+static void
+gtk_icon_view_cell_layout_add_attribute (GtkCellLayout *layout,
+ GtkCellRenderer *renderer,
+ const gchar *attribute,
+ gint column)
+{
+ GtkIconViewCellInfo *info;
+ GtkIconView *icon_view = GTK_ICON_VIEW (layout);
+
+ info = gtk_icon_view_get_cell_info (icon_view, renderer);
+ g_return_if_fail (info != NULL);
+
+ info->attributes = g_slist_prepend (info->attributes,
+ GINT_TO_POINTER (column));
+ info->attributes = g_slist_prepend (info->attributes,
+ g_strdup (attribute));
+}
+
+static void
+gtk_icon_view_cell_layout_clear (GtkCellLayout *layout)
+{
+ GtkIconView *icon_view = GTK_ICON_VIEW (layout);
+
+ while (icon_view->priv->cell_list)
+ {
+ GtkIconViewCellInfo *info = (GtkIconViewCellInfo *)icon_view->priv->cell_list->data;
+ free_cell_info (info);
+ icon_view->priv->cell_list = g_list_delete_link (icon_view->priv->cell_list,
+ icon_view->priv->cell_list);
+ }
+
+ icon_view->priv->n_cells = 0;
+}
+
+static void
+gtk_icon_view_cell_layout_set_cell_data_func (GtkCellLayout *layout,
+ GtkCellRenderer *cell,
+ GtkCellLayoutDataFunc func,
+ gpointer func_data,
+ GDestroyNotify destroy)
+{
+ GtkIconViewCellInfo *info;
+ GtkIconView *icon_view = GTK_ICON_VIEW (layout);
+
+ info = gtk_icon_view_get_cell_info (icon_view, cell);
+ g_return_if_fail (info != NULL);
+
+ if (info->destroy)
+ {
+ GDestroyNotify d = info->destroy;
+
+ info->destroy = NULL;
+ d (info->func_data);
+ }
+
+ info->func = func;
+ info->func_data = func_data;
+ info->destroy = destroy;
+}
+
+static void
+gtk_icon_view_cell_layout_clear_attributes (GtkCellLayout *layout,
+ GtkCellRenderer *renderer)
+{
+ GtkIconViewCellInfo *info;
+
+ info = gtk_icon_view_get_cell_info (GTK_ICON_VIEW (layout), renderer);
+ if (info != NULL)
+ free_cell_attributes (info);
+}
+
+static void
+gtk_icon_view_cell_layout_reorder (GtkCellLayout *layout,
+ GtkCellRenderer *cell,
+ gint position)
+{
+ GtkIconView *icon_view;
+ GList *link, *l;
+ GtkIconViewCellInfo *info;
+ gint i;
+
+ icon_view = GTK_ICON_VIEW (layout);
+
+ g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
+
+ info = gtk_icon_view_get_cell_info (icon_view, cell);
+
+ g_return_if_fail (info != NULL);
+ g_return_if_fail (position >= 0);
+
+ link = g_list_find (icon_view->priv->cell_list, info);
+
+ g_return_if_fail (link != NULL);
+
+ icon_view->priv->cell_list = g_list_remove_link (icon_view->priv->cell_list,
+ link);
+ icon_view->priv->cell_list = g_list_insert (icon_view->priv->cell_list,
+ info, position);
+
+ for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
+ {
+ info = l->data;
+
+ info->position = i;
}
+
+ gtk_widget_queue_draw (GTK_WIDGET (icon_view));
}
/* Public API */
* @y: The y position to be identified
*
* Finds the path at the point (@x, @y), relative to widget coordinates.
+ * See gtk_icon_view_get_item_at_pos(), if you are also interested in
+ * the cell at the specified position.
*
* Return value: The #GtkTreePath corresponding to the icon or %NULL
* if no icon exists at that position.
g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
- item = gtk_icon_view_get_item_at_pos (icon_view, x, y);
+ item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, NULL);
if (!item)
return NULL;
}
/**
- * gtk_icon_view_selected_foreach:
+ * gtk_icon_view_get_item_at_pos:
* @icon_view: A #GtkIconView.
- * @func: The funcion to call for each selected icon.
- * @data: User data to pass to the function.
+ * @x: The x position to be identified
+ * @y: The y position to be identified
+ * @path: Return location for the path, or %NULL
+ * @cell: Return location for the renderer responsible for the cell
+ * at (@x, @y), or %NULL
*
- * Calls a function for each selected icon. Note that the model or
- * selection cannot be modified from within this function.
+ * Finds the path at the point (@x, @y), relative to widget coordinates.
+ * In contrast to gtk_icon_view_get_path_at_pos(), this function also
+ * obtains the cell at the specified position. The returned path should
+ * be freed with gtk_tree_path_free().
+ *
+ * Return value: %TRUE if an item exists at the specified position
*
- * Since: 2.6
+ * Since: 2.8
**/
-void
-gtk_icon_view_selected_foreach (GtkIconView *icon_view,
- GtkIconViewForeachFunc func,
- gpointer data)
+gboolean
+gtk_icon_view_get_item_at_pos (GtkIconView *icon_view,
+ gint x,
+ gint y,
+ GtkTreePath **path,
+ GtkCellRenderer **cell)
{
- GList *list;
+ GtkIconViewItem *item;
+ GtkIconViewCellInfo *info;
- for (list = icon_view->priv->items; list; list = list->next)
- {
- GtkIconViewItem *item = list->data;
- GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
+ g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
- if (item->selected)
- (* func) (icon_view, path, data);
+ item = gtk_icon_view_get_item_at_coords (icon_view, x, y, TRUE, &info);
- gtk_tree_path_free (path);
+ if (path != NULL)
+ {
+ if (item != NULL)
+ *path = gtk_tree_path_new_from_indices (item->index, -1);
+ else
+ *path = NULL;
+ }
+
+ if (cell != NULL)
+ {
+ if (info != NULL)
+ *cell = info->cell;
+ else
+ *cell = NULL;
}
+
+ return (item != NULL);
}
+
/**
- * gtk_icon_view_set_selection_mode:
- * @icon_view: A #GtkIconView.
- * @mode: The selection mode
+ * gtk_icon_view_get_visible_range:
+ * @icon_view: A #GtkIconView
+ * @start_path: Return location for start of region, or %NULL
+ * @end_path: Return location for end of region, or %NULL
*
- * Sets the selection mode of the @icon_view.
+ * Sets @start_path and @end_path to be the first and last visible path.
+ * Note that there may be invisible paths in between.
+ *
+ * Both paths should be freed with gtk_tree_path_free() after use.
+ *
+ * Return value: %TRUE, if valid paths were placed in @start_path and @end_path
*
- * Since: 2.6
+ * Since: 2.8
**/
-void
-gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
- GtkSelectionMode mode)
+gboolean
+gtk_icon_view_get_visible_range (GtkIconView *icon_view,
+ GtkTreePath **start_path,
+ GtkTreePath **end_path)
+{
+ gint start_index = -1;
+ gint end_index = -1;
+ GList *icons;
+
+ g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
+
+ if (icon_view->priv->hadjustment == NULL ||
+ icon_view->priv->vadjustment == NULL)
+ return FALSE;
+
+ if (start_path == NULL && end_path == NULL)
+ return FALSE;
+
+ for (icons = icon_view->priv->items; icons; icons = icons->next)
+ {
+ GtkIconViewItem *item = icons->data;
+
+ if ((item->x + item->width >= (int)icon_view->priv->hadjustment->value) &&
+ (item->y + item->height >= (int)icon_view->priv->vadjustment->value) &&
+ (item->x <= (int) (icon_view->priv->hadjustment->value + icon_view->priv->hadjustment->page_size)) &&
+ (item->y <= (int) (icon_view->priv->vadjustment->value + icon_view->priv->vadjustment->page_size)))
+ {
+ if (start_index == -1)
+ start_index = item->index;
+ end_index = item->index;
+ }
+ }
+
+ if (start_path && start_index != -1)
+ *start_path = gtk_tree_path_new_from_indices (start_index, -1);
+ if (end_path && end_index != -1)
+ *end_path = gtk_tree_path_new_from_indices (end_index, -1);
+
+ return start_index != -1;
+}
+
+/**
+ * gtk_icon_view_selected_foreach:
+ * @icon_view: A #GtkIconView.
+ * @func: The funcion to call for each selected icon.
+ * @data: User data to pass to the function.
+ *
+ * Calls a function for each selected icon. Note that the model or
+ * selection cannot be modified from within this function.
+ *
+ * Since: 2.6
+ **/
+void
+gtk_icon_view_selected_foreach (GtkIconView *icon_view,
+ GtkIconViewForeachFunc func,
+ gpointer data)
+{
+ GList *list;
+
+ for (list = icon_view->priv->items; list; list = list->next)
+ {
+ GtkIconViewItem *item = list->data;
+ GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
+
+ if (item->selected)
+ (* func) (icon_view, path, data);
+
+ gtk_tree_path_free (path);
+ }
+}
+
+/**
+ * gtk_icon_view_set_selection_mode:
+ * @icon_view: A #GtkIconView.
+ * @mode: The selection mode
+ *
+ * Sets the selection mode of the @icon_view.
+ *
+ * Since: 2.6
+ **/
+void
+gtk_icon_view_set_selection_mode (GtkIconView *icon_view,
+ GtkSelectionMode mode)
{
g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
icon_view->priv->selection_mode = mode;
- g_object_notify (G_OBJECT (icon_view), "selection_mode");
+ g_object_notify (G_OBJECT (icon_view), "selection-mode");
}
/**
if (icon_view->priv->model == model)
return;
+ if (icon_view->priv->scroll_to_path)
+ {
+ gtk_tree_row_reference_free (icon_view->priv->scroll_to_path);
+ icon_view->priv->scroll_to_path = NULL;
+ }
+
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+
if (model)
{
- GType pixbuf_column_type, text_column_type;
+ GType column_type;
g_return_if_fail (gtk_tree_model_get_flags (model) & GTK_TREE_MODEL_LIST_ONLY);
if (icon_view->priv->pixbuf_column != -1)
{
- pixbuf_column_type = gtk_tree_model_get_column_type (icon_view->priv->model,
- icon_view->priv->pixbuf_column);
+ column_type = gtk_tree_model_get_column_type (model,
+ icon_view->priv->pixbuf_column);
- g_return_if_fail (pixbuf_column_type == GDK_TYPE_PIXBUF);
+ g_return_if_fail (column_type == GDK_TYPE_PIXBUF);
}
if (icon_view->priv->text_column != -1)
{
- text_column_type = gtk_tree_model_get_column_type (icon_view->priv->model,
- icon_view->priv->pixbuf_column);
+ column_type = gtk_tree_model_get_column_type (model,
+ icon_view->priv->text_column);
+
+ g_return_if_fail (column_type == G_TYPE_STRING);
+ }
+
+ if (icon_view->priv->markup_column != -1)
+ {
+ column_type = gtk_tree_model_get_column_type (model,
+ icon_view->priv->markup_column);
- g_return_if_fail (text_column_type == G_TYPE_STRING);
+ g_return_if_fail (column_type == G_TYPE_STRING);
}
}
icon_view->priv->anchor_item = NULL;
icon_view->priv->cursor_item = NULL;
icon_view->priv->last_single_clicked = NULL;
+ icon_view->priv->width = 0;
+ icon_view->priv->height = 0;
}
icon_view->priv->model = model;
icon_view);
gtk_icon_view_build_items (icon_view);
+
+ gtk_icon_view_queue_layout (icon_view);
}
g_object_notify (G_OBJECT (icon_view), "model");
+
+ if (GTK_WIDGET_REALIZED (icon_view))
+ gtk_widget_queue_resize (GTK_WIDGET (icon_view));
}
/**
return icon_view->priv->model;
}
+static void
+update_text_cell (GtkIconView *icon_view)
+{
+ GtkIconViewCellInfo *info;
+ GList *l;
+ gint i;
+
+ if (icon_view->priv->text_column == -1 &&
+ icon_view->priv->markup_column == -1)
+ {
+ if (icon_view->priv->text_cell != -1)
+ {
+ if (icon_view->priv->pixbuf_cell > icon_view->priv->text_cell)
+ icon_view->priv->pixbuf_cell--;
+
+ info = g_list_nth_data (icon_view->priv->cell_list,
+ icon_view->priv->text_cell);
+
+ icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
+
+ free_cell_info (info);
+
+ icon_view->priv->n_cells--;
+ icon_view->priv->text_cell = -1;
+ }
+ }
+ else
+ {
+ if (icon_view->priv->text_cell == -1)
+ {
+ GtkCellRenderer *cell = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
+ for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
+ {
+ info = l->data;
+ if (info->cell == cell)
+ {
+ icon_view->priv->text_cell = i;
+ break;
+ }
+ }
+ }
+
+ info = g_list_nth_data (icon_view->priv->cell_list,
+ icon_view->priv->text_cell);
+
+ if (icon_view->priv->markup_column != -1)
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
+ info->cell,
+ "markup", icon_view->priv->markup_column,
+ NULL);
+ else
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
+ info->cell,
+ "text", icon_view->priv->text_column,
+ NULL);
+
+ if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
+ g_object_set (info->cell,
+ "wrap-mode", PANGO_WRAP_CHAR,
+ "wrap-width", icon_view->priv->item_width,
+ "xalign", 0.5,
+ "yalign", 0.0,
+ NULL);
+ else
+ g_object_set (info->cell,
+ "wrap-mode", PANGO_WRAP_CHAR,
+ "wrap-width", icon_view->priv->item_width,
+ "xalign", 0.0,
+ "yalign", 0.0,
+ NULL);
+ }
+}
+
+static void
+update_pixbuf_cell (GtkIconView *icon_view)
+{
+ GtkIconViewCellInfo *info;
+ GList *l;
+ gint i;
+
+ if (icon_view->priv->pixbuf_column == -1)
+ {
+ if (icon_view->priv->pixbuf_cell != -1)
+ {
+ if (icon_view->priv->text_cell > icon_view->priv->pixbuf_cell)
+ icon_view->priv->text_cell--;
+
+ info = g_list_nth_data (icon_view->priv->cell_list,
+ icon_view->priv->pixbuf_cell);
+
+ icon_view->priv->cell_list = g_list_remove (icon_view->priv->cell_list, info);
+
+ free_cell_info (info);
+
+ icon_view->priv->n_cells--;
+ icon_view->priv->pixbuf_cell = -1;
+ }
+ }
+ else
+ {
+ if (icon_view->priv->pixbuf_cell == -1)
+ {
+ GtkCellRenderer *cell = gtk_cell_renderer_pixbuf_new ();
+
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), cell, FALSE);
+ for (l = icon_view->priv->cell_list, i = 0; l; l = l->next, i++)
+ {
+ info = l->data;
+ if (info->cell == cell)
+ {
+ icon_view->priv->pixbuf_cell = i;
+ break;
+ }
+ }
+ }
+
+ info = g_list_nth_data (icon_view->priv->cell_list,
+ icon_view->priv->pixbuf_cell);
+
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view),
+ info->cell,
+ "pixbuf", icon_view->priv->pixbuf_column,
+ NULL);
+
+ if (icon_view->priv->orientation == GTK_ORIENTATION_VERTICAL)
+ g_object_set (info->cell,
+ "follow-state", TRUE,
+ "xalign", 0.5,
+ "yalign", 1.0,
+ NULL);
+ else
+ g_object_set (info->cell,
+ "follow-state", TRUE,
+ "xalign", 0.0,
+ "yalign", 0.0,
+ NULL);
+ }
+}
+
/**
* gtk_icon_view_set_text_column:
* @icon_view: A #GtkIconView.
icon_view->priv->text_column = column;
}
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+
+ update_text_cell (icon_view);
+
gtk_icon_view_invalidate_sizes (icon_view);
gtk_icon_view_queue_layout (icon_view);
- g_object_notify (G_OBJECT (icon_view), "text_column");
+ g_object_notify (G_OBJECT (icon_view), "text-column");
}
/**
icon_view->priv->markup_column = column;
}
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+
+ update_text_cell (icon_view);
+
gtk_icon_view_invalidate_sizes (icon_view);
gtk_icon_view_queue_layout (icon_view);
- g_object_notify (G_OBJECT (icon_view), "markup_column");
+ g_object_notify (G_OBJECT (icon_view), "markup-column");
}
/**
icon_view->priv->pixbuf_column = column;
}
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+
+ update_pixbuf_cell (icon_view);
+
gtk_icon_view_invalidate_sizes (icon_view);
gtk_icon_view_queue_layout (icon_view);
- g_object_notify (G_OBJECT (icon_view), "pixbuf_column");
+ g_object_notify (G_OBJECT (icon_view), "pixbuf-column");
}
gtk_icon_view_select_path (GtkIconView *icon_view,
GtkTreePath *path)
{
- GtkIconViewItem *item;
-
+ GtkIconViewItem *item = NULL;
+
g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
g_return_if_fail (icon_view->priv->model != NULL);
g_return_if_fail (path != NULL);
- item = g_list_nth (icon_view->priv->items,
- gtk_tree_path_get_indices(path)[0])->data;
+ if (gtk_tree_path_get_depth (path) > 0)
+ item = g_list_nth_data (icon_view->priv->items,
+ gtk_tree_path_get_indices(path)[0]);
- if (!item)
- return;
-
- gtk_icon_view_select_item (icon_view, item);
+ if (item)
+ gtk_icon_view_select_item (icon_view, item);
}
/**
g_return_if_fail (icon_view->priv->model != NULL);
g_return_if_fail (path != NULL);
- item = g_list_nth (icon_view->priv->items,
- gtk_tree_path_get_indices(path)[0])->data;
+ item = g_list_nth_data (icon_view->priv->items,
+ gtk_tree_path_get_indices(path)[0]);
if (!item)
return;
* gtk_icon_view_get_selected_items:
* @icon_view: A #GtkIconView.
*
- * Creates a list of path of all selected items. Additionally, if you are
+ * Creates a list of paths of all selected items. Additionally, if you are
* planning on modifying the model after calling this function, you may
* want to convert the returned list into a list of #GtkTreeRowReference<!-- -->s.
* To do this, you can use gtk_tree_row_reference_new().
{
GtkTreePath *path = gtk_tree_path_new_from_indices (item->index, -1);
- selected = g_list_prepend (selected, path);
- }
+ selected = g_list_prepend (selected, path);
+ }
+ }
+
+ return selected;
+}
+
+/**
+ * gtk_icon_view_select_all:
+ * @icon_view: A #GtkIconView.
+ *
+ * Selects all the icons. @icon_view must has its selection mode set
+ * to #GTK_SELECTION_MULTIPLE.
+ *
+ * Since: 2.6
+ **/
+void
+gtk_icon_view_select_all (GtkIconView *icon_view)
+{
+ GList *items;
+ gboolean dirty = FALSE;
+
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+
+ if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
+ return;
+
+ for (items = icon_view->priv->items; items; items = items->next)
+ {
+ GtkIconViewItem *item = items->data;
+
+ if (!item->selected)
+ {
+ dirty = TRUE;
+ item->selected = TRUE;
+ gtk_icon_view_queue_draw_item (icon_view, item);
+ }
+ }
+
+ if (dirty)
+ g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
+}
+
+/**
+ * gtk_icon_view_unselect_all:
+ * @icon_view: A #GtkIconView.
+ *
+ * Unselects all the icons.
+ *
+ * Since: 2.6
+ **/
+void
+gtk_icon_view_unselect_all (GtkIconView *icon_view)
+{
+ gboolean dirty = FALSE;
+
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+
+ if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
+ return;
+
+ dirty = gtk_icon_view_unselect_all_internal (icon_view);
+
+ if (dirty)
+ g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
+}
+
+/**
+ * gtk_icon_view_path_is_selected:
+ * @icon_view: A #GtkIconView.
+ * @path: A #GtkTreePath to check selection on.
+ *
+ * Returns %TRUE if the icon pointed to by @path is currently
+ * selected. If @path does not point to a valid location, %FALSE is returned.
+ *
+ * Return value: %TRUE if @path is selected.
+ *
+ * Since: 2.6
+ **/
+gboolean
+gtk_icon_view_path_is_selected (GtkIconView *icon_view,
+ GtkTreePath *path)
+{
+ GtkIconViewItem *item;
+
+ g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
+ g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
+ g_return_val_if_fail (path != NULL, FALSE);
+
+ item = g_list_nth_data (icon_view->priv->items,
+ gtk_tree_path_get_indices(path)[0]);
+
+ if (!item)
+ return FALSE;
+
+ return item->selected;
+}
+
+/**
+ * gtk_icon_view_item_activated:
+ * @icon_view: A #GtkIconView
+ * @path: The #GtkTreePath to be activated
+ *
+ * Activates the item determined by @path.
+ *
+ * Since: 2.6
+ **/
+void
+gtk_icon_view_item_activated (GtkIconView *icon_view,
+ GtkTreePath *path)
+{
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+ g_return_if_fail (path != NULL);
+
+ g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
+}
+
+/**
+ * gtk_icon_view_set_orientation:
+ * @icon_view: a #GtkIconView
+ * @orientation: the relative position of texts and icons
+ *
+ * Sets the ::orientation property which determines whether the labels
+ * are drawn beside the icons instead of below.
+ *
+ * Since: 2.6
+ **/
+void
+gtk_icon_view_set_orientation (GtkIconView *icon_view,
+ GtkOrientation orientation)
+{
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+
+ if (icon_view->priv->orientation != orientation)
+ {
+ icon_view->priv->orientation = orientation;
+
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+ gtk_icon_view_invalidate_sizes (icon_view);
+ gtk_icon_view_queue_layout (icon_view);
+
+ update_text_cell (icon_view);
+ update_pixbuf_cell (icon_view);
+
+ g_object_notify (G_OBJECT (icon_view), "orientation");
+ }
+}
+
+/**
+ * gtk_icon_view_get_orientation:
+ * @icon_view: a #GtkIconView
+ *
+ * Returns the value of the ::orientation property which determines
+ * whether the labels are drawn beside the icons instead of below.
+ *
+ * Return value: the relative position of texts and icons
+ *
+ * Since: 2.6
+ **/
+GtkOrientation
+gtk_icon_view_get_orientation (GtkIconView *icon_view)
+{
+ g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
+ GTK_ORIENTATION_VERTICAL);
+
+ return icon_view->priv->orientation;
+}
+
+/**
+ * gtk_icon_view_set_columns:
+ * @icon_view: a #GtkIconView
+ * @columns: the number of columns
+ *
+ * Sets the ::columns property which determines in how
+ * many columns the icons are arranged. If @columns is
+ * -1, the number of columns will be chosen automatically
+ * to fill the available area.
+ *
+ * Since: 2.6
+ */
+void
+gtk_icon_view_set_columns (GtkIconView *icon_view,
+ gint columns)
+{
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+
+ if (icon_view->priv->columns != columns)
+ {
+ icon_view->priv->columns = columns;
+
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+ gtk_icon_view_queue_layout (icon_view);
+
+ g_object_notify (G_OBJECT (icon_view), "columns");
+ }
+}
+
+/**
+ * gtk_icon_view_get_columns:
+ * @icon_view: a #GtkIconView
+ *
+ * Returns the value of the ::columns property.
+ *
+ * Return value: the number of columns, or -1
+ *
+ * Since: 2.6
+ */
+gint
+gtk_icon_view_get_columns (GtkIconView *icon_view)
+{
+ g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
+
+ return icon_view->priv->columns;
+}
+
+/**
+ * gtk_icon_view_set_item_width:
+ * @icon_view: a #GtkIconView
+ * @item_width: the width for each item
+ *
+ * Sets the ::item-width property which specifies the width
+ * to use for each item. If it is set to -1, the icon view will
+ * automatically determine a suitable item size.
+ *
+ * Since: 2.6
+ */
+void
+gtk_icon_view_set_item_width (GtkIconView *icon_view,
+ gint item_width)
+{
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+
+ if (icon_view->priv->item_width != item_width)
+ {
+ icon_view->priv->item_width = item_width;
+
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+ gtk_icon_view_invalidate_sizes (icon_view);
+ gtk_icon_view_queue_layout (icon_view);
+
+ update_text_cell (icon_view);
+
+ g_object_notify (G_OBJECT (icon_view), "item-width");
+ }
+}
+
+/**
+ * gtk_icon_view_get_item_width:
+ * @icon_view: a #GtkIconView
+ *
+ * Returns the value of the ::item-width property.
+ *
+ * Return value: the width of a single item, or -1
+ *
+ * Since: 2.6
+ */
+gint
+gtk_icon_view_get_item_width (GtkIconView *icon_view)
+{
+ g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
+
+ return icon_view->priv->item_width;
+}
+
+
+/**
+ * gtk_icon_view_set_spacing:
+ * @icon_view: a #GtkIconView
+ * @spacing: the spacing
+ *
+ * Sets the ::spacing property which specifies the space
+ * which is inserted between the cells (i.e. the icon and
+ * the text) of an item.
+ *
+ * Since: 2.6
+ */
+void
+gtk_icon_view_set_spacing (GtkIconView *icon_view,
+ gint spacing)
+{
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+
+ if (icon_view->priv->spacing != spacing)
+ {
+ icon_view->priv->spacing = spacing;
+
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+ gtk_icon_view_invalidate_sizes (icon_view);
+ gtk_icon_view_queue_layout (icon_view);
+
+ g_object_notify (G_OBJECT (icon_view), "spacing");
+ }
+}
+
+/**
+ * gtk_icon_view_get_spacing:
+ * @icon_view: a #GtkIconView
+ *
+ * Returns the value of the ::spacing property.
+ *
+ * Return value: the space between cells
+ *
+ * Since: 2.6
+ */
+gint
+gtk_icon_view_get_spacing (GtkIconView *icon_view)
+{
+ g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
+
+ return icon_view->priv->spacing;
+}
+
+/**
+ * gtk_icon_view_set_row_spacing:
+ * @icon_view: a #GtkIconView
+ * @row_spacing: the row spacing
+ *
+ * Sets the ::row-spacing property which specifies the space
+ * which is inserted between the rows of the icon view.
+ *
+ * Since: 2.6
+ */
+void
+gtk_icon_view_set_row_spacing (GtkIconView *icon_view,
+ gint row_spacing)
+{
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+
+ if (icon_view->priv->row_spacing != row_spacing)
+ {
+ icon_view->priv->row_spacing = row_spacing;
+
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+ gtk_icon_view_invalidate_sizes (icon_view);
+ gtk_icon_view_queue_layout (icon_view);
+
+ g_object_notify (G_OBJECT (icon_view), "row-spacing");
+ }
+}
+
+/**
+ * gtk_icon_view_get_row_spacing:
+ * @icon_view: a #GtkIconView
+ *
+ * Returns the value of the ::row-spacing property.
+ *
+ * Return value: the space between rows
+ *
+ * Since: 2.6
+ */
+gint
+gtk_icon_view_get_row_spacing (GtkIconView *icon_view)
+{
+ g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
+
+ return icon_view->priv->row_spacing;
+}
+
+/**
+ * gtk_icon_view_set_column_spacing:
+ * @icon_view: a #GtkIconView
+ * @column_spacing: the column spacing
+ *
+ * Sets the ::column-spacing property which specifies the space
+ * which is inserted between the columns of the icon view.
+ *
+ * Since: 2.6
+ */
+void
+gtk_icon_view_set_column_spacing (GtkIconView *icon_view,
+ gint column_spacing)
+{
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+
+ if (icon_view->priv->column_spacing != column_spacing)
+ {
+ icon_view->priv->column_spacing = column_spacing;
+
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+ gtk_icon_view_invalidate_sizes (icon_view);
+ gtk_icon_view_queue_layout (icon_view);
+
+ g_object_notify (G_OBJECT (icon_view), "column-spacing");
+ }
+}
+
+/**
+ * gtk_icon_view_get_column_spacing:
+ * @icon_view: a #GtkIconView
+ *
+ * Returns the value of the ::column-spacing property.
+ *
+ * Return value: the space between columns
+ *
+ * Since: 2.6
+ */
+gint
+gtk_icon_view_get_column_spacing (GtkIconView *icon_view)
+{
+ g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
+
+ return icon_view->priv->column_spacing;
+}
+
+/**
+ * gtk_icon_view_set_margin:
+ * @icon_view: a #GtkIconView
+ * @margin: the margin
+ *
+ * Sets the ::margin property which specifies the space
+ * which is inserted at the top, bottom, left and right
+ * of the icon view.
+ *
+ * Since: 2.6
+ */
+void
+gtk_icon_view_set_margin (GtkIconView *icon_view,
+ gint margin)
+{
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+
+ if (icon_view->priv->margin != margin)
+ {
+ icon_view->priv->margin = margin;
+
+ gtk_icon_view_stop_editing (icon_view, TRUE);
+ gtk_icon_view_invalidate_sizes (icon_view);
+ gtk_icon_view_queue_layout (icon_view);
+
+ g_object_notify (G_OBJECT (icon_view), "margin");
+ }
+}
+
+/**
+ * gtk_icon_view_get_margin:
+ * @icon_view: a #GtkIconView
+ *
+ * Returns the value of the ::margin property.
+ *
+ * Return value: the space at the borders
+ *
+ * Since: 2.6
+ */
+gint
+gtk_icon_view_get_margin (GtkIconView *icon_view)
+{
+ g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), -1);
+
+ return icon_view->priv->margin;
+}
+
+
+/* Get/set whether drag_motion requested the drag data and
+ * drag_data_received should thus not actually insert the data,
+ * since the data doesn't result from a drop.
+ */
+static void
+set_status_pending (GdkDragContext *context,
+ GdkDragAction suggested_action)
+{
+ g_object_set_data (G_OBJECT (context),
+ I_("gtk-icon-view-status-pending"),
+ GINT_TO_POINTER (suggested_action));
+}
+
+static GdkDragAction
+get_status_pending (GdkDragContext *context)
+{
+ return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
+ "gtk-icon-view-status-pending"));
+}
+
+static void
+unset_reorderable (GtkIconView *icon_view)
+{
+ if (icon_view->priv->reorderable)
+ {
+ icon_view->priv->reorderable = FALSE;
+ g_object_notify (G_OBJECT (icon_view), "reorderable");
+ }
+}
+
+static void
+clear_source_info (GtkIconView *icon_view)
+{
+ if (icon_view->priv->source_targets)
+ gtk_target_list_unref (icon_view->priv->source_targets);
+ icon_view->priv->source_targets = NULL;
+
+ icon_view->priv->source_set = FALSE;
+}
+
+static void
+clear_dest_info (GtkIconView *icon_view)
+{
+ if (icon_view->priv->dest_targets)
+ gtk_target_list_unref (icon_view->priv->dest_targets);
+ icon_view->priv->dest_targets = NULL;
+
+ icon_view->priv->dest_set = FALSE;
+}
+
+static void
+set_source_row (GdkDragContext *context,
+ GtkTreeModel *model,
+ GtkTreePath *source_row)
+{
+ if (source_row)
+ g_object_set_data_full (G_OBJECT (context),
+ I_("gtk-icon-view-source-row"),
+ gtk_tree_row_reference_new (model, source_row),
+ (GDestroyNotify) gtk_tree_row_reference_free);
+ else
+ g_object_set_data_full (G_OBJECT (context),
+ I_("gtk-icon-view-source-row"),
+ NULL, NULL);
+}
+
+static GtkTreePath*
+get_source_row (GdkDragContext *context)
+{
+ GtkTreeRowReference *ref;
+
+ ref = g_object_get_data (G_OBJECT (context), "gtk-icon-view-source-row");
+
+ if (ref)
+ return gtk_tree_row_reference_get_path (ref);
+ else
+ return NULL;
+}
+
+typedef struct
+{
+ GtkTreeRowReference *dest_row;
+ gboolean empty_view_drop;
+ gboolean drop_append_mode;
+} DestRow;
+
+static void
+dest_row_free (gpointer data)
+{
+ DestRow *dr = (DestRow *)data;
+
+ gtk_tree_row_reference_free (dr->dest_row);
+ g_free (dr);
+}
+
+static void
+set_dest_row (GdkDragContext *context,
+ GtkTreeModel *model,
+ GtkTreePath *dest_row,
+ gboolean empty_view_drop,
+ gboolean drop_append_mode)
+{
+ DestRow *dr;
+
+ if (!dest_row)
+ {
+ g_object_set_data_full (G_OBJECT (context),
+ I_("gtk-icon-view-dest-row"),
+ NULL, NULL);
+ return;
+ }
+
+ dr = g_new0 (DestRow, 1);
+
+ dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
+ dr->empty_view_drop = empty_view_drop;
+ dr->drop_append_mode = drop_append_mode;
+ g_object_set_data_full (G_OBJECT (context),
+ I_("gtk-icon-view-dest-row"),
+ dr, (GDestroyNotify) dest_row_free);
+}
+
+static GtkTreePath*
+get_dest_row (GdkDragContext *context)
+{
+ DestRow *dr;
+
+ dr = g_object_get_data (G_OBJECT (context), "gtk-icon-view-dest-row");
+
+ if (dr)
+ {
+ GtkTreePath *path = NULL;
+
+ if (dr->dest_row)
+ path = gtk_tree_row_reference_get_path (dr->dest_row);
+ else if (dr->empty_view_drop)
+ path = gtk_tree_path_new_from_indices (0, -1);
+ else
+ path = NULL;
+
+ if (path && dr->drop_append_mode)
+ gtk_tree_path_next (path);
+
+ return path;
+ }
+ else
+ return NULL;
+}
+
+static gboolean
+check_model_dnd (GtkTreeModel *model,
+ GType required_iface,
+ const gchar *signal)
+{
+ if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
+ {
+ g_warning ("You must override the default '%s' handler "
+ "on GtkIconView when using models that don't support "
+ "the %s interface and enabling drag-and-drop. The simplest way to do this "
+ "is to connect to '%s' and call "
+ "g_signal_stop_emission_by_name() in your signal handler to prevent "
+ "the default handler from running. Look at the source code "
+ "for the default handler in gtkiconview.c to get an idea what "
+ "your handler should do. (gtkiconview.c is in the GTK+ source "
+ "code.) If you're using GTK+ from a language other than C, "
+ "there may be a more natural way to override default handlers, e.g. via derivation.",
+ signal, g_type_name (required_iface), signal);
+ return FALSE;
+ }
+ else
+ return TRUE;
+}
+
+static void
+remove_scroll_timeout (GtkIconView *icon_view)
+{
+ if (icon_view->priv->scroll_timeout_id != 0)
+ {
+ g_source_remove (icon_view->priv->scroll_timeout_id);
+
+ icon_view->priv->scroll_timeout_id = 0;
+ }
+}
+
+static void
+gtk_icon_view_autoscroll (GtkIconView *icon_view)
+{
+ gint px, py, x, y, width, height;
+ gint hoffset, voffset;
+ gfloat value;
+
+ gdk_window_get_pointer (GTK_WIDGET (icon_view)->window, &px, &py, NULL);
+ gdk_window_get_geometry (GTK_WIDGET (icon_view)->window, &x, &y, &width, &height, NULL);
+
+ /* see if we are near the edge. */
+ voffset = py - (y + 2 * SCROLL_EDGE_SIZE);
+ if (voffset > 0)
+ voffset = MAX (py - (y + height - 2 * SCROLL_EDGE_SIZE), 0);
+
+ hoffset = px - (x + 2 * SCROLL_EDGE_SIZE);
+ if (hoffset > 0)
+ hoffset = MAX (px - (x + width - 2 * SCROLL_EDGE_SIZE), 0);
+
+ if (voffset != 0)
+ {
+ value = CLAMP (icon_view->priv->vadjustment->value + voffset,
+ icon_view->priv->vadjustment->lower,
+ icon_view->priv->vadjustment->upper - icon_view->priv->vadjustment->page_size);
+ gtk_adjustment_set_value (icon_view->priv->vadjustment, value);
+ }
+ if (hoffset != 0)
+ {
+ value = CLAMP (icon_view->priv->hadjustment->value + hoffset,
+ icon_view->priv->hadjustment->lower,
+ icon_view->priv->hadjustment->upper - icon_view->priv->hadjustment->page_size);
+ gtk_adjustment_set_value (icon_view->priv->hadjustment, value);
+ }
+}
+
+
+static gboolean
+drag_scroll_timeout (gpointer data)
+{
+ GtkIconView *icon_view = GTK_ICON_VIEW (data);
+
+ gtk_icon_view_autoscroll (icon_view);
+
+ return TRUE;
+}
+
+
+static gboolean
+set_destination (GtkIconView *icon_view,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GdkDragAction *suggested_action,
+ GdkAtom *target)
+{
+ GtkWidget *widget;
+ GtkTreePath *path = NULL;
+ GtkIconViewDropPosition pos;
+ GtkIconViewDropPosition old_pos;
+ GtkTreePath *old_dest_path = NULL;
+ gboolean can_drop = FALSE;
+
+ widget = GTK_WIDGET (icon_view);
+
+ *suggested_action = 0;
+ *target = GDK_NONE;
+
+ if (!icon_view->priv->dest_set)
+ {
+ /* someone unset us as a drag dest, note that if
+ * we return FALSE drag_leave isn't called
+ */
+
+ gtk_icon_view_set_drag_dest_item (icon_view,
+ NULL,
+ GTK_ICON_VIEW_DROP_LEFT);
+
+ remove_scroll_timeout (GTK_ICON_VIEW (widget));
+
+ return FALSE; /* no longer a drop site */
+ }
+
+ *target = gtk_drag_dest_find_target (widget, context, icon_view->priv->dest_targets);
+ if (*target == GDK_NONE)
+ return FALSE;
+
+ if (!gtk_icon_view_get_dest_item_at_pos (icon_view, x, y, &path, &pos))
+ {
+ gint n_children;
+ GtkTreeModel *model;
+
+ /* the row got dropped on empty space, let's setup a special case
+ */
+
+ if (path)
+ gtk_tree_path_free (path);
+
+ model = gtk_icon_view_get_model (icon_view);
+
+ n_children = gtk_tree_model_iter_n_children (model, NULL);
+ if (n_children)
+ {
+ pos = GTK_ICON_VIEW_DROP_BELOW;
+ path = gtk_tree_path_new_from_indices (n_children - 1, -1);
+ }
+ else
+ {
+ pos = GTK_ICON_VIEW_DROP_ABOVE;
+ path = gtk_tree_path_new_from_indices (0, -1);
+ }
+
+ can_drop = TRUE;
+
+ goto out;
+ }
+
+ g_assert (path);
+
+ gtk_icon_view_get_drag_dest_item (icon_view,
+ &old_dest_path,
+ &old_pos);
+
+ if (old_dest_path)
+ gtk_tree_path_free (old_dest_path);
+
+ if (TRUE /* FIXME if the location droppable predicate */)
+ {
+ can_drop = TRUE;
+ }
+
+out:
+ if (can_drop)
+ {
+ GtkWidget *source_widget;
+
+ *suggested_action = context->suggested_action;
+ source_widget = gtk_drag_get_source_widget (context);
+
+ if (source_widget == widget)
+ {
+ /* Default to MOVE, unless the user has
+ * pressed ctrl or shift to affect available actions
+ */
+ if ((context->actions & GDK_ACTION_MOVE) != 0)
+ *suggested_action = GDK_ACTION_MOVE;
+ }
+
+ gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
+ path, pos);
+ }
+ else
+ {
+ /* can't drop here */
+ gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
+ NULL,
+ GTK_ICON_VIEW_DROP_LEFT);
+ }
+
+ if (path)
+ gtk_tree_path_free (path);
+
+ return TRUE;
+}
+
+static GtkTreePath*
+get_logical_destination (GtkIconView *icon_view,
+ gboolean *drop_append_mode)
+{
+ /* adjust path to point to the row the drop goes in front of */
+ GtkTreePath *path = NULL;
+ GtkIconViewDropPosition pos;
+
+ *drop_append_mode = FALSE;
+
+ gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
+
+ if (path == NULL)
+ return NULL;
+
+ if (pos == GTK_ICON_VIEW_DROP_RIGHT ||
+ pos == GTK_ICON_VIEW_DROP_BELOW)
+ {
+ GtkTreeIter iter;
+ GtkTreeModel *model = icon_view->priv->model;
+
+ if (!gtk_tree_model_get_iter (model, &iter, path) ||
+ !gtk_tree_model_iter_next (model, &iter))
+ *drop_append_mode = TRUE;
+ else
+ {
+ *drop_append_mode = FALSE;
+ gtk_tree_path_next (path);
+ }
+ }
+
+ return path;
+}
+
+static gboolean
+gtk_icon_view_maybe_begin_drag (GtkIconView *icon_view,
+ GdkEventMotion *event)
+{
+ GdkDragContext *context;
+ GtkTreePath *path = NULL;
+ gint button;
+ GtkTreeModel *model;
+ gboolean retval = FALSE;
+
+ if (!icon_view->priv->source_set)
+ goto out;
+
+ if (icon_view->priv->pressed_button < 0)
+ goto out;
+
+ if (!gtk_drag_check_threshold (GTK_WIDGET (icon_view),
+ icon_view->priv->press_start_x,
+ icon_view->priv->press_start_y,
+ event->x, event->y))
+ goto out;
+
+ model = gtk_icon_view_get_model (icon_view);
+
+ if (model == NULL)
+ goto out;
+
+ button = icon_view->priv->pressed_button;
+ icon_view->priv->pressed_button = -1;
+
+ path = gtk_icon_view_get_path_at_pos (icon_view,
+ icon_view->priv->press_start_x,
+ icon_view->priv->press_start_y);
+
+ if (path == NULL)
+ goto out;
+
+ if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
+ !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
+ path))
+ goto out;
+
+ /* FIXME Check whether we're a start button, if not return FALSE and
+ * free path
+ */
+
+ /* Now we can begin the drag */
+
+ retval = TRUE;
+
+ context = gtk_drag_begin (GTK_WIDGET (icon_view),
+ icon_view->priv->source_targets,
+ icon_view->priv->source_actions,
+ button,
+ (GdkEvent*)event);
+
+ set_source_row (context, model, path);
+
+ out:
+ if (path)
+ gtk_tree_path_free (path);
+
+ return retval;
+}
+
+/* Source side drag signals */
+static void
+gtk_icon_view_drag_begin (GtkWidget *widget,
+ GdkDragContext *context)
+{
+ GtkIconView *icon_view;
+ GtkIconViewItem *item;
+ GdkPixmap *icon;
+ gint x, y;
+ GtkTreePath *path;
+
+ icon_view = GTK_ICON_VIEW (widget);
+
+ /* if the user uses a custom DnD impl, we don't set the icon here */
+ if (!icon_view->priv->dest_set && !icon_view->priv->source_set)
+ return;
+
+ item = gtk_icon_view_get_item_at_coords (icon_view,
+ icon_view->priv->press_start_x,
+ icon_view->priv->press_start_y,
+ TRUE,
+ NULL);
+
+ g_return_if_fail (item != NULL);
+
+ x = icon_view->priv->press_start_x - item->x + 1;
+ y = icon_view->priv->press_start_y - item->y + 1;
+
+ path = gtk_tree_path_new_from_indices (item->index, -1);
+ icon = gtk_icon_view_create_drag_icon (icon_view, path);
+ gtk_tree_path_free (path);
+
+ gtk_drag_set_icon_pixmap (context,
+ gdk_drawable_get_colormap (icon),
+ icon,
+ NULL,
+ x, y);
+
+ g_object_unref (icon);
+}
+
+static void
+gtk_icon_view_drag_end (GtkWidget *widget,
+ GdkDragContext *context)
+{
+ /* do nothing */
+}
+
+static void
+gtk_icon_view_drag_data_get (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time)
+{
+ GtkIconView *icon_view;
+ GtkTreeModel *model;
+ GtkTreePath *source_row;
+
+ icon_view = GTK_ICON_VIEW (widget);
+ model = gtk_icon_view_get_model (icon_view);
+
+ if (model == NULL)
+ return;
+
+ if (!icon_view->priv->dest_set)
+ return;
+
+ source_row = get_source_row (context);
+
+ if (source_row == NULL)
+ return;
+
+ /* We can implement the GTK_TREE_MODEL_ROW target generically for
+ * any model; for DragSource models there are some other targets
+ * we also support.
+ */
+
+ if (GTK_IS_TREE_DRAG_SOURCE (model) &&
+ gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
+ source_row,
+ selection_data))
+ goto done;
+
+ /* If drag_data_get does nothing, try providing row data. */
+ if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
+ gtk_tree_set_row_drag_data (selection_data,
+ model,
+ source_row);
+
+ done:
+ gtk_tree_path_free (source_row);
+}
+
+static void
+gtk_icon_view_drag_data_delete (GtkWidget *widget,
+ GdkDragContext *context)
+{
+ GtkTreeModel *model;
+ GtkIconView *icon_view;
+ GtkTreePath *source_row;
+
+ icon_view = GTK_ICON_VIEW (widget);
+ model = gtk_icon_view_get_model (icon_view);
+
+ if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
+ return;
+
+ if (!icon_view->priv->dest_set)
+ return;
+
+ source_row = get_source_row (context);
+
+ if (source_row == NULL)
+ return;
+
+ gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
+ source_row);
+
+ gtk_tree_path_free (source_row);
+
+ set_source_row (context, NULL, NULL);
+}
+
+/* Target side drag signals */
+static void
+gtk_icon_view_drag_leave (GtkWidget *widget,
+ GdkDragContext *context,
+ guint time)
+{
+ GtkIconView *icon_view;
+
+ icon_view = GTK_ICON_VIEW (widget);
+
+ /* unset any highlight row */
+ gtk_icon_view_set_drag_dest_item (icon_view,
+ NULL,
+ GTK_ICON_VIEW_DROP_LEFT);
+
+ remove_scroll_timeout (icon_view);
+}
+
+static gboolean
+gtk_icon_view_drag_motion (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time)
+{
+ GtkTreePath *path = NULL;
+ GtkIconViewDropPosition pos;
+ GtkIconView *icon_view;
+ GdkDragAction suggested_action = 0;
+ GdkAtom target;
+ gboolean empty;
+
+ icon_view = GTK_ICON_VIEW (widget);
+
+ if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
+ return FALSE;
+
+ gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
+
+ /* we only know this *after* set_desination_row */
+ empty = icon_view->priv->empty_view_drop;
+
+ if (path == NULL && !empty)
+ {
+ /* Can't drop here. */
+ gdk_drag_status (context, 0, time);
+ }
+ else
+ {
+ if (icon_view->priv->scroll_timeout_id == 0)
+ {
+ icon_view->priv->scroll_timeout_id =
+ gdk_threads_add_timeout (50, drag_scroll_timeout, icon_view);
+ }
+
+ if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
+ {
+ /* Request data so we can use the source row when
+ * determining whether to accept the drop
+ */
+ set_status_pending (context, suggested_action);
+ gtk_drag_get_data (widget, context, target, time);
+ }
+ else
+ {
+ set_status_pending (context, 0);
+ gdk_drag_status (context, suggested_action, time);
+ }
+ }
+
+ if (path)
+ gtk_tree_path_free (path);
+
+ return TRUE;
+}
+
+static gboolean
+gtk_icon_view_drag_drop (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time)
+{
+ GtkIconView *icon_view;
+ GtkTreePath *path;
+ GdkDragAction suggested_action = 0;
+ GdkAtom target = GDK_NONE;
+ GtkTreeModel *model;
+ gboolean drop_append_mode;
+
+ icon_view = GTK_ICON_VIEW (widget);
+ model = gtk_icon_view_get_model (icon_view);
+
+ remove_scroll_timeout (GTK_ICON_VIEW (widget));
+
+ if (!icon_view->priv->dest_set)
+ return FALSE;
+
+ if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
+ return FALSE;
+
+ if (!set_destination (icon_view, context, x, y, &suggested_action, &target))
+ return FALSE;
+
+ path = get_logical_destination (icon_view, &drop_append_mode);
+
+ if (target != GDK_NONE && path != NULL)
+ {
+ /* in case a motion had requested drag data, change things so we
+ * treat drag data receives as a drop.
+ */
+ set_status_pending (context, 0);
+ set_dest_row (context, model, path,
+ icon_view->priv->empty_view_drop, drop_append_mode);
+ }
+
+ if (path)
+ gtk_tree_path_free (path);
+
+ /* Unset this thing */
+ gtk_icon_view_set_drag_dest_item (icon_view, NULL, GTK_ICON_VIEW_DROP_LEFT);
+
+ if (target != GDK_NONE)
+ {
+ gtk_drag_get_data (widget, context, target, time);
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
+static void
+gtk_icon_view_drag_data_received (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time)
+{
+ GtkTreePath *path;
+ gboolean accepted = FALSE;
+ GtkTreeModel *model;
+ GtkIconView *icon_view;
+ GtkTreePath *dest_row;
+ GdkDragAction suggested_action;
+ gboolean drop_append_mode;
+
+ icon_view = GTK_ICON_VIEW (widget);
+ model = gtk_icon_view_get_model (icon_view);
+
+ if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
+ return;
+
+ if (!icon_view->priv->dest_set)
+ return;
+
+ suggested_action = get_status_pending (context);
+
+ if (suggested_action)
+ {
+ /* We are getting this data due to a request in drag_motion,
+ * rather than due to a request in drag_drop, so we are just
+ * supposed to call drag_status, not actually paste in the
+ * data.
+ */
+ path = get_logical_destination (icon_view, &drop_append_mode);
+
+ if (path == NULL)
+ suggested_action = 0;
+
+ if (suggested_action)
+ {
+ if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
+ path,
+ selection_data))
+ suggested_action = 0;
+ }
+
+ gdk_drag_status (context, suggested_action, time);
+
+ if (path)
+ gtk_tree_path_free (path);
+
+ /* If you can't drop, remove user drop indicator until the next motion */
+ if (suggested_action == 0)
+ gtk_icon_view_set_drag_dest_item (icon_view,
+ NULL,
+ GTK_ICON_VIEW_DROP_LEFT);
+ return;
+ }
+
+
+ dest_row = get_dest_row (context);
+
+ if (dest_row == NULL)
+ return;
+
+ if (selection_data->length >= 0)
+ {
+ if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
+ dest_row,
+ selection_data))
+ accepted = TRUE;
+ }
+
+ gtk_drag_finish (context,
+ accepted,
+ (context->action == GDK_ACTION_MOVE),
+ time);
+
+ gtk_tree_path_free (dest_row);
+
+ /* drop dest_row */
+ set_dest_row (context, NULL, NULL, FALSE, FALSE);
+}
+
+/* Drag-and-Drop support */
+/**
+ * gtk_icon_view_enable_model_drag_source:
+ * @icon_view: a #GtkIconTreeView
+ * @start_button_mask: Mask of allowed buttons to start drag
+ * @targets: the table of targets that the drag will support
+ * @n_targets: the number of items in @targets
+ * @actions: the bitmask of possible actions for a drag from this
+ * widget
+ *
+ * Turns @icon_view into a drag source for automatic DND.
+ *
+ * Since: 2.8
+ **/
+void
+gtk_icon_view_enable_model_drag_source (GtkIconView *icon_view,
+ GdkModifierType start_button_mask,
+ const GtkTargetEntry *targets,
+ gint n_targets,
+ GdkDragAction actions)
+{
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+
+ gtk_drag_source_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
+
+ clear_source_info (icon_view);
+ icon_view->priv->start_button_mask = start_button_mask;
+ icon_view->priv->source_targets = gtk_target_list_new (targets, n_targets);
+ icon_view->priv->source_actions = actions;
+
+ icon_view->priv->source_set = TRUE;
+
+ unset_reorderable (icon_view);
+}
+
+/**
+ * gtk_icon_view_enable_model_drag_dest:
+ * @icon_view: a #GtkIconView
+ * @targets: the table of targets that the drag will support
+ * @n_targets: the number of items in @targets
+ * @actions: the bitmask of possible actions for a drag to this
+ * widget
+ *
+ * Turns @icon_view into a drop destination for automatic DND.
+ *
+ * Since: 2.8
+ **/
+void
+gtk_icon_view_enable_model_drag_dest (GtkIconView *icon_view,
+ const GtkTargetEntry *targets,
+ gint n_targets,
+ GdkDragAction actions)
+{
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+
+ gtk_drag_dest_set (GTK_WIDGET (icon_view), 0, NULL, 0, actions);
+
+ clear_dest_info (icon_view);
+
+ icon_view->priv->dest_targets = gtk_target_list_new (targets, n_targets);
+ icon_view->priv->dest_actions = actions;
+
+ icon_view->priv->dest_set = TRUE;
+
+ unset_reorderable (icon_view);
+}
+
+/**
+ * gtk_icon_view_unset_model_drag_source:
+ * @icon_view: a #GtkIconView
+ *
+ * Undoes the effect of gtk_icon_view_enable_model_drag_source().
+ *
+ * Since: 2.8
+ **/
+void
+gtk_icon_view_unset_model_drag_source (GtkIconView *icon_view)
+{
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+
+ if (icon_view->priv->source_set)
+ {
+ gtk_drag_source_unset (GTK_WIDGET (icon_view));
+ clear_source_info (icon_view);
+ }
+
+ unset_reorderable (icon_view);
+}
+
+/**
+ * gtk_icon_view_unset_model_drag_dest:
+ * @icon_view: a #GtkIconView
+ *
+ * Undoes the effect of gtk_icon_view_enable_model_drag_dest().
+ *
+ * Since: 2.8
+ **/
+void
+gtk_icon_view_unset_model_drag_dest (GtkIconView *icon_view)
+{
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+
+ if (icon_view->priv->dest_set)
+ {
+ gtk_drag_dest_unset (GTK_WIDGET (icon_view));
+ clear_dest_info (icon_view);
}
- return selected;
+ unset_reorderable (icon_view);
}
+/* These are useful to implement your own custom stuff. */
/**
- * gtk_icon_view_select_all:
- * @icon_view: A #GtkIconView.
+ * gtk_icon_view_set_drag_dest_item:
+ * @icon_view: a #GtkIconView
+ * @path: The path of the item to highlight, or %NULL.
+ * @pos: Specifies where to drop, relative to the item
*
- * Selects all the icons. @icon_view must has its selection mode set
- * to #GTK_SELECTION_MULTIPLE.
+ * Sets the item that is highlighted for feedback.
*
- * Since: 2.6
- **/
+ * Since: 2.8
+ */
void
-gtk_icon_view_select_all (GtkIconView *icon_view)
+gtk_icon_view_set_drag_dest_item (GtkIconView *icon_view,
+ GtkTreePath *path,
+ GtkIconViewDropPosition pos)
{
- GList *items;
- gboolean dirty = FALSE;
-
+ /* Note; this function is exported to allow a custom DND
+ * implementation, so it can't touch TreeViewDragInfo
+ */
+
g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
- if (icon_view->priv->selection_mode != GTK_SELECTION_MULTIPLE)
- return;
+ if (icon_view->priv->dest_item)
+ {
+ GtkTreePath *current_path;
+ current_path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
+ gtk_tree_row_reference_free (icon_view->priv->dest_item);
+ icon_view->priv->dest_item = NULL;
- for (items = icon_view->priv->items; items; items = items->next)
+ gtk_icon_view_queue_draw_path (icon_view, current_path);
+ gtk_tree_path_free (current_path);
+ }
+
+ /* special case a drop on an empty model */
+ icon_view->priv->empty_view_drop = FALSE;
+ if (pos == GTK_TREE_VIEW_DROP_BEFORE && path
+ && gtk_tree_path_get_depth (path) == 1
+ && gtk_tree_path_get_indices (path)[0] == 0)
{
- GtkIconViewItem *item = items->data;
-
- if (!item->selected)
- {
- dirty = TRUE;
- item->selected = TRUE;
- gtk_icon_view_queue_draw_item (icon_view, item);
- }
+ gint n_children;
+
+ n_children = gtk_tree_model_iter_n_children (icon_view->priv->model,
+ NULL);
+
+ if (n_children == 0)
+ icon_view->priv->empty_view_drop = TRUE;
}
- if (dirty)
- g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
+ icon_view->priv->dest_pos = pos;
+
+ if (path)
+ {
+ icon_view->priv->dest_item =
+ gtk_tree_row_reference_new_proxy (G_OBJECT (icon_view),
+ icon_view->priv->model, path);
+
+ gtk_icon_view_queue_draw_path (icon_view, path);
+ }
}
/**
- * gtk_icon_view_unselect_all:
- * @icon_view: A #GtkIconView.
+ * gtk_icon_view_get_drag_dest_item:
+ * @icon_view: a #GtkIconView
+ * @path: Return location for the path of the highlighted item, or %NULL.
+ * @pos: Return location for the drop position, or %NULL
*
- * Unselects all the icons.
+ * Gets information about the item that is highlighted for feedback.
*
- * Since: 2.6
+ * Since: 2.8
**/
void
-gtk_icon_view_unselect_all (GtkIconView *icon_view)
+gtk_icon_view_get_drag_dest_item (GtkIconView *icon_view,
+ GtkTreePath **path,
+ GtkIconViewDropPosition *pos)
{
- gboolean dirty = FALSE;
-
g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
- if (icon_view->priv->selection_mode == GTK_SELECTION_BROWSE)
- return;
-
- dirty = gtk_icon_view_unselect_all_internal (icon_view);
+ if (path)
+ {
+ if (icon_view->priv->dest_item)
+ *path = gtk_tree_row_reference_get_path (icon_view->priv->dest_item);
+ else
+ *path = NULL;
+ }
- if (dirty)
- g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
+ if (pos)
+ *pos = icon_view->priv->dest_pos;
}
/**
- * gtk_icon_view_path_is_selected:
- * @icon_view: A #GtkIconView.
- * @path: A #GtkTreePath to check selection on.
+ * gtk_icon_view_get_dest_item_at_pos:
+ * @icon_view: a #GtkIconView
+ * @drag_x: the position to determine the destination item for
+ * @drag_y: the position to determine the destination item for
+ * @path: Return location for the path of the item, or %NULL.
+ * @pos: Return location for the drop position, or %NULL
*
- * Returns %TRUE if the icon pointed to by @path is currently
- * selected. If @icon does not point to a valid location, %FALSE is returned.
+ * Determines the destination item for a given position.
*
- * Return value: %TRUE if @path is selected.
+ * Return value: whether there is an item at the given position.
*
- * Since: 2.6
+ * Since: 2.8
**/
gboolean
-gtk_icon_view_path_is_selected (GtkIconView *icon_view,
- GtkTreePath *path)
+gtk_icon_view_get_dest_item_at_pos (GtkIconView *icon_view,
+ gint drag_x,
+ gint drag_y,
+ GtkTreePath **path,
+ GtkIconViewDropPosition *pos)
{
GtkIconViewItem *item;
-
+
+ /* Note; this function is exported to allow a custom DND
+ * implementation, so it can't touch TreeViewDragInfo
+ */
+
g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
- g_return_val_if_fail (icon_view->priv->model != NULL, FALSE);
- g_return_val_if_fail (path != NULL, FALSE);
-
- item = g_list_nth (icon_view->priv->items,
- gtk_tree_path_get_indices(path)[0])->data;
+ g_return_val_if_fail (drag_x >= 0, FALSE);
+ g_return_val_if_fail (drag_y >= 0, FALSE);
+ g_return_val_if_fail (icon_view->priv->bin_window != NULL, FALSE);
- if (!item)
+
+ if (path)
+ *path = NULL;
+
+ item = gtk_icon_view_get_item_at_coords (icon_view,
+ drag_x + icon_view->priv->hadjustment->value,
+ drag_y + icon_view->priv->vadjustment->value,
+ FALSE, NULL);
+
+ if (item == NULL)
return FALSE;
-
- return item->selected;
+
+ if (path)
+ *path = gtk_tree_path_new_from_indices (item->index, -1);
+
+ if (pos)
+ {
+ if (drag_x < item->x + item->width / 4)
+ *pos = GTK_ICON_VIEW_DROP_LEFT;
+ else if (drag_x > item->x + item->width * 3 / 4)
+ *pos = GTK_ICON_VIEW_DROP_RIGHT;
+ else if (drag_y < item->y + item->height / 4)
+ *pos = GTK_ICON_VIEW_DROP_ABOVE;
+ else if (drag_y > item->y + item->height * 3 / 4)
+ *pos = GTK_ICON_VIEW_DROP_BELOW;
+ else
+ *pos = GTK_ICON_VIEW_DROP_INTO;
+ }
+
+ return TRUE;
}
/**
- * gtk_icon_view_item_activated:
- * @icon_view: A #GtkIconView
- * @path: The #GtkTreePath to be activated
- *
- * Activates the item determined by @path.
+ * gtk_icon_view_create_drag_icon:
+ * @icon_view: a #GtkIconView
+ * @path: a #GtkTreePath in @icon_view
*
- * Since: 2.6
+ * Creates a #GdkPixmap representation of the item at @path.
+ * This image is used for a drag icon.
+ *
+ * Return value: a newly-allocated pixmap of the drag icon.
+ *
+ * Since: 2.8
**/
-void
-gtk_icon_view_item_activated (GtkIconView *icon_view,
- GtkTreePath *path)
+GdkPixmap *
+gtk_icon_view_create_drag_icon (GtkIconView *icon_view,
+ GtkTreePath *path)
{
- g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
- g_return_if_fail (path != NULL);
+ GtkWidget *widget;
+ cairo_t *cr;
+ GdkPixmap *drawable;
+ GList *l;
+ gint index;
+ GdkRectangle area;
+
+ g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), NULL);
+ g_return_val_if_fail (path != NULL, NULL);
+
+ widget = GTK_WIDGET (icon_view);
+
+ if (!GTK_WIDGET_REALIZED (widget))
+ return NULL;
+
+ index = gtk_tree_path_get_indices (path)[0];
+
+ for (l = icon_view->priv->items; l; l = l->next)
+ {
+ GtkIconViewItem *item = l->data;
+
+ if (index == item->index)
+ {
+ drawable = gdk_pixmap_new (icon_view->priv->bin_window,
+ item->width + 2,
+ item->height + 2,
+ -1);
+
+ cr = gdk_cairo_create (drawable);
+ cairo_set_line_width (cr, 1.);
+
+ gdk_cairo_set_source_color
+ (cr, &widget->style->base[GTK_WIDGET_STATE (widget)]);
+ cairo_rectangle (cr, 0, 0, item->width + 2, item->height + 2);
+ cairo_fill (cr);
+
+ area.x = 0;
+ area.y = 0;
+ area.width = item->width;
+ area.height = item->height;
+
+ gtk_icon_view_paint_item (icon_view, cr, item, &area,
+ drawable, 1, 1, FALSE);
+
+ cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); /* black */
+ cairo_rectangle (cr, 0.5, 0.5, item->width + 1, item->height + 1);
+ cairo_stroke (cr);
+
+ cairo_destroy (cr);
+
+ return drawable;
+ }
+ }
- g_signal_emit (icon_view, icon_view_signals[ITEM_ACTIVATED], 0, path);
+ return NULL;
}
/**
- * gtk_icon_view_set_orientation:
+ * gtk_icon_view_get_reorderable:
* @icon_view: a #GtkIconView
- * @orientation: the relative position of texts and icons
- *
- * Sets the ::orientation property which determines whether the labels
- * are drawn beside the icons instead of below.
*
- * Since: 2.6
+ * Retrieves whether the user can reorder the list via drag-and-drop.
+ * See gtk_icon_view_set_reorderable().
+ *
+ * Return value: %TRUE if the list can be reordered.
+ *
+ * Since: 2.8
**/
-void
-gtk_icon_view_set_orientation (GtkIconView *icon_view,
- GtkOrientation orientation)
+gboolean
+gtk_icon_view_get_reorderable (GtkIconView *icon_view)
{
- g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
-
- if (icon_view->priv->orientation != orientation)
- {
- icon_view->priv->orientation = orientation;
+ g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
- gtk_icon_view_invalidate_sizes (icon_view);
- gtk_icon_view_queue_layout (icon_view);
-
- g_object_notify (G_OBJECT (icon_view), "orientation");
- }
+ return icon_view->priv->reorderable;
}
+static const GtkTargetEntry item_targets[] = {
+ { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
+};
+
+
/**
- * gtk_icon_view_get_orientation:
- * @icon_view: a #GtkIconView
- *
- * Returns the value of the ::orientation property which determines
- * whether the labels are drawn beside the icons instead of below.
- *
- * Return value: the relative position of texts and icons
+ * gtk_icon_view_set_reorderable:
+ * @icon_view: A #GtkIconView.
+ * @reorderable: %TRUE, if the list of items can be reordered.
*
- * Since: 2.6
+ * This function is a convenience function to allow you to reorder models that
+ * support the #GtkTreeDragSourceIface and the #GtkTreeDragDestIface. Both
+ * #GtkTreeStore and #GtkListStore support these. If @reorderable is %TRUE, then
+ * the user can reorder the model by dragging and dropping rows. The
+ * developer can listen to these changes by connecting to the model's
+ * row_inserted and row_deleted signals.
+ *
+ * This function does not give you any degree of control over the order -- any
+ * reordering is allowed. If more control is needed, you should probably
+ * handle drag and drop manually.
+ *
+ * Since: 2.8
**/
-GtkOrientation
-gtk_icon_view_get_orientation (GtkIconView *icon_view)
+void
+gtk_icon_view_set_reorderable (GtkIconView *icon_view,
+ gboolean reorderable)
{
- g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view),
- GTK_ORIENTATION_VERTICAL);
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
- return icon_view->priv->orientation;
+ reorderable = reorderable != FALSE;
+
+ if (icon_view->priv->reorderable == reorderable)
+ return;
+
+ if (reorderable)
+ {
+ gtk_icon_view_enable_model_drag_source (icon_view,
+ GDK_BUTTON1_MASK,
+ item_targets,
+ G_N_ELEMENTS (item_targets),
+ GDK_ACTION_MOVE);
+ gtk_icon_view_enable_model_drag_dest (icon_view,
+ item_targets,
+ G_N_ELEMENTS (item_targets),
+ GDK_ACTION_MOVE);
+ }
+ else
+ {
+ gtk_icon_view_unset_model_drag_source (icon_view);
+ gtk_icon_view_unset_model_drag_dest (icon_view);
+ }
+
+ icon_view->priv->reorderable = reorderable;
+
+ g_object_notify (G_OBJECT (icon_view), "reorderable");
}
+
/* Accessibility Support */
static gpointer accessible_parent_class;
guint action_idle_handler;
} GtkIconViewItemAccessible;
-static const gchar *gtk_icon_view_item_accessible_action_names[] =
+static const gchar *const gtk_icon_view_item_accessible_action_names[] =
{
"activate",
NULL
};
-static const gchar *gtk_icon_view_item_accessible_action_descriptions[] =
+static const gchar *const gtk_icon_view_item_accessible_action_descriptions[] =
{
"Activate item",
NULL
GtkIconView *icon_view;
GtkTreePath *path;
- GDK_THREADS_ENTER ();
-
item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (data);
item->action_idle_handler = 0;
gtk_tree_path_free (path);
}
- GDK_THREADS_LEAVE ();
-
return FALSE;
}
gint i)
{
GtkIconViewItemAccessible *item;
- GtkIconView *icon_view;
if (i < 0 || i >= LAST_ACTION)
return FALSE;
if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
return FALSE;
- icon_view = GTK_ICON_VIEW (item->widget);
-
switch (i)
{
case ACTION_ACTIVATE:
if (!item->action_idle_handler)
- item->action_idle_handler = g_idle_add (gtk_icon_view_item_accessible_idle_do_action, item);
+ item->action_idle_handler = gdk_threads_add_idle (gtk_icon_view_item_accessible_idle_do_action, item);
break;
default:
g_assert_not_reached ();
return TRUE;
}
+static gboolean
+get_pixbuf_box (GtkIconView *icon_view,
+ GtkIconViewItem *item,
+ GdkRectangle *box)
+{
+ GList *l;
+
+ for (l = icon_view->priv->cell_list; l; l = l->next)
+ {
+ GtkIconViewCellInfo *info = l->data;
+
+ if (GTK_IS_CELL_RENDERER_PIXBUF (info->cell))
+ {
+ gtk_icon_view_get_cell_box (icon_view, item, info, box);
+
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static gchar *
+get_text (GtkIconView *icon_view,
+ GtkIconViewItem *item)
+{
+ GList *l;
+ gchar *text;
+
+ for (l = icon_view->priv->cell_list; l; l = l->next)
+ {
+ GtkIconViewCellInfo *info = l->data;
+
+ if (GTK_IS_CELL_RENDERER_TEXT (info->cell))
+ {
+ g_object_get (info->cell, "text", &text, NULL);
+
+ return text;
+ }
+ }
+
+ return NULL;
+}
+
static void
gtk_icon_view_item_accessible_image_get_image_size (AtkImage *image,
gint *width,
gint *height)
{
GtkIconViewItemAccessible *item;
+ GdkRectangle box;
item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
return;
- *width = item->item->pixbuf_width;
- *height = item->item->pixbuf_height;
+ if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
+ {
+ *width = box.width;
+ *height = box.height;
+ }
}
static void
AtkCoordType coord_type)
{
GtkIconViewItemAccessible *item;
+ GdkRectangle box;
item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (image);
return;
atk_component_get_position (ATK_COMPONENT (image), x, y, coord_type);
- *x+= item->item->pixbuf_x - item->item->x;
- *y+= item->item->pixbuf_y - item->item->y;
+
+ if (get_pixbuf_box (GTK_ICON_VIEW (item->widget), item->item, &box))
+ {
+ *x+= box.x - item->item->x;
+ *y+= box.y - item->item->y;
+ }
+
}
static void
return unichar;
}
+#if 0
static void
get_pango_text_offsets (PangoLayout *layout,
GtkTextBuffer *buffer,
gtk_text_buffer_get_iter_at_offset (buffer, start_iter, *start_offset);
gtk_text_buffer_get_iter_at_offset (buffer, end_iter, *end_offset);
}
+#endif
static gchar*
gtk_icon_view_item_accessible_text_get_text_before_offset (AtkText *text,
GtkIconViewItemAccessible *item;
GtkTextIter start, end;
GtkTextBuffer *buffer;
+#if 0
GtkIconView *icon_view;
+#endif
item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
break;
case ATK_TEXT_BOUNDARY_LINE_START:
case ATK_TEXT_BOUNDARY_LINE_END:
+#if 0
icon_view = GTK_ICON_VIEW (item->widget);
+ /* FIXME we probably have to use GailTextCell to salvage this */
gtk_icon_view_update_item_text (icon_view, item->item);
get_pango_text_offsets (icon_view->priv->layout,
buffer,
end_offset,
&start,
&end);
+#endif
break;
}
GtkIconViewItemAccessible *item;
GtkTextIter start, end;
GtkTextBuffer *buffer;
+#if 0
GtkIconView *icon_view;
+#endif
item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
break;
case ATK_TEXT_BOUNDARY_LINE_START:
case ATK_TEXT_BOUNDARY_LINE_END:
+#if 0
icon_view = GTK_ICON_VIEW (item->widget);
+ /* FIXME we probably have to use GailTextCell to salvage this */
gtk_icon_view_update_item_text (icon_view, item->item);
get_pango_text_offsets (icon_view->priv->layout,
buffer,
end_offset,
&start,
&end);
+#endif
break;
}
GtkIconViewItemAccessible *item;
GtkTextIter start, end;
GtkTextBuffer *buffer;
+#if 0
GtkIconView *icon_view;
+#endif
item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
break;
case ATK_TEXT_BOUNDARY_LINE_START:
case ATK_TEXT_BOUNDARY_LINE_END:
+#if 0
icon_view = GTK_ICON_VIEW (item->widget);
+ /* FIXME we probably have to use GailTextCell to salvage this */
gtk_icon_view_update_item_text (icon_view, item->item);
get_pango_text_offsets (icon_view->priv->layout,
buffer,
end_offset,
&start,
&end);
+#endif
break;
}
*start_offset = gtk_text_iter_get_offset (&start);
AtkCoordType coord_type)
{
GtkIconViewItemAccessible *item;
+#if 0
GtkIconView *icon_view;
PangoRectangle char_rect;
const gchar *item_text;
gint index;
+#endif
item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
return;
+#if 0
icon_view = GTK_ICON_VIEW (item->widget);
+ /* FIXME we probably have to use GailTextCell to salvage this */
gtk_icon_view_update_item_text (icon_view, item->item);
item_text = pango_layout_get_text (icon_view->priv->layout);
index = g_utf8_offset_to_pointer (item_text, offset) - item_text;
atk_component_get_position (ATK_COMPONENT (text), x, y, coord_type);
*x += item->item->layout_x - item->item->x + char_rect.x / PANGO_SCALE;
/* Look at gtk_icon_view_paint_item() to see where the text is. */
- *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, MINIMUM_ICON_ITEM_WIDTH) - item->item->width) / 2,
+ *x -= ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
*y += item->item->layout_y - item->item->y + char_rect.y / PANGO_SCALE;
*width = char_rect.width / PANGO_SCALE;
*height = char_rect.height / PANGO_SCALE;
+#endif
}
static gint
AtkCoordType coord_type)
{
GtkIconViewItemAccessible *item;
+ gint offset = 0;
+#if 0
GtkIconView *icon_view;
const gchar *item_text;
gint index;
- gint offset;
gint l_x, l_y;
+#endif
item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (text);
if (atk_state_set_contains_state (item->state_set, ATK_STATE_DEFUNCT))
return -1;
+#if 0
icon_view = GTK_ICON_VIEW (item->widget);
+ /* FIXME we probably have to use GailTextCell to salvage this */
gtk_icon_view_update_item_text (icon_view, item->item);
atk_component_get_position (ATK_COMPONENT (text), &l_x, &l_y, coord_type);
x -= l_x + item->item->layout_x - item->item->x;
- x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, MINIMUM_ICON_ITEM_WIDTH) - item->item->width) / 2,
+ x += ((item->item->width - item->item->layout_width) / 2) + (MAX (item->item->pixbuf_width, icon_view->priv->item_width) - item->item->width) / 2,
y -= l_y + item->item->layout_y - item->item->y;
item_text = pango_layout_get_text (icon_view->priv->layout);
if (!pango_layout_xy_to_index (icon_view->priv->layout,
offset = g_utf8_strlen (item_text, -1);
else
offset = g_utf8_pointer_to_offset (item_text, item_text + index);
-
+#endif
return offset;
}
return FALSE;
gtk_widget_grab_focus (item->widget);
- gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item);
+ gtk_icon_view_set_cursor_item (GTK_ICON_VIEW (item->widget), item->item, -1);
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item->widget));
if (GTK_WIDGET_TOPLEVEL (toplevel))
gtk_window_present (GTK_WINDOW (toplevel));
if (!type)
{
- static const GTypeInfo tinfo =
+ const GTypeInfo tinfo =
{
sizeof (GtkIconViewItemAccessibleClass),
(GBaseInitFunc) NULL, /* base init */
};
type = g_type_register_static (ATK_TYPE_OBJECT,
- "GtkIconViewItemAccessible", &tinfo, 0);
+ I_("GtkIconViewItemAccessible"), &tinfo, 0);
g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
&atk_component_info);
g_type_add_interface_static (type, ATK_TYPE_ACTION,
a11y_item->item = item;
a11y_item->widget = widget;
a11y_item->text_buffer = gtk_text_buffer_new (NULL);
- gtk_icon_view_update_item_text (icon_view, item);
+
+ gtk_icon_view_set_cell_data (icon_view, item);
gtk_text_buffer_set_text (a11y_item->text_buffer,
- pango_layout_get_text (icon_view->priv->layout),
- -1);
+ get_text (icon_view, item), -1);
+
gtk_icon_view_item_accessible_set_visibility (a11y_item, FALSE);
g_object_add_weak_pointer (G_OBJECT (widget), (gpointer) &(a11y_item->widget));
}
AtkObject *atk_obj;
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
- g_signal_emit_by_name (atk_obj, "visible-data-changed");
+ g_signal_emit_by_name (atk_obj, "visible_data_changed");
return;
}
{
GtkIconViewAccessiblePrivate *priv;
GtkIconViewItemAccessibleInfo *info;
- GtkIconViewAccessible *view;
GtkIconView *icon_view;
GtkIconViewItemAccessible *item;
GList *items;
- GList *tmp_list;
AtkObject *atk_obj;
atk_obj = gtk_widget_get_accessible (GTK_WIDGET (user_data));
icon_view = GTK_ICON_VIEW (user_data);
- view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
priv = gtk_icon_view_accessible_get_priv (atk_obj);
items = priv->items;
- tmp_list = NULL;
while (items)
{
info = items->data;
item = GTK_ICON_VIEW_ITEM_ACCESSIBLE (info->item);
info->index = new_order[info->index];
- tmp_list = g_list_nth (icon_view->priv->items, info->index);
- item->item = tmp_list->data;
+ item->item = g_list_nth_data (icon_view->priv->items, info->index);
items = items->next;
}
priv->items = g_list_sort (priv->items,
GObject *obj;
obj = G_OBJECT (icon_view->priv->model);
- g_signal_connect_data (obj, "row-changed",
+ g_signal_connect_data (obj, "row_changed",
(GCallback) gtk_icon_view_accessible_model_row_changed,
icon_view, NULL, 0);
- g_signal_connect_data (obj, "row-inserted",
+ g_signal_connect_data (obj, "row_inserted",
(GCallback) gtk_icon_view_accessible_model_row_inserted,
icon_view, NULL, G_CONNECT_AFTER);
- g_signal_connect_data (obj, "row-deleted",
+ g_signal_connect_data (obj, "row_deleted",
(GCallback) gtk_icon_view_accessible_model_row_deleted,
icon_view, NULL, G_CONNECT_AFTER);
- g_signal_connect_data (obj, "rows-reordered",
+ g_signal_connect_data (obj, "rows_reordered",
(GCallback) gtk_icon_view_accessible_model_rows_reordered,
icon_view, NULL, G_CONNECT_AFTER);
}
GtkIconView *icon_view;
GtkWidget *widget;
AtkObject *atk_obj;
- GtkIconViewAccessible *view;
GtkIconViewAccessiblePrivate *priv;
if (strcmp (pspec->name, "model") == 0)
{
widget = GTK_WIDGET (obj);
atk_obj = gtk_widget_get_accessible (widget);
- view = GTK_ICON_VIEW_ACCESSIBLE (atk_obj);
priv = gtk_icon_view_accessible_get_priv (atk_obj);
if (priv->model)
{
icon_view = GTK_ICON_VIEW (widget);
atk_component_get_extents (component, &x_pos, &y_pos, NULL, NULL, coord_type);
- item = gtk_icon_view_get_item_at_pos (icon_view, x - x_pos, y - y_pos);
+ item = gtk_icon_view_get_item_at_coords (icon_view, x - x_pos, y - y_pos, TRUE, NULL);
if (item)
return gtk_icon_view_accessible_ref_child (ATK_OBJECT (component), item->index);
GtkWidget *widget;
GtkIconView *icon_view;
GtkIconViewItem *item;
- GList *l;
widget = GTK_ACCESSIBLE (selection)->widget;
if (widget == NULL)
icon_view = GTK_ICON_VIEW (widget);
- l = g_list_nth (icon_view->priv->items, i);
- if (!l)
+ item = g_list_nth_data (icon_view->priv->items, i);
+
+ if (!item)
return FALSE;
- item = l->data;
gtk_icon_view_select_item (icon_view, item);
return TRUE;
GtkWidget *widget;
GtkIconView *icon_view;
GtkIconViewItem *item;
- GList *l;
widget = GTK_ACCESSIBLE (selection)->widget;
if (widget == NULL)
return FALSE;
icon_view = GTK_ICON_VIEW (widget);
- l = g_list_nth (icon_view->priv->items, i);
- if (!l)
- return FALSE;
- item = l->data;
+ item = g_list_nth_data (icon_view->priv->items, i);
+ if (!item)
+ return FALSE;
return item->selected;
}
(GInterfaceFinalizeFunc) NULL,
NULL
};
- static GInterfaceInfo atk_selection_info =
+ static const GInterfaceInfo atk_selection_info =
{
(GInterfaceInitFunc) gtk_icon_view_accessible_selection_interface_init,
(GInterfaceFinalizeFunc) NULL,
if (!type)
{
- static const GTypeInfo tinfo =
+ const GTypeInfo tinfo =
{
sizeof (AtkObjectFactoryClass),
NULL, /* base_init */
return type;
}
+
static AtkObject *
gtk_icon_view_get_accessible (GtkWidget *widget)
{
gtk_icon_view_accessible_factory_get_type ());
first_time = FALSE;
}
- return GTK_WIDGET_CLASS (parent_class)->get_accessible (widget);
+ return (* GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->get_accessible) (widget);
}
+#define __GTK_ICON_VIEW_C__
+#include "gtkaliasdef.c"