2006-01-21 06:25:33 +00:00
|
|
|
/*
|
2008-07-01 22:57:50 +00:00
|
|
|
* GTK - The GIMP Toolkit
|
2006-01-21 06:25:33 +00:00
|
|
|
* Copyright (C) 1999 Red Hat, Inc.
|
|
|
|
* Copyright (C) 2002 Anders Carlsson <andersca@gnu.org>
|
|
|
|
* Copyright (C) 2003 Matthias Clasen <mclasen@redhat.com>
|
|
|
|
* Copyright (C) 2005 Carlos Garnacho Parro <carlosg@gnome.org>
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2006-01-21 06:25:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static GtkWidget*
|
|
|
|
get_test_page (const gchar *text)
|
|
|
|
{
|
|
|
|
return gtk_label_new (text);
|
|
|
|
}
|
|
|
|
|
2006-01-30 04:53:53 +00:00
|
|
|
typedef struct {
|
|
|
|
GtkAssistant *assistant;
|
|
|
|
GtkWidget *page;
|
|
|
|
} PageData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
complete_cb (GtkWidget *check,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
PageData *pdata = data;
|
|
|
|
gboolean complete;
|
|
|
|
|
|
|
|
complete = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
|
|
|
|
|
|
|
|
gtk_assistant_set_page_complete (pdata->assistant,
|
|
|
|
pdata->page,
|
|
|
|
complete);
|
|
|
|
}
|
|
|
|
|
2006-01-31 16:57:18 +00:00
|
|
|
static GtkWidget *
|
2006-01-30 04:53:53 +00:00
|
|
|
add_completion_test_page (GtkWidget *assistant,
|
|
|
|
const gchar *text,
|
|
|
|
gboolean visible,
|
|
|
|
gboolean complete)
|
|
|
|
{
|
|
|
|
GtkWidget *page;
|
|
|
|
GtkWidget *check;
|
|
|
|
PageData *pdata;
|
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
page = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2006-01-30 04:53:53 +00:00
|
|
|
check = gtk_check_button_new_with_label ("Complete");
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (page), gtk_label_new (text));
|
|
|
|
gtk_box_append (GTK_BOX (page), check);
|
2006-01-30 04:53:53 +00:00
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), complete);
|
|
|
|
|
|
|
|
pdata = g_new (PageData, 1);
|
|
|
|
pdata->assistant = GTK_ASSISTANT (assistant);
|
|
|
|
pdata->page = page;
|
|
|
|
g_signal_connect (G_OBJECT (check), "toggled",
|
|
|
|
G_CALLBACK (complete_cb), pdata);
|
|
|
|
|
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_set_visible (page, visible);
|
2006-01-30 04:53:53 +00:00
|
|
|
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, text);
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, complete);
|
2006-01-31 16:57:18 +00:00
|
|
|
|
|
|
|
return page;
|
2006-01-30 04:53:53 +00:00
|
|
|
}
|
|
|
|
|
2006-01-21 06:25:33 +00:00
|
|
|
static void
|
|
|
|
cancel_callback (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
g_print ("cancel\n");
|
|
|
|
|
|
|
|
gtk_widget_hide (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
close_callback (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
g_print ("close\n");
|
|
|
|
|
|
|
|
gtk_widget_hide (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
apply_callback (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
g_print ("apply\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
progress_timeout (GtkWidget *assistant)
|
|
|
|
{
|
2014-05-24 00:42:47 +00:00
|
|
|
GtkWidget *progress;
|
2006-01-21 06:25:33 +00:00
|
|
|
gint current_page;
|
|
|
|
gdouble value;
|
|
|
|
|
|
|
|
current_page = gtk_assistant_get_current_page (GTK_ASSISTANT (assistant));
|
2014-05-24 00:42:47 +00:00
|
|
|
progress = gtk_assistant_get_nth_page (GTK_ASSISTANT (assistant), current_page);
|
2006-01-21 06:25:33 +00:00
|
|
|
|
|
|
|
value = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (progress));
|
|
|
|
value += 0.1;
|
|
|
|
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress), value);
|
|
|
|
|
|
|
|
if (value >= 1.0)
|
|
|
|
{
|
2014-05-24 00:42:47 +00:00
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), progress, TRUE);
|
2006-01-21 06:25:33 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
prepare_callback (GtkWidget *widget, GtkWidget *page)
|
|
|
|
{
|
|
|
|
if (GTK_IS_LABEL (page))
|
|
|
|
g_print ("prepare: %s\n", gtk_label_get_text (GTK_LABEL (page)));
|
|
|
|
else if (gtk_assistant_get_page_type (GTK_ASSISTANT (widget), page) == GTK_ASSISTANT_PAGE_PROGRESS)
|
|
|
|
{
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (widget), page, FALSE);
|
2014-05-24 00:42:47 +00:00
|
|
|
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (page), 0.0);
|
2018-02-02 14:51:47 +00:00
|
|
|
g_timeout_add (300, (GSourceFunc) progress_timeout, widget);
|
2006-01-21 06:25:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
g_print ("prepare: %d\n", gtk_assistant_get_current_page (GTK_ASSISTANT (widget)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_simple_assistant (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *assistant = NULL;
|
|
|
|
|
|
|
|
if (!assistant)
|
|
|
|
{
|
|
|
|
GtkWidget *page;
|
|
|
|
|
|
|
|
assistant = gtk_assistant_new ();
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (assistant), 400, 300);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "cancel",
|
|
|
|
G_CALLBACK (cancel_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "close",
|
|
|
|
G_CALLBACK (close_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "apply",
|
|
|
|
G_CALLBACK (apply_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "prepare",
|
|
|
|
G_CALLBACK (prepare_callback), NULL);
|
|
|
|
|
|
|
|
page = get_test_page ("Page 1");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 1");
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
|
|
|
page = get_test_page ("Page 2");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 2");
|
|
|
|
gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_CONFIRM);
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
}
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (assistant))
|
2006-01-21 06:25:33 +00:00
|
|
|
gtk_widget_show (assistant);
|
|
|
|
else
|
|
|
|
{
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (assistant));
|
2006-01-21 06:25:33 +00:00
|
|
|
assistant = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-17 03:01:30 +00:00
|
|
|
static void
|
|
|
|
create_anonymous_assistant (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *assistant = NULL;
|
|
|
|
|
|
|
|
if (!assistant)
|
|
|
|
{
|
|
|
|
GtkWidget *page;
|
|
|
|
|
|
|
|
assistant = gtk_assistant_new ();
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (assistant), 400, 300);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "cancel",
|
|
|
|
G_CALLBACK (cancel_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "close",
|
|
|
|
G_CALLBACK (close_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "apply",
|
|
|
|
G_CALLBACK (apply_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "prepare",
|
|
|
|
G_CALLBACK (prepare_callback), NULL);
|
|
|
|
|
|
|
|
page = get_test_page ("Page 1");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
|
|
|
page = get_test_page ("Page 2");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_CONFIRM);
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_widget_get_visible (assistant))
|
|
|
|
gtk_widget_show (assistant);
|
|
|
|
else
|
|
|
|
{
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (assistant));
|
2011-04-17 03:01:30 +00:00
|
|
|
assistant = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-31 16:57:18 +00:00
|
|
|
static void
|
|
|
|
visible_cb (GtkWidget *check,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *page = data;
|
|
|
|
gboolean visible;
|
|
|
|
|
|
|
|
visible = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (page), "visible", visible, NULL);
|
|
|
|
}
|
|
|
|
|
2006-01-21 06:25:33 +00:00
|
|
|
static void
|
|
|
|
create_generous_assistant (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *assistant = NULL;
|
|
|
|
|
|
|
|
if (!assistant)
|
|
|
|
{
|
2006-01-31 16:57:18 +00:00
|
|
|
GtkWidget *page, *next, *check;
|
2009-12-10 16:34:29 +00:00
|
|
|
PageData *pdata;
|
2006-01-21 06:25:33 +00:00
|
|
|
|
|
|
|
assistant = gtk_assistant_new ();
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (assistant), 400, 300);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "cancel",
|
|
|
|
G_CALLBACK (cancel_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "close",
|
|
|
|
G_CALLBACK (close_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "apply",
|
|
|
|
G_CALLBACK (apply_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "prepare",
|
|
|
|
G_CALLBACK (prepare_callback), NULL);
|
|
|
|
|
|
|
|
page = get_test_page ("Introduction");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Introduction");
|
|
|
|
gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_INTRO);
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
2006-01-31 16:57:18 +00:00
|
|
|
page = add_completion_test_page (assistant, "Content", TRUE, FALSE);
|
|
|
|
next = add_completion_test_page (assistant, "More Content", TRUE, TRUE);
|
|
|
|
|
|
|
|
check = gtk_check_button_new_with_label ("Next page visible");
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE);
|
|
|
|
g_signal_connect (G_OBJECT (check), "toggled",
|
2020-05-11 14:57:25 +00:00
|
|
|
G_CALLBACK (visible_cb), next);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (page), check);
|
2006-01-31 16:57:18 +00:00
|
|
|
|
2006-01-30 04:53:53 +00:00
|
|
|
add_completion_test_page (assistant, "Even More Content", TRUE, TRUE);
|
2006-01-21 06:25:33 +00:00
|
|
|
|
|
|
|
page = get_test_page ("Confirmation");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Confirmation");
|
|
|
|
gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_CONFIRM);
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
2014-05-24 00:42:47 +00:00
|
|
|
page = gtk_progress_bar_new ();
|
|
|
|
gtk_widget_set_halign (page, GTK_ALIGN_FILL);
|
|
|
|
gtk_widget_set_valign (page, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_margin_start (page, 20);
|
|
|
|
gtk_widget_set_margin_end (page, 20);
|
2006-01-21 06:25:33 +00:00
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Progress");
|
|
|
|
gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_PROGRESS);
|
|
|
|
|
2009-12-10 16:34:29 +00:00
|
|
|
page = gtk_check_button_new_with_label ("Summary complete");
|
2006-01-21 06:25:33 +00:00
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Summary");
|
|
|
|
gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_SUMMARY);
|
2009-12-10 16:34:29 +00:00
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page),
|
|
|
|
gtk_assistant_get_page_complete (GTK_ASSISTANT (assistant),
|
|
|
|
page));
|
|
|
|
|
|
|
|
pdata = g_new (PageData, 1);
|
|
|
|
pdata->assistant = GTK_ASSISTANT (assistant);
|
|
|
|
pdata->page = page;
|
|
|
|
g_signal_connect (page, "toggled",
|
|
|
|
G_CALLBACK (complete_cb), pdata);
|
2006-01-21 06:25:33 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (assistant))
|
2006-01-21 06:25:33 +00:00
|
|
|
gtk_widget_show (assistant);
|
|
|
|
else
|
|
|
|
{
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (assistant));
|
2006-01-21 06:25:33 +00:00
|
|
|
assistant = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gchar selected_branch = 'A';
|
|
|
|
|
|
|
|
static void
|
|
|
|
select_branch (GtkWidget *widget, gchar branch)
|
|
|
|
{
|
|
|
|
selected_branch = branch;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
nonlinear_assistant_forward_page (gint current_page, gpointer data)
|
|
|
|
{
|
|
|
|
switch (current_page)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if (selected_branch == 'A')
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 2;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
return 3;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_nonlinear_assistant (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *assistant = NULL;
|
|
|
|
|
|
|
|
if (!assistant)
|
|
|
|
{
|
|
|
|
GtkWidget *page, *button;
|
|
|
|
|
|
|
|
assistant = gtk_assistant_new ();
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (assistant), 400, 300);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "cancel",
|
|
|
|
G_CALLBACK (cancel_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "close",
|
|
|
|
G_CALLBACK (close_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "apply",
|
|
|
|
G_CALLBACK (apply_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "prepare",
|
|
|
|
G_CALLBACK (prepare_callback), NULL);
|
|
|
|
|
|
|
|
gtk_assistant_set_forward_page_func (GTK_ASSISTANT (assistant),
|
|
|
|
nonlinear_assistant_forward_page,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
page = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
2006-01-21 06:25:33 +00:00
|
|
|
|
|
|
|
button = gtk_radio_button_new_with_label (NULL, "branch A");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (page), button);
|
2006-01-21 06:25:33 +00:00
|
|
|
g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (select_branch), GINT_TO_POINTER ('A'));
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
|
2016-10-02 15:37:22 +00:00
|
|
|
|
2006-01-21 06:25:33 +00:00
|
|
|
button = gtk_radio_button_new_with_label (gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
|
|
|
|
"branch B");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (page), button);
|
2006-01-21 06:25:33 +00:00
|
|
|
g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (select_branch), GINT_TO_POINTER ('B'));
|
|
|
|
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 1");
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
2016-10-02 15:37:22 +00:00
|
|
|
|
2006-01-21 06:25:33 +00:00
|
|
|
page = get_test_page ("Page 2A");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
2011-04-17 03:01:30 +00:00
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 2");
|
2006-01-21 06:25:33 +00:00
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
|
|
|
page = get_test_page ("Page 2B");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
2011-04-17 03:01:30 +00:00
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 2");
|
2006-01-21 06:25:33 +00:00
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
|
|
|
page = get_test_page ("Confirmation");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Confirmation");
|
|
|
|
gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_CONFIRM);
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
}
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (assistant))
|
2006-01-21 06:25:33 +00:00
|
|
|
gtk_widget_show (assistant);
|
|
|
|
else
|
|
|
|
{
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (assistant));
|
2006-01-21 06:25:33 +00:00
|
|
|
assistant = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
looping_assistant_forward_page (gint current_page, gpointer data)
|
|
|
|
{
|
|
|
|
switch (current_page)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return 1;
|
|
|
|
case 1:
|
|
|
|
return 2;
|
|
|
|
case 2:
|
|
|
|
return 3;
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
GtkAssistant *assistant;
|
|
|
|
GtkWidget *page;
|
|
|
|
|
|
|
|
assistant = (GtkAssistant*) data;
|
|
|
|
page = gtk_assistant_get_nth_page (assistant, current_page);
|
|
|
|
|
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (page)))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_looping_assistant (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *assistant = NULL;
|
|
|
|
|
|
|
|
if (!assistant)
|
|
|
|
{
|
|
|
|
GtkWidget *page;
|
|
|
|
|
|
|
|
assistant = gtk_assistant_new ();
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (assistant), 400, 300);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "cancel",
|
|
|
|
G_CALLBACK (cancel_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "close",
|
|
|
|
G_CALLBACK (close_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "apply",
|
|
|
|
G_CALLBACK (apply_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "prepare",
|
|
|
|
G_CALLBACK (prepare_callback), NULL);
|
|
|
|
|
|
|
|
gtk_assistant_set_forward_page_func (GTK_ASSISTANT (assistant),
|
|
|
|
looping_assistant_forward_page,
|
|
|
|
assistant, NULL);
|
|
|
|
|
|
|
|
page = get_test_page ("Introduction");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Introduction");
|
|
|
|
gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_INTRO);
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
|
|
|
page = get_test_page ("Content");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Content");
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
|
|
|
page = get_test_page ("More content");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "More content");
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
|
|
|
page = gtk_check_button_new_with_label ("Loop?");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Loop?");
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
|
|
|
page = get_test_page ("Confirmation");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Confirmation");
|
|
|
|
gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_CONFIRM);
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
}
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (assistant))
|
2006-01-21 06:25:33 +00:00
|
|
|
gtk_widget_show (assistant);
|
|
|
|
else
|
|
|
|
{
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (assistant));
|
2006-01-21 06:25:33 +00:00
|
|
|
assistant = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-17 03:01:30 +00:00
|
|
|
static void
|
|
|
|
toggle_invisible (GtkButton *button, GtkAssistant *assistant)
|
|
|
|
{
|
|
|
|
GtkWidget *page;
|
|
|
|
|
|
|
|
page = gtk_assistant_get_nth_page (assistant, 1);
|
|
|
|
|
|
|
|
gtk_widget_set_visible (page, !gtk_widget_get_visible (page));
|
|
|
|
}
|
|
|
|
|
2006-01-30 04:53:53 +00:00
|
|
|
static void
|
|
|
|
create_full_featured_assistant (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *assistant = NULL;
|
|
|
|
|
|
|
|
if (!assistant)
|
|
|
|
{
|
|
|
|
GtkWidget *page, *button;
|
|
|
|
|
|
|
|
assistant = gtk_assistant_new ();
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (assistant), 400, 300);
|
|
|
|
|
2013-06-24 21:31:22 +00:00
|
|
|
button = gtk_button_new_with_label ("_Stop");
|
2014-01-29 02:42:39 +00:00
|
|
|
gtk_button_set_use_underline (GTK_BUTTON (button), TRUE);
|
2011-05-06 20:08:09 +00:00
|
|
|
gtk_assistant_add_action_widget (GTK_ASSISTANT (assistant), button);
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (toggle_invisible), assistant);
|
2006-01-30 04:53:53 +00:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "cancel",
|
|
|
|
G_CALLBACK (cancel_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "close",
|
|
|
|
G_CALLBACK (close_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "apply",
|
|
|
|
G_CALLBACK (apply_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "prepare",
|
|
|
|
G_CALLBACK (prepare_callback), NULL);
|
|
|
|
|
|
|
|
page = get_test_page ("Page 1");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 1");
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
|
|
|
page = get_test_page ("Invisible page");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
2011-04-17 03:01:30 +00:00
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 2");
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
2006-01-30 04:53:53 +00:00
|
|
|
|
2015-06-15 01:05:49 +00:00
|
|
|
page = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_OPEN);
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Filechooser");
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
2006-01-30 04:53:53 +00:00
|
|
|
page = get_test_page ("Page 3");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 3");
|
|
|
|
gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_CONFIRM);
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
}
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (assistant))
|
2006-01-30 04:53:53 +00:00
|
|
|
gtk_widget_show (assistant);
|
|
|
|
else
|
|
|
|
{
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (assistant));
|
2006-01-30 04:53:53 +00:00
|
|
|
assistant = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-26 13:16:38 +00:00
|
|
|
static void
|
|
|
|
flip_pages (GtkButton *button, GtkAssistant *assistant)
|
|
|
|
{
|
|
|
|
GtkWidget *page;
|
|
|
|
gchar *title;
|
|
|
|
|
|
|
|
page = gtk_assistant_get_nth_page (assistant, 1);
|
|
|
|
|
|
|
|
g_object_ref (page);
|
|
|
|
|
|
|
|
title = g_strdup (gtk_assistant_get_page_title (assistant, page));
|
|
|
|
|
|
|
|
gtk_assistant_remove_page (assistant, 1);
|
|
|
|
gtk_assistant_insert_page (assistant, page, 2);
|
|
|
|
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, title);
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
|
|
|
g_object_unref (page);
|
|
|
|
g_free (title);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_page_flipping_assistant (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *assistant = NULL;
|
|
|
|
|
|
|
|
if (!assistant)
|
|
|
|
{
|
|
|
|
GtkWidget *page, *button;
|
|
|
|
|
|
|
|
assistant = gtk_assistant_new ();
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (assistant), 400, 300);
|
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("_Flip");
|
|
|
|
gtk_button_set_use_underline (GTK_BUTTON (button), TRUE);
|
|
|
|
gtk_assistant_add_action_widget (GTK_ASSISTANT (assistant), button);
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (flip_pages), assistant);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "cancel",
|
|
|
|
G_CALLBACK (cancel_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "close",
|
|
|
|
G_CALLBACK (close_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "apply",
|
|
|
|
G_CALLBACK (apply_callback), NULL);
|
|
|
|
g_signal_connect (G_OBJECT (assistant), "prepare",
|
|
|
|
G_CALLBACK (prepare_callback), NULL);
|
|
|
|
|
|
|
|
page = get_test_page ("Page 1");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 1");
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
2015-10-26 20:52:34 +00:00
|
|
|
page = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (page),
|
2017-04-21 20:34:36 +00:00
|
|
|
get_test_page ("Page 2"));
|
2015-10-26 13:16:38 +00:00
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 2");
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
|
|
|
page = get_test_page ("Page 3");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 3");
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
|
|
|
|
page = get_test_page ("Summary");
|
|
|
|
gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
|
|
|
|
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Summary");
|
|
|
|
gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_SUMMARY);
|
|
|
|
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_widget_get_visible (assistant))
|
|
|
|
gtk_widget_show (assistant);
|
|
|
|
else
|
|
|
|
{
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (assistant));
|
2015-10-26 13:16:38 +00:00
|
|
|
assistant = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-21 06:25:33 +00:00
|
|
|
struct {
|
2020-03-06 17:05:43 +00:00
|
|
|
const char *text;
|
2006-01-21 06:25:33 +00:00
|
|
|
void (*func) (GtkWidget *widget);
|
|
|
|
} buttons[] =
|
|
|
|
{
|
2006-01-30 04:53:53 +00:00
|
|
|
{ "simple assistant", create_simple_assistant },
|
2011-04-17 03:01:30 +00:00
|
|
|
{ "anonymous assistant", create_anonymous_assistant },
|
2006-01-30 04:53:53 +00:00
|
|
|
{ "generous assistant", create_generous_assistant },
|
|
|
|
{ "nonlinear assistant", create_nonlinear_assistant },
|
|
|
|
{ "looping assistant", create_looping_assistant },
|
|
|
|
{ "full featured assistant", create_full_featured_assistant },
|
2015-10-26 13:16:38 +00:00
|
|
|
{ "page-flipping assistant", create_page_flipping_assistant },
|
2006-01-21 06:25:33 +00:00
|
|
|
};
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
|
|
|
|
2006-01-21 06:25:33 +00:00
|
|
|
int
|
|
|
|
main (int argc, gchar *argv[])
|
|
|
|
{
|
|
|
|
GtkWidget *window, *box, *button;
|
|
|
|
gint i;
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean done = FALSE;
|
2006-01-21 06:25:33 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2006-01-21 06:25:33 +00:00
|
|
|
|
|
|
|
if (g_getenv ("RTL"))
|
|
|
|
gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
|
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2017-12-31 17:52:54 +00:00
|
|
|
gtk_window_set_hide_on_close (GTK_WINDOW (window), TRUE);
|
2006-01-21 06:25:33 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (quit_cb), &done);
|
2006-01-21 06:25:33 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), box);
|
2006-01-21 06:25:33 +00:00
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (buttons); i++)
|
|
|
|
{
|
|
|
|
button = gtk_button_new_with_label (buttons[i].text);
|
|
|
|
|
|
|
|
if (buttons[i].func)
|
|
|
|
g_signal_connect (G_OBJECT (button), "clicked",
|
|
|
|
G_CALLBACK (buttons[i].func), NULL);
|
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), button);
|
2006-01-21 06:25:33 +00:00
|
|
|
}
|
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2020-02-10 03:24:47 +00:00
|
|
|
|
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2006-01-21 06:25:33 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|