#include "gtktreednd.h"
#include "gtktypebuiltins.h"
#include "gtkprivate.h"
-#include "a11y/gtkiconviewaccessible.h"
+#include "a11y/gtkiconviewaccessibleprivate.h"
/**
* SECTION:gtkiconview
PROP_TOOLTIP_COLUMN,
PROP_ITEM_PADDING,
PROP_CELL_AREA,
-
- /* For scrollable interface */
PROP_HADJUSTMENT,
PROP_VADJUSTMENT,
PROP_HSCROLL_POLICY,
- PROP_VSCROLL_POLICY
+ PROP_VSCROLL_POLICY,
+ PROP_ACTIVATE_ON_SINGLE_CLICK
};
/* GObject vfuncs */
static void gtk_icon_view_destroy (GtkWidget *widget);
static void gtk_icon_view_realize (GtkWidget *widget);
static void gtk_icon_view_unrealize (GtkWidget *widget);
-static void gtk_icon_view_style_updated (GtkWidget *widget);
-static void gtk_icon_view_state_flags_changed (GtkWidget *widget,
- GtkStateFlags previous_state);
static GtkSizeRequestMode gtk_icon_view_get_request_mode (GtkWidget *widget);
static void gtk_icon_view_get_preferred_width (GtkWidget *widget,
gint *minimum,
widget_class->destroy = gtk_icon_view_destroy;
widget_class->realize = gtk_icon_view_realize;
widget_class->unrealize = gtk_icon_view_unrealize;
- widget_class->style_updated = gtk_icon_view_style_updated;
widget_class->get_request_mode = gtk_icon_view_get_request_mode;
widget_class->get_preferred_width = gtk_icon_view_get_preferred_width;
widget_class->get_preferred_height = gtk_icon_view_get_preferred_height;
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_flags_changed = gtk_icon_view_state_flags_changed;
container_class->remove = gtk_icon_view_remove;
container_class->forall = gtk_icon_view_forall;
GTK_TYPE_CELL_AREA,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ /**
+ * GtkIconView:activate-on-single-click:
+ *
+ * The activate-on-single-click property specifies whether the "item-activated" signal
+ * will be emitted after a single click.
+ *
+ * Since: 3.8
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_ACTIVATE_ON_SINGLE_CLICK,
+ g_param_spec_boolean ("activate-on-single-click",
+ P_("Activate on Single Click"),
+ P_("Activate row on a single click"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
/* Scrollable interface properties */
g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
* @path: the #GtkTreePath for the activated item
*
* The ::item-activated signal is emitted when the method
- * gtk_icon_view_item_activated() is called or the user double
- * clicks an item. It is also emitted when a non-editable item
- * is selected and one of the keys: Space, Return or Enter is
- * pressed.
+ * gtk_icon_view_item_activated() is called, when the user double
+ * clicks an item with the "activate-on-single-click" property set
+ * to %FALSE, or when the user single clicks an item when the
+ * "activate-on-single-click" property set to %TRUE. It is also
+ * emitted when a non-editable item is selected and one of the keys:
+ * Space, Return or Enter is pressed.
*/
icon_view_signals[ITEM_ACTIVATED] =
g_signal_new (I_("item-activated"),
icon_view->priv->column_spacing = 6;
icon_view->priv->margin = 6;
icon_view->priv->item_padding = 6;
+ icon_view->priv->activate_on_single_click = FALSE;
icon_view->priv->draw_focus = TRUE;
icon_view->priv->row_contexts =
g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
+
+ gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (icon_view)),
+ GTK_STYLE_CLASS_VIEW);
}
/* GObject methods */
gtk_icon_view_set_item_padding (icon_view, g_value_get_int (value));
break;
+ case PROP_ACTIVATE_ON_SINGLE_CLICK:
+ gtk_icon_view_set_activate_on_single_click (icon_view, g_value_get_boolean (value));
+ break;
+
case PROP_CELL_AREA:
/* Construct-only, can only be assigned once */
area = g_value_get_object (value);
g_value_set_int (value, icon_view->priv->item_padding);
break;
+ case PROP_ACTIVATE_ON_SINGLE_CLICK:
+ g_value_set_boolean (value, icon_view->priv->activate_on_single_click);
+ break;
+
case PROP_CELL_AREA:
g_value_set_object (value, icon_view->priv->cell_area);
break;
GdkWindow *window;
GdkWindowAttr attributes;
gint attributes_mask;
- GtkStyleContext *context;
gtk_widget_set_realized (widget, TRUE);
icon_view->priv->bin_window = gdk_window_new (window,
&attributes, attributes_mask);
gdk_window_set_user_data (icon_view->priv->bin_window, widget);
-
- context = gtk_widget_get_style_context (widget);
-
- gtk_style_context_save (context);
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
- gtk_style_context_set_background (context, icon_view->priv->bin_window);
- gtk_style_context_set_background (context, window);
- gtk_style_context_restore (context);
-
gdk_window_show (icon_view->priv->bin_window);
}
GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->unrealize (widget);
}
-static void
-_gtk_icon_view_update_background (GtkIconView *icon_view)
-{
- GtkWidget *widget = GTK_WIDGET (icon_view);
-
- if (gtk_widget_get_realized (widget))
- {
- GtkStyleContext *context;
-
- context = gtk_widget_get_style_context (widget);
-
- gtk_style_context_save (context);
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
-
- gtk_style_context_set_background (context, gtk_widget_get_window (widget));
- gtk_style_context_set_background (context, icon_view->priv->bin_window);
-
- gtk_style_context_restore (context);
- }
-}
-
-static void
-gtk_icon_view_state_flags_changed (GtkWidget *widget,
- GtkStateFlags previous_state)
-{
- _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
- gtk_widget_queue_draw (widget);
-}
-
-static void
-gtk_icon_view_style_updated (GtkWidget *widget)
-{
- GTK_WIDGET_CLASS (gtk_icon_view_parent_class)->style_updated (widget);
-
- _gtk_icon_view_update_background (GTK_ICON_VIEW (widget));
- gtk_widget_queue_resize (widget);
-}
-
static gint
gtk_icon_view_get_n_items (GtkIconView *icon_view)
{
gint dest_index;
GtkIconViewDropPosition dest_pos;
GtkIconViewItem *dest_item = NULL;
+ GtkStyleContext *context;
icon_view = GTK_ICON_VIEW (widget);
+ context = gtk_widget_get_style_context (widget);
+ gtk_render_background (context, cr,
+ 0, 0,
+ gtk_widget_get_allocated_width (widget),
+ gtk_widget_get_allocated_height (widget));
+
if (!gtk_cairo_should_draw_window (cr, icon_view->priv->bin_window))
return FALSE;
&cell);
/*
- * We consider only the the cells' area as the item area if the
+ * We consider only the cells' area as the item area if the
* item is not selected, but if it *is* selected, the complete
* selection rectangle is considered to be part of the item.
*/
icon_view->priv->draw_focus = FALSE;
}
- if (event->button == GDK_BUTTON_PRIMARY && event->type == GDK_2BUTTON_PRESS)
+ if (!icon_view->priv->activate_on_single_click
+ && event->button == GDK_BUTTON_PRIMARY
+ && event->type == GDK_2BUTTON_PRESS)
{
item = _gtk_icon_view_get_item_at_coords (icon_view,
event->x, event->y,
return event->button == GDK_BUTTON_PRIMARY;
}
+static gboolean
+button_event_modifies_selection (GdkEventButton *event)
+{
+ return (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0;
+}
+
static gboolean
gtk_icon_view_button_release (GtkWidget *widget,
GdkEventButton *event)
remove_scroll_timeout (icon_view);
+ if (event->button == GDK_BUTTON_PRIMARY
+ && icon_view->priv->activate_on_single_click
+ && !button_event_modifies_selection (event)
+ && icon_view->priv->last_single_clicked != NULL)
+ {
+ GtkIconViewItem *item;
+
+ item = _gtk_icon_view_get_item_at_coords (icon_view,
+ event->x, event->y,
+ FALSE,
+ NULL);
+ if (item == icon_view->priv->last_single_clicked)
+ {
+ GtkTreePath *path;
+ path = gtk_tree_path_new_from_indices (item->index, -1);
+ gtk_icon_view_item_activated (icon_view, path);
+ gtk_tree_path_free (path);
+ }
+
+ icon_view->priv->last_single_clicked = NULL;
+ }
+
return TRUE;
}
if (icon_view->priv->doing_rubberband)
gtk_icon_view_update_rubberband (GTK_WIDGET (icon_view));
-
+
_gtk_icon_view_accessible_adjustment_changed (icon_view);
}
}
state = gtk_widget_get_state_flags (widget);
gtk_style_context_save (style_context);
- gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_CELL);
state &= ~(GTK_STATE_FLAG_SELECTED | GTK_STATE_FLAG_PRELIGHT);
+ if ((state & GTK_STATE_FLAG_FOCUSED) &&
+ item == icon_view->priv->cursor_item)
+ flags |= GTK_CELL_RENDERER_FOCUSED;
+
if (item->selected)
{
- if ((state & GTK_STATE_FLAG_FOCUSED) &&
- item == icon_view->priv->cursor_item)
- {
- flags |= GTK_CELL_RENDERER_FOCUSED;
- }
-
state |= GTK_STATE_FLAG_SELECTED;
flags |= GTK_CELL_RENDERER_SELECTED;
}
* @x: (inout): the x coordinate (relative to widget coordinates)
* @y: (inout): the y coordinate (relative to widget coordinates)
* @keyboard_tip: whether this is a keyboard tooltip or not
- * @model: (out) (allow-none): a pointer to receive a #GtkTreeModel or %NULL
+ * @model: (out) (allow-none) (transfer none): a pointer to receive a
+ * #GtkTreeModel or %NULL
* @path: (out) (allow-none): a pointer to receive a #GtkTreePath or %NULL
* @iter: (out) (allow-none): a pointer to receive a #GtkTreeIter or %NULL
*
gtk_icon_view_set_model (GtkIconView *icon_view,
GtkTreeModel *model)
{
+ gboolean dirty;
+
g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
if (icon_view->priv->cell_area)
gtk_cell_area_stop_editing (icon_view->priv->cell_area, TRUE);
+ dirty = gtk_icon_view_unselect_all_internal (icon_view);
+
if (model)
{
GType column_type;
g_object_notify (G_OBJECT (icon_view), "model");
+ if (dirty)
+ g_signal_emit (icon_view, icon_view_signals[SELECTION_CHANGED], 0);
+
gtk_widget_queue_resize (GTK_WIDGET (icon_view));
}
*
* To free the return value, use:
* |[
- * g_list_free_full (list, (GDestroyNotify) gtk_tree_patch_free);
+ * g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
* ]|
*
* Return value: (element-type GtkTreePath) (transfer full): A #GList containing a #GtkTreePath for each selected row.
g_object_notify (G_OBJECT (icon_view), "reorderable");
}
+/**
+ * gtk_icon_view_set_activate_on_single_click:
+ * @icon_view: a #GtkIconView
+ * @setting: %TRUE to emit item-activated on a single click
+ *
+ * Causes the "item-activated" signal to be emitted on a single click
+ * instead of a double click.
+ *
+ * Since: 3.8
+ **/
+void
+gtk_icon_view_set_activate_on_single_click (GtkIconView *icon_view,
+ gboolean setting)
+{
+ g_return_if_fail (GTK_IS_ICON_VIEW (icon_view));
+
+ setting = setting != FALSE;
+
+ if (icon_view->priv->activate_on_single_click == setting)
+ return;
+
+ icon_view->priv->activate_on_single_click = setting;
+ g_object_notify (G_OBJECT (icon_view), "activate-on-single-click");
+}
+
+/**
+ * gtk_icon_view_get_activate_on_single_click:
+ * @icon_view: a #GtkIconView
+ *
+ * Gets the setting set by gtk_icon_view_set_activate_on_single_click().
+ *
+ * Return value: %TRUE if item-activated will be emitted on a single click
+ *
+ * Since: 3.8
+ **/
+gboolean
+gtk_icon_view_get_activate_on_single_click (GtkIconView *icon_view)
+{
+ g_return_val_if_fail (GTK_IS_ICON_VIEW (icon_view), FALSE);
+
+ return icon_view->priv->activate_on_single_click;
+}
+
static gboolean
gtk_icon_view_buildable_custom_tag_start (GtkBuildable *buildable,
GtkBuilder *builder,