2 * GTK - The GIMP Toolkit
3 * Copyright (C) 1999 Red Hat, Inc.
4 * Copyright (C) 2002 Anders Carlsson <andersca@gnu.org>
5 * Copyright (C) 2003 Matthias Clasen <mclasen@redhat.com>
6 * Copyright (C) 2005 Carlos Garnacho Parro <carlosg@gnome.org>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
27 * SECTION:gtkassistant
28 * @Short_description: A widget used to guide users through multi-step operations
29 * @Title: GtkAssistant
31 * A #GtkAssistant is a widget used to represent a generally complex
32 * operation splitted in several steps, guiding the user through its pages
33 * and controlling the page flow to collect the necessary data.
35 * The design of GtkAssistant is that it controls what buttons to show and
36 * to make sensitive, based on what it knows about the page sequence and
37 * the <link linkend="GtkAssistantPageType">type</link> of each page, in
38 * addition to state information like the page
39 * <link linkend="gtk-assistant-set-page-complete">completion</link> and
40 * <link linkend="gtk-assistant-commit">committed</link> status.
42 * If you have a case that doesn't quite fit in #GtkAssistants way of
43 * handling buttons, you can use the #GTK_ASSISTANT_PAGE_CUSTOM page type
44 * and handle buttons yourself.
46 * <refsect2 id="GtkAssistant-BUILDER-UI">
47 * <title>GtkAssistant as GtkBuildable</title>
49 * The GtkAssistant implementation of the GtkBuildable interface exposes the
50 * @action_area as internal children with the name "action_area".
52 * To add pages to an assistant in GtkBuilder, simply add it as a
53 * <child> to the GtkAssistant object, and set its child properties
63 #include "gtkassistant.h"
65 #include "gtkbutton.h"
68 #include "gtknotebook.h"
71 #include "gtksizegroup.h"
72 #include "gtksizerequest.h"
74 #include "gtktypebuiltins.h"
76 #include "gtkprivate.h"
77 #include "gtkbuildable.h"
78 #include "a11y/gtkwindowaccessible.h"
81 #define HEADER_SPACING 12
82 #define ACTION_AREA_SPACING 12
84 typedef struct _GtkAssistantPage GtkAssistantPage;
86 struct _GtkAssistantPage
88 GtkAssistantPageType type;
90 guint complete_set : 1;
95 GtkWidget *regular_title;
96 GtkWidget *current_title;
97 GdkPixbuf *header_image;
98 GdkPixbuf *sidebar_image;
101 struct _GtkAssistantPrivate
112 GtkWidget *action_area;
115 GSList *visited_pages;
116 GtkAssistantPage *current_page;
118 GtkSizeGroup *button_size_group;
119 GtkSizeGroup *title_size_group;
121 GtkAssistantPageFunc forward_function;
122 gpointer forward_function_data;
123 GDestroyNotify forward_data_destroy;
130 static void gtk_assistant_class_init (GtkAssistantClass *class);
131 static void gtk_assistant_init (GtkAssistant *assistant);
132 static void gtk_assistant_destroy (GtkWidget *widget);
133 static void gtk_assistant_map (GtkWidget *widget);
134 static void gtk_assistant_unmap (GtkWidget *widget);
135 static gboolean gtk_assistant_delete_event (GtkWidget *widget,
137 static void gtk_assistant_add (GtkContainer *container,
139 static void gtk_assistant_remove (GtkContainer *container,
141 static void gtk_assistant_set_child_property (GtkContainer *container,
146 static void gtk_assistant_get_child_property (GtkContainer *container,
152 static void gtk_assistant_buildable_interface_init (GtkBuildableIface *iface);
153 static GObject *gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
155 const gchar *childname);
156 static gboolean gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
159 const gchar *tagname,
160 GMarkupParser *parser,
162 static void gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
165 const gchar *tagname,
168 static GList* find_page (GtkAssistant *assistant,
170 static void gtk_assistant_do_set_page_header_image (GtkAssistant *assistant,
173 static void gtk_assistant_do_set_page_side_image (GtkAssistant *assistant,
177 GType _gtk_assistant_accessible_get_type (void);
182 CHILD_PROP_PAGE_TYPE,
183 CHILD_PROP_PAGE_TITLE,
184 CHILD_PROP_PAGE_HEADER_IMAGE,
185 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
186 CHILD_PROP_PAGE_COMPLETE
198 static guint signals [LAST_SIGNAL] = { 0 };
201 G_DEFINE_TYPE_WITH_CODE (GtkAssistant, gtk_assistant, GTK_TYPE_WINDOW,
202 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
203 gtk_assistant_buildable_interface_init))
207 gtk_assistant_class_init (GtkAssistantClass *class)
209 GObjectClass *gobject_class;
210 GtkWidgetClass *widget_class;
211 GtkContainerClass *container_class;
213 gobject_class = (GObjectClass *) class;
214 widget_class = (GtkWidgetClass *) class;
215 container_class = (GtkContainerClass *) class;
217 widget_class->destroy = gtk_assistant_destroy;
218 widget_class->map = gtk_assistant_map;
219 widget_class->unmap = gtk_assistant_unmap;
220 widget_class->delete_event = gtk_assistant_delete_event;
222 gtk_widget_class_set_accessible_type (widget_class, _gtk_assistant_accessible_get_type ());
224 container_class->add = gtk_assistant_add;
225 container_class->remove = gtk_assistant_remove;
226 container_class->set_child_property = gtk_assistant_set_child_property;
227 container_class->get_child_property = gtk_assistant_get_child_property;
230 * GtkAssistant::cancel:
231 * @assistant: the #GtkAssistant
233 * The ::cancel signal is emitted when then the cancel button is clicked.
238 g_signal_new (I_("cancel"),
239 G_TYPE_FROM_CLASS (gobject_class),
241 G_STRUCT_OFFSET (GtkAssistantClass, cancel),
243 g_cclosure_marshal_VOID__VOID,
247 * GtkAssistant::prepare:
248 * @assistant: the #GtkAssistant
249 * @page: the current page
251 * The ::prepare signal is emitted when a new page is set as the
252 * assistant's current page, before making the new page visible.
254 * A handler for this signal can do any preparations which are
255 * necessary before showing @page.
260 g_signal_new (I_("prepare"),
261 G_TYPE_FROM_CLASS (gobject_class),
263 G_STRUCT_OFFSET (GtkAssistantClass, prepare),
265 g_cclosure_marshal_VOID__OBJECT,
266 G_TYPE_NONE, 1, GTK_TYPE_WIDGET);
269 * GtkAssistant::apply:
270 * @assistant: the #GtkAssistant
272 * The ::apply signal is emitted when the apply button is clicked.
274 * The default behavior of the #GtkAssistant is to switch to the page
275 * after the current page, unless the current page is the last one.
277 * A handler for the ::apply signal should carry out the actions for
278 * which the wizard has collected data. If the action takes a long time
279 * to complete, you might consider putting a page of type
280 * %GTK_ASSISTANT_PAGE_PROGRESS after the confirmation page and handle
281 * this operation within the #GtkAssistant::prepare signal of the progress
287 g_signal_new (I_("apply"),
288 G_TYPE_FROM_CLASS (gobject_class),
290 G_STRUCT_OFFSET (GtkAssistantClass, apply),
292 g_cclosure_marshal_VOID__VOID,
296 * GtkAssistant::close:
297 * @assistant: the #GtkAssistant
299 * The ::close signal is emitted either when the close button of
300 * a summary page is clicked, or when the apply button in the last
301 * page in the flow (of type %GTK_ASSISTANT_PAGE_CONFIRM) is clicked.
306 g_signal_new (I_("close"),
307 G_TYPE_FROM_CLASS (gobject_class),
309 G_STRUCT_OFFSET (GtkAssistantClass, close),
311 g_cclosure_marshal_VOID__VOID,
314 gtk_widget_class_install_style_property (widget_class,
315 g_param_spec_int ("header-padding",
316 P_("Header Padding"),
317 P_("Number of pixels around the header."),
321 GTK_PARAM_READABLE));
322 gtk_widget_class_install_style_property (widget_class,
323 g_param_spec_int ("content-padding",
324 P_("Content Padding"),
325 P_("Number of pixels around the content pages."),
329 GTK_PARAM_READABLE));
332 * GtkAssistant:page-type:
334 * The type of the assistant page.
338 gtk_container_class_install_child_property (container_class,
339 CHILD_PROP_PAGE_TYPE,
340 g_param_spec_enum ("page-type",
342 P_("The type of the assistant page"),
343 GTK_TYPE_ASSISTANT_PAGE_TYPE,
344 GTK_ASSISTANT_PAGE_CONTENT,
345 GTK_PARAM_READWRITE));
348 * GtkAssistant:title:
350 * The title of the page.
354 gtk_container_class_install_child_property (container_class,
355 CHILD_PROP_PAGE_TITLE,
356 g_param_spec_string ("title",
358 P_("The title of the assistant page"),
360 GTK_PARAM_READWRITE));
363 * GtkAssistant:header-image:
365 * This image used to be displayed in the page header.
369 * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
370 * add your header decoration to the page content instead.
372 gtk_container_class_install_child_property (container_class,
373 CHILD_PROP_PAGE_HEADER_IMAGE,
374 g_param_spec_object ("header-image",
376 P_("Header image for the assistant page"),
378 GTK_PARAM_READWRITE));
381 * GtkAssistant:sidebar-image:
383 * This image used to be displayed in the 'sidebar'.
387 * Deprecated: 3.2: Since GTK+ 3.2, the sidebar image is no longer shown.
389 gtk_container_class_install_child_property (container_class,
390 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
391 g_param_spec_object ("sidebar-image",
393 P_("Sidebar image for the assistant page"),
395 GTK_PARAM_READWRITE));
398 * GtkAssistant:complete:
400 * Setting the "complete" child property to %TRUE marks a page as
401 * complete (i.e.: all the required fields are filled out). GTK+ uses
402 * this information to control the sensitivity of the navigation buttons.
406 gtk_container_class_install_child_property (container_class,
407 CHILD_PROP_PAGE_COMPLETE,
408 g_param_spec_boolean ("complete",
410 P_("Whether all required fields on the page have been filled out"),
414 g_type_class_add_private (gobject_class, sizeof (GtkAssistantPrivate));
418 default_forward_function (gint current_page, gpointer data)
420 GtkAssistant *assistant;
421 GtkAssistantPrivate *priv;
422 GtkAssistantPage *page_info;
425 assistant = GTK_ASSISTANT (data);
426 priv = assistant->priv;
428 page_node = g_list_nth (priv->pages, ++current_page);
433 page_info = (GtkAssistantPage *) page_node->data;
435 while (page_node && !gtk_widget_get_visible (page_info->page))
437 page_node = page_node->next;
441 page_info = (GtkAssistantPage *) page_node->data;
448 last_button_visible (GtkAssistant *assistant, GtkAssistantPage *page)
450 GtkAssistantPrivate *priv = assistant->priv;
451 GtkAssistantPage *page_info;
452 gint count, page_num, n_pages;
457 if (page->type != GTK_ASSISTANT_PAGE_CONTENT)
461 page_num = g_list_index (priv->pages, page);
462 n_pages = g_list_length (priv->pages);
465 while (page_num >= 0 && page_num < n_pages &&
466 page_info->type == GTK_ASSISTANT_PAGE_CONTENT &&
467 (count == 0 || page_info->complete) &&
470 page_num = (priv->forward_function) (page_num, priv->forward_function_data);
471 page_info = g_list_nth_data (priv->pages, page_num);
476 /* Make the last button visible if we can skip multiple
477 * pages and end on a confirmation or summary page
479 if (count > 1 && page_info &&
480 (page_info->type == GTK_ASSISTANT_PAGE_CONFIRM ||
481 page_info->type == GTK_ASSISTANT_PAGE_SUMMARY))
488 update_actions_size (GtkAssistant *assistant)
490 GtkAssistantPrivate *priv = assistant->priv;
492 GtkAssistantPage *page;
493 gint buttons, page_buttons;
495 if (!priv->current_page)
498 /* Some heuristics to find out how many buttons we should
499 * reserve space for. It is possible to trick this code
500 * with page forward functions and invisible pages, etc.
503 for (l = priv->pages; l; l = l->next)
507 if (!gtk_widget_get_visible (page->page))
510 page_buttons = 2; /* cancel, forward/apply/close */
511 if (l != priv->pages)
512 page_buttons += 1; /* back */
513 if (last_button_visible (assistant, page))
514 page_buttons += 1; /* last */
516 buttons = MAX (buttons, page_buttons);
519 buttons += priv->extra_buttons;
521 gtk_widget_set_size_request (priv->action_area,
522 buttons * gtk_widget_get_allocated_width (priv->cancel) + (buttons - 1) * 6,
527 compute_last_button_state (GtkAssistant *assistant)
529 GtkAssistantPrivate *priv = assistant->priv;
531 gtk_widget_set_sensitive (priv->last, priv->current_page->complete);
532 if (last_button_visible (assistant, priv->current_page))
533 gtk_widget_show (priv->last);
535 gtk_widget_hide (priv->last);
539 compute_progress_state (GtkAssistant *assistant)
541 GtkAssistantPrivate *priv = assistant->priv;
542 gint page_num, n_pages;
544 n_pages = gtk_assistant_get_n_pages (assistant);
545 page_num = gtk_assistant_get_current_page (assistant);
547 page_num = (priv->forward_function) (page_num, priv->forward_function_data);
549 if (page_num >= 0 && page_num < n_pages)
550 gtk_widget_show (priv->forward);
552 gtk_widget_hide (priv->forward);
556 update_buttons_state (GtkAssistant *assistant)
558 GtkAssistantPrivate *priv = assistant->priv;
560 if (!priv->current_page)
563 switch (priv->current_page->type)
565 case GTK_ASSISTANT_PAGE_INTRO:
566 gtk_widget_set_sensitive (priv->cancel, TRUE);
567 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
568 gtk_widget_grab_default (priv->forward);
569 gtk_widget_show (priv->forward);
570 gtk_widget_hide (priv->back);
571 gtk_widget_hide (priv->apply);
572 gtk_widget_hide (priv->close);
573 compute_last_button_state (assistant);
575 case GTK_ASSISTANT_PAGE_CONFIRM:
576 gtk_widget_set_sensitive (priv->cancel, TRUE);
577 gtk_widget_set_sensitive (priv->back, TRUE);
578 gtk_widget_set_sensitive (priv->apply, priv->current_page->complete);
579 gtk_widget_grab_default (priv->apply);
580 gtk_widget_show (priv->back);
581 gtk_widget_show (priv->apply);
582 gtk_widget_hide (priv->forward);
583 gtk_widget_hide (priv->close);
584 gtk_widget_hide (priv->last);
586 case GTK_ASSISTANT_PAGE_CONTENT:
587 gtk_widget_set_sensitive (priv->cancel, TRUE);
588 gtk_widget_set_sensitive (priv->back, TRUE);
589 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
590 gtk_widget_grab_default (priv->forward);
591 gtk_widget_show (priv->back);
592 gtk_widget_show (priv->forward);
593 gtk_widget_hide (priv->apply);
594 gtk_widget_hide (priv->close);
595 compute_last_button_state (assistant);
597 case GTK_ASSISTANT_PAGE_SUMMARY:
598 gtk_widget_set_sensitive (priv->close, priv->current_page->complete);
599 gtk_widget_grab_default (priv->close);
600 gtk_widget_show (priv->close);
601 gtk_widget_hide (priv->back);
602 gtk_widget_hide (priv->forward);
603 gtk_widget_hide (priv->apply);
604 gtk_widget_hide (priv->last);
606 case GTK_ASSISTANT_PAGE_PROGRESS:
607 gtk_widget_set_sensitive (priv->cancel, priv->current_page->complete);
608 gtk_widget_set_sensitive (priv->back, priv->current_page->complete);
609 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
610 gtk_widget_grab_default (priv->forward);
611 gtk_widget_show (priv->back);
612 gtk_widget_hide (priv->apply);
613 gtk_widget_hide (priv->close);
614 gtk_widget_hide (priv->last);
615 compute_progress_state (assistant);
617 case GTK_ASSISTANT_PAGE_CUSTOM:
618 gtk_widget_hide (priv->cancel);
619 gtk_widget_hide (priv->back);
620 gtk_widget_hide (priv->forward);
621 gtk_widget_hide (priv->apply);
622 gtk_widget_hide (priv->last);
623 gtk_widget_hide (priv->close);
626 g_assert_not_reached ();
630 gtk_widget_hide (priv->cancel);
631 else if (priv->current_page->type == GTK_ASSISTANT_PAGE_SUMMARY ||
632 priv->current_page->type == GTK_ASSISTANT_PAGE_CUSTOM)
633 gtk_widget_hide (priv->cancel);
635 gtk_widget_show (priv->cancel);
637 /* this is quite general, we don't want to
638 * go back if it's the first page
640 if (!priv->visited_pages)
641 gtk_widget_hide (priv->back);
645 update_page_title_state (GtkAssistant *assistant, GList *list)
647 GtkAssistantPage *page, *other;
648 GtkAssistantPrivate *priv = assistant->priv;
654 if (page->title == NULL || page->title[0] == 0)
657 visible = gtk_widget_get_visible (page->page);
659 if (page == priv->current_page)
661 gtk_widget_set_visible (page->regular_title, FALSE);
662 gtk_widget_set_visible (page->current_title, visible);
666 /* If multiple consecutive pages have the same title,
667 * we only show it once, since it would otherwise look
668 * silly. We have to be a little careful, since we
669 * _always_ show the title of the current page.
673 other = list->prev->data;
674 if (g_strcmp0 (page->title, other->title) == 0)
677 for (l = list->next; l; l = l->next)
680 if (g_strcmp0 (page->title, other->title) != 0)
683 if (other == priv->current_page)
690 gtk_widget_set_visible (page->regular_title, visible);
691 gtk_widget_set_visible (page->current_title, FALSE);
698 update_title_state (GtkAssistant *assistant)
700 GtkAssistantPrivate *priv = assistant->priv;
702 gboolean show_titles;
705 for (l = priv->pages; l != NULL; l = l->next)
707 if (update_page_title_state (assistant, l))
711 gtk_widget_set_visible (priv->sidebar, show_titles);
715 set_current_page (GtkAssistant *assistant,
718 GtkAssistantPrivate *priv = assistant->priv;
720 priv->current_page = (GtkAssistantPage *)g_list_nth_data (priv->pages, page_num);
722 g_signal_emit (assistant, signals [PREPARE], 0, priv->current_page->page);
724 update_title_state (assistant);
726 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->content), page_num);
728 /* update buttons state, flow may have changed */
729 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
730 update_buttons_state (assistant);
732 if (!gtk_widget_child_focus (priv->current_page->page, GTK_DIR_TAB_FORWARD))
734 GtkWidget *button[6];
737 /* find the best button to focus */
738 button[0] = priv->apply;
739 button[1] = priv->close;
740 button[2] = priv->forward;
741 button[3] = priv->back;
742 button[4] = priv->cancel;
743 button[5] = priv->last;
744 for (i = 0; i < 6; i++)
746 if (gtk_widget_get_visible (button[i]) &&
747 gtk_widget_get_sensitive (button[i]))
749 gtk_widget_grab_focus (button[i]);
755 gtk_widget_queue_resize (GTK_WIDGET (assistant));
759 compute_next_step (GtkAssistant *assistant)
761 GtkAssistantPrivate *priv = assistant->priv;
762 GtkAssistantPage *page_info;
763 gint current_page, n_pages, next_page;
765 current_page = gtk_assistant_get_current_page (assistant);
766 page_info = priv->current_page;
767 n_pages = gtk_assistant_get_n_pages (assistant);
769 next_page = (priv->forward_function) (current_page,
770 priv->forward_function_data);
772 if (next_page >= 0 && next_page < n_pages)
774 priv->visited_pages = g_slist_prepend (priv->visited_pages, page_info);
775 set_current_page (assistant, next_page);
784 on_assistant_close (GtkWidget *widget,
785 GtkAssistant *assistant)
787 g_signal_emit (assistant, signals [CLOSE], 0, NULL);
791 on_assistant_apply (GtkWidget *widget,
792 GtkAssistant *assistant)
796 g_signal_emit (assistant, signals [APPLY], 0);
798 success = compute_next_step (assistant);
800 /* if the assistant hasn't switched to another page, just emit
801 * the CLOSE signal, it't the last page in the assistant flow
804 g_signal_emit (assistant, signals [CLOSE], 0);
808 on_assistant_forward (GtkWidget *widget,
809 GtkAssistant *assistant)
811 gtk_assistant_next_page (assistant);
815 on_assistant_back (GtkWidget *widget,
816 GtkAssistant *assistant)
818 gtk_assistant_previous_page (assistant);
822 on_assistant_cancel (GtkWidget *widget,
823 GtkAssistant *assistant)
825 g_signal_emit (assistant, signals [CANCEL], 0, NULL);
829 on_assistant_last (GtkWidget *widget,
830 GtkAssistant *assistant)
832 GtkAssistantPrivate *priv = assistant->priv;
834 while (priv->current_page->type == GTK_ASSISTANT_PAGE_CONTENT &&
835 priv->current_page->complete)
836 compute_next_step (assistant);
840 alternative_button_order (GtkAssistant *assistant)
842 GtkSettings *settings;
846 screen = gtk_widget_get_screen (GTK_WIDGET (assistant));
847 settings = gtk_settings_get_for_screen (screen);
849 g_object_get (settings,
850 "gtk-alternative-button-order", &result,
856 assistant_sidebar_draw_cb (GtkWidget *widget,
861 GtkStyleContext *context;
863 width = gtk_widget_get_allocated_width (widget);
864 height = gtk_widget_get_allocated_height (widget);
865 context = gtk_widget_get_style_context (widget);
867 gtk_render_background (context, cr, 0, 0, width, height);
873 on_page_notify_visibility (GtkWidget *widget,
877 GtkAssistant *assistant = GTK_ASSISTANT (data);
879 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
881 update_buttons_state (assistant);
882 update_title_state (assistant);
887 assistant_remove_page_cb (GtkNotebook *notebook,
889 GtkAssistant *assistant)
891 GtkAssistantPrivate *priv = assistant->priv;
892 GtkAssistantPage *page_info;
896 element = find_page (assistant, page);
900 page_info = element->data;
902 /* If this is the current page, we need to switch away. */
903 if (page_info == priv->current_page)
905 if (!compute_next_step (assistant))
907 /* The best we can do at this point is probably to pick
908 * the first visible page.
910 page_node = priv->pages;
913 !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
914 page_node = page_node->next;
916 if (page_node == element)
917 page_node = page_node->next;
920 priv->current_page = page_node->data;
922 priv->current_page = NULL;
926 g_signal_handlers_disconnect_by_func (page_info->page, on_page_notify_visibility, assistant);
928 gtk_size_group_remove_widget (priv->title_size_group, page_info->regular_title);
929 gtk_size_group_remove_widget (priv->title_size_group, page_info->current_title);
931 gtk_container_remove (GTK_CONTAINER (priv->sidebar), page_info->regular_title);
932 gtk_container_remove (GTK_CONTAINER (priv->sidebar), page_info->current_title);
934 priv->pages = g_list_remove_link (priv->pages, element);
935 priv->visited_pages = g_slist_remove_all (priv->visited_pages, page_info);
937 g_free (page_info->title);
939 g_slice_free (GtkAssistantPage, page_info);
940 g_list_free_1 (element);
942 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
944 update_buttons_state (assistant);
945 update_actions_size (assistant);
950 gtk_assistant_init (GtkAssistant *assistant)
952 GtkAssistantPrivate *priv;
953 GtkStyleContext *context;
955 GtkWidget *content_box;
956 GtkWidget *sidebar_frame;
958 assistant->priv = G_TYPE_INSTANCE_GET_PRIVATE (assistant,
960 GtkAssistantPrivate);
961 priv = assistant->priv;
963 /* use border on inner panes instead */
964 gtk_container_set_border_width (GTK_CONTAINER (assistant), 0);
966 gtk_widget_push_composite_child ();
968 main_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
969 priv->sidebar = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
971 /* use a frame for the sidebar, and manually render a background
972 * in it. GtkFrame also gives us padding support for free.
974 sidebar_frame = gtk_frame_new (NULL);
975 context = gtk_widget_get_style_context (sidebar_frame);
976 gtk_style_context_add_class (context, GTK_STYLE_CLASS_SIDEBAR);
978 g_signal_connect (sidebar_frame, "draw",
979 G_CALLBACK (assistant_sidebar_draw_cb), assistant);
981 content_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
982 gtk_container_set_border_width (GTK_CONTAINER (content_box), 12);
983 priv->content = gtk_notebook_new ();
984 gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->content), FALSE);
985 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->content), FALSE);
986 priv->action_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
988 g_signal_connect (priv->content, "remove",
989 G_CALLBACK (assistant_remove_page_cb), assistant);
991 gtk_container_add (GTK_CONTAINER (sidebar_frame), priv->sidebar);
992 gtk_box_pack_start (GTK_BOX (main_box), sidebar_frame, FALSE, FALSE, 0);
993 gtk_box_pack_start (GTK_BOX (main_box), content_box, TRUE, TRUE, 0);
994 gtk_box_pack_start (GTK_BOX (content_box), priv->content, TRUE, TRUE, 0);
995 gtk_box_pack_start (GTK_BOX (content_box), priv->action_area, FALSE, TRUE, 0);
996 gtk_widget_set_halign (priv->action_area, GTK_ALIGN_END);
998 gtk_widget_show_all (main_box);
1000 gtk_widget_set_parent (main_box, GTK_WIDGET (assistant));
1001 _gtk_bin_set_child (GTK_BIN (assistant), main_box);
1003 priv->close = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
1004 priv->apply = gtk_button_new_from_stock (GTK_STOCK_APPLY);
1005 priv->forward = gtk_button_new_with_mnemonic (_("C_ontinue"));
1006 gtk_button_set_image (GTK_BUTTON (priv->forward),
1007 gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD, GTK_ICON_SIZE_BUTTON));
1008 priv->back = gtk_button_new_with_mnemonic (_("Go _Back"));
1009 gtk_button_set_image (GTK_BUTTON (priv->forward),
1010 gtk_image_new_from_stock (GTK_STOCK_GO_BACK, GTK_ICON_SIZE_BUTTON));
1011 priv->cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
1012 priv->last = gtk_button_new_with_mnemonic (_("_Finish"));
1013 gtk_button_set_image (GTK_BUTTON (priv->forward),
1014 gtk_image_new_from_stock (GTK_STOCK_GOTO_LAST, GTK_ICON_SIZE_BUTTON));
1015 gtk_widget_set_can_default (priv->close, TRUE);
1016 gtk_widget_set_can_default (priv->apply, TRUE);
1017 gtk_widget_set_can_default (priv->forward, TRUE);
1019 priv->button_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
1020 gtk_size_group_add_widget (priv->button_size_group, priv->close);
1021 gtk_size_group_add_widget (priv->button_size_group, priv->apply);
1022 gtk_size_group_add_widget (priv->button_size_group, priv->forward);
1023 gtk_size_group_add_widget (priv->button_size_group, priv->back);
1024 gtk_size_group_add_widget (priv->button_size_group, priv->cancel);
1025 gtk_size_group_add_widget (priv->button_size_group, priv->last);
1027 gtk_widget_set_no_show_all (priv->close, TRUE);
1028 gtk_widget_set_no_show_all (priv->apply, TRUE);
1029 gtk_widget_set_no_show_all (priv->forward, TRUE);
1030 gtk_widget_set_no_show_all (priv->back, TRUE);
1031 gtk_widget_set_no_show_all (priv->cancel, TRUE);
1032 gtk_widget_set_no_show_all (priv->last, TRUE);
1034 if (!alternative_button_order (assistant))
1036 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
1037 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
1038 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
1039 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
1040 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
1041 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->close, FALSE, FALSE, 0);
1045 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->close, FALSE, FALSE, 0);
1046 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
1047 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
1048 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
1049 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
1050 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
1053 gtk_widget_show (priv->forward);
1054 gtk_widget_show (priv->back);
1055 gtk_widget_show (priv->cancel);
1056 gtk_widget_show (priv->action_area);
1058 gtk_widget_pop_composite_child ();
1060 priv->title_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
1063 priv->current_page = NULL;
1064 priv->visited_pages = NULL;
1066 priv->forward_function = default_forward_function;
1067 priv->forward_function_data = assistant;
1068 priv->forward_data_destroy = NULL;
1070 g_signal_connect (G_OBJECT (priv->close), "clicked",
1071 G_CALLBACK (on_assistant_close), assistant);
1072 g_signal_connect (G_OBJECT (priv->apply), "clicked",
1073 G_CALLBACK (on_assistant_apply), assistant);
1074 g_signal_connect (G_OBJECT (priv->forward), "clicked",
1075 G_CALLBACK (on_assistant_forward), assistant);
1076 g_signal_connect (G_OBJECT (priv->back), "clicked",
1077 G_CALLBACK (on_assistant_back), assistant);
1078 g_signal_connect (G_OBJECT (priv->cancel), "clicked",
1079 G_CALLBACK (on_assistant_cancel), assistant);
1080 g_signal_connect (G_OBJECT (priv->last), "clicked",
1081 G_CALLBACK (on_assistant_last), assistant);
1085 gtk_assistant_set_child_property (GtkContainer *container,
1088 const GValue *value,
1091 switch (property_id)
1093 case CHILD_PROP_PAGE_TYPE:
1094 gtk_assistant_set_page_type (GTK_ASSISTANT (container), child,
1095 g_value_get_enum (value));
1097 case CHILD_PROP_PAGE_TITLE:
1098 gtk_assistant_set_page_title (GTK_ASSISTANT (container), child,
1099 g_value_get_string (value));
1101 case CHILD_PROP_PAGE_HEADER_IMAGE:
1102 gtk_assistant_do_set_page_header_image (GTK_ASSISTANT (container), child,
1103 g_value_get_object (value));
1105 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
1106 gtk_assistant_do_set_page_side_image (GTK_ASSISTANT (container), child,
1107 g_value_get_object (value));
1109 case CHILD_PROP_PAGE_COMPLETE:
1110 gtk_assistant_set_page_complete (GTK_ASSISTANT (container), child,
1111 g_value_get_boolean (value));
1114 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
1120 gtk_assistant_get_child_property (GtkContainer *container,
1126 GtkAssistant *assistant = GTK_ASSISTANT (container);
1128 switch (property_id)
1130 case CHILD_PROP_PAGE_TYPE:
1131 g_value_set_enum (value,
1132 gtk_assistant_get_page_type (assistant, child));
1134 case CHILD_PROP_PAGE_TITLE:
1135 g_value_set_string (value,
1136 gtk_assistant_get_page_title (assistant, child));
1138 case CHILD_PROP_PAGE_HEADER_IMAGE:
1139 g_value_set_object (value,
1140 ((GtkAssistantPage*) find_page (assistant, child))->header_image);
1142 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
1143 g_value_set_object (value,
1144 ((GtkAssistantPage*) find_page (assistant, child))->sidebar_image);
1146 case CHILD_PROP_PAGE_COMPLETE:
1147 g_value_set_boolean (value,
1148 gtk_assistant_get_page_complete (assistant, child));
1151 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
1157 gtk_assistant_destroy (GtkWidget *widget)
1159 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1160 GtkAssistantPrivate *priv = assistant->priv;
1162 /* We set current to NULL so that the remove code doesn't try
1163 * to do anything funny
1165 priv->current_page = NULL;
1169 GtkNotebook *notebook;
1172 /* Remove all pages from the content notebook. */
1173 notebook = (GtkNotebook *) priv->content;
1174 while ((page = gtk_notebook_get_nth_page (notebook, 0)) != NULL)
1175 gtk_container_remove ((GtkContainer *) notebook, page);
1177 /* Our GtkAssistantPage list should be empty now. */
1178 g_warn_if_fail (priv->pages == NULL);
1180 priv->content = NULL;
1184 priv->sidebar = NULL;
1186 if (priv->action_area)
1187 priv->action_area = NULL;
1189 if (priv->button_size_group)
1191 g_object_unref (priv->button_size_group);
1192 priv->button_size_group = NULL;
1195 if (priv->title_size_group)
1197 g_object_unref (priv->title_size_group);
1198 priv->title_size_group = NULL;
1201 if (priv->forward_function)
1203 if (priv->forward_function_data &&
1204 priv->forward_data_destroy)
1205 priv->forward_data_destroy (priv->forward_function_data);
1207 priv->forward_function = NULL;
1208 priv->forward_function_data = NULL;
1209 priv->forward_data_destroy = NULL;
1212 if (priv->visited_pages)
1214 g_slist_free (priv->visited_pages);
1215 priv->visited_pages = NULL;
1218 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->destroy (widget);
1222 find_page (GtkAssistant *assistant,
1225 GtkAssistantPrivate *priv = assistant->priv;
1226 GList *child = priv->pages;
1230 GtkAssistantPage *page_info = child->data;
1231 if (page_info->page == page)
1234 child = child->next;
1241 gtk_assistant_map (GtkWidget *widget)
1243 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1244 GtkAssistantPrivate *priv = assistant->priv;
1246 GtkAssistantPage *page;
1249 /* if there's no default page, pick the first one */
1252 if (!priv->current_page)
1254 page_node = priv->pages;
1256 while (page_node && !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
1258 page_node = page_node->next;
1263 page = page_node->data;
1266 if (page && gtk_widget_get_visible (page->page))
1267 set_current_page (assistant, page_num);
1269 update_buttons_state (assistant);
1270 update_actions_size (assistant);
1271 update_title_state (assistant);
1273 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->map (widget);
1277 gtk_assistant_unmap (GtkWidget *widget)
1279 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1280 GtkAssistantPrivate *priv = assistant->priv;
1282 g_slist_free (priv->visited_pages);
1283 priv->visited_pages = NULL;
1284 priv->current_page = NULL;
1286 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->unmap (widget);
1290 gtk_assistant_delete_event (GtkWidget *widget,
1293 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1294 GtkAssistantPrivate *priv = assistant->priv;
1296 /* Do not allow cancelling in the middle of a progress page */
1297 if (priv->current_page &&
1298 (priv->current_page->type != GTK_ASSISTANT_PAGE_PROGRESS ||
1299 priv->current_page->complete))
1300 g_signal_emit (widget, signals [CANCEL], 0, NULL);
1306 gtk_assistant_add (GtkContainer *container,
1309 gtk_assistant_append_page (GTK_ASSISTANT (container), page);
1313 gtk_assistant_remove (GtkContainer *container,
1316 GtkAssistant *assistant = (GtkAssistant*) container;
1318 /* Forward this removal to the content notebook */
1319 if (gtk_widget_get_parent (page) == assistant->priv->content)
1321 container = (GtkContainer *) assistant->priv->content;
1322 gtk_container_remove (container, page);
1327 * gtk_assistant_new:
1329 * Creates a new #GtkAssistant.
1331 * Return value: a newly created #GtkAssistant
1336 gtk_assistant_new (void)
1338 GtkWidget *assistant;
1340 assistant = g_object_new (GTK_TYPE_ASSISTANT, NULL);
1346 * gtk_assistant_get_current_page:
1347 * @assistant: a #GtkAssistant
1349 * Returns the page number of the current page.
1351 * Return value: The index (starting from 0) of the current
1352 * page in the @assistant, or -1 if the @assistant has no pages,
1353 * or no current page.
1358 gtk_assistant_get_current_page (GtkAssistant *assistant)
1360 GtkAssistantPrivate *priv;
1362 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), -1);
1364 priv = assistant->priv;
1366 if (!priv->pages || !priv->current_page)
1369 return g_list_index (priv->pages, priv->current_page);
1373 * gtk_assistant_set_current_page:
1374 * @assistant: a #GtkAssistant
1375 * @page_num: index of the page to switch to, starting from 0.
1376 * If negative, the last page will be used. If greater
1377 * than the number of pages in the @assistant, nothing
1380 * Switches the page to @page_num.
1382 * Note that this will only be necessary in custom buttons,
1383 * as the @assistant flow can be set with
1384 * gtk_assistant_set_forward_page_func().
1389 gtk_assistant_set_current_page (GtkAssistant *assistant,
1392 GtkAssistantPrivate *priv;
1393 GtkAssistantPage *page;
1395 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1397 priv = assistant->priv;
1400 page = (GtkAssistantPage *) g_list_nth_data (priv->pages, page_num);
1403 page = (GtkAssistantPage *) g_list_last (priv->pages)->data;
1404 page_num = g_list_length (priv->pages);
1407 g_return_if_fail (page != NULL);
1409 if (priv->current_page == page)
1412 /* only add the page to the visited list if the assistant is mapped,
1413 * if not, just use it as an initial page setting, for the cases where
1414 * the initial page is != to 0
1416 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1417 priv->visited_pages = g_slist_prepend (priv->visited_pages,
1418 priv->current_page);
1420 set_current_page (assistant, page_num);
1424 * gtk_assistant_next_page:
1425 * @assistant: a #GtkAssistant
1427 * Navigate to the next page.
1429 * It is a programming error to call this function when
1430 * there is no next page.
1432 * This function is for use when creating pages of the
1433 * #GTK_ASSISTANT_PAGE_CUSTOM type.
1438 gtk_assistant_next_page (GtkAssistant *assistant)
1440 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1442 if (!compute_next_step (assistant))
1443 g_critical ("Page flow is broken.\n"
1444 "You may want to end it with a page of type\n"
1445 "GTK_ASSISTANT_PAGE_CONFIRM or GTK_ASSISTANT_PAGE_SUMMARY");
1449 * gtk_assistant_previous_page:
1450 * @assistant: a #GtkAssistant
1452 * Navigate to the previous visited page.
1454 * It is a programming error to call this function when
1455 * no previous page is available.
1457 * This function is for use when creating pages of the
1458 * #GTK_ASSISTANT_PAGE_CUSTOM type.
1463 gtk_assistant_previous_page (GtkAssistant *assistant)
1465 GtkAssistantPrivate *priv;
1466 GtkAssistantPage *page_info;
1469 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1471 priv = assistant->priv;
1473 /* skip the progress pages when going back */
1476 page_node = priv->visited_pages;
1478 g_return_if_fail (page_node != NULL);
1480 priv->visited_pages = priv->visited_pages->next;
1481 page_info = (GtkAssistantPage *) page_node->data;
1482 g_slist_free_1 (page_node);
1484 while (page_info->type == GTK_ASSISTANT_PAGE_PROGRESS ||
1485 !gtk_widget_get_visible (page_info->page));
1487 set_current_page (assistant, g_list_index (priv->pages, page_info));
1491 * gtk_assistant_get_n_pages:
1492 * @assistant: a #GtkAssistant
1494 * Returns the number of pages in the @assistant
1496 * Return value: the number of pages in the @assistant
1501 gtk_assistant_get_n_pages (GtkAssistant *assistant)
1503 GtkAssistantPrivate *priv;
1505 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1507 priv = assistant->priv;
1509 return g_list_length (priv->pages);
1513 * gtk_assistant_get_nth_page:
1514 * @assistant: a #GtkAssistant
1515 * @page_num: the index of a page in the @assistant,
1516 * or -1 to get the last page
1518 * Returns the child widget contained in page number @page_num.
1520 * Return value: (transfer none): the child widget, or %NULL
1521 * if @page_num is out of bounds
1526 gtk_assistant_get_nth_page (GtkAssistant *assistant,
1529 GtkAssistantPrivate *priv;
1530 GtkAssistantPage *page;
1533 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1534 g_return_val_if_fail (page_num >= -1, NULL);
1536 priv = assistant->priv;
1539 elem = g_list_last (priv->pages);
1541 elem = g_list_nth (priv->pages, page_num);
1546 page = (GtkAssistantPage *) elem->data;
1552 * gtk_assistant_prepend_page:
1553 * @assistant: a #GtkAssistant
1554 * @page: a #GtkWidget
1556 * Prepends a page to the @assistant.
1558 * Return value: the index (starting at 0) of the inserted page
1563 gtk_assistant_prepend_page (GtkAssistant *assistant,
1566 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1567 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1569 return gtk_assistant_insert_page (assistant, page, 0);
1573 * gtk_assistant_append_page:
1574 * @assistant: a #GtkAssistant
1575 * @page: a #GtkWidget
1577 * Appends a page to the @assistant.
1579 * Return value: the index (starting at 0) of the inserted page
1584 gtk_assistant_append_page (GtkAssistant *assistant,
1587 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1588 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1590 return gtk_assistant_insert_page (assistant, page, -1);
1594 * gtk_assistant_insert_page:
1595 * @assistant: a #GtkAssistant
1596 * @page: a #GtkWidget
1597 * @position: the index (starting at 0) at which to insert the page,
1598 * or -1 to append the page to the @assistant
1600 * Inserts a page in the @assistant at a given position.
1602 * Return value: the index (starting from 0) of the inserted page
1607 gtk_assistant_insert_page (GtkAssistant *assistant,
1611 GtkAssistantPrivate *priv;
1612 GtkAssistantPage *page_info;
1614 GtkStyleContext *context;
1616 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1617 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1618 g_return_val_if_fail (gtk_widget_get_parent (page) == NULL, 0);
1619 g_return_val_if_fail (!gtk_widget_is_toplevel (page), 0);
1621 priv = assistant->priv;
1623 page_info = g_slice_new0 (GtkAssistantPage);
1624 page_info->page = page;
1625 page_info->regular_title = gtk_label_new (NULL);
1626 gtk_widget_set_no_show_all (page_info->regular_title, TRUE);
1627 page_info->current_title = gtk_label_new (NULL);
1628 gtk_widget_set_no_show_all (page_info->current_title, TRUE);
1630 /* Note: we need to use misc alignment here as long as GtkLabel
1631 * pays attention to it. GtkWiget::halign is ineffective, since
1632 * all the labels are getting the same size anyway, due to the
1635 gtk_misc_set_alignment (GTK_MISC (page_info->regular_title), 0, 0.5);
1636 gtk_widget_show (page_info->regular_title);
1638 gtk_misc_set_alignment (GTK_MISC (page_info->current_title), 0, 0.5);
1639 gtk_widget_hide (page_info->current_title);
1641 context = gtk_widget_get_style_context (page_info->current_title);
1642 gtk_style_context_add_class (context, GTK_STYLE_CLASS_HIGHLIGHT);
1644 gtk_size_group_add_widget (priv->title_size_group, page_info->regular_title);
1645 gtk_size_group_add_widget (priv->title_size_group, page_info->current_title);
1647 g_signal_connect (G_OBJECT (page), "notify::visible",
1648 G_CALLBACK (on_page_notify_visibility), assistant);
1650 n_pages = g_list_length (priv->pages);
1652 if (position < 0 || position > n_pages)
1655 priv->pages = g_list_insert (priv->pages, page_info, position);
1657 gtk_box_pack_start (GTK_BOX (priv->sidebar), page_info->regular_title, FALSE, FALSE, 0);
1658 gtk_box_pack_start (GTK_BOX (priv->sidebar), page_info->current_title, FALSE, FALSE, 0);
1659 gtk_box_reorder_child (GTK_BOX (priv->sidebar), page_info->regular_title, 2 * position);
1660 gtk_box_reorder_child (GTK_BOX (priv->sidebar), page_info->current_title, 2 * position + 1);
1662 gtk_notebook_insert_page (GTK_NOTEBOOK (priv->content), page, NULL, position);
1664 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1666 update_buttons_state (assistant);
1667 update_actions_size (assistant);
1674 * gtk_assistant_remove_page:
1675 * @assistant: a #GtkAssistant
1676 * @page_num: the index of a page in the @assistant,
1677 * or -1 to remove the last page
1679 * Removes the @page_num's page from @assistant.
1684 gtk_assistant_remove_page (GtkAssistant *assistant,
1689 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1691 page = gtk_assistant_get_nth_page (assistant, page_num);
1694 gtk_container_remove (GTK_CONTAINER (assistant), page);
1698 * gtk_assistant_set_forward_page_func:
1699 * @assistant: a #GtkAssistant
1700 * @page_func: (allow-none): the #GtkAssistantPageFunc, or %NULL
1701 * to use the default one
1702 * @data: user data for @page_func
1703 * @destroy: destroy notifier for @data
1705 * Sets the page forwarding function to be @page_func.
1707 * This function will be used to determine what will be
1708 * the next page when the user presses the forward button.
1709 * Setting @page_func to %NULL will make the assistant to
1710 * use the default forward function, which just goes to the
1711 * next visible page.
1716 gtk_assistant_set_forward_page_func (GtkAssistant *assistant,
1717 GtkAssistantPageFunc page_func,
1719 GDestroyNotify destroy)
1721 GtkAssistantPrivate *priv;
1723 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1725 priv = assistant->priv;
1727 if (priv->forward_data_destroy &&
1728 priv->forward_function_data)
1729 (*priv->forward_data_destroy) (priv->forward_function_data);
1733 priv->forward_function = page_func;
1734 priv->forward_function_data = data;
1735 priv->forward_data_destroy = destroy;
1739 priv->forward_function = default_forward_function;
1740 priv->forward_function_data = assistant;
1741 priv->forward_data_destroy = NULL;
1744 /* Page flow has possibly changed, so the
1745 * buttons state might need to change too
1747 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1748 update_buttons_state (assistant);
1752 * gtk_assistant_add_action_widget:
1753 * @assistant: a #GtkAssistant
1754 * @child: a #GtkWidget
1756 * Adds a widget to the action area of a #GtkAssistant.
1761 gtk_assistant_add_action_widget (GtkAssistant *assistant,
1764 GtkAssistantPrivate *priv;
1766 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1767 g_return_if_fail (GTK_IS_WIDGET (child));
1769 priv = assistant->priv;
1771 if (GTK_IS_BUTTON (child))
1773 gtk_size_group_add_widget (priv->button_size_group, child);
1774 priv->extra_buttons += 1;
1775 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1776 update_actions_size (assistant);
1779 gtk_box_pack_end (GTK_BOX (priv->action_area), child, FALSE, FALSE, 0);
1783 * gtk_assistant_remove_action_widget:
1784 * @assistant: a #GtkAssistant
1785 * @child: a #GtkWidget
1787 * Removes a widget from the action area of a #GtkAssistant.
1792 gtk_assistant_remove_action_widget (GtkAssistant *assistant,
1795 GtkAssistantPrivate *priv;
1797 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1798 g_return_if_fail (GTK_IS_WIDGET (child));
1800 priv = assistant->priv;
1802 if (GTK_IS_BUTTON (child))
1804 gtk_size_group_remove_widget (priv->button_size_group, child);
1805 priv->extra_buttons -= 1;
1806 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1807 update_actions_size (assistant);
1810 gtk_container_remove (GTK_CONTAINER (priv->action_area), child);
1814 * gtk_assistant_set_page_title:
1815 * @assistant: a #GtkAssistant
1816 * @page: a page of @assistant
1817 * @title: the new title for @page
1819 * Sets a title for @page.
1821 * The title is displayed in the header area of the assistant
1822 * when @page is the current page.
1827 gtk_assistant_set_page_title (GtkAssistant *assistant,
1831 GtkAssistantPage *page_info;
1834 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1835 g_return_if_fail (GTK_IS_WIDGET (page));
1837 child = find_page (assistant, page);
1839 g_return_if_fail (child != NULL);
1841 page_info = (GtkAssistantPage*) child->data;
1843 g_free (page_info->title);
1844 page_info->title = g_strdup (title);
1846 gtk_label_set_text ((GtkLabel*) page_info->regular_title, title);
1847 gtk_label_set_text ((GtkLabel*) page_info->current_title, title);
1849 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1850 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "title");
1854 * gtk_assistant_get_page_title:
1855 * @assistant: a #GtkAssistant
1856 * @page: a page of @assistant
1858 * Gets the title for @page.
1860 * Return value: the title for @page
1865 gtk_assistant_get_page_title (GtkAssistant *assistant,
1868 GtkAssistantPage *page_info;
1871 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1872 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1874 child = find_page (assistant, page);
1876 g_return_val_if_fail (child != NULL, NULL);
1878 page_info = (GtkAssistantPage*) child->data;
1880 return page_info->title;
1884 * gtk_assistant_set_page_type:
1885 * @assistant: a #GtkAssistant
1886 * @page: a page of @assistant
1887 * @type: the new type for @page
1889 * Sets the page type for @page.
1891 * The page type determines the page behavior in the @assistant.
1896 gtk_assistant_set_page_type (GtkAssistant *assistant,
1898 GtkAssistantPageType type)
1900 GtkAssistantPage *page_info;
1903 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1904 g_return_if_fail (GTK_IS_WIDGET (page));
1906 child = find_page (assistant, page);
1908 g_return_if_fail (child != NULL);
1910 page_info = (GtkAssistantPage*) child->data;
1912 if (type != page_info->type)
1914 page_info->type = type;
1916 /* backwards compatibility to the era before fixing bug 604289 */
1917 if (type == GTK_ASSISTANT_PAGE_SUMMARY && !page_info->complete_set)
1919 gtk_assistant_set_page_complete (assistant, page, TRUE);
1920 page_info->complete_set = FALSE;
1923 /* Always set buttons state, a change in a future page
1924 * might change current page buttons
1926 update_buttons_state (assistant);
1928 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "page-type");
1933 * gtk_assistant_get_page_type:
1934 * @assistant: a #GtkAssistant
1935 * @page: a page of @assistant
1937 * Gets the page type of @page.
1939 * Return value: the page type of @page
1943 GtkAssistantPageType
1944 gtk_assistant_get_page_type (GtkAssistant *assistant,
1947 GtkAssistantPage *page_info;
1950 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), GTK_ASSISTANT_PAGE_CONTENT);
1951 g_return_val_if_fail (GTK_IS_WIDGET (page), GTK_ASSISTANT_PAGE_CONTENT);
1953 child = find_page (assistant, page);
1955 g_return_val_if_fail (child != NULL, GTK_ASSISTANT_PAGE_CONTENT);
1957 page_info = (GtkAssistantPage*) child->data;
1959 return page_info->type;
1963 * gtk_assistant_set_page_header_image:
1964 * @assistant: a #GtkAssistant
1965 * @page: a page of @assistant
1966 * @pixbuf: (allow-none): the new header image @page
1968 * Sets a header image for @page.
1972 * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
1973 * add your header decoration to the page content instead.
1976 gtk_assistant_set_page_header_image (GtkAssistant *assistant,
1980 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1981 g_return_if_fail (GTK_IS_WIDGET (page));
1982 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1984 gtk_assistant_do_set_page_header_image (assistant, page, pixbuf);
1988 gtk_assistant_do_set_page_header_image (GtkAssistant *assistant,
1992 GtkAssistantPage *page_info;
1995 child = find_page (assistant, page);
1997 g_return_if_fail (child != NULL);
1999 page_info = (GtkAssistantPage*) child->data;
2001 if (pixbuf != page_info->header_image)
2003 if (page_info->header_image)
2005 g_object_unref (page_info->header_image);
2006 page_info->header_image = NULL;
2010 page_info->header_image = g_object_ref (pixbuf);
2012 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "header-image");
2017 * gtk_assistant_get_page_header_image:
2018 * @assistant: a #GtkAssistant
2019 * @page: a page of @assistant
2021 * Gets the header image for @page.
2023 * Return value: (transfer none): the header image for @page,
2024 * or %NULL if there's no header image for the page
2028 * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
2029 * add your header decoration to the page content instead.
2032 gtk_assistant_get_page_header_image (GtkAssistant *assistant,
2035 GtkAssistantPage *page_info;
2038 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2039 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2041 child = find_page (assistant, page);
2043 g_return_val_if_fail (child != NULL, NULL);
2045 page_info = (GtkAssistantPage*) child->data;
2047 return page_info->header_image;
2051 * gtk_assistant_set_page_side_image:
2052 * @assistant: a #GtkAssistant
2053 * @page: a page of @assistant
2054 * @pixbuf: (allow-none): the new side image @page
2056 * Sets a side image for @page.
2058 * This image used to be displayed in the side area of the assistant
2059 * when @page is the current page.
2063 * Deprecated: 3.2: Since GTK+ 3.2, sidebar images are not
2067 gtk_assistant_set_page_side_image (GtkAssistant *assistant,
2071 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2072 g_return_if_fail (GTK_IS_WIDGET (page));
2073 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2075 gtk_assistant_do_set_page_side_image (assistant, page, pixbuf);
2079 gtk_assistant_do_set_page_side_image (GtkAssistant *assistant,
2083 GtkAssistantPage *page_info;
2086 child = find_page (assistant, page);
2088 g_return_if_fail (child != NULL);
2090 page_info = (GtkAssistantPage*) child->data;
2092 if (pixbuf != page_info->sidebar_image)
2094 if (page_info->sidebar_image)
2096 g_object_unref (page_info->sidebar_image);
2097 page_info->sidebar_image = NULL;
2101 page_info->sidebar_image = g_object_ref (pixbuf);
2103 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "sidebar-image");
2108 * gtk_assistant_get_page_side_image:
2109 * @assistant: a #GtkAssistant
2110 * @page: a page of @assistant
2112 * Gets the side image for @page.
2114 * Return value: (transfer none): the side image for @page,
2115 * or %NULL if there's no side image for the page
2119 * Deprecated: 3.2: Since GTK+ 3.2, sidebar images are not
2123 gtk_assistant_get_page_side_image (GtkAssistant *assistant,
2126 GtkAssistantPage *page_info;
2129 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2130 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2132 child = find_page (assistant, page);
2134 g_return_val_if_fail (child != NULL, NULL);
2136 page_info = (GtkAssistantPage*) child->data;
2138 return page_info->sidebar_image;
2142 * gtk_assistant_set_page_complete:
2143 * @assistant: a #GtkAssistant
2144 * @page: a page of @assistant
2145 * @complete: the completeness status of the page
2147 * Sets whether @page contents are complete.
2149 * This will make @assistant update the buttons state
2150 * to be able to continue the task.
2155 gtk_assistant_set_page_complete (GtkAssistant *assistant,
2159 GtkAssistantPage *page_info;
2162 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2163 g_return_if_fail (GTK_IS_WIDGET (page));
2165 child = find_page (assistant, page);
2167 g_return_if_fail (child != NULL);
2169 page_info = (GtkAssistantPage*) child->data;
2171 if (complete != page_info->complete)
2173 page_info->complete = complete;
2174 page_info->complete_set = TRUE;
2176 /* Always set buttons state, a change in a future page
2177 * might change current page buttons
2179 update_buttons_state (assistant);
2181 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "complete");
2186 * gtk_assistant_get_page_complete:
2187 * @assistant: a #GtkAssistant
2188 * @page: a page of @assistant
2190 * Gets whether @page is complete.
2192 * Return value: %TRUE if @page is complete.
2197 gtk_assistant_get_page_complete (GtkAssistant *assistant,
2200 GtkAssistantPage *page_info;
2203 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), FALSE);
2204 g_return_val_if_fail (GTK_IS_WIDGET (page), FALSE);
2206 child = find_page (assistant, page);
2208 g_return_val_if_fail (child != NULL, FALSE);
2210 page_info = (GtkAssistantPage*) child->data;
2212 return page_info->complete;
2216 * gtk_assistant_update_buttons_state:
2217 * @assistant: a #GtkAssistant
2219 * Forces @assistant to recompute the buttons state.
2221 * GTK+ automatically takes care of this in most situations,
2222 * e.g. when the user goes to a different page, or when the
2223 * visibility or completeness of a page changes.
2225 * One situation where it can be necessary to call this
2226 * function is when changing a value on the current page
2227 * affects the future page flow of the assistant.
2232 gtk_assistant_update_buttons_state (GtkAssistant *assistant)
2234 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2236 update_buttons_state (assistant);
2240 * gtk_assistant_commit:
2241 * @assistant: a #GtkAssistant
2243 * Erases the visited page history so the back button is not
2244 * shown on the current page, and removes the cancel button
2245 * from subsequent pages.
2247 * Use this when the information provided up to the current
2248 * page is hereafter deemed permanent and cannot be modified
2249 * or undone. For example, showing a progress page to track
2250 * a long-running, unreversible operation after the user has
2251 * clicked apply on a confirmation page.
2256 gtk_assistant_commit (GtkAssistant *assistant)
2258 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2260 g_slist_free (assistant->priv->visited_pages);
2261 assistant->priv->visited_pages = NULL;
2263 assistant->priv->committed = TRUE;
2265 update_buttons_state (assistant);
2268 /* accessible implementation */
2270 /* dummy typedefs */
2271 typedef GtkWindowAccessible GtkAssistantAccessible;
2272 typedef GtkWindowAccessibleClass GtkAssistantAccessibleClass;
2274 G_DEFINE_TYPE (GtkAssistantAccessible, _gtk_assistant_accessible, GTK_TYPE_WINDOW_ACCESSIBLE);
2277 gtk_assistant_accessible_get_n_children (AtkObject *accessible)
2281 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2285 return g_list_length (GTK_ASSISTANT (widget)->priv->pages) + 1;
2289 gtk_assistant_accessible_ref_child (AtkObject *accessible,
2292 GtkAssistant *assistant;
2293 GtkAssistantPrivate *priv;
2294 GtkWidget *widget, *child;
2299 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2303 assistant = GTK_ASSISTANT (widget);
2304 priv = assistant->priv;
2305 n_pages = g_list_length (priv->pages);
2309 else if (index < n_pages)
2311 GtkAssistantPage *page = g_list_nth_data (priv->pages, index);
2314 title = gtk_assistant_get_page_title (assistant, child);
2316 else if (index == n_pages)
2318 child = priv->action_area;
2324 obj = gtk_widget_get_accessible (child);
2327 atk_object_set_name (obj, title);
2329 return g_object_ref (obj);
2333 _gtk_assistant_accessible_class_init (GtkAssistantAccessibleClass *klass)
2335 AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
2337 atk_class->get_n_children = gtk_assistant_accessible_get_n_children;
2338 atk_class->ref_child = gtk_assistant_accessible_ref_child;
2342 _gtk_assistant_accessible_init (GtkAssistantAccessible *self)
2346 /* buildable implementation */
2348 static GtkBuildableIface *parent_buildable_iface;
2351 gtk_assistant_buildable_interface_init (GtkBuildableIface *iface)
2353 parent_buildable_iface = g_type_interface_peek_parent (iface);
2354 iface->get_internal_child = gtk_assistant_buildable_get_internal_child;
2355 iface->custom_tag_start = gtk_assistant_buildable_custom_tag_start;
2356 iface->custom_finished = gtk_assistant_buildable_custom_finished;
2360 gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
2361 GtkBuilder *builder,
2362 const gchar *childname)
2364 if (strcmp (childname, "action_area") == 0)
2365 return G_OBJECT (GTK_ASSISTANT (buildable)->priv->action_area);
2367 return parent_buildable_iface->get_internal_child (buildable,
2373 gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
2374 GtkBuilder *builder,
2376 const gchar *tagname,
2377 GMarkupParser *parser,
2380 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
2381 tagname, parser, data);
2385 gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
2386 GtkBuilder *builder,
2388 const gchar *tagname,
2391 parent_buildable_iface->custom_finished (buildable, builder, child,
2392 tagname, user_data);