+2008-12-05 Claudio Saavedra <csaavedra@igalia.com>
+
+ * examples/hildon-wizard-dialog-example.c: (on_page_switch),
+ (some_page_func), (main): Update the example to use a
+ HildonWizardDialogPageFunc function.
+
+ * src/hildon-wizard-dialog-private.h: Add private data for
+ the HildonWizardDialogPageFunc function usage.
+
+ * src/hildon-wizard-dialog.c: (hildon_wizard_dialog_class_init),
+ (destroy), (hildon_wizard_dialog_init), (response),
+ (hildon_wizard_dialog_set_forward_page_func):
+ * src/hildon-wizard-dialog.h: Add a HildonWizardDialogPageFunc function,
+ that applications can use to stop a HildonWizardDialog to jump to
+ the next page.
+
+ Fixes: NB#94214 (No way to stop HildonWizardDialog from going to
+ next page)
+
2008-12-04 Alberto Garcia <agarcia@igalia.com>
* src/hildon-program.h
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <glib.h>
#include <gtk/gtk.h>
#include "hildon.h"
g_debug ("Page %d", num);
if (num == 1) {
- g_debug ("Making next insensitive! %d", num);
- gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), HILDON_WIZARD_DIALOG_NEXT, FALSE);
+ /* g_debug ("Making next insensitive! %d", num); */
+ /* gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), HILDON_WIZARD_DIALOG_NEXT, FALSE); */
}
-
+
+ return TRUE;
+}
+
+static gboolean
+some_page_func (GtkNotebook *nb,
+ gint current,
+ gpointer userdata)
+{
+ HildonEntry *entry;
+
+ /* Validate data only for the third page. */
+ switch (current) {
+ case 2:
+ entry = HILDON_ENTRY (gtk_notebook_get_nth_page (nb, current));
+ return (strlen (hildon_entry_get_text (entry)) != 0);
+ default:
return TRUE;
+ }
}
int
GtkWidget *notebook = gtk_notebook_new ();
GtkWidget *label_1 = gtk_label_new ("Page 1");
GtkWidget *label_2 = gtk_label_new ("Page 2");
- GtkWidget *label_3 = gtk_label_new ("Page 3");
+ GtkWidget *entry_3 = hildon_entry_new (HILDON_SIZE_AUTO);
+ hildon_entry_set_placeholder (HILDON_ENTRY (entry_3), " Write something to continue");
+ GtkWidget *label_4 = gtk_label_new ("Page 4");
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), label_1, NULL);
gtk_notebook_append_page (GTK_NOTEBOOK (notebook), label_2, NULL);
- gtk_notebook_append_page (GTK_NOTEBOOK (notebook), label_3, NULL);
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook), entry_3, NULL);
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook), label_4, NULL);
GtkWidget *dialog = hildon_wizard_dialog_new (NULL, "Wizard", GTK_NOTEBOOK (notebook));
g_signal_connect (G_OBJECT (notebook), "switch-page", G_CALLBACK (on_page_switch), dialog);
+ hildon_wizard_dialog_set_forward_page_func (HILDON_WIZARD_DIALOG (dialog),
+ some_page_func, NULL, NULL);
gtk_widget_show_all (dialog);
gtk_dialog_run (GTK_DIALOG (dialog));
static void
finalize (GObject *object);
+static void
+destroy (GObject *object);
+
static void
response (HildonWizardDialog *wizard,
gint response_id,
hildon_wizard_dialog_class_init (HildonWizardDialogClass *wizard_dialog_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (wizard_dialog_class);
-
+ GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (wizard_dialog_class);
parent_class = g_type_class_peek_parent (wizard_dialog_class);
g_type_class_add_private (wizard_dialog_class, sizeof (HildonWizardDialogPrivate));
object_class->set_property = hildon_wizard_dialog_set_property;
object_class->get_property = hildon_wizard_dialog_get_property;
object_class->finalize = finalize;
+ gtk_object_class->destroy = destroy;
/**
* HildonWizardDialog:wizard-name:
G_OBJECT_CLASS (parent_class)->finalize (object);
}
+static void
+destroy (GObject *object)
+{
+ HildonWizardDialogPrivate *priv = HILDON_WIZARD_DIALOG_GET_PRIVATE (object);
+
+ g_assert (priv);
+
+ if (priv->forward_function)
+ {
+ if (priv->forward_function_data &&
+ priv->forward_data_destroy)
+ priv->forward_data_destroy (priv->forward_function_data);
+
+ priv->forward_function = NULL;
+ priv->forward_function_data = NULL;
+ priv->forward_data_destroy = NULL;
+ }
+}
+
/* Disable or enable the Previous, Next and Finish buttons */
static void
make_buttons_sensitive (HildonWizardDialog *wizard_dialog,
priv->wizard_name = NULL;
priv->autotitle = TRUE;
+ priv->forward_function = NULL;
+ priv->forward_function_data = NULL;
+ priv->forward_data_destroy = NULL;
+
/* Add response buttons: finish, previous, next */
gtk_dialog_add_button (dialog, _("wdgt_bd_finish"), HILDON_WIZARD_DIALOG_FINISH);
gtk_dialog_add_button (dialog, _("wdgt_bd_previous"), HILDON_WIZARD_DIALOG_PREVIOUS);
break;
case HILDON_WIZARD_DIALOG_NEXT:
- ++current;
- is_last = (current == last);
- is_first = (current == 0);
- make_buttons_sensitive (wizard_dialog,
- !is_first, !is_first, !is_last);
- gtk_notebook_next_page (notebook); /* go to next page */
+
+ if (priv->forward_function &&
+ (*priv->forward_function) (priv->notebook, current, priv->forward_function_data)) {
+ ++current;
+ is_last = (current == last);
+ is_first = (current == 0);
+ make_buttons_sensitive (wizard_dialog,
+ !is_first, !is_first, !is_last);
+ gtk_notebook_next_page (notebook); /* go to next page */
+ }
break;
- case HILDON_WIZARD_DIALOG_FINISH:
+ case HILDON_WIZARD_DIALOG_FINISH:
return;
}
return widget;
}
+/**
+ * hildon_wizard_dialog_set_forward_page_func:
+ * @dialog: a #HildonWizardDialog
+ * @page_func: the #HildonWizardDialogPageFunc
+ * @data: user data for @page_func
+ * @destroy: destroy notifier for @data
+ *
+ * Sets the page forwarding function to be @page_func. This function
+ * will be used to determine whether it is possible to go to the next page
+ * when the user presses the forward button. Setting @page_func to %NULL
+ * wil make the wizard to simply go always to the next page.
+ *
+ * Since: 2.2
+ **/
+void
+hildon_wizard_dialog_set_forward_page_func (HildonWizardDialog *wizard_dialog,
+ HildonWizardDialogPageFunc page_func,
+ gpointer data,
+ GDestroyNotify destroy)
+{
+ g_return_if_fail (HILDON_IS_WIZARD_DIALOG (wizard_dialog));
+
+ HildonWizardDialogPrivate *priv = HILDON_WIZARD_DIALOG_GET_PRIVATE (wizard_dialog);
+
+ if (priv->forward_data_destroy &&
+ priv->forward_function_data) {
+ (*priv->forward_data_destroy) (priv->forward_function_data);
+ }
+
+ priv->forward_function = page_func;
+ priv->forward_function_data = data;
+ priv->forward_data_destroy = destroy;
+}