[gtk+/wip/baedert/drawing: 29/60] spinbutton: Add text property



commit a6b1f9470acd6c7e05406aa7c0679d97014ea517
Author: Timm Bäder <mail baedert org>
Date:   Thu May 4 20:48:50 2017 +0200

    spinbutton: Add text property

 docs/reference/gtk/gtk4-sections.txt |    2 +
 gtk/gtkspinbutton.c                  |   49 ++++++++++++++++++++++++++++++++++
 gtk/gtkspinbutton.h                  |    5 +++
 3 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index a40491c..082c286 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -2717,6 +2717,8 @@ gtk_spin_button_get_snap_to_ticks
 gtk_spin_button_get_update_policy
 gtk_spin_button_get_value
 gtk_spin_button_get_wrap
+gtk_spin_button_set_text
+gtk_spin_button_get_text
 GTK_INPUT_ERROR
 <SUBSECTION Standard>
 GTK_SPIN_BUTTON
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index 2266f89..7a00dca 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -220,6 +220,7 @@ enum {
   PROP_VALUE,
   PROP_WIDTH_CHARS,
   PROP_MAX_WIDTH_CHARS,
+  PROP_TEXT,
   PROP_ORIENTATION,
 };
 
@@ -414,6 +415,14 @@ gtk_spin_button_class_init (GtkSpinButtonClass *class)
                                                      -1,
                                                      GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
 
+  g_object_class_install_property (gobject_class,
+                                   PROP_TEXT,
+                                   g_param_spec_string ("text",
+                                   P_("Text"),
+                                   P_("The contents of the entry"),
+                                   "",
+                                   GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
+
   g_object_class_override_property (gobject_class,
                                     PROP_ORIENTATION,
                                     "orientation");
@@ -615,6 +624,9 @@ gtk_spin_button_set_property (GObject      *object,
     case PROP_MAX_WIDTH_CHARS:
       gtk_entry_set_max_width_chars (GTK_ENTRY (priv->entry), g_value_get_int (value));
       break;
+    case PROP_TEXT:
+      gtk_entry_set_text (GTK_ENTRY (priv->entry), g_value_get_string (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -665,6 +677,8 @@ gtk_spin_button_get_property (GObject      *object,
     case PROP_MAX_WIDTH_CHARS:
       g_value_set_int (value, gtk_entry_get_max_width_chars (GTK_ENTRY (priv->entry)));
       break;
+    case PROP_TEXT:
+      g_value_set_string (value, gtk_entry_get_text (GTK_ENTRY (priv->entry)));
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -2257,3 +2271,38 @@ gtk_spin_button_update (GtkSpinButton *spin_button)
   else
     gtk_spin_button_set_value (spin_button, val);
 }
+
+/**
+ * gtk_spin_button_get_text:
+ * @spin_button:
+ *
+ * Returns: (transfer none): The text
+ */
+const char *
+gtk_spin_button_get_text (GtkSpinButton *spin_button)
+{
+  GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button);
+
+  g_return_val_if_fail (GTK_IS_SPIN_BUTTON (spin_button), NULL);
+
+  return gtk_entry_get_text (GTK_ENTRY (priv->entry));
+}
+
+/**
+ * gtk_spin_button_set_text:
+ * @spin_button
+ *
+ *
+ */
+void
+gtk_spin_button_set_text (GtkSpinButton *spin_button,
+                          const char    *text)
+{
+  GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (spin_button);
+
+  g_return_if_fail (GTK_IS_SPIN_BUTTON (spin_button));
+
+  gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
+
+  g_object_notify (G_OBJECT (spin_button), "text");
+}
diff --git a/gtk/gtkspinbutton.h b/gtk/gtkspinbutton.h
index 4abadc8..5dc3b7c 100644
--- a/gtk/gtkspinbutton.h
+++ b/gtk/gtkspinbutton.h
@@ -227,6 +227,11 @@ GDK_AVAILABLE_IN_ALL
 gboolean        gtk_spin_button_get_snap_to_ticks  (GtkSpinButton  *spin_button);
 GDK_AVAILABLE_IN_ALL
 void            gtk_spin_button_update             (GtkSpinButton  *spin_button);
+GDK_AVAILABLE_IN_3_92
+const char *    gtk_spin_button_get_text           (GtkSpinButton *spin_button);
+GDK_AVAILABLE_IN_3_92
+void            gtk_spin_button_set_text           (GtkSpinButton *spin_button,
+                                                    const char    *text);
 
 G_END_DECLS
 


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