[gtk/matthiasc/for-master: 6/7] expression: Add some introspection



commit 7b36b339aa953b0b8ff07c88f91d8ec9d3642848
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Jul 13 20:19:07 2020 -0400

    expression: Add some introspection
    
    Add a few apis to peek inside expressions, mainly
    for the benefit of GtkInspector and similar uses.

 docs/reference/gtk/gtk4-sections.txt |  4 ++
 gtk/gtkexpression.c                  | 74 ++++++++++++++++++++++++++++++++++++
 gtk/gtkexpression.h                  | 11 ++++++
 3 files changed, 89 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 481b890c34..564dd410c9 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -7541,9 +7541,13 @@ gtk_expression_watch_unwatch
 <SUBSECTION>
 gtk_property_expression_new
 gtk_property_expression_new_for_pspec
+gtk_property_expression_get_expression
+gtk_property_expression_get_pspec
 gtk_constant_expression_new
 gtk_constant_expression_new_for_value
+gtk_constant_expression_get_value
 gtk_object_expression_new
+gtk_object_expression_get_object
 gtk_closure_expression_new
 gtk_cclosure_expression_new
 
diff --git a/gtk/gtkexpression.c b/gtk/gtkexpression.c
index 180a1e4858..829acc781f 100644
--- a/gtk/gtkexpression.c
+++ b/gtk/gtkexpression.c
@@ -855,6 +855,24 @@ gtk_constant_expression_new_for_value (const GValue *value)
   return result;
 }
 
+/**
+ * gtk_constant_expression_get_value:
+ * @expression: a constant #GtkExpression
+ *
+ * Gets the value that a constant expression evaluates to.
+ *
+ * Returns: (transfer none): the value
+ */
+const GValue *
+gtk_constant_expression_get_value (GtkExpression *expression)
+{
+  GtkConstantExpression *self = (GtkConstantExpression *) expression;
+
+  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (expression, GTK_TYPE_CONSTANT_EXPRESSION), NULL);
+
+  return &self->value;
+}
+
 /* }}} */
 
 /* {{{ GtkObjectExpression */
@@ -1002,6 +1020,24 @@ gtk_object_expression_new (GObject *object)
   return result;
 }
 
+/**
+ * gtk_object_expression_get_object:
+ * @expression: an object #GtkExpression
+ *
+ * Gets the object that the expression evaluates to.
+ *
+ * Returns: (transfer none): the object, or %NULL
+ */
+GObject *
+gtk_object_expression_get_object (GtkExpression *expression)
+{
+  GtkObjectExpression *self = (GtkObjectExpression *) expression;
+
+  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (expression, GTK_TYPE_OBJECT_EXPRESSION), NULL);
+
+  return self->object;
+}
+
 /* }}} */
 
 /* {{{ GtkPropertyExpression */
@@ -1307,6 +1343,44 @@ gtk_property_expression_new_for_pspec (GtkExpression *expression,
   return result;
 }
 
+/**
+ * gtk_property_expression_get_expression:
+ * @expression: a property #GtkExpression
+ *
+ * Gets the expression specifying the object of
+ * a property expression.
+ *
+ * Returns: (transfer none): the object expression
+ */
+GtkExpression *
+gtk_property_expression_get_expression (GtkExpression *expression)
+{
+  GtkPropertyExpression *self = (GtkPropertyExpression *) expression;
+
+  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (expression, GTK_TYPE_PROPERTY_EXPRESSION), NULL);
+
+  return self->expr;
+}
+
+/**
+ * gtk_property_expression_get_pspec:
+ * @expression: a property #GtkExpression
+ *
+ * Gets the #GParamSpec specifying the property of
+ * a property expression.
+ *
+ * Returns: (transfer none): the #GParamSpec
+ */
+GParamSpec *
+gtk_property_expression_get_pspec (GtkExpression *expression)
+{
+  GtkPropertyExpression *self = (GtkPropertyExpression *) expression;
+
+  g_return_val_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (expression, GTK_TYPE_PROPERTY_EXPRESSION), NULL);
+
+  return self->pspec;
+}
+
 /* }}} */
 
 /* {{{ GtkClosureExpression */
diff --git a/gtk/gtkexpression.h b/gtk/gtkexpression.h
index 44bebf75bb..2eb9650142 100644
--- a/gtk/gtkexpression.h
+++ b/gtk/gtkexpression.h
@@ -93,6 +93,11 @@ GDK_AVAILABLE_IN_ALL
 GtkExpression *         gtk_property_expression_new_for_pspec   (GtkExpression                  *expression,
                                                                  GParamSpec                     *pspec);
 
+GDK_AVAILABLE_IN_ALL
+GtkExpression *         gtk_property_expression_get_expression  (GtkExpression                  *expression);
+GDK_AVAILABLE_IN_ALL
+GParamSpec *            gtk_property_expression_get_pspec       (GtkExpression                  *expression);
+
 #define GTK_TYPE_CONSTANT_EXPRESSION (gtk_constant_expression_get_type())
 typedef struct _GtkConstantExpression   GtkConstantExpression;
 
@@ -105,6 +110,9 @@ GtkExpression *         gtk_constant_expression_new             (GType
 GDK_AVAILABLE_IN_ALL
 GtkExpression *         gtk_constant_expression_new_for_value   (const GValue                   *value);
 
+GDK_AVAILABLE_IN_ALL
+const GValue *          gtk_constant_expression_get_value       (GtkExpression                  *expression);
+
 #define GTK_TYPE_OBJECT_EXPRESSION (gtk_object_expression_get_type())
 typedef struct _GtkObjectExpression     GtkObjectExpression;
 
@@ -114,6 +122,9 @@ GType                   gtk_object_expression_get_type          (void) G_GNUC_CO
 GDK_AVAILABLE_IN_ALL
 GtkExpression *         gtk_object_expression_new               (GObject                        *object);
 
+GDK_AVAILABLE_IN_ALL
+GObject *               gtk_object_expression_get_object        (GtkExpression                  *expression);
+
 #define GTK_TYPE_CLOSURE_EXPRESSION (gtk_closure_expression_get_type())
 typedef struct _GtkClosureExpression    GtkClosureExpression;
 


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