From e6ddacab747f5a8ad34a6673e29500167aa31e33 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 30 Apr 2011 13:37:07 +0200 Subject: [PATCH] Added properties to GObject. --- glade/gtkdateentry.xml | 7 ++++-- src/gtkdateentry.c | 52 ++++++++++++++++++++++++++++++++++++++++-- tests/date_entry.c | 6 ++--- 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/glade/gtkdateentry.xml b/glade/gtkdateentry.xml index b263365..4c3b22a 100644 --- a/glade/gtkdateentry.xml +++ b/glade/gtkdateentry.xml @@ -4,11 +4,14 @@ - + + + + - + diff --git a/src/gtkdateentry.c b/src/gtkdateentry.c index eeb5979..6dc7a56 100644 --- a/src/gtkdateentry.c +++ b/src/gtkdateentry.c @@ -33,7 +33,10 @@ enum { PROP_0, - PROP_EDITABLE_WITH_CALENDAR + PROP_SEPARATOR, + PROP_FORMAT, + PROP_EDITABLE_WITH_CALENDAR, + PROP_CALENDAR_BUTTON_VISIBLE }; static void gtk_date_entry_class_init (GtkDateEntryClass *klass); @@ -115,13 +118,34 @@ gtk_date_entry_class_init (GtkDateEntryClass *klass) widget_class->size_request = gtk_date_entry_size_request; widget_class->size_allocate = gtk_date_entry_size_allocate; + g_object_class_install_property (object_class, PROP_SEPARATOR, + g_param_spec_string ("separator", + "The separator", + "The separator between day, month and year", + "", + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, PROP_FORMAT, + g_param_spec_string ("format", + "The date's format", + "The date's format", + "", + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, PROP_EDITABLE_WITH_CALENDAR, - g_param_spec_boolean ("editable-with-calendar", + g_param_spec_boolean ("editable-from-calendar", "TRUE if it is editable only from calendar", "Determines if the user can edit the text" " in the #GtkDateEntry widget only from the calendar or not", FALSE, G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, PROP_CALENDAR_BUTTON_VISIBLE, + g_param_spec_boolean ("calendar-button-visible", + "TRUE to show the calendar's button", + "Determines if the calendar's button is visible or not", + TRUE, + G_PARAM_READWRITE)); } static void @@ -937,10 +961,22 @@ gtk_date_entry_set_property (GObject *object, guint property_id, const GValue *v switch (property_id) { + case PROP_SEPARATOR: + gtk_date_entry_set_separator (date_entry, g_value_get_string (value)); + break; + + case PROP_FORMAT: + gtk_date_entry_set_format (date_entry, g_value_get_string (value)); + break; + case PROP_EDITABLE_WITH_CALENDAR: gtk_date_entry_set_editable_with_calendar (date_entry, g_value_get_boolean (value)); break; + case PROP_CALENDAR_BUTTON_VISIBLE: + gtk_date_entry_set_calendar_button_visible (date_entry, g_value_get_boolean (value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -956,10 +992,22 @@ gtk_date_entry_get_property (GObject *object, guint property_id, GValue *value, switch (property_id) { + case PROP_SEPARATOR: + g_value_set_string (value, priv->separator); + break; + + case PROP_FORMAT: + g_value_set_string (value, priv->format); + break; + case PROP_EDITABLE_WITH_CALENDAR: g_value_set_boolean (value, priv->editable_with_calendar); break; + case PROP_CALENDAR_BUTTON_VISIBLE: + g_value_set_boolean (value, gtk_widget_get_visible (priv->btnCalendar)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; diff --git a/tests/date_entry.c b/tests/date_entry.c index f3bbc80..f841c19 100644 --- a/tests/date_entry.c +++ b/tests/date_entry.c @@ -90,12 +90,12 @@ on_tbtnEditableWithCalendar_toggled (GtkToggleButton *togglebutton, if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tbtnEditableWithCalendar))) { gtk_date_entry_set_editable_with_calendar (GTK_DATE_ENTRY (date), TRUE); - gtk_button_set_label (GTK_BUTTON (tbtnEditableWithCalendar), "Editable only with calendar"); + gtk_button_set_label (GTK_BUTTON (tbtnEditableWithCalendar), "Editable only from calendar"); } else { gtk_date_entry_set_editable_with_calendar (GTK_DATE_ENTRY (date), FALSE); - gtk_button_set_label (GTK_BUTTON (tbtnEditableWithCalendar), "Editable also with calendar"); + gtk_button_set_label (GTK_BUTTON (tbtnEditableWithCalendar), "Editable also from calendar"); } } @@ -197,7 +197,7 @@ main (int argc, char **argv) g_signal_connect (G_OBJECT (tbtnEditable), "toggled", G_CALLBACK (on_tbtnEditable_toggled), NULL); - tbtnEditableWithCalendar = gtk_toggle_button_new_with_label ("Editable also with calendar"); + tbtnEditableWithCalendar = gtk_toggle_button_new_with_label ("Editable also from calendar"); gtk_table_attach (GTK_TABLE (table), tbtnEditableWithCalendar, 1, 2, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); gtk_widget_show (tbtnEditableWithCalendar); -- 2.49.0