]> saetta.ns0.it Git - libgtkdateentry/commitdiff
- GtkDateEntry struct is completely private
authorAndrea Zagli <azagli@libero.it>
Sun, 14 Jan 2007 09:56:53 +0000 (09:56 +0000)
committerAndrea Zagli <azagli@libero.it>
Sun, 14 Jan 2007 09:56:53 +0000 (09:56 +0000)
- gtk_date_entry_set_format now returns a gboolean
- changing separator or format there's no date's loss
- autogen.sh: added

15 files changed:
ChangeLog
Makefile.am
autogen.sh [new file with mode: 0755]
configure.ac
docs/reference/Makefile.am
docs/reference/gtkdateentry-docs.sgml
docs/reference/gtkdateentry-sections.txt
docs/reference/gtkdateentry-undocumented.txt
docs/reference/tmpl/gtkdateentry-unused.sgml
docs/reference/tmpl/gtkdateentry.sgml
docs/reference/version.xml.in [new file with mode: 0644]
src/gtkdateentry.c
src/gtkdateentry.h
tests/Makefile.am
tests/date_entry.c

index 99aae6285186976aec4284f194477a45da6f2446..eace781ed6ca361c70a572bb4c0c8d1a69640562 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-01-13 Andrea Zagli <azagli@inwind.it>
+
+       * 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 <azagli@inwind.it>
 
        * gtkdateentry.c: gtk_date_entry_get_strf now return "" if the date
index e32411e66e0a6d0b27d12b4f7e25ac14014d16d5..38c630203af024114406bc3c3287e02d8e26a85f 100644 (file)
@@ -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 (executable)
index 0000000..1f14fa9
--- /dev/null
@@ -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
index ea138b55567a5096a331f14d63ba138bbbaec48a..53cae48880814f4ec32e976b8912cdb425227475 100644 (file)
@@ -43,5 +43,6 @@ AC_CONFIG_FILES([
   tests/Makefile
   docs/Makefile
   docs/reference/Makefile
+  docs/reference/version.xml
 ])
 AC_OUTPUT
index aa0dbe53f6d6980e3f873d4a6b6cfeca9e928edf..0aa7badf18c8488c9a1fcaa2273dc4753d4316c7 100644 (file)
@@ -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 
index ebbd4058a52c5cb2371b7bb0c80feebfa1e8986e..d5f8533b2603335b276ef53d76ba8664f6fef87f 100644 (file)
@@ -1,13 +1,16 @@
 <?xml version="1.0"?>
 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 
-               "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
+               "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
+<!ENTITY version SYSTEM "version.xml">
+]>
 <book id="index" xmlns:xi="http://www.w3.org/2003/XInclude">
   <bookinfo>
-    <title>[Insert name here] Reference Manual</title>
+    <title>GtkDateEntry Reference Manual</title>
+    <releaseinfo>for GtkDateEntry &version;</releaseinfo>
   </bookinfo>
 
   <chapter>
-    <title>[Insert title here]</title>
+    <title>GtkDateEntry</title>
     <xi:include href="xml/gtkdateentry.xml"/>
   </chapter>
 </book>
index f6d7f631d7cabf429d55caacdf7b5fce8e22cfef..2b40615f583601293e3a0d850f5b7b87b120fba2 100644 (file)
@@ -1,26 +1,20 @@
 <SECTION>
 <FILE>gtkdateentry</FILE>
-GTK_TYPE_DATE_ENTRY
-GTK_DATE_ENTRY
-GTK_DATE_ENTRY_CLASS
-GTK_DATE_ENTRY_GET_CLASS
 <TITLE>GtkDateEntry</TITLE>
+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
 <SUBSECTION Standard>
+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
+<SUBSECTION Private>
+gtk_date_entry_get_type
 </SECTION>
 
index 86287d829e2c12790ac4b560a714604fcaa36e59..e0a749003e3d1124140224d8e93e6c3ab3bd33d3 100644 (file)
@@ -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
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..b0f165c8cf15d6362eddae143a742eea006cd4b5 100644 (file)
@@ -0,0 +1,27 @@
+<!-- ##### MACRO GTK_DATE_ENTRY ##### -->
+<para>
+
+</para>
+
+@obj: 
+
+<!-- ##### MACRO GTK_DATE_ENTRY_CLASS ##### -->
+<para>
+
+</para>
+
+@klass: 
+
+<!-- ##### MACRO GTK_DATE_ENTRY_GET_CLASS ##### -->
+<para>
+
+</para>
+
+@obj: 
+
+<!-- ##### MACRO GTK_TYPE_DATE_ENTRY ##### -->
+<para>
+
+</para>
+
+
index 866611f358331c94953e8753a66c86d3633c6040..c22b0875411f343b30ce22827fe9fd1ff822acdf 100644 (file)
@@ -2,7 +2,7 @@
 GtkDateEntry
 
 <!-- ##### SECTION Short_Description ##### -->
