[gtk/prop-list: 32/37] columnviewcolumn: Add a reorderable property



commit e8feb09dc894f2c2338dd408aeb5653f3173d48b
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Dec 20 17:51:24 2019 -0500

    columnviewcolumn: Add a reorderable property
    
    This will be used for interactive column reordering
    in the future.

 gtk/gtkcolumnviewcolumn.c | 64 +++++++++++++++++++++++++++++++++++++++++++++--
 gtk/gtkcolumnviewcolumn.h |  6 +++++
 2 files changed, 68 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkcolumnviewcolumn.c b/gtk/gtkcolumnviewcolumn.c
index 0bf35d627f..53f6a77ed4 100644
--- a/gtk/gtkcolumnviewcolumn.c
+++ b/gtk/gtkcolumnviewcolumn.c
@@ -64,8 +64,9 @@ struct _GtkColumnViewColumn
 
   int fixed_width;
 
-  guint visible   : 1;
-  guint resizable : 1;
+  guint visible     : 1;
+  guint resizable   : 1;
+  guint reorderable : 1;
 
   /* This list isn't sorted - this is just caching for performance */
   GtkColumnViewCell *first_cell; /* no reference, just caching */
@@ -85,6 +86,7 @@ enum
   PROP_SORTER,
   PROP_VISIBLE,
   PROP_RESIZABLE,
+  PROP_REORDERABLE,
   PROP_FIXED_WIDTH,
 
   N_PROPS
@@ -143,6 +145,10 @@ gtk_column_view_column_get_property (GObject    *object,
       g_value_set_boolean (value, self->resizable);
       break;
 
+    case PROP_REORDERABLE:
+      g_value_set_boolean (value, self->reorderable);
+      break;
+
     case PROP_FIXED_WIDTH:
       g_value_set_int (value, self->fixed_width);
       break;
@@ -183,6 +189,10 @@ gtk_column_view_column_set_property (GObject      *object,
       gtk_column_view_column_set_resizable (self, g_value_get_boolean (value));
       break;
 
+    case PROP_REORDERABLE:
+      gtk_column_view_column_set_reorderable (self, g_value_get_boolean (value));
+      break;
+
     case PROP_FIXED_WIDTH:
       gtk_column_view_column_set_fixed_width (self, g_value_get_int (value));
       break;
@@ -269,6 +279,18 @@ gtk_column_view_column_class_init (GtkColumnViewColumnClass *klass)
                           TRUE,
                           G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
 
+  /**
+   * GtkColumnViewColumn:reorderable:
+   *
+   * Whether this column is reorderable 
+   */
+  properties[PROP_REORDERABLE] =
+    g_param_spec_boolean ("reorderable",
+                          P_("Reorderable"),
+                          P_("Whether this column is reorderable"),
+                          TRUE,
+                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
   properties[PROP_FIXED_WIDTH] =
     g_param_spec_int ("fixed-width",
                       P_("Fixed width"),
@@ -286,6 +308,7 @@ gtk_column_view_column_init (GtkColumnViewColumn *self)
   self->natural_size_request = -1;
   self->visible = TRUE;
   self->resizable = TRUE;
+  self->reorderable = TRUE;
   self->fixed_width = -1;
 }
 
@@ -810,6 +833,43 @@ gtk_column_view_column_get_resizable (GtkColumnViewColumn *self)
   return self->resizable;
 }
 
+/**
+ * gtk_column_view_column_set_reorderable:
+ * @self: a #GtkColumnViewColumn
+ * @reorderable: whether this column should be reorderable
+ *
+ * Sets whether this column should be reorderable by dragging.
+ */
+void
+gtk_column_view_column_set_reorderable (GtkColumnViewColumn *self,
+                                        gboolean             reorderable)
+{
+  g_return_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self));
+
+  if (self->reorderable == reorderable)
+    return;
+
+  self->reorderable = reorderable;
+
+  g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_REORDERABLE]);
+}
+
+/**
+ * gtk_column_view_get_reorderable:
+ * @self: a #GtkColumnView
+ *
+ * Returns whether this column is reorderable.
+ *
+ * Returns: %TRUE if this column is reorderable
+ */
+gboolean
+gtk_column_view_column_get_reorderable (GtkColumnViewColumn *self)
+{
+  g_return_val_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self), TRUE);
+
+  return self->reorderable;
+}
+
 void
 gtk_column_view_column_set_fixed_width (GtkColumnViewColumn *self,
                                         int                  fixed_width)
diff --git a/gtk/gtkcolumnviewcolumn.h b/gtk/gtkcolumnviewcolumn.h
index 3be8a1cb7d..5163cc587b 100644
--- a/gtk/gtkcolumnviewcolumn.h
+++ b/gtk/gtkcolumnviewcolumn.h
@@ -90,6 +90,12 @@ void                    gtk_column_view_column_set_resizable            (GtkColu
 GDK_AVAILABLE_IN_ALL
 gboolean                gtk_column_view_column_get_resizable            (GtkColumnViewColumn    *self);
 
+GDK_AVAILABLE_IN_ALL
+void                    gtk_column_view_column_set_reorderable          (GtkColumnViewColumn    *self,
+                                                                         gboolean                
reorderable);
+GDK_AVAILABLE_IN_ALL
+gboolean                gtk_column_view_column_get_reorderable          (GtkColumnViewColumn    *self);
+
 G_END_DECLS
 
 #endif  /* __GTK_COLUMN_VIEW_COLUMN_H__ */


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