Index: exo/exo-icon-view.h =================================================================== --- exo/exo-icon-view.h (revision 19690) +++ exo/exo-icon-view.h (working copy) @@ -1,6 +1,6 @@ /* $Id$ */ /*- - * Copyright (c) 2004-2005 os-cillation e.K. + * Copyright (c) 2004-2006 os-cillation e.K. * Copyright (c) 2002,2004 Anders Carlsson * * Written by Benedikt Meurer . @@ -163,6 +163,10 @@ void exo_icon_view_set_selection_mode (ExoIconView *icon_view, GtkSelectionMode mode); +gboolean exo_icon_view_get_single_click (const ExoIconView *icon_view); +void exo_icon_view_set_single_click (ExoIconView *icon_view, + gboolean single_click); + void exo_icon_view_widget_to_icon_coords (const ExoIconView *icon_view, gint wx, gint wy, Index: exo/exo.symbols =================================================================== --- exo/exo.symbols (revision 19690) +++ exo/exo.symbols (working copy) @@ -171,6 +171,8 @@ exo_icon_view_set_margin exo_icon_view_get_selection_mode exo_icon_view_set_selection_mode +exo_icon_view_get_single_click +exo_icon_view_set_single_click exo_icon_view_widget_to_icon_coords exo_icon_view_icon_to_widget_coords exo_icon_view_get_path_at_pos Index: exo/exo-icon-view.c =================================================================== --- exo/exo-icon-view.c (revision 19697) +++ exo/exo-icon-view.c (working copy) @@ -66,7 +66,8 @@ PROP_ROW_SPACING, PROP_COLUMN_SPACING, PROP_MARGIN, - PROP_REORDERABLE + PROP_REORDERABLE, + PROP_SINGLE_CLICK, }; /* Signal identifiers */ @@ -429,6 +430,7 @@ guint source_set : 1; guint dest_set : 1; guint reorderable : 1; + guint single_click : 1; guint empty_view_drop :1; guint ctrl_pressed : 1; @@ -490,12 +492,12 @@ GtkBindingSet *gtkbinding_set; GObjectClass *gobject_class; - gtkbinding_set = gtk_binding_set_by_class (klass); + /* determine the parent type class */ + exo_icon_view_parent_class = g_type_class_peek_parent (klass); + /* add our private data to the type's instances */ g_type_class_add_private (klass, sizeof (ExoIconViewPrivate)); - exo_icon_view_parent_class = g_type_class_peek_parent (klass); - gobject_class = G_OBJECT_CLASS (klass); gobject_class->dispose = exo_icon_view_dispose; gobject_class->finalize = exo_icon_view_finalize; @@ -534,7 +536,7 @@ klass->move_cursor = exo_icon_view_real_move_cursor; /** - * ExoIconView::column-spacing: + * ExoIconView:column-spacing: * * The column-spacing property specifies the space which is inserted between * the columns of the icon view. @@ -550,7 +552,7 @@ EXO_PARAM_READWRITE)); /** - * ExoIconView::columns: + * ExoIconView: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 @@ -568,7 +570,7 @@ /** - * ExoIconView::item-width: + * ExoIconView: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 @@ -585,7 +587,7 @@ EXO_PARAM_READWRITE)); /** - * ExoIconView::margin: + * ExoIconView:margin: * * The margin property specifies the space which is inserted * at the edges of the icon view. @@ -601,7 +603,7 @@ EXO_PARAM_READWRITE)); /** - * ExoIconView::markup-column: + * ExoIconView:markup-column: * * The ::markup-column property contains the number of the model column * containing markup information to be displayed. The markup column must be @@ -618,7 +620,7 @@ EXO_PARAM_READWRITE)); /** - * ExoIconView::model: + * ExoIconView:model: * * The ::model property contains the #GtkTreeModel, which should be * display by this icon view. Setting this property to %NULL turns @@ -633,7 +635,7 @@ EXO_PARAM_READWRITE)); /** - * ExoIconView::orientation: + * ExoIconView:orientation: * * The orientation property specifies how the cells (i.e. the icon and * the text) of the item are positioned relative to each other. @@ -648,7 +650,7 @@ EXO_PARAM_READWRITE)); /** - * ExoIconView::pixbuf-column: + * ExoIconView:pixbuf-column: * * The ::pixbuf-column property contains the number of the model column * containing the pixbufs which are displayed. The pixbuf column must be @@ -664,7 +666,7 @@ EXO_PARAM_READWRITE)); /** - * ExoIconView::reorderable: + * ExoIconView:reorderable: * * The reorderable property specifies if the items can be reordered * by Drag and Drop. @@ -680,7 +682,7 @@ EXO_PARAM_READWRITE)); /** - * ExoIconView::row-spacing: + * ExoIconView:row-spacing: * * The row-spacing property specifies the space which is inserted between * the rows of the icon view. @@ -696,7 +698,7 @@ EXO_PARAM_READWRITE)); /** - * ExoIconView::selection-mode: + * ExoIconView:selection-mode: * * The ::selection-mode property specifies the selection mode of * icon view. If the mode is #GTK_SELECTION_MULTIPLE, rubberband selection @@ -712,8 +714,23 @@ EXO_PARAM_READWRITE)); /** - * ExoIconView::spacing: + * ExoIconView:single-click: * + * Determines whether items can be activated by single or double clicks. + * + * Since: 0.3.1.3 + **/ + g_object_class_install_property (gobject_class, + PROP_SINGLE_CLICK, + g_param_spec_boolean ("single-click", + _("Single Click"), + _("Whether the items in the view can be activated with single clicks"), + FALSE, + EXO_PARAM_READWRITE)); + + /** + * ExoIconView:spacing: + * * The spacing property specifies the space which is inserted between * the cells (i.e. the icon and the text) of an item. * @@ -728,7 +745,7 @@ EXO_PARAM_READWRITE)); /** - * ExoIconView::text-column: + * ExoIconView:text-column: * * The ::text-column property contains the number of the model column * containing the texts which are displayed. The text column must be @@ -745,7 +762,7 @@ /** - * ExoIconView::selection-box-color: + * ExoIconView:selection-box-color: * Color of the selection box. **/ gtk_widget_class_install_style_property (gtkwidget_class, @@ -756,7 +773,7 @@ EXO_PARAM_READABLE)); /** - * ExoIconView::selection-box-alpha: + * ExoIconView:selection-box-alpha: * Opacity of the selection box. **/ gtk_widget_class_install_style_property (gtkwidget_class, @@ -898,6 +915,7 @@ G_TYPE_INT); /* Key bindings */ + gtkbinding_set = gtk_binding_set_by_class (klass); gtk_binding_entry_add_signal (gtkbinding_set, GDK_a, GDK_CONTROL_MASK, "select-all", 0); gtk_binding_entry_add_signal (gtkbinding_set, GDK_a, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0); gtk_binding_entry_add_signal (gtkbinding_set, GDK_space, GDK_CONTROL_MASK, "toggle-cursor-item", 0); @@ -1081,6 +1099,10 @@ g_value_set_enum (value, icon_view->priv->selection_mode); break; + case PROP_SINGLE_CLICK: + g_value_set_boolean (value, icon_view->priv->single_click); + break; + case PROP_SPACING: g_value_set_int (value, icon_view->priv->spacing); break; @@ -1151,6 +1173,10 @@ exo_icon_view_set_selection_mode (icon_view, g_value_get_enum (value)); break; + case PROP_SINGLE_CLICK: + exo_icon_view_set_single_click (icon_view, g_value_get_boolean (value)); + break; + case PROP_SPACING: exo_icon_view_set_spacing (icon_view, g_value_get_int (value)); break; @@ -1517,6 +1543,7 @@ { ExoIconViewItem *item; ExoIconView *icon_view = EXO_ICON_VIEW (widget); + GdkCursor *cursor; gint abs_y; exo_icon_view_maybe_begin_drag (icon_view, event); @@ -1559,6 +1586,24 @@ icon_view->priv->prelit_item = item; if (G_LIKELY (item != NULL)) exo_icon_view_queue_draw_item (icon_view, item); + + /* check if we are in single click mode right now */ + if (G_UNLIKELY (icon_view->priv->single_click)) + { + /* display a hand cursor when pointer is above an item */ + if (G_LIKELY (item != NULL)) + { + /* hand2 seems to be what we should use */ + cursor = gdk_cursor_new (GDK_HAND2); + gdk_window_set_cursor (event->window, cursor); + gdk_cursor_unref (cursor); + } + else + { + /* reset the cursor */ + gdk_window_set_cursor (event->window, NULL); + } + } } } @@ -1949,11 +1994,33 @@ exo_icon_view_button_release_event (GtkWidget *widget, GdkEventButton *event) { - ExoIconView *icon_view = EXO_ICON_VIEW (widget); + ExoIconViewItem *item; + ExoIconView *icon_view = EXO_ICON_VIEW (widget); + GtkTreePath *path; if (icon_view->priv->pressed_button == event->button) - icon_view->priv->pressed_button = -1; + { + /* check if we're in single click mode */ + if (G_UNLIKELY (icon_view->priv->single_click)) + { + /* determine the item at the mouse coords and check if this is the last single clicked one */ + item = exo_icon_view_get_item_at_coords (icon_view, event->x, event->y, TRUE, NULL); + if (G_LIKELY (item != NULL && item == icon_view->priv->last_single_clicked)) + { + /* emit an "item-activated" signal for this item */ + path = gtk_tree_path_new_from_indices (item->index, -1); + exo_icon_view_item_activated (icon_view, path); + gtk_tree_path_free (path); + } + /* reset the last single clicked item */ + icon_view->priv->last_single_clicked = NULL; + } + + /* reset the pressed_button state */ + icon_view->priv->pressed_button = -1; + } + exo_icon_view_stop_rubberbanding (icon_view); remove_scroll_timeout (icon_view); @@ -3129,8 +3196,15 @@ icon_view->priv->cursor_item = NULL; if (G_UNLIKELY (item == icon_view->priv->prelit_item)) - icon_view->priv->prelit_item = NULL; + { + /* reset the prelit item */ + icon_view->priv->prelit_item = NULL; + /* in single click mode, we also reset the cursor when realized */ + if (G_UNLIKELY (icon_view->priv->single_click && GTK_WIDGET_REALIZED (icon_view))) + gdk_window_set_cursor (icon_view->priv->bin_window, NULL); + } + /* check if the selection changed */ if (G_UNLIKELY (item->selected)) changed = TRUE; @@ -4307,6 +4381,55 @@ /** + * exo_icon_view_get_single_click: + * @icon_view : a #ExoIconView. + * + * Returns %TRUE if @icon_view is currently in single click mode, + * else %FALSE will be returned. + * + * Return value: whether @icon_view is currently in single click mode. + * + * Since: 0.3.1.3 + **/ +gboolean +exo_icon_view_get_single_click (const ExoIconView *icon_view) +{ + g_return_val_if_fail (EXO_IS_ICON_VIEW (icon_view), FALSE); + return icon_view->priv->single_click; +} + + + +/** + * exo_icon_view_set_single_click: + * @icon_view : a #ExoIconView. + * @single_click : %TRUE for single click, %FALSE for double click mode. + * + * If @single_click is %TRUE, @icon_view will be in single click mode + * afterwards, else @icon_view will be in double click mode. + * + * Since: 0.3.1.3 + **/ +void +exo_icon_view_set_single_click (ExoIconView *icon_view, + gboolean single_click) +{ + g_return_if_fail (EXO_IS_ICON_VIEW (icon_view)); + + /* normalize the value */ + single_click = !!single_click; + + /* check if we have a new setting here */ + if (icon_view->priv->single_click != single_click) + { + icon_view->priv->single_click = single_click; + g_object_notify (G_OBJECT (icon_view), "single-click"); + } +} + + + +/** * exo_icon_view_get_model: * @icon_view : a #ExoIconView * @@ -4397,6 +4520,10 @@ icon_view->priv->last_single_clicked = NULL; icon_view->priv->width = 0; icon_view->priv->height = 0; + + /* reset cursor when in single click mode and realized */ + if (G_UNLIKELY (icon_view->priv->single_click && GTK_WIDGET_REALIZED (icon_view))) + gdk_window_set_cursor (icon_view->priv->bin_window, NULL); } /* activate the new model */