spinbutton: Add text property

This commit is contained in:
Timm Bäder 2017-05-04 20:48:50 +02:00 committed by Matthias Clasen
parent 37d6fd1ffa
commit f736b071b4
3 changed files with 56 additions and 0 deletions

View File

@ -2739,6 +2739,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

View File

@ -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;
@ -2253,3 +2267,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");
}

View File

@ -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