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, see <http://www.gnu.org/licenses/>.
25 * SECTION:gtkassistant
26 * @Short_description: A widget used to guide users through multi-step operations
27 * @Title: GtkAssistant
29 * A #GtkAssistant is a widget used to represent a generally complex
30 * operation splitted in several steps, guiding the user through its pages
31 * and controlling the page flow to collect the necessary data.
33 * The design of GtkAssistant is that it controls what buttons to show and
34 * to make sensitive, based on what it knows about the page sequence and
35 * the <link linkend="GtkAssistantPageType">type</link> of each page, in
36 * addition to state information like the page
37 * <link linkend="gtk-assistant-set-page-complete">completion</link> and
38 * <link linkend="gtk-assistant-commit">committed</link> status.
40 * If you have a case that doesn't quite fit in #GtkAssistants way of
41 * handling buttons, you can use the #GTK_ASSISTANT_PAGE_CUSTOM page type
42 * and handle buttons yourself.
44 * <refsect2 id="GtkAssistant-BUILDER-UI">
45 * <title>GtkAssistant as GtkBuildable</title>
47 * The GtkAssistant implementation of the GtkBuildable interface exposes the
48 * @action_area as internal children with the name "action_area".
50 * To add pages to an assistant in GtkBuilder, simply add it as a
51 * <child> to the GtkAssistant object, and set its child properties
61 #include "gtkassistant.h"
63 #include "gtkbutton.h"
66 #include "gtknotebook.h"
69 #include "gtksizegroup.h"
70 #include "gtksizerequest.h"
72 #include "gtktypebuiltins.h"
74 #include "gtkprivate.h"
75 #include "gtkbuildable.h"
76 #include "a11y/gtkwindowaccessible.h"
79 #define HEADER_SPACING 12
80 #define ACTION_AREA_SPACING 12
82 typedef struct _GtkAssistantPage GtkAssistantPage;
84 struct _GtkAssistantPage
86 GtkAssistantPageType type;
88 guint complete_set : 1;
93 GtkWidget *regular_title;
94 GtkWidget *current_title;
95 GdkPixbuf *header_image;
96 GdkPixbuf *sidebar_image;
99 struct _GtkAssistantPrivate
110 GtkWidget *action_area;
113 GSList *visited_pages;
114 GtkAssistantPage *current_page;
116 GtkSizeGroup *button_size_group;
117 GtkSizeGroup *title_size_group;
119 GtkAssistantPageFunc forward_function;
120 gpointer forward_function_data;
121 GDestroyNotify forward_data_destroy;
128 static void gtk_assistant_class_init (GtkAssistantClass *class);
129 static void gtk_assistant_init (GtkAssistant *assistant);
130 static void gtk_assistant_destroy (GtkWidget *widget);
131 static void gtk_assistant_map (GtkWidget *widget);
132 static void gtk_assistant_unmap (GtkWidget *widget);
133 static gboolean gtk_assistant_delete_event (GtkWidget *widget,
135 static void gtk_assistant_add (GtkContainer *container,
137 static void gtk_assistant_remove (GtkContainer *container,
139 static void gtk_assistant_set_child_property (GtkContainer *container,
144 static void gtk_assistant_get_child_property (GtkContainer *container,
150 static void gtk_assistant_buildable_interface_init (GtkBuildableIface *iface);
151 static GObject *gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
153 const gchar *childname);
154 static gboolean gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
157 const gchar *tagname,
158 GMarkupParser *parser,
160 static void gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
163 const gchar *tagname,
166 static GList* find_page (GtkAssistant *assistant,
168 static void gtk_assistant_do_set_page_header_image (GtkAssistant *assistant,
171 static void gtk_assistant_do_set_page_side_image (GtkAssistant *assistant,
175 GType _gtk_assistant_accessible_get_type (void);
180 CHILD_PROP_PAGE_TYPE,
181 CHILD_PROP_PAGE_TITLE,
182 CHILD_PROP_PAGE_HEADER_IMAGE,
183 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
184 CHILD_PROP_PAGE_COMPLETE
196 static guint signals [LAST_SIGNAL] = { 0 };
199 G_DEFINE_TYPE_WITH_CODE (GtkAssistant, gtk_assistant, GTK_TYPE_WINDOW,
200 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
201 gtk_assistant_buildable_interface_init))
205 gtk_assistant_class_init (GtkAssistantClass *class)
207 GObjectClass *gobject_class;
208 GtkWidgetClass *widget_class;
209 GtkContainerClass *container_class;
211 gobject_class = (GObjectClass *) class;
212 widget_class = (GtkWidgetClass *) class;
213 container_class = (GtkContainerClass *) class;
215 widget_class->destroy = gtk_assistant_destroy;
216 widget_class->map = gtk_assistant_map;
217 widget_class->unmap = gtk_assistant_unmap;
218 widget_class->delete_event = gtk_assistant_delete_event;
220 gtk_widget_class_set_accessible_type (widget_class, _gtk_assistant_accessible_get_type ());
222 container_class->add = gtk_assistant_add;
223 container_class->remove = gtk_assistant_remove;
224 container_class->set_child_property = gtk_assistant_set_child_property;
225 container_class->get_child_property = gtk_assistant_get_child_property;
228 * GtkAssistant::cancel:
229 * @assistant: the #GtkAssistant
231 * The ::cancel signal is emitted when then the cancel button is clicked.
236 g_signal_new (I_("cancel"),
237 G_TYPE_FROM_CLASS (gobject_class),
239 G_STRUCT_OFFSET (GtkAssistantClass, cancel),
241 g_cclosure_marshal_VOID__VOID,
245 * GtkAssistant::prepare:
246 * @assistant: the #GtkAssistant
247 * @page: the current page
249 * The ::prepare signal is emitted when a new page is set as the
250 * assistant's current page, before making the new page visible.
252 * A handler for this signal can do any preparations which are
253 * necessary before showing @page.
258 g_signal_new (I_("prepare"),
259 G_TYPE_FROM_CLASS (gobject_class),
261 G_STRUCT_OFFSET (GtkAssistantClass, prepare),
263 g_cclosure_marshal_VOID__OBJECT,
264 G_TYPE_NONE, 1, GTK_TYPE_WIDGET);
267 * GtkAssistant::apply:
268 * @assistant: the #GtkAssistant
270 * The ::apply signal is emitted when the apply button is clicked.
272 * The default behavior of the #GtkAssistant is to switch to the page
273 * after the current page, unless the current page is the last one.
275 * A handler for the ::apply signal should carry out the actions for
276 * which the wizard has collected data. If the action takes a long time
277 * to complete, you might consider putting a page of type
278 * %GTK_ASSISTANT_PAGE_PROGRESS after the confirmation page and handle
279 * this operation within the #GtkAssistant::prepare signal of the progress
285 g_signal_new (I_("apply"),
286 G_TYPE_FROM_CLASS (gobject_class),
288 G_STRUCT_OFFSET (GtkAssistantClass, apply),
290 g_cclosure_marshal_VOID__VOID,
294 * GtkAssistant::close:
295 * @assistant: the #GtkAssistant
297 * The ::close signal is emitted either when the close button of
298 * a summary page is clicked, or when the apply button in the last
299 * page in the flow (of type %GTK_ASSISTANT_PAGE_CONFIRM) is clicked.
304 g_signal_new (I_("close"),
305 G_TYPE_FROM_CLASS (gobject_class),
307 G_STRUCT_OFFSET (GtkAssistantClass, close),
309 g_cclosure_marshal_VOID__VOID,
312 gtk_widget_class_install_style_property (widget_class,
313 g_param_spec_int ("header-padding",
314 P_("Header Padding"),
315 P_("Number of pixels around the header."),
319 GTK_PARAM_READABLE));
320 gtk_widget_class_install_style_property (widget_class,
321 g_param_spec_int ("content-padding",
322 P_("Content Padding"),
323 P_("Number of pixels around the content pages."),
327 GTK_PARAM_READABLE));
330 * GtkAssistant:page-type:
332 * The type of the assistant page.
336 gtk_container_class_install_child_property (container_class,
337 CHILD_PROP_PAGE_TYPE,
338 g_param_spec_enum ("page-type",
340 P_("The type of the assistant page"),
341 GTK_TYPE_ASSISTANT_PAGE_TYPE,
342 GTK_ASSISTANT_PAGE_CONTENT,
343 GTK_PARAM_READWRITE));
346 * GtkAssistant:title:
348 * The title of the page.
352 gtk_container_class_install_child_property (container_class,
353 CHILD_PROP_PAGE_TITLE,
354 g_param_spec_string ("title",
356 P_("The title of the assistant page"),
358 GTK_PARAM_READWRITE));
361 * GtkAssistant:header-image:
363 * This image used to be displayed in the page header.
367 * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
368 * add your header decoration to the page content instead.
370 gtk_container_class_install_child_property (container_class,
371 CHILD_PROP_PAGE_HEADER_IMAGE,
372 g_param_spec_object ("header-image",
374 P_("Header image for the assistant page"),
376 GTK_PARAM_READWRITE));
379 * GtkAssistant:sidebar-image:
381 * This image used to be displayed in the 'sidebar'.
385 * Deprecated: 3.2: Since GTK+ 3.2, the sidebar image is no longer shown.
387 gtk_container_class_install_child_property (container_class,
388 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
389 g_param_spec_object ("sidebar-image",
391 P_("Sidebar image for the assistant page"),
393 GTK_PARAM_READWRITE));
396 * GtkAssistant:complete:
398 * Setting the "complete" child property to %TRUE marks a page as
399 * complete (i.e.: all the required fields are filled out). GTK+ uses
400 * this information to control the sensitivity of the navigation buttons.
404 gtk_container_class_install_child_property (container_class,
405 CHILD_PROP_PAGE_COMPLETE,
406 g_param_spec_boolean ("complete",
408 P_("Whether all required fields on the page have been filled out"),
412 g_type_class_add_private (gobject_class, sizeof (GtkAssistantPrivate));
416 default_forward_function (gint current_page, gpointer data)
418 GtkAssistant *assistant;
419 GtkAssistantPrivate *priv;
420 GtkAssistantPage *page_info;
423 assistant = GTK_ASSISTANT (data);
424 priv = assistant->priv;
426 page_node = g_list_nth (priv->pages, ++current_page);
431 page_info = (GtkAssistantPage *) page_node->data;
433 while (page_node && !gtk_widget_get_visible (page_info->page))
435 page_node = page_node->next;
439 page_info = (GtkAssistantPage *) page_node->data;
446 last_button_visible (GtkAssistant *assistant, GtkAssistantPage *page)
448 GtkAssistantPrivate *priv = assistant->priv;
449 GtkAssistantPage *page_info;
450 gint count, page_num, n_pages;
455 if (page->type != GTK_ASSISTANT_PAGE_CONTENT)
459 page_num = g_list_index (priv->pages, page);
460 n_pages = g_list_length (priv->pages);
463 while (page_num >= 0 && page_num < n_pages &&
464 page_info->type == GTK_ASSISTANT_PAGE_CONTENT &&
465 (count == 0 || page_info->complete) &&
468 page_num = (priv->forward_function) (page_num, priv->forward_function_data);
469 page_info = g_list_nth_data (priv->pages, page_num);
474 /* Make the last button visible if we can skip multiple
475 * pages and end on a confirmation or summary page
477 if (count > 1 && page_info &&
478 (page_info->type == GTK_ASSISTANT_PAGE_CONFIRM ||
479 page_info->type == GTK_ASSISTANT_PAGE_SUMMARY))
486 update_actions_size (GtkAssistant *assistant)
488 GtkAssistantPrivate *priv = assistant->priv;
490 GtkAssistantPage *page;
491 gint buttons, page_buttons;
493 if (!priv->current_page)
496 /* Some heuristics to find out how many buttons we should
497 * reserve space for. It is possible to trick this code
498 * with page forward functions and invisible pages, etc.
501 for (l = priv->pages; l; l = l->next)
505 if (!gtk_widget_get_visible (page->page))
508 page_buttons = 2; /* cancel, forward/apply/close */
509 if (l != priv->pages)
510 page_buttons += 1; /* back */
511 if (last_button_visible (assistant, page))
512 page_buttons += 1; /* last */
514 buttons = MAX (buttons, page_buttons);
517 buttons += priv->extra_buttons;
519 gtk_widget_set_size_request (priv->action_area,
520 buttons * gtk_widget_get_allocated_width (priv->cancel) + (buttons - 1) * 6,
525 compute_last_button_state (GtkAssistant *assistant)
527 GtkAssistantPrivate *priv = assistant->priv;
529 gtk_widget_set_sensitive (priv->last, priv->current_page->complete);
530 if (last_button_visible (assistant, priv->current_page))
531 gtk_widget_show (priv->last);
533 gtk_widget_hide (priv->last);
537 compute_progress_state (GtkAssistant *assistant)
539 GtkAssistantPrivate *priv = assistant->priv;
540 gint page_num, n_pages;
542 n_pages = gtk_assistant_get_n_pages (assistant);
543 page_num = gtk_assistant_get_current_page (assistant);
545 page_num = (priv->forward_function) (page_num, priv->forward_function_data);
547 if (page_num >= 0 && page_num < n_pages)
548 gtk_widget_show (priv->forward);
550 gtk_widget_hide (priv->forward);
554 update_buttons_state (GtkAssistant *assistant)
556 GtkAssistantPrivate *priv = assistant->priv;
558 if (!priv->current_page)
561 switch (priv->current_page->type)
563 case GTK_ASSISTANT_PAGE_INTRO:
564 gtk_widget_set_sensitive (priv->cancel, TRUE);
565 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
566 gtk_widget_grab_default (priv->forward);
567 gtk_widget_show (priv->forward);
568 gtk_widget_hide (priv->back);
569 gtk_widget_hide (priv->apply);
570 gtk_widget_hide (priv->close);
571 compute_last_button_state (assistant);
573 case GTK_ASSISTANT_PAGE_CONFIRM:
574 gtk_widget_set_sensitive (priv->cancel, TRUE);
575 gtk_widget_set_sensitive (priv->back, TRUE);
576 gtk_widget_set_sensitive (priv->apply, priv->current_page->complete);
577 gtk_widget_grab_default (priv->apply);
578 gtk_widget_show (priv->back);
579 gtk_widget_show (priv->apply);
580 gtk_widget_hide (priv->forward);
581 gtk_widget_hide (priv->close);
582 gtk_widget_hide (priv->last);
584 case GTK_ASSISTANT_PAGE_CONTENT:
585 gtk_widget_set_sensitive (priv->cancel, TRUE);
586 gtk_widget_set_sensitive (priv->back, TRUE);
587 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
588 gtk_widget_grab_default (priv->forward);
589 gtk_widget_show (priv->back);
590 gtk_widget_show (priv->forward);
591 gtk_widget_hide (priv->apply);
592 gtk_widget_hide (priv->close);
593 compute_last_button_state (assistant);
595 case GTK_ASSISTANT_PAGE_SUMMARY:
596 gtk_widget_set_sensitive (priv->close, priv->current_page->complete);
597 gtk_widget_grab_default (priv->close);
598 gtk_widget_show (priv->close);
599 gtk_widget_hide (priv->back);
600 gtk_widget_hide (priv->forward);
601 gtk_widget_hide (priv->apply);
602 gtk_widget_hide (priv->last);
604 case GTK_ASSISTANT_PAGE_PROGRESS:
605 gtk_widget_set_sensitive (priv->cancel, priv->current_page->complete);
606 gtk_widget_set_sensitive (priv->back, priv->current_page->complete);
607 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
608 gtk_widget_grab_default (priv->forward);
609 gtk_widget_show (priv->back);
610 gtk_widget_hide (priv->apply);
611 gtk_widget_hide (priv->close);
612 gtk_widget_hide (priv->last);
613 compute_progress_state (assistant);
615 case GTK_ASSISTANT_PAGE_CUSTOM:
616 gtk_widget_hide (priv->cancel);
617 gtk_widget_hide (priv->back);
618 gtk_widget_hide (priv->forward);
619 gtk_widget_hide (priv->apply);
620 gtk_widget_hide (priv->last);
621 gtk_widget_hide (priv->close);
624 g_assert_not_reached ();
628 gtk_widget_hide (priv->cancel);
629 else if (priv->current_page->type == GTK_ASSISTANT_PAGE_SUMMARY ||
630 priv->current_page->type == GTK_ASSISTANT_PAGE_CUSTOM)
631 gtk_widget_hide (priv->cancel);
633 gtk_widget_show (priv->cancel);
635 /* this is quite general, we don't want to
636 * go back if it's the first page
638 if (!priv->visited_pages)
639 gtk_widget_hide (priv->back);
643 update_page_title_state (GtkAssistant *assistant, GList *list)
645 GtkAssistantPage *page, *other;
646 GtkAssistantPrivate *priv = assistant->priv;
652 if (page->title == NULL || page->title[0] == 0)
655 visible = gtk_widget_get_visible (page->page);
657 if (page == priv->current_page)
659 gtk_widget_set_visible (page->regular_title, FALSE);
660 gtk_widget_set_visible (page->current_title, visible);
664 /* If multiple consecutive pages have the same title,
665 * we only show it once, since it would otherwise look
666 * silly. We have to be a little careful, since we
667 * _always_ show the title of the current page.
671 other = list->prev->data;
672 if (g_strcmp0 (page->title, other->title) == 0)
675 for (l = list->next; l; l = l->next)
678 if (g_strcmp0 (page->title, other->title) != 0)
681 if (other == priv->current_page)
688 gtk_widget_set_visible (page->regular_title, visible);
689 gtk_widget_set_visible (page->current_title, FALSE);
696 update_title_state (GtkAssistant *assistant)
698 GtkAssistantPrivate *priv = assistant->priv;
700 gboolean show_titles;
703 for (l = priv->pages; l != NULL; l = l->next)
705 if (update_page_title_state (assistant, l))
709 gtk_widget_set_visible (priv->sidebar, show_titles);
713 set_current_page (GtkAssistant *assistant,
716 GtkAssistantPrivate *priv = assistant->priv;
718 priv->current_page = (GtkAssistantPage *)g_list_nth_data (priv->pages, page_num);
720 g_signal_emit (assistant, signals [PREPARE], 0, priv->current_page->page);
722 update_title_state (assistant);
724 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->content), page_num);
726 /* update buttons state, flow may have changed */
727 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
728 update_buttons_state (assistant);
730 if (!gtk_widget_child_focus (priv->current_page->page, GTK_DIR_TAB_FORWARD))
732 GtkWidget *button[6];
735 /* find the best button to focus */
736 button[0] = priv->apply;
737 button[1] = priv->close;
738 button[2] = priv->forward;
739 button[3] = priv->back;
740 button[4] = priv->cancel;
741 button[5] = priv->last;
742 for (i = 0; i < 6; i++)
744 if (gtk_widget_get_visible (button[i]) &&
745 gtk_widget_get_sensitive (button[i]))
747 gtk_widget_grab_focus (button[i]);
753 gtk_widget_queue_resize (GTK_WIDGET (assistant));
757 compute_next_step (GtkAssistant *assistant)
759 GtkAssistantPrivate *priv = assistant->priv;
760 GtkAssistantPage *page_info;
761 gint current_page, n_pages, next_page;
763 current_page = gtk_assistant_get_current_page (assistant);
764 page_info = priv->current_page;
765 n_pages = gtk_assistant_get_n_pages (assistant);
767 next_page = (priv->forward_function) (current_page,
768 priv->forward_function_data);
770 if (next_page >= 0 && next_page < n_pages)
772 priv->visited_pages = g_slist_prepend (priv->visited_pages, page_info);
773 set_current_page (assistant, next_page);
782 on_assistant_close (GtkWidget *widget,
783 GtkAssistant *assistant)
785 g_signal_emit (assistant, signals [CLOSE], 0, NULL);
789 on_assistant_apply (GtkWidget *widget,
790 GtkAssistant *assistant)
794 g_signal_emit (assistant, signals [APPLY], 0);
796 success = compute_next_step (assistant);
798 /* if the assistant hasn't switched to another page, just emit
799 * the CLOSE signal, it't the last page in the assistant flow
802 g_signal_emit (assistant, signals [CLOSE], 0);
806 on_assistant_forward (GtkWidget *widget,
807 GtkAssistant *assistant)
809 gtk_assistant_next_page (assistant);
813 on_assistant_back (GtkWidget *widget,
814 GtkAssistant *assistant)
816 gtk_assistant_previous_page (assistant);
820 on_assistant_cancel (GtkWidget *widget,
821 GtkAssistant *assistant)
823 g_signal_emit (assistant, signals [CANCEL], 0, NULL);
827 on_assistant_last (GtkWidget *widget,
828 GtkAssistant *assistant)
830 GtkAssistantPrivate *priv = assistant->priv;
832 while (priv->current_page->type == GTK_ASSISTANT_PAGE_CONTENT &&
833 priv->current_page->complete)
834 compute_next_step (assistant);
838 alternative_button_order (GtkAssistant *assistant)
840 GtkSettings *settings;
844 screen = gtk_widget_get_screen (GTK_WIDGET (assistant));
845 settings = gtk_settings_get_for_screen (screen);
847 g_object_get (settings,
848 "gtk-alternative-button-order", &result,
854 assistant_sidebar_draw_cb (GtkWidget *widget,
859 GtkStyleContext *context;
861 width = gtk_widget_get_allocated_width (widget);
862 height = gtk_widget_get_allocated_height (widget);
863 context = gtk_widget_get_style_context (widget);
865 gtk_render_background (context, cr, 0, 0, width, height);
871 on_page_notify_visibility (GtkWidget *widget,
875 GtkAssistant *assistant = GTK_ASSISTANT (data);
877 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
879 update_buttons_state (assistant);
880 update_title_state (assistant);
885 assistant_remove_page_cb (GtkNotebook *notebook,
887 GtkAssistant *assistant)
889 GtkAssistantPrivate *priv = assistant->priv;
890 GtkAssistantPage *page_info;
894 element = find_page (assistant, page);
898 page_info = element->data;
900 /* If this is the current page, we need to switch away. */
901 if (page_info == priv->current_page)
903 if (!compute_next_step (assistant))
905 /* The best we can do at this point is probably to pick
906 * the first visible page.
908 page_node = priv->pages;
911 !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
912 page_node = page_node->next;
914 if (page_node == element)
915 page_node = page_node->next;
918 priv->current_page = page_node->data;
920 priv->current_page = NULL;
924 g_signal_handlers_disconnect_by_func (page_info->page, on_page_notify_visibility, assistant);
926 gtk_size_group_remove_widget (priv->title_size_group, page_info->regular_title);
927 gtk_size_group_remove_widget (priv->title_size_group, page_info->current_title);
929 gtk_container_remove (GTK_CONTAINER (priv->sidebar), page_info->regular_title);
930 gtk_container_remove (GTK_CONTAINER (priv->sidebar), page_info->current_title);
932 priv->pages = g_list_remove_link (priv->pages, element);
933 priv->visited_pages = g_slist_remove_all (priv->visited_pages, page_info);
935 g_free (page_info->title);
937 g_slice_free (GtkAssistantPage, page_info);
938 g_list_free_1 (element);
940 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
942 update_buttons_state (assistant);
943 update_actions_size (assistant);
948 gtk_assistant_init (GtkAssistant *assistant)
950 GtkAssistantPrivate *priv;
951 GtkStyleContext *context;
953 GtkWidget *content_box;
954 GtkWidget *sidebar_frame;
956 assistant->priv = G_TYPE_INSTANCE_GET_PRIVATE (assistant,
958 GtkAssistantPrivate);
959 priv = assistant->priv;
961 /* use border on inner panes instead */
962 gtk_container_set_border_width (GTK_CONTAINER (assistant), 0);
964 gtk_widget_push_composite_child ();
966 main_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
967 priv->sidebar = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
969 /* use a frame for the sidebar, and manually render a background
970 * in it. GtkFrame also gives us padding support for free.
972 sidebar_frame = gtk_frame_new (NULL);
973 context = gtk_widget_get_style_context (sidebar_frame);
974 gtk_style_context_add_class (context, GTK_STYLE_CLASS_SIDEBAR);
976 g_signal_connect (sidebar_frame, "draw",
977 G_CALLBACK (assistant_sidebar_draw_cb), assistant);
979 content_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
980 gtk_container_set_border_width (GTK_CONTAINER (content_box), 12);
981 priv->content = gtk_notebook_new ();
982 gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->content), FALSE);
983 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->content), FALSE);
984 priv->action_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
986 g_signal_connect (priv->content, "remove",
987 G_CALLBACK (assistant_remove_page_cb), assistant);
989 gtk_container_add (GTK_CONTAINER (sidebar_frame), priv->sidebar);
990 gtk_box_pack_start (GTK_BOX (main_box), sidebar_frame, FALSE, FALSE, 0);
991 gtk_box_pack_start (GTK_BOX (main_box), content_box, TRUE, TRUE, 0);
992 gtk_box_pack_start (GTK_BOX (content_box), priv->content, TRUE, TRUE, 0);
993 gtk_box_pack_start (GTK_BOX (content_box), priv->action_area, FALSE, TRUE, 0);
994 gtk_widget_set_halign (priv->action_area, GTK_ALIGN_END);
996 gtk_widget_show_all (main_box);
998 gtk_widget_set_parent (main_box, GTK_WIDGET (assistant));
999 _gtk_bin_set_child (GTK_BIN (assistant), main_box);
1001 priv->close = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
1002 priv->apply = gtk_button_new_from_stock (GTK_STOCK_APPLY);
1003 priv->forward = gtk_button_new_with_mnemonic (_("C_ontinue"));
1004 gtk_button_set_image (GTK_BUTTON (priv->forward),
1005 gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD, GTK_ICON_SIZE_BUTTON));
1006 priv->back = gtk_button_new_with_mnemonic (_("Go _Back"));
1007 gtk_button_set_image (GTK_BUTTON (priv->forward),
1008 gtk_image_new_from_stock (GTK_STOCK_GO_BACK, GTK_ICON_SIZE_BUTTON));
1009 priv->cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
1010 priv->last = gtk_button_new_with_mnemonic (_("_Finish"));
1011 gtk_button_set_image (GTK_BUTTON (priv->forward),
1012 gtk_image_new_from_stock (GTK_STOCK_GOTO_LAST, GTK_ICON_SIZE_BUTTON));
1013 gtk_widget_set_can_default (priv->close, TRUE);
1014 gtk_widget_set_can_default (priv->apply, TRUE);
1015 gtk_widget_set_can_default (priv->forward, TRUE);
1017 priv->button_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
1018 gtk_size_group_add_widget (priv->button_size_group, priv->close);
1019 gtk_size_group_add_widget (priv->button_size_group, priv->apply);
1020 gtk_size_group_add_widget (priv->button_size_group, priv->forward);
1021 gtk_size_group_add_widget (priv->button_size_group, priv->back);
1022 gtk_size_group_add_widget (priv->button_size_group, priv->cancel);
1023 gtk_size_group_add_widget (priv->button_size_group, priv->last);
1025 gtk_widget_set_no_show_all (priv->close, TRUE);
1026 gtk_widget_set_no_show_all (priv->apply, TRUE);
1027 gtk_widget_set_no_show_all (priv->forward, TRUE);
1028 gtk_widget_set_no_show_all (priv->back, TRUE);
1029 gtk_widget_set_no_show_all (priv->cancel, TRUE);
1030 gtk_widget_set_no_show_all (priv->last, TRUE);
1032 if (!alternative_button_order (assistant))
1034 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
1035 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
1036 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
1037 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
1038 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
1039 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->close, FALSE, FALSE, 0);
1043 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->close, FALSE, FALSE, 0);
1044 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
1045 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
1046 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
1047 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
1048 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
1051 gtk_widget_show (priv->forward);
1052 gtk_widget_show (priv->back);
1053 gtk_widget_show (priv->cancel);
1054 gtk_widget_show (priv->action_area);
1056 gtk_widget_pop_composite_child ();
1058 priv->title_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
1061 priv->current_page = NULL;
1062 priv->visited_pages = NULL;
1064 priv->forward_function = default_forward_function;
1065 priv->forward_function_data = assistant;
1066 priv->forward_data_destroy = NULL;
1068 g_signal_connect (G_OBJECT (priv->close), "clicked",
1069 G_CALLBACK (on_assistant_close), assistant);
1070 g_signal_connect (G_OBJECT (priv->apply), "clicked",
1071 G_CALLBACK (on_assistant_apply), assistant);
1072 g_signal_connect (G_OBJECT (priv->forward), "clicked",
1073 G_CALLBACK (on_assistant_forward), assistant);
1074 g_signal_connect (G_OBJECT (priv->back), "clicked",
1075 G_CALLBACK (on_assistant_back), assistant);
1076 g_signal_connect (G_OBJECT (priv->cancel), "clicked",
1077 G_CALLBACK (on_assistant_cancel), assistant);
1078 g_signal_connect (G_OBJECT (priv->last), "clicked",
1079 G_CALLBACK (on_assistant_last), assistant);
1083 gtk_assistant_set_child_property (GtkContainer *container,
1086 const GValue *value,
1089 switch (property_id)
1091 case CHILD_PROP_PAGE_TYPE:
1092 gtk_assistant_set_page_type (GTK_ASSISTANT (container), child,
1093 g_value_get_enum (value));
1095 case CHILD_PROP_PAGE_TITLE:
1096 gtk_assistant_set_page_title (GTK_ASSISTANT (container), child,
1097 g_value_get_string (value));
1099 case CHILD_PROP_PAGE_HEADER_IMAGE:
1100 gtk_assistant_do_set_page_header_image (GTK_ASSISTANT (container), child,
1101 g_value_get_object (value));
1103 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
1104 gtk_assistant_do_set_page_side_image (GTK_ASSISTANT (container), child,
1105 g_value_get_object (value));
1107 case CHILD_PROP_PAGE_COMPLETE:
1108 gtk_assistant_set_page_complete (GTK_ASSISTANT (container), child,
1109 g_value_get_boolean (value));
1112 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
1118 gtk_assistant_get_child_property (GtkContainer *container,
1124 GtkAssistant *assistant = GTK_ASSISTANT (container);
1126 switch (property_id)
1128 case CHILD_PROP_PAGE_TYPE:
1129 g_value_set_enum (value,
1130 gtk_assistant_get_page_type (assistant, child));
1132 case CHILD_PROP_PAGE_TITLE:
1133 g_value_set_string (value,
1134 gtk_assistant_get_page_title (assistant, child));
1136 case CHILD_PROP_PAGE_HEADER_IMAGE:
1137 g_value_set_object (value,
1138 ((GtkAssistantPage*) find_page (assistant, child))->header_image);
1140 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
1141 g_value_set_object (value,
1142 ((GtkAssistantPage*) find_page (assistant, child))->sidebar_image);
1144 case CHILD_PROP_PAGE_COMPLETE:
1145 g_value_set_boolean (value,
1146 gtk_assistant_get_page_complete (assistant, child));
1149 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
1155 gtk_assistant_destroy (GtkWidget *widget)
1157 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1158 GtkAssistantPrivate *priv = assistant->priv;
1160 /* We set current to NULL so that the remove code doesn't try
1161 * to do anything funny
1163 priv->current_page = NULL;
1167 GtkNotebook *notebook;
1170 /* Remove all pages from the content notebook. */
1171 notebook = (GtkNotebook *) priv->content;
1172 while ((page = gtk_notebook_get_nth_page (notebook, 0)) != NULL)
1173 gtk_container_remove ((GtkContainer *) notebook, page);
1175 /* Our GtkAssistantPage list should be empty now. */
1176 g_warn_if_fail (priv->pages == NULL);
1178 priv->content = NULL;
1182 priv->sidebar = NULL;
1184 if (priv->action_area)
1185 priv->action_area = NULL;
1187 if (priv->button_size_group)
1189 g_object_unref (priv->button_size_group);
1190 priv->button_size_group = NULL;
1193 if (priv->title_size_group)
1195 g_object_unref (priv->title_size_group);
1196 priv->title_size_group = NULL;
1199 if (priv->forward_function)
1201 if (priv->forward_function_data &&
1202 priv->forward_data_destroy)
1203 priv->forward_data_destroy (priv->forward_function_data);
1205 priv->forward_function = NULL;
1206 priv->forward_function_data = NULL;
1207 priv->forward_data_destroy = NULL;
1210 if (priv->visited_pages)
1212 g_slist_free (priv->visited_pages);
1213 priv->visited_pages = NULL;
1216 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->destroy (widget);
1220 find_page (GtkAssistant *assistant,
1223 GtkAssistantPrivate *priv = assistant->priv;
1224 GList *child = priv->pages;
1228 GtkAssistantPage *page_info = child->data;
1229 if (page_info->page == page)
1232 child = child->next;
1239 gtk_assistant_map (GtkWidget *widget)
1241 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1242 GtkAssistantPrivate *priv = assistant->priv;
1244 GtkAssistantPage *page;
1247 /* if there's no default page, pick the first one */
1250 if (!priv->current_page)
1252 page_node = priv->pages;
1254 while (page_node && !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
1256 page_node = page_node->next;
1261 page = page_node->data;
1264 if (page && gtk_widget_get_visible (page->page))
1265 set_current_page (assistant, page_num);
1267 update_buttons_state (assistant);
1268 update_actions_size (assistant);
1269 update_title_state (assistant);
1271 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->map (widget);
1275 gtk_assistant_unmap (GtkWidget *widget)
1277 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1278 GtkAssistantPrivate *priv = assistant->priv;
1280 g_slist_free (priv->visited_pages);
1281 priv->visited_pages = NULL;
1282 priv->current_page = NULL;
1284 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->unmap (widget);
1288 gtk_assistant_delete_event (GtkWidget *widget,
1291 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1292 GtkAssistantPrivate *priv = assistant->priv;
1294 /* Do not allow cancelling in the middle of a progress page */
1295 if (priv->current_page &&
1296 (priv->current_page->type != GTK_ASSISTANT_PAGE_PROGRESS ||
1297 priv->current_page->complete))
1298 g_signal_emit (widget, signals [CANCEL], 0, NULL);
1304 gtk_assistant_add (GtkContainer *container,
1307 gtk_assistant_append_page (GTK_ASSISTANT (container), page);
1311 gtk_assistant_remove (GtkContainer *container,
1314 GtkAssistant *assistant = (GtkAssistant*) container;
1316 /* Forward this removal to the content notebook */
1317 if (gtk_widget_get_parent (page) == assistant->priv->content)
1319 container = (GtkContainer *) assistant->priv->content;
1320 gtk_container_remove (container, page);
1325 * gtk_assistant_new:
1327 * Creates a new #GtkAssistant.
1329 * Return value: a newly created #GtkAssistant
1334 gtk_assistant_new (void)
1336 GtkWidget *assistant;
1338 assistant = g_object_new (GTK_TYPE_ASSISTANT, NULL);
1344 * gtk_assistant_get_current_page:
1345 * @assistant: a #GtkAssistant
1347 * Returns the page number of the current page.
1349 * Return value: The index (starting from 0) of the current
1350 * page in the @assistant, or -1 if the @assistant has no pages,
1351 * or no current page.
1356 gtk_assistant_get_current_page (GtkAssistant *assistant)
1358 GtkAssistantPrivate *priv;
1360 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), -1);
1362 priv = assistant->priv;
1364 if (!priv->pages || !priv->current_page)
1367 return g_list_index (priv->pages, priv->current_page);
1371 * gtk_assistant_set_current_page:
1372 * @assistant: a #GtkAssistant
1373 * @page_num: index of the page to switch to, starting from 0.
1374 * If negative, the last page will be used. If greater
1375 * than the number of pages in the @assistant, nothing
1378 * Switches the page to @page_num.
1380 * Note that this will only be necessary in custom buttons,
1381 * as the @assistant flow can be set with
1382 * gtk_assistant_set_forward_page_func().
1387 gtk_assistant_set_current_page (GtkAssistant *assistant,
1390 GtkAssistantPrivate *priv;
1391 GtkAssistantPage *page;
1393 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1395 priv = assistant->priv;
1398 page = (GtkAssistantPage *) g_list_nth_data (priv->pages, page_num);
1401 page = (GtkAssistantPage *) g_list_last (priv->pages)->data;
1402 page_num = g_list_length (priv->pages);
1405 g_return_if_fail (page != NULL);
1407 if (priv->current_page == page)
1410 /* only add the page to the visited list if the assistant is mapped,
1411 * if not, just use it as an initial page setting, for the cases where
1412 * the initial page is != to 0
1414 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1415 priv->visited_pages = g_slist_prepend (priv->visited_pages,
1416 priv->current_page);
1418 set_current_page (assistant, page_num);
1422 * gtk_assistant_next_page:
1423 * @assistant: a #GtkAssistant
1425 * Navigate to the next page.
1427 * It is a programming error to call this function when
1428 * there is no next page.
1430 * This function is for use when creating pages of the
1431 * #GTK_ASSISTANT_PAGE_CUSTOM type.
1436 gtk_assistant_next_page (GtkAssistant *assistant)
1438 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1440 if (!compute_next_step (assistant))
1441 g_critical ("Page flow is broken.\n"
1442 "You may want to end it with a page of type\n"
1443 "GTK_ASSISTANT_PAGE_CONFIRM or GTK_ASSISTANT_PAGE_SUMMARY");
1447 * gtk_assistant_previous_page:
1448 * @assistant: a #GtkAssistant
1450 * Navigate to the previous visited page.
1452 * It is a programming error to call this function when
1453 * no previous page is available.
1455 * This function is for use when creating pages of the
1456 * #GTK_ASSISTANT_PAGE_CUSTOM type.
1461 gtk_assistant_previous_page (GtkAssistant *assistant)
1463 GtkAssistantPrivate *priv;
1464 GtkAssistantPage *page_info;
1467 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1469 priv = assistant->priv;
1471 /* skip the progress pages when going back */
1474 page_node = priv->visited_pages;
1476 g_return_if_fail (page_node != NULL);
1478 priv->visited_pages = priv->visited_pages->next;
1479 page_info = (GtkAssistantPage *) page_node->data;
1480 g_slist_free_1 (page_node);
1482 while (page_info->type == GTK_ASSISTANT_PAGE_PROGRESS ||
1483 !gtk_widget_get_visible (page_info->page));
1485 set_current_page (assistant, g_list_index (priv->pages, page_info));
1489 * gtk_assistant_get_n_pages:
1490 * @assistant: a #GtkAssistant
1492 * Returns the number of pages in the @assistant
1494 * Return value: the number of pages in the @assistant
1499 gtk_assistant_get_n_pages (GtkAssistant *assistant)
1501 GtkAssistantPrivate *priv;
1503 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1505 priv = assistant->priv;
1507 return g_list_length (priv->pages);
1511 * gtk_assistant_get_nth_page:
1512 * @assistant: a #GtkAssistant
1513 * @page_num: the index of a page in the @assistant,
1514 * or -1 to get the last page
1516 * Returns the child widget contained in page number @page_num.
1518 * Return value: (transfer none): the child widget, or %NULL
1519 * if @page_num is out of bounds
1524 gtk_assistant_get_nth_page (GtkAssistant *assistant,
1527 GtkAssistantPrivate *priv;
1528 GtkAssistantPage *page;
1531 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1532 g_return_val_if_fail (page_num >= -1, NULL);
1534 priv = assistant->priv;
1537 elem = g_list_last (priv->pages);
1539 elem = g_list_nth (priv->pages, page_num);
1544 page = (GtkAssistantPage *) elem->data;
1550 * gtk_assistant_prepend_page:
1551 * @assistant: a #GtkAssistant
1552 * @page: a #GtkWidget
1554 * Prepends a page to the @assistant.
1556 * Return value: the index (starting at 0) of the inserted page
1561 gtk_assistant_prepend_page (GtkAssistant *assistant,
1564 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1565 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1567 return gtk_assistant_insert_page (assistant, page, 0);
1571 * gtk_assistant_append_page:
1572 * @assistant: a #GtkAssistant
1573 * @page: a #GtkWidget
1575 * Appends a page to the @assistant.
1577 * Return value: the index (starting at 0) of the inserted page
1582 gtk_assistant_append_page (GtkAssistant *assistant,
1585 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1586 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1588 return gtk_assistant_insert_page (assistant, page, -1);
1592 * gtk_assistant_insert_page:
1593 * @assistant: a #GtkAssistant
1594 * @page: a #GtkWidget
1595 * @position: the index (starting at 0) at which to insert the page,
1596 * or -1 to append the page to the @assistant
1598 * Inserts a page in the @assistant at a given position.
1600 * Return value: the index (starting from 0) of the inserted page
1605 gtk_assistant_insert_page (GtkAssistant *assistant,
1609 GtkAssistantPrivate *priv;
1610 GtkAssistantPage *page_info;
1612 GtkStyleContext *context;
1614 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1615 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1616 g_return_val_if_fail (gtk_widget_get_parent (page) == NULL, 0);
1617 g_return_val_if_fail (!gtk_widget_is_toplevel (page), 0);
1619 priv = assistant->priv;
1621 page_info = g_slice_new0 (GtkAssistantPage);
1622 page_info->page = page;
1623 page_info->regular_title = gtk_label_new (NULL);
1624 gtk_widget_set_no_show_all (page_info->regular_title, TRUE);
1625 page_info->current_title = gtk_label_new (NULL);
1626 gtk_widget_set_no_show_all (page_info->current_title, TRUE);
1628 /* Note: we need to use misc alignment here as long as GtkLabel
1629 * pays attention to it. GtkWiget::halign is ineffective, since
1630 * all the labels are getting the same size anyway, due to the
1633 gtk_misc_set_alignment (GTK_MISC (page_info->regular_title), 0, 0.5);
1634 gtk_widget_show (page_info->regular_title);
1636 gtk_misc_set_alignment (GTK_MISC (page_info->current_title), 0, 0.5);
1637 gtk_widget_hide (page_info->current_title);
1639 context = gtk_widget_get_style_context (page_info->current_title);
1640 gtk_style_context_add_class (context, GTK_STYLE_CLASS_HIGHLIGHT);
1642 gtk_size_group_add_widget (priv->title_size_group, page_info->regular_title);
1643 gtk_size_group_add_widget (priv->title_size_group, page_info->current_title);
1645 g_signal_connect (G_OBJECT (page), "notify::visible",
1646 G_CALLBACK (on_page_notify_visibility), assistant);
1648 n_pages = g_list_length (priv->pages);
1650 if (position < 0 || position > n_pages)
1653 priv->pages = g_list_insert (priv->pages, page_info, position);
1655 gtk_box_pack_start (GTK_BOX (priv->sidebar), page_info->regular_title, FALSE, FALSE, 0);
1656 gtk_box_pack_start (GTK_BOX (priv->sidebar), page_info->current_title, FALSE, FALSE, 0);
1657 gtk_box_reorder_child (GTK_BOX (priv->sidebar), page_info->regular_title, 2 * position);
1658 gtk_box_reorder_child (GTK_BOX (priv->sidebar), page_info->current_title, 2 * position + 1);
1660 gtk_notebook_insert_page (GTK_NOTEBOOK (priv->content), page, NULL, position);
1662 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1664 update_buttons_state (assistant);
1665 update_actions_size (assistant);
1672 * gtk_assistant_remove_page:
1673 * @assistant: a #GtkAssistant
1674 * @page_num: the index of a page in the @assistant,
1675 * or -1 to remove the last page
1677 * Removes the @page_num's page from @assistant.
1682 gtk_assistant_remove_page (GtkAssistant *assistant,
1687 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1689 page = gtk_assistant_get_nth_page (assistant, page_num);
1692 gtk_container_remove (GTK_CONTAINER (assistant), page);
1696 * gtk_assistant_set_forward_page_func:
1697 * @assistant: a #GtkAssistant
1698 * @page_func: (allow-none): the #GtkAssistantPageFunc, or %NULL
1699 * to use the default one
1700 * @data: user data for @page_func
1701 * @destroy: destroy notifier for @data
1703 * Sets the page forwarding function to be @page_func.
1705 * This function will be used to determine what will be
1706 * the next page when the user presses the forward button.
1707 * Setting @page_func to %NULL will make the assistant to
1708 * use the default forward function, which just goes to the
1709 * next visible page.
1714 gtk_assistant_set_forward_page_func (GtkAssistant *assistant,
1715 GtkAssistantPageFunc page_func,
1717 GDestroyNotify destroy)
1719 GtkAssistantPrivate *priv;
1721 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1723 priv = assistant->priv;
1725 if (priv->forward_data_destroy &&
1726 priv->forward_function_data)
1727 (*priv->forward_data_destroy) (priv->forward_function_data);
1731 priv->forward_function = page_func;
1732 priv->forward_function_data = data;
1733 priv->forward_data_destroy = destroy;
1737 priv->forward_function = default_forward_function;
1738 priv->forward_function_data = assistant;
1739 priv->forward_data_destroy = NULL;
1742 /* Page flow has possibly changed, so the
1743 * buttons state might need to change too
1745 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1746 update_buttons_state (assistant);
1750 * gtk_assistant_add_action_widget:
1751 * @assistant: a #GtkAssistant
1752 * @child: a #GtkWidget
1754 * Adds a widget to the action area of a #GtkAssistant.
1759 gtk_assistant_add_action_widget (GtkAssistant *assistant,
1762 GtkAssistantPrivate *priv;
1764 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1765 g_return_if_fail (GTK_IS_WIDGET (child));
1767 priv = assistant->priv;
1769 if (GTK_IS_BUTTON (child))
1771 gtk_size_group_add_widget (priv->button_size_group, child);
1772 priv->extra_buttons += 1;
1773 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1774 update_actions_size (assistant);
1777 gtk_box_pack_end (GTK_BOX (priv->action_area), child, FALSE, FALSE, 0);
1781 * gtk_assistant_remove_action_widget:
1782 * @assistant: a #GtkAssistant
1783 * @child: a #GtkWidget
1785 * Removes a widget from the action area of a #GtkAssistant.
1790 gtk_assistant_remove_action_widget (GtkAssistant *assistant,
1793 GtkAssistantPrivate *priv;
1795 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1796 g_return_if_fail (GTK_IS_WIDGET (child));
1798 priv = assistant->priv;
1800 if (GTK_IS_BUTTON (child))
1802 gtk_size_group_remove_widget (priv->button_size_group, child);
1803 priv->extra_buttons -= 1;
1804 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1805 update_actions_size (assistant);
1808 gtk_container_remove (GTK_CONTAINER (priv->action_area), child);
1812 * gtk_assistant_set_page_title:
1813 * @assistant: a #GtkAssistant
1814 * @page: a page of @assistant
1815 * @title: the new title for @page
1817 * Sets a title for @page.
1819 * The title is displayed in the header area of the assistant
1820 * when @page is the current page.
1825 gtk_assistant_set_page_title (GtkAssistant *assistant,
1829 GtkAssistantPage *page_info;
1832 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1833 g_return_if_fail (GTK_IS_WIDGET (page));
1835 child = find_page (assistant, page);
1837 g_return_if_fail (child != NULL);
1839 page_info = (GtkAssistantPage*) child->data;
1841 g_free (page_info->title);
1842 page_info->title = g_strdup (title);
1844 gtk_label_set_text ((GtkLabel*) page_info->regular_title, title);
1845 gtk_label_set_text ((GtkLabel*) page_info->current_title, title);
1847 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1848 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "title");
1852 * gtk_assistant_get_page_title:
1853 * @assistant: a #GtkAssistant
1854 * @page: a page of @assistant
1856 * Gets the title for @page.
1858 * Return value: the title for @page
1863 gtk_assistant_get_page_title (GtkAssistant *assistant,
1866 GtkAssistantPage *page_info;
1869 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1870 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1872 child = find_page (assistant, page);
1874 g_return_val_if_fail (child != NULL, NULL);
1876 page_info = (GtkAssistantPage*) child->data;
1878 return page_info->title;
1882 * gtk_assistant_set_page_type:
1883 * @assistant: a #GtkAssistant
1884 * @page: a page of @assistant
1885 * @type: the new type for @page
1887 * Sets the page type for @page.
1889 * The page type determines the page behavior in the @assistant.
1894 gtk_assistant_set_page_type (GtkAssistant *assistant,
1896 GtkAssistantPageType type)
1898 GtkAssistantPage *page_info;
1901 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1902 g_return_if_fail (GTK_IS_WIDGET (page));
1904 child = find_page (assistant, page);
1906 g_return_if_fail (child != NULL);
1908 page_info = (GtkAssistantPage*) child->data;
1910 if (type != page_info->type)
1912 page_info->type = type;
1914 /* backwards compatibility to the era before fixing bug 604289 */
1915 if (type == GTK_ASSISTANT_PAGE_SUMMARY && !page_info->complete_set)
1917 gtk_assistant_set_page_complete (assistant, page, TRUE);
1918 page_info->complete_set = FALSE;
1921 /* Always set buttons state, a change in a future page
1922 * might change current page buttons
1924 update_buttons_state (assistant);
1926 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "page-type");
1931 * gtk_assistant_get_page_type:
1932 * @assistant: a #GtkAssistant
1933 * @page: a page of @assistant
1935 * Gets the page type of @page.
1937 * Return value: the page type of @page
1941 GtkAssistantPageType
1942 gtk_assistant_get_page_type (GtkAssistant *assistant,
1945 GtkAssistantPage *page_info;
1948 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), GTK_ASSISTANT_PAGE_CONTENT);
1949 g_return_val_if_fail (GTK_IS_WIDGET (page), GTK_ASSISTANT_PAGE_CONTENT);
1951 child = find_page (assistant, page);
1953 g_return_val_if_fail (child != NULL, GTK_ASSISTANT_PAGE_CONTENT);
1955 page_info = (GtkAssistantPage*) child->data;
1957 return page_info->type;
1961 * gtk_assistant_set_page_header_image:
1962 * @assistant: a #GtkAssistant
1963 * @page: a page of @assistant
1964 * @pixbuf: (allow-none): the new header image @page
1966 * Sets a header image for @page.
1970 * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
1971 * add your header decoration to the page content instead.
1974 gtk_assistant_set_page_header_image (GtkAssistant *assistant,
1978 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1979 g_return_if_fail (GTK_IS_WIDGET (page));
1980 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1982 gtk_assistant_do_set_page_header_image (assistant, page, pixbuf);
1986 gtk_assistant_do_set_page_header_image (GtkAssistant *assistant,
1990 GtkAssistantPage *page_info;
1993 child = find_page (assistant, page);
1995 g_return_if_fail (child != NULL);
1997 page_info = (GtkAssistantPage*) child->data;
1999 if (pixbuf != page_info->header_image)
2001 if (page_info->header_image)
2003 g_object_unref (page_info->header_image);
2004 page_info->header_image = NULL;
2008 page_info->header_image = g_object_ref (pixbuf);
2010 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "header-image");
2015 * gtk_assistant_get_page_header_image:
2016 * @assistant: a #GtkAssistant
2017 * @page: a page of @assistant
2019 * Gets the header image for @page.
2021 * Return value: (transfer none): the header image for @page,
2022 * or %NULL if there's no header image for the page
2026 * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
2027 * add your header decoration to the page content instead.
2030 gtk_assistant_get_page_header_image (GtkAssistant *assistant,
2033 GtkAssistantPage *page_info;
2036 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2037 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2039 child = find_page (assistant, page);
2041 g_return_val_if_fail (child != NULL, NULL);
2043 page_info = (GtkAssistantPage*) child->data;
2045 return page_info->header_image;
2049 * gtk_assistant_set_page_side_image:
2050 * @assistant: a #GtkAssistant
2051 * @page: a page of @assistant
2052 * @pixbuf: (allow-none): the new side image @page
2054 * Sets a side image for @page.
2056 * This image used to be displayed in the side area of the assistant
2057 * when @page is the current page.
2061 * Deprecated: 3.2: Since GTK+ 3.2, sidebar images are not
2065 gtk_assistant_set_page_side_image (GtkAssistant *assistant,
2069 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2070 g_return_if_fail (GTK_IS_WIDGET (page));
2071 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2073 gtk_assistant_do_set_page_side_image (assistant, page, pixbuf);
2077 gtk_assistant_do_set_page_side_image (GtkAssistant *assistant,
2081 GtkAssistantPage *page_info;
2084 child = find_page (assistant, page);
2086 g_return_if_fail (child != NULL);
2088 page_info = (GtkAssistantPage*) child->data;
2090 if (pixbuf != page_info->sidebar_image)
2092 if (page_info->sidebar_image)
2094 g_object_unref (page_info->sidebar_image);
2095 page_info->sidebar_image = NULL;
2099 page_info->sidebar_image = g_object_ref (pixbuf);
2101 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "sidebar-image");
2106 * gtk_assistant_get_page_side_image:
2107 * @assistant: a #GtkAssistant
2108 * @page: a page of @assistant
2110 * Gets the side image for @page.
2112 * Return value: (transfer none): the side image for @page,
2113 * or %NULL if there's no side image for the page
2117 * Deprecated: 3.2: Since GTK+ 3.2, sidebar images are not
2121 gtk_assistant_get_page_side_image (GtkAssistant *assistant,
2124 GtkAssistantPage *page_info;
2127 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2128 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2130 child = find_page (assistant, page);
2132 g_return_val_if_fail (child != NULL, NULL);
2134 page_info = (GtkAssistantPage*) child->data;
2136 return page_info->sidebar_image;
2140 * gtk_assistant_set_page_complete:
2141 * @assistant: a #GtkAssistant
2142 * @page: a page of @assistant
2143 * @complete: the completeness status of the page
2145 * Sets whether @page contents are complete.
2147 * This will make @assistant update the buttons state
2148 * to be able to continue the task.
2153 gtk_assistant_set_page_complete (GtkAssistant *assistant,
2157 GtkAssistantPage *page_info;
2160 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2161 g_return_if_fail (GTK_IS_WIDGET (page));
2163 child = find_page (assistant, page);
2165 g_return_if_fail (child != NULL);
2167 page_info = (GtkAssistantPage*) child->data;
2169 if (complete != page_info->complete)
2171 page_info->complete = complete;
2172 page_info->complete_set = TRUE;
2174 /* Always set buttons state, a change in a future page
2175 * might change current page buttons
2177 update_buttons_state (assistant);
2179 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "complete");
2184 * gtk_assistant_get_page_complete:
2185 * @assistant: a #GtkAssistant
2186 * @page: a page of @assistant
2188 * Gets whether @page is complete.
2190 * Return value: %TRUE if @page is complete.
2195 gtk_assistant_get_page_complete (GtkAssistant *assistant,
2198 GtkAssistantPage *page_info;
2201 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), FALSE);
2202 g_return_val_if_fail (GTK_IS_WIDGET (page), FALSE);
2204 child = find_page (assistant, page);
2206 g_return_val_if_fail (child != NULL, FALSE);
2208 page_info = (GtkAssistantPage*) child->data;
2210 return page_info->complete;
2214 * gtk_assistant_update_buttons_state:
2215 * @assistant: a #GtkAssistant
2217 * Forces @assistant to recompute the buttons state.
2219 * GTK+ automatically takes care of this in most situations,
2220 * e.g. when the user goes to a different page, or when the
2221 * visibility or completeness of a page changes.
2223 * One situation where it can be necessary to call this
2224 * function is when changing a value on the current page
2225 * affects the future page flow of the assistant.
2230 gtk_assistant_update_buttons_state (GtkAssistant *assistant)
2232 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2234 update_buttons_state (assistant);
2238 * gtk_assistant_commit:
2239 * @assistant: a #GtkAssistant
2241 * Erases the visited page history so the back button is not
2242 * shown on the current page, and removes the cancel button
2243 * from subsequent pages.
2245 * Use this when the information provided up to the current
2246 * page is hereafter deemed permanent and cannot be modified
2247 * or undone. For example, showing a progress page to track
2248 * a long-running, unreversible operation after the user has
2249 * clicked apply on a confirmation page.
2254 gtk_assistant_commit (GtkAssistant *assistant)
2256 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2258 g_slist_free (assistant->priv->visited_pages);
2259 assistant->priv->visited_pages = NULL;
2261 assistant->priv->committed = TRUE;
2263 update_buttons_state (assistant);
2266 /* accessible implementation */
2268 /* dummy typedefs */
2269 typedef GtkWindowAccessible GtkAssistantAccessible;
2270 typedef GtkWindowAccessibleClass GtkAssistantAccessibleClass;
2272 G_DEFINE_TYPE (GtkAssistantAccessible, _gtk_assistant_accessible, GTK_TYPE_WINDOW_ACCESSIBLE);
2275 gtk_assistant_accessible_get_n_children (AtkObject *accessible)
2279 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2283 return g_list_length (GTK_ASSISTANT (widget)->priv->pages) + 1;
2287 gtk_assistant_accessible_ref_child (AtkObject *accessible,
2290 GtkAssistant *assistant;
2291 GtkAssistantPrivate *priv;
2292 GtkWidget *widget, *child;
2297 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2301 assistant = GTK_ASSISTANT (widget);
2302 priv = assistant->priv;
2303 n_pages = g_list_length (priv->pages);
2307 else if (index < n_pages)
2309 GtkAssistantPage *page = g_list_nth_data (priv->pages, index);
2312 title = gtk_assistant_get_page_title (assistant, child);
2314 else if (index == n_pages)
2316 child = priv->action_area;
2322 obj = gtk_widget_get_accessible (child);
2325 atk_object_set_name (obj, title);
2327 return g_object_ref (obj);
2331 _gtk_assistant_accessible_class_init (GtkAssistantAccessibleClass *klass)
2333 AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
2335 atk_class->get_n_children = gtk_assistant_accessible_get_n_children;
2336 atk_class->ref_child = gtk_assistant_accessible_ref_child;
2340 _gtk_assistant_accessible_init (GtkAssistantAccessible *self)
2344 /* buildable implementation */
2346 static GtkBuildableIface *parent_buildable_iface;
2349 gtk_assistant_buildable_interface_init (GtkBuildableIface *iface)
2351 parent_buildable_iface = g_type_interface_peek_parent (iface);
2352 iface->get_internal_child = gtk_assistant_buildable_get_internal_child;
2353 iface->custom_tag_start = gtk_assistant_buildable_custom_tag_start;
2354 iface->custom_finished = gtk_assistant_buildable_custom_finished;
2358 gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
2359 GtkBuilder *builder,
2360 const gchar *childname)
2362 if (strcmp (childname, "action_area") == 0)
2363 return G_OBJECT (GTK_ASSISTANT (buildable)->priv->action_area);
2365 return parent_buildable_iface->get_internal_child (buildable,
2371 gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
2372 GtkBuilder *builder,
2374 const gchar *tagname,
2375 GMarkupParser *parser,
2378 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
2379 tagname, parser, data);
2383 gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
2384 GtkBuilder *builder,
2386 const gchar *tagname,
2389 parent_buildable_iface->custom_finished (buildable, builder, child,
2390 tagname, user_data);