# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
-AC_INIT([libgtkform], [0.1.1], [azagli@libero.it])
+AC_INIT([libgtkform], [0.1.2], [azagli@libero.it])
AC_CONFIG_SRCDIR([src/form.c])
AC_CONFIG_HEADER([config.h])
<!ELEMENT table (#PCDATA)>
-<!ELEMENT widget (column-field?, return-value?, field?)>
+<!ELEMENT widget (column-field?, sql?, return-value?, field?)>
<!ATTLIST widget
type (checkbox | combobox | entry | label | radio | spin | textview) #REQUIRED
<!ELEMENT column-field (#PCDATA)>
+<!ELEMENT sql (#PCDATA)>
+
+<!ATTLIST sql
+ with-empty-entry (#PCDATA)
+>
+
<!ELEMENT return-value (#PCDATA)>
<!ELEMENT field (to-save?, obligatory?, default?, is-key?, auto-increment?, datetime-type?, display-format?)>
*gtk_form_new_from_xml (xmlDoc *xmldoc, GtkBuilder *gtkbuilder)
{
GtkForm *form;
+
+ form = gtk_form_new ();
+
+ if (!gtk_form_load_from_xml (form, xmldoc, gtkbuilder))
+ {
+ form = NULL;
+ }
+
+ return form;
+}
+
+/**
+ * gtk_form_new_from_file:
+ * @filename:
+ * @gtkbuilder:
+ *
+ * Returns: the newly created #GtkForm object from a file that contains the
+ * xml denifition of the form.
+ */
+GtkForm
+*gtk_form_new_from_file (const gchar *filename, GtkBuilder *gtkbuilder)
+{
+ GtkForm *form;
+ xmlDoc *xdoc;
+
+ g_return_val_if_fail (filename != NULL, NULL);
+
+ form = NULL;
+
+ xdoc = xmlParseFile (filename);
+ if (xdoc != NULL)
+ {
+ form = gtk_form_new_from_xml (xdoc, gtkbuilder);
+ }
+
+ return form;
+}
+
+/**
+ * gtk_form_load_from_xml:
+ * @form:
+ * @xmldoc:
+ * @gtkbuilder:
+ *
+ */
+gboolean
+gtk_form_load_from_xml (GtkForm *form, xmlDoc *xmldoc, GtkBuilder *gtkbuilder)
+{
GtkFormPrivate *priv;
xmlNode *cur;
- form = NULL;
+ gboolean ret;
+
+ g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
+ g_return_val_if_fail (xmldoc != NULL, FALSE);
+
+ ret = FALSE;
cur = xmlDocGetRootElement (xmldoc);
if (cur != NULL)
GtkFormField *field;
xmlNode *node_field;
- form = gtk_form_new ();
+ ret = TRUE;
priv = GTK_FORM_GET_PRIVATE (form);
g_object_set (G_OBJECT (widget), "column-field",
strtol ((gchar *)xmlNodeGetContent (node_widget), NULL, 10), NULL);
}
+ else if (xmlStrcmp (node_widget->name, (const xmlChar *)"sql") == 0
+ && IS_GTK_FORM_WIDGET_COMBO_BOX (widget) && IS_GDAEX (priv->gdaex))
+ {
+ gtk_form_widget_combo_box_fill_from_sql (widget,
+ priv->gdaex,
+ (gchar *)xmlNodeGetContent (node_widget),
+ gtk_form_field_boolean_str_to_boolean (xmlGetProp (node_widget, "with-empty-entry")));
+ }
else if (xmlStrcmp (node_widget->name, (const xmlChar *)"return-value") == 0
&& IS_GTK_FORM_WIDGET_RADIO (widget))
{
}
}
- return form;
+ return ret;
}
/**
- * gtk_form_new_from_file:
+ * gtk_form_load_from_file:
+ * @form:
* @filename:
* @gtkbuilder:
*
- * Returns: the newly created #GtkForm object from a file that contains the
- * xml denifition of the form.
*/
-GtkForm
-*gtk_form_new_from_file (const gchar *filename, GtkBuilder *gtkbuilder)
+gboolean
+gtk_form_load_from_file (GtkForm *form, const gchar *filename, GtkBuilder *gtkbuilder)
{
- GtkForm *form;
xmlDoc *xdoc;
- g_return_val_if_fail (filename != NULL, NULL);
+ gboolean ret;
- form = NULL;
+ g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
+ g_return_val_if_fail (filename != NULL, FALSE);
+
+ ret = FALSE;
xdoc = xmlParseFile (filename);
if (xdoc != NULL)
{
- form = gtk_form_new_from_xml (xdoc, gtkbuilder);
+ ret = gtk_form_load_from_xml (form, xdoc, gtkbuilder);
}
- return form;
+ return ret;
}
/**
GtkForm *gtk_form_new_from_xml (xmlDoc *xmldoc, GtkBuilder *gtkbuilder);
GtkForm *gtk_form_new_from_file (const gchar *filename, GtkBuilder *gtkbuilder);
+gboolean gtk_form_load_from_xml (GtkForm *form, xmlDoc *xmldoc, GtkBuilder *gtkbuilder);
+gboolean gtk_form_load_from_file (GtkForm *form, const gchar *filename, GtkBuilder *gtkbuilder);
+
GtkBuilder *gtk_form_get_gtkbuilder (GtkForm *form);
gchar *gtk_form_get_table (GtkForm *form);
gtk_widget_set_sensitive (w, editable);
}
+/**
+ * gtk_form_widget_combo_box_fill_from_datamodel:
+ * @fwidget: a #GtkFormWidget object.
+ * @dm:
+ * @with_empty_entry:
+ *
+ */
+void
+gtk_form_widget_combo_box_fill_from_datamodel (GtkFormWidget *fwidget, GdaDataModel *dm, gboolean with_empty_entry)
+{
+ GtkWidget *w;
+
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ guint rows;
+ guint row;
+
+ g_return_if_fail (IS_GTK_FORM_WIDGET_COMBO_BOX (fwidget));
+ g_return_if_fail (GDA_IS_DATA_MODEL (dm));
+
+ g_object_get (G_OBJECT (fwidget),
+ "widget", &w,
+ NULL);
+
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (w));
+ g_return_if_fail (GTK_IS_TREE_MODEL (model));
+
+ if (with_empty_entry)
+ {
+ gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+ 0, "",
+ 1, "",
+ -1);
+ }
+
+ rows = gda_data_model_get_n_rows (dm);
+ for (row = 0; row < rows; row++)
+ {
+ gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+ 0, gdaex_data_model_get_value_stringify_at (dm, row, 0),
+ 1, gdaex_data_model_get_value_stringify_at (dm, row, 1),
+ -1);
+ }
+}
+
+/**
+ * gtk_form_widget_combo_box_fill_from_sql:
+ * @fwidget: a #GtkFormWidget object.
+ * @gdaex:
+ * @sql:
+ * @with_empty_entry:
+ *
+ */
+void
+gtk_form_widget_combo_box_fill_from_sql (GtkFormWidget *fwidget, GdaEx *gdaex, const gchar *sql, gboolean with_empty_entry)
+{
+ GdaDataModel *dm;
+
+ g_return_if_fail (IS_GDAEX (gdaex));
+
+ dm = gdaex_query (gdaex, sql);
+ gtk_form_widget_combo_box_fill_from_datamodel (fwidget, dm, with_empty_entry);
+}
+
/* PRIVATE */
static void
gtk_form_widget_combo_box_set_property (GObject *object,
/*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#ifndef __LIBGTK_FORM_WIDGET_COMBO_BOX_H__
#define __LIBGTK_FORM_WIDGET_COMBO_BOX_H__
+#include <libgdaex.h>
+
#include "widget.h"
void gtk_form_widget_combo_box_set_editable (GtkFormWidget *fwidget, gboolean editable);
+void gtk_form_widget_combo_box_fill_from_datamodel (GtkFormWidget *fwidget, GdaDataModel *dm, gboolean with_empty_entry);
+void gtk_form_widget_combo_box_fill_from_sql (GtkFormWidget *fwidget, GdaEx *gdaex, const gchar *sql, gboolean with_empty_entry);
+
G_END_DECLS