[gtk/columnview-rubberbanding: 31/32] Add rubberband api



commit 58a0235a2e73305174c4feab9938cdb6f83e0372
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Dec 23 14:47:19 2019 -0500

    Add rubberband api
    
    Add an enable-rubberband property to GtkListView,
    GtkGridView and GtkColumnView.

 docs/reference/gtk/gtk4-sections.txt |  6 ++++
 gtk/gtkcolumnview.c                  | 58 ++++++++++++++++++++++++++++++++++++
 gtk/gtkcolumnview.h                  |  7 +++++
 gtk/gtkgridview.c                    | 58 ++++++++++++++++++++++++++++++++++++
 gtk/gtkgridview.h                    |  5 ++++
 gtk/gtklistview.c                    | 58 ++++++++++++++++++++++++++++++++++++
 gtk/gtklistview.h                    |  6 ++++
 7 files changed, 198 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 3cb238e74a..87f55a2193 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -489,6 +489,8 @@ gtk_list_view_set_show_separators
 gtk_list_view_get_show_separators
 gtk_list_view_set_single_click_activate
 gtk_list_view_get_single_click_activate
+gtk_list_view_set_enable_rubberband
+gtk_list_view_get_enable_rubberband
 <SUBSECTION Standard>
 GTK_LIST_VIEW
 GTK_LIST_VIEW_CLASS
@@ -517,6 +519,8 @@ gtk_column_view_set_show_separators
 gtk_column_view_sort_by_column
 gtk_column_view_set_single_click_activate
 gtk_column_view_get_single_click_activate
+gtk_column_view_set_enable_rubberband
+gtk_column_view_get_enable_rubberband
 <SUBSECTION Standard>
 GTK_COLUMN_VIEW
 GTK_COLUMN_VIEW_CLASS
@@ -573,6 +577,8 @@ gtk_grid_view_set_min_columns
 gtk_grid_view_get_min_columns
 gtk_grid_view_set_single_click_activate
 gtk_grid_view_get_single_click_activate
+gtk_grid_view_set_enable_rubberband
+gtk_grid_view_get_enable_rubberband
 <SUBSECTION Standard>
 GTK_GRID_VIEW
 GTK_GRID_VIEW_CLASS
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
index 17cdedf467..86671f1ae8 100644
--- a/gtk/gtkcolumnview.c
+++ b/gtk/gtkcolumnview.c
@@ -103,6 +103,7 @@ enum
   PROP_VADJUSTMENT,
   PROP_VSCROLL_POLICY,
   PROP_SINGLE_CLICK_ACTIVATE,
+  PROP_ENABLE_RUBBERBAND,
 
   N_PROPS
 };
