<!ATTLIST widget
type (checkbox | combobox | entry | label | spin | textview) #REQUIRED
name CDATA #REQUIRED
+ label CDATA #IMPLIED
>
<!ELEMENT column-field (#PCDATA)>
gtk_form_add_field
gtk_form_remove_field
gtk_form_add_fields
-gtk_form_get_field_from_name
-gtk_form_get_widget_from_name
+gtk_form_get_form_field_from_name
+gtk_form_get_form_widget_from_name
+gtk_form_get_widgets
+gtk_form_get_objects_by_name
gtk_form_clear
gtk_form_check
gtk_form_is_changed
GtkForm *form, ...
</FUNCTION>
<FUNCTION>
-<NAME>gtk_form_get_field_from_name</NAME>
+<NAME>gtk_form_get_form_field_from_name</NAME>
<RETURNS>GtkFormField *</RETURNS>
GtkForm *form, const gchar *field_name
</FUNCTION>
<FUNCTION>
-<NAME>gtk_form_get_widget_from_name</NAME>
+<NAME>gtk_form_get_form_widget_from_name</NAME>
<RETURNS>GtkFormWidget *</RETURNS>
GtkForm *form, const gchar *widget_name
</FUNCTION>
<FUNCTION>
+<NAME>gtk_form_get_widgets</NAME>
+<RETURNS>GtkWidget **</RETURNS>
+GtkForm *form
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_get_objects_by_name</NAME>
+<RETURNS>GObject **</RETURNS>
+GtkForm *form, ...
+</FUNCTION>
+<FUNCTION>
<NAME>gtk_form_clear</NAME>
<RETURNS>gboolean </RETURNS>
GtkForm *form
+gtk_form_get_field_from_name
+gtk_form_get_widget_from_name
6% symbol docs coverage.
17 symbols documented.
2 symbols incomplete.
-259 not documented.
+261 not documented.
GTK_FORM
gtk_form_field_text_set_from_datamodel
gtk_form_filed_boolean_is_changed
gtk_form_fill_from_datamodel
-gtk_form_get_field_from_name
+gtk_form_get_form_field_from_name
+gtk_form_get_form_widget_from_name
gtk_form_get_gtkbuilder
gtk_form_get_key
+gtk_form_get_objects
+gtk_form_get_objects_by_name
gtk_form_get_sql
gtk_form_get_table
gtk_form_get_type
-gtk_form_get_widget_from_name
gtk_form_is_changed
gtk_form_key_add_field
gtk_form_key_add_fields
gtk_form_field_is_changed
gtk_form_field_text_is_changed
gtk_form_filed_boolean_is_changed
+gtk_form_get_form_field_from_name
+gtk_form_get_form_widget_from_name
gtk_form_get_gtkbuilder
gtk_form_get_key
+gtk_form_get_objects_by_name
gtk_form_get_table
+gtk_form_get_widgets
gtk_form_is_changed
gtk_form_new_from_file
gtk_form_new_from_xml
@Returns:
-<!-- ##### FUNCTION gtk_form_get_field_from_name ##### -->
-<para>
-
-</para>
-
-@form:
-@field_name:
-@Returns:
-
-
-<!-- ##### FUNCTION gtk_form_get_widget_from_name ##### -->
-<para>
-
-</para>
-
-@form:
-@widget_name:
-@Returns:
-
-
<!-- ##### FUNCTION gtk_form_clear ##### -->
<para>
@value:
@Returns:
+<!-- ##### FUNCTION gtk_form_get_field_from_name ##### -->
+<para>
+
+</para>
+
+@form:
+@field_name:
+@Returns:
+
+<!-- ##### FUNCTION gtk_form_get_widget_from_name ##### -->
+<para>
+
+</para>
+
+@form:
+@widget_name:
+@Returns:
+
}
/**
- * gtk_form_field_get_gtk_form_widget:
+ * gtk_form_field_get_form_widget:
* @field: a #GtkFormField object.
*
* Return: the associated #GtkFormWidget.
*/
GtkFormWidget
-*gtk_form_field_get_gtk_form_widget (GtkFormField *field)
+*gtk_form_field_get_form_widget (GtkFormField *field)
{
GtkFormFieldPrivate *priv = GTK_FORM_FIELD_GET_PRIVATE (field);
* gtk_form_field_is_empty:
* @field: a #GtkFormField object.
*
+ * Returns: TRUE if the field is empty.
*/
gboolean
gtk_form_field_is_empty (GtkFormField *field)
{
- gboolean ret = FALSE;
+ gboolean ret = TRUE;
if (IS_GTK_FORM_FIELD (field) && GTK_FORM_FIELD_GET_CLASS (field)->is_empty != NULL)
{
GtkFormField *gtk_form_field_new_from_gtk_form_widget (GtkFormWidget *fwidget);
const gchar *gtk_form_field_get_field_name (GtkFormField *field);
-GtkFormWidget *gtk_form_field_get_gtk_form_widget (GtkFormField *field);
+GtkFormWidget *gtk_form_field_get_form_widget (GtkFormField *field);
const gchar *gtk_form_field_get_value_stringify (GtkFormField *field);
const GValue *gtk_form_field_get_value (GtkFormField *field);
gboolean
gtk_form_field_boolean_is_empty (GtkFormField *field)
{
- gboolean ret = TRUE;
+ gboolean ret;
+
+ g_return_val_if_fail (IS_GTK_FORM_FIELD_BOOLEAN (field), TRUE);
+
+ ret = FALSE;
return ret;
}
gboolean
gtk_form_field_datetime_is_empty (GtkFormField *field)
{
- gboolean ret = TRUE;
+ gboolean ret;
+
+ g_return_val_if_fail (IS_GTK_FORM_FIELD_DATETIME (field), TRUE);
+
+ ret = FALSE;
return ret;
}
value = gtk_form_field_datetime_get_tm_from_str (gtk_form_field_datetime_get_value_stringify (field));
- ret = (value->tm_year != priv->original_value->tm_year
- || value->tm_mon != priv->original_value->tm_mon
- || value->tm_mday != priv->original_value->tm_mday
- || value->tm_hour != priv->original_value->tm_hour
- || value->tm_min != priv->original_value->tm_min
- || value->tm_sec != priv->original_value->tm_sec);
+ if (value != NULL)
+ {
+ ret = (value->tm_year != priv->original_value->tm_year
+ || value->tm_mon != priv->original_value->tm_mon
+ || value->tm_mday != priv->original_value->tm_mday
+ || value->tm_hour != priv->original_value->tm_hour
+ || value->tm_min != priv->original_value->tm_min
+ || value->tm_sec != priv->original_value->tm_sec);
+ }
return ret;
}
gboolean
gtk_form_field_float_is_empty (GtkFormField *field)
{
- gboolean ret = TRUE;
+ gboolean ret;
const gchar *value;
+ g_return_val_if_fail (IS_GTK_FORM_FIELD_FLOAT (field), TRUE);
+
value = gtk_form_field_float_get_value_stringify (field);
- if (strtod (value, NULL) == 0.0f)
+ if (g_strtod (value, NULL) == 0.0f)
+ {
+ ret = TRUE;
+ }
+ else
{
ret = FALSE;
}
gboolean
gtk_form_field_integer_is_empty (GtkFormField *field)
{
- gboolean ret = TRUE;
+ gboolean ret;
const gchar *value;
+ g_return_val_if_fail (IS_GTK_FORM_FIELD_INTEGER (field), TRUE);
+
value = gtk_form_field_integer_get_value_stringify (field);
if (strtol (value, NULL, 10) == 0)
+ {
+ ret = TRUE;
+ }
+ else
{
ret = FALSE;
}
gboolean
gtk_form_field_text_is_empty (GtkFormField *field)
{
- gboolean ret = TRUE;
+ gboolean ret;
const gchar *value;
+ g_return_val_if_fail (IS_GTK_FORM_FIELD_TEXT (field), TRUE);
+
value = gtk_form_field_text_get_value_stringify (field);
- if (strcmp (value, "") == 0)
+ if (g_strcmp0 (value, "") == 0)
+ {
+ ret = TRUE;
+ }
+ else
{
ret = FALSE;
}
#include <libxml/xpath.h>
+#include <gtk/gtk.h>
+
#include "form.h"
#include "fieldboolean.h"
{
gchar *type;
gchar *name;
+ gchar *label;
GtkFormWidget *widget;
xmlNode *node_widget;
if (GTK_IS_BUILDER (priv->gtkbuilder))
{
gtk_form_widget_set_from_gtkbuilder (widget, priv->gtkbuilder, name);
+
+ label = xmlGetProp (cur, (const xmlChar *)"label");
+ if (label != NULL && g_strcmp0 (g_strstrip (label), "") != 0)
+ {
+ GtkLabel *wlabel;
+ wlabel = GTK_LABEL (gtk_builder_get_object (priv->gtkbuilder, label));
+ gtk_form_widget_set_label (widget, wlabel);
+ }
}
node_widget = cur->children;
GSList *fields = priv->fields;
while (fields != NULL)
{
- widget = gtk_form_field_get_gtk_form_widget ((GtkFormField *)fields->data);
+ widget = gtk_form_field_get_form_widget ((GtkFormField *)fields->data);
if (strcmp (gtk_form_widget_get_widget_name (widget), widget_name) == 0)
{
l++;
ret = g_realloc (ret, l * sizeof (GtkWidget *));
- form_widget = gtk_form_field_get_gtk_form_widget ((GtkFormField *)fields->data);
+ form_widget = gtk_form_field_get_form_widget ((GtkFormField *)fields->data);
widget = gtk_form_widget_get_widget (form_widget);
ret[l] = widget;
priv = GTK_FORM_GET_PRIVATE (form);
- if (priv->gtkbuilder == NULL) return NULL;
+ g_return_val_if_fail (GTK_IS_BUILDER (priv->gtkbuilder), NULL);
ret = NULL;
l = 0;
while ((object_name = va_arg (vargs, gchar *)) != NULL)
{
object = gtk_builder_get_object (priv->gtkbuilder, object_name);
- if (object != NULL)
+ if (G_IS_OBJECT (object))
{
l++;
- ret = g_realloc (ret, l * sizeof (GObject *));
- ret[l] = object;
+ if (l == 1)
+ {
+ ret = g_malloc (sizeof (GObject *));
+ }
+ else
+ {
+ ret = g_realloc (ret, l * sizeof (GObject *));
+ }
+ ret[l - 1] = object;
+ }
+ else
+ {
+ g_warning ("Object «%s» not found.", object_name);
}
}
/**
* gtk_form_check:
* @form: a #GtkForm object.
+ * @form_widget: a #GtkFormWidget.
+ * @show_error_dialog:
+ * @set_focus:
*
- * Returns: TRUE if all obligatory fields are full.
+ * Returns: TRUE if all obligatory fields are full and @widget is NULL. Otherwise
+ * if @widget isn't NULL, it is the first #GtkFormWidget empty.
*/
gboolean
-gtk_form_check (GtkForm *form)
+gtk_form_check (GtkForm *form, GtkFormWidget **form_widget,
+ gboolean show_error_dialog, GtkWidget *parent_window,
+ gboolean set_focus)
{
GtkFormPrivate *priv;
GSList *fields;
GtkFormField *field;
+ GtkFormWidget *fwidget;
+ GtkWidget *widget;
gboolean ret = TRUE;
gboolean obl = FALSE;
g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
+ g_return_val_if_fail (form_widget == NULL || *form_widget == NULL, FALSE);
+
+ if (show_error_dialog)
+ {
+ g_return_val_if_fail (GTK_IS_WINDOW (parent_window), FALSE);
+ }
priv = GTK_FORM_GET_PRIVATE (form);
"obligatory", &obl,
NULL);
- if (obl && !gtk_form_field_is_empty (field))
+ if (obl && gtk_form_field_is_empty (field))
{
ret = FALSE;
+
+ fwidget = gtk_form_field_get_form_widget (field);
+ widget = gtk_form_widget_get_widget (fwidget);
+
+ if (form_widget != NULL)
+ {
+ *form_widget = fwidget;
+ }
+
+ if (show_error_dialog)
+ {
+ GtkWidget *dialog;
+ GtkWidget *label;
+ const gchar *label_text;
+
+ label = gtk_form_widget_get_label (fwidget);
+ if (GTK_IS_LABEL (label))
+ {
+ label_text = gtk_label_get_text (GTK_LABEL (label));
+ }
+ else
+ {
+ label_text = gtk_form_widget_get_widget_name (fwidget);
+ }
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (parent_window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "The field «%s» is obligatory.", label_text);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ }
+
+ if (set_focus)
+ {
+ gtk_widget_grab_focus (widget);
+ }
break;
}
GSList *fields = priv->fields;
while (fields != NULL)
{
- fwidget = gtk_form_field_get_gtk_form_widget ((GtkFormField *)fields->data);
+ fwidget = gtk_form_field_get_form_widget ((GtkFormField *)fields->data);
widget = gtk_form_widget_get_widget (fwidget);
gtk_widget_set_sensitive (widget, sensitive);
GSList *fields = priv->fields;
while (fields != NULL)
{
- fwidget = gtk_form_field_get_gtk_form_widget ((GtkFormField *)fields->data);
+ fwidget = gtk_form_field_get_form_widget ((GtkFormField *)fields->data);
gtk_form_widget_set_editable (fwidget, editable);
gboolean gtk_form_clear (GtkForm *form);
-gboolean gtk_form_check (GtkForm *form);
+gboolean gtk_form_check (GtkForm *form, GtkFormWidget **form_widget,
+ gboolean show_error_dialog, GtkWidget *parent_window,
+ gboolean set_focus);
gboolean gtk_form_is_changed (GtkForm *form);
{
GtkWidget *widget;
gchar *widget_name;
+
+ GtkWidget *label;
};
/**
* gtk_form_widget_set_from_gtkbuilder:
- * @fwidget:
+ * @fwidget: a #GtkFormWidget object.
* @gtkbuilder:
* @widget_name:
*
GtkBuilder *gtkbuilder,
const gchar *widget_name)
{
- gboolean ret = FALSE;
+ gboolean ret;
+
+ GtkWidget *w;
+
+ g_return_val_if_fail (IS_GTK_FORM_WIDGET (fwidget), FALSE);
+ g_return_val_if_fail (GTK_IS_BUILDER (gtkbuilder), FALSE);
+
+ ret = FALSE;
- GtkWidget *w = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, widget_name));
+ w = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, widget_name));
if (w != NULL)
{
g_object_set (fwidget,
ret = TRUE;
}
+ else
+ {
+ g_warning ("Widget «%s» not found.", widget_name);
+ }
return ret;
}
/**
* gtk_form_widget_get_widget:
- * @fwidget:
+ * @fwidget: a #GtkFormWidget object.
*
*/
GtkWidget
*gtk_form_widget_get_widget (GtkFormWidget *fwidget)
{
- GtkFormWidgetPrivate *priv = GTK_FORM_WIDGET_GET_PRIVATE (fwidget);
+ GtkFormWidgetPrivate *priv;
+
+ g_return_val_if_fail (IS_GTK_FORM_WIDGET (fwidget), NULL);
+
+ priv = GTK_FORM_WIDGET_GET_PRIVATE (fwidget);
return priv->widget;
}
/**
* gtk_form_widget_get_widget_name:
- * @fwidget:
+ * @fwidget: a #GtkFormWidget object.
*
* Returns: the #GtkFormWidget's name.
*/
const gchar
*gtk_form_widget_get_widget_name (GtkFormWidget *fwidget)
{
- GtkFormWidgetPrivate *priv = GTK_FORM_WIDGET_GET_PRIVATE (fwidget);
+ GtkFormWidgetPrivate *priv;
+
+ g_return_val_if_fail (IS_GTK_FORM_WIDGET (fwidget), NULL);
+
+ priv = GTK_FORM_WIDGET_GET_PRIVATE (fwidget);
return (const gchar *)g_strdup (priv->widget_name);
}
+/**
+ * gtk_form_widget_get_label:
+ * @fwidget: a #GtkFormWidget object.
+ *
+ */
+GtkWidget
+*gtk_form_widget_get_label (GtkFormWidget *fwidget)
+{
+ GtkFormWidgetPrivate *priv;
+
+ g_return_val_if_fail (IS_GTK_FORM_WIDGET (fwidget), NULL);
+
+ priv = GTK_FORM_WIDGET_GET_PRIVATE (fwidget);
+
+ return priv->label;
+}
+
+/**
+ * gtk_form_widget_set_label:
+ * @fwidget: a #GtkFormWidget object.
+ * @label: a @GtkLabel object.
+ *
+ */
+void
+gtk_form_widget_set_label (GtkFormWidget *fwidget, GtkLabel *label)
+{
+ GtkFormWidgetPrivate *priv;
+
+ g_return_if_fail (IS_GTK_FORM_WIDGET (fwidget));
+ g_return_if_fail (GTK_IS_LABEL (label));
+
+ priv = GTK_FORM_WIDGET_GET_PRIVATE (fwidget);
+
+ priv->label = GTK_WIDGET (label);
+}
+
/**
* gtk_form_widget_get_value_stringify:
- * @fwidget:
+ * @fwidget: a #GtkFormWidget object.
*
*/
const gchar
/**
* gtk_form_widget_set_value_stringify:
- * @fwidget:
+ * @fwidget: a #GtkFormWidget object.
* @value:
*
*/
/**
* gtk_form_widget_set_editable:
- * @fwidget:
+ * @fwidget: a #GtkFormWidget object.
* @editable:
*
*/
const gchar *gtk_form_widget_get_widget_name (GtkFormWidget *fwidget);
+GtkWidget *gtk_form_widget_get_label (GtkFormWidget *fwidget);
+void gtk_form_widget_set_label (GtkFormWidget *fwidget, GtkLabel *label);
+
const gchar *gtk_form_widget_get_value_stringify (GtkFormWidget *fwidget);
gboolean gtk_form_widget_set_value_stringify (GtkFormWidget *fwidget, const gchar *value);
on_btnCheck_clicked (GtkButton *button,
gpointer user_data)
{
- if (!gtk_form_check (form))
+ if (!gtk_form_check (form, NULL, FALSE, NULL, FALSE))
{
GtkWidget *diag = gtk_message_dialog_new (GTK_WINDOW (w),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
on_btnCheck_clicked (GtkButton *button,
gpointer user_data)
{
- if (!gtk_form_check (form))
+ if (!gtk_form_check (form, NULL, FALSE, NULL, FALSE))
{
GtkWidget *diag = gtk_message_dialog_new (GTK_WINDOW (w),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,