-
+A Gtk+ widget that simplifies date input.
 
 <!-- ##### SECTION Long_Description ##### -->
 <para>
@@ -17,37 +17,12 @@ GtkDateEntry
 <!-- ##### SECTION Stability_Level ##### -->
 
 
-<!-- ##### MACRO GTK_TYPE_DATE_ENTRY ##### -->
+<!-- ##### STRUCT GtkDateEntry ##### -->
 <para>
-
+The #GtkDateEntry struct contains private data only, and should be manipulated using the functions below.
 </para>
 
 
-
-<!-- ##### MACRO GTK_DATE_ENTRY ##### -->
-<para>
-
-</para>
-
-@obj: 
-
-
-<!-- ##### MACRO GTK_DATE_ENTRY_CLASS ##### -->
-<para>
-
-</para>
-
-@klass: 
-
-
-<!-- ##### MACRO GTK_DATE_ENTRY_GET_CLASS ##### -->
-<para>
-
-</para>
-
-@obj: 
-
-
 <!-- ##### FUNCTION gtk_date_entry_new ##### -->
 <para>
 
@@ -75,6 +50,7 @@ GtkDateEntry
 
 @date: 
 @format: 
+@Returns: 
 
 
 <!-- ##### FUNCTION gtk_date_entry_get_text ##### -->
@@ -97,78 +73,3 @@ GtkDateEntry
 @Returns: 
 
 
-<!-- ##### FUNCTION gtk_date_entry_get_tm ##### -->
-<para>
-
-</para>
-
-@date: 
-@Returns: 
-
-
-<!-- ##### FUNCTION gtk_date_entry_get_gdate ##### -->
-<para>
-
-</para>
-
-@date: 
-@Returns: 
-
-
-<!-- ##### FUNCTION gtk_date_entry_set_date_strf ##### -->
-<para>
-
-</para>
-
-@date: 
-@str: 
-@format: 
-@separator: 
-@Returns: 
-
-
-<!-- ##### FUNCTION gtk_date_entry_set_date_tm ##### -->
-<para>
-
-</para>
-
-@date: 
-@tmdate: 
-
-
-<!-- ##### FUNCTION gtk_date_entry_set_date_gdate ##### -->
-<para>
-
-</para>
-
-@date: 
-@gdate: 
-
-
-<!-- ##### FUNCTION gtk_date_entry_is_valid ##### -->
-<para>
-
-</para>
-
-@date: 
-@Returns: 
-
-
-<!-- ##### FUNCTION gtk_date_entry_set_editable ##### -->
-<para>
-
-</para>
-
-@date: 
-@is_editable: 
-
-
-<!-- ##### FUNCTION gtk_date_entry_set_calendar_button_visible ##### -->
-<para>
-
-</para>
-
-@date: 
-@is_visible: 
-
-
diff --git a/docs/reference/version.xml.in b/docs/reference/version.xml.in
new file mode 100644 (file)
index 0000000..c5d0fd6
--- /dev/null
@@ -0,0 +1,2 @@
+@PACKAGE_VERSION@
+
index 34b8568334a5eeecebeba565d02219b21f587db6..45baf051fac57f80276aa934e3b74e381a58742b 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <gdk/gdkkeysyms.h>
 
+#include <gtk/gtkmain.h>
 #include <gtk/gtkhbox.h>
 #include <gtk/gtktogglebutton.h>
 #include <gtk/gtkwindow.h>
@@ -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 ());
                }
 }
index 21a01059c9a396dc35c333fca3705ff19afe4051..7c0d83d29f3f1e0a209b328b100ffc0264864c8c 100644 (file)
@@ -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,
index 0fdc73f060cc859cd254e0e3e28d203dce71c1f3..71b524fbef37d684815d5b50269c39d1d691c787 100644 (file)
@@ -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
index 9bee8d8f215cd2566b7c9389ab431c00800baf6f..029923b96368b8492bfa8801bc4ccd974ed7196c 100644 (file)
@@ -1,6 +1,6 @@
 #include <gtk/gtk.h>
 
-#include "gtkdateentry.h"
+#include <gtkdateentry.h>
 
 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 ();