From: Andrea Zagli Date: Sun, 14 Jan 2007 09:56:53 +0000 (+0000) Subject: - GtkDateEntry struct is completely private X-Git-Tag: 0.0.3~12 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=2f61d58b5258858137e034c9da6cf15bc3633142;p=libgtkdateentry - GtkDateEntry struct is completely private - gtk_date_entry_set_format now returns a gboolean - changing separator or format there's no date's loss - autogen.sh: added --- diff --git a/ChangeLog b/ChangeLog index 99aae62..eace781 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-01-13 Andrea Zagli + + * gtkdateentry.h: + * gtkdateentry.c: + - GtkDateEntry struct is completely private + - gtk_date_entry_set_format now returns a gboolean + - changing separator or format there's no date's loss + * autogen.sh: added + 2006-12-23 Andrea Zagli * gtkdateentry.c: gtk_date_entry_get_strf now return "" if the date diff --git a/Makefile.am b/Makefile.am index e32411e..38c6302 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,8 @@ SUBDIRS = src tests docs -EXTRA_DIST = \ - libgtkdateentry.pc.in +EXTRA_DIST = libgtkdateentry.pc.in pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libgtkdateentry.pc + +DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..1f14fa9 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,98 @@ +#!/bin/sh +# Run this to generate all the initial makefiles, etc. + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +ORIGDIR=`pwd` +cd $srcdir +PROJECT=libgtkdateentry +TEST_TYPE=-f +FILE=configure.ac + +DIE=0 + +have_libtool=false +if libtoolize --version < /dev/null > /dev/null 2>&1 ; then + libtool_version=`libtoolize --version | sed 's/^[^0-9]*\([0-9.][0-9.]*\).*/\1/'` + case $libtool_version in + 1.4*|1.5*) + have_libtool=true + ;; + esac +fi +if $have_libtool ; then : ; else + echo + echo "You must have libtool 1.4 installed to compile $PROJECT." + echo "Install the appropriate package for your distribution," + echo "or get the source tarball at http://ftp.gnu.org/gnu/libtool/" + DIE=1 +fi + +(gtkdocize --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have gtk-doc installed to compile $PROJECT." + echo "Install the appropriate package for your distribution," + echo "or get the source tarball at http://ftp.gnome.org/pub/GNOME/sources/gtk-doc/" + DIE=1 +} + +(autoconf --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have autoconf installed to compile $PROJECT." + echo "Install the appropriate package for your distribution," + echo "or get the source tarball at http://ftp.gnu.org/gnu/autoconf/" + DIE=1 +} + +if automake --version < /dev/null > /dev/null 2>&1 ; then + AUTOMAKE=automake + ACLOCAL=aclocal +else + echo + echo "You must have automake 1.7.x installed to compile $PROJECT." + echo "Install the appropriate package for your distribution," + echo "or get the source tarball at http://ftp.gnu.org/gnu/automake/" + DIE=1 +fi + +if test "$DIE" -eq 1; then + exit 1 +fi + +test $TEST_TYPE $FILE || { + echo "You must run this script in the top-level $PROJECT directory" + exit 1 +} + +if test -z "$AUTOGEN_SUBDIR_MODE"; then + if test -z "$*"; then + echo "I am going to run ./configure with no arguments - if you wish " + echo "to pass any to it, please specify them on the $0 command line." + fi +fi + +rm -rf autom4te.cache + +# README and INSTALL are required by automake, but may be deleted by clean +# up rules. to get automake to work, simply touch these here, they will be +# regenerated from their corresponding *.in files by ./configure anyway. +touch README INSTALL + +$ACLOCAL || exit $? + +libtoolize --force || exit $? +gtkdocize || exit $? + +autoheader || exit $? + +$AUTOMAKE --add-missing || exit $? +autoconf || exit $? +cd $ORIGDIR || exit $? + +if test -z "$AUTOGEN_SUBDIR_MODE"; then + $srcdir/configure --enable-maintainer-mode $AUTOGEN_CONFIGURE_ARGS "$@" || exit $? + + echo + echo "Now type 'make' to compile $PROJECT." +fi diff --git a/configure.ac b/configure.ac index ea138b5..53cae48 100644 --- a/configure.ac +++ b/configure.ac @@ -43,5 +43,6 @@ AC_CONFIG_FILES([ tests/Makefile docs/Makefile docs/reference/Makefile + docs/reference/version.xml ]) AC_OUTPUT diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am index aa0dbe5..0aa7bad 100644 --- a/docs/reference/Makefile.am +++ b/docs/reference/Makefile.am @@ -55,7 +55,7 @@ HTML_IMAGES= # Extra SGML files that are included by $(DOC_MAIN_SGML_FILE). # e.g. content_files=running.sgml building.sgml changes-2.0.sgml -content_files= +content_files = version.xml # SGML files where gtk-doc abbrevations (#GtkWidget) are expanded # These files must be listed here *and* in content_files @@ -68,11 +68,11 @@ expand_content_files= # e.g. INCLUDES=-I$(top_srcdir) -I$(top_builddir) $(GTK_DEBUG_FLAGS) # e.g. GTKDOC_LIBS=$(top_builddir)/gtk/$(gtktargetlib) INCLUDES = -I$(top_srcdir)/src $(GTKDATEENTRY_CFLAGS) -GTKDOC_LIBS = $(top_srcdir)/src/libgtkdateentry.la $(GTKDATEENTRY_LIBS) +GTKDOC_LIBS = $(top_builddir)/src/libgtkdateentry.la $(GTKDATEENTRY_LIBS) # This includes the standard gtk-doc make rules, copied by gtkdocize. include $(top_srcdir)/gtk-doc.make # Other files to distribute # e.g. EXTRA_DIST += version.xml.in -EXTRA_DIST += +EXTRA_DIST += version.xml.in diff --git a/docs/reference/gtkdateentry-docs.sgml b/docs/reference/gtkdateentry-docs.sgml index ebbd405..d5f8533 100644 --- a/docs/reference/gtkdateentry-docs.sgml +++ b/docs/reference/gtkdateentry-docs.sgml @@ -1,13 +1,16 @@ + "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [ + +]> - [Insert name here] Reference Manual + GtkDateEntry Reference Manual + for GtkDateEntry &version; - [Insert title here] + GtkDateEntry diff --git a/docs/reference/gtkdateentry-sections.txt b/docs/reference/gtkdateentry-sections.txt index f6d7f63..2b40615 100644 --- a/docs/reference/gtkdateentry-sections.txt +++ b/docs/reference/gtkdateentry-sections.txt @@ -1,26 +1,20 @@
gtkdateentry -GTK_TYPE_DATE_ENTRY -GTK_DATE_ENTRY -GTK_DATE_ENTRY_CLASS -GTK_DATE_ENTRY_GET_CLASS GtkDateEntry +GtkDateEntry gtk_date_entry_new gtk_date_entry_set_separator gtk_date_entry_set_format gtk_date_entry_get_text gtk_date_entry_get_strf -gtk_date_entry_get_tm -gtk_date_entry_get_gdate -gtk_date_entry_set_date_strf -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_calendar_button_visible +GTK_TYPE_DATE_ENTRY +GTK_DATE_ENTRY +GTK_DATE_ENTRY_CLASS +GTK_DATE_ENTRY_GET_CLASS GTK_IS_DATE -gtk_date_entry_get_type GTK_IS_DATE_CLASS + +gtk_date_entry_get_type
diff --git a/docs/reference/gtkdateentry-undocumented.txt b/docs/reference/gtkdateentry-undocumented.txt index 86287d8..e0a7490 100644 --- a/docs/reference/gtkdateentry-undocumented.txt +++ b/docs/reference/gtkdateentry-undocumented.txt @@ -1,14 +1,9 @@ -68% symbol docs coverage. -13 symbols documented. +88% symbol docs coverage. +7 symbols documented. 0 symbols incomplete. -6 not documented. +1 not documented. -GTK_DATE_ENTRY -GTK_DATE_ENTRY_CLASS -GTK_DATE_ENTRY_GET_CLASS -GTK_TYPE_DATE_ENTRY gtk_date_entry_get_strf -gtkdateentry:Short_Description diff --git a/docs/reference/tmpl/gtkdateentry-unused.sgml b/docs/reference/tmpl/gtkdateentry-unused.sgml index e69de29..b0f165c 100644 --- a/docs/reference/tmpl/gtkdateentry-unused.sgml +++ b/docs/reference/tmpl/gtkdateentry-unused.sgml @@ -0,0 +1,27 @@ + + + + + +@obj: + + + + + + +@klass: + + + + + + +@obj: + + + + + + + diff --git a/docs/reference/tmpl/gtkdateentry.sgml b/docs/reference/tmpl/gtkdateentry.sgml index 866611f..c22b087 100644 --- a/docs/reference/tmpl/gtkdateentry.sgml +++ b/docs/reference/tmpl/gtkdateentry.sgml @@ -2,7 +2,7 @@ GtkDateEntry - +A Gtk+ widget that simplifies date input. @@ -17,37 +17,12 @@ GtkDateEntry - + - +The #GtkDateEntry struct contains private data only, and should be manipulated using the functions below. - - - - - - -@obj: - - - - - - - -@klass: - - - - - - - -@obj: - - @@ -75,6 +50,7 @@ GtkDateEntry @date: @format: +@Returns: @@ -97,78 +73,3 @@ GtkDateEntry @Returns: - - - - - -@date: -@Returns: - - - - - - - -@date: -@Returns: - - - - - - - -@date: -@str: -@format: -@separator: -@Returns: - - - - - - - -@date: -@tmdate: - - - - - - - -@date: -@gdate: - - - - - - - -@date: -@Returns: - - - - - - - -@date: -@is_editable: - - - - - - - -@date: -@is_visible: - - diff --git a/docs/reference/version.xml.in b/docs/reference/version.xml.in new file mode 100644 index 0000000..c5d0fd6 --- /dev/null +++ b/docs/reference/version.xml.in @@ -0,0 +1,2 @@ +@PACKAGE_VERSION@ + diff --git a/src/gtkdateentry.c b/src/gtkdateentry.c index 34b8568..45baf05 100644 --- a/src/gtkdateentry.c +++ b/src/gtkdateentry.c @@ -23,6 +23,7 @@ #include +#include #include #include #include @@ -57,6 +58,21 @@ static void calendar_on_day_selected_double_click (GtkCalendar *calendar, static GtkWidgetClass *parent_class = NULL; + +#define GTK_DATE_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_DATE_ENTRY, GtkDateEntryPrivate)) + +typedef struct _GtkDateEntryPrivate GtkDateEntryPrivate; +struct _GtkDateEntryPrivate + { + GtkWidget *day; + GtkWidget *btnCalendar; + GtkWidget *wCalendar; + GtkWidget *calendar; + + gchar separator; + gchar *format; + }; + GType gtk_date_entry_get_type (void) { @@ -77,19 +93,24 @@ gtk_date_entry_get_type (void) (GInstanceInitFunc) gtk_date_entry_init, }; - date_type = g_type_register_static (GTK_TYPE_HBOX, "GtkDateEntry", &date_info, 0); + date_type = g_type_register_static (GTK_TYPE_HBOX, "GtkDateEntry", + &date_info, 0); } return date_type; } static void -gtk_date_entry_class_init (GtkDateEntryClass *class) +gtk_date_entry_class_init (GtkDateEntryClass *klass) { GtkWidgetClass *widget_class; - widget_class = (GtkWidgetClass*) class; - parent_class = g_type_class_peek_parent (class); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (object_class, sizeof (GtkDateEntryPrivate)); + + widget_class = (GtkWidgetClass*) klass; + parent_class = g_type_class_peek_parent (klass); } static void @@ -97,50 +118,52 @@ gtk_date_entry_init (GtkDateEntry *date) { GtkWidget *arrow; + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + /* TO DO * read separator and format from locale settings */ - date->separator = '/'; - date->format = g_strdup ("dmY"); + priv->separator = '/'; + priv->format = g_strdup ("dmY"); - date->day = gtk_masked_entry_new (); + priv->day = gtk_masked_entry_new (); gtk_date_entry_change_mask (date); - gtk_box_pack_start (GTK_BOX (date), date->day, TRUE, TRUE, 0); - gtk_widget_show (date->day); + gtk_box_pack_start (GTK_BOX (date), priv->day, TRUE, TRUE, 0); + gtk_widget_show (priv->day); - date->btnCalendar = gtk_toggle_button_new (); - gtk_box_pack_start (GTK_BOX (date), date->btnCalendar, FALSE, FALSE, 0); - gtk_widget_set_no_show_all (date->btnCalendar, TRUE); - gtk_widget_show (date->btnCalendar); + priv->btnCalendar = gtk_toggle_button_new (); + gtk_box_pack_start (GTK_BOX (date), priv->btnCalendar, FALSE, FALSE, 0); + gtk_widget_set_no_show_all (priv->btnCalendar, TRUE); + gtk_widget_show (priv->btnCalendar); - g_signal_connect (G_OBJECT (date->btnCalendar), "toggled", + g_signal_connect (G_OBJECT (priv->btnCalendar), "toggled", G_CALLBACK (btnCalendar_on_toggled), (gpointer)date); arrow = (GtkWidget *)gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE); - gtk_container_add (GTK_CONTAINER (date->btnCalendar), arrow); + gtk_container_add (GTK_CONTAINER (priv->btnCalendar), arrow); gtk_widget_show (arrow); - date->wCalendar = gtk_window_new (GTK_WINDOW_POPUP); - gtk_window_set_resizable (GTK_WINDOW (date->wCalendar), FALSE); - gtk_container_set_border_width (GTK_CONTAINER (date->wCalendar), 3); + priv->wCalendar = gtk_window_new (GTK_WINDOW_POPUP); + gtk_window_set_resizable (GTK_WINDOW (priv->wCalendar), FALSE); + gtk_container_set_border_width (GTK_CONTAINER (priv->wCalendar), 3); - gtk_widget_set_events (date->wCalendar, - gtk_widget_get_events (date->wCalendar) | GDK_KEY_PRESS_MASK); + gtk_widget_set_events (priv->wCalendar, + gtk_widget_get_events (priv->wCalendar) | GDK_KEY_PRESS_MASK); - g_signal_connect (date->wCalendar, "delete_event", + g_signal_connect (priv->wCalendar, "delete_event", G_CALLBACK (delete_popup), date); - g_signal_connect (date->wCalendar, "key_press_event", + g_signal_connect (priv->wCalendar, "key_press_event", G_CALLBACK (key_press_popup), date); - g_signal_connect (date->wCalendar, "button_press_event", + g_signal_connect (priv->wCalendar, "button_press_event", G_CALLBACK (button_press_popup), date); - date->calendar = gtk_calendar_new (); - gtk_container_add (GTK_CONTAINER (date->wCalendar), date->calendar); - gtk_widget_show (date->calendar); + priv->calendar = gtk_calendar_new (); + gtk_container_add (GTK_CONTAINER (priv->wCalendar), priv->calendar); + gtk_widget_show (priv->calendar); - g_signal_connect (G_OBJECT (date->calendar), "day-selected", + g_signal_connect (G_OBJECT (priv->calendar), "day-selected", G_CALLBACK (calendar_on_day_selected), (gpointer)date); - g_signal_connect (G_OBJECT (date->calendar), "day-selected-double-click", + g_signal_connect (G_OBJECT (priv->calendar), "day-selected-double-click", G_CALLBACK (calendar_on_day_selected_double_click), (gpointer)date); } @@ -156,14 +179,14 @@ gtk_date_entry_init (GtkDateEntry *date) * * Creates a new #GtkDateEntry. * - * Return value: The newly created #GtkDateEntry widget. - **/ + * Returns: The newly created #GtkDateEntry widget. + */ GtkWidget *gtk_date_entry_new (const gchar *format, const gchar separator, gboolean calendar_button_is_visible) { GtkWidget *w = GTK_WIDGET (g_object_new (gtk_date_entry_get_type (), NULL)); - gtk_date_entry_set_format (GTK_DATE_ENTRY (w), format); + if (!gtk_date_entry_set_format (GTK_DATE_ENTRY (w), format)) return NULL; gtk_date_entry_set_separator (GTK_DATE_ENTRY (w), separator); gtk_date_entry_set_calendar_button_visible (GTK_DATE_ENTRY (w), calendar_button_is_visible); @@ -173,34 +196,53 @@ GtkWidget /** * gtk_date_entry_set_separator: - * @date: a #GtkDateEntry. + * @date: a #GtkDateEntry object. * @separator: a #gchar that represents the separator between day, month and year. * * Set the separator between day, month and year. - **/ + */ void gtk_date_entry_set_separator (GtkDateEntry *date, const gchar separator) { - date->separator = separator; + GDate *gdate = gtk_date_entry_get_gdate (date); + + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + + priv->separator = separator; gtk_date_entry_change_mask (date); + gtk_date_entry_set_date_gdate (date, gdate); } /** * gtk_date_entry_set_format: - * @date: a #GtkDateEntry. + * @date: a #GtkDateEntry object. * @format: a #gchar which is the date's format. * * Sets the date's format. - **/ -void + * + * Returns: FALSE if @format isn't a valid date format. + */ +gboolean gtk_date_entry_set_format (GtkDateEntry *date, const gchar *format) { gint i; - gboolean d, m, y; + gboolean d = FALSE; + gboolean m = FALSE; + gboolean y = FALSE; + gchar *format_; + GDate *gdate; + + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); - if (strlen (format) != 3) + if (format == NULL) { - return; + return FALSE; + } + + format_ = g_strstrip (g_strdup (format)); + if (strlen (format_) != 3) + { + return FALSE; } for (i = 0; i < 3; i++) @@ -208,62 +250,71 @@ gtk_date_entry_set_format (GtkDateEntry *date, const gchar *format) switch (format[i]) { case 'd': - if (d) return; + if (d) return FALSE; d = TRUE; break; case 'm': - if (m) return; + if (m) return FALSE; m = TRUE; break; case 'Y': - if (y) return; + if (y) return FALSE; y = TRUE; break; default: - return; + return FALSE; } } - if (!d || !m || !y) return; + if (!d || !m || !y) return FALSE; + + gdate = gtk_date_entry_get_gdate (date); - date->format = g_strdup (format); + priv->format = g_strdup (format); gtk_date_entry_change_mask (date); + gtk_date_entry_set_date_gdate (date, gdate); + + return TRUE; } /** * gtk_date_entry_get_text: - * @date: a #GtkDateEntry. + * @date: a #GtkDateEntry object. * * Returns the @date's content as is. * - * Return value: A pointer to the content of the widget as is. - **/ + * Returns: A pointer to the content of the widget as is. + */ const gchar *gtk_date_entry_get_text (GtkDateEntry *date) { - return gtk_entry_get_text (GTK_ENTRY (date->day)); + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + + return gtk_entry_get_text (GTK_ENTRY (priv->day)); } /** * gtk_date_entry_get_strf: - * @date: a #GtkDateEntry. + * @date: a #GtkDateEntry object. * @format: a #gchar which is the date's format. * @separator: a #gchar which is the separator between day, month and year. * - * Return value: A pointer to the content of the widget formatted as - * specified in @format with @separator. - **/ + * Returns: A pointer to the content of the widget formatted as specified in + * @format with @separator. + */ const gchar *gtk_date_entry_get_strf (GtkDateEntry *date, const gchar *format, - const gchar separator) + gchar separator) { gchar *fmt, sep, *ret = ""; gint i; GDate *gdate = (GDate *)gtk_date_entry_get_gdate (date); + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + if (gdate == NULL) { return ""; @@ -271,7 +322,7 @@ const gchar if (format == NULL) { - fmt = date->format; + fmt = priv->format; } else { @@ -279,7 +330,7 @@ const gchar } if (separator == 0) { - sep = date->separator; + sep = priv->separator; } else { @@ -314,13 +365,11 @@ const gchar /** * gtk_date_entry_get_tm: - * @date: a #GtkDateEntry - * - * Returns the @date's content as a tm struct. + * @date: a #GtkDateEntry object. * - * Return value: the @date's content as a tm struct. + * Returns: the @date's content as a struct tm. */ -const struct tm +struct tm *gtk_date_entry_get_tm (GtkDateEntry *date) { struct tm tm; @@ -331,30 +380,30 @@ const struct tm g_date_to_struct_tm (gdate, &tm); - return (const struct tm *)g_memdup ((gconstpointer)&tm, sizeof (struct tm)); + return (struct tm *)g_memdup ((gconstpointer)&tm, sizeof (struct tm)); } /** * gtk_date_entry_get_gdate: - * @date: a #GtkDateEntry. + * @date: a #GtkDateEntry object. * - * Returns the @date's content as a #GDate. - * - * Return value: the @date's content as a #GDate. + * Returns: the @date's content as a #GDate. */ -const GDate +GDate *gtk_date_entry_get_gdate (GtkDateEntry *date) { gint i, pos = 0, val; gchar *txt; GDate *gdate; - txt = (gchar *)gtk_entry_get_text (GTK_ENTRY (date->day)); + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + + txt = (gchar *)gtk_entry_get_text (GTK_ENTRY (priv->day)); gdate = g_date_new (); for (i = 0; i < 3; i++) { - switch (date->format[i]) + switch (priv->format[i]) { case 'd': val = atol (g_strndup (txt + pos, 2)); @@ -397,7 +446,7 @@ const GDate } } - return (const GDate *)gdate; + return gdate; } /** @@ -410,7 +459,7 @@ const GDate * Sets @date's content from the @str string and based on @format and @separator, * if it's a valid date. * - * Return value: TRUE if @date's content is setted. + * Returns: TRUE if @date's content is setted. */ gboolean gtk_date_entry_set_date_strf (GtkDateEntry *date, @@ -426,9 +475,11 @@ gtk_date_entry_set_date_strf (GtkDateEntry *date, gint i; gint pos = 0; + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + if (format == NULL) { - fmt = date->format; + fmt = priv->format; } else { @@ -436,7 +487,7 @@ gtk_date_entry_set_date_strf (GtkDateEntry *date, } if (separator == 0) { - sep = date->separator; + sep = priv->separator; } else { @@ -509,9 +560,13 @@ gtk_date_entry_set_date_gdate (GtkDateEntry *date, const GDate *gdate) gint i; gchar *txt = ""; + if (gdate == NULL || !g_date_valid (gdate)) return; + + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + for (i = 0; i < 3; i++) { - switch (date->format[i]) + switch (priv->format[i]) { case 'd': txt = g_strjoin (NULL, txt, g_strdup_printf ("%02d", g_date_get_day (gdate)), NULL); @@ -528,11 +583,11 @@ gtk_date_entry_set_date_gdate (GtkDateEntry *date, const GDate *gdate) if (i < 2) { - txt = g_strjoin (NULL, txt, g_strdup_printf ("%c", date->separator), NULL); + txt = g_strjoin (NULL, txt, g_strdup_printf ("%c", priv->separator), NULL); } } - gtk_entry_set_text (GTK_ENTRY (date->day), txt); + gtk_entry_set_text (GTK_ENTRY (priv->day), txt); } /** @@ -541,7 +596,7 @@ gtk_date_entry_set_date_gdate (GtkDateEntry *date, const GDate *gdate) * * Checks if @date's content is a valid date. * - * Return value: TRUE if @date's content is a valid date. + * Returns: TRUE if @date's content is a valid date. **/ gboolean gtk_date_entry_is_valid (GtkDateEntry *date) @@ -568,7 +623,10 @@ void gtk_date_entry_set_editable (GtkDateEntry *date, gboolean is_editable) { - gtk_editable_set_editable (GTK_EDITABLE (date->day), is_editable); + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + + gtk_editable_set_editable (GTK_EDITABLE (priv->day), is_editable); + gtk_widget_set_sensitive (priv->btnCalendar, is_editable); } /** @@ -582,13 +640,15 @@ void gtk_date_entry_set_calendar_button_visible (GtkDateEntry *date, gboolean is_visible) { + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + if (is_visible) { - gtk_widget_show (date->btnCalendar); + gtk_widget_show (priv->btnCalendar); } else { - gtk_widget_hide (date->btnCalendar); + gtk_widget_hide (priv->btnCalendar); } } @@ -599,13 +659,15 @@ gtk_date_entry_change_mask (GtkDateEntry *date) gchar *mask, *format[3]; gint i; + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + for (i = 0; i < 3; i++) { - if (date->format[i] == 'd' || date->format[i] == 'm') + if (priv->format[i] == 'd' || priv->format[i] == 'm') { format[i] = g_strdup ("00"); } - else if (date->format[i] == 'Y') + else if (priv->format[i] == 'Y') { format[i] = g_strdup ("0000"); } @@ -613,11 +675,11 @@ gtk_date_entry_change_mask (GtkDateEntry *date) mask = g_strdup_printf ("%s%c%s%c%s", format[0], - date->separator, + priv->separator, format[1], - date->separator, + priv->separator, format[2]); - gtk_masked_entry_set_mask (GTK_MASKED_ENTRY (date->day), mask); + gtk_masked_entry_set_mask (GTK_MASKED_ENTRY (priv->day), mask); } /* @@ -626,10 +688,11 @@ gtk_date_entry_change_mask (GtkDateEntry *date) static void hide_popup (GtkWidget *date) { - GtkDateEntry *de = (GtkDateEntry *)date; - gtk_widget_hide (de->wCalendar); - gtk_grab_remove (de->wCalendar); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (de->btnCalendar), FALSE); + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE ((GtkDateEntry *)date); + + gtk_widget_hide (priv->wCalendar); + gtk_grab_remove (priv->wCalendar); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->btnCalendar), FALSE); } static gboolean @@ -723,19 +786,22 @@ btnCalendar_on_toggled (GtkToggleButton *togglebutton, { if (gtk_toggle_button_get_active (togglebutton)) { + GtkDateEntry *date = (GtkDateEntry *)user_data; + GtkDateEntryPrivate *priv = GTK_DATE_ENTRY_GET_PRIVATE (date); + gint x, y, bwidth, bheight; GtkRequisition req; - GtkWidget *btn = ((GtkDateEntry *)user_data)->btnCalendar, - *wCalendar = ((GtkDateEntry *)user_data)->wCalendar; + GtkWidget *btn = priv->btnCalendar, + *wCalendar = priv->wCalendar; /* sets current date */ - const GDate *gdate = gtk_date_entry_get_gdate ((GtkDateEntry *)user_data); + const GDate *gdate = gtk_date_entry_get_gdate (date); if (gdate != NULL) { - gtk_calendar_select_month (GTK_CALENDAR (((GtkDateEntry *)user_data)->calendar), + gtk_calendar_select_month (GTK_CALENDAR (priv->calendar), (guint)g_date_get_month (gdate) - 1, (guint)g_date_get_year (gdate)); - gtk_calendar_select_day (GTK_CALENDAR (((GtkDateEntry *)user_data)->calendar), + gtk_calendar_select_day (GTK_CALENDAR (priv->calendar), (guint)g_date_get_day (gdate)); } @@ -754,7 +820,7 @@ btnCalendar_on_toggled (GtkToggleButton *togglebutton, gtk_grab_add (wCalendar); gtk_window_move (GTK_WINDOW (wCalendar), x, y); gtk_widget_show (wCalendar); - gtk_widget_grab_focus (((GtkDateEntry *)user_data)->calendar); + gtk_widget_grab_focus (priv->calendar); popup_grab_on_window (wCalendar->window, gtk_get_current_event_time ()); } } diff --git a/src/gtkdateentry.h b/src/gtkdateentry.h index 21a0105..7c0d83d 100644 --- a/src/gtkdateentry.h +++ b/src/gtkdateentry.h @@ -45,14 +45,6 @@ typedef struct _GtkDateEntryClass GtkDateEntryClass; struct _GtkDateEntry { GtkHBox hbox; - - GtkWidget *day, - *btnCalendar, - *wCalendar, - *calendar; - - gchar separator, - *format; }; struct _GtkDateEntryClass @@ -69,16 +61,16 @@ GtkWidget *gtk_date_entry_new (const gchar *format, void gtk_date_entry_set_separator (GtkDateEntry *date, const gchar separator); -void gtk_date_entry_set_format (GtkDateEntry *date, - const gchar *format); +gboolean gtk_date_entry_set_format (GtkDateEntry *date, + const gchar *format); const gchar *gtk_date_entry_get_text (GtkDateEntry *date); const gchar *gtk_date_entry_get_strf (GtkDateEntry *date, const gchar *format, - const gchar separator); + gchar separator); -const struct tm *gtk_date_entry_get_tm (GtkDateEntry *date); -const GDate *gtk_date_entry_get_gdate (GtkDateEntry *date); +struct tm *gtk_date_entry_get_tm (GtkDateEntry *date); +GDate *gtk_date_entry_get_gdate (GtkDateEntry *date); gboolean gtk_date_entry_set_date_strf (GtkDateEntry *date, const gchar *str, diff --git a/tests/Makefile.am b/tests/Makefile.am index 0fdc73f..71b524f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,8 +1,10 @@ AM_CPPFLAGS = $(WARN_CFLAGS) \ $(DISABLE_DEPRECATED_CFLAGS) \ - $(GTKDATEENTRY_CFLAGS) - -I../src + $(GTKDATEENTRY_CFLAGS) \ + -I$(top_srcdir)/src -LDADD = ../src/libgtkdateentry.la +LIBS = $(GTKDATEENTRY_LIBS) + +LDADD = $(top_builddir)/src/libgtkdateentry.la noinst_PROGRAMS = date_entry diff --git a/tests/date_entry.c b/tests/date_entry.c index 9bee8d8..029923b 100644 --- a/tests/date_entry.c +++ b/tests/date_entry.c @@ -1,6 +1,6 @@ #include -#include "gtkdateentry.h" +#include GtkWidget *window, *table, @@ -12,7 +12,9 @@ GtkWidget *window, *txtSetStrf, *txtSetStrfFormat, *txtSetStrfSep, - *btnSetStrf; + *btnSetStrf, + *tbtnEditable, + *tbtnSensitive; static void on_btnSeparator_clicked (GtkButton *button, @@ -26,8 +28,12 @@ static void on_btnFormat_clicked (GtkButton *button, gpointer user_data) { - gtk_date_entry_set_format (GTK_DATE_ENTRY (date), - (const gchar *)gtk_entry_get_text (GTK_ENTRY (format))); + const gchar *str_format = gtk_entry_get_text (GTK_ENTRY (format)); + + if (!gtk_date_entry_set_format (GTK_DATE_ENTRY (date), str_format)) + { + g_warning ("Error on gtk_date_entry_set_format (%s).", str_format); + } } static void @@ -39,6 +45,38 @@ on_btnSetStrf_clicked (GtkButton *button, NULL, 0); } +static void +on_tbtnEditable_toggled (GtkToggleButton *togglebutton, + gpointer user_data) +{ + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tbtnEditable))) + { + gtk_date_entry_set_editable (GTK_DATE_ENTRY (date), FALSE); + gtk_button_set_label (GTK_BUTTON (tbtnEditable), "Not Editable"); + } + else + { + gtk_date_entry_set_editable (GTK_DATE_ENTRY (date), TRUE); + gtk_button_set_label (GTK_BUTTON (tbtnEditable), "Editable"); + } +} + +static void +on_tbtnSensitive_toggled (GtkToggleButton *togglebutton, + gpointer user_data) +{ + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tbtnSensitive))) + { + gtk_widget_set_sensitive (date, FALSE); + gtk_button_set_label (GTK_BUTTON (tbtnSensitive), "Not Sensitive"); + } + else + { + gtk_widget_set_sensitive (date, TRUE); + gtk_button_set_label (GTK_BUTTON (tbtnSensitive), "Sensitive"); + } +} + int main (int argc, char **argv) { @@ -53,7 +91,7 @@ main (int argc, char **argv) g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); - table = gtk_table_new (4, 3, FALSE); + table = gtk_table_new (5, 3, FALSE); gtk_container_add (GTK_CONTAINER (window), table); gtk_widget_show (table); @@ -114,6 +152,20 @@ main (int argc, char **argv) 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); + + g_signal_connect (G_OBJECT (tbtnEditable), "toggled", + G_CALLBACK (on_tbtnEditable_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); + + g_signal_connect (G_OBJECT (tbtnSensitive), "toggled", + G_CALLBACK (on_tbtnSensitive_toggled), NULL); + gtk_widget_show (window); gtk_main ();