@@ -394,6 +395,10 @@ gtk_column_view_get_property (GObject    *object,
       g_value_set_boolean (value, gtk_column_view_get_single_click_activate (self));
       break;
 
+    case PROP_ENABLE_RUBBERBAND:
+      g_value_set_boolean (value, gtk_column_view_get_enable_rubberband (self));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -465,6 +470,10 @@ gtk_column_view_set_property (GObject      *object,
       gtk_column_view_set_single_click_activate (self, g_value_get_boolean (value));
       break;
 
+    case PROP_ENABLE_RUBBERBAND:
+      gtk_column_view_set_enable_rubberband (self, g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -561,6 +570,18 @@ gtk_column_view_class_init (GtkColumnViewClass *klass)
                           FALSE,
                           G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * GtkColumnView:enable-rubberband:
+   *
+   * Allow rubberband selection
+   */
+  properties[PROP_ENABLE_RUBBERBAND] =
+    g_param_spec_boolean ("enable-rubberband",
+                          P_("Enable rubberband selection"),
+                          P_("Allow selecting items by dragging with the mouse"),
+                          FALSE,
+                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (gobject_class, N_PROPS, properties);
 
   /**
@@ -1342,3 +1363,40 @@ gtk_column_view_get_single_click_activate (GtkColumnView *self)
 
   return gtk_list_view_get_single_click_activate (self->listview);
 }
+
+/**
+ * gtk_column_view_set_enable_rubberband:
+ * @self: a #GtkColumnView
+ * @enable_rubberband: %TRUE to enable rubberband selection
+ *
+ * Sets whether selections can be changed by dragging with the mouse.
+ */
+void
+gtk_column_view_set_enable_rubberband (GtkColumnView *self,
+                                       gboolean       enable_rubberband)
+{
+  g_return_if_fail (GTK_IS_COLUMN_VIEW (self));
+
+  if (enable_rubberband == gtk_list_view_get_enable_rubberband (self->listview))
+    return;
+
+  gtk_list_view_set_enable_rubberband (self->listview, enable_rubberband);
+
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ENABLE_RUBBERBAND]);
+}
+
+/**
+ * gtk_column_view_get_enable_rubberband:
+ * @self: a #GtkColumnView
+ *
+ * Returns whether rows can be selected by dragging with the mouse.
+ *
+ * Returns: %TRUE if rubberband selection is enabled
+ */
+gboolean
+gtk_column_view_get_enable_rubberband (GtkColumnView *self)
+{
+  g_return_val_if_fail (GTK_IS_COLUMN_VIEW (self), FALSE);
+
+  return gtk_list_view_get_enable_rubberband (self->listview);
+}
diff --git a/gtk/gtkcolumnview.h b/gtk/gtkcolumnview.h
index 0866b6449c..8b38986417 100644
--- a/gtk/gtkcolumnview.h
+++ b/gtk/gtkcolumnview.h
@@ -92,6 +92,13 @@ void            gtk_column_view_set_single_click_activate       (GtkColumnView
 GDK_AVAILABLE_IN_ALL
 gboolean        gtk_column_view_get_single_click_activate       (GtkColumnView          *self);
 
+GDK_AVAILABLE_IN_ALL
+void            gtk_column_view_set_enable_rubberband           (GtkColumnView          *self,
+                                                                 gboolean                enable_rubberband);
+GDK_AVAILABLE_IN_ALL
+gboolean        gtk_column_view_get_enable_rubberband           (GtkColumnView          *self);
+
+
 G_END_DECLS
 
 #endif  /* __GTK_COLUMN_VIEW_H__ */
diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c
index debfcf0946..01feba2c16 100644
--- a/gtk/gtkgridview.c
+++ b/gtk/gtkgridview.c
@@ -91,6 +91,7 @@ enum
   PROP_MIN_COLUMNS,
   PROP_MODEL,
   PROP_SINGLE_CLICK_ACTIVATE,
+  PROP_ENABLE_RUBBERBAND,
 
   N_PROPS
 };
@@ -914,6 +915,10 @@ gtk_grid_view_get_property (GObject    *object,
       g_value_set_boolean (value, gtk_list_item_manager_get_single_click_activate (self->item_manager));
       break;
 
+    case PROP_ENABLE_RUBBERBAND:
+      g_value_set_boolean (value, gtk_list_base_get_enable_rubberband (GTK_LIST_BASE (self)));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -950,6 +955,10 @@ gtk_grid_view_set_property (GObject      *object,
       gtk_grid_view_set_single_click_activate (self, g_value_get_boolean (value));
       break;
 
+    case PROP_ENABLE_RUBBERBAND:
+      gtk_grid_view_set_enable_rubberband (self, g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -1062,6 +1071,18 @@ gtk_grid_view_class_init (GtkGridViewClass *klass)
                           FALSE,
                           G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * GtkGridView:enable-rubberband:
+   *
+   * Allow rubberband selection
+   */
+  properties[PROP_ENABLE_RUBBERBAND] =
+    g_param_spec_boolean ("enable-rubberband",
+                          P_("Enable rubberband selection"),
+                          P_("Allow selecting items by dragging with the mouse"),
+                          FALSE,
+                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (gobject_class, N_PROPS, properties);
 
   /**
@@ -1370,3 +1391,40 @@ gtk_grid_view_get_single_click_activate (GtkGridView *self)
 
   return gtk_list_item_manager_get_single_click_activate (self->item_manager);
 }
+
+/**
+ * gtk_grid_view_set_enable_rubberband:
+ * @self: a #GtkGridView
+ * @enable_rubberband: %TRUE to enable rubberband selection
+ *
+ * Sets whether selections can be changed by dragging with the mouse.
+ */
+void
+gtk_grid_view_set_enable_rubberband (GtkGridView *self,
+                                     gboolean     enable_rubberband)
+{
+  g_return_if_fail (GTK_IS_GRID_VIEW (self));
+
+  if (enable_rubberband == gtk_list_base_get_enable_rubberband (GTK_LIST_BASE (self)))
+    return;
+
+  gtk_list_base_set_enable_rubberband (GTK_LIST_BASE (self), enable_rubberband);
+
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ENABLE_RUBBERBAND]);
+}
+
+/**
+ * gtk_grid_view_get_enable_rubberband:
+ * @self: a #GtkGridView
+ *
+ * Returns whether rows can be selected by dragging with the mouse.
+ *
+ * Returns: %TRUE if rubberband selection is enabled
+ */
+gboolean
+gtk_grid_view_get_enable_rubberband (GtkGridView *self)
+{
+  g_return_val_if_fail (GTK_IS_GRID_VIEW (self), FALSE);
+
+  return gtk_list_base_get_enable_rubberband (GTK_LIST_BASE (self));
+}
diff --git a/gtk/gtkgridview.h b/gtk/gtkgridview.h
index 7b78fe15e8..6fb035ce12 100644
--- a/gtk/gtkgridview.h
+++ b/gtk/gtkgridview.h
@@ -73,6 +73,11 @@ guint           gtk_grid_view_get_max_columns                   (GtkGridView
 GDK_AVAILABLE_IN_ALL
 void            gtk_grid_view_set_max_columns                   (GtkGridView            *self,
                                                                  guint                   max_columns);
+GDK_AVAILABLE_IN_ALL
+void            gtk_grid_view_set_enable_rubberband             (GtkGridView            *self,
+                                                                 gboolean                enable_rubberband);
+GDK_AVAILABLE_IN_ALL
+gboolean        gtk_grid_view_get_enable_rubberband             (GtkGridView            *self);
 
 GDK_AVAILABLE_IN_ALL
 void            gtk_grid_view_set_single_click_activate         (GtkGridView            *self,
diff --git a/gtk/gtklistview.c b/gtk/gtklistview.c
index 30cd6bc847..ea757c1f41 100644
--- a/gtk/gtklistview.c
+++ b/gtk/gtklistview.c
@@ -85,6 +85,7 @@ enum
   PROP_MODEL,
   PROP_SHOW_SEPARATORS,
   PROP_SINGLE_CLICK_ACTIVATE,
+  PROP_ENABLE_RUBBERBAND,
 
   N_PROPS
 };
@@ -643,6 +644,10 @@ gtk_list_view_get_property (GObject    *object,
       g_value_set_boolean (value, gtk_list_item_manager_get_single_click_activate (self->item_manager));
       break;
 
+    case PROP_ENABLE_RUBBERBAND:
+      g_value_set_boolean (value, gtk_list_base_get_enable_rubberband (GTK_LIST_BASE (self)));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -675,6 +680,10 @@ gtk_list_view_set_property (GObject      *object,
       gtk_list_view_set_single_click_activate (self, g_value_get_boolean (value));
       break;
 
+    case PROP_ENABLE_RUBBERBAND:
+      gtk_list_view_set_enable_rubberband (self, g_value_get_boolean (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -771,6 +780,18 @@ gtk_list_view_class_init (GtkListViewClass *klass)
                           FALSE,
                           G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * GtkListView:enable-rubberband:
+   *
+   * Allow rubberband selection
+   */
+  properties[PROP_ENABLE_RUBBERBAND] =
+    g_param_spec_boolean ("enable-rubberband",
+                          P_("Enable rubberband selection"),
+                          P_("Allow selecting items by dragging with the mouse"),
+                          FALSE,
+                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (gobject_class, N_PROPS, properties);
 
   /**
@@ -1033,3 +1054,40 @@ gtk_list_view_get_single_click_activate (GtkListView *self)
 
   return gtk_list_item_manager_get_single_click_activate (self->item_manager);
 }
+
+/**
+ * gtk_list_view_set_enable_rubberband:
+ * @self: a #GtkListView
+ * @enable_rubberband: %TRUE to enable rubberband selection
+ *
+ * Sets whether selections can be changed by dragging with the mouse.
+ */
+void
+gtk_list_view_set_enable_rubberband (GtkListView *self,
+                                     gboolean     enable_rubberband)
+{
+  g_return_if_fail (GTK_IS_LIST_VIEW (self));
+
+  if (enable_rubberband == gtk_list_base_get_enable_rubberband (GTK_LIST_BASE (self)))
+    return;
+
+  gtk_list_base_set_enable_rubberband (GTK_LIST_BASE (self), enable_rubberband);
+
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ENABLE_RUBBERBAND]);
+}
+
+/**
+ * gtk_list_view_get_enable_rubberband:
+ * @self: a #GtkListView
+ *
+ * Returns whether rows can be selected by dragging with the mouse.
+ *
+ * Returns: %TRUE if rubberband selection is enabled
+ */
+gboolean
+gtk_list_view_get_enable_rubberband (GtkListView *self)
+{
+  g_return_val_if_fail (GTK_IS_LIST_VIEW (self), FALSE);
+
+  return gtk_list_base_get_enable_rubberband (GTK_LIST_BASE (self));
+}
diff --git a/gtk/gtklistview.h b/gtk/gtklistview.h
index f00bcf7e3f..afcfb6225f 100644
--- a/gtk/gtklistview.h
+++ b/gtk/gtklistview.h
@@ -75,6 +75,12 @@ void            gtk_list_view_set_single_click_activate         (GtkListView
 GDK_AVAILABLE_IN_ALL
 gboolean        gtk_list_view_get_single_click_activate         (GtkListView            *self);
 
+GDK_AVAILABLE_IN_ALL
+void            gtk_list_view_set_enable_rubberband             (GtkListView            *self,
+                                                                 gboolean                enable_rubberband);
+GDK_AVAILABLE_IN_ALL
+gboolean        gtk_list_view_get_enable_rubberband             (GtkListView            *self);
+
 G_END_DECLS
 
 #endif  /* __GTK_LIST_VIEW_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]