From: Andrea Zagli Date: Fri, 22 Dec 2006 10:23:47 +0000 (+0000) Subject: Some bugfixes and added widgetcombobox and widgetdateentry. X-Git-Tag: 0.1.0~45 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=3ee5fdf5b89c8db3c0254821a9208be9d5541621;p=libgtkform Some bugfixes and added widgetcombobox and widgetdateentry. --- diff --git a/ChangeLog b/ChangeLog index e69de29..30474e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -0,0 +1,23 @@ +2006-12-21 Andrea Zagli + + * libform.h: + * form.c: form_get_field_from_name, form_get_widget_from_name + * libformfield.h: + * field.c: added form_field_get_form_widget + * libformwidget.h: + * widget.c: added form_widget_get_widget_name + +2006-12-20 Andrea Zagli + + * configure.ac: changed version to 0.0.2 + Added GtkDateEntry as dependency. + * libformkey.h: + * formkey.c: added form_key_add_fields + * libformdatetime.h: + * formdatetime.c: added field's type (date and time, only date or only time) + * libform.h: + * form.c: added form_add_fields + * libformwidgetdateentry.h: + * widgetdateentry.c: added to manage GtkDateEntry + * libformwidgetcombobox.h: + * widgetcombobox.c: added to manage GtkComboBox diff --git a/configure.ac b/configure.ac index 80384f0..822ac9f 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT([libform], [0.0.1], [azagli@inwind.it]) +AC_INIT([libform], [0.0.2], [azagli@inwind.it]) AC_CONFIG_SRCDIR([src/form.c]) AC_CONFIG_HEADER([config.h]) @@ -27,7 +27,8 @@ GTK_DOC_CHECK # Checks for libraries. PKG_CHECK_MODULES(FORM, [gtk+-2.0 >= 2.6.0 libglade-2.0 >= 2.0.0 - libgdaobj >= 0.0.2]) + libgdaobj >= 0.0.2 + libgtkdateentry >= 0.0.2]) AC_SUBST(FORM_CFLAGS) AC_SUBST(FORM_LIBS) diff --git a/docs/reference/libform-undocumented.txt b/docs/reference/libform-undocumented.txt index 432c88b..e78c3cb 100644 --- a/docs/reference/libform-undocumented.txt +++ b/docs/reference/libform-undocumented.txt @@ -1,7 +1,7 @@ -6% symbol docs coverage. -13 symbols documented. -1 symbols incomplete. -216 not documented. +5% symbol docs coverage. +12 symbols documented. +0 symbols incomplete. +217 not documented. FORM @@ -105,7 +105,7 @@ TYPE_FORM_WIDGET_SPIN TYPE_FORM_WIDGET_TEXTVIEW form_add_field form_check -form_clear (Returns) +form_clear form_field_boolean_clear form_field_boolean_get_type form_field_boolean_get_value diff --git a/docs/reference/libform.types b/docs/reference/libform.types index ee162b1..b9b0f95 100644 --- a/docs/reference/libform.types +++ b/docs/reference/libform.types @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include #include @@ -21,6 +23,8 @@ form_field_text_get_type form_key_get_type form_widget_get_type form_widget_check_get_type +form_widget_combo_box_get_type +form_widget_date_entry_get_type form_widget_entry_get_type form_widget_label_get_type form_widget_spin_get_type diff --git a/src/Makefile.am b/src/Makefile.am index b2a4d67..74c52fd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,11 +13,13 @@ libform_la_SOURCES = form.c \ fieldboolean.c \ fielddatetime.c \ widget.c \ - widgetlabel.c \ + widgetcheck.c \ + widgetcombobox.c \ + widgetdateentry.c \ widgetentry.c \ - widgettextview.c \ + widgetlabel.c \ widgetspin.c \ - widgetcheck.c + widgettextview.c libform_la_LDFLAGS = -no-undefined @@ -30,10 +32,12 @@ libform_include_HEADERS = libform.h \ libformfieldboolean.h \ libformfielddatetime.h \ libformwidget.h \ - libformwidgetlabel.h \ + libformwidgetcheck.h \ + libformwidgetcombobox.h \ + libformwidgetdateentry.h \ libformwidgetentry.h \ - libformwidgettextview.h \ + libformwidgetlabel.h \ libformwidgetspin.h \ - libformwidgetcheck.h + libformwidgettextview.h libform_includedir = $(includedir)/libform diff --git a/src/field.c b/src/field.c index 08ecb7b..b05be10 100644 --- a/src/field.c +++ b/src/field.c @@ -159,6 +159,7 @@ FormField * form_field_get_field_name: * @field: * + * Returns: the field's name. */ const gchar *form_field_get_field_name (FormField *field) @@ -168,6 +169,20 @@ const gchar return (const gchar *)g_strdup (priv->field); } +/** + * form_field_get_form_widget: + * @field: + * + * Return: the associated #FormWidget. + */ +FormWidget +*form_field_get_form_widget (FormField *field) +{ + FormFieldPrivate *priv = FORM_FIELD_GET_PRIVATE (field); + + return (FormWidget *)priv->widget; +} + /** * form_field_get_value_stringify: * @field: diff --git a/src/fielddatetime.c b/src/fielddatetime.c index 68f6648..a47dbc1 100644 --- a/src/fielddatetime.c +++ b/src/fielddatetime.c @@ -27,7 +27,8 @@ enum { PROP_0, - PROP_DEFAULT + PROP_DEFAULT, + PROP_TYPE }; static void form_field_datetime_class_init (FormFieldDateTimeClass *klass); @@ -44,12 +45,15 @@ static void form_field_datetime_get_property (GObject *object, static gboolean form_field_datetime_set_value_stringify (FormField *field, const gchar *value); +static gchar *form_field_get_str_format (FormField *field); + #define FORM_FIELD_DATETIME_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_FIELD_DATETIME, FormFieldDateTimePrivate)) typedef struct _FormFieldDateTimePrivate FormFieldDateTimePrivate; struct _FormFieldDateTimePrivate { struct tm *default_value; + gint type; }; @@ -75,7 +79,7 @@ form_field_datetime_get_type (void) }; form_field_datetime_type = g_type_register_static (TYPE_FORM_FIELD, "FormFieldDateTime", - &form_field_datetime_info, 0); + &form_field_datetime_info, 0); } return form_field_datetime_type; @@ -103,6 +107,15 @@ form_field_datetime_class_init (FormFieldDateTimeClass *klass) "Default value", G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + g_object_class_install_property (object_class, PROP_TYPE, + g_param_spec_int ("type", + "Type", + "Type", + G_MININT, + G_MAXINT, + FORM_FIELD_DATETIME_TYPE_DATETIME, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + g_type_class_add_private (object_class, sizeof (FormFieldDateTimePrivate)); } @@ -153,10 +166,11 @@ const GValue { struct tm datetime; GValue *ret = g_malloc0 (sizeof (GValue)); + const gchar *format = form_field_get_str_format (field); const gchar *value = form_field_datetime_get_value_stringify (field); - if (strptime (value, "%F %T", &datetime) != NULL) + if (strptime (value, format, &datetime) != '\0') { g_value_init (ret, G_TYPE_POINTER); g_value_set_pointer (ret, &datetime); @@ -175,18 +189,19 @@ const gchar { const gchar *ret = NULL; const gchar *value = form_field_datetime_get_value_stringify (field); + const gchar *format = form_field_get_str_format (field); if (value != NULL) { struct tm datetime; - if (strptime (value, "%F %T", &datetime) != NULL) + if (strptime (value, format, &datetime) != '\0') { char *buf; buf = malloc (100); - if (strftime (buf, 100, "%F %T", &datetime) != 0) + if (strftime (buf, 100, format, &datetime) != 0) { ret = g_strconcat ("'", buf, "'", NULL); } @@ -205,6 +220,7 @@ gboolean form_field_datetime_clear (FormField *field) { gboolean ret = FALSE; + gchar *format = form_field_get_str_format (field); FormFieldDateTimePrivate *priv = FORM_FIELD_DATETIME_GET_PRIVATE (field); @@ -214,7 +230,7 @@ form_field_datetime_clear (FormField *field) buf = malloc (100); - if (strftime (buf, 100, "%F %T", priv->default_value) != NULL) + if (strftime (buf, 100, format, priv->default_value) != '\0') { ret = form_field_datetime_set_value_stringify (field, buf); } @@ -275,6 +291,10 @@ form_field_datetime_set_property (GObject *object, priv->default_value = g_value_get_pointer (value); break; + case PROP_TYPE: + priv->type = g_value_get_int (value); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -297,6 +317,10 @@ form_field_datetime_get_property (GObject *object, g_value_set_pointer (value, priv->default_value); break; + case PROP_TYPE: + g_value_set_int (value, priv->type); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -317,3 +341,33 @@ form_field_datetime_set_value_stringify (FormField *field, const gchar *value) return ret; } + +/** + * form_field_get_str_format: + * @field: + * + */ +static gchar +*form_field_get_str_format (FormField *field) +{ + gchar *format; + + FormFieldDateTimePrivate *priv = FORM_FIELD_DATETIME_GET_PRIVATE (field); + + switch (priv->type) + { + case FORM_FIELD_DATETIME_TYPE_DATETIME: + format = g_strdup ("%F %T"); + break; + + case FORM_FIELD_DATETIME_TYPE_DATE: + format = g_strdup ("%F"); + break; + + case FORM_FIELD_DATETIME_TYPE_TIME: + format = g_strdup ("%T"); + break; + } + + return format; +} diff --git a/src/form.c b/src/form.c index bf10e4c..907d475 100644 --- a/src/form.c +++ b/src/form.c @@ -171,6 +171,83 @@ form_remove_field (Form *form, FormField *field) return ret; } +/** + * form_add_fields: + * @form: + * + */ +gboolean +form_add_fields (Form *form, ...) +{ + FormField *field; + + va_list vargs; + + va_start (vargs, form); + + while ((field = va_arg (vargs, FormField *)) != NULL) + { + form_add_field (form, field); + } + + va_end (vargs); +} + +/** + * form_get_field_from_name: + * @form: + * @field_name: + * + */ +FormField +*form_get_field_from_name (Form *form, const gchar *field_name) +{ + FormField *field = NULL; + const gchar *name; + FormPrivate *priv = FORM_GET_PRIVATE (form); + + GList *fields = g_list_first (priv->fields); + while (fields != NULL) + { + name = form_field_get_field_name ((FormField *)fields->data); + if (strcmp (name, field_name) == 0) + { + field = (FormField *)fields->data; + break; + } + + fields = g_list_next (fields); + } + + return field; +} + +/** + * form_get_widget_from_name: + * @form: + * @widget_name: + * + */ +FormWidget +*form_get_widget_from_name (Form *form, const gchar *widget_name) +{ + FormWidget *widget = NULL; + FormWidget *widget_ret = NULL; + gchar *name; + FormPrivate *priv = FORM_GET_PRIVATE (form); + + GList *fields = g_list_first (priv->fields); + while (fields != NULL) + { + widget = form_field_get_form_widget ((FormField *)fields->data); + + + fields = g_list_next (fields); + } + + return widget_ret; +} + /** * form_clear: * @form: diff --git a/src/formkey.c b/src/formkey.c index 8189c1f..5aeee28 100644 --- a/src/formkey.c +++ b/src/formkey.c @@ -16,6 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include #include #include "libformkey.h" @@ -132,6 +133,28 @@ form_key_remove_field (FormKey *form_key, FormField *field) return ret; } +/** + * form_key_add_fields: + * @form_key: + * + */ +gboolean +form_key_add_fields (FormKey *form_key, ...) +{ + FormField *field; + + va_list vargs; + + va_start (vargs, form_key); + + while ((field = va_arg (vargs, FormField *)) != NULL) + { + form_key_add_field (form_key, field); + } + + va_end (vargs); +} + /** * form_key_check: * @form_key: diff --git a/src/libform.h b/src/libform.h index 9c0f376..23fbdb2 100644 --- a/src/libform.h +++ b/src/libform.h @@ -25,6 +25,7 @@ #include #include +#include #include @@ -60,6 +61,11 @@ Form *form_new (void); gboolean form_add_field (Form *form, FormField *field); gboolean form_remove_field (Form *form, FormField *field); +gboolean form_add_fields (Form *form, ...); + +FormField *form_get_field_from_name (Form *form, const gchar *field_name); +FormWidget *form_get_widget_from_name (Form *form, const gchar *widget_name); + gboolean form_clear (Form *form); gboolean form_check (Form *form); diff --git a/src/libformfield.h b/src/libformfield.h index 4cc6277..0b2c3b9 100644 --- a/src/libformfield.h +++ b/src/libformfield.h @@ -64,6 +64,7 @@ FormField *form_field_new (void); FormField *form_field_new_from_form_widget (FormWidget *fwidget); const gchar *form_field_get_field_name (FormField *field); +FormWidget *form_field_get_form_widget (FormField *field); const gchar *form_field_get_value_stringify (FormField *field); const GValue *form_field_get_value (FormField *field); diff --git a/src/libformfielddatetime.h b/src/libformfielddatetime.h index 8236d6a..2ca5cea 100644 --- a/src/libformfielddatetime.h +++ b/src/libformfielddatetime.h @@ -50,6 +50,13 @@ struct _FormFieldDateTimeClass GType form_field_datetime_get_type (void) G_GNUC_CONST; +enum +{ + FORM_FIELD_DATETIME_TYPE_DATETIME, + FORM_FIELD_DATETIME_TYPE_DATE, + FORM_FIELD_DATETIME_TYPE_TIME +}; + FormField *form_field_datetime_new (void); const gchar *form_field_datetime_get_value_stringify (FormField *field); diff --git a/src/libformkey.h b/src/libformkey.h index 816dd10..99e7c94 100644 --- a/src/libformkey.h +++ b/src/libformkey.h @@ -56,6 +56,8 @@ FormKey *form_key_new (void); gboolean form_key_add_field (FormKey *form_key, FormField *field); gboolean form_key_remove_field (FormKey *form_key, FormField *field); +gboolean form_key_add_fields (FormKey *form_key, ...); + gboolean form_key_check (FormKey *form_key); gchar *form_key_get_sql (FormKey *form_key); diff --git a/src/libformwidget.h b/src/libformwidget.h index e715189..f0d2887 100644 --- a/src/libformwidget.h +++ b/src/libformwidget.h @@ -60,6 +60,8 @@ gboolean form_widget_set_from_glade (FormWidget *fwidget, GladeXML *glade, const GtkWidget *form_widget_get_widget (FormWidget *fwidget); +const gchar *form_widget_get_widget_name (FormWidget *fwidget); + const gchar *form_widget_get_value_stringify (FormWidget *fwidget); gboolean form_widget_set_value_stringify (FormWidget *fwidget, const gchar *value); diff --git a/src/libformwidgetcombobox.h b/src/libformwidgetcombobox.h new file mode 100644 index 0000000..a0ed57c --- /dev/null +++ b/src/libformwidgetcombobox.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_WIDGET_COMBO_BOX_H__ +#define __LIBFORM_WIDGET_COMBO_BOX_H__ + +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM_WIDGET_COMBO_BOX (form_widget_combo_box_get_type ()) +#define FORM_WIDGET_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM_WIDGET_COMBO_BOX, FormWidgetComboBox)) +#define FORM_WIDGET_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM_WIDGET_COMBO_BOX, FormWidgetComboBoxClass)) +#define IS_FORM_WIDGET_COMBO_BOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM_WIDGET_COMBO_BOX)) +#define IS_FORM_WIDGET_COMBO_BOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM_WIDGET_COMBO_BOX)) +#define FORM_WIDGET_COMBO_BOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM_WIDGET_COMBO_BOX, FormWidgetComboBoxClass)) + + +typedef struct _FormWidgetComboBox FormWidgetComboBox; +typedef struct _FormWidgetComboBoxClass FormWidgetComboBoxClass; + +struct _FormWidgetComboBox + { + FormWidget parent; + }; + +struct _FormWidgetComboBoxClass + { + FormWidgetClass parent_class; + }; + +GType form_widget_combo_box_get_type (void) G_GNUC_CONST; + +FormWidget *form_widget_combo_box_new (void); + +const gchar *form_widget_combo_box_get_value_stringify (FormWidget *widget); + +gboolean form_widget_combo_box_set_value_stringify (FormWidget *fwidget, const gchar *value); + + +G_END_DECLS + + +#endif /* __LIBFORM_WIDGET_COMBO_BOX_H__ */ diff --git a/src/libformwidgetdateentry.h b/src/libformwidgetdateentry.h new file mode 100644 index 0000000..fcf7033 --- /dev/null +++ b/src/libformwidgetdateentry.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2005-2006 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. + */ + +#ifndef __LIBFORM_WIDGET_DATE_ENTRY_H__ +#define __LIBFORM_WIDGET_DATE_ENTRY_H__ + +#include + + +G_BEGIN_DECLS + + +#define TYPE_FORM_WIDGET_DATE_ENTRY (form_widget_date_entry_get_type ()) +#define FORM_WIDGET_DATE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FORM_WIDGET_DATE_ENTRY, FormWidgetDateEntry)) +#define FORM_WIDGET_DATE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FORM_WIDGET_DATE_ENTRY, FormWidgetDateEntryClass)) +#define IS_FORM_WIDGET_DATE_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FORM_WIDGET_DATE_ENTRY)) +#define IS_FORM_WIDGET_DATE_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FORM_WIDGET_DATE_ENTRY)) +#define FORM_WIDGET_DATE_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FORM_WIDGET_DATE_ENTRY, FormWidgetDateEntryClass)) + + +typedef struct _FormWidgetDateEntry FormWidgetDateEntry; +typedef struct _FormWidgetDateEntryClass FormWidgetDateEntryClass; + +struct _FormWidgetDateEntry + { + FormWidget parent; + }; + +struct _FormWidgetDateEntryClass + { + FormWidgetClass parent_class; + }; + +GType form_widget_date_entry_get_type (void) G_GNUC_CONST; + +FormWidget *form_widget_date_entry_new (void); + +const gchar *form_widget_date_entry_get_value_stringify (FormWidget *widget); + +gboolean form_widget_date_entry_set_value_stringify (FormWidget *fwidget, const gchar *value); + + +G_END_DECLS + + +#endif /* __LIBFORM_WIDGET_DATE_ENTRY_H__ */ diff --git a/src/widget.c b/src/widget.c index 47f05ba..e4b1bb9 100644 --- a/src/widget.c +++ b/src/widget.c @@ -157,6 +157,20 @@ GtkWidget return priv->widget; } +/** + * form_widget_get_widget_name: + * @fwidget: + * + * Returns: the #FormWidget's name. + */ +const gchar +*form_widget_get_widget_name (FormWidget *fwidget) +{ + FormWidgetPrivate *priv = FORM_WIDGET_GET_PRIVATE (fwidget); + + return (const gchar *)g_strdup (priv->widget_name); +} + /** * form_widget_get_value_stringify: * @fwidget: diff --git a/src/widgetcombobox.c b/src/widgetcombobox.c new file mode 100644 index 0000000..e9cb62c --- /dev/null +++ b/src/widgetcombobox.c @@ -0,0 +1,248 @@ +/* + * Copyright (C) 2005-2006 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 "libformwidgetcombobox.h" + +enum +{ + PROP_0, + PROP_COLUMN_FIELD +}; + +static void form_widget_combo_box_class_init (FormWidgetComboBoxClass *klass); +static void form_widget_combo_box_init (FormWidgetComboBox *form_widget_combo_box); + +static void form_widget_combo_box_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void form_widget_combo_box_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +#define FORM_WIDGET_COMBO_BOX_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_WIDGET_COMBO_BOX, FormWidgetComboBoxPrivate)) + +typedef struct _FormWidgetComboBoxPrivate FormWidgetComboBoxPrivate; +struct _FormWidgetComboBoxPrivate + { + gint column_field; + }; + + +GType +form_widget_combo_box_get_type (void) +{ + static GType form_widget_combo_box_type = 0; + + if (!form_widget_combo_box_type) + { + static const GTypeInfo form_widget_combo_box_info = + { + sizeof (FormWidgetComboBoxClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_widget_combo_box_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FormWidgetComboBox), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_widget_combo_box_init, + NULL + }; + + form_widget_combo_box_type = g_type_register_static (TYPE_FORM_WIDGET, "FormWidgetComboBox", + &form_widget_combo_box_info, 0); + } + + return form_widget_combo_box_type; +} + +static void +form_widget_combo_box_class_init (FormWidgetComboBoxClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FormWidgetClass *widget_class = FORM_WIDGET_CLASS (klass); + + object_class->set_property = form_widget_combo_box_set_property; + object_class->get_property = form_widget_combo_box_get_property; + + widget_class->get_value_stringify = form_widget_combo_box_get_value_stringify; + widget_class->set_value_stringify = form_widget_combo_box_set_value_stringify; + + g_object_class_install_property (object_class, PROP_COLUMN_FIELD, + g_param_spec_int ("column-field", + "Column Field", + "Column's Field", + G_MININT, + G_MAXINT, + 0, + G_PARAM_READWRITE)); + + g_type_class_add_private (object_class, sizeof (FormWidgetComboBoxPrivate)); +} + +static void +form_widget_combo_box_init (FormWidgetComboBox *form_widget_combo_box) +{ +} + +/** + * form_widget_combo_box_new: + * + * Returns: the newly created #FormWidgetComboBox. + */ +FormWidget +*form_widget_combo_box_new () +{ + return g_object_new (TYPE_FORM_WIDGET_COMBO_BOX, NULL); +} + +/** + * form_widget_combo_box_get_value_stringify: + * @widget: + * + */ +const gchar +*form_widget_combo_box_get_value_stringify (FormWidget *fwidget) +{ + const gchar *ret = ""; + GtkWidget *w = form_widget_get_widget (fwidget); + + FormWidgetComboBoxPrivate *priv = FORM_WIDGET_COMBO_BOX_GET_PRIVATE (fwidget); + + GtkTreeModel *tmodel = gtk_combo_box_get_model (GTK_COMBO_BOX (w)); + if (tmodel != NULL) + { + GtkTreeIter iter; + + if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &iter)) + { + GValue *gvalue = g_malloc0 (sizeof (GValue)); + GValue *gvstr = g_malloc0 (sizeof (GValue)); + + gtk_tree_model_get_value (tmodel, &iter, priv->column_field, gvalue); + + g_value_init (gvstr, G_TYPE_STRING); + g_value_transform (gvalue, gvstr); + + ret = g_value_get_string (gvstr); + } + } + + return ret; +} + +/** + * form_widget_combo_box_set_value_stringify: + * @fwidget: + * @value: + * + */ +gboolean +form_widget_combo_box_set_value_stringify (FormWidget *fwidget, const gchar *value) +{ + gboolean ret = FALSE; + GtkWidget *w; + GtkTreeModel *tmodel; + + FormWidgetComboBoxPrivate *priv = FORM_WIDGET_COMBO_BOX_GET_PRIVATE (fwidget); + + g_object_get (G_OBJECT (fwidget), + "widget", &w, + NULL); + + gtk_combo_box_set_active (GTK_COMBO_BOX (w), -1); + + tmodel = gtk_combo_box_get_model (GTK_COMBO_BOX (w)); + if (tmodel != NULL) + { + GtkTreeIter iter; + + if (gtk_tree_model_get_iter_first (tmodel, &iter)) + { + do + { + GValue *gvalue = g_malloc0 (sizeof (GValue)); + GValue *gvstr = g_malloc0 (sizeof (GValue)); + + gtk_tree_model_get_value (tmodel, &iter, priv->column_field, gvalue); + + g_value_init (gvstr, G_TYPE_STRING); + g_value_transform (gvalue, gvstr); + if (strcmp (g_value_get_string (gvstr), value) == 0) + { + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (w), &iter); + break; + } + + } while (gtk_tree_model_iter_next (tmodel, &iter)); + } + } + + ret = TRUE; + + return ret; +} + +/* PRIVATE */ +static void +form_widget_combo_box_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + FormWidgetComboBox *widget_combo_box = (FormWidgetComboBox *)object; + + FormWidgetComboBoxPrivate *priv = FORM_WIDGET_COMBO_BOX_GET_PRIVATE (widget_combo_box); + + switch (property_id) + { + case PROP_COLUMN_FIELD: + priv->column_field = g_value_get_int (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +form_widget_combo_box_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + FormWidgetComboBox *widget_combo_box = (FormWidgetComboBox *)object; + + FormWidgetComboBoxPrivate *priv = FORM_WIDGET_COMBO_BOX_GET_PRIVATE (widget_combo_box); + + switch (property_id) + { + case PROP_COLUMN_FIELD: + g_value_set_int (value, priv->column_field); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/src/widgetdateentry.c b/src/widgetdateentry.c new file mode 100644 index 0000000..61b3ed6 --- /dev/null +++ b/src/widgetdateentry.c @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2005-2006 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 + +#include "libformwidgetdateentry.h" + +enum +{ + PROP_0, + PROP_DATE_FORMAT, + PROP_SEPARATOR +}; + +static void form_widget_date_entry_class_init (FormWidgetDateEntryClass *klass); +static void form_widget_date_entry_init (FormWidgetDateEntry *form_widget_date_entry); + +static void form_widget_date_entry_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void form_widget_date_entry_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +#define FORM_WIDGET_DATE_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_FORM_WIDGET_DATE_ENTRY, FormWidgetDateEntryPrivate)) + +typedef struct _FormWidgetDateEntryPrivate FormWidgetDateEntryPrivate; +struct _FormWidgetDateEntryPrivate + { + gchar *date_format; + gchar separator; + }; + + +GType +form_widget_date_entry_get_type (void) +{ + static GType form_widget_date_entry_type = 0; + + if (!form_widget_date_entry_type) + { + static const GTypeInfo form_widget_date_entry_info = + { + sizeof (FormWidgetDateEntryClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) form_widget_date_entry_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FormWidgetDateEntry), + 0, /* n_preallocs */ + (GInstanceInitFunc) form_widget_date_entry_init, + NULL + }; + + form_widget_date_entry_type = g_type_register_static (TYPE_FORM_WIDGET, "FormWidgetDateEntry", + &form_widget_date_entry_info, 0); + } + + return form_widget_date_entry_type; +} + +static void +form_widget_date_entry_class_init (FormWidgetDateEntryClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FormWidgetClass *widget_class = FORM_WIDGET_CLASS (klass); + + object_class->set_property = form_widget_date_entry_set_property; + object_class->get_property = form_widget_date_entry_get_property; + + widget_class->get_value_stringify = form_widget_date_entry_get_value_stringify; + widget_class->set_value_stringify = form_widget_date_entry_set_value_stringify; + + g_object_class_install_property (object_class, PROP_DATE_FORMAT, + g_param_spec_string ("date-format", + "Date Format", + "Date Format", + "", + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, PROP_SEPARATOR, + g_param_spec_char ("separator", + "Separator", + "Separator", + G_MININT8, + G_MAXINT8, + '-', + G_PARAM_READWRITE)); + + g_type_class_add_private (object_class, sizeof (FormWidgetDateEntryPrivate)); +} + +static void +form_widget_date_entry_init (FormWidgetDateEntry *form_widget_date_entry) +{ +} + +/** + * form_widget_date_entry_new: + * + * Returns: the newly created #FormWidgetDateEntry. + */ +FormWidget +*form_widget_date_entry_new () +{ + return g_object_new (TYPE_FORM_WIDGET_DATE_ENTRY, NULL); +} + +/** + * form_widget_date_entry_get_value_stringify: + * @widget: + * + */ +const gchar +*form_widget_date_entry_get_value_stringify (FormWidget *fwidget) +{ + FormWidgetDateEntryPrivate *priv = FORM_WIDGET_DATE_ENTRY_GET_PRIVATE (fwidget); + GtkWidget *w = form_widget_get_widget (fwidget); + + return gtk_date_entry_get_strf (GTK_DATE_ENTRY (w), priv->date_format, priv->separator); +} + +/** + * form_widget_date_entry_set_value_stringify: + * @fwidget: + * @value: + * + */ +gboolean +form_widget_date_entry_set_value_stringify (FormWidget *fwidget, const gchar *value) +{ + gboolean ret = FALSE; + GtkWidget *w; + + FormWidgetDateEntryPrivate *priv = FORM_WIDGET_DATE_ENTRY_GET_PRIVATE (fwidget); + + g_object_get (G_OBJECT (fwidget), + "widget", &w, + NULL); + + gtk_date_entry_set_date_strf (GTK_DATE_ENTRY (w), value, priv->date_format, 0); + + ret = TRUE; + + return ret; +} + +/* PRIVATE */ +static void +form_widget_date_entry_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + FormWidgetDateEntry *widget_date_entry = (FormWidgetDateEntry *)object; + + FormWidgetDateEntryPrivate *priv = FORM_WIDGET_DATE_ENTRY_GET_PRIVATE (widget_date_entry); + + switch (property_id) + { + case PROP_DATE_FORMAT: + priv->date_format = g_strstrip (g_strdup (g_value_get_string (value))); + break; + + case PROP_SEPARATOR: + priv->separator = g_value_get_char (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +form_widget_date_entry_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + FormWidgetDateEntry *widget_date_entry = (FormWidgetDateEntry *)object; + + FormWidgetDateEntryPrivate *priv = FORM_WIDGET_DATE_ENTRY_GET_PRIVATE (widget_date_entry); + + switch (property_id) + { + case PROP_DATE_FORMAT: + g_value_set_string (value, priv->date_format); + break; + + case PROP_SEPARATOR: + g_value_set_char (value, priv->separator); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} diff --git a/test/main.c b/test/main.c index 08016d0..053a72f 100644 --- a/test/main.c +++ b/test/main.c @@ -21,20 +21,23 @@ #include #include +#include #include #include -#include -#include -#include #include #include +#include +#include +#include #include -#include +#include +#include +#include #include -#include +#include #include -#include +#include Form *form; @@ -49,6 +52,8 @@ FormWidget *wentry; FormWidget *wtxtv; FormWidget *wspin; FormWidget *wcheck; +FormWidget *wdate; +FormWidget *wcombobox; GtkWidget *w; GtkWidget *txtvSql; @@ -116,6 +121,65 @@ on_btnSqlDelete_clicked (GtkButton *button, gtk_text_buffer_set_text (buf, sql, strlen (sql)); } +GtkWidget +*create_gtkdateentry (gchar *widget_name, gchar *string1, gchar *string2, + gint int1, gint int2) +{ + GtkWidget *w = gtk_date_entry_new ("dmY", '/', TRUE); + gtk_widget_show (w); + + return w; +} + +void +create_cb_nation (GtkWidget *w) +{ + GtkCellRenderer *renderer; + GtkListStore *store; + GtkTreeIter iter; + gint id = 0; + + store = gtk_list_store_new (2, + G_TYPE_INT, + G_TYPE_STRING); + gtk_combo_box_set_model (GTK_COMBO_BOX (w), GTK_TREE_MODEL (store)); + renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (w), renderer, FALSE); + gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (w), renderer, + "text", 1); + + id++; + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + 0, id, + 1, "China", + -1); + id++; + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + 0, id, + 1, "Germany", + -1); + id++; + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + 0, id, + 1, "India", + -1); + id++; + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + 0, id, + 1, "Italy", + -1); + id++; + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + 0, id, + 1, "USA", + -1); +} + int main (int argc, char **argv) { @@ -201,6 +265,23 @@ main (int argc, char **argv) NULL); form_add_field (form, ffloat); + /* COMBOBOX - INTEGER */ + create_cb_nation (glade_xml_get_widget (glade, "cbNation")); + + wcombobox = form_widget_combo_box_new (); + form_widget_set_from_glade (wcombobox, glade, "cbNation"); + g_object_set (wcombobox, + "column-field", 0, + NULL); + + fint = form_field_integer_new (); + g_object_set (fint, + "field", "id_nation", + "form-widget", wcombobox, + "default", 3, + NULL); + form_add_field (form, fint); + /* CHECK - BOOL*/ wcheck = form_widget_check_new (); form_widget_set_from_glade (wcheck, glade, "chkMarried"); @@ -239,6 +320,23 @@ main (int argc, char **argv) NULL); form_add_field (form, fdatetime); + /* DATE_ENTRY - DATETIME */ + wdate = form_widget_date_entry_new (); + form_widget_set_from_glade (wdate, glade, "date_entry"); + g_object_set (wdate, + "date-format", "Ymd", + "separator", '-', + NULL); + + fdatetime = form_field_datetime_new (); + g_object_set (fdatetime, + "field", "birthday", + "form-widget", wdate, + "default", now, + "type", FORM_FIELD_DATETIME_TYPE_DATE, + NULL); + form_add_field (form, fdatetime); + txtvSql = glade_xml_get_widget (glade, "txtvSql"); glade_xml_signal_autoconnect (glade); diff --git a/test/test.glade b/test/test.glade index 3d8cdb5..40c1914 100644 --- a/test/test.glade +++ b/test/test.glade @@ -9,6 +9,8 @@ GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE False + 600 + 440 True False True @@ -31,7 +33,7 @@ 3 True - 9 + 10 2 False 3 @@ -243,7 +245,7 @@ True - GtkComboBox + GtkComboBox (integer) (id_nation) False False GTK_JUSTIFY_LEFT @@ -268,22 +270,6 @@ - - - True - False - True - - - 1 - 2 - 4 - 5 - fill - fill - - - True @@ -512,6 +498,68 @@ + + + + True + GtkDateEntry (DateTime) (birthday) + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 9 + 10 + fill + + + + + + + True + create_gtkdateentry + 0 + 0 + Wed, 20 Dec 2006 09:51:37 GMT + + + 1 + 2 + 9 + 10 + fill + fill + + + + + + True + False + True + + + 1 + 2 + 4 + 5 + fill + fill + + 0