]> Pileus Git - ~andy/gtk/blob - gtk/gtkassistant.c
gtk/gtkassistant: gtk_misc_set_alignment replacing
[~andy/gtk] / gtk / gtkassistant.c
1 /*
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>
7  *
8  * All rights reserved.
9  *
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.
14  *
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.
19  *
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.
24  */
25
26 /**
27  * SECTION:gtkassistant
28  * @Short_description: A widget used to guide users through multi-step operations
29  * @Title: GtkAssistant
30  *
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.
34  *
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.
41  *
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.
45  *
46  * <refsect2 id="GtkAssistant-BUILDER-UI">
47  * <title>GtkAssistant as GtkBuildable</title>
48  * <para>
49  * The GtkAssistant implementation of the GtkBuildable interface exposes the
50  * @action_area as internal children with the name "action_area".
51  *
52  * To add pages to an assistant in GtkBuilder, simply add it as a
53  * &lt;child&gt; to the GtkAssistant object, and set its child properties
54  * as necessary.
55  * </para>
56  * </refsect2>
57  */
58
59 #include "config.h"
60
61 #include <atk/atk.h>
62
63 #include "gtkassistant.h"
64
65 #include "gtkaccessibleprivate.h"
66 #include "gtkbutton.h"
67 #include "gtkbox.h"
68 #include "gtkframe.h"
69 #include "gtknotebook.h"
70 #include "gtkimage.h"
71 #include "gtklabel.h"
72 #include "gtksizegroup.h"
73 #include "gtksizerequest.h"
74 #include "gtkstock.h"
75 #include "gtktypebuiltins.h"
76 #include "gtkintl.h"
77 #include "gtkprivate.h"
78 #include "gtkbuildable.h"
79
80
81 #define HEADER_SPACING 12
82 #define ACTION_AREA_SPACING 12
83
84 typedef struct _GtkAssistantPage GtkAssistantPage;
85
86 struct _GtkAssistantPage
87 {
88   GtkAssistantPageType type;
89   guint      complete     : 1;
90   guint      complete_set : 1;
91
92   gchar *title;
93
94   GtkWidget *page;
95   GtkWidget *regular_title;
96   GtkWidget *current_title;
97   GdkPixbuf *header_image;
98   GdkPixbuf *sidebar_image;
99 };
100
101 struct _GtkAssistantPrivate
102 {
103   GtkWidget *cancel;
104   GtkWidget *forward;
105   GtkWidget *back;
106   GtkWidget *apply;
107   GtkWidget *close;
108   GtkWidget *last;
109
110   GtkWidget *sidebar;
111   GtkWidget *content;
112   GtkWidget *action_area;
113
114   GList     *pages;
115   GSList    *visited_pages;
116   GtkAssistantPage *current_page;
117
118   GtkSizeGroup *button_size_group;
119   GtkSizeGroup *title_size_group;
120
121   GtkAssistantPageFunc forward_function;
122   gpointer forward_function_data;
123   GDestroyNotify forward_data_destroy;
124
125   gint extra_buttons;
126
127   guint committed : 1;
128 };
129
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,
136                                                   GdkEventAny       *event);
137 static void     gtk_assistant_add                (GtkContainer      *container,
138                                                   GtkWidget         *page);
139 static void     gtk_assistant_remove             (GtkContainer      *container,
140                                                   GtkWidget         *page);
141 static void     gtk_assistant_set_child_property (GtkContainer      *container,
142                                                   GtkWidget         *child,
143                                                   guint              property_id,
144                                                   const GValue      *value,
145                                                   GParamSpec        *pspec);
146 static void     gtk_assistant_get_child_property (GtkContainer      *container,
147                                                   GtkWidget         *child,
148                                                   guint              property_id,
149                                                   GValue            *value,
150                                                   GParamSpec        *pspec);
151
152 static AtkObject *gtk_assistant_get_accessible   (GtkWidget         *widget);
153 static GType      gtk_assistant_accessible_factory_get_type  (void);
154
155 static void       gtk_assistant_buildable_interface_init     (GtkBuildableIface *iface);
156 static GObject   *gtk_assistant_buildable_get_internal_child (GtkBuildable  *buildable,
157                                                               GtkBuilder    *builder,
158                                                               const gchar   *childname);
159 static gboolean   gtk_assistant_buildable_custom_tag_start   (GtkBuildable  *buildable,
160                                                               GtkBuilder    *builder,
161                                                               GObject       *child,
162                                                               const gchar   *tagname,
163                                                               GMarkupParser *parser,
164                                                               gpointer      *data);
165 static void       gtk_assistant_buildable_custom_finished    (GtkBuildable  *buildable,
166                                                               GtkBuilder    *builder,
167                                                               GObject       *child,
168                                                               const gchar   *tagname,
169                                                               gpointer       user_data);
170
171 static GList*     find_page                                  (GtkAssistant  *assistant,
172                                                               GtkWidget     *page);
173
174 enum
175 {
176   CHILD_PROP_0,
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
182 };
183
184 enum
185 {
186   CANCEL,
187   PREPARE,
188   APPLY,
189   CLOSE,
190   LAST_SIGNAL
191 };
192
193 static guint signals [LAST_SIGNAL] = { 0 };
194
195
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))
199
200
201 static void
202 gtk_assistant_class_init (GtkAssistantClass *class)
203 {
204   GObjectClass *gobject_class;
205   GtkWidgetClass *widget_class;
206   GtkContainerClass *container_class;
207
208   gobject_class   = (GObjectClass *) class;
209   widget_class    = (GtkWidgetClass *) class;
210   container_class = (GtkContainerClass *) class;
211
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;
217
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;
222
223   /**
224    * GtkAssistant::cancel:
225    * @assistant: the #GtkAssistant
226    *
227    * The ::cancel signal is emitted when then the cancel button is clicked.
228    *
229    * Since: 2.10
230    */
231   signals[CANCEL] =
232     g_signal_new (I_("cancel"),
233                   G_TYPE_FROM_CLASS (gobject_class),
234                   G_SIGNAL_RUN_LAST,
235                   G_STRUCT_OFFSET (GtkAssistantClass, cancel),
236                   NULL, NULL,
237                   g_cclosure_marshal_VOID__VOID,
238                   G_TYPE_NONE, 0);
239
240   /**
241    * GtkAssistant::prepare:
242    * @assistant: the #GtkAssistant
243    * @page: the current page
244    *
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.
247    *
248    * A handler for this signal can do any preparations which are
249    * necessary before showing @page.
250    *
251    * Since: 2.10
252    */
253   signals[PREPARE] =
254     g_signal_new (I_("prepare"),
255                   G_TYPE_FROM_CLASS (gobject_class),
256                   G_SIGNAL_RUN_LAST,
257                   G_STRUCT_OFFSET (GtkAssistantClass, prepare),
258                   NULL, NULL,
259                   g_cclosure_marshal_VOID__OBJECT,
260                   G_TYPE_NONE, 1, GTK_TYPE_WIDGET);
261
262   /**
263    * GtkAssistant::apply:
264    * @assistant: the #GtkAssistant
265    *
266    * The ::apply signal is emitted when the apply button is clicked.
267    *
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.
270    *
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
276    * page.
277    *
278    * Since: 2.10
279    */
280   signals[APPLY] =
281     g_signal_new (I_("apply"),
282                   G_TYPE_FROM_CLASS (gobject_class),
283                   G_SIGNAL_RUN_LAST,
284                   G_STRUCT_OFFSET (GtkAssistantClass, apply),
285                   NULL, NULL,
286                   g_cclosure_marshal_VOID__VOID,
287                   G_TYPE_NONE, 0);
288
289   /**
290    * GtkAssistant::close:
291    * @assistant: the #GtkAssistant
292    *
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.
296    *
297    * Since: 2.10
298    */
299   signals[CLOSE] =
300     g_signal_new (I_("close"),
301                   G_TYPE_FROM_CLASS (gobject_class),
302                   G_SIGNAL_RUN_LAST,
303                   G_STRUCT_OFFSET (GtkAssistantClass, close),
304                   NULL, NULL,
305                   g_cclosure_marshal_VOID__VOID,
306                   G_TYPE_NONE, 0);
307
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."),
312                                                              0,
313                                                              G_MAXINT,
314                                                              6,
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."),
320                                                              0,
321                                                              G_MAXINT,
322                                                              1,
323                                                              GTK_PARAM_READABLE));
324
325   /**
326    * GtkAssistant:page-type:
327    *
328    * The type of the assistant page.
329    *
330    * Since: 2.10
331    */
332   gtk_container_class_install_child_property (container_class,
333                                               CHILD_PROP_PAGE_TYPE,
334                                               g_param_spec_enum ("page-type",
335                                                                  P_("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));
340
341   /**
342    * GtkAssistant:title:
343    *
344    * The title of the page.
345    *
346    * Since: 2.10
347    */
348   gtk_container_class_install_child_property (container_class,
349                                               CHILD_PROP_PAGE_TITLE,
350                                               g_param_spec_string ("title",
351                                                                    P_("Page title"),
352                                                                    P_("The title of the assistant page"),
353                                                                    NULL,
354                                                                    GTK_PARAM_READWRITE));
355
356   /**
357    * GtkAssistant:header-image:
358    *
359    * This image used to be displayed in the page header.
360    *
361    * Since: 2.10
362    *
363    * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
364    *     add your header decoration to the page content instead.
365    */
366   gtk_container_class_install_child_property (container_class,
367                                               CHILD_PROP_PAGE_HEADER_IMAGE,
368                                               g_param_spec_object ("header-image",
369                                                                    P_("Header image"),
370                                                                    P_("Header image for the assistant page"),
371                                                                    GDK_TYPE_PIXBUF,
372                                                                    GTK_PARAM_READWRITE));
373
374   /**
375    * GtkAssistant:sidebar-image:
376    *
377    * This image used to be displayed in the 'sidebar'.
378    *
379    * Since: 2.10
380    *
381    * Deprecated: 3.2: Since GTK+ 3.2, the sidebar image is no longer shown.
382    */
383   gtk_container_class_install_child_property (container_class,
384                                               CHILD_PROP_PAGE_SIDEBAR_IMAGE,
385                                               g_param_spec_object ("sidebar-image",
386                                                                    P_("Sidebar image"),
387                                                                    P_("Sidebar image for the assistant page"),
388                                                                    GDK_TYPE_PIXBUF,
389                                                                    GTK_PARAM_READWRITE));
390
391   /**
392    * GtkAssistant:complete:
393    *
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.
397    *
398    * Since: 2.10
399    */
400   gtk_container_class_install_child_property (container_class,
401                                               CHILD_PROP_PAGE_COMPLETE,
402                                               g_param_spec_boolean ("complete",
403                                                                     P_("Page complete"),
404                                                                     P_("Whether all required fields on the page have been filled out"),
405                                                                     FALSE,
406                                                                     G_PARAM_READWRITE));
407
408   g_type_class_add_private (gobject_class, sizeof (GtkAssistantPrivate));
409 }
410
411 static gint
412 default_forward_function (gint current_page, gpointer data)
413 {
414   GtkAssistant *assistant;
415   GtkAssistantPrivate *priv;
416   GtkAssistantPage *page_info;
417   GList *page_node;
418
419   assistant = GTK_ASSISTANT (data);
420   priv = assistant->priv;
421
422   page_node = g_list_nth (priv->pages, ++current_page);
423
424   if (!page_node)
425     return -1;
426
427   page_info = (GtkAssistantPage *) page_node->data;
428
429   while (page_node && !gtk_widget_get_visible (page_info->page))
430     {
431       page_node = page_node->next;
432       current_page++;
433
434       if (page_node)
435         page_info = (GtkAssistantPage *) page_node->data;
436     }
437
438   return current_page;
439 }
440
441 static gboolean
442 last_button_visible (GtkAssistant *assistant, GtkAssistantPage *page)
443 {
444   GtkAssistantPrivate *priv = assistant->priv;
445   GtkAssistantPage *page_info;
446   gint count, page_num, n_pages;
447
448   if (page == NULL)
449     return FALSE;
450
451   if (page->type != GTK_ASSISTANT_PAGE_CONTENT)
452     return FALSE;
453
454   count = 0;
455   page_num = g_list_index (priv->pages, page);
456   n_pages  = g_list_length (priv->pages);
457   page_info = page;
458
459   while (page_num >= 0 && page_num < n_pages &&
460          page_info->type == GTK_ASSISTANT_PAGE_CONTENT &&
461          (count == 0 || page_info->complete) &&
462          count < n_pages)
463     {
464       page_num = (priv->forward_function) (page_num, priv->forward_function_data);
465       page_info = g_list_nth_data (priv->pages, page_num);
466
467       count++;
468     }
469
470   /* Make the last button visible if we can skip multiple
471    * pages and end on a confirmation or summary page
472    */
473   if (count > 1 && page_info &&
474       (page_info->type == GTK_ASSISTANT_PAGE_CONFIRM ||
475        page_info->type == GTK_ASSISTANT_PAGE_SUMMARY))
476     return TRUE;
477   else
478     return FALSE;
479 }
480
481 static void
482 update_actions_size (GtkAssistant *assistant)
483 {
484   GtkAssistantPrivate *priv = assistant->priv;
485   GList *l;
486   GtkAssistantPage *page;
487   gint buttons, page_buttons;
488
489   if (!priv->current_page)
490     return;
491
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.
495    */
496   buttons = 0;
497   for (l = priv->pages; l; l = l->next)
498     {
499       page = l->data;
500
501       if (!gtk_widget_get_visible (page->page))
502         continue;
503
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 */
509
510       buttons = MAX (buttons, page_buttons);
511     }
512
513   buttons += priv->extra_buttons;
514
515   gtk_widget_set_size_request (priv->action_area,
516                                buttons * gtk_widget_get_allocated_width (priv->cancel) + (buttons - 1) * 6,
517                                -1);
518 }
519
520 static void
521 compute_last_button_state (GtkAssistant *assistant)
522 {
523   GtkAssistantPrivate *priv = assistant->priv;
524
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);
528   else
529     gtk_widget_hide (priv->last);
530 }
531
532 static void
533 compute_progress_state (GtkAssistant *assistant)
534 {
535   GtkAssistantPrivate *priv = assistant->priv;
536   gint page_num, n_pages;
537
538   n_pages = gtk_assistant_get_n_pages (assistant);
539   page_num = gtk_assistant_get_current_page (assistant);
540
541   page_num = (priv->forward_function) (page_num, priv->forward_function_data);
542
543   if (page_num >= 0 && page_num < n_pages)
544     gtk_widget_show (priv->forward);
545   else
546     gtk_widget_hide (priv->forward);
547 }
548
549 static void
550 update_buttons_state (GtkAssistant *assistant)
551 {
552   GtkAssistantPrivate *priv = assistant->priv;
553
554   if (!priv->current_page)
555     return;
556
557   switch (priv->current_page->type)
558     {
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);
568       break;
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);
579       break;
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);
590       break;
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);
599       break;
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);
610       break;
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);
618       break;
619     default:
620       g_assert_not_reached ();
621     }
622
623   if (priv->committed)
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);
628   else
629     gtk_widget_show (priv->cancel);
630
631   /* this is quite general, we don't want to
632    * go back if it's the first page
633    */
634   if (!priv->visited_pages)
635     gtk_widget_hide (priv->back);
636 }
637
638 static gboolean
639 update_page_title_state (GtkAssistant *assistant, GList *list)
640 {
641   GtkAssistantPage *page, *other;
642   GtkAssistantPrivate *priv = assistant->priv;
643   gboolean visible;
644   GList *l;
645
646   page = list->data;
647
648   if (page->title == NULL || page->title[0] == 0)
649     visible = FALSE;
650   else
651     visible = gtk_widget_get_visible (page->page);
652
653   if (page == priv->current_page)
654     {
655       gtk_widget_set_visible (page->regular_title, FALSE);
656       gtk_widget_set_visible (page->current_title, visible);
657     }
658   else
659     {
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.
664        */
665       if (list->prev)
666         {
667           other = list->prev->data;
668           if (g_strcmp0 (page->title, other->title) == 0)
669             visible = FALSE;
670         }
671       for (l = list->next; l; l = l->next)
672         {
673           other = l->data;
674           if (g_strcmp0 (page->title, other->title) != 0)
675             break;
676
677           if (other == priv->current_page)
678             {
679               visible = FALSE;
680               break;
681             }
682         }
683
684       gtk_widget_set_visible (page->regular_title, visible);
685       gtk_widget_set_visible (page->current_title, FALSE);
686     }
687
688   return visible;
689 }
690
691 static void
692 update_title_state (GtkAssistant *assistant)
693 {
694   GtkAssistantPrivate *priv = assistant->priv;
695   GList *l;
696   gboolean show_titles;
697
698   show_titles = FALSE;
699   for (l = priv->pages; l != NULL; l = l->next)
700     {
701       if (update_page_title_state (assistant, l))
702         show_titles = TRUE;
703     }
704
705   gtk_widget_set_visible (priv->sidebar, show_titles);
706 }
707
708 static void
709 set_current_page (GtkAssistant *assistant,
710                   gint          page_num)
711 {
712   GtkAssistantPrivate *priv = assistant->priv;
713
714   priv->current_page = (GtkAssistantPage *)g_list_nth_data (priv->pages, page_num);
715
716   g_signal_emit (assistant, signals [PREPARE], 0, priv->current_page->page);
717
718   update_title_state (assistant);
719
720   gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->content), page_num);
721
722   /* update buttons state, flow may have changed */
723   if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
724     update_buttons_state (assistant);
725
726   if (!gtk_widget_child_focus (priv->current_page->page, GTK_DIR_TAB_FORWARD))
727     {
728       GtkWidget *button[6];
729       gint i;
730
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++)
739         {
740           if (gtk_widget_get_visible (button[i]) &&
741               gtk_widget_get_sensitive (button[i]))
742             {
743               gtk_widget_grab_focus (button[i]);
744               break;
745             }
746         }
747     }
748
749   gtk_widget_queue_resize (GTK_WIDGET (assistant));
750 }
751
752 static gint
753 compute_next_step (GtkAssistant *assistant)
754 {
755   GtkAssistantPrivate *priv = assistant->priv;
756   GtkAssistantPage *page_info;
757   gint current_page, n_pages, next_page;
758
759   current_page = gtk_assistant_get_current_page (assistant);
760   page_info = priv->current_page;
761   n_pages = gtk_assistant_get_n_pages (assistant);
762
763   next_page = (priv->forward_function) (current_page,
764                                         priv->forward_function_data);
765
766   if (next_page >= 0 && next_page < n_pages)
767     {
768       priv->visited_pages = g_slist_prepend (priv->visited_pages, page_info);
769       set_current_page (assistant, next_page);
770
771       return TRUE;
772     }
773
774   return FALSE;
775 }
776
777 static void
778 on_assistant_close (GtkWidget    *widget,
779                     GtkAssistant *assistant)
780 {
781   g_signal_emit (assistant, signals [CLOSE], 0, NULL);
782 }
783
784 static void
785 on_assistant_apply (GtkWidget    *widget,
786                     GtkAssistant *assistant)
787 {
788   gboolean success;
789
790   g_signal_emit (assistant, signals [APPLY], 0);
791
792   success = compute_next_step (assistant);
793
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
796    */
797   if (!success)
798     g_signal_emit (assistant, signals [CLOSE], 0);
799 }
800
801 static void
802 on_assistant_forward (GtkWidget    *widget,
803                       GtkAssistant *assistant)
804 {
805   gtk_assistant_next_page (assistant);
806 }
807
808 static void
809 on_assistant_back (GtkWidget    *widget,
810                    GtkAssistant *assistant)
811 {
812   gtk_assistant_previous_page (assistant);
813 }
814
815 static void
816 on_assistant_cancel (GtkWidget    *widget,
817                      GtkAssistant *assistant)
818 {
819   g_signal_emit (assistant, signals [CANCEL], 0, NULL);
820 }
821
822 static void
823 on_assistant_last (GtkWidget    *widget,
824                    GtkAssistant *assistant)
825 {
826   GtkAssistantPrivate *priv = assistant->priv;
827
828   while (priv->current_page->type == GTK_ASSISTANT_PAGE_CONTENT &&
829          priv->current_page->complete)
830     compute_next_step (assistant);
831 }
832
833 static gboolean
834 alternative_button_order (GtkAssistant *assistant)
835 {
836   GtkSettings *settings;
837   GdkScreen *screen;
838   gboolean result;
839
840   screen   = gtk_widget_get_screen (GTK_WIDGET (assistant));
841   settings = gtk_settings_get_for_screen (screen);
842
843   g_object_get (settings,
844                 "gtk-alternative-button-order", &result,
845                 NULL);
846   return result;
847 }
848
849 static gboolean
850 assistant_sidebar_draw_cb (GtkWidget *widget,
851                            cairo_t *cr,
852                            gpointer user_data)
853 {
854   gint width, height;
855   GtkStyleContext *context;
856
857   width = gtk_widget_get_allocated_width (widget);
858   height = gtk_widget_get_allocated_height (widget);
859   context = gtk_widget_get_style_context (widget);
860
861   gtk_render_background (context, cr, 0, 0, width, height);
862
863   return FALSE;
864 }
865
866 static void
867 gtk_assistant_init (GtkAssistant *assistant)
868 {
869   GtkAssistantPrivate *priv;
870   GtkStyleContext *context;
871   GtkWidget *main_box;
872   GtkWidget *content_box;
873   GtkWidget *sidebar_frame;
874
875   assistant->priv = G_TYPE_INSTANCE_GET_PRIVATE (assistant,
876                                                  GTK_TYPE_ASSISTANT,
877                                                  GtkAssistantPrivate);
878   priv = assistant->priv;
879
880   /* use border on inner panes instead */
881   gtk_container_set_border_width (GTK_CONTAINER (assistant), 0);
882
883   gtk_widget_push_composite_child ();
884
885   main_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
886   priv->sidebar = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
887
888   /* use a frame for the sidebar, and manually render a background
889    * in it. GtkFrame also gives us padding support for free.
890    */
891   sidebar_frame = gtk_frame_new (NULL);
892   context = gtk_widget_get_style_context (sidebar_frame);
893   gtk_style_context_add_class (context, GTK_STYLE_CLASS_SIDEBAR);
894
895   g_signal_connect (sidebar_frame, "draw",
896                     G_CALLBACK (assistant_sidebar_draw_cb), assistant);
897
898   content_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
899   gtk_container_set_border_width (GTK_CONTAINER (content_box), 12);
900   priv->content = gtk_notebook_new ();
901   gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->content), FALSE);
902   gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->content), FALSE);
903   priv->action_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
904
905   gtk_container_add (GTK_CONTAINER (sidebar_frame), priv->sidebar);
906   gtk_box_pack_start (GTK_BOX (main_box), sidebar_frame, FALSE, FALSE, 0);
907   gtk_box_pack_start (GTK_BOX (main_box), content_box, TRUE, TRUE, 0);
908   gtk_box_pack_start (GTK_BOX (content_box), priv->content, TRUE, TRUE, 0);
909   gtk_box_pack_start (GTK_BOX (content_box), priv->action_area, FALSE, TRUE, 0);
910   gtk_widget_set_halign (priv->action_area, GTK_ALIGN_END);
911
912   gtk_widget_show_all (main_box);
913
914   gtk_widget_set_parent (main_box, GTK_WIDGET (assistant));
915   _gtk_bin_set_child (GTK_BIN (assistant), main_box);
916
917   priv->close   = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
918   priv->apply   = gtk_button_new_from_stock (GTK_STOCK_APPLY);
919   priv->forward = gtk_button_new_from_stock (GTK_STOCK_GO_FORWARD);
920   priv->back    = gtk_button_new_from_stock (GTK_STOCK_GO_BACK);
921   priv->cancel  = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
922   priv->last    = gtk_button_new_from_stock (GTK_STOCK_GOTO_LAST);
923   gtk_widget_set_can_default (priv->close, TRUE);
924   gtk_widget_set_can_default (priv->apply, TRUE);
925   gtk_widget_set_can_default (priv->forward, TRUE);
926
927   priv->button_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
928   gtk_size_group_add_widget (priv->button_size_group, priv->close);
929   gtk_size_group_add_widget (priv->button_size_group, priv->apply);
930   gtk_size_group_add_widget (priv->button_size_group, priv->forward);
931   gtk_size_group_add_widget (priv->button_size_group, priv->back);
932   gtk_size_group_add_widget (priv->button_size_group, priv->cancel);
933   gtk_size_group_add_widget (priv->button_size_group, priv->last);
934
935   if (!alternative_button_order (assistant))
936     {
937       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
938       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
939       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
940       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
941       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
942       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->close, FALSE, FALSE, 0);
943     }
944   else
945     {
946       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->close, FALSE, FALSE, 0);
947       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
948       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
949       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
950       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
951       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
952     }
953
954   gtk_widget_show (priv->forward);
955   gtk_widget_show (priv->back);
956   gtk_widget_show (priv->cancel);
957   gtk_widget_show (priv->action_area);
958
959   gtk_widget_pop_composite_child ();
960
961   priv->title_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
962
963   priv->pages = NULL;
964   priv->current_page = NULL;
965   priv->visited_pages = NULL;
966
967   priv->forward_function = default_forward_function;
968   priv->forward_function_data = assistant;
969   priv->forward_data_destroy = NULL;
970
971   g_signal_connect (G_OBJECT (priv->close), "clicked",
972                     G_CALLBACK (on_assistant_close), assistant);
973   g_signal_connect (G_OBJECT (priv->apply), "clicked",
974                     G_CALLBACK (on_assistant_apply), assistant);
975   g_signal_connect (G_OBJECT (priv->forward), "clicked",
976                     G_CALLBACK (on_assistant_forward), assistant);
977   g_signal_connect (G_OBJECT (priv->back), "clicked",
978                     G_CALLBACK (on_assistant_back), assistant);
979   g_signal_connect (G_OBJECT (priv->cancel), "clicked",
980                     G_CALLBACK (on_assistant_cancel), assistant);
981   g_signal_connect (G_OBJECT (priv->last), "clicked",
982                     G_CALLBACK (on_assistant_last), assistant);
983 }
984
985 static void
986 gtk_assistant_set_child_property (GtkContainer *container,
987                                   GtkWidget    *child,
988                                   guint         property_id,
989                                   const GValue *value,
990                                   GParamSpec   *pspec)
991 {
992   switch (property_id)
993     {
994     case CHILD_PROP_PAGE_TYPE:
995       gtk_assistant_set_page_type (GTK_ASSISTANT (container), child,
996                                    g_value_get_enum (value));
997       break;
998     case CHILD_PROP_PAGE_TITLE:
999       gtk_assistant_set_page_title (GTK_ASSISTANT (container), child,
1000                                     g_value_get_string (value));
1001       break;
1002     case CHILD_PROP_PAGE_HEADER_IMAGE:
1003       gtk_assistant_set_page_header_image (GTK_ASSISTANT (container), child,
1004                                            g_value_get_object (value));
1005       break;
1006     case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
1007       gtk_assistant_set_page_side_image (GTK_ASSISTANT (container), child,
1008                                          g_value_get_object (value));
1009       break;
1010     case CHILD_PROP_PAGE_COMPLETE:
1011       gtk_assistant_set_page_complete (GTK_ASSISTANT (container), child,
1012                                        g_value_get_boolean (value));
1013       break;
1014     default:
1015       GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
1016       break;
1017     }
1018 }
1019
1020 static void
1021 gtk_assistant_get_child_property (GtkContainer *container,
1022                                   GtkWidget    *child,
1023                                   guint         property_id,
1024                                   GValue       *value,
1025                                   GParamSpec   *pspec)
1026 {
1027   switch (property_id)
1028     {
1029     case CHILD_PROP_PAGE_TYPE:
1030       g_value_set_enum (value,
1031                         gtk_assistant_get_page_type (GTK_ASSISTANT (container), child));
1032       break;
1033     case CHILD_PROP_PAGE_TITLE:
1034       g_value_set_string (value,
1035                           gtk_assistant_get_page_title (GTK_ASSISTANT (container), child));
1036       break;
1037     case CHILD_PROP_PAGE_HEADER_IMAGE:
1038       g_value_set_object (value,
1039                           gtk_assistant_get_page_header_image (GTK_ASSISTANT (container), child));
1040       break;
1041     case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
1042       g_value_set_object (value,
1043                           gtk_assistant_get_page_side_image (GTK_ASSISTANT (container), child));
1044       break;
1045     case CHILD_PROP_PAGE_COMPLETE:
1046       g_value_set_boolean (value,
1047                            gtk_assistant_get_page_complete (GTK_ASSISTANT (container), child));
1048       break;
1049     default:
1050       GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
1051       break;
1052     }
1053 }
1054
1055 static void
1056 on_page_notify_visibility (GtkWidget  *widget,
1057                            GParamSpec *arg,
1058                            gpointer    data)
1059 {
1060   GtkAssistant *assistant = GTK_ASSISTANT (data);
1061
1062   if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1063     {
1064       update_buttons_state (assistant);
1065       update_title_state (assistant);
1066     }
1067 }
1068
1069 static void
1070 remove_page (GtkAssistant *assistant,
1071              GList        *element)
1072 {
1073   GtkAssistantPrivate *priv = assistant->priv;
1074   GtkAssistantPage *page_info;
1075   GList *page_node;
1076
1077   page_info = element->data;
1078
1079   /* If this is the current page, we need to switch away. */
1080   if (page_info == priv->current_page)
1081     {
1082       if (!compute_next_step (assistant))
1083         {
1084           /* The best we can do at this point is probably to pick
1085            * the first visible page.
1086            */
1087           page_node = priv->pages;
1088
1089           while (page_node &&
1090                  !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
1091             page_node = page_node->next;
1092
1093           if (page_node == element)
1094             page_node = page_node->next;
1095
1096           if (page_node)
1097             priv->current_page = page_node->data;
1098           else
1099             priv->current_page = NULL;
1100         }
1101     }
1102
1103   g_signal_handlers_disconnect_by_func (page_info->page, on_page_notify_visibility, assistant);
1104
1105   gtk_size_group_remove_widget (priv->title_size_group, page_info->regular_title);
1106   gtk_size_group_remove_widget (priv->title_size_group, page_info->current_title);
1107
1108   gtk_container_remove (GTK_CONTAINER (priv->sidebar), page_info->regular_title);
1109   gtk_container_remove (GTK_CONTAINER (priv->sidebar), page_info->current_title);
1110
1111   gtk_notebook_remove_page (GTK_NOTEBOOK (priv->content), gtk_notebook_page_num (GTK_NOTEBOOK (priv->content), page_info->page));
1112   priv->pages = g_list_remove_link (priv->pages, element);
1113   priv->visited_pages = g_slist_remove_all (priv->visited_pages, page_info);
1114
1115   g_free (page_info->title);
1116
1117   g_slice_free (GtkAssistantPage, page_info);
1118   g_list_free_1 (element);
1119
1120   if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1121     {
1122       update_buttons_state (assistant);
1123       update_actions_size (assistant);
1124     }
1125 }
1126
1127 static void
1128 gtk_assistant_destroy (GtkWidget *widget)
1129 {
1130   GtkAssistant *assistant = GTK_ASSISTANT (widget);
1131   GtkAssistantPrivate *priv = assistant->priv;
1132
1133   /* We set current to NULL so that the remove code doesn't try
1134    * to do anything funny
1135    */
1136   priv->current_page = NULL;
1137
1138   while (priv->pages)
1139     remove_page (assistant, priv->pages);
1140
1141   if (priv->sidebar)
1142     priv->sidebar = NULL;
1143
1144   if (priv->content)
1145     priv->content = NULL;
1146
1147   if (priv->action_area)
1148     priv->action_area = NULL;
1149
1150   if (priv->button_size_group)
1151     {
1152       g_object_unref (priv->button_size_group);
1153       priv->button_size_group = NULL;
1154     }
1155
1156   if (priv->title_size_group)
1157     {
1158       g_object_unref (priv->title_size_group);
1159       priv->title_size_group = NULL;
1160     }
1161
1162   if (priv->forward_function)
1163     {
1164       if (priv->forward_function_data &&
1165           priv->forward_data_destroy)
1166         priv->forward_data_destroy (priv->forward_function_data);
1167
1168       priv->forward_function = NULL;
1169       priv->forward_function_data = NULL;
1170       priv->forward_data_destroy = NULL;
1171     }
1172
1173   if (priv->visited_pages)
1174     {
1175       g_slist_free (priv->visited_pages);
1176       priv->visited_pages = NULL;
1177     }
1178
1179   GTK_WIDGET_CLASS (gtk_assistant_parent_class)->destroy (widget);
1180 }
1181
1182 static GList*
1183 find_page (GtkAssistant  *assistant,
1184            GtkWidget     *page)
1185 {
1186   GtkAssistantPrivate *priv = assistant->priv;
1187   GList *child = priv->pages;
1188
1189   while (child)
1190     {
1191       GtkAssistantPage *page_info = child->data;
1192       if (page_info->page == page)
1193         return child;
1194
1195       child = child->next;
1196     }
1197
1198   return NULL;
1199 }
1200
1201 static void
1202 gtk_assistant_map (GtkWidget *widget)
1203 {
1204   GtkAssistant *assistant = GTK_ASSISTANT (widget);
1205   GtkAssistantPrivate *priv = assistant->priv;
1206   GList *page_node;
1207   GtkAssistantPage *page;
1208   gint page_num;
1209
1210   /* if there's no default page, pick the first one */
1211   page = NULL;
1212   page_num = 0;
1213   if (!priv->current_page)
1214     {
1215       page_node = priv->pages;
1216
1217       while (page_node && !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
1218         {
1219           page_node = page_node->next;
1220           page_num++;
1221         }
1222
1223       if (page_node)
1224         page = page_node->data;
1225     }
1226
1227   if (page && gtk_widget_get_visible (page->page))
1228     set_current_page (assistant, page_num);
1229
1230   update_buttons_state (assistant);
1231   update_actions_size (assistant);
1232   update_title_state (assistant);
1233
1234   GTK_WIDGET_CLASS (gtk_assistant_parent_class)->map (widget);
1235 }
1236
1237 static void
1238 gtk_assistant_unmap (GtkWidget *widget)
1239 {
1240   GtkAssistant *assistant = GTK_ASSISTANT (widget);
1241   GtkAssistantPrivate *priv = assistant->priv;
1242
1243   g_slist_free (priv->visited_pages);
1244   priv->visited_pages = NULL;
1245   priv->current_page  = NULL;
1246
1247   GTK_WIDGET_CLASS (gtk_assistant_parent_class)->unmap (widget);
1248 }
1249
1250 static gboolean
1251 gtk_assistant_delete_event (GtkWidget   *widget,
1252                             GdkEventAny *event)
1253 {
1254   GtkAssistant *assistant = GTK_ASSISTANT (widget);
1255   GtkAssistantPrivate *priv = assistant->priv;
1256
1257   /* Do not allow cancelling in the middle of a progress page */
1258   if (priv->current_page &&
1259       (priv->current_page->type != GTK_ASSISTANT_PAGE_PROGRESS ||
1260        priv->current_page->complete))
1261     g_signal_emit (widget, signals [CANCEL], 0, NULL);
1262
1263   return TRUE;
1264 }
1265
1266 static void
1267 gtk_assistant_add (GtkContainer *container,
1268                    GtkWidget    *page)
1269 {
1270   gtk_assistant_append_page (GTK_ASSISTANT (container), page);
1271 }
1272
1273 static void
1274 gtk_assistant_remove (GtkContainer *container,
1275                       GtkWidget    *page)
1276 {
1277   GtkAssistant *assistant = (GtkAssistant*) container;
1278   GList *element;
1279
1280   element = find_page (assistant, page);
1281
1282   if (element)
1283     {
1284       remove_page (assistant, element);
1285       gtk_widget_queue_resize ((GtkWidget *) container);
1286     }
1287 }
1288
1289 /**
1290  * gtk_assistant_new:
1291  *
1292  * Creates a new #GtkAssistant.
1293  *
1294  * Return value: a newly created #GtkAssistant
1295  *
1296  * Since: 2.10
1297  */
1298 GtkWidget*
1299 gtk_assistant_new (void)
1300 {
1301   GtkWidget *assistant;
1302
1303   assistant = g_object_new (GTK_TYPE_ASSISTANT, NULL);
1304
1305   return assistant;
1306 }
1307
1308 /**
1309  * gtk_assistant_get_current_page:
1310  * @assistant: a #GtkAssistant
1311  *
1312  * Returns the page number of the current page.
1313  *
1314  * Return value: The index (starting from 0) of the current
1315  *     page in the @assistant, or -1 if the @assistant has no pages,
1316  *     or no current page.
1317  *
1318  * Since: 2.10
1319  */
1320 gint
1321 gtk_assistant_get_current_page (GtkAssistant *assistant)
1322 {
1323   GtkAssistantPrivate *priv;
1324
1325   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), -1);
1326
1327   priv = assistant->priv;
1328
1329   if (!priv->pages || !priv->current_page)
1330     return -1;
1331
1332   return g_list_index (priv->pages, priv->current_page);
1333 }
1334
1335 /**
1336  * gtk_assistant_set_current_page:
1337  * @assistant: a #GtkAssistant
1338  * @page_num: index of the page to switch to, starting from 0.
1339  *     If negative, the last page will be used. If greater
1340  *     than the number of pages in the @assistant, nothing
1341  *     will be done.
1342  *
1343  * Switches the page to @page_num.
1344  *
1345  * Note that this will only be necessary in custom buttons,
1346  * as the @assistant flow can be set with
1347  * gtk_assistant_set_forward_page_func().
1348  *
1349  * Since: 2.10
1350  */
1351 void
1352 gtk_assistant_set_current_page (GtkAssistant *assistant,
1353                                 gint          page_num)
1354 {
1355   GtkAssistantPrivate *priv;
1356   GtkAssistantPage *page;
1357
1358   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1359
1360   priv = assistant->priv;
1361
1362   if (page_num >= 0)
1363     page = (GtkAssistantPage *) g_list_nth_data (priv->pages, page_num);
1364   else
1365     {
1366       page = (GtkAssistantPage *) g_list_last (priv->pages)->data;
1367       page_num = g_list_length (priv->pages);
1368     }
1369
1370   g_return_if_fail (page != NULL);
1371
1372   if (priv->current_page == page)
1373     return;
1374
1375   /* only add the page to the visited list if the assistant is mapped,
1376    * if not, just use it as an initial page setting, for the cases where
1377    * the initial page is != to 0
1378    */
1379   if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1380     priv->visited_pages = g_slist_prepend (priv->visited_pages,
1381                                            priv->current_page);
1382
1383   set_current_page (assistant, page_num);
1384 }
1385
1386 /**
1387  * gtk_assistant_next_page:
1388  * @assistant: a #GtkAssistant
1389  *
1390  * Navigate to the next page.
1391  *
1392  * It is a programming error to call this function when
1393  * there is no next page.
1394  *
1395  * This function is for use when creating pages of the
1396  * #GTK_ASSISTANT_PAGE_CUSTOM type.
1397  *
1398  * Since: 3.0
1399  */
1400 void
1401 gtk_assistant_next_page (GtkAssistant *assistant)
1402 {
1403   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1404
1405   if (!compute_next_step (assistant))
1406     g_critical ("Page flow is broken.\n"
1407                 "You may want to end it with a page of type\n"
1408                 "GTK_ASSISTANT_PAGE_CONFIRM or GTK_ASSISTANT_PAGE_SUMMARY");
1409 }
1410
1411 /**
1412  * gtk_assistant_previous_page:
1413  * @assistant: a #GtkAssistant
1414  *
1415  * Navigate to the previous visited page.
1416  *
1417  * It is a programming error to call this function when
1418  * no previous page is available.
1419  *
1420  * This function is for use when creating pages of the
1421  * #GTK_ASSISTANT_PAGE_CUSTOM type.
1422  *
1423  * Since: 3.0
1424  */
1425 void
1426 gtk_assistant_previous_page (GtkAssistant *assistant)
1427 {
1428   GtkAssistantPrivate *priv;
1429   GtkAssistantPage *page_info;
1430   GSList *page_node;
1431
1432   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1433
1434   priv = assistant->priv;
1435
1436   /* skip the progress pages when going back */
1437   do
1438     {
1439       page_node = priv->visited_pages;
1440
1441       g_return_if_fail (page_node != NULL);
1442
1443       priv->visited_pages = priv->visited_pages->next;
1444       page_info = (GtkAssistantPage *) page_node->data;
1445       g_slist_free_1 (page_node);
1446     }
1447   while (page_info->type == GTK_ASSISTANT_PAGE_PROGRESS ||
1448          !gtk_widget_get_visible (page_info->page));
1449
1450   set_current_page (assistant, g_list_index (priv->pages, page_info));
1451 }
1452
1453 /**
1454  * gtk_assistant_get_n_pages:
1455  * @assistant: a #GtkAssistant
1456  *
1457  * Returns the number of pages in the @assistant
1458  *
1459  * Return value: the number of pages in the @assistant
1460  *
1461  * Since: 2.10
1462  */
1463 gint
1464 gtk_assistant_get_n_pages (GtkAssistant *assistant)
1465 {
1466   GtkAssistantPrivate *priv;
1467
1468   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1469
1470   priv = assistant->priv;
1471
1472   return g_list_length (priv->pages);
1473 }
1474
1475 /**
1476  * gtk_assistant_get_nth_page:
1477  * @assistant: a #GtkAssistant
1478  * @page_num: the index of a page in the @assistant,
1479  *     or -1 to get the last page
1480  *
1481  * Returns the child widget contained in page number @page_num.
1482  *
1483  * Return value: (transfer none): the child widget, or %NULL
1484  *     if @page_num is out of bounds
1485  *
1486  * Since: 2.10
1487  */
1488 GtkWidget*
1489 gtk_assistant_get_nth_page (GtkAssistant *assistant,
1490                             gint          page_num)
1491 {
1492   GtkAssistantPrivate *priv;
1493   GtkAssistantPage *page;
1494   GList *elem;
1495
1496   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1497   g_return_val_if_fail (page_num >= -1, NULL);
1498
1499   priv = assistant->priv;
1500
1501   if (page_num == -1)
1502     elem = g_list_last (priv->pages);
1503   else
1504     elem = g_list_nth (priv->pages, page_num);
1505
1506   if (!elem)
1507     return NULL;
1508
1509   page = (GtkAssistantPage *) elem->data;
1510
1511   return page->page;
1512 }
1513
1514 /**
1515  * gtk_assistant_prepend_page:
1516  * @assistant: a #GtkAssistant
1517  * @page: a #GtkWidget
1518  *
1519  * Prepends a page to the @assistant.
1520  *
1521  * Return value: the index (starting at 0) of the inserted page
1522  *
1523  * Since: 2.10
1524  */
1525 gint
1526 gtk_assistant_prepend_page (GtkAssistant *assistant,
1527                             GtkWidget    *page)
1528 {
1529   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1530   g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1531
1532   return gtk_assistant_insert_page (assistant, page, 0);
1533 }
1534
1535 /**
1536  * gtk_assistant_append_page:
1537  * @assistant: a #GtkAssistant
1538  * @page: a #GtkWidget
1539  *
1540  * Appends a page to the @assistant.
1541  *
1542  * Return value: the index (starting at 0) of the inserted page
1543  *
1544  * Since: 2.10
1545  */
1546 gint
1547 gtk_assistant_append_page (GtkAssistant *assistant,
1548                            GtkWidget    *page)
1549 {
1550   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1551   g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1552
1553   return gtk_assistant_insert_page (assistant, page, -1);
1554 }
1555
1556 /**
1557  * gtk_assistant_insert_page:
1558  * @assistant: a #GtkAssistant
1559  * @page: a #GtkWidget
1560  * @position: the index (starting at 0) at which to insert the page,
1561  *     or -1 to append the page to the @assistant
1562  *
1563  * Inserts a page in the @assistant at a given position.
1564  *
1565  * Return value: the index (starting from 0) of the inserted page
1566  *
1567  * Since: 2.10
1568  */
1569 gint
1570 gtk_assistant_insert_page (GtkAssistant *assistant,
1571                            GtkWidget    *page,
1572                            gint          position)
1573 {
1574   GtkAssistantPrivate *priv;
1575   GtkAssistantPage *page_info;
1576   gint n_pages;
1577   GtkStyleContext *context;
1578
1579   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1580   g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1581   g_return_val_if_fail (gtk_widget_get_parent (page) == NULL, 0);
1582   g_return_val_if_fail (!gtk_widget_is_toplevel (page), 0);
1583
1584   priv = assistant->priv;
1585
1586   page_info = g_slice_new0 (GtkAssistantPage);
1587   page_info->page  = page;
1588   page_info->regular_title = gtk_label_new (NULL);
1589   page_info->current_title = gtk_label_new (NULL);
1590
1591   gtk_widget_set_halign (page_info->regular_title, GTK_ALIGN_START);
1592   gtk_widget_set_valign (page_info->regular_title, GTK_ALIGN_CENTER);
1593   gtk_widget_show (page_info->regular_title);
1594
1595   gtk_widget_set_halign (page_info->current_title, GTK_ALIGN_START);
1596   gtk_widget_set_valign (page_info->current_title, GTK_ALIGN_CENTER);
1597   gtk_widget_hide (page_info->current_title);
1598
1599   context = gtk_widget_get_style_context (page_info->current_title);
1600   gtk_style_context_add_class (context, GTK_STYLE_CLASS_HIGHLIGHT);
1601
1602   gtk_size_group_add_widget (priv->title_size_group, page_info->regular_title);
1603   gtk_size_group_add_widget (priv->title_size_group, page_info->current_title);
1604
1605   g_signal_connect (G_OBJECT (page), "notify::visible",
1606                     G_CALLBACK (on_page_notify_visibility), assistant);
1607
1608   n_pages = g_list_length (priv->pages);
1609
1610   if (position < 0 || position > n_pages)
1611     position = n_pages;
1612
1613   priv->pages = g_list_insert (priv->pages, page_info, position);
1614
1615   gtk_box_pack_start (GTK_BOX (priv->sidebar), page_info->regular_title, FALSE, FALSE, 0);
1616   gtk_box_pack_start (GTK_BOX (priv->sidebar), page_info->current_title, FALSE, FALSE, 0);
1617   gtk_box_reorder_child (GTK_BOX (priv->sidebar), page_info->regular_title, 2 * position);
1618   gtk_box_reorder_child (GTK_BOX (priv->sidebar), page_info->current_title, 2 * position + 1);
1619
1620   gtk_notebook_insert_page (GTK_NOTEBOOK (priv->content), page, NULL, position);
1621
1622   if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1623     {
1624       update_buttons_state (assistant);
1625       update_actions_size (assistant);
1626     }
1627
1628   return position;
1629 }
1630
1631 /**
1632  * gtk_assistant_set_forward_page_func:
1633  * @assistant: a #GtkAssistant
1634  * @page_func: (allow-none): the #GtkAssistantPageFunc, or %NULL
1635  *     to use the default one
1636  * @data: user data for @page_func
1637  * @destroy: destroy notifier for @data
1638  *
1639  * Sets the page forwarding function to be @page_func.
1640  *
1641  * This function will be used to determine what will be
1642  * the next page when the user presses the forward button.
1643  * Setting @page_func to %NULL will make the assistant to
1644  * use the default forward function, which just goes to the
1645  * next visible page.
1646  *
1647  * Since: 2.10
1648  */
1649 void
1650 gtk_assistant_set_forward_page_func (GtkAssistant         *assistant,
1651                                      GtkAssistantPageFunc  page_func,
1652                                      gpointer              data,
1653                                      GDestroyNotify        destroy)
1654 {
1655   GtkAssistantPrivate *priv;
1656
1657   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1658
1659   priv = assistant->priv;
1660
1661   if (priv->forward_data_destroy &&
1662       priv->forward_function_data)
1663     (*priv->forward_data_destroy) (priv->forward_function_data);
1664
1665   if (page_func)
1666     {
1667       priv->forward_function = page_func;
1668       priv->forward_function_data = data;
1669       priv->forward_data_destroy = destroy;
1670     }
1671   else
1672     {
1673       priv->forward_function = default_forward_function;
1674       priv->forward_function_data = assistant;
1675       priv->forward_data_destroy = NULL;
1676     }
1677
1678   /* Page flow has possibly changed, so the
1679    * buttons state might need to change too
1680    */
1681   if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1682     update_buttons_state (assistant);
1683 }
1684
1685 /**
1686  * gtk_assistant_add_action_widget:
1687  * @assistant: a #GtkAssistant
1688  * @child: a #GtkWidget
1689  *
1690  * Adds a widget to the action area of a #GtkAssistant.
1691  *
1692  * Since: 2.10
1693  */
1694 void
1695 gtk_assistant_add_action_widget (GtkAssistant *assistant,
1696                                  GtkWidget    *child)
1697 {
1698   GtkAssistantPrivate *priv;
1699
1700   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1701   g_return_if_fail (GTK_IS_WIDGET (child));
1702
1703   priv = assistant->priv;
1704
1705   if (GTK_IS_BUTTON (child))
1706     {
1707       gtk_size_group_add_widget (priv->button_size_group, child);
1708       priv->extra_buttons += 1;
1709       if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1710         update_actions_size (assistant);
1711     }
1712
1713   gtk_box_pack_end (GTK_BOX (priv->action_area), child, FALSE, FALSE, 0);
1714 }
1715
1716 /**
1717  * gtk_assistant_remove_action_widget:
1718  * @assistant: a #GtkAssistant
1719  * @child: a #GtkWidget
1720  *
1721  * Removes a widget from the action area of a #GtkAssistant.
1722  *
1723  * Since: 2.10
1724  */
1725 void
1726 gtk_assistant_remove_action_widget (GtkAssistant *assistant,
1727                                     GtkWidget    *child)
1728 {
1729   GtkAssistantPrivate *priv;
1730
1731   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1732   g_return_if_fail (GTK_IS_WIDGET (child));
1733
1734   priv = assistant->priv;
1735
1736   if (GTK_IS_BUTTON (child))
1737     {
1738       gtk_size_group_remove_widget (priv->button_size_group, child);
1739       priv->extra_buttons -= 1;
1740       if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1741         update_actions_size (assistant);
1742     }
1743
1744   gtk_container_remove (GTK_CONTAINER (priv->action_area), child);
1745 }
1746
1747 /**
1748  * gtk_assistant_set_page_title:
1749  * @assistant: a #GtkAssistant
1750  * @page: a page of @assistant
1751  * @title: the new title for @page
1752  *
1753  * Sets a title for @page.
1754  *
1755  * The title is displayed in the header area of the assistant
1756  * when @page is the current page.
1757  *
1758  * Since: 2.10
1759  */
1760 void
1761 gtk_assistant_set_page_title (GtkAssistant *assistant,
1762                               GtkWidget    *page,
1763                               const gchar  *title)
1764 {
1765   GtkAssistantPage *page_info;
1766   GList *child;
1767
1768   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1769   g_return_if_fail (GTK_IS_WIDGET (page));
1770
1771   child = find_page (assistant, page);
1772
1773   g_return_if_fail (child != NULL);
1774
1775   page_info = (GtkAssistantPage*) child->data;
1776
1777   g_free (page_info->title);
1778   page_info->title = g_strdup (title);
1779
1780   gtk_label_set_text ((GtkLabel*) page_info->regular_title, title);
1781   gtk_label_set_text ((GtkLabel*) page_info->current_title, title);
1782
1783   gtk_widget_queue_resize (GTK_WIDGET (assistant));
1784   gtk_container_child_notify (GTK_CONTAINER (assistant), page, "title");
1785 }
1786
1787 /**
1788  * gtk_assistant_get_page_title:
1789  * @assistant: a #GtkAssistant
1790  * @page: a page of @assistant
1791  *
1792  * Gets the title for @page.
1793  *
1794  * Return value: the title for @page
1795  *
1796  * Since: 2.10
1797  */
1798 const gchar*
1799 gtk_assistant_get_page_title (GtkAssistant *assistant,
1800                               GtkWidget    *page)
1801 {
1802   GtkAssistantPage *page_info;
1803   GList *child;
1804
1805   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1806   g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1807
1808   child = find_page (assistant, page);
1809
1810   g_return_val_if_fail (child != NULL, NULL);
1811
1812   page_info = (GtkAssistantPage*) child->data;
1813
1814   return page_info->title;
1815 }
1816
1817 /**
1818  * gtk_assistant_set_page_type:
1819  * @assistant: a #GtkAssistant
1820  * @page: a page of @assistant
1821  * @type: the new type for @page
1822  *
1823  * Sets the page type for @page.
1824  *
1825  * The page type determines the page behavior in the @assistant.
1826  *
1827  * Since: 2.10
1828  */
1829 void
1830 gtk_assistant_set_page_type (GtkAssistant         *assistant,
1831                              GtkWidget            *page,
1832                              GtkAssistantPageType  type)
1833 {
1834   GtkAssistantPage *page_info;
1835   GList *child;
1836
1837   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1838   g_return_if_fail (GTK_IS_WIDGET (page));
1839
1840   child = find_page (assistant, page);
1841
1842   g_return_if_fail (child != NULL);
1843
1844   page_info = (GtkAssistantPage*) child->data;
1845
1846   if (type != page_info->type)
1847     {
1848       page_info->type = type;
1849
1850       /* backwards compatibility to the era before fixing bug 604289 */
1851       if (type == GTK_ASSISTANT_PAGE_SUMMARY && !page_info->complete_set)
1852         {
1853           gtk_assistant_set_page_complete (assistant, page, TRUE);
1854           page_info->complete_set = FALSE;
1855         }
1856
1857       /* Always set buttons state, a change in a future page
1858        * might change current page buttons
1859        */
1860       update_buttons_state (assistant);
1861
1862       gtk_container_child_notify (GTK_CONTAINER (assistant), page, "page-type");
1863     }
1864 }
1865
1866 /**
1867  * gtk_assistant_get_page_type:
1868  * @assistant: a #GtkAssistant
1869  * @page: a page of @assistant
1870  *
1871  * Gets the page type of @page.
1872  *
1873  * Return value: the page type of @page
1874  *
1875  * Since: 2.10
1876  */
1877 GtkAssistantPageType
1878 gtk_assistant_get_page_type (GtkAssistant *assistant,
1879                              GtkWidget    *page)
1880 {
1881   GtkAssistantPage *page_info;
1882   GList *child;
1883
1884   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), GTK_ASSISTANT_PAGE_CONTENT);
1885   g_return_val_if_fail (GTK_IS_WIDGET (page), GTK_ASSISTANT_PAGE_CONTENT);
1886
1887   child = find_page (assistant, page);
1888
1889   g_return_val_if_fail (child != NULL, GTK_ASSISTANT_PAGE_CONTENT);
1890
1891   page_info = (GtkAssistantPage*) child->data;
1892
1893   return page_info->type;
1894 }
1895
1896 /**
1897  * gtk_assistant_set_page_header_image:
1898  * @assistant: a #GtkAssistant
1899  * @page: a page of @assistant
1900  * @pixbuf: (allow-none): the new header image @page
1901  *
1902  * Sets a header image for @page.
1903  *
1904  * Since: 2.10
1905  *
1906  * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
1907  *     add your header decoration to the page content instead.
1908  */
1909 void
1910 gtk_assistant_set_page_header_image (GtkAssistant *assistant,
1911                                      GtkWidget    *page,
1912                                      GdkPixbuf    *pixbuf)
1913 {
1914   GtkAssistantPage *page_info;
1915   GList *child;
1916
1917   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1918   g_return_if_fail (GTK_IS_WIDGET (page));
1919   g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1920
1921   child = find_page (assistant, page);
1922
1923   g_return_if_fail (child != NULL);
1924
1925   page_info = (GtkAssistantPage*) child->data;
1926
1927   if (pixbuf != page_info->header_image)
1928     {
1929       if (page_info->header_image)
1930         {
1931           g_object_unref (page_info->header_image);
1932           page_info->header_image = NULL;
1933         }
1934
1935       if (pixbuf)
1936         page_info->header_image = g_object_ref (pixbuf);
1937
1938       gtk_container_child_notify (GTK_CONTAINER (assistant), page, "header-image");
1939     }
1940 }
1941
1942 /**
1943  * gtk_assistant_get_page_header_image:
1944  * @assistant: a #GtkAssistant
1945  * @page: a page of @assistant
1946  *
1947  * Gets the header image for @page.
1948  *
1949  * Return value: (transfer none): the header image for @page,
1950  *     or %NULL if there's no header image for the page
1951  *
1952  * Since: 2.10
1953  *
1954  * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
1955  *     add your header decoration to the page content instead.
1956  */
1957 GdkPixbuf*
1958 gtk_assistant_get_page_header_image (GtkAssistant *assistant,
1959                                      GtkWidget    *page)
1960 {
1961   GtkAssistantPage *page_info;
1962   GList *child;
1963
1964   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1965   g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1966
1967   child = find_page (assistant, page);
1968
1969   g_return_val_if_fail (child != NULL, NULL);
1970
1971   page_info = (GtkAssistantPage*) child->data;
1972
1973   return page_info->header_image;
1974 }
1975
1976 /**
1977  * gtk_assistant_set_page_side_image:
1978  * @assistant: a #GtkAssistant
1979  * @page: a page of @assistant
1980  * @pixbuf: (allow-none): the new side image @page
1981  *
1982  * Sets a side image for @page.
1983  *
1984  * This image used to be displayed in the side area of the assistant
1985  * when @page is the current page.
1986  *
1987  * Since: 2.10
1988  *
1989  * Deprecated: 3.2: Since GTK+ 3.2, sidebar images are not
1990  *     shown anymore.
1991  */
1992 void
1993 gtk_assistant_set_page_side_image (GtkAssistant *assistant,
1994                                    GtkWidget    *page,
1995                                    GdkPixbuf    *pixbuf)
1996 {
1997   GtkAssistantPage *page_info;
1998   GList *child;
1999
2000   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2001   g_return_if_fail (GTK_IS_WIDGET (page));
2002   g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2003
2004   child = find_page (assistant, page);
2005
2006   g_return_if_fail (child != NULL);
2007
2008   page_info = (GtkAssistantPage*) child->data;
2009
2010   if (pixbuf != page_info->sidebar_image)
2011     {
2012       if (page_info->sidebar_image)
2013         {
2014           g_object_unref (page_info->sidebar_image);
2015           page_info->sidebar_image = NULL;
2016         }
2017
2018       if (pixbuf)
2019         page_info->sidebar_image = g_object_ref (pixbuf);
2020
2021       gtk_container_child_notify (GTK_CONTAINER (assistant), page, "sidebar-image");
2022     }
2023 }
2024
2025 /**
2026  * gtk_assistant_get_page_side_image:
2027  * @assistant: a #GtkAssistant
2028  * @page: a page of @assistant
2029  *
2030  * Gets the side image for @page.
2031  *
2032  * Return value: (transfer none): the side image for @page,
2033  *     or %NULL if there's no side image for the page
2034  *
2035  * Since: 2.10
2036  *
2037  * Deprecated: 3.2: Since GTK+ 3.2, sidebar images are not
2038  *     shown anymore.
2039  */
2040 GdkPixbuf*
2041 gtk_assistant_get_page_side_image (GtkAssistant *assistant,
2042                                    GtkWidget    *page)
2043 {
2044   GtkAssistantPage *page_info;
2045   GList *child;
2046
2047   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2048   g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2049
2050   child = find_page (assistant, page);
2051
2052   g_return_val_if_fail (child != NULL, NULL);
2053
2054   page_info = (GtkAssistantPage*) child->data;
2055
2056   return page_info->sidebar_image;
2057 }
2058
2059 /**
2060  * gtk_assistant_set_page_complete:
2061  * @assistant: a #GtkAssistant
2062  * @page: a page of @assistant
2063  * @complete: the completeness status of the page
2064  *
2065  * Sets whether @page contents are complete.
2066  *
2067  * This will make @assistant update the buttons state
2068  * to be able to continue the task.
2069  *
2070  * Since: 2.10
2071  */
2072 void
2073 gtk_assistant_set_page_complete (GtkAssistant *assistant,
2074                                  GtkWidget    *page,
2075                                  gboolean      complete)
2076 {
2077   GtkAssistantPage *page_info;
2078   GList *child;
2079
2080   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2081   g_return_if_fail (GTK_IS_WIDGET (page));
2082
2083   child = find_page (assistant, page);
2084
2085   g_return_if_fail (child != NULL);
2086
2087   page_info = (GtkAssistantPage*) child->data;
2088
2089   if (complete != page_info->complete)
2090     {
2091       page_info->complete = complete;
2092       page_info->complete_set = TRUE;
2093
2094       /* Always set buttons state, a change in a future page
2095        * might change current page buttons
2096        */
2097       update_buttons_state (assistant);
2098
2099       gtk_container_child_notify (GTK_CONTAINER (assistant), page, "complete");
2100     }
2101 }
2102
2103 /**
2104  * gtk_assistant_get_page_complete:
2105  * @assistant: a #GtkAssistant
2106  * @page: a page of @assistant
2107  *
2108  * Gets whether @page is complete.
2109  *
2110  * Return value: %TRUE if @page is complete.
2111  *
2112  * Since: 2.10
2113  */
2114 gboolean
2115 gtk_assistant_get_page_complete (GtkAssistant *assistant,
2116                                  GtkWidget    *page)
2117 {
2118   GtkAssistantPage *page_info;
2119   GList *child;
2120
2121   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), FALSE);
2122   g_return_val_if_fail (GTK_IS_WIDGET (page), FALSE);
2123
2124   child = find_page (assistant, page);
2125
2126   g_return_val_if_fail (child != NULL, FALSE);
2127
2128   page_info = (GtkAssistantPage*) child->data;
2129
2130   return page_info->complete;
2131 }
2132
2133 /**
2134  * gtk_assistant_update_buttons_state:
2135  * @assistant: a #GtkAssistant
2136  *
2137  * Forces @assistant to recompute the buttons state.
2138  *
2139  * GTK+ automatically takes care of this in most situations,
2140  * e.g. when the user goes to a different page, or when the
2141  * visibility or completeness of a page changes.
2142  *
2143  * One situation where it can be necessary to call this
2144  * function is when changing a value on the current page
2145  * affects the future page flow of the assistant.
2146  *
2147  * Since: 2.10
2148  */
2149 void
2150 gtk_assistant_update_buttons_state (GtkAssistant *assistant)
2151 {
2152   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2153
2154   update_buttons_state (assistant);
2155 }
2156
2157 /**
2158  * gtk_assistant_commit:
2159  * @assistant: a #GtkAssistant
2160  *
2161  * Erases the visited page history so the back button is not
2162  * shown on the current page, and removes the cancel button
2163  * from subsequent pages.
2164  *
2165  * Use this when the information provided up to the current
2166  * page is hereafter deemed permanent and cannot be modified
2167  * or undone. For example, showing a progress page to track
2168  * a long-running, unreversible operation after the user has
2169  * clicked apply on a confirmation page.
2170  *
2171  * Since: 2.22
2172  */
2173 void
2174 gtk_assistant_commit (GtkAssistant *assistant)
2175 {
2176   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2177
2178   g_slist_free (assistant->priv->visited_pages);
2179   assistant->priv->visited_pages = NULL;
2180
2181   assistant->priv->committed = TRUE;
2182
2183   update_buttons_state (assistant);
2184 }
2185
2186 static AtkObject *
2187 gtk_assistant_get_accessible (GtkWidget *widget)
2188 {
2189   static gboolean first_time = TRUE;
2190
2191   if (first_time)
2192     {
2193       _gtk_accessible_set_factory_type (GTK_TYPE_ASSISTANT,
2194                                         gtk_assistant_accessible_factory_get_type ());
2195
2196       first_time = FALSE;
2197     }
2198
2199   return GTK_WIDGET_CLASS (gtk_assistant_parent_class)->get_accessible (widget);
2200 }
2201
2202 /* accessible implementation */
2203
2204 /* dummy typedefs */
2205 typedef struct _GtkAssistantAccessible          GtkAssistantAccessible;
2206 typedef struct _GtkAssistantAccessibleClass     GtkAssistantAccessibleClass;
2207
2208 ATK_DEFINE_TYPE (GtkAssistantAccessible, _gtk_assistant_accessible, GTK_TYPE_ASSISTANT);
2209
2210 static gint
2211 gtk_assistant_accessible_get_n_children (AtkObject *accessible)
2212 {
2213   GtkWidget *widget;
2214
2215   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2216   if (widget == NULL)
2217     return 0;
2218
2219   return g_list_length (GTK_ASSISTANT (widget)->priv->pages) + 1;
2220 }
2221
2222 static AtkObject *
2223 gtk_assistant_accessible_ref_child (AtkObject *accessible,
2224                                     gint       index)
2225 {
2226   GtkAssistant *assistant;
2227   GtkAssistantPrivate *priv;
2228   GtkWidget *widget, *child;
2229   gint n_pages;
2230   AtkObject *obj;
2231   const gchar *title;
2232
2233   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2234   if (widget == NULL)
2235     return NULL;
2236
2237   assistant = GTK_ASSISTANT (widget);
2238   priv = assistant->priv;
2239   n_pages = g_list_length (priv->pages);
2240
2241   if (index < 0)
2242     return NULL;
2243   else if (index < n_pages)
2244     {
2245       GtkAssistantPage *page = g_list_nth_data (priv->pages, index);
2246
2247       child = page->page;
2248       title = gtk_assistant_get_page_title (assistant, child);
2249     }
2250   else if (index == n_pages)
2251     {
2252       child = priv->action_area;
2253       title = NULL;
2254     }
2255   else
2256     return NULL;
2257
2258   obj = gtk_widget_get_accessible (child);
2259
2260   if (title)
2261     atk_object_set_name (obj, title);
2262
2263   return g_object_ref (obj);
2264 }
2265
2266 static void
2267 _gtk_assistant_accessible_class_init (GtkAssistantAccessibleClass *klass)
2268 {
2269   AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
2270
2271   atk_class->get_n_children = gtk_assistant_accessible_get_n_children;
2272   atk_class->ref_child = gtk_assistant_accessible_ref_child;
2273 }
2274
2275 static void
2276 _gtk_assistant_accessible_init (GtkAssistantAccessible *self)
2277 {
2278 }
2279
2280 /* factory */
2281 typedef AtkObjectFactory        GtkAssistantAccessibleFactory;
2282 typedef AtkObjectFactoryClass   GtkAssistantAccessibleFactoryClass;
2283
2284 G_DEFINE_TYPE (GtkAssistantAccessibleFactory,
2285                gtk_assistant_accessible_factory,
2286                ATK_TYPE_OBJECT_FACTORY);
2287
2288 static GType
2289 gtk_assistant_accessible_factory_get_accessible_type (void)
2290 {
2291   return _gtk_assistant_accessible_get_type ();
2292 }
2293
2294 static AtkObject*
2295 gtk_assistant_accessible_factory_create_accessible (GObject *obj)
2296 {
2297   AtkObject *accessible;
2298
2299   accessible = g_object_new (_gtk_assistant_accessible_get_type (), NULL);
2300   atk_object_initialize (accessible, obj);
2301
2302   return accessible;
2303 }
2304
2305 static void
2306 gtk_assistant_accessible_factory_class_init (AtkObjectFactoryClass *class)
2307 {
2308   class->create_accessible = gtk_assistant_accessible_factory_create_accessible;
2309   class->get_accessible_type = gtk_assistant_accessible_factory_get_accessible_type;
2310 }
2311
2312 static void
2313 gtk_assistant_accessible_factory_init (AtkObjectFactory *factory)
2314 {
2315 }
2316
2317 /* buildable implementation */
2318
2319 static GtkBuildableIface *parent_buildable_iface;
2320
2321 static void
2322 gtk_assistant_buildable_interface_init (GtkBuildableIface *iface)
2323 {
2324   parent_buildable_iface = g_type_interface_peek_parent (iface);
2325   iface->get_internal_child = gtk_assistant_buildable_get_internal_child;
2326   iface->custom_tag_start = gtk_assistant_buildable_custom_tag_start;
2327   iface->custom_finished = gtk_assistant_buildable_custom_finished;
2328 }
2329
2330 static GObject *
2331 gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
2332                                             GtkBuilder   *builder,
2333                                             const gchar  *childname)
2334 {
2335     if (strcmp (childname, "action_area") == 0)
2336       return G_OBJECT (GTK_ASSISTANT (buildable)->priv->action_area);
2337
2338     return parent_buildable_iface->get_internal_child (buildable,
2339                                                        builder,
2340                                                        childname);
2341 }
2342
2343 gboolean
2344 gtk_assistant_buildable_custom_tag_start (GtkBuildable  *buildable,
2345                                           GtkBuilder    *builder,
2346                                           GObject       *child,
2347                                           const gchar   *tagname,
2348                                           GMarkupParser *parser,
2349                                           gpointer      *data)
2350 {
2351   return parent_buildable_iface->custom_tag_start (buildable, builder, child,
2352                                                    tagname, parser, data);
2353 }
2354
2355 static void
2356 gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
2357                                          GtkBuilder   *builder,
2358                                          GObject      *child,
2359                                          const gchar  *tagname,
2360                                          gpointer      user_data)
2361 {
2362   parent_buildable_iface->custom_finished (buildable, builder, child,
2363                                            tagname, user_data);
2364 }