/*
* GtkDateEntry widget for GTK+
*
- * Copyright (C) 2005-2006 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#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);
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;
gchar separator;
gchar *format;
+ gboolean editable_with_calendar;
};
GType
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
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.
{
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;
+ }
+}
+/*
+ * GtkDateEntry widget for GTK+
+ *
+ * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ *
+ * 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 <gtk/gtk.h>
#include <gtkdateentry.h>
-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,
}
}
+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)
{
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;
}