From: Andrea Zagli Date: Wed, 11 Nov 2009 17:28:22 +0000 (+0100) Subject: Added property editable-with-calendar. X-Git-Tag: 0.0.3~8^2~1 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=b0d061919fb4ded56d30bb3c68b7749424333b9a;p=libgtkdateentry Added property editable-with-calendar. --- diff --git a/configure.ac b/configure.ac index 53cae48..f1f10f0 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ(2.59) -AC_INIT([GtkDateEntry], [0.0.2], [azagli@inwind.it]) +AC_INIT([GtkDateEntry], [0.0.3], [azagli@libero.it]) AC_CONFIG_SRCDIR([src/gtkdateentry.c]) AC_CONFIG_HEADER([config.h]) diff --git a/docs/reference/gtkdateentry-decl-list.txt b/docs/reference/gtkdateentry-decl-list.txt index 925b073..b060f65 100644 --- a/docs/reference/gtkdateentry-decl-list.txt +++ b/docs/reference/gtkdateentry-decl-list.txt @@ -18,6 +18,7 @@ gtk_date_entry_set_date_tm gtk_date_entry_set_date_gdate gtk_date_entry_is_valid gtk_date_entry_set_editable +gtk_date_entry_set_editable_with_calendar gtk_date_entry_set_calendar_button_visible GTK_IS_DATE diff --git a/docs/reference/gtkdateentry-decl.txt b/docs/reference/gtkdateentry-decl.txt index d017b05..b34e66d 100644 --- a/docs/reference/gtkdateentry-decl.txt +++ b/docs/reference/gtkdateentry-decl.txt @@ -108,6 +108,11 @@ GtkDateEntry *date GtkDateEntry *date,gboolean is_editable +gtk_date_entry_set_editable_with_calendar +void +GtkDateEntry *date,gboolean is_editable_with_calendar + + gtk_date_entry_set_calendar_button_visible void GtkDateEntry *date,gboolean is_visible diff --git a/docs/reference/gtkdateentry-undocumented.txt b/docs/reference/gtkdateentry-undocumented.txt index 36fc823..bc71459 100644 --- a/docs/reference/gtkdateentry-undocumented.txt +++ b/docs/reference/gtkdateentry-undocumented.txt @@ -1,5 +1,5 @@ -81% symbol docs coverage. -13 symbols documented. +83% symbol docs coverage. +15 symbols documented. 0 symbols incomplete. 3 not documented. diff --git a/docs/reference/gtkdateentry-unused.txt b/docs/reference/gtkdateentry-unused.txt index 1ffae14..ccad406 100644 --- a/docs/reference/gtkdateentry-unused.txt +++ b/docs/reference/gtkdateentry-unused.txt @@ -7,3 +7,4 @@ gtk_date_entry_set_date_gdate gtk_date_entry_set_date_strf gtk_date_entry_set_date_tm gtk_date_entry_set_editable +gtk_date_entry_set_editable_with_calendar diff --git a/docs/reference/gtkdateentry.args b/docs/reference/gtkdateentry.args index e69de29..c2ba606 100644 --- a/docs/reference/gtkdateentry.args +++ b/docs/reference/gtkdateentry.args @@ -0,0 +1,10 @@ + +GtkDateEntry::editable-with-calendar +gboolean + +rw +Tabulation inside the widget +Whether pressing tab moves between mask's parts or outside the widget. +FALSE + + diff --git a/docs/reference/tmpl/gtkdateentry.sgml b/docs/reference/tmpl/gtkdateentry.sgml index 82935a3..6460425 100644 --- a/docs/reference/tmpl/gtkdateentry.sgml +++ b/docs/reference/tmpl/gtkdateentry.sgml @@ -24,6 +24,11 @@ using the functions below. + + + + + diff --git a/src/gtkdateentry.c b/src/gtkdateentry.c index 45baf05..d62428f 100644 --- a/src/gtkdateentry.c +++ b/src/gtkdateentry.c @@ -1,7 +1,7 @@ /* * GtkDateEntry widget for GTK+ * - * Copyright (C) 2005-2006 Andrea Zagli + * Copyright (C) 2005-2009 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -33,6 +33,12 @@ #include "gtkdateentry.h" +enum +{ + PROP_0, + PROP_EDITABLE_WITH_CALENDAR +}; + static void gtk_date_entry_class_init (GtkDateEntryClass *klass); static void gtk_date_entry_init (GtkDateEntry *date); @@ -56,6 +62,15 @@ static void calendar_on_day_selected (GtkCalendar *calendar, static void calendar_on_day_selected_double_click (GtkCalendar *calendar, gpointer user_data); +static void gtk_date_entry_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void gtk_date_entry_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + static GtkWidgetClass *parent_class = NULL; @@ -71,6 +86,7 @@ struct _GtkDateEntryPrivate gchar separator; gchar *format; + gboolean editable_with_calendar; }; GType @@ -111,6 +127,16 @@ gtk_date_entry_class_init (GtkDateEntryClass *klass) widget_class = (GtkWidgetClass*) klass; parent_class = g_type_class_peek_parent (klass); + + object_class->set_property = gtk_date_entry_set_property; + object_class->get_property = gtk_date_entry_get_property; + + g_object_class_install_property (object_class, PROP_EDITABLE_WITH_CALENDAR, + g_param_spec_boolean ("editable-with-calendar", + "Tabulation inside the widget", + "Whether pressing tab moves between mask's parts or outside the widget", + FALSE, + G_PARAM_READWRITE)); } static void @@ -629,6 +655,24 @@ gtk_date_entry_set_editable (GtkDateEntry *date, gtk_widget_set_sensitive (priv->btnCalendar, is_editable); } +/** + * gtk_date_entry_set_editable_with_calendar: + * @date: a #GtkDateEntry. + * @is_editable_with_calendar: TRUE if the user is allowed to edit the text + * in the widget only from the calendar. + * + * Determines if the user can edit the text in the #GtkDateEntry widget only + * from the calendar or not. + */ +void +gtk_date_entry_set_editable_with_calendar (GtkDateEntry *date, + gboolean is_editable_with_calendar) +{ + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + + gtk_editable_set_editable (GTK_EDITABLE (priv->day), !is_editable_with_calendar); +} + /** * gtk_date_entry_set_calendar_button_visible: * @date: a #GtkDateEntry. @@ -844,3 +888,41 @@ calendar_on_day_selected_double_click (GtkCalendar *calendar, { hide_popup ((GtkWidget *)user_data); } + +static void +gtk_date_entry_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + GtkDateEntry *date_entry = GTK_DATE_ENTRY (object); + + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date_entry); + + switch (property_id) + { + case PROP_EDITABLE_WITH_CALENDAR: + gtk_date_entry_set_editable_with_calendar (date_entry, g_value_get_boolean (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gtk_date_entry_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + GtkDateEntry *date_entry = GTK_DATE_ENTRY (object); + + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date_entry); + + switch (property_id) + { + case PROP_EDITABLE_WITH_CALENDAR: + g_value_set_boolean (value, priv->editable_with_calendar); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/src/gtkdateentry.h b/src/gtkdateentry.h index 7c0d83d..89cc9e6 100644 --- a/src/gtkdateentry.h +++ b/src/gtkdateentry.h @@ -1,7 +1,7 @@ /* * GtkDateEntry widget for GTK+ * - * Copyright (C) 2005-2006 Andrea Zagli + * Copyright (C) 2005-2009 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -86,6 +86,8 @@ gboolean gtk_date_entry_is_valid (GtkDateEntry *date); void gtk_date_entry_set_editable (GtkDateEntry *date, gboolean is_editable); +void gtk_date_entry_set_editable_with_calendar (GtkDateEntry *date, + gboolean is_editable_with_calendar); void gtk_date_entry_set_calendar_button_visible (GtkDateEntry *date, gboolean is_visible); diff --git a/tests/date_entry.c b/tests/date_entry.c index 029923b..f538a6c 100644 --- a/tests/date_entry.c +++ b/tests/date_entry.c @@ -1,20 +1,42 @@ +/* + * GtkDateEntry widget for GTK+ + * + * Copyright (C) 2005-2009 Andrea Zagli + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + #include #include -GtkWidget *window, - *table, - *date, - *separator, - *btnSeparator, - *format, - *btnFormat, - *txtSetStrf, - *txtSetStrfFormat, - *txtSetStrfSep, - *btnSetStrf, - *tbtnEditable, - *tbtnSensitive; +GtkWidget *window; +GtkWidget *table; +GtkWidget *date; +GtkWidget *separator; +GtkWidget *btnSeparator; +GtkWidget *format; +GtkWidget *btnFormat; +GtkWidget *txtSetStrf; +GtkWidget *txtSetStrfFormat; +GtkWidget *txtSetStrfSep; +GtkWidget *btnSetStrf; +GtkWidget *tbtnEditable; +GtkWidget *tbtnEditableWithCalendar; +GtkWidget *tbtnSensitive; static void on_btnSeparator_clicked (GtkButton *button, @@ -61,6 +83,22 @@ on_tbtnEditable_toggled (GtkToggleButton *togglebutton, } } +static void +on_tbtnEditableWithCalendar_toggled (GtkToggleButton *togglebutton, + gpointer user_data) +{ + 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"); + } + else + { + gtk_date_entry_set_editable_with_calendar (GTK_DATE_ENTRY (date), FALSE); + gtk_button_set_label (GTK_BUTTON (tbtnEditableWithCalendar), "Editable also with calendar"); + } +} + static void on_tbtnSensitive_toggled (GtkToggleButton *togglebutton, gpointer user_data) @@ -82,93 +120,100 @@ main (int argc, char **argv) { GtkWidget *label; - gtk_init (&argc, &argv); + gtk_init (&argc, &argv); - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "GtkDateEntry Test"); + gtk_window_set_title (GTK_WINDOW (window), "GtkDateEntry Test"); - g_signal_connect (G_OBJECT (window), "destroy", - G_CALLBACK (gtk_main_quit), NULL); + g_signal_connect (G_OBJECT (window), "destroy", + G_CALLBACK (gtk_main_quit), NULL); - table = gtk_table_new (5, 3, FALSE); - gtk_container_add (GTK_CONTAINER (window), table); - gtk_widget_show (table); + table = gtk_table_new (5, 3, FALSE); + gtk_container_add (GTK_CONTAINER (window), table); + gtk_widget_show (table); label = gtk_label_new ("GtkDateEntry"); - gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (label); + gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_show (label); - date = gtk_date_entry_new ("dmY", '/', TRUE); - gtk_table_attach (GTK_TABLE (table), date, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (date); + date = gtk_date_entry_new ("dmY", '/', TRUE); + gtk_table_attach (GTK_TABLE (table), date, 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_show (date); label = gtk_label_new ("Separator"); - gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (label); + gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_show (label); - separator = gtk_entry_new (); + separator = gtk_entry_new (); gtk_entry_set_text (GTK_ENTRY (separator), "/"); gtk_entry_set_max_length (GTK_ENTRY (separator), 1); - gtk_table_attach (GTK_TABLE (table), separator, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (separator); + gtk_table_attach (GTK_TABLE (table), separator, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_show (separator); - btnSeparator = gtk_button_new_with_label ("Set separator"); - gtk_table_attach (GTK_TABLE (table), btnSeparator, 2, 3, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (btnSeparator); + btnSeparator = gtk_button_new_with_label ("Set separator"); + gtk_table_attach (GTK_TABLE (table), btnSeparator, 2, 3, 1, 2, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_show (btnSeparator); g_signal_connect (G_OBJECT (btnSeparator), "clicked", - G_CALLBACK (on_btnSeparator_clicked), NULL); + G_CALLBACK (on_btnSeparator_clicked), NULL); label = gtk_label_new ("Format"); - gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (label); + gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_show (label); - format = gtk_entry_new (); + format = gtk_entry_new (); gtk_entry_set_text (GTK_ENTRY (format), "dmY"); gtk_entry_set_max_length (GTK_ENTRY (format), 3); - gtk_table_attach (GTK_TABLE (table), format, 1, 2, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (format); + gtk_table_attach (GTK_TABLE (table), format, 1, 2, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_show (format); - btnFormat = gtk_button_new_with_label ("Set format"); - gtk_table_attach (GTK_TABLE (table), btnFormat, 2, 3, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (btnFormat); + btnFormat = gtk_button_new_with_label ("Set format"); + gtk_table_attach (GTK_TABLE (table), btnFormat, 2, 3, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_show (btnFormat); g_signal_connect (G_OBJECT (btnFormat), "clicked", G_CALLBACK (on_btnFormat_clicked), NULL); label = gtk_label_new ("Strf"); - gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (label); + gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_show (label); - txtSetStrf = gtk_entry_new (); - gtk_table_attach (GTK_TABLE (table), txtSetStrf, 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (txtSetStrf); + txtSetStrf = gtk_entry_new (); + gtk_table_attach (GTK_TABLE (table), txtSetStrf, 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_show (txtSetStrf); - btnSetStrf = gtk_button_new_with_label ("set_date_strf"); - gtk_table_attach (GTK_TABLE (table), btnSetStrf, 2, 3, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (btnSetStrf); + btnSetStrf = gtk_button_new_with_label ("set_date_strf"); + gtk_table_attach (GTK_TABLE (table), btnSetStrf, 2, 3, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_show (btnSetStrf); g_signal_connect (G_OBJECT (btnSetStrf), "clicked", G_CALLBACK (on_btnSetStrf_clicked), NULL); tbtnEditable = gtk_toggle_button_new_with_label ("Editable"); - gtk_table_attach (GTK_TABLE (table), tbtnEditable, 0, 1, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (tbtnEditable); + gtk_table_attach (GTK_TABLE (table), tbtnEditable, 0, 1, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_show (tbtnEditable); g_signal_connect (G_OBJECT (tbtnEditable), "toggled", G_CALLBACK (on_tbtnEditable_toggled), NULL); + tbtnEditableWithCalendar = gtk_toggle_button_new_with_label ("Editable also with 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); + + g_signal_connect (G_OBJECT (tbtnEditableWithCalendar), "toggled", + G_CALLBACK (on_tbtnEditableWithCalendar_toggled), NULL); + tbtnSensitive = gtk_toggle_button_new_with_label ("Sensitive"); - gtk_table_attach (GTK_TABLE (table), tbtnSensitive, 1, 2, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (tbtnSensitive); + gtk_table_attach (GTK_TABLE (table), tbtnSensitive, 2, 3, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); + gtk_widget_show (tbtnSensitive); g_signal_connect (G_OBJECT (tbtnSensitive), "toggled", G_CALLBACK (on_tbtnSensitive_toggled), NULL); gtk_widget_show (window); - gtk_main (); - - return 0; + gtk_main (); + + return 0; }