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 "gtksettings.h"
70 #include "gtksizegroup.h"
71 #include "gtksizerequest.h"
73 #include "gtktypebuiltins.h"
75 #include "gtkprivate.h"
76 #include "gtkbuildable.h"
77 #include "a11y/gtkwindowaccessible.h"
80 #define HEADER_SPACING 12
81 #define ACTION_AREA_SPACING 12
83 typedef struct _GtkAssistantPage GtkAssistantPage;
85 struct _GtkAssistantPage
87 GtkAssistantPageType type;
89 guint complete_set : 1;
94 GtkWidget *regular_title;
95 GtkWidget *current_title;
96 GdkPixbuf *header_image;
97 GdkPixbuf *sidebar_image;
100 struct _GtkAssistantPrivate
111 GtkWidget *action_area;
114 GSList *visited_pages;
115 GtkAssistantPage *current_page;
117 GtkSizeGroup *button_size_group;
118 GtkSizeGroup *title_size_group;
120 GtkAssistantPageFunc forward_function;
121 gpointer forward_function_data;
122 GDestroyNotify forward_data_destroy;
129 static void gtk_assistant_class_init (GtkAssistantClass *class);
130 static void gtk_assistant_init (GtkAssistant *assistant);
131 static void gtk_assistant_destroy (GtkWidget *widget);
132 static void gtk_assistant_map (GtkWidget *widget);
133 static void gtk_assistant_unmap (GtkWidget *widget);
134 static gboolean gtk_assistant_delete_event (GtkWidget *widget,
136 static void gtk_assistant_add (GtkContainer *container,
138 static void gtk_assistant_remove (GtkContainer *container,
140 static void gtk_assistant_set_child_property (GtkContainer *container,
145 static void gtk_assistant_get_child_property (GtkContainer *container,
151 static void gtk_assistant_buildable_interface_init (GtkBuildableIface *iface);
152 static GObject *gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
154 const gchar *childname);
155 static gboolean gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
158 const gchar *tagname,
159 GMarkupParser *parser,
161 static void gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
164 const gchar *tagname,
167 static GList* find_page (GtkAssistant *assistant,
169 static void gtk_assistant_do_set_page_header_image (GtkAssistant *assistant,
172 static void gtk_assistant_do_set_page_side_image (GtkAssistant *assistant,
176 GType _gtk_assistant_accessible_get_type (void);
181 CHILD_PROP_PAGE_TYPE,
182 CHILD_PROP_PAGE_TITLE,
183 CHILD_PROP_PAGE_HEADER_IMAGE,
184 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
185 CHILD_PROP_PAGE_COMPLETE
197 static guint signals [LAST_SIGNAL] = { 0 };
200 G_DEFINE_TYPE_WITH_CODE (GtkAssistant, gtk_assistant, GTK_TYPE_WINDOW,
201 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
202 gtk_assistant_buildable_interface_init))
206 gtk_assistant_class_init (GtkAssistantClass *class)
208 GObjectClass *gobject_class;
209 GtkWidgetClass *widget_class;
210 GtkContainerClass *container_class;
212 gobject_class = (GObjectClass *) class;
213 widget_class = (GtkWidgetClass *) class;
214 container_class = (GtkContainerClass *) class;
216 widget_class->destroy = gtk_assistant_destroy;
217 widget_class->map = gtk_assistant_map;
218 widget_class->unmap = gtk_assistant_unmap;
219 widget_class->delete_event = gtk_assistant_delete_event;
221 gtk_widget_class_set_accessible_type (widget_class, _gtk_assistant_accessible_get_type ());
223 container_class->add = gtk_assistant_add;
224 container_class->remove = gtk_assistant_remove;
225 container_class->set_child_property = gtk_assistant_set_child_property;
226 container_class->get_child_property = gtk_assistant_get_child_property;
229 * GtkAssistant::cancel:
230 * @assistant: the #GtkAssistant
232 * The ::cancel signal is emitted when then the cancel button is clicked.
237 g_signal_new (I_("cancel"),
238 G_TYPE_FROM_CLASS (gobject_class),
240 G_STRUCT_OFFSET (GtkAssistantClass, cancel),
242 g_cclosure_marshal_VOID__VOID,
246 * GtkAssistant::prepare:
247 * @assistant: the #GtkAssistant
248 * @page: the current page
250 * The ::prepare signal is emitted when a new page is set as the
251 * assistant's current page, before making the new page visible.
253 * A handler for this signal can do any preparations which are
254 * necessary before showing @page.
259 g_signal_new (I_("prepare"),
260 G_TYPE_FROM_CLASS (gobject_class),
262 G_STRUCT_OFFSET (GtkAssistantClass, prepare),
264 g_cclosure_marshal_VOID__OBJECT,
265 G_TYPE_NONE, 1, GTK_TYPE_WIDGET);
268 * GtkAssistant::apply:
269 * @assistant: the #GtkAssistant
271 * The ::apply signal is emitted when the apply button is clicked.
273 * The default behavior of the #GtkAssistant is to switch to the page
274 * after the current page, unless the current page is the last one.
276 * A handler for the ::apply signal should carry out the actions for
277 * which the wizard has collected data. If the action takes a long time
278 * to complete, you might consider putting a page of type
279 * %GTK_ASSISTANT_PAGE_PROGRESS after the confirmation page and handle
280 * this operation within the #GtkAssistant::prepare signal of the progress
286 g_signal_new (I_("apply"),
287 G_TYPE_FROM_CLASS (gobject_class),
289 G_STRUCT_OFFSET (GtkAssistantClass, apply),
291 g_cclosure_marshal_VOID__VOID,
295 * GtkAssistant::close:
296 * @assistant: the #GtkAssistant
298 * The ::close signal is emitted either when the close button of
299 * a summary page is clicked, or when the apply button in the last
300 * page in the flow (of type %GTK_ASSISTANT_PAGE_CONFIRM) is clicked.
305 g_signal_new (I_("close"),
306 G_TYPE_FROM_CLASS (gobject_class),
308 G_STRUCT_OFFSET (GtkAssistantClass, close),
310 g_cclosure_marshal_VOID__VOID,
313 gtk_widget_class_install_style_property (widget_class,
314 g_param_spec_int ("header-padding",
315 P_("Header Padding"),
316 P_("Number of pixels around the header."),
320 GTK_PARAM_READABLE));
321 gtk_widget_class_install_style_property (widget_class,
322 g_param_spec_int ("content-padding",
323 P_("Content Padding"),
324 P_("Number of pixels around the content pages."),
328 GTK_PARAM_READABLE));
331 * GtkAssistant:page-type:
333 * The type of the assistant page.
337 gtk_container_class_install_child_property (container_class,
338 CHILD_PROP_PAGE_TYPE,
339 g_param_spec_enum ("page-type",
341 P_("The type of the assistant page"),
342 GTK_TYPE_ASSISTANT_PAGE_TYPE,
343 GTK_ASSISTANT_PAGE_CONTENT,
344 GTK_PARAM_READWRITE));
347 * GtkAssistant:title:
349 * The title of the page.
353 gtk_container_class_install_child_property (container_class,
354 CHILD_PROP_PAGE_TITLE,
355 g_param_spec_string ("title",
357 P_("The title of the assistant page"),
359 GTK_PARAM_READWRITE));
362 * GtkAssistant:header-image:
364 * This image used to be displayed in the page header.
368 * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
369 * add your header decoration to the page content instead.
371 gtk_container_class_install_child_property (container_class,
372 CHILD_PROP_PAGE_HEADER_IMAGE,
373 g_param_spec_object ("header-image",
375 P_("Header image for the assistant page"),
377 GTK_PARAM_READWRITE));
380 * GtkAssistant:sidebar-image:
382 * This image used to be displayed in the 'sidebar'.
386 * Deprecated: 3.2: Since GTK+ 3.2, the sidebar image is no longer shown.
388 gtk_container_class_install_child_property (container_class,
389 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
390 g_param_spec_object ("sidebar-image",
392 P_("Sidebar image for the assistant page"),
394 GTK_PARAM_READWRITE));
397 * GtkAssistant:complete:
399 * Setting the "complete" child property to %TRUE marks a page as
400 * complete (i.e.: all the required fields are filled out). GTK+ uses
401 * this information to control the sensitivity of the navigation buttons.
405 gtk_container_class_install_child_property (container_class,
406 CHILD_PROP_PAGE_COMPLETE,
407 g_param_spec_boolean ("complete",
409 P_("Whether all required fields on the page have been filled out"),
413 g_type_class_add_private (gobject_class, sizeof (GtkAssistantPrivate));
417 default_forward_function (gint current_page, gpointer data)
419 GtkAssistant *assistant;
420 GtkAssistantPrivate *priv;
421 GtkAssistantPage *page_info;
424 assistant = GTK_ASSISTANT (data);
425 priv = assistant->priv;
427 page_node = g_list_nth (priv->pages, ++current_page);
432 page_info = (GtkAssistantPage *) page_node->data;
434 while (page_node && !gtk_widget_get_visible (page_info->page))
436 page_node = page_node->next;
440 page_info = (GtkAssistantPage *) page_node->data;
447 last_button_visible (GtkAssistant *assistant, GtkAssistantPage *page)
449 GtkAssistantPrivate *priv = assistant->priv;
450 GtkAssistantPage *page_info;
451 gint count, page_num, n_pages;
456 if (page->type != GTK_ASSISTANT_PAGE_CONTENT)
460 page_num = g_list_index (priv->pages, page);
461 n_pages = g_list_length (priv->pages);
464 while (page_num >= 0 && page_num < n_pages &&
465 page_info->type == GTK_ASSISTANT_PAGE_CONTENT &&
466 (count == 0 || page_info->complete) &&
469 page_num = (priv->forward_function) (page_num, priv->forward_function_data);
470 page_info = g_list_nth_data (priv->pages, page_num);
475 /* Make the last button visible if we can skip multiple
476 * pages and end on a confirmation or summary page
478 if (count > 1 && page_info &&
479 (page_info->type == GTK_ASSISTANT_PAGE_CONFIRM ||
480 page_info->type == GTK_ASSISTANT_PAGE_SUMMARY))
487 update_actions_size (GtkAssistant *assistant)
489 GtkAssistantPrivate *priv = assistant->priv;
491 GtkAssistantPage *page;
492 gint buttons, page_buttons;
494 if (!priv->current_page)
497 /* Some heuristics to find out how many buttons we should
498 * reserve space for. It is possible to trick this code
499 * with page forward functions and invisible pages, etc.
502 for (l = priv->pages; l; l = l->next)
506 if (!gtk_widget_get_visible (page->page))
509 page_buttons = 2; /* cancel, forward/apply/close */
510 if (l != priv->pages)
511 page_buttons += 1; /* back */
512 if (last_button_visible (assistant, page))
513 page_buttons += 1; /* last */
515 buttons = MAX (buttons, page_buttons);
518 buttons += priv->extra_buttons;
520 gtk_widget_set_size_request (priv->action_area,
521 buttons * gtk_widget_get_allocated_width (priv->cancel) + (buttons - 1) * 6,
526 compute_last_button_state (GtkAssistant *assistant)
528 GtkAssistantPrivate *priv = assistant->priv;
530 gtk_widget_set_sensitive (priv->last, priv->current_page->complete);
531 if (last_button_visible (assistant, priv->current_page))
532 gtk_widget_show (priv->last);
534 gtk_widget_hide (priv->last);
538 compute_progress_state (GtkAssistant *assistant)
540 GtkAssistantPrivate *priv = assistant->priv;
541 gint page_num, n_pages;
543 n_pages = gtk_assistant_get_n_pages (assistant);
544 page_num = gtk_assistant_get_current_page (assistant);
546 page_num = (priv->forward_function) (page_num, priv->forward_function_data);
548 if (page_num >= 0 && page_num < n_pages)
549 gtk_widget_show (priv->forward);
551 gtk_widget_hide (priv->forward);
555 update_buttons_state (GtkAssistant *assistant)
557 GtkAssistantPrivate *priv = assistant->priv;
559 if (!priv->current_page)
562 switch (priv->current_page->type)
564 case GTK_ASSISTANT_PAGE_INTRO:
565 gtk_widget_set_sensitive (priv->cancel, TRUE);
566 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
567 gtk_widget_grab_default (priv->forward);
568 gtk_widget_show (priv->forward);
569 gtk_widget_hide (priv->back);
570 gtk_widget_hide (priv->apply);
571 gtk_widget_hide (priv->close);
572 compute_last_button_state (assistant);
574 case GTK_ASSISTANT_PAGE_CONFIRM:
575 gtk_widget_set_sensitive (priv->cancel, TRUE);
576 gtk_widget_set_sensitive (priv->back, TRUE);
577 gtk_widget_set_sensitive (priv->apply, priv->current_page->complete);
578 gtk_widget_grab_default (priv->apply);
579 gtk_widget_show (priv->back);
580 gtk_widget_show (priv->apply);
581 gtk_widget_hide (priv->forward);
582 gtk_widget_hide (priv->close);
583 gtk_widget_hide (priv->last);
585 case GTK_ASSISTANT_PAGE_CONTENT:
586 gtk_widget_set_sensitive (priv->cancel, TRUE);
587 gtk_widget_set_sensitive (priv->back, TRUE);
588 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
589 gtk_widget_grab_default (priv->forward);
590 gtk_widget_show (priv->back);
591 gtk_widget_show (priv->forward);
592 gtk_widget_hide (priv->apply);
593 gtk_widget_hide (priv->close);
594 compute_last_button_state (assistant);
596 case GTK_ASSISTANT_PAGE_SUMMARY:
597 gtk_widget_set_sensitive (priv->close, priv->current_page->complete);
598 gtk_widget_grab_default (priv->close);
599 gtk_widget_show (priv->close);
600 gtk_widget_hide (priv->back);
601 gtk_widget_hide (priv->forward);
602 gtk_widget_hide (priv->apply);
603 gtk_widget_hide (priv->last);
605 case GTK_ASSISTANT_PAGE_PROGRESS:
606 gtk_widget_set_sensitive (priv->cancel, priv->current_page->complete);
607 gtk_widget_set_sensitive (priv->back, priv->current_page->complete);
608 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
609 gtk_widget_grab_default (priv->forward);
610 gtk_widget_show (priv->back);
611 gtk_widget_hide (priv->apply);
612 gtk_widget_hide (priv->close);
613 gtk_widget_hide (priv->last);
614 compute_progress_state (assistant);
616 case GTK_ASSISTANT_PAGE_CUSTOM:
617 gtk_widget_hide (priv->cancel);
618 gtk_widget_hide (priv->back);
619 gtk_widget_hide (priv->forward);
620 gtk_widget_hide (priv->apply);
621 gtk_widget_hide (priv->last);
622 gtk_widget_hide (priv->close);
625 g_assert_not_reached ();
629 gtk_widget_hide (priv->cancel);
630 else if (priv->current_page->type == GTK_ASSISTANT_PAGE_SUMMARY ||
631 priv->current_page->type == GTK_ASSISTANT_PAGE_CUSTOM)
632 gtk_widget_hide (priv->cancel);
634 gtk_widget_show (priv->cancel);
636 /* this is quite general, we don't want to
637 * go back if it's the first page
639 if (!priv->visited_pages)
640 gtk_widget_hide (priv->back);
644 update_page_title_state (GtkAssistant *assistant, GList *list)
646 GtkAssistantPage *page, *other;
647 GtkAssistantPrivate *priv = assistant->priv;
653 if (page->title == NULL || page->title[0] == 0)
656 visible = gtk_widget_get_visible (page->page);
658 if (page == priv->current_page)
660 gtk_widget_set_visible (page->regular_title, FALSE);
661 gtk_widget_set_visible (page->current_title, visible);
665 /* If multiple consecutive pages have the same title,
666 * we only show it once, since it would otherwise look
667 * silly. We have to be a little careful, since we
668 * _always_ show the title of the current page.
672 other = list->prev->data;
673 if (g_strcmp0 (page->title, other->title) == 0)
676 for (l = list->next; l; l = l->next)
679 if (g_strcmp0 (page->title, other->title) != 0)
682 if (other == priv->current_page)
689 gtk_widget_set_visible (page->regular_title, visible);
690 gtk_widget_set_visible (page->current_title, FALSE);
697 update_title_state (GtkAssistant *assistant)
699 GtkAssistantPrivate *priv = assistant->priv;
701 gboolean show_titles;
704 for (l = priv->pages; l != NULL; l = l->next)
706 if (update_page_title_state (assistant, l))
710 gtk_widget_set_visible (priv->sidebar, show_titles);
714 set_current_page (GtkAssistant *assistant,
717 GtkAssistantPrivate *priv = assistant->priv;
719 priv->current_page = (GtkAssistantPage *)g_list_nth_data (priv->pages, page_num);
721 g_signal_emit (assistant, signals [PREPARE], 0, priv->current_page->page);
723 update_title_state (assistant);
725 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->content), page_num);
727 /* update buttons state, flow may have changed */
728 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
729 update_buttons_state (assistant);
731 if (!gtk_widget_child_focus (priv->current_page->page, GTK_DIR_TAB_FORWARD))
733 GtkWidget *button[6];
736 /* find the best button to focus */
737 button[0] = priv->apply;
738 button[1] = priv->close;
739 button[2] = priv->forward;
740 button[3] = priv->back;
741 button[4] = priv->cancel;
742 button[5] = priv->last;
743 for (i = 0; i < 6; i++)
745 if (gtk_widget_get_visible (button[i]) &&
746 gtk_widget_get_sensitive (button[i]))
748 gtk_widget_grab_focus (button[i]);
754 gtk_widget_queue_resize (GTK_WIDGET (assistant));
758 compute_next_step (GtkAssistant *assistant)
760 GtkAssistantPrivate *priv = assistant->priv;
761 GtkAssistantPage *page_info;
762 gint current_page, n_pages, next_page;
764 current_page = gtk_assistant_get_current_page (assistant);
765 page_info = priv->current_page;
766 n_pages = gtk_assistant_get_n_pages (assistant);
768 next_page = (priv->forward_function) (current_page,
769 priv->forward_function_data);
771 if (next_page >= 0 && next_page < n_pages)
773 priv->visited_pages = g_slist_prepend (priv->visited_pages, page_info);
774 set_current_page (assistant, next_page);
783 on_assistant_close (GtkWidget *widget,
784 GtkAssistant *assistant)
786 g_signal_emit (assistant, signals [CLOSE], 0, NULL);
790 on_assistant_apply (GtkWidget *widget,
791 GtkAssistant *assistant)
795 g_signal_emit (assistant, signals [APPLY], 0);
797 success = compute_next_step (assistant);
799 /* if the assistant hasn't switched to another page, just emit
800 * the CLOSE signal, it't the last page in the assistant flow
803 g_signal_emit (assistant, signals [CLOSE], 0);
807 on_assistant_forward (GtkWidget *widget,
808 GtkAssistant *assistant)
810 gtk_assistant_next_page (assistant);
814 on_assistant_back (GtkWidget *widget,
815 GtkAssistant *assistant)
817 gtk_assistant_previous_page (assistant);
821 on_assistant_cancel (GtkWidget *widget,
822 GtkAssistant *assistant)
824 g_signal_emit (assistant, signals [CANCEL], 0, NULL);
828 on_assistant_last (GtkWidget *widget,
829 GtkAssistant *assistant)
831 GtkAssistantPrivate *priv = assistant->priv;
833 while (priv->current_page->type == GTK_ASSISTANT_PAGE_CONTENT &&
834 priv->current_page->complete)
835 compute_next_step (assistant);
839 alternative_button_order (GtkAssistant *assistant)
841 GtkSettings *settings;
845 screen = gtk_widget_get_screen (GTK_WIDGET (assistant));
846 settings = gtk_settings_get_for_screen (screen);
848 g_object_get (settings,
849 "gtk-alternative-button-order", &result,
855 assistant_sidebar_draw_cb (GtkWidget *widget,
860 GtkStyleContext *context;
862 width = gtk_widget_get_allocated_width (widget);
863 height = gtk_widget_get_allocated_height (widget);
864 context = gtk_widget_get_style_context (widget);
866 gtk_render_background (context, cr, 0, 0, width, height);
872 on_page_notify_visibility (GtkWidget *widget,
876 GtkAssistant *assistant = GTK_ASSISTANT (data);
878 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
880 update_buttons_state (assistant);
881 update_title_state (assistant);
886 assistant_remove_page_cb (GtkNotebook *notebook,
888 GtkAssistant *assistant)
890 GtkAssistantPrivate *priv = assistant->priv;
891 GtkAssistantPage *page_info;
895 element = find_page (assistant, page);
899 page_info = element->data;
901 /* If this is the current page, we need to switch away. */
902 if (page_info == priv->current_page)
904 if (!compute_next_step (assistant))
906 /* The best we can do at this point is probably to pick
907 * the first visible page.
909 page_node = priv->pages;
912 !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
913 page_node = page_node->next;
915 if (page_node == element)
916 page_node = page_node->next;
919 priv->current_page = page_node->data;
921 priv->current_page = NULL;
925 g_signal_handlers_disconnect_by_func (page_info->page, on_page_notify_visibility, assistant);
927 gtk_size_group_remove_widget (priv->title_size_group, page_info->regular_title);
928 gtk_size_group_remove_widget (priv->title_size_group, page_info->current_title);
930 gtk_container_remove (GTK_CONTAINER (priv->sidebar), page_info->regular_title);
931 gtk_container_remove (GTK_CONTAINER (priv->sidebar), page_info->current_title);
933 priv->pages = g_list_remove_link (priv->pages, element);
934 priv->visited_pages = g_slist_remove_all (priv->visited_pages, page_info);
936 g_free (page_info->title);
938 g_slice_free (GtkAssistantPage, page_info);
939 g_list_free_1 (element);
941 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
943 update_buttons_state (assistant);
944 update_actions_size (assistant);
949 gtk_assistant_init (GtkAssistant *assistant)
951 GtkAssistantPrivate *priv;
952 GtkStyleContext *context;
954 GtkWidget *content_box;
955 GtkWidget *sidebar_frame;
957 assistant->priv = G_TYPE_INSTANCE_GET_PRIVATE (assistant,
959 GtkAssistantPrivate);
960 priv = assistant->priv;
962 /* use border on inner panes instead */
963 gtk_container_set_border_width (GTK_CONTAINER (assistant), 0);
965 gtk_widget_push_composite_child ();
967 main_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
968 priv->sidebar = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
970 /* use a frame for the sidebar, and manually render a background
971 * in it. GtkFrame also gives us padding support for free.
973 sidebar_frame = gtk_frame_new (NULL);
974 context = gtk_widget_get_style_context (sidebar_frame);
975 gtk_style_context_add_class (context, GTK_STYLE_CLASS_SIDEBAR);
977 g_signal_connect (sidebar_frame, "draw",
978 G_CALLBACK (assistant_sidebar_draw_cb), assistant);
980 content_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
981 gtk_container_set_border_width (GTK_CONTAINER (content_box), 12);
982 priv->content = gtk_notebook_new ();
983 gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->content), FALSE);
984 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->content), FALSE);
985 priv->action_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
987 g_signal_connect (priv->content, "remove",
988 G_CALLBACK (assistant_remove_page_cb), assistant);
990 gtk_container_add (GTK_CONTAINER (sidebar_frame), priv->sidebar);
991 gtk_box_pack_start (GTK_BOX (main_box), sidebar_frame, FALSE, FALSE, 0);
992 gtk_box_pack_start (GTK_BOX (main_box), content_box, TRUE, TRUE, 0);
993 gtk_box_pack_start (GTK_BOX (content_box), priv->content, TRUE, TRUE, 0);
994 gtk_box_pack_start (GTK_BOX (content_box), priv->action_area, FALSE, TRUE, 0);
995 gtk_widget_set_halign (priv->action_area, GTK_ALIGN_END);
997 gtk_widget_show_all (main_box);
999 gtk_widget_set_parent (main_box, GTK_WIDGET (assistant));
1000 _gtk_bin_set_child (GTK_BIN (assistant), main_box);
1002 priv->close = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
1003 priv->apply = gtk_button_new_from_stock (GTK_STOCK_APPLY);
1004 priv->forward = gtk_button_new_with_mnemonic (_("C_ontinue"));
1005 gtk_button_set_image (GTK_BUTTON (priv->forward),
1006 gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD, GTK_ICON_SIZE_BUTTON));
1007 priv->back = gtk_button_new_with_mnemonic (_("Go _Back"));
1008 gtk_button_set_image (GTK_BUTTON (priv->forward),
1009 gtk_image_new_from_stock (GTK_STOCK_GO_BACK, GTK_ICON_SIZE_BUTTON));
1010 priv->cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
1011 priv->last = gtk_button_new_with_mnemonic (_("_Finish"));
1012 gtk_button_set_image (GTK_BUTTON (priv->forward),
1013 gtk_image_new_from_stock (GTK_STOCK_GOTO_LAST, GTK_ICON_SIZE_BUTTON));
1014 gtk_widget_set_can_default (priv->close, TRUE);
1015 gtk_widget_set_can_default (priv->apply, TRUE);
1016 gtk_widget_set_can_default (priv->forward, TRUE);
1018 priv->button_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
1019 gtk_size_group_add_widget (priv->button_size_group, priv->close);
1020 gtk_size_group_add_widget (priv->button_size_group, priv->apply);
1021 gtk_size_group_add_widget (priv->button_size_group, priv->forward);
1022 gtk_size_group_add_widget (priv->button_size_group, priv->back);
1023 gtk_size_group_add_widget (priv->button_size_group, priv->cancel);
1024 gtk_size_group_add_widget (priv->button_size_group, priv->last);
1026 gtk_widget_set_no_show_all (priv->close, TRUE);
1027 gtk_widget_set_no_show_all (priv->apply, TRUE);
1028 gtk_widget_set_no_show_all (priv->forward, TRUE);
1029 gtk_widget_set_no_show_all (priv->back, TRUE);
1030 gtk_widget_set_no_show_all (priv->cancel, TRUE);
1031 gtk_widget_set_no_show_all (priv->last, TRUE);
1033 if (!alternative_button_order (assistant))
1035 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
1036 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
1037 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
1038 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
1039 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
1040 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->close, FALSE, FALSE, 0);
1045 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
1046 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
1047 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
1048 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
1049 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
1052 gtk_widget_show (priv->forward);
1053 gtk_widget_show (priv->back);
1054 gtk_widget_show (priv->cancel);
1055 gtk_widget_show (priv->action_area);
1057 gtk_widget_pop_composite_child ();
1059 priv->title_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
1062 priv->current_page = NULL;
1063 priv->visited_pages = NULL;
1065 priv->forward_function = default_forward_function;
1066 priv->forward_function_data = assistant;
1067 priv->forward_data_destroy = NULL;
1069 g_signal_connect (G_OBJECT (priv->close), "clicked",
1070 G_CALLBACK (on_assistant_close), assistant);
1071 g_signal_connect (G_OBJECT (priv->apply), "clicked",
1072 G_CALLBACK (on_assistant_apply), assistant);
1073 g_signal_connect (G_OBJECT (priv->forward), "clicked",
1074 G_CALLBACK (on_assistant_forward), assistant);
1075 g_signal_connect (G_OBJECT (priv->back), "clicked",
1076 G_CALLBACK (on_assistant_back), assistant);
1077 g_signal_connect (G_OBJECT (priv->cancel), "clicked",
1078 G_CALLBACK (on_assistant_cancel), assistant);
1079 g_signal_connect (G_OBJECT (priv->last), "clicked",
1080 G_CALLBACK (on_assistant_last), assistant);
1084 gtk_assistant_set_child_property (GtkContainer *container,
1087 const GValue *value,
1090 switch (property_id)
1092 case CHILD_PROP_PAGE_TYPE:
1093 gtk_assistant_set_page_type (GTK_ASSISTANT (container), child,
1094 g_value_get_enum (value));
1096 case CHILD_PROP_PAGE_TITLE:
1097 gtk_assistant_set_page_title (GTK_ASSISTANT (container), child,
1098 g_value_get_string (value));
1100 case CHILD_PROP_PAGE_HEADER_IMAGE:
1101 gtk_assistant_do_set_page_header_image (GTK_ASSISTANT (container), child,
1102 g_value_get_object (value));
1104 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
1105 gtk_assistant_do_set_page_side_image (GTK_ASSISTANT (container), child,
1106 g_value_get_object (value));
1108 case CHILD_PROP_PAGE_COMPLETE:
1109 gtk_assistant_set_page_complete (GTK_ASSISTANT (container), child,
1110 g_value_get_boolean (value));
1113 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
1119 gtk_assistant_get_child_property (GtkContainer *container,
1125 GtkAssistant *assistant = GTK_ASSISTANT (container);
1127 switch (property_id)
1129 case CHILD_PROP_PAGE_TYPE:
1130 g_value_set_enum (value,
1131 gtk_assistant_get_page_type (assistant, child));
1133 case CHILD_PROP_PAGE_TITLE:
1134 g_value_set_string (value,
1135 gtk_assistant_get_page_title (assistant, child));
1137 case CHILD_PROP_PAGE_HEADER_IMAGE:
1138 g_value_set_object (value,
1139 ((GtkAssistantPage*) find_page (assistant, child))->header_image);
1141 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
1142 g_value_set_object (value,
1143 ((GtkAssistantPage*) find_page (assistant, child))->sidebar_image);
1145 case CHILD_PROP_PAGE_COMPLETE:
1146 g_value_set_boolean (value,
1147 gtk_assistant_get_page_complete (assistant, child));
1150 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
1156 gtk_assistant_destroy (GtkWidget *widget)
1158 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1159 GtkAssistantPrivate *priv = assistant->priv;
1161 /* We set current to NULL so that the remove code doesn't try
1162 * to do anything funny
1164 priv->current_page = NULL;
1168 GtkNotebook *notebook;
1171 /* Remove all pages from the content notebook. */
1172 notebook = (GtkNotebook *) priv->content;
1173 while ((page = gtk_notebook_get_nth_page (notebook, 0)) != NULL)
1174 gtk_container_remove ((GtkContainer *) notebook, page);
1176 /* Our GtkAssistantPage list should be empty now. */
1177 g_warn_if_fail (priv->pages == NULL);
1179 priv->content = NULL;
1183 priv->sidebar = NULL;
1185 if (priv->action_area)
1186 priv->action_area = NULL;
1188 if (priv->button_size_group)
1190 g_object_unref (priv->button_size_group);
1191 priv->button_size_group = NULL;
1194 if (priv->title_size_group)
1196 g_object_unref (priv->title_size_group);
1197 priv->title_size_group = NULL;
1200 if (priv->forward_function)
1202 if (priv->forward_function_data &&
1203 priv->forward_data_destroy)
1204 priv->forward_data_destroy (priv->forward_function_data);
1206 priv->forward_function = NULL;
1207 priv->forward_function_data = NULL;
1208 priv->forward_data_destroy = NULL;
1211 if (priv->visited_pages)
1213 g_slist_free (priv->visited_pages);
1214 priv->visited_pages = NULL;
1217 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->destroy (widget);
1221 find_page (GtkAssistant *assistant,
1224 GtkAssistantPrivate *priv = assistant->priv;
1225 GList *child = priv->pages;
1229 GtkAssistantPage *page_info = child->data;
1230 if (page_info->page == page)
1233 child = child->next;
1240 gtk_assistant_map (GtkWidget *widget)
1242 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1243 GtkAssistantPrivate *priv = assistant->priv;
1245 GtkAssistantPage *page;
1248 /* if there's no default page, pick the first one */
1251 if (!priv->current_page)
1253 page_node = priv->pages;
1255 while (page_node && !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
1257 page_node = page_node->next;
1262 page = page_node->data;
1265 if (page && gtk_widget_get_visible (page->page))
1266 set_current_page (assistant, page_num);
1268 update_buttons_state (assistant);
1269 update_actions_size (assistant);
1270 update_title_state (assistant);
1272 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->map (widget);
1276 gtk_assistant_unmap (GtkWidget *widget)
1278 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1279 GtkAssistantPrivate *priv = assistant->priv;
1281 g_slist_free (priv->visited_pages);
1282 priv->visited_pages = NULL;
1283 priv->current_page = NULL;
1285 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->unmap (widget);
1289 gtk_assistant_delete_event (GtkWidget *widget,
1292 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1293 GtkAssistantPrivate *priv = assistant->priv;
1295 /* Do not allow cancelling in the middle of a progress page */
1296 if (priv->current_page &&
1297 (priv->current_page->type != GTK_ASSISTANT_PAGE_PROGRESS ||
1298 priv->current_page->complete))
1299 g_signal_emit (widget, signals [CANCEL], 0, NULL);
1305 gtk_assistant_add (GtkContainer *container,
1308 gtk_assistant_append_page (GTK_ASSISTANT (container), page);
1312 gtk_assistant_remove (GtkContainer *container,
1315 GtkAssistant *assistant = (GtkAssistant*) container;
1317 /* Forward this removal to the content notebook */
1318 if (gtk_widget_get_parent (page) == assistant->priv->content)
1320 container = (GtkContainer *) assistant->priv->content;
1321 gtk_container_remove (container, page);
1326 * gtk_assistant_new:
1328 * Creates a new #GtkAssistant.
1330 * Return value: a newly created #GtkAssistant
1335 gtk_assistant_new (void)
1337 GtkWidget *assistant;
1339 assistant = g_object_new (GTK_TYPE_ASSISTANT, NULL);
1345 * gtk_assistant_get_current_page:
1346 * @assistant: a #GtkAssistant
1348 * Returns the page number of the current page.
1350 * Return value: The index (starting from 0) of the current
1351 * page in the @assistant, or -1 if the @assistant has no pages,
1352 * or no current page.
1357 gtk_assistant_get_current_page (GtkAssistant *assistant)
1359 GtkAssistantPrivate *priv;
1361 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), -1);
1363 priv = assistant->priv;
1365 if (!priv->pages || !priv->current_page)
1368 return g_list_index (priv->pages, priv->current_page);
1372 * gtk_assistant_set_current_page:
1373 * @assistant: a #GtkAssistant
1374 * @page_num: index of the page to switch to, starting from 0.
1375 * If negative, the last page will be used. If greater
1376 * than the number of pages in the @assistant, nothing
1379 * Switches the page to @page_num.
1381 * Note that this will only be necessary in custom buttons,
1382 * as the @assistant flow can be set with
1383 * gtk_assistant_set_forward_page_func().
1388 gtk_assistant_set_current_page (GtkAssistant *assistant,
1391 GtkAssistantPrivate *priv;
1392 GtkAssistantPage *page;
1394 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1396 priv = assistant->priv;
1399 page = (GtkAssistantPage *) g_list_nth_data (priv->pages, page_num);
1402 page = (GtkAssistantPage *) g_list_last (priv->pages)->data;
1403 page_num = g_list_length (priv->pages);
1406 g_return_if_fail (page != NULL);
1408 if (priv->current_page == page)
1411 /* only add the page to the visited list if the assistant is mapped,
1412 * if not, just use it as an initial page setting, for the cases where
1413 * the initial page is != to 0
1415 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1416 priv->visited_pages = g_slist_prepend (priv->visited_pages,
1417 priv->current_page);
1419 set_current_page (assistant, page_num);
1423 * gtk_assistant_next_page:
1424 * @assistant: a #GtkAssistant
1426 * Navigate to the next page.
1428 * It is a programming error to call this function when
1429 * there is no next page.
1431 * This function is for use when creating pages of the
1432 * #GTK_ASSISTANT_PAGE_CUSTOM type.
1437 gtk_assistant_next_page (GtkAssistant *assistant)
1439 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1441 if (!compute_next_step (assistant))
1442 g_critical ("Page flow is broken.\n"
1443 "You may want to end it with a page of type\n"
1444 "GTK_ASSISTANT_PAGE_CONFIRM or GTK_ASSISTANT_PAGE_SUMMARY");
1448 * gtk_assistant_previous_page:
1449 * @assistant: a #GtkAssistant
1451 * Navigate to the previous visited page.
1453 * It is a programming error to call this function when
1454 * no previous page is available.
1456 * This function is for use when creating pages of the
1457 * #GTK_ASSISTANT_PAGE_CUSTOM type.
1462 gtk_assistant_previous_page (GtkAssistant *assistant)
1464 GtkAssistantPrivate *priv;
1465 GtkAssistantPage *page_info;
1468 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1470 priv = assistant->priv;
1472 /* skip the progress pages when going back */
1475 page_node = priv->visited_pages;
1477 g_return_if_fail (page_node != NULL);
1479 priv->visited_pages = priv->visited_pages->next;
1480 page_info = (GtkAssistantPage *) page_node->data;
1481 g_slist_free_1 (page_node);
1483 while (page_info->type == GTK_ASSISTANT_PAGE_PROGRESS ||
1484 !gtk_widget_get_visible (page_info->page));
1486 set_current_page (assistant, g_list_index (priv->pages, page_info));
1490 * gtk_assistant_get_n_pages:
1491 * @assistant: a #GtkAssistant
1493 * Returns the number of pages in the @assistant
1495 * Return value: the number of pages in the @assistant
1500 gtk_assistant_get_n_pages (GtkAssistant *assistant)
1502 GtkAssistantPrivate *priv;
1504 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1506 priv = assistant->priv;
1508 return g_list_length (priv->pages);
1512 * gtk_assistant_get_nth_page:
1513 * @assistant: a #GtkAssistant
1514 * @page_num: the index of a page in the @assistant,
1515 * or -1 to get the last page
1517 * Returns the child widget contained in page number @page_num.
1519 * Return value: (transfer none): the child widget, or %NULL
1520 * if @page_num is out of bounds
1525 gtk_assistant_get_nth_page (GtkAssistant *assistant,
1528 GtkAssistantPrivate *priv;
1529 GtkAssistantPage *page;
1532 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1533 g_return_val_if_fail (page_num >= -1, NULL);
1535 priv = assistant->priv;
1538 elem = g_list_last (priv->pages);
1540 elem = g_list_nth (priv->pages, page_num);
1545 page = (GtkAssistantPage *) elem->data;
1551 * gtk_assistant_prepend_page:
1552 * @assistant: a #GtkAssistant
1553 * @page: a #GtkWidget
1555 * Prepends a page to the @assistant.
1557 * Return value: the index (starting at 0) of the inserted page
1562 gtk_assistant_prepend_page (GtkAssistant *assistant,
1565 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1566 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1568 return gtk_assistant_insert_page (assistant, page, 0);
1572 * gtk_assistant_append_page:
1573 * @assistant: a #GtkAssistant
1574 * @page: a #GtkWidget
1576 * Appends a page to the @assistant.
1578 * Return value: the index (starting at 0) of the inserted page
1583 gtk_assistant_append_page (GtkAssistant *assistant,
1586 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1587 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1589 return gtk_assistant_insert_page (assistant, page, -1);
1593 * gtk_assistant_insert_page:
1594 * @assistant: a #GtkAssistant
1595 * @page: a #GtkWidget
1596 * @position: the index (starting at 0) at which to insert the page,
1597 * or -1 to append the page to the @assistant
1599 * Inserts a page in the @assistant at a given position.
1601 * Return value: the index (starting from 0) of the inserted page
1606 gtk_assistant_insert_page (GtkAssistant *assistant,
1610 GtkAssistantPrivate *priv;
1611 GtkAssistantPage *page_info;
1613 GtkStyleContext *context;
1615 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1616 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1617 g_return_val_if_fail (gtk_widget_get_parent (page) == NULL, 0);
1618 g_return_val_if_fail (!gtk_widget_is_toplevel (page), 0);
1620 priv = assistant->priv;
1622 page_info = g_slice_new0 (GtkAssistantPage);
1623 page_info->page = page;
1624 page_info->regular_title = gtk_label_new (NULL);
1625 gtk_widget_set_no_show_all (page_info->regular_title, TRUE);
1626 page_info->current_title = gtk_label_new (NULL);
1627 gtk_widget_set_no_show_all (page_info->current_title, TRUE);
1629 /* Note: we need to use misc alignment here as long as GtkLabel
1630 * pays attention to it. GtkWiget::halign is ineffective, since
1631 * all the labels are getting the same size anyway, due to the
1634 gtk_misc_set_alignment (GTK_MISC (page_info->regular_title), 0, 0.5);
1635 gtk_widget_show (page_info->regular_title);
1637 gtk_misc_set_alignment (GTK_MISC (page_info->current_title), 0, 0.5);
1638 gtk_widget_hide (page_info->current_title);
1640 context = gtk_widget_get_style_context (page_info->current_title);
1641 gtk_style_context_add_class (context, GTK_STYLE_CLASS_HIGHLIGHT);
1643 gtk_size_group_add_widget (priv->title_size_group, page_info->regular_title);
1644 gtk_size_group_add_widget (priv->title_size_group, page_info->current_title);
1646 g_signal_connect (G_OBJECT (page), "notify::visible",
1647 G_CALLBACK (on_page_notify_visibility), assistant);
1649 n_pages = g_list_length (priv->pages);
1651 if (position < 0 || position > n_pages)
1654 priv->pages = g_list_insert (priv->pages, page_info, position);
1656 gtk_box_pack_start (GTK_BOX (priv->sidebar), page_info->regular_title, FALSE, FALSE, 0);
1657 gtk_box_pack_start (GTK_BOX (priv->sidebar), page_info->current_title, FALSE, FALSE, 0);
1658 gtk_box_reorder_child (GTK_BOX (priv->sidebar), page_info->regular_title, 2 * position);
1659 gtk_box_reorder_child (GTK_BOX (priv->sidebar), page_info->current_title, 2 * position + 1);
1661 gtk_notebook_insert_page (GTK_NOTEBOOK (priv->content), page, NULL, position);
1663 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1665 update_buttons_state (assistant);
1666 update_actions_size (assistant);
1673 * gtk_assistant_remove_page:
1674 * @assistant: a #GtkAssistant
1675 * @page_num: the index of a page in the @assistant,
1676 * or -1 to remove the last page
1678 * Removes the @page_num's page from @assistant.
1683 gtk_assistant_remove_page (GtkAssistant *assistant,
1688 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1690 page = gtk_assistant_get_nth_page (assistant, page_num);
1693 gtk_container_remove (GTK_CONTAINER (assistant), page);
1697 * gtk_assistant_set_forward_page_func:
1698 * @assistant: a #GtkAssistant
1699 * @page_func: (allow-none): the #GtkAssistantPageFunc, or %NULL
1700 * to use the default one
1701 * @data: user data for @page_func
1702 * @destroy: destroy notifier for @data
1704 * Sets the page forwarding function to be @page_func.
1706 * This function will be used to determine what will be
1707 * the next page when the user presses the forward button.
1708 * Setting @page_func to %NULL will make the assistant to
1709 * use the default forward function, which just goes to the
1710 * next visible page.
1715 gtk_assistant_set_forward_page_func (GtkAssistant *assistant,
1716 GtkAssistantPageFunc page_func,
1718 GDestroyNotify destroy)
1720 GtkAssistantPrivate *priv;
1722 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1724 priv = assistant->priv;
1726 if (priv->forward_data_destroy &&
1727 priv->forward_function_data)
1728 (*priv->forward_data_destroy) (priv->forward_function_data);
1732 priv->forward_function = page_func;
1733 priv->forward_function_data = data;
1734 priv->forward_data_destroy = destroy;
1738 priv->forward_function = default_forward_function;
1739 priv->forward_function_data = assistant;
1740 priv->forward_data_destroy = NULL;
1743 /* Page flow has possibly changed, so the
1744 * buttons state might need to change too
1746 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1747 update_buttons_state (assistant);
1751 * gtk_assistant_add_action_widget:
1752 * @assistant: a #GtkAssistant
1753 * @child: a #GtkWidget
1755 * Adds a widget to the action area of a #GtkAssistant.
1760 gtk_assistant_add_action_widget (GtkAssistant *assistant,
1763 GtkAssistantPrivate *priv;
1765 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1766 g_return_if_fail (GTK_IS_WIDGET (child));
1768 priv = assistant->priv;
1770 if (GTK_IS_BUTTON (child))
1772 gtk_size_group_add_widget (priv->button_size_group, child);
1773 priv->extra_buttons += 1;
1774 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1775 update_actions_size (assistant);
1778 gtk_box_pack_end (GTK_BOX (priv->action_area), child, FALSE, FALSE, 0);
1782 * gtk_assistant_remove_action_widget:
1783 * @assistant: a #GtkAssistant
1784 * @child: a #GtkWidget
1786 * Removes a widget from the action area of a #GtkAssistant.
1791 gtk_assistant_remove_action_widget (GtkAssistant *assistant,
1794 GtkAssistantPrivate *priv;
1796 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1797 g_return_if_fail (GTK_IS_WIDGET (child));
1799 priv = assistant->priv;
1801 if (GTK_IS_BUTTON (child))
1803 gtk_size_group_remove_widget (priv->button_size_group, child);
1804 priv->extra_buttons -= 1;
1805 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1806 update_actions_size (assistant);
1809 gtk_container_remove (GTK_CONTAINER (priv->action_area), child);
1813 * gtk_assistant_set_page_title:
1814 * @assistant: a #GtkAssistant
1815 * @page: a page of @assistant
1816 * @title: the new title for @page
1818 * Sets a title for @page.
1820 * The title is displayed in the header area of the assistant
1821 * when @page is the current page.
1826 gtk_assistant_set_page_title (GtkAssistant *assistant,
1830 GtkAssistantPage *page_info;
1833 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1834 g_return_if_fail (GTK_IS_WIDGET (page));
1836 child = find_page (assistant, page);
1838 g_return_if_fail (child != NULL);
1840 page_info = (GtkAssistantPage*) child->data;
1842 g_free (page_info->title);
1843 page_info->title = g_strdup (title);
1845 gtk_label_set_text ((GtkLabel*) page_info->regular_title, title);
1846 gtk_label_set_text ((GtkLabel*) page_info->current_title, title);
1848 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1849 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "title");
1853 * gtk_assistant_get_page_title:
1854 * @assistant: a #GtkAssistant
1855 * @page: a page of @assistant
1857 * Gets the title for @page.
1859 * Return value: the title for @page
1864 gtk_assistant_get_page_title (GtkAssistant *assistant,
1867 GtkAssistantPage *page_info;
1870 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1871 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1873 child = find_page (assistant, page);
1875 g_return_val_if_fail (child != NULL, NULL);
1877 page_info = (GtkAssistantPage*) child->data;
1879 return page_info->title;
1883 * gtk_assistant_set_page_type:
1884 * @assistant: a #GtkAssistant
1885 * @page: a page of @assistant
1886 * @type: the new type for @page
1888 * Sets the page type for @page.
1890 * The page type determines the page behavior in the @assistant.
1895 gtk_assistant_set_page_type (GtkAssistant *assistant,
1897 GtkAssistantPageType type)
1899 GtkAssistantPage *page_info;
1902 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1903 g_return_if_fail (GTK_IS_WIDGET (page));
1905 child = find_page (assistant, page);
1907 g_return_if_fail (child != NULL);
1909 page_info = (GtkAssistantPage*) child->data;
1911 if (type != page_info->type)
1913 page_info->type = type;
1915 /* backwards compatibility to the era before fixing bug 604289 */
1916 if (type == GTK_ASSISTANT_PAGE_SUMMARY && !page_info->complete_set)
1918 gtk_assistant_set_page_complete (assistant, page, TRUE);
1919 page_info->complete_set = FALSE;
1922 /* Always set buttons state, a change in a future page
1923 * might change current page buttons
1925 update_buttons_state (assistant);
1927 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "page-type");
1932 * gtk_assistant_get_page_type:
1933 * @assistant: a #GtkAssistant
1934 * @page: a page of @assistant
1936 * Gets the page type of @page.
1938 * Return value: the page type of @page
1942 GtkAssistantPageType
1943 gtk_assistant_get_page_type (GtkAssistant *assistant,
1946 GtkAssistantPage *page_info;
1949 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), GTK_ASSISTANT_PAGE_CONTENT);
1950 g_return_val_if_fail (GTK_IS_WIDGET (page), GTK_ASSISTANT_PAGE_CONTENT);
1952 child = find_page (assistant, page);
1954 g_return_val_if_fail (child != NULL, GTK_ASSISTANT_PAGE_CONTENT);
1956 page_info = (GtkAssistantPage*) child->data;
1958 return page_info->type;
1962 * gtk_assistant_set_page_header_image:
1963 * @assistant: a #GtkAssistant
1964 * @page: a page of @assistant
1965 * @pixbuf: (allow-none): the new header image @page
1967 * Sets a header image for @page.
1971 * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
1972 * add your header decoration to the page content instead.
1975 gtk_assistant_set_page_header_image (GtkAssistant *assistant,
1979 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1980 g_return_if_fail (GTK_IS_WIDGET (page));
1981 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1983 gtk_assistant_do_set_page_header_image (assistant, page, pixbuf);
1987 gtk_assistant_do_set_page_header_image (GtkAssistant *assistant,
1991 GtkAssistantPage *page_info;
1994 child = find_page (assistant, page);
1996 g_return_if_fail (child != NULL);
1998 page_info = (GtkAssistantPage*) child->data;
2000 if (pixbuf != page_info->header_image)
2002 if (page_info->header_image)
2004 g_object_unref (page_info->header_image);
2005 page_info->header_image = NULL;
2009 page_info->header_image = g_object_ref (pixbuf);
2011 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "header-image");
2016 * gtk_assistant_get_page_header_image:
2017 * @assistant: a #GtkAssistant
2018 * @page: a page of @assistant
2020 * Gets the header image for @page.
2022 * Return value: (transfer none): the header image for @page,
2023 * or %NULL if there's no header image for the page
2027 * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
2028 * add your header decoration to the page content instead.
2031 gtk_assistant_get_page_header_image (GtkAssistant *assistant,
2034 GtkAssistantPage *page_info;
2037 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2038 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2040 child = find_page (assistant, page);
2042 g_return_val_if_fail (child != NULL, NULL);
2044 page_info = (GtkAssistantPage*) child->data;
2046 return page_info->header_image;
2050 * gtk_assistant_set_page_side_image:
2051 * @assistant: a #GtkAssistant
2052 * @page: a page of @assistant
2053 * @pixbuf: (allow-none): the new side image @page
2055 * Sets a side image for @page.
2057 * This image used to be displayed in the side area of the assistant
2058 * when @page is the current page.
2062 * Deprecated: 3.2: Since GTK+ 3.2, sidebar images are not
2066 gtk_assistant_set_page_side_image (GtkAssistant *assistant,
2070 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2071 g_return_if_fail (GTK_IS_WIDGET (page));
2072 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2074 gtk_assistant_do_set_page_side_image (assistant, page, pixbuf);
2078 gtk_assistant_do_set_page_side_image (GtkAssistant *assistant,
2082 GtkAssistantPage *page_info;
2085 child = find_page (assistant, page);
2087 g_return_if_fail (child != NULL);
2089 page_info = (GtkAssistantPage*) child->data;
2091 if (pixbuf != page_info->sidebar_image)
2093 if (page_info->sidebar_image)
2095 g_object_unref (page_info->sidebar_image);
2096 page_info->sidebar_image = NULL;
2100 page_info->sidebar_image = g_object_ref (pixbuf);
2102 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "sidebar-image");
2107 * gtk_assistant_get_page_side_image:
2108 * @assistant: a #GtkAssistant
2109 * @page: a page of @assistant
2111 * Gets the side image for @page.
2113 * Return value: (transfer none): the side image for @page,
2114 * or %NULL if there's no side image for the page
2118 * Deprecated: 3.2: Since GTK+ 3.2, sidebar images are not
2122 gtk_assistant_get_page_side_image (GtkAssistant *assistant,
2125 GtkAssistantPage *page_info;
2128 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2129 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2131 child = find_page (assistant, page);
2133 g_return_val_if_fail (child != NULL, NULL);
2135 page_info = (GtkAssistantPage*) child->data;
2137 return page_info->sidebar_image;
2141 * gtk_assistant_set_page_complete:
2142 * @assistant: a #GtkAssistant
2143 * @page: a page of @assistant
2144 * @complete: the completeness status of the page
2146 * Sets whether @page contents are complete.
2148 * This will make @assistant update the buttons state
2149 * to be able to continue the task.
2154 gtk_assistant_set_page_complete (GtkAssistant *assistant,
2158 GtkAssistantPage *page_info;
2161 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2162 g_return_if_fail (GTK_IS_WIDGET (page));
2164 child = find_page (assistant, page);
2166 g_return_if_fail (child != NULL);
2168 page_info = (GtkAssistantPage*) child->data;
2170 if (complete != page_info->complete)
2172 page_info->complete = complete;
2173 page_info->complete_set = TRUE;
2175 /* Always set buttons state, a change in a future page
2176 * might change current page buttons
2178 update_buttons_state (assistant);
2180 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "complete");
2185 * gtk_assistant_get_page_complete:
2186 * @assistant: a #GtkAssistant
2187 * @page: a page of @assistant
2189 * Gets whether @page is complete.
2191 * Return value: %TRUE if @page is complete.
2196 gtk_assistant_get_page_complete (GtkAssistant *assistant,
2199 GtkAssistantPage *page_info;
2202 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), FALSE);
2203 g_return_val_if_fail (GTK_IS_WIDGET (page), FALSE);
2205 child = find_page (assistant, page);
2207 g_return_val_if_fail (child != NULL, FALSE);
2209 page_info = (GtkAssistantPage*) child->data;
2211 return page_info->complete;
2215 * gtk_assistant_update_buttons_state:
2216 * @assistant: a #GtkAssistant
2218 * Forces @assistant to recompute the buttons state.
2220 * GTK+ automatically takes care of this in most situations,
2221 * e.g. when the user goes to a different page, or when the
2222 * visibility or completeness of a page changes.
2224 * One situation where it can be necessary to call this
2225 * function is when changing a value on the current page
2226 * affects the future page flow of the assistant.
2231 gtk_assistant_update_buttons_state (GtkAssistant *assistant)
2233 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2235 update_buttons_state (assistant);
2239 * gtk_assistant_commit:
2240 * @assistant: a #GtkAssistant
2242 * Erases the visited page history so the back button is not
2243 * shown on the current page, and removes the cancel button
2244 * from subsequent pages.
2246 * Use this when the information provided up to the current
2247 * page is hereafter deemed permanent and cannot be modified
2248 * or undone. For example, showing a progress page to track
2249 * a long-running, unreversible operation after the user has
2250 * clicked apply on a confirmation page.
2255 gtk_assistant_commit (GtkAssistant *assistant)
2257 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2259 g_slist_free (assistant->priv->visited_pages);
2260 assistant->priv->visited_pages = NULL;
2262 assistant->priv->committed = TRUE;
2264 update_buttons_state (assistant);
2267 /* accessible implementation */
2269 /* dummy typedefs */
2270 typedef GtkWindowAccessible GtkAssistantAccessible;
2271 typedef GtkWindowAccessibleClass GtkAssistantAccessibleClass;
2273 G_DEFINE_TYPE (GtkAssistantAccessible, _gtk_assistant_accessible, GTK_TYPE_WINDOW_ACCESSIBLE);
2276 gtk_assistant_accessible_get_n_children (AtkObject *accessible)
2280 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2284 return g_list_length (GTK_ASSISTANT (widget)->priv->pages) + 1;
2288 gtk_assistant_accessible_ref_child (AtkObject *accessible,
2291 GtkAssistant *assistant;
2292 GtkAssistantPrivate *priv;
2293 GtkWidget *widget, *child;
2298 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2302 assistant = GTK_ASSISTANT (widget);
2303 priv = assistant->priv;
2304 n_pages = g_list_length (priv->pages);
2308 else if (index < n_pages)
2310 GtkAssistantPage *page = g_list_nth_data (priv->pages, index);
2313 title = gtk_assistant_get_page_title (assistant, child);
2315 else if (index == n_pages)
2317 child = priv->action_area;
2323 obj = gtk_widget_get_accessible (child);
2326 atk_object_set_name (obj, title);
2328 return g_object_ref (obj);
2332 _gtk_assistant_accessible_class_init (GtkAssistantAccessibleClass *klass)
2334 AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
2336 atk_class->get_n_children = gtk_assistant_accessible_get_n_children;
2337 atk_class->ref_child = gtk_assistant_accessible_ref_child;
2341 _gtk_assistant_accessible_init (GtkAssistantAccessible *self)
2345 /* buildable implementation */
2347 static GtkBuildableIface *parent_buildable_iface;
2350 gtk_assistant_buildable_interface_init (GtkBuildableIface *iface)
2352 parent_buildable_iface = g_type_interface_peek_parent (iface);
2353 iface->get_internal_child = gtk_assistant_buildable_get_internal_child;
2354 iface->custom_tag_start = gtk_assistant_buildable_custom_tag_start;
2355 iface->custom_finished = gtk_assistant_buildable_custom_finished;
2359 gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
2360 GtkBuilder *builder,
2361 const gchar *childname)
2363 if (strcmp (childname, "action_area") == 0)
2364 return G_OBJECT (GTK_ASSISTANT (buildable)->priv->action_area);
2366 return parent_buildable_iface->get_internal_child (buildable,
2372 gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
2373 GtkBuilder *builder,
2375 const gchar *tagname,
2376 GMarkupParser *parser,
2379 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
2380 tagname, parser, data);
2384 gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
2385 GtkBuilder *builder,
2387 const gchar *tagname,
2390 parent_buildable_iface->custom_finished (buildable, builder, child,
2391 tagname, user_data);