GValue *value,
GParamSpec *pspec);
+static void gtk_form_show_check_error_dialog (GtkFormWidget *fwidget,
+ GtkWidget *parent_window);
+
#define GTK_FORM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_FORM, GtkFormPrivate))
typedef struct _GtkFormPrivate GtkFormPrivate;
/**
* gtk_form_check:
* @form: a #GtkForm object.
+ * @with_key: whether check also the key or not.
* @form_widget: a #GtkFormWidget.
* @show_error_dialog:
* @set_focus:
* if @widget isn't NULL, it is the first #GtkFormWidget empty.
*/
gboolean
-gtk_form_check (GtkForm *form, GtkFormWidget **form_widget,
+gtk_form_check (GtkForm *form, gboolean with_key, GtkFormWidget **form_widget,
gboolean show_error_dialog, GtkWidget *parent_window,
gboolean set_focus)
{
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)
{
fwidget = gtk_form_field_get_form_widget (field);
widget = gtk_form_widget_get_widget (fwidget);
- if (form_widget != NULL)
- {
+ if (form_widget != NULL && *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);
+ gtk_form_show_check_error_dialog (fwidget, parent_window);
}
if (set_focus)
fields = g_slist_next (fields);
}
- if (ret && IS_GTK_FORM_KEY (priv->key))
+ if (with_key && ret && IS_GTK_FORM_KEY (priv->key))
{
- ret = gtk_form_key_check (priv->key);
+ GtkFormWidget *key_form_widget = NULL;
+
+ ret = gtk_form_key_check (priv->key, &key_form_widget);
+
+ if (!ret && form_widget != NULL && *form_widget == NULL && key_form_widget != NULL)
+ {
+ *form_widget = key_form_widget;
+ }
+
+ if (!ret && key_form_widget != NULL && show_error_dialog)
+ {
+ gtk_form_show_check_error_dialog (key_form_widget, parent_window);
+ }
+
+ if (!ret && key_form_widget != NULL && set_focus)
+ {
+ gtk_widget_grab_focus (gtk_form_widget_get_widget (key_form_widget));
+ }
}
return ret;
break;
}
}
+
+static void
+gtk_form_show_check_error_dialog (GtkFormWidget *fwidget, GtkWidget *parent_window)
+{
+ 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);
+}
gboolean gtk_form_clear (GtkForm *form);
-gboolean gtk_form_check (GtkForm *form, GtkFormWidget **form_widget,
+gboolean gtk_form_check (GtkForm *form, gboolean with_key,
+ GtkFormWidget **form_widget,
gboolean show_error_dialog, GtkWidget *parent_window,
gboolean set_focus);
typedef struct _GtkFormKeyPrivate GtkFormKeyPrivate;
struct _GtkFormKeyPrivate
{
- GList *fields;
+ GSList *fields;
};
g_return_val_if_fail (IS_GTK_FORM_FIELD (field), FALSE);
- priv->fields = g_list_append (priv->fields, field);
+ priv->fields = g_slist_append (priv->fields, field);
ret = TRUE;
g_return_val_if_fail (IS_GTK_FORM_FIELD (field), FALSE);
- priv->fields = g_list_remove (priv->fields, field);
+ priv->fields = g_slist_remove (priv->fields, field);
ret = TRUE;
/**
* gtk_form_key_check:
* @gtk_form_key: a #GtkFormKey object.
+ * @form_widget:
*
* Returns: TRUE if all obligatory fields are full.
*/
gboolean
-gtk_form_key_check (GtkFormKey *gtk_form_key)
+gtk_form_key_check (GtkFormKey *gtk_form_key, GtkFormWidget **form_widget)
{
GtkFormField *field;
- gboolean ret = FALSE;
+ gboolean ret;
- GtkFormKeyPrivate *priv = GTK_FORM_KEY_GET_PRIVATE (gtk_form_key);
+ GtkFormKeyPrivate *priv;
+ GSList *fields;
+
+ g_return_val_if_fail (IS_GTK_FORM_KEY (gtk_form_key), FALSE);
+
+ priv = GTK_FORM_KEY_GET_PRIVATE (gtk_form_key);
+
+ ret = TRUE;
- GList *fields = g_list_first (priv->fields);
+ fields = priv->fields;
while (fields != NULL)
{
if (gtk_form_field_is_empty (field))
{
- ret = TRUE;
+ GtkFormWidget *fwidget;
+
+ fwidget = gtk_form_field_get_form_widget (field);
+ if (form_widget != NULL && *form_widget == NULL)
+ {
+ *form_widget = fwidget;
+ }
+
+ ret = FALSE;
break;
}
- fields = g_list_next (fields);
+ fields = g_slist_next (fields);
}
return ret;
gchar *sql = "";
gchar *field_name;
+ GtkFormKeyPrivate *priv;
+ GSList *fields;
+
g_return_val_if_fail (IS_GTK_FORM_KEY (gtk_form_key), NULL);
- GtkFormKeyPrivate *priv = GTK_FORM_KEY_GET_PRIVATE (gtk_form_key);
+ priv = GTK_FORM_KEY_GET_PRIVATE (gtk_form_key);
- GList *fields = g_list_first (priv->fields);
+ fields = priv->fields;
while (fields != NULL)
{
sql = g_strconcat (sql, " AND ", field_name, " = ",
gtk_form_field_get_value_sql (field), NULL);
- fields = g_list_next (fields);
+ fields = g_slist_next (fields);
}
if (strcmp (sql, "") != 0)
gboolean
gtk_form_key_field_is_key (GtkFormKey *gtk_form_key, GtkFormField *field)
{
+ GtkFormKeyPrivate *priv;
+
g_return_val_if_fail (IS_GTK_FORM_KEY (gtk_form_key), FALSE);
g_return_val_if_fail (IS_GTK_FORM_FIELD (field), FALSE);
- GtkFormKeyPrivate *priv = GTK_FORM_KEY_GET_PRIVATE (gtk_form_key);
+ priv = GTK_FORM_KEY_GET_PRIVATE (gtk_form_key);
- return (g_list_index (priv->fields, field) >= 0 ? TRUE : FALSE);
+ return (g_slist_index (priv->fields, field) >= 0 ? TRUE : FALSE);
}
#include <glib.h>
#include "field.h"
+#include "widget.h"
G_BEGIN_DECLS
gboolean gtk_form_key_add_fields (GtkFormKey *gtk_form_key, ...);
-gboolean gtk_form_key_check (GtkFormKey *gtk_form_key);
+gboolean gtk_form_key_check (GtkFormKey *gtk_form_key, GtkFormWidget **form_widget);
gchar *gtk_form_key_get_sql (GtkFormKey *gtk_form_key);
on_btnCheck_clicked (GtkButton *button,
gpointer user_data)
{
- if (!gtk_form_check (form, NULL, FALSE, NULL, FALSE))
+ if (!gtk_form_check (form, TRUE, 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, NULL, FALSE, NULL, FALSE))
+ if (!gtk_form_check (form, TRUE, NULL, FALSE, NULL, FALSE))
{
GtkWidget *diag = gtk_message_dialog_new (GTK_WINDOW (w),
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,