2 * GTK - The GIMP Toolkit
3 * Copyright (C) 1999 Red Hat, Inc.
4 * Copyright (C) 2002 Anders Carlsson <andersca@gnu.org>
5 * Copyright (C) 2003 Matthias Clasen <mclasen@redhat.com>
6 * Copyright (C) 2005 Carlos Garnacho Parro <carlosg@gnome.org>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
27 * SECTION:gtkassistant
28 * @Short_description: A widget used to guide users through multi-step operations
29 * @Title: GtkAssistant
31 * A #GtkAssistant is a widget used to represent a generally complex
32 * operation splitted in several steps, guiding the user through its pages
33 * and controlling the page flow to collect the necessary data.
35 * The design of GtkAssistant is that it controls what buttons to show and
36 * to make sensitive, based on what it knows about the page sequence and
37 * the <link linkend="GtkAssistantPageType">type</link> of each page, in
38 * addition to state information like the page
39 * <link linkend="gtk-assistant-set-page-complete">completion</link> and
40 * <link linkend="gtk-assistant-commit">committed</link> status.
42 * If you have a case that doesn't quite fit in #GtkAssistants way of
43 * handling buttons, you can use the #GTK_ASSISTANT_PAGE_CUSTOM page type
44 * and handle buttons yourself.
46 * <refsect2 id="GtkAssistant-BUILDER-UI">
47 * <title>GtkAssistant as GtkBuildable</title>
49 * The GtkAssistant implementation of the GtkBuildable interface exposes the
50 * @action_area as internal children with the name "action_area".
52 * To add pages to an assistant in GtkBuilder, simply add it as a
53 * <child> to the GtkAssistant object, and set its child properties
63 #include "gtkassistant.h"
65 #include "gtkaccessibleprivate.h"
66 #include "gtkbutton.h"
68 #include "gtkeventbox.h"
69 #include "gtknotebook.h"
72 #include "gtksizegroup.h"
73 #include "gtksizerequest.h"
75 #include "gtktypebuiltins.h"
77 #include "gtkprivate.h"
78 #include "gtkbuildable.h"
81 #define HEADER_SPACING 12
82 #define ACTION_AREA_SPACING 12
84 typedef struct _GtkAssistantPage GtkAssistantPage;
86 struct _GtkAssistantPage
88 GtkAssistantPageType type;
90 guint complete_set : 1;
95 GtkWidget *regular_title;
96 GtkWidget *current_title;
97 GdkPixbuf *header_image;
98 GdkPixbuf *sidebar_image;
101 struct _GtkAssistantPrivate
112 GtkWidget *action_area;
115 GSList *visited_pages;
116 GtkAssistantPage *current_page;
118 GtkSizeGroup *button_size_group;
119 GtkSizeGroup *title_size_group;
121 GtkAssistantPageFunc forward_function;
122 gpointer forward_function_data;
123 GDestroyNotify forward_data_destroy;
130 static void gtk_assistant_class_init (GtkAssistantClass *class);
131 static void gtk_assistant_init (GtkAssistant *assistant);
132 static void gtk_assistant_destroy (GtkWidget *widget);
133 static void gtk_assistant_map (GtkWidget *widget);
134 static void gtk_assistant_unmap (GtkWidget *widget);
135 static gboolean gtk_assistant_delete_event (GtkWidget *widget,
137 static void gtk_assistant_add (GtkContainer *container,
139 static void gtk_assistant_remove (GtkContainer *container,
141 static void gtk_assistant_set_child_property (GtkContainer *container,
146 static void gtk_assistant_get_child_property (GtkContainer *container,
152 static AtkObject *gtk_assistant_get_accessible (GtkWidget *widget);
153 static GType gtk_assistant_accessible_factory_get_type (void);
155 static void gtk_assistant_buildable_interface_init (GtkBuildableIface *iface);
156 static GObject *gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
158 const gchar *childname);
159 static gboolean gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
162 const gchar *tagname,
163 GMarkupParser *parser,
165 static void gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
168 const gchar *tagname,
171 static GList* find_page (GtkAssistant *assistant,
177 CHILD_PROP_PAGE_TYPE,
178 CHILD_PROP_PAGE_TITLE,
179 CHILD_PROP_PAGE_HEADER_IMAGE,
180 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
181 CHILD_PROP_PAGE_COMPLETE
193 static guint signals [LAST_SIGNAL] = { 0 };
196 G_DEFINE_TYPE_WITH_CODE (GtkAssistant, gtk_assistant, GTK_TYPE_WINDOW,
197 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
198 gtk_assistant_buildable_interface_init))
202 gtk_assistant_class_init (GtkAssistantClass *class)
204 GObjectClass *gobject_class;
205 GtkWidgetClass *widget_class;
206 GtkContainerClass *container_class;
208 gobject_class = (GObjectClass *) class;
209 widget_class = (GtkWidgetClass *) class;
210 container_class = (GtkContainerClass *) class;
212 widget_class->destroy = gtk_assistant_destroy;
213 widget_class->map = gtk_assistant_map;
214 widget_class->unmap = gtk_assistant_unmap;
215 widget_class->delete_event = gtk_assistant_delete_event;
216 widget_class->get_accessible = gtk_assistant_get_accessible;
218 container_class->add = gtk_assistant_add;
219 container_class->remove = gtk_assistant_remove;
220 container_class->set_child_property = gtk_assistant_set_child_property;
221 container_class->get_child_property = gtk_assistant_get_child_property;
224 * GtkAssistant::cancel:
225 * @assistant: the #GtkAssistant
227 * The ::cancel signal is emitted when then the cancel button is clicked.
232 g_signal_new (I_("cancel"),
233 G_TYPE_FROM_CLASS (gobject_class),
235 G_STRUCT_OFFSET (GtkAssistantClass, cancel),
237 g_cclosure_marshal_VOID__VOID,
241 * GtkAssistant::prepare:
242 * @assistant: the #GtkAssistant
243 * @page: the current page
245 * The ::prepare signal is emitted when a new page is set as the
246 * assistant's current page, before making the new page visible.
248 * A handler for this signal can do any preparations which are
249 * necessary before showing @page.
254 g_signal_new (I_("prepare"),
255 G_TYPE_FROM_CLASS (gobject_class),
257 G_STRUCT_OFFSET (GtkAssistantClass, prepare),
259 g_cclosure_marshal_VOID__OBJECT,
260 G_TYPE_NONE, 1, GTK_TYPE_WIDGET);
263 * GtkAssistant::apply:
264 * @assistant: the #GtkAssistant
266 * The ::apply signal is emitted when the apply button is clicked.
268 * The default behavior of the #GtkAssistant is to switch to the page
269 * after the current page, unless the current page is the last one.
271 * A handler for the ::apply signal should carry out the actions for
272 * which the wizard has collected data. If the action takes a long time
273 * to complete, you might consider putting a page of type
274 * %GTK_ASSISTANT_PAGE_PROGRESS after the confirmation page and handle
275 * this operation within the #GtkAssistant::prepare signal of the progress
281 g_signal_new (I_("apply"),
282 G_TYPE_FROM_CLASS (gobject_class),
284 G_STRUCT_OFFSET (GtkAssistantClass, apply),
286 g_cclosure_marshal_VOID__VOID,
290 * GtkAssistant::close:
291 * @assistant: the #GtkAssistant
293 * The ::close signal is emitted either when the close button of
294 * a summary page is clicked, or when the apply button in the last
295 * page in the flow (of type %GTK_ASSISTANT_PAGE_CONFIRM) is clicked.
300 g_signal_new (I_("close"),
301 G_TYPE_FROM_CLASS (gobject_class),
303 G_STRUCT_OFFSET (GtkAssistantClass, close),
305 g_cclosure_marshal_VOID__VOID,
308 gtk_widget_class_install_style_property (widget_class,
309 g_param_spec_int ("header-padding",
310 P_("Header Padding"),
311 P_("Number of pixels around the header."),
315 GTK_PARAM_READABLE));
316 gtk_widget_class_install_style_property (widget_class,
317 g_param_spec_int ("content-padding",
318 P_("Content Padding"),
319 P_("Number of pixels around the content pages."),
323 GTK_PARAM_READABLE));
326 * GtkAssistant:page-type:
328 * The type of the assistant page.
332 gtk_container_class_install_child_property (container_class,
333 CHILD_PROP_PAGE_TYPE,
334 g_param_spec_enum ("page-type",
336 P_("The type of the assistant page"),
337 GTK_TYPE_ASSISTANT_PAGE_TYPE,
338 GTK_ASSISTANT_PAGE_CONTENT,
339 GTK_PARAM_READWRITE));
342 * GtkAssistant:title:
344 * The title of the page.
348 gtk_container_class_install_child_property (container_class,
349 CHILD_PROP_PAGE_TITLE,
350 g_param_spec_string ("title",
352 P_("The title of the assistant page"),
354 GTK_PARAM_READWRITE));
357 * GtkAssistant:header-image:
359 * This image used to be displayed in the page header.
363 * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
364 * add your header decoration to the page content instead.
366 gtk_container_class_install_child_property (container_class,
367 CHILD_PROP_PAGE_HEADER_IMAGE,
368 g_param_spec_object ("header-image",
370 P_("Header image for the assistant page"),
372 GTK_PARAM_READWRITE));
375 * GtkAssistant:sidebar-image:
377 * This image used to be displayed in the 'sidebar'.
381 * Deprecated: 3.2: Since GTK+ 3.2, the sidebar image is no longer shown.
383 gtk_container_class_install_child_property (container_class,
384 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
385 g_param_spec_object ("sidebar-image",
387 P_("Sidebar image for the assistant page"),
389 GTK_PARAM_READWRITE));
392 * GtkAssistant:complete:
394 * Setting the "complete" child property to %TRUE marks a page as
395 * complete (i.e.: all the required fields are filled out). GTK+ uses
396 * this information to control the sensitivity of the navigation buttons.
400 gtk_container_class_install_child_property (container_class,
401 CHILD_PROP_PAGE_COMPLETE,
402 g_param_spec_boolean ("complete",
404 P_("Whether all required fields on the page have been filled out"),
408 g_type_class_add_private (gobject_class, sizeof (GtkAssistantPrivate));
412 default_forward_function (gint current_page, gpointer data)
414 GtkAssistant *assistant;
415 GtkAssistantPrivate *priv;
416 GtkAssistantPage *page_info;
419 assistant = GTK_ASSISTANT (data);
420 priv = assistant->priv;
422 page_node = g_list_nth (priv->pages, ++current_page);
427 page_info = (GtkAssistantPage *) page_node->data;
429 while (page_node && !gtk_widget_get_visible (page_info->page))
431 page_node = page_node->next;
435 page_info = (GtkAssistantPage *) page_node->data;
442 last_button_visible (GtkAssistant *assistant, GtkAssistantPage *page)
444 GtkAssistantPrivate *priv = assistant->priv;
445 GtkAssistantPage *page_info;
446 gint count, page_num, n_pages;
451 if (page->type != GTK_ASSISTANT_PAGE_CONTENT)
455 page_num = g_list_index (priv->pages, page);
456 n_pages = g_list_length (priv->pages);
459 while (page_num >= 0 && page_num < n_pages &&
460 page_info->type == GTK_ASSISTANT_PAGE_CONTENT &&
461 (count == 0 || page_info->complete) &&
464 page_num = (priv->forward_function) (page_num, priv->forward_function_data);
465 page_info = g_list_nth_data (priv->pages, page_num);
470 /* Make the last button visible if we can skip multiple
471 * pages and end on a confirmation or summary page
473 if (count > 1 && page_info &&
474 (page_info->type == GTK_ASSISTANT_PAGE_CONFIRM ||
475 page_info->type == GTK_ASSISTANT_PAGE_SUMMARY))
482 update_actions_size (GtkAssistant *assistant)
484 GtkAssistantPrivate *priv = assistant->priv;
486 GtkAssistantPage *page;
487 gint buttons, page_buttons;
489 if (!priv->current_page)
492 /* Some heuristics to find out how many buttons we should
493 * reserve space for. It is possible to trick this code
494 * with page forward functions and invisible pages, etc.
497 for (l = priv->pages; l; l = l->next)
501 if (!gtk_widget_get_visible (page->page))
504 page_buttons = 2; /* cancel, forward/apply/close */
505 if (l != priv->pages)
506 page_buttons += 1; /* back */
507 if (last_button_visible (assistant, page))
508 page_buttons += 1; /* last */
510 buttons = MAX (buttons, page_buttons);
513 buttons += priv->extra_buttons;
515 gtk_widget_set_size_request (priv->action_area,
516 buttons * gtk_widget_get_allocated_width (priv->cancel) + (buttons - 1) * 6,
521 compute_last_button_state (GtkAssistant *assistant)
523 GtkAssistantPrivate *priv = assistant->priv;
525 gtk_widget_set_sensitive (priv->last, priv->current_page->complete);
526 if (last_button_visible (assistant, priv->current_page))
527 gtk_widget_show (priv->last);
529 gtk_widget_hide (priv->last);
533 compute_progress_state (GtkAssistant *assistant)
535 GtkAssistantPrivate *priv = assistant->priv;
536 gint page_num, n_pages;
538 n_pages = gtk_assistant_get_n_pages (assistant);
539 page_num = gtk_assistant_get_current_page (assistant);
541 page_num = (priv->forward_function) (page_num, priv->forward_function_data);
543 if (page_num >= 0 && page_num < n_pages)
544 gtk_widget_show (priv->forward);
546 gtk_widget_hide (priv->forward);
550 update_buttons_state (GtkAssistant *assistant)
552 GtkAssistantPrivate *priv = assistant->priv;
554 if (!priv->current_page)
557 switch (priv->current_page->type)
559 case GTK_ASSISTANT_PAGE_INTRO:
560 gtk_widget_set_sensitive (priv->cancel, TRUE);
561 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
562 gtk_widget_grab_default (priv->forward);
563 gtk_widget_show (priv->forward);
564 gtk_widget_hide (priv->back);
565 gtk_widget_hide (priv->apply);
566 gtk_widget_hide (priv->close);
567 compute_last_button_state (assistant);
569 case GTK_ASSISTANT_PAGE_CONFIRM:
570 gtk_widget_set_sensitive (priv->cancel, TRUE);
571 gtk_widget_set_sensitive (priv->back, TRUE);
572 gtk_widget_set_sensitive (priv->apply, priv->current_page->complete);
573 gtk_widget_grab_default (priv->apply);
574 gtk_widget_show (priv->back);
575 gtk_widget_show (priv->apply);
576 gtk_widget_hide (priv->forward);
577 gtk_widget_hide (priv->close);
578 gtk_widget_hide (priv->last);
580 case GTK_ASSISTANT_PAGE_CONTENT:
581 gtk_widget_set_sensitive (priv->cancel, TRUE);
582 gtk_widget_set_sensitive (priv->back, TRUE);
583 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
584 gtk_widget_grab_default (priv->forward);
585 gtk_widget_show (priv->back);
586 gtk_widget_show (priv->forward);
587 gtk_widget_hide (priv->apply);
588 gtk_widget_hide (priv->close);
589 compute_last_button_state (assistant);
591 case GTK_ASSISTANT_PAGE_SUMMARY:
592 gtk_widget_set_sensitive (priv->close, priv->current_page->complete);
593 gtk_widget_grab_default (priv->close);
594 gtk_widget_show (priv->close);
595 gtk_widget_hide (priv->back);
596 gtk_widget_hide (priv->forward);
597 gtk_widget_hide (priv->apply);
598 gtk_widget_hide (priv->last);
600 case GTK_ASSISTANT_PAGE_PROGRESS:
601 gtk_widget_set_sensitive (priv->cancel, priv->current_page->complete);
602 gtk_widget_set_sensitive (priv->back, priv->current_page->complete);
603 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
604 gtk_widget_grab_default (priv->forward);
605 gtk_widget_show (priv->back);
606 gtk_widget_hide (priv->apply);
607 gtk_widget_hide (priv->close);
608 gtk_widget_hide (priv->last);
609 compute_progress_state (assistant);
611 case GTK_ASSISTANT_PAGE_CUSTOM:
612 gtk_widget_hide (priv->cancel);
613 gtk_widget_hide (priv->back);
614 gtk_widget_hide (priv->forward);
615 gtk_widget_hide (priv->apply);
616 gtk_widget_hide (priv->last);
617 gtk_widget_hide (priv->close);
620 g_assert_not_reached ();
624 gtk_widget_hide (priv->cancel);
625 else if (priv->current_page->type == GTK_ASSISTANT_PAGE_SUMMARY ||
626 priv->current_page->type == GTK_ASSISTANT_PAGE_CUSTOM)
627 gtk_widget_hide (priv->cancel);
629 gtk_widget_show (priv->cancel);
631 /* this is quite general, we don't want to
632 * go back if it's the first page
634 if (!priv->visited_pages)
635 gtk_widget_hide (priv->back);
639 update_page_title_state (GtkAssistant *assistant, GList *list)
641 GtkAssistantPage *page, *other;
642 GtkAssistantPrivate *priv = assistant->priv;
648 if (page->title == NULL || page->title[0] == 0)
651 visible = gtk_widget_get_visible (page->page);
653 if (page == priv->current_page)
655 gtk_widget_set_visible (page->regular_title, FALSE);
656 gtk_widget_set_visible (page->current_title, visible);
660 /* If multiple consecutive pages have the same title,
661 * we only show it once, since it would otherwise look
662 * silly. We have to be a little careful, since we
663 * _always_ show the title of the current page.
667 other = list->prev->data;
668 if (g_strcmp0 (page->title, other->title) == 0)
671 for (l = list->next; l; l = l->next)
674 if (g_strcmp0 (page->title, other->title) != 0)
677 if (other == priv->current_page)
684 gtk_widget_set_visible (page->regular_title, visible);
685 gtk_widget_set_visible (page->current_title, FALSE);
692 update_title_state (GtkAssistant *assistant)
694 GtkAssistantPrivate *priv = assistant->priv;
696 gboolean show_titles;
699 for (l = priv->pages; l != NULL; l = l->next)
701 if (update_page_title_state (assistant, l))
705 gtk_widget_set_visible (priv->sidebar, show_titles);
709 set_current_page (GtkAssistant *assistant,
712 GtkAssistantPrivate *priv = assistant->priv;
714 priv->current_page = (GtkAssistantPage *)g_list_nth_data (priv->pages, page_num);
716 g_signal_emit (assistant, signals [PREPARE], 0, priv->current_page->page);
718 update_title_state (assistant);
720 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->content), page_num);
722 /* update buttons state, flow may have changed */
723 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
724 update_buttons_state (assistant);
726 if (!gtk_widget_child_focus (priv->current_page->page, GTK_DIR_TAB_FORWARD))
728 GtkWidget *button[6];
731 /* find the best button to focus */
732 button[0] = priv->apply;
733 button[1] = priv->close;
734 button[2] = priv->forward;
735 button[3] = priv->back;
736 button[4] = priv->cancel;
737 button[5] = priv->last;
738 for (i = 0; i < 6; i++)
740 if (gtk_widget_get_visible (button[i]) &&
741 gtk_widget_get_sensitive (button[i]))
743 gtk_widget_grab_focus (button[i]);
749 gtk_widget_queue_resize (GTK_WIDGET (assistant));
753 compute_next_step (GtkAssistant *assistant)
755 GtkAssistantPrivate *priv = assistant->priv;
756 GtkAssistantPage *page_info;
757 gint current_page, n_pages, next_page;
759 current_page = gtk_assistant_get_current_page (assistant);
760 page_info = priv->current_page;
761 n_pages = gtk_assistant_get_n_pages (assistant);
763 next_page = (priv->forward_function) (current_page,
764 priv->forward_function_data);
766 if (next_page >= 0 && next_page < n_pages)
768 priv->visited_pages = g_slist_prepend (priv->visited_pages, page_info);
769 set_current_page (assistant, next_page);
778 on_assistant_close (GtkWidget *widget,
779 GtkAssistant *assistant)
781 g_signal_emit (assistant, signals [CLOSE], 0, NULL);
785 on_assistant_apply (GtkWidget *widget,
786 GtkAssistant *assistant)
790 g_signal_emit (assistant, signals [APPLY], 0);
792 success = compute_next_step (assistant);
794 /* if the assistant hasn't switched to another page, just emit
795 * the CLOSE signal, it't the last page in the assistant flow
798 g_signal_emit (assistant, signals [CLOSE], 0);
802 on_assistant_forward (GtkWidget *widget,
803 GtkAssistant *assistant)
805 gtk_assistant_next_page (assistant);
809 on_assistant_back (GtkWidget *widget,
810 GtkAssistant *assistant)
812 gtk_assistant_previous_page (assistant);
816 on_assistant_cancel (GtkWidget *widget,
817 GtkAssistant *assistant)
819 g_signal_emit (assistant, signals [CANCEL], 0, NULL);
823 on_assistant_last (GtkWidget *widget,
824 GtkAssistant *assistant)
826 GtkAssistantPrivate *priv = assistant->priv;
828 while (priv->current_page->type == GTK_ASSISTANT_PAGE_CONTENT &&
829 priv->current_page->complete)
830 compute_next_step (assistant);
834 alternative_button_order (GtkAssistant *assistant)
836 GtkSettings *settings;
840 screen = gtk_widget_get_screen (GTK_WIDGET (assistant));
841 settings = gtk_settings_get_for_screen (screen);
843 g_object_get (settings,
844 "gtk-alternative-button-order", &result,
850 gtk_assistant_init (GtkAssistant *assistant)
852 GtkAssistantPrivate *priv;
853 GtkStyleContext *context;
855 GtkWidget *content_box;
858 assistant->priv = G_TYPE_INSTANCE_GET_PRIVATE (assistant,
860 GtkAssistantPrivate);
861 priv = assistant->priv;
863 /* use border on inner panes instead */
864 gtk_container_set_border_width (GTK_CONTAINER (assistant), 0);
866 gtk_widget_push_composite_child ();
868 main_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
869 priv->sidebar = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
870 gtk_container_set_border_width (GTK_CONTAINER (priv->sidebar), 12);
871 /* Add an event box so we can set the background */
872 side_box = gtk_event_box_new ();
873 context = gtk_widget_get_style_context (side_box);
874 gtk_style_context_add_class (context, GTK_STYLE_CLASS_SIDEBAR);
876 content_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
877 gtk_container_set_border_width (GTK_CONTAINER (content_box), 12);
878 priv->content = gtk_notebook_new ();
879 gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->content), FALSE);
880 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->content), FALSE);
881 priv->action_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
883 gtk_container_add (GTK_CONTAINER (side_box), priv->sidebar);
884 gtk_box_pack_start (GTK_BOX (main_box), side_box, FALSE, FALSE, 0);
885 gtk_box_pack_start (GTK_BOX (main_box), content_box, TRUE, TRUE, 0);
886 gtk_box_pack_start (GTK_BOX (content_box), priv->content, TRUE, FALSE, 0);
887 gtk_box_pack_start (GTK_BOX (content_box), priv->action_area, FALSE, TRUE, 0);
888 gtk_widget_set_halign (priv->action_area, GTK_ALIGN_END);
890 gtk_widget_show_all (main_box);
892 gtk_widget_set_parent (main_box, GTK_WIDGET (assistant));
893 _gtk_bin_set_child (GTK_BIN (assistant), main_box);
895 priv->close = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
896 priv->apply = gtk_button_new_from_stock (GTK_STOCK_APPLY);
897 priv->forward = gtk_button_new_from_stock (GTK_STOCK_GO_FORWARD);
898 priv->back = gtk_button_new_from_stock (GTK_STOCK_GO_BACK);
899 priv->cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
900 priv->last = gtk_button_new_from_stock (GTK_STOCK_GOTO_LAST);
901 gtk_widget_set_can_default (priv->close, TRUE);
902 gtk_widget_set_can_default (priv->apply, TRUE);
903 gtk_widget_set_can_default (priv->forward, TRUE);
905 priv->button_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
906 gtk_size_group_add_widget (priv->button_size_group, priv->close);
907 gtk_size_group_add_widget (priv->button_size_group, priv->apply);
908 gtk_size_group_add_widget (priv->button_size_group, priv->forward);
909 gtk_size_group_add_widget (priv->button_size_group, priv->back);
910 gtk_size_group_add_widget (priv->button_size_group, priv->cancel);
911 gtk_size_group_add_widget (priv->button_size_group, priv->last);
913 if (!alternative_button_order (assistant))
915 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
916 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
917 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
918 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
919 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
920 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->close, FALSE, FALSE, 0);
924 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->close, FALSE, FALSE, 0);
925 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
926 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
927 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
928 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
929 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
932 gtk_widget_show (priv->forward);
933 gtk_widget_show (priv->back);
934 gtk_widget_show (priv->cancel);
935 gtk_widget_show (priv->action_area);
937 gtk_widget_pop_composite_child ();
939 priv->title_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
942 priv->current_page = NULL;
943 priv->visited_pages = NULL;
945 priv->forward_function = default_forward_function;
946 priv->forward_function_data = assistant;
947 priv->forward_data_destroy = NULL;
949 g_signal_connect (G_OBJECT (priv->close), "clicked",
950 G_CALLBACK (on_assistant_close), assistant);
951 g_signal_connect (G_OBJECT (priv->apply), "clicked",
952 G_CALLBACK (on_assistant_apply), assistant);
953 g_signal_connect (G_OBJECT (priv->forward), "clicked",
954 G_CALLBACK (on_assistant_forward), assistant);
955 g_signal_connect (G_OBJECT (priv->back), "clicked",
956 G_CALLBACK (on_assistant_back), assistant);
957 g_signal_connect (G_OBJECT (priv->cancel), "clicked",
958 G_CALLBACK (on_assistant_cancel), assistant);
959 g_signal_connect (G_OBJECT (priv->last), "clicked",
960 G_CALLBACK (on_assistant_last), assistant);
964 gtk_assistant_set_child_property (GtkContainer *container,
972 case CHILD_PROP_PAGE_TYPE:
973 gtk_assistant_set_page_type (GTK_ASSISTANT (container), child,
974 g_value_get_enum (value));
976 case CHILD_PROP_PAGE_TITLE:
977 gtk_assistant_set_page_title (GTK_ASSISTANT (container), child,
978 g_value_get_string (value));
980 case CHILD_PROP_PAGE_HEADER_IMAGE:
981 gtk_assistant_set_page_header_image (GTK_ASSISTANT (container), child,
982 g_value_get_object (value));
984 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
985 gtk_assistant_set_page_side_image (GTK_ASSISTANT (container), child,
986 g_value_get_object (value));
988 case CHILD_PROP_PAGE_COMPLETE:
989 gtk_assistant_set_page_complete (GTK_ASSISTANT (container), child,
990 g_value_get_boolean (value));
993 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
999 gtk_assistant_get_child_property (GtkContainer *container,
1005 switch (property_id)
1007 case CHILD_PROP_PAGE_TYPE:
1008 g_value_set_enum (value,
1009 gtk_assistant_get_page_type (GTK_ASSISTANT (container), child));
1011 case CHILD_PROP_PAGE_TITLE:
1012 g_value_set_string (value,
1013 gtk_assistant_get_page_title (GTK_ASSISTANT (container), child));
1015 case CHILD_PROP_PAGE_HEADER_IMAGE:
1016 g_value_set_object (value,
1017 gtk_assistant_get_page_header_image (GTK_ASSISTANT (container), child));
1019 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
1020 g_value_set_object (value,
1021 gtk_assistant_get_page_side_image (GTK_ASSISTANT (container), child));
1023 case CHILD_PROP_PAGE_COMPLETE:
1024 g_value_set_boolean (value,
1025 gtk_assistant_get_page_complete (GTK_ASSISTANT (container), child));
1028 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
1034 on_page_notify_visibility (GtkWidget *widget,
1038 GtkAssistant *assistant = GTK_ASSISTANT (data);
1040 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1042 update_buttons_state (assistant);
1043 update_title_state (assistant);
1048 remove_page (GtkAssistant *assistant,
1051 GtkAssistantPrivate *priv = assistant->priv;
1052 GtkAssistantPage *page_info;
1055 page_info = element->data;
1057 /* If this is the current page, we need to switch away. */
1058 if (page_info == priv->current_page)
1060 if (!compute_next_step (assistant))
1062 /* The best we can do at this point is probably to pick
1063 * the first visible page.
1065 page_node = priv->pages;
1068 !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
1069 page_node = page_node->next;
1071 if (page_node == element)
1072 page_node = page_node->next;
1075 priv->current_page = page_node->data;
1077 priv->current_page = NULL;
1081 g_signal_handlers_disconnect_by_func (page_info->page, on_page_notify_visibility, assistant);
1083 gtk_size_group_remove_widget (priv->title_size_group, page_info->regular_title);
1084 gtk_size_group_remove_widget (priv->title_size_group, page_info->current_title);
1086 gtk_container_remove (GTK_CONTAINER (priv->sidebar), page_info->regular_title);
1087 gtk_container_remove (GTK_CONTAINER (priv->sidebar), page_info->current_title);
1089 gtk_notebook_remove_page (GTK_NOTEBOOK (priv->content), gtk_notebook_page_num (GTK_NOTEBOOK (priv->content), page_info->page));
1090 priv->pages = g_list_remove_link (priv->pages, element);
1091 priv->visited_pages = g_slist_remove_all (priv->visited_pages, page_info);
1093 g_free (page_info->title);
1095 g_slice_free (GtkAssistantPage, page_info);
1096 g_list_free_1 (element);
1098 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1100 update_buttons_state (assistant);
1101 update_actions_size (assistant);
1106 gtk_assistant_destroy (GtkWidget *widget)
1108 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1109 GtkAssistantPrivate *priv = assistant->priv;
1111 /* We set current to NULL so that the remove code doesn't try
1112 * to do anything funny
1114 priv->current_page = NULL;
1117 remove_page (assistant, priv->pages);
1120 priv->sidebar = NULL;
1123 priv->content = NULL;
1125 if (priv->action_area)
1126 priv->action_area = NULL;
1128 if (priv->button_size_group)
1130 g_object_unref (priv->button_size_group);
1131 priv->button_size_group = NULL;
1134 if (priv->title_size_group)
1136 g_object_unref (priv->title_size_group);
1137 priv->title_size_group = NULL;
1140 if (priv->forward_function)
1142 if (priv->forward_function_data &&
1143 priv->forward_data_destroy)
1144 priv->forward_data_destroy (priv->forward_function_data);
1146 priv->forward_function = NULL;
1147 priv->forward_function_data = NULL;
1148 priv->forward_data_destroy = NULL;
1151 if (priv->visited_pages)
1153 g_slist_free (priv->visited_pages);
1154 priv->visited_pages = NULL;
1157 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->destroy (widget);
1161 find_page (GtkAssistant *assistant,
1164 GtkAssistantPrivate *priv = assistant->priv;
1165 GList *child = priv->pages;
1169 GtkAssistantPage *page_info = child->data;
1170 if (page_info->page == page)
1173 child = child->next;
1180 gtk_assistant_map (GtkWidget *widget)
1182 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1183 GtkAssistantPrivate *priv = assistant->priv;
1185 GtkAssistantPage *page;
1188 /* if there's no default page, pick the first one */
1191 if (!priv->current_page)
1193 page_node = priv->pages;
1195 while (page_node && !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
1197 page_node = page_node->next;
1202 page = page_node->data;
1205 if (page && gtk_widget_get_visible (page->page))
1206 set_current_page (assistant, page_num);
1208 update_buttons_state (assistant);
1209 update_actions_size (assistant);
1210 update_title_state (assistant);
1212 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->map (widget);
1216 gtk_assistant_unmap (GtkWidget *widget)
1218 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1219 GtkAssistantPrivate *priv = assistant->priv;
1221 g_slist_free (priv->visited_pages);
1222 priv->visited_pages = NULL;
1223 priv->current_page = NULL;
1225 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->unmap (widget);
1229 gtk_assistant_delete_event (GtkWidget *widget,
1232 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1233 GtkAssistantPrivate *priv = assistant->priv;
1235 /* Do not allow cancelling in the middle of a progress page */
1236 if (priv->current_page &&
1237 (priv->current_page->type != GTK_ASSISTANT_PAGE_PROGRESS ||
1238 priv->current_page->complete))
1239 g_signal_emit (widget, signals [CANCEL], 0, NULL);
1245 gtk_assistant_add (GtkContainer *container,
1248 gtk_assistant_append_page (GTK_ASSISTANT (container), page);
1252 gtk_assistant_remove (GtkContainer *container,
1255 GtkAssistant *assistant = (GtkAssistant*) container;
1258 element = find_page (assistant, page);
1262 remove_page (assistant, element);
1263 gtk_widget_queue_resize ((GtkWidget *) container);
1268 * gtk_assistant_new:
1270 * Creates a new #GtkAssistant.
1272 * Return value: a newly created #GtkAssistant
1277 gtk_assistant_new (void)
1279 GtkWidget *assistant;
1281 assistant = g_object_new (GTK_TYPE_ASSISTANT, NULL);
1287 * gtk_assistant_get_current_page:
1288 * @assistant: a #GtkAssistant
1290 * Returns the page number of the current page.
1292 * Return value: The index (starting from 0) of the current
1293 * page in the @assistant, or -1 if the @assistant has no pages,
1294 * or no current page.
1299 gtk_assistant_get_current_page (GtkAssistant *assistant)
1301 GtkAssistantPrivate *priv;
1303 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), -1);
1305 priv = assistant->priv;
1307 if (!priv->pages || !priv->current_page)
1310 return g_list_index (priv->pages, priv->current_page);
1314 * gtk_assistant_set_current_page:
1315 * @assistant: a #GtkAssistant
1316 * @page_num: index of the page to switch to, starting from 0.
1317 * If negative, the last page will be used. If greater
1318 * than the number of pages in the @assistant, nothing
1321 * Switches the page to @page_num.
1323 * Note that this will only be necessary in custom buttons,
1324 * as the @assistant flow can be set with
1325 * gtk_assistant_set_forward_page_func().
1330 gtk_assistant_set_current_page (GtkAssistant *assistant,
1333 GtkAssistantPrivate *priv;
1334 GtkAssistantPage *page;
1336 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1338 priv = assistant->priv;
1341 page = (GtkAssistantPage *) g_list_nth_data (priv->pages, page_num);
1344 page = (GtkAssistantPage *) g_list_last (priv->pages)->data;
1345 page_num = g_list_length (priv->pages);
1348 g_return_if_fail (page != NULL);
1350 if (priv->current_page == page)
1353 /* only add the page to the visited list if the assistant is mapped,
1354 * if not, just use it as an initial page setting, for the cases where
1355 * the initial page is != to 0
1357 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1358 priv->visited_pages = g_slist_prepend (priv->visited_pages,
1359 priv->current_page);
1361 set_current_page (assistant, page_num);
1365 * gtk_assistant_next_page:
1366 * @assistant: a #GtkAssistant
1368 * Navigate to the next page.
1370 * It is a programming error to call this function when
1371 * there is no next page.
1373 * This function is for use when creating pages of the
1374 * #GTK_ASSISTANT_PAGE_CUSTOM type.
1379 gtk_assistant_next_page (GtkAssistant *assistant)
1381 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1383 if (!compute_next_step (assistant))
1384 g_critical ("Page flow is broken.\n"
1385 "You may want to end it with a page of type\n"
1386 "GTK_ASSISTANT_PAGE_CONFIRM or GTK_ASSISTANT_PAGE_SUMMARY");
1390 * gtk_assistant_previous_page:
1391 * @assistant: a #GtkAssistant
1393 * Navigate to the previous visited page.
1395 * It is a programming error to call this function when
1396 * no previous page is available.
1398 * This function is for use when creating pages of the
1399 * #GTK_ASSISTANT_PAGE_CUSTOM type.
1404 gtk_assistant_previous_page (GtkAssistant *assistant)
1406 GtkAssistantPrivate *priv;
1407 GtkAssistantPage *page_info;
1410 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1412 priv = assistant->priv;
1414 /* skip the progress pages when going back */
1417 page_node = priv->visited_pages;
1419 g_return_if_fail (page_node != NULL);
1421 priv->visited_pages = priv->visited_pages->next;
1422 page_info = (GtkAssistantPage *) page_node->data;
1423 g_slist_free_1 (page_node);
1425 while (page_info->type == GTK_ASSISTANT_PAGE_PROGRESS ||
1426 !gtk_widget_get_visible (page_info->page));
1428 set_current_page (assistant, g_list_index (priv->pages, page_info));
1432 * gtk_assistant_get_n_pages:
1433 * @assistant: a #GtkAssistant
1435 * Returns the number of pages in the @assistant
1437 * Return value: the number of pages in the @assistant
1442 gtk_assistant_get_n_pages (GtkAssistant *assistant)
1444 GtkAssistantPrivate *priv;
1446 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1448 priv = assistant->priv;
1450 return g_list_length (priv->pages);
1454 * gtk_assistant_get_nth_page:
1455 * @assistant: a #GtkAssistant
1456 * @page_num: the index of a page in the @assistant,
1457 * or -1 to get the last page
1459 * Returns the child widget contained in page number @page_num.
1461 * Return value: (transfer none): the child widget, or %NULL
1462 * if @page_num is out of bounds
1467 gtk_assistant_get_nth_page (GtkAssistant *assistant,
1470 GtkAssistantPrivate *priv;
1471 GtkAssistantPage *page;
1474 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1475 g_return_val_if_fail (page_num >= -1, NULL);
1477 priv = assistant->priv;
1480 elem = g_list_last (priv->pages);
1482 elem = g_list_nth (priv->pages, page_num);
1487 page = (GtkAssistantPage *) elem->data;
1493 * gtk_assistant_prepend_page:
1494 * @assistant: a #GtkAssistant
1495 * @page: a #GtkWidget
1497 * Prepends a page to the @assistant.
1499 * Return value: the index (starting at 0) of the inserted page
1504 gtk_assistant_prepend_page (GtkAssistant *assistant,
1507 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1508 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1510 return gtk_assistant_insert_page (assistant, page, 0);
1514 * gtk_assistant_append_page:
1515 * @assistant: a #GtkAssistant
1516 * @page: a #GtkWidget
1518 * Appends a page to the @assistant.
1520 * Return value: the index (starting at 0) of the inserted page
1525 gtk_assistant_append_page (GtkAssistant *assistant,
1528 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1529 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1531 return gtk_assistant_insert_page (assistant, page, -1);
1535 * gtk_assistant_insert_page:
1536 * @assistant: a #GtkAssistant
1537 * @page: a #GtkWidget
1538 * @position: the index (starting at 0) at which to insert the page,
1539 * or -1 to append the page to the @assistant
1541 * Inserts a page in the @assistant at a given position.
1543 * Return value: the index (starting from 0) of the inserted page
1548 gtk_assistant_insert_page (GtkAssistant *assistant,
1552 GtkAssistantPrivate *priv;
1553 GtkAssistantPage *page_info;
1555 GtkStyleContext *context;
1557 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1558 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1559 g_return_val_if_fail (gtk_widget_get_parent (page) == NULL, 0);
1560 g_return_val_if_fail (!gtk_widget_is_toplevel (page), 0);
1562 priv = assistant->priv;
1564 page_info = g_slice_new0 (GtkAssistantPage);
1565 page_info->page = page;
1566 page_info->regular_title = gtk_label_new (NULL);
1567 page_info->current_title = gtk_label_new (NULL);
1569 gtk_misc_set_alignment (GTK_MISC (page_info->regular_title), 0.,0.5);
1570 gtk_widget_show (page_info->regular_title);
1572 gtk_misc_set_alignment (GTK_MISC (page_info->current_title), 0.,0.5);
1573 gtk_widget_hide (page_info->current_title);
1575 context = gtk_widget_get_style_context (page_info->current_title);
1576 gtk_style_context_add_class (context, GTK_STYLE_CLASS_HIGHLIGHT);
1577 gtk_widget_reset_style (page_info->current_title);
1579 gtk_size_group_add_widget (priv->title_size_group, page_info->regular_title);
1580 gtk_size_group_add_widget (priv->title_size_group, page_info->current_title);
1582 g_signal_connect (G_OBJECT (page), "notify::visible",
1583 G_CALLBACK (on_page_notify_visibility), assistant);
1585 n_pages = g_list_length (priv->pages);
1587 if (position < 0 || position > n_pages)
1590 priv->pages = g_list_insert (priv->pages, page_info, position);
1592 gtk_box_pack_start (GTK_BOX (priv->sidebar), page_info->regular_title, FALSE, FALSE, 0);
1593 gtk_box_pack_start (GTK_BOX (priv->sidebar), page_info->current_title, FALSE, FALSE, 0);
1594 gtk_box_reorder_child (GTK_BOX (priv->sidebar), page_info->regular_title, 2 * position);
1595 gtk_box_reorder_child (GTK_BOX (priv->sidebar), page_info->current_title, 2 * position + 1);
1597 gtk_notebook_insert_page (GTK_NOTEBOOK (priv->content), page, NULL, position);
1599 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1601 update_buttons_state (assistant);
1602 update_actions_size (assistant);
1609 * gtk_assistant_set_forward_page_func:
1610 * @assistant: a #GtkAssistant
1611 * @page_func: (allow-none): the #GtkAssistantPageFunc, or %NULL
1612 * to use the default one
1613 * @data: user data for @page_func
1614 * @destroy: destroy notifier for @data
1616 * Sets the page forwarding function to be @page_func.
1618 * This function will be used to determine what will be
1619 * the next page when the user presses the forward button.
1620 * Setting @page_func to %NULL will make the assistant to
1621 * use the default forward function, which just goes to the
1622 * next visible page.
1627 gtk_assistant_set_forward_page_func (GtkAssistant *assistant,
1628 GtkAssistantPageFunc page_func,
1630 GDestroyNotify destroy)
1632 GtkAssistantPrivate *priv;
1634 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1636 priv = assistant->priv;
1638 if (priv->forward_data_destroy &&
1639 priv->forward_function_data)
1640 (*priv->forward_data_destroy) (priv->forward_function_data);
1644 priv->forward_function = page_func;
1645 priv->forward_function_data = data;
1646 priv->forward_data_destroy = destroy;
1650 priv->forward_function = default_forward_function;
1651 priv->forward_function_data = assistant;
1652 priv->forward_data_destroy = NULL;
1655 /* Page flow has possibly changed, so the
1656 * buttons state might need to change too
1658 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1659 update_buttons_state (assistant);
1663 * gtk_assistant_add_action_widget:
1664 * @assistant: a #GtkAssistant
1665 * @child: a #GtkWidget
1667 * Adds a widget to the action area of a #GtkAssistant.
1672 gtk_assistant_add_action_widget (GtkAssistant *assistant,
1675 GtkAssistantPrivate *priv;
1677 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1678 g_return_if_fail (GTK_IS_WIDGET (child));
1680 priv = assistant->priv;
1682 if (GTK_IS_BUTTON (child))
1684 gtk_size_group_add_widget (priv->button_size_group, child);
1685 priv->extra_buttons += 1;
1686 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1687 update_actions_size (assistant);
1690 gtk_box_pack_end (GTK_BOX (priv->action_area), child, FALSE, FALSE, 0);
1694 * gtk_assistant_remove_action_widget:
1695 * @assistant: a #GtkAssistant
1696 * @child: a #GtkWidget
1698 * Removes a widget from the action area of a #GtkAssistant.
1703 gtk_assistant_remove_action_widget (GtkAssistant *assistant,
1706 GtkAssistantPrivate *priv;
1708 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1709 g_return_if_fail (GTK_IS_WIDGET (child));
1711 priv = assistant->priv;
1713 if (GTK_IS_BUTTON (child))
1715 gtk_size_group_remove_widget (priv->button_size_group, child);
1716 priv->extra_buttons -= 1;
1717 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1718 update_actions_size (assistant);
1721 gtk_container_remove (GTK_CONTAINER (priv->action_area), child);
1725 * gtk_assistant_set_page_title:
1726 * @assistant: a #GtkAssistant
1727 * @page: a page of @assistant
1728 * @title: the new title for @page
1730 * Sets a title for @page.
1732 * The title is displayed in the header area of the assistant
1733 * when @page is the current page.
1738 gtk_assistant_set_page_title (GtkAssistant *assistant,
1742 GtkAssistantPage *page_info;
1745 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1746 g_return_if_fail (GTK_IS_WIDGET (page));
1748 child = find_page (assistant, page);
1750 g_return_if_fail (child != NULL);
1752 page_info = (GtkAssistantPage*) child->data;
1754 g_free (page_info->title);
1755 page_info->title = g_strdup (title);
1757 gtk_label_set_text ((GtkLabel*) page_info->regular_title, title);
1758 gtk_label_set_text ((GtkLabel*) page_info->current_title, title);
1760 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1761 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "title");
1765 * gtk_assistant_get_page_title:
1766 * @assistant: a #GtkAssistant
1767 * @page: a page of @assistant
1769 * Gets the title for @page.
1771 * Return value: the title for @page
1775 G_CONST_RETURN gchar*
1776 gtk_assistant_get_page_title (GtkAssistant *assistant,
1779 GtkAssistantPage *page_info;
1782 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1783 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1785 child = find_page (assistant, page);
1787 g_return_val_if_fail (child != NULL, NULL);
1789 page_info = (GtkAssistantPage*) child->data;
1791 return page_info->title;
1795 * gtk_assistant_set_page_type:
1796 * @assistant: a #GtkAssistant
1797 * @page: a page of @assistant
1798 * @type: the new type for @page
1800 * Sets the page type for @page.
1802 * The page type determines the page behavior in the @assistant.
1807 gtk_assistant_set_page_type (GtkAssistant *assistant,
1809 GtkAssistantPageType type)
1811 GtkAssistantPage *page_info;
1814 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1815 g_return_if_fail (GTK_IS_WIDGET (page));
1817 child = find_page (assistant, page);
1819 g_return_if_fail (child != NULL);
1821 page_info = (GtkAssistantPage*) child->data;
1823 if (type != page_info->type)
1825 page_info->type = type;
1827 /* backwards compatibility to the era before fixing bug 604289 */
1828 if (type == GTK_ASSISTANT_PAGE_SUMMARY && !page_info->complete_set)
1830 gtk_assistant_set_page_complete (assistant, page, TRUE);
1831 page_info->complete_set = FALSE;
1834 /* Always set buttons state, a change in a future page
1835 * might change current page buttons
1837 update_buttons_state (assistant);
1839 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "page-type");
1844 * gtk_assistant_get_page_type:
1845 * @assistant: a #GtkAssistant
1846 * @page: a page of @assistant
1848 * Gets the page type of @page.
1850 * Return value: the page type of @page
1854 GtkAssistantPageType
1855 gtk_assistant_get_page_type (GtkAssistant *assistant,
1858 GtkAssistantPage *page_info;
1861 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), GTK_ASSISTANT_PAGE_CONTENT);
1862 g_return_val_if_fail (GTK_IS_WIDGET (page), GTK_ASSISTANT_PAGE_CONTENT);
1864 child = find_page (assistant, page);
1866 g_return_val_if_fail (child != NULL, GTK_ASSISTANT_PAGE_CONTENT);
1868 page_info = (GtkAssistantPage*) child->data;
1870 return page_info->type;
1874 * gtk_assistant_set_page_header_image:
1875 * @assistant: a #GtkAssistant
1876 * @page: a page of @assistant
1877 * @pixbuf: (allow-none): the new header image @page
1879 * Sets a header image for @page.
1883 * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
1884 * add your header decoration to the page content instead.
1887 gtk_assistant_set_page_header_image (GtkAssistant *assistant,
1891 GtkAssistantPage *page_info;
1894 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1895 g_return_if_fail (GTK_IS_WIDGET (page));
1896 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1898 child = find_page (assistant, page);
1900 g_return_if_fail (child != NULL);
1902 page_info = (GtkAssistantPage*) child->data;
1904 if (pixbuf != page_info->header_image)
1906 if (page_info->header_image)
1908 g_object_unref (page_info->header_image);
1909 page_info->header_image = NULL;
1913 page_info->header_image = g_object_ref (pixbuf);
1915 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "header-image");
1920 * gtk_assistant_get_page_header_image:
1921 * @assistant: a #GtkAssistant
1922 * @page: a page of @assistant
1924 * Gets the header image for @page.
1926 * Return value: (transfer none): the header image for @page,
1927 * or %NULL if there's no header image for the page
1931 * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
1932 * add your header decoration to the page content instead.
1935 gtk_assistant_get_page_header_image (GtkAssistant *assistant,
1938 GtkAssistantPage *page_info;
1941 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1942 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1944 child = find_page (assistant, page);
1946 g_return_val_if_fail (child != NULL, NULL);
1948 page_info = (GtkAssistantPage*) child->data;
1950 return page_info->header_image;
1954 * gtk_assistant_set_page_side_image:
1955 * @assistant: a #GtkAssistant
1956 * @page: a page of @assistant
1957 * @pixbuf: (allow-none): the new side image @page
1959 * Sets a side image for @page.
1961 * This image used to be displayed in the side area of the assistant
1962 * when @page is the current page.
1966 * Deprecated: 3.2: Since GTK+ 3.2, sidebar images are not
1970 gtk_assistant_set_page_side_image (GtkAssistant *assistant,
1974 GtkAssistantPage *page_info;
1977 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1978 g_return_if_fail (GTK_IS_WIDGET (page));
1979 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1981 child = find_page (assistant, page);
1983 g_return_if_fail (child != NULL);
1985 page_info = (GtkAssistantPage*) child->data;
1987 if (pixbuf != page_info->sidebar_image)
1989 if (page_info->sidebar_image)
1991 g_object_unref (page_info->sidebar_image);
1992 page_info->sidebar_image = NULL;
1996 page_info->sidebar_image = g_object_ref (pixbuf);
1998 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "sidebar-image");
2003 * gtk_assistant_get_page_side_image:
2004 * @assistant: a #GtkAssistant
2005 * @page: a page of @assistant
2007 * Gets the side image for @page.
2009 * Return value: (transfer none): the side image for @page,
2010 * or %NULL if there's no side image for the page
2014 * Deprecated: 3.2: Since GTK+ 3.2, sidebar images are not
2018 gtk_assistant_get_page_side_image (GtkAssistant *assistant,
2021 GtkAssistantPage *page_info;
2024 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2025 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2027 child = find_page (assistant, page);
2029 g_return_val_if_fail (child != NULL, NULL);
2031 page_info = (GtkAssistantPage*) child->data;
2033 return page_info->sidebar_image;
2037 * gtk_assistant_set_page_complete:
2038 * @assistant: a #GtkAssistant
2039 * @page: a page of @assistant
2040 * @complete: the completeness status of the page
2042 * Sets whether @page contents are complete.
2044 * This will make @assistant update the buttons state
2045 * to be able to continue the task.
2050 gtk_assistant_set_page_complete (GtkAssistant *assistant,
2054 GtkAssistantPage *page_info;
2057 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2058 g_return_if_fail (GTK_IS_WIDGET (page));
2060 child = find_page (assistant, page);
2062 g_return_if_fail (child != NULL);
2064 page_info = (GtkAssistantPage*) child->data;
2066 if (complete != page_info->complete)
2068 page_info->complete = complete;
2069 page_info->complete_set = TRUE;
2071 /* Always set buttons state, a change in a future page
2072 * might change current page buttons
2074 update_buttons_state (assistant);
2076 gtk_container_child_notify (GTK_CONTAINER (assistant), page, "complete");
2081 * gtk_assistant_get_page_complete:
2082 * @assistant: a #GtkAssistant
2083 * @page: a page of @assistant
2085 * Gets whether @page is complete.
2087 * Return value: %TRUE if @page is complete.
2092 gtk_assistant_get_page_complete (GtkAssistant *assistant,
2095 GtkAssistantPage *page_info;
2098 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), FALSE);
2099 g_return_val_if_fail (GTK_IS_WIDGET (page), FALSE);
2101 child = find_page (assistant, page);
2103 g_return_val_if_fail (child != NULL, FALSE);
2105 page_info = (GtkAssistantPage*) child->data;
2107 return page_info->complete;
2111 * gtk_assistant_update_buttons_state:
2112 * @assistant: a #GtkAssistant
2114 * Forces @assistant to recompute the buttons state.
2116 * GTK+ automatically takes care of this in most situations,
2117 * e.g. when the user goes to a different page, or when the
2118 * visibility or completeness of a page changes.
2120 * One situation where it can be necessary to call this
2121 * function is when changing a value on the current page
2122 * affects the future page flow of the assistant.
2127 gtk_assistant_update_buttons_state (GtkAssistant *assistant)
2129 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2131 update_buttons_state (assistant);
2135 * gtk_assistant_commit:
2136 * @assistant: a #GtkAssistant
2138 * Erases the visited page history so the back button is not
2139 * shown on the current page, and removes the cancel button
2140 * from subsequent pages.
2142 * Use this when the information provided up to the current
2143 * page is hereafter deemed permanent and cannot be modified
2144 * or undone. For example, showing a progress page to track
2145 * a long-running, unreversible operation after the user has
2146 * clicked apply on a confirmation page.
2151 gtk_assistant_commit (GtkAssistant *assistant)
2153 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2155 g_slist_free (assistant->priv->visited_pages);
2156 assistant->priv->visited_pages = NULL;
2158 assistant->priv->committed = TRUE;
2160 update_buttons_state (assistant);
2164 gtk_assistant_get_accessible (GtkWidget *widget)
2166 static gboolean first_time = TRUE;
2170 _gtk_accessible_set_factory_type (GTK_TYPE_ASSISTANT,
2171 gtk_assistant_accessible_factory_get_type ());
2176 return GTK_WIDGET_CLASS (gtk_assistant_parent_class)->get_accessible (widget);
2179 /* accessible implementation */
2181 /* dummy typedefs */
2182 typedef struct _GtkAssistantAccessible GtkAssistantAccessible;
2183 typedef struct _GtkAssistantAccessibleClass GtkAssistantAccessibleClass;
2185 ATK_DEFINE_TYPE (GtkAssistantAccessible, _gtk_assistant_accessible, GTK_TYPE_ASSISTANT);
2188 gtk_assistant_accessible_get_n_children (AtkObject *accessible)
2192 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2196 return g_list_length (GTK_ASSISTANT (widget)->priv->pages) + 1;
2200 gtk_assistant_accessible_ref_child (AtkObject *accessible,
2203 GtkAssistant *assistant;
2204 GtkAssistantPrivate *priv;
2205 GtkWidget *widget, *child;
2210 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2214 assistant = GTK_ASSISTANT (widget);
2215 priv = assistant->priv;
2216 n_pages = g_list_length (priv->pages);
2220 else if (index < n_pages)
2222 GtkAssistantPage *page = g_list_nth_data (priv->pages, index);
2225 title = gtk_assistant_get_page_title (assistant, child);
2227 else if (index == n_pages)
2229 child = priv->action_area;
2235 obj = gtk_widget_get_accessible (child);
2238 atk_object_set_name (obj, title);
2240 return g_object_ref (obj);
2244 _gtk_assistant_accessible_class_init (GtkAssistantAccessibleClass *klass)
2246 AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
2248 atk_class->get_n_children = gtk_assistant_accessible_get_n_children;
2249 atk_class->ref_child = gtk_assistant_accessible_ref_child;
2253 _gtk_assistant_accessible_init (GtkAssistantAccessible *self)
2258 typedef AtkObjectFactory GtkAssistantAccessibleFactory;
2259 typedef AtkObjectFactoryClass GtkAssistantAccessibleFactoryClass;
2261 G_DEFINE_TYPE (GtkAssistantAccessibleFactory,
2262 gtk_assistant_accessible_factory,
2263 ATK_TYPE_OBJECT_FACTORY);
2266 gtk_assistant_accessible_factory_get_accessible_type (void)
2268 return _gtk_assistant_accessible_get_type ();
2272 gtk_assistant_accessible_factory_create_accessible (GObject *obj)
2274 AtkObject *accessible;
2276 accessible = g_object_new (_gtk_assistant_accessible_get_type (), NULL);
2277 atk_object_initialize (accessible, obj);
2283 gtk_assistant_accessible_factory_class_init (AtkObjectFactoryClass *class)
2285 class->create_accessible = gtk_assistant_accessible_factory_create_accessible;
2286 class->get_accessible_type = gtk_assistant_accessible_factory_get_accessible_type;
2290 gtk_assistant_accessible_factory_init (AtkObjectFactory *factory)
2294 /* buildable implementation */
2296 static GtkBuildableIface *parent_buildable_iface;
2299 gtk_assistant_buildable_interface_init (GtkBuildableIface *iface)
2301 parent_buildable_iface = g_type_interface_peek_parent (iface);
2302 iface->get_internal_child = gtk_assistant_buildable_get_internal_child;
2303 iface->custom_tag_start = gtk_assistant_buildable_custom_tag_start;
2304 iface->custom_finished = gtk_assistant_buildable_custom_finished;
2308 gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
2309 GtkBuilder *builder,
2310 const gchar *childname)
2312 if (strcmp (childname, "action_area") == 0)
2313 return G_OBJECT (GTK_ASSISTANT (buildable)->priv->action_area);
2315 return parent_buildable_iface->get_internal_child (buildable,
2321 gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
2322 GtkBuilder *builder,
2324 const gchar *tagname,
2325 GMarkupParser *parser,
2328 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
2329 tagname, parser, data);
2333 gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
2334 GtkBuilder *builder,
2336 const gchar *tagname,
2339 parent_buildable_iface->custom_finished (buildable, builder, child,
2340 tagname, user_data);