]> Pileus Git - ~andy/gtk/blob - gtk/gtkassistant.c
gtk_assistant_remove_page() docs: Fix typo.
[~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 "gtkbutton.h"
66 #include "gtkbox.h"
67 #include "gtkframe.h"
68 #include "gtknotebook.h"
69 #include "gtkimage.h"
70 #include "gtklabel.h"
71 #include "gtksizegroup.h"
72 #include "gtksizerequest.h"
73 #include "gtkstock.h"
74 #include "gtktypebuiltins.h"
75 #include "gtkintl.h"
76 #include "gtkprivate.h"
77 #include "gtkbuildable.h"
78 #include "a11y/gtkwindowaccessible.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 void       gtk_assistant_buildable_interface_init     (GtkBuildableIface *iface);
153 static GObject   *gtk_assistant_buildable_get_internal_child (GtkBuildable  *buildable,
154                                                               GtkBuilder    *builder,
155                                                               const gchar   *childname);
156 static gboolean   gtk_assistant_buildable_custom_tag_start   (GtkBuildable  *buildable,
157                                                               GtkBuilder    *builder,
158                                                               GObject       *child,
159                                                               const gchar   *tagname,
160                                                               GMarkupParser *parser,
161                                                               gpointer      *data);
162 static void       gtk_assistant_buildable_custom_finished    (GtkBuildable  *buildable,
163                                                               GtkBuilder    *builder,
164                                                               GObject       *child,
165                                                               const gchar   *tagname,
166                                                               gpointer       user_data);
167
168 static GList*     find_page                                  (GtkAssistant  *assistant,
169                                                               GtkWidget     *page);
170
171 GType             _gtk_assistant_accessible_get_type         (void);
172
173 enum
174 {
175   CHILD_PROP_0,
176   CHILD_PROP_PAGE_TYPE,
177   CHILD_PROP_PAGE_TITLE,
178   CHILD_PROP_PAGE_HEADER_IMAGE,
179   CHILD_PROP_PAGE_SIDEBAR_IMAGE,
180   CHILD_PROP_PAGE_COMPLETE
181 };
182
183 enum
184 {
185   CANCEL,
186   PREPARE,
187   APPLY,
188   CLOSE,
189   LAST_SIGNAL
190 };
191
192 static guint signals [LAST_SIGNAL] = { 0 };
193
194
195 G_DEFINE_TYPE_WITH_CODE (GtkAssistant, gtk_assistant, GTK_TYPE_WINDOW,
196                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
197                                                 gtk_assistant_buildable_interface_init))
198
199
200 static void
201 gtk_assistant_class_init (GtkAssistantClass *class)
202 {
203   GObjectClass *gobject_class;
204   GtkWidgetClass *widget_class;
205   GtkContainerClass *container_class;
206
207   gobject_class   = (GObjectClass *) class;
208   widget_class    = (GtkWidgetClass *) class;
209   container_class = (GtkContainerClass *) class;
210
211   widget_class->destroy = gtk_assistant_destroy;
212   widget_class->map = gtk_assistant_map;
213   widget_class->unmap = gtk_assistant_unmap;
214   widget_class->delete_event = gtk_assistant_delete_event;
215
216   gtk_widget_class_set_accessible_type (widget_class, _gtk_assistant_accessible_get_type ());
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 on_page_notify_visibility (GtkWidget  *widget,
868                            GParamSpec *arg,
869                            gpointer    data)
870 {
871   GtkAssistant *assistant = GTK_ASSISTANT (data);
872
873   if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
874     {
875       update_buttons_state (assistant);
876       update_title_state (assistant);
877     }
878 }
879
880 static void
881 assistant_remove_page_cb (GtkNotebook *notebook,
882                           GtkWidget *page,
883                           GtkAssistant *assistant)
884 {
885   GtkAssistantPrivate *priv = assistant->priv;
886   GtkAssistantPage *page_info;
887   GList *page_node;
888   GList *element;
889
890   element = find_page (assistant, page);
891   if (!element)
892     return;
893
894   page_info = element->data;
895
896   /* If this is the current page, we need to switch away. */
897   if (page_info == priv->current_page)
898     {
899       if (!compute_next_step (assistant))
900         {
901           /* The best we can do at this point is probably to pick
902            * the first visible page.
903            */
904           page_node = priv->pages;
905
906           while (page_node &&
907                  !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
908             page_node = page_node->next;
909
910           if (page_node == element)
911             page_node = page_node->next;
912
913           if (page_node)
914             priv->current_page = page_node->data;
915           else
916             priv->current_page = NULL;
917         }
918     }
919
920   g_signal_handlers_disconnect_by_func (page_info->page, on_page_notify_visibility, assistant);
921
922   gtk_size_group_remove_widget (priv->title_size_group, page_info->regular_title);
923   gtk_size_group_remove_widget (priv->title_size_group, page_info->current_title);
924
925   gtk_container_remove (GTK_CONTAINER (priv->sidebar), page_info->regular_title);
926   gtk_container_remove (GTK_CONTAINER (priv->sidebar), page_info->current_title);
927
928   priv->pages = g_list_remove_link (priv->pages, element);
929   priv->visited_pages = g_slist_remove_all (priv->visited_pages, page_info);
930
931   g_free (page_info->title);
932
933   g_slice_free (GtkAssistantPage, page_info);
934   g_list_free_1 (element);
935
936   if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
937     {
938       update_buttons_state (assistant);
939       update_actions_size (assistant);
940     }
941 }
942
943 static void
944 gtk_assistant_init (GtkAssistant *assistant)
945 {
946   GtkAssistantPrivate *priv;
947   GtkStyleContext *context;
948   GtkWidget *main_box;
949   GtkWidget *content_box;
950   GtkWidget *sidebar_frame;
951
952   assistant->priv = G_TYPE_INSTANCE_GET_PRIVATE (assistant,
953                                                  GTK_TYPE_ASSISTANT,
954                                                  GtkAssistantPrivate);
955   priv = assistant->priv;
956
957   /* use border on inner panes instead */
958   gtk_container_set_border_width (GTK_CONTAINER (assistant), 0);
959
960   gtk_widget_push_composite_child ();
961
962   main_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
963   priv->sidebar = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
964
965   /* use a frame for the sidebar, and manually render a background
966    * in it. GtkFrame also gives us padding support for free.
967    */
968   sidebar_frame = gtk_frame_new (NULL);
969   context = gtk_widget_get_style_context (sidebar_frame);
970   gtk_style_context_add_class (context, GTK_STYLE_CLASS_SIDEBAR);
971
972   g_signal_connect (sidebar_frame, "draw",
973                     G_CALLBACK (assistant_sidebar_draw_cb), assistant);
974
975   content_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
976   gtk_container_set_border_width (GTK_CONTAINER (content_box), 12);
977   priv->content = gtk_notebook_new ();
978   gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->content), FALSE);
979   gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->content), FALSE);
980   priv->action_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
981
982   g_signal_connect (priv->content, "remove",
983                     G_CALLBACK (assistant_remove_page_cb), assistant);
984
985   gtk_container_add (GTK_CONTAINER (sidebar_frame), priv->sidebar);
986   gtk_box_pack_start (GTK_BOX (main_box), sidebar_frame, FALSE, FALSE, 0);
987   gtk_box_pack_start (GTK_BOX (main_box), content_box, TRUE, TRUE, 0);
988   gtk_box_pack_start (GTK_BOX (content_box), priv->content, TRUE, TRUE, 0);
989   gtk_box_pack_start (GTK_BOX (content_box), priv->action_area, FALSE, TRUE, 0);
990   gtk_widget_set_halign (priv->action_area, GTK_ALIGN_END);
991
992   gtk_widget_show_all (main_box);
993
994   gtk_widget_set_parent (main_box, GTK_WIDGET (assistant));
995   _gtk_bin_set_child (GTK_BIN (assistant), main_box);
996
997   priv->close   = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
998   priv->apply   = gtk_button_new_from_stock (GTK_STOCK_APPLY);
999   priv->forward = gtk_button_new_with_mnemonic (_("C_ontinue"));
1000   gtk_button_set_image (GTK_BUTTON (priv->forward),
1001       gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD, GTK_ICON_SIZE_BUTTON));
1002   priv->back    = gtk_button_new_with_mnemonic (_("Go _Back"));
1003   gtk_button_set_image (GTK_BUTTON (priv->forward),
1004       gtk_image_new_from_stock (GTK_STOCK_GO_BACK, GTK_ICON_SIZE_BUTTON));
1005   priv->cancel  = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
1006   priv->last    = gtk_button_new_with_mnemonic (_("_Finish"));
1007   gtk_button_set_image (GTK_BUTTON (priv->forward),
1008       gtk_image_new_from_stock (GTK_STOCK_GOTO_LAST, GTK_ICON_SIZE_BUTTON));
1009   gtk_widget_set_can_default (priv->close, TRUE);
1010   gtk_widget_set_can_default (priv->apply, TRUE);
1011   gtk_widget_set_can_default (priv->forward, TRUE);
1012
1013   priv->button_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
1014   gtk_size_group_add_widget (priv->button_size_group, priv->close);
1015   gtk_size_group_add_widget (priv->button_size_group, priv->apply);
1016   gtk_size_group_add_widget (priv->button_size_group, priv->forward);
1017   gtk_size_group_add_widget (priv->button_size_group, priv->back);
1018   gtk_size_group_add_widget (priv->button_size_group, priv->cancel);
1019   gtk_size_group_add_widget (priv->button_size_group, priv->last);
1020
1021   if (!alternative_button_order (assistant))
1022     {
1023       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
1024       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
1025       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
1026       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
1027       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
1028       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->close, FALSE, FALSE, 0);
1029     }
1030   else
1031     {
1032       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->close, FALSE, FALSE, 0);
1033       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
1034       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
1035       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
1036       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
1037       gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
1038     }
1039
1040   gtk_widget_show (priv->forward);
1041   gtk_widget_show (priv->back);
1042   gtk_widget_show (priv->cancel);
1043   gtk_widget_show (priv->action_area);
1044
1045   gtk_widget_pop_composite_child ();
1046
1047   priv->title_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
1048
1049   priv->pages = NULL;
1050   priv->current_page = NULL;
1051   priv->visited_pages = NULL;
1052
1053   priv->forward_function = default_forward_function;
1054   priv->forward_function_data = assistant;
1055   priv->forward_data_destroy = NULL;
1056
1057   g_signal_connect (G_OBJECT (priv->close), "clicked",
1058                     G_CALLBACK (on_assistant_close), assistant);
1059   g_signal_connect (G_OBJECT (priv->apply), "clicked",
1060                     G_CALLBACK (on_assistant_apply), assistant);
1061   g_signal_connect (G_OBJECT (priv->forward), "clicked",
1062                     G_CALLBACK (on_assistant_forward), assistant);
1063   g_signal_connect (G_OBJECT (priv->back), "clicked",
1064                     G_CALLBACK (on_assistant_back), assistant);
1065   g_signal_connect (G_OBJECT (priv->cancel), "clicked",
1066                     G_CALLBACK (on_assistant_cancel), assistant);
1067   g_signal_connect (G_OBJECT (priv->last), "clicked",
1068                     G_CALLBACK (on_assistant_last), assistant);
1069 }
1070
1071 static void
1072 gtk_assistant_set_child_property (GtkContainer *container,
1073                                   GtkWidget    *child,
1074                                   guint         property_id,
1075                                   const GValue *value,
1076                                   GParamSpec   *pspec)
1077 {
1078   switch (property_id)
1079     {
1080     case CHILD_PROP_PAGE_TYPE:
1081       gtk_assistant_set_page_type (GTK_ASSISTANT (container), child,
1082                                    g_value_get_enum (value));
1083       break;
1084     case CHILD_PROP_PAGE_TITLE:
1085       gtk_assistant_set_page_title (GTK_ASSISTANT (container), child,
1086                                     g_value_get_string (value));
1087       break;
1088     case CHILD_PROP_PAGE_HEADER_IMAGE:
1089       gtk_assistant_set_page_header_image (GTK_ASSISTANT (container), child,
1090                                            g_value_get_object (value));
1091       break;
1092     case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
1093       gtk_assistant_set_page_side_image (GTK_ASSISTANT (container), child,
1094                                          g_value_get_object (value));
1095       break;
1096     case CHILD_PROP_PAGE_COMPLETE:
1097       gtk_assistant_set_page_complete (GTK_ASSISTANT (container), child,
1098                                        g_value_get_boolean (value));
1099       break;
1100     default:
1101       GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
1102       break;
1103     }
1104 }
1105
1106 static void
1107 gtk_assistant_get_child_property (GtkContainer *container,
1108                                   GtkWidget    *child,
1109                                   guint         property_id,
1110                                   GValue       *value,
1111                                   GParamSpec   *pspec)
1112 {
1113   switch (property_id)
1114     {
1115     case CHILD_PROP_PAGE_TYPE:
1116       g_value_set_enum (value,
1117                         gtk_assistant_get_page_type (GTK_ASSISTANT (container), child));
1118       break;
1119     case CHILD_PROP_PAGE_TITLE:
1120       g_value_set_string (value,
1121                           gtk_assistant_get_page_title (GTK_ASSISTANT (container), child));
1122       break;
1123     case CHILD_PROP_PAGE_HEADER_IMAGE:
1124       g_value_set_object (value,
1125                           gtk_assistant_get_page_header_image (GTK_ASSISTANT (container), child));
1126       break;
1127     case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
1128       g_value_set_object (value,
1129                           gtk_assistant_get_page_side_image (GTK_ASSISTANT (container), child));
1130       break;
1131     case CHILD_PROP_PAGE_COMPLETE:
1132       g_value_set_boolean (value,
1133                            gtk_assistant_get_page_complete (GTK_ASSISTANT (container), child));
1134       break;
1135     default:
1136       GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
1137       break;
1138     }
1139 }
1140
1141 static void
1142 gtk_assistant_destroy (GtkWidget *widget)
1143 {
1144   GtkAssistant *assistant = GTK_ASSISTANT (widget);
1145   GtkAssistantPrivate *priv = assistant->priv;
1146
1147   /* We set current to NULL so that the remove code doesn't try
1148    * to do anything funny
1149    */
1150   priv->current_page = NULL;
1151
1152   if (priv->content)
1153     {
1154       GtkNotebook *notebook;
1155       GtkWidget *page;
1156
1157       /* Remove all pages from the content notebook. */
1158       notebook = (GtkNotebook *) priv->content;
1159       while ((page = gtk_notebook_get_nth_page (notebook, 0)) != NULL)
1160         gtk_container_remove ((GtkContainer *) notebook, page);
1161
1162       /* Our GtkAssistantPage list should be empty now. */
1163       g_warn_if_fail (priv->pages == NULL);
1164
1165       priv->content = NULL;
1166     }
1167
1168   if (priv->sidebar)
1169     priv->sidebar = NULL;
1170
1171   if (priv->action_area)
1172     priv->action_area = NULL;
1173
1174   if (priv->button_size_group)
1175     {
1176       g_object_unref (priv->button_size_group);
1177       priv->button_size_group = NULL;
1178     }
1179
1180   if (priv->title_size_group)
1181     {
1182       g_object_unref (priv->title_size_group);
1183       priv->title_size_group = NULL;
1184     }
1185
1186   if (priv->forward_function)
1187     {
1188       if (priv->forward_function_data &&
1189           priv->forward_data_destroy)
1190         priv->forward_data_destroy (priv->forward_function_data);
1191
1192       priv->forward_function = NULL;
1193       priv->forward_function_data = NULL;
1194       priv->forward_data_destroy = NULL;
1195     }
1196
1197   if (priv->visited_pages)
1198     {
1199       g_slist_free (priv->visited_pages);
1200       priv->visited_pages = NULL;
1201     }
1202
1203   GTK_WIDGET_CLASS (gtk_assistant_parent_class)->destroy (widget);
1204 }
1205
1206 static GList*
1207 find_page (GtkAssistant  *assistant,
1208            GtkWidget     *page)
1209 {
1210   GtkAssistantPrivate *priv = assistant->priv;
1211   GList *child = priv->pages;
1212
1213   while (child)
1214     {
1215       GtkAssistantPage *page_info = child->data;
1216       if (page_info->page == page)
1217         return child;
1218
1219       child = child->next;
1220     }
1221
1222   return NULL;
1223 }
1224
1225 static void
1226 gtk_assistant_map (GtkWidget *widget)
1227 {
1228   GtkAssistant *assistant = GTK_ASSISTANT (widget);
1229   GtkAssistantPrivate *priv = assistant->priv;
1230   GList *page_node;
1231   GtkAssistantPage *page;
1232   gint page_num;
1233
1234   /* if there's no default page, pick the first one */
1235   page = NULL;
1236   page_num = 0;
1237   if (!priv->current_page)
1238     {
1239       page_node = priv->pages;
1240
1241       while (page_node && !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
1242         {
1243           page_node = page_node->next;
1244           page_num++;
1245         }
1246
1247       if (page_node)
1248         page = page_node->data;
1249     }
1250
1251   if (page && gtk_widget_get_visible (page->page))
1252     set_current_page (assistant, page_num);
1253
1254   update_buttons_state (assistant);
1255   update_actions_size (assistant);
1256   update_title_state (assistant);
1257
1258   GTK_WIDGET_CLASS (gtk_assistant_parent_class)->map (widget);
1259 }
1260
1261 static void
1262 gtk_assistant_unmap (GtkWidget *widget)
1263 {
1264   GtkAssistant *assistant = GTK_ASSISTANT (widget);
1265   GtkAssistantPrivate *priv = assistant->priv;
1266
1267   g_slist_free (priv->visited_pages);
1268   priv->visited_pages = NULL;
1269   priv->current_page  = NULL;
1270
1271   GTK_WIDGET_CLASS (gtk_assistant_parent_class)->unmap (widget);
1272 }
1273
1274 static gboolean
1275 gtk_assistant_delete_event (GtkWidget   *widget,
1276                             GdkEventAny *event)
1277 {
1278   GtkAssistant *assistant = GTK_ASSISTANT (widget);
1279   GtkAssistantPrivate *priv = assistant->priv;
1280
1281   /* Do not allow cancelling in the middle of a progress page */
1282   if (priv->current_page &&
1283       (priv->current_page->type != GTK_ASSISTANT_PAGE_PROGRESS ||
1284        priv->current_page->complete))
1285     g_signal_emit (widget, signals [CANCEL], 0, NULL);
1286
1287   return TRUE;
1288 }
1289
1290 static void
1291 gtk_assistant_add (GtkContainer *container,
1292                    GtkWidget    *page)
1293 {
1294   gtk_assistant_append_page (GTK_ASSISTANT (container), page);
1295 }
1296
1297 static void
1298 gtk_assistant_remove (GtkContainer *container,
1299                       GtkWidget    *page)
1300 {
1301   GtkAssistant *assistant = (GtkAssistant*) container;
1302
1303   /* Forward this removal to the content notebook */
1304   if (gtk_widget_get_parent (page) == assistant->priv->content)
1305     {
1306       container = (GtkContainer *) assistant->priv->content;
1307       gtk_container_remove (container, page);
1308     }
1309 }
1310
1311 /**
1312  * gtk_assistant_new:
1313  *
1314  * Creates a new #GtkAssistant.
1315  *
1316  * Return value: a newly created #GtkAssistant
1317  *
1318  * Since: 2.10
1319  */
1320 GtkWidget*
1321 gtk_assistant_new (void)
1322 {
1323   GtkWidget *assistant;
1324
1325   assistant = g_object_new (GTK_TYPE_ASSISTANT, NULL);
1326
1327   return assistant;
1328 }
1329
1330 /**
1331  * gtk_assistant_get_current_page:
1332  * @assistant: a #GtkAssistant
1333  *
1334  * Returns the page number of the current page.
1335  *
1336  * Return value: The index (starting from 0) of the current
1337  *     page in the @assistant, or -1 if the @assistant has no pages,
1338  *     or no current page.
1339  *
1340  * Since: 2.10
1341  */
1342 gint
1343 gtk_assistant_get_current_page (GtkAssistant *assistant)
1344 {
1345   GtkAssistantPrivate *priv;
1346
1347   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), -1);
1348
1349   priv = assistant->priv;
1350
1351   if (!priv->pages || !priv->current_page)
1352     return -1;
1353
1354   return g_list_index (priv->pages, priv->current_page);
1355 }
1356
1357 /**
1358  * gtk_assistant_set_current_page:
1359  * @assistant: a #GtkAssistant
1360  * @page_num: index of the page to switch to, starting from 0.
1361  *     If negative, the last page will be used. If greater
1362  *     than the number of pages in the @assistant, nothing
1363  *     will be done.
1364  *
1365  * Switches the page to @page_num.
1366  *
1367  * Note that this will only be necessary in custom buttons,
1368  * as the @assistant flow can be set with
1369  * gtk_assistant_set_forward_page_func().
1370  *
1371  * Since: 2.10
1372  */
1373 void
1374 gtk_assistant_set_current_page (GtkAssistant *assistant,
1375                                 gint          page_num)
1376 {
1377   GtkAssistantPrivate *priv;
1378   GtkAssistantPage *page;
1379
1380   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1381
1382   priv = assistant->priv;
1383
1384   if (page_num >= 0)
1385     page = (GtkAssistantPage *) g_list_nth_data (priv->pages, page_num);
1386   else
1387     {
1388       page = (GtkAssistantPage *) g_list_last (priv->pages)->data;
1389       page_num = g_list_length (priv->pages);
1390     }
1391
1392   g_return_if_fail (page != NULL);
1393
1394   if (priv->current_page == page)
1395     return;
1396
1397   /* only add the page to the visited list if the assistant is mapped,
1398    * if not, just use it as an initial page setting, for the cases where
1399    * the initial page is != to 0
1400    */
1401   if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1402     priv->visited_pages = g_slist_prepend (priv->visited_pages,
1403                                            priv->current_page);
1404
1405   set_current_page (assistant, page_num);
1406 }
1407
1408 /**
1409  * gtk_assistant_next_page:
1410  * @assistant: a #GtkAssistant
1411  *
1412  * Navigate to the next page.
1413  *
1414  * It is a programming error to call this function when
1415  * there is no next page.
1416  *
1417  * This function is for use when creating pages of the
1418  * #GTK_ASSISTANT_PAGE_CUSTOM type.
1419  *
1420  * Since: 3.0
1421  */
1422 void
1423 gtk_assistant_next_page (GtkAssistant *assistant)
1424 {
1425   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1426
1427   if (!compute_next_step (assistant))
1428     g_critical ("Page flow is broken.\n"
1429                 "You may want to end it with a page of type\n"
1430                 "GTK_ASSISTANT_PAGE_CONFIRM or GTK_ASSISTANT_PAGE_SUMMARY");
1431 }
1432
1433 /**
1434  * gtk_assistant_previous_page:
1435  * @assistant: a #GtkAssistant
1436  *
1437  * Navigate to the previous visited page.
1438  *
1439  * It is a programming error to call this function when
1440  * no previous page is available.
1441  *
1442  * This function is for use when creating pages of the
1443  * #GTK_ASSISTANT_PAGE_CUSTOM type.
1444  *
1445  * Since: 3.0
1446  */
1447 void
1448 gtk_assistant_previous_page (GtkAssistant *assistant)
1449 {
1450   GtkAssistantPrivate *priv;
1451   GtkAssistantPage *page_info;
1452   GSList *page_node;
1453
1454   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1455
1456   priv = assistant->priv;
1457
1458   /* skip the progress pages when going back */
1459   do
1460     {
1461       page_node = priv->visited_pages;
1462
1463       g_return_if_fail (page_node != NULL);
1464
1465       priv->visited_pages = priv->visited_pages->next;
1466       page_info = (GtkAssistantPage *) page_node->data;
1467       g_slist_free_1 (page_node);
1468     }
1469   while (page_info->type == GTK_ASSISTANT_PAGE_PROGRESS ||
1470          !gtk_widget_get_visible (page_info->page));
1471
1472   set_current_page (assistant, g_list_index (priv->pages, page_info));
1473 }
1474
1475 /**
1476  * gtk_assistant_get_n_pages:
1477  * @assistant: a #GtkAssistant
1478  *
1479  * Returns the number of pages in the @assistant
1480  *
1481  * Return value: the number of pages in the @assistant
1482  *
1483  * Since: 2.10
1484  */
1485 gint
1486 gtk_assistant_get_n_pages (GtkAssistant *assistant)
1487 {
1488   GtkAssistantPrivate *priv;
1489
1490   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1491
1492   priv = assistant->priv;
1493
1494   return g_list_length (priv->pages);
1495 }
1496
1497 /**
1498  * gtk_assistant_get_nth_page:
1499  * @assistant: a #GtkAssistant
1500  * @page_num: the index of a page in the @assistant,
1501  *     or -1 to get the last page
1502  *
1503  * Returns the child widget contained in page number @page_num.
1504  *
1505  * Return value: (transfer none): the child widget, or %NULL
1506  *     if @page_num is out of bounds
1507  *
1508  * Since: 2.10
1509  */
1510 GtkWidget*
1511 gtk_assistant_get_nth_page (GtkAssistant *assistant,
1512                             gint          page_num)
1513 {
1514   GtkAssistantPrivate *priv;
1515   GtkAssistantPage *page;
1516   GList *elem;
1517
1518   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1519   g_return_val_if_fail (page_num >= -1, NULL);
1520
1521   priv = assistant->priv;
1522
1523   if (page_num == -1)
1524     elem = g_list_last (priv->pages);
1525   else
1526     elem = g_list_nth (priv->pages, page_num);
1527
1528   if (!elem)
1529     return NULL;
1530
1531   page = (GtkAssistantPage *) elem->data;
1532
1533   return page->page;
1534 }
1535
1536 /**
1537  * gtk_assistant_prepend_page:
1538  * @assistant: a #GtkAssistant
1539  * @page: a #GtkWidget
1540  *
1541  * Prepends a page to the @assistant.
1542  *
1543  * Return value: the index (starting at 0) of the inserted page
1544  *
1545  * Since: 2.10
1546  */
1547 gint
1548 gtk_assistant_prepend_page (GtkAssistant *assistant,
1549                             GtkWidget    *page)
1550 {
1551   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1552   g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1553
1554   return gtk_assistant_insert_page (assistant, page, 0);
1555 }
1556
1557 /**
1558  * gtk_assistant_append_page:
1559  * @assistant: a #GtkAssistant
1560  * @page: a #GtkWidget
1561  *
1562  * Appends a page to the @assistant.
1563  *
1564  * Return value: the index (starting at 0) of the inserted page
1565  *
1566  * Since: 2.10
1567  */
1568 gint
1569 gtk_assistant_append_page (GtkAssistant *assistant,
1570                            GtkWidget    *page)
1571 {
1572   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1573   g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1574
1575   return gtk_assistant_insert_page (assistant, page, -1);
1576 }
1577
1578 /**
1579  * gtk_assistant_insert_page:
1580  * @assistant: a #GtkAssistant
1581  * @page: a #GtkWidget
1582  * @position: the index (starting at 0) at which to insert the page,
1583  *     or -1 to append the page to the @assistant
1584  *
1585  * Inserts a page in the @assistant at a given position.
1586  *
1587  * Return value: the index (starting from 0) of the inserted page
1588  *
1589  * Since: 2.10
1590  */
1591 gint
1592 gtk_assistant_insert_page (GtkAssistant *assistant,
1593                            GtkWidget    *page,
1594                            gint          position)
1595 {
1596   GtkAssistantPrivate *priv;
1597   GtkAssistantPage *page_info;
1598   gint n_pages;
1599   GtkStyleContext *context;
1600
1601   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1602   g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1603   g_return_val_if_fail (gtk_widget_get_parent (page) == NULL, 0);
1604   g_return_val_if_fail (!gtk_widget_is_toplevel (page), 0);
1605
1606   priv = assistant->priv;
1607
1608   page_info = g_slice_new0 (GtkAssistantPage);
1609   page_info->page  = page;
1610   page_info->regular_title = gtk_label_new (NULL);
1611   page_info->current_title = gtk_label_new (NULL);
1612
1613   /* Note: we need to use misc alignment here as long as GtkLabel
1614    * pays attention to it. GtkWiget::halign is ineffective, since
1615    * all the labels are getting the same size anyway, due to the
1616    * size group.
1617    */
1618   gtk_misc_set_alignment (GTK_MISC (page_info->regular_title), 0, 0.5);
1619   gtk_widget_show (page_info->regular_title);
1620
1621   gtk_misc_set_alignment (GTK_MISC (page_info->current_title), 0, 0.5);
1622   gtk_widget_hide (page_info->current_title);
1623
1624   context = gtk_widget_get_style_context (page_info->current_title);
1625   gtk_style_context_add_class (context, GTK_STYLE_CLASS_HIGHLIGHT);
1626
1627   gtk_size_group_add_widget (priv->title_size_group, page_info->regular_title);
1628   gtk_size_group_add_widget (priv->title_size_group, page_info->current_title);
1629
1630   g_signal_connect (G_OBJECT (page), "notify::visible",
1631                     G_CALLBACK (on_page_notify_visibility), assistant);
1632
1633   n_pages = g_list_length (priv->pages);
1634
1635   if (position < 0 || position > n_pages)
1636     position = n_pages;
1637
1638   priv->pages = g_list_insert (priv->pages, page_info, position);
1639
1640   gtk_box_pack_start (GTK_BOX (priv->sidebar), page_info->regular_title, FALSE, FALSE, 0);
1641   gtk_box_pack_start (GTK_BOX (priv->sidebar), page_info->current_title, FALSE, FALSE, 0);
1642   gtk_box_reorder_child (GTK_BOX (priv->sidebar), page_info->regular_title, 2 * position);
1643   gtk_box_reorder_child (GTK_BOX (priv->sidebar), page_info->current_title, 2 * position + 1);
1644
1645   gtk_notebook_insert_page (GTK_NOTEBOOK (priv->content), page, NULL, position);
1646
1647   if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1648     {
1649       update_buttons_state (assistant);
1650       update_actions_size (assistant);
1651     }
1652
1653   return position;
1654 }
1655
1656 /**
1657  * gtk_assistant_remove_page:
1658  * @assistant: a #GtkAssistant
1659  * @page_num: the index of a page in the @assistant,
1660  *     or -1 to remove the last page
1661  *
1662  * Removes the @page_num's page from @assistant.
1663  *
1664  * Since: 3.2
1665  */
1666 void
1667 gtk_assistant_remove_page (GtkAssistant *assistant,
1668                            gint          page_num)
1669 {
1670   GtkWidget *page;
1671
1672   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1673
1674   page = gtk_assistant_get_nth_page (assistant, page_num);
1675
1676   if (page)
1677     gtk_container_remove (GTK_CONTAINER (assistant), page);
1678 }
1679
1680 /**
1681  * gtk_assistant_set_forward_page_func:
1682  * @assistant: a #GtkAssistant
1683  * @page_func: (allow-none): the #GtkAssistantPageFunc, or %NULL
1684  *     to use the default one
1685  * @data: user data for @page_func
1686  * @destroy: destroy notifier for @data
1687  *
1688  * Sets the page forwarding function to be @page_func.
1689  *
1690  * This function will be used to determine what will be
1691  * the next page when the user presses the forward button.
1692  * Setting @page_func to %NULL will make the assistant to
1693  * use the default forward function, which just goes to the
1694  * next visible page.
1695  *
1696  * Since: 2.10
1697  */
1698 void
1699 gtk_assistant_set_forward_page_func (GtkAssistant         *assistant,
1700                                      GtkAssistantPageFunc  page_func,
1701                                      gpointer              data,
1702                                      GDestroyNotify        destroy)
1703 {
1704   GtkAssistantPrivate *priv;
1705
1706   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1707
1708   priv = assistant->priv;
1709
1710   if (priv->forward_data_destroy &&
1711       priv->forward_function_data)
1712     (*priv->forward_data_destroy) (priv->forward_function_data);
1713
1714   if (page_func)
1715     {
1716       priv->forward_function = page_func;
1717       priv->forward_function_data = data;
1718       priv->forward_data_destroy = destroy;
1719     }
1720   else
1721     {
1722       priv->forward_function = default_forward_function;
1723       priv->forward_function_data = assistant;
1724       priv->forward_data_destroy = NULL;
1725     }
1726
1727   /* Page flow has possibly changed, so the
1728    * buttons state might need to change too
1729    */
1730   if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1731     update_buttons_state (assistant);
1732 }
1733
1734 /**
1735  * gtk_assistant_add_action_widget:
1736  * @assistant: a #GtkAssistant
1737  * @child: a #GtkWidget
1738  *
1739  * Adds a widget to the action area of a #GtkAssistant.
1740  *
1741  * Since: 2.10
1742  */
1743 void
1744 gtk_assistant_add_action_widget (GtkAssistant *assistant,
1745                                  GtkWidget    *child)
1746 {
1747   GtkAssistantPrivate *priv;
1748
1749   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1750   g_return_if_fail (GTK_IS_WIDGET (child));
1751
1752   priv = assistant->priv;
1753
1754   if (GTK_IS_BUTTON (child))
1755     {
1756       gtk_size_group_add_widget (priv->button_size_group, child);
1757       priv->extra_buttons += 1;
1758       if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1759         update_actions_size (assistant);
1760     }
1761
1762   gtk_box_pack_end (GTK_BOX (priv->action_area), child, FALSE, FALSE, 0);
1763 }
1764
1765 /**
1766  * gtk_assistant_remove_action_widget:
1767  * @assistant: a #GtkAssistant
1768  * @child: a #GtkWidget
1769  *
1770  * Removes a widget from the action area of a #GtkAssistant.
1771  *
1772  * Since: 2.10
1773  */
1774 void
1775 gtk_assistant_remove_action_widget (GtkAssistant *assistant,
1776                                     GtkWidget    *child)
1777 {
1778   GtkAssistantPrivate *priv;
1779
1780   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1781   g_return_if_fail (GTK_IS_WIDGET (child));
1782
1783   priv = assistant->priv;
1784
1785   if (GTK_IS_BUTTON (child))
1786     {
1787       gtk_size_group_remove_widget (priv->button_size_group, child);
1788       priv->extra_buttons -= 1;
1789       if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1790         update_actions_size (assistant);
1791     }
1792
1793   gtk_container_remove (GTK_CONTAINER (priv->action_area), child);
1794 }
1795
1796 /**
1797  * gtk_assistant_set_page_title:
1798  * @assistant: a #GtkAssistant
1799  * @page: a page of @assistant
1800  * @title: the new title for @page
1801  *
1802  * Sets a title for @page.
1803  *
1804  * The title is displayed in the header area of the assistant
1805  * when @page is the current page.
1806  *
1807  * Since: 2.10
1808  */
1809 void
1810 gtk_assistant_set_page_title (GtkAssistant *assistant,
1811                               GtkWidget    *page,
1812                               const gchar  *title)
1813 {
1814   GtkAssistantPage *page_info;
1815   GList *child;
1816
1817   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1818   g_return_if_fail (GTK_IS_WIDGET (page));
1819
1820   child = find_page (assistant, page);
1821
1822   g_return_if_fail (child != NULL);
1823
1824   page_info = (GtkAssistantPage*) child->data;
1825
1826   g_free (page_info->title);
1827   page_info->title = g_strdup (title);
1828
1829   gtk_label_set_text ((GtkLabel*) page_info->regular_title, title);
1830   gtk_label_set_text ((GtkLabel*) page_info->current_title, title);
1831
1832   gtk_widget_queue_resize (GTK_WIDGET (assistant));
1833   gtk_container_child_notify (GTK_CONTAINER (assistant), page, "title");
1834 }
1835
1836 /**
1837  * gtk_assistant_get_page_title:
1838  * @assistant: a #GtkAssistant
1839  * @page: a page of @assistant
1840  *
1841  * Gets the title for @page.
1842  *
1843  * Return value: the title for @page
1844  *
1845  * Since: 2.10
1846  */
1847 const gchar*
1848 gtk_assistant_get_page_title (GtkAssistant *assistant,
1849                               GtkWidget    *page)
1850 {
1851   GtkAssistantPage *page_info;
1852   GList *child;
1853
1854   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1855   g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1856
1857   child = find_page (assistant, page);
1858
1859   g_return_val_if_fail (child != NULL, NULL);
1860
1861   page_info = (GtkAssistantPage*) child->data;
1862
1863   return page_info->title;
1864 }
1865
1866 /**
1867  * gtk_assistant_set_page_type:
1868  * @assistant: a #GtkAssistant
1869  * @page: a page of @assistant
1870  * @type: the new type for @page
1871  *
1872  * Sets the page type for @page.
1873  *
1874  * The page type determines the page behavior in the @assistant.
1875  *
1876  * Since: 2.10
1877  */
1878 void
1879 gtk_assistant_set_page_type (GtkAssistant         *assistant,
1880                              GtkWidget            *page,
1881                              GtkAssistantPageType  type)
1882 {
1883   GtkAssistantPage *page_info;
1884   GList *child;
1885
1886   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1887   g_return_if_fail (GTK_IS_WIDGET (page));
1888
1889   child = find_page (assistant, page);
1890
1891   g_return_if_fail (child != NULL);
1892
1893   page_info = (GtkAssistantPage*) child->data;
1894
1895   if (type != page_info->type)
1896     {
1897       page_info->type = type;
1898
1899       /* backwards compatibility to the era before fixing bug 604289 */
1900       if (type == GTK_ASSISTANT_PAGE_SUMMARY && !page_info->complete_set)
1901         {
1902           gtk_assistant_set_page_complete (assistant, page, TRUE);
1903           page_info->complete_set = FALSE;
1904         }
1905
1906       /* Always set buttons state, a change in a future page
1907        * might change current page buttons
1908        */
1909       update_buttons_state (assistant);
1910
1911       gtk_container_child_notify (GTK_CONTAINER (assistant), page, "page-type");
1912     }
1913 }
1914
1915 /**
1916  * gtk_assistant_get_page_type:
1917  * @assistant: a #GtkAssistant
1918  * @page: a page of @assistant
1919  *
1920  * Gets the page type of @page.
1921  *
1922  * Return value: the page type of @page
1923  *
1924  * Since: 2.10
1925  */
1926 GtkAssistantPageType
1927 gtk_assistant_get_page_type (GtkAssistant *assistant,
1928                              GtkWidget    *page)
1929 {
1930   GtkAssistantPage *page_info;
1931   GList *child;
1932
1933   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), GTK_ASSISTANT_PAGE_CONTENT);
1934   g_return_val_if_fail (GTK_IS_WIDGET (page), GTK_ASSISTANT_PAGE_CONTENT);
1935
1936   child = find_page (assistant, page);
1937
1938   g_return_val_if_fail (child != NULL, GTK_ASSISTANT_PAGE_CONTENT);
1939
1940   page_info = (GtkAssistantPage*) child->data;
1941
1942   return page_info->type;
1943 }
1944
1945 /**
1946  * gtk_assistant_set_page_header_image:
1947  * @assistant: a #GtkAssistant
1948  * @page: a page of @assistant
1949  * @pixbuf: (allow-none): the new header image @page
1950  *
1951  * Sets a header image for @page.
1952  *
1953  * Since: 2.10
1954  *
1955  * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
1956  *     add your header decoration to the page content instead.
1957  */
1958 void
1959 gtk_assistant_set_page_header_image (GtkAssistant *assistant,
1960                                      GtkWidget    *page,
1961                                      GdkPixbuf    *pixbuf)
1962 {
1963   GtkAssistantPage *page_info;
1964   GList *child;
1965
1966   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1967   g_return_if_fail (GTK_IS_WIDGET (page));
1968   g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1969
1970   child = find_page (assistant, page);
1971
1972   g_return_if_fail (child != NULL);
1973
1974   page_info = (GtkAssistantPage*) child->data;
1975
1976   if (pixbuf != page_info->header_image)
1977     {
1978       if (page_info->header_image)
1979         {
1980           g_object_unref (page_info->header_image);
1981           page_info->header_image = NULL;
1982         }
1983
1984       if (pixbuf)
1985         page_info->header_image = g_object_ref (pixbuf);
1986
1987       gtk_container_child_notify (GTK_CONTAINER (assistant), page, "header-image");
1988     }
1989 }
1990
1991 /**
1992  * gtk_assistant_get_page_header_image:
1993  * @assistant: a #GtkAssistant
1994  * @page: a page of @assistant
1995  *
1996  * Gets the header image for @page.
1997  *
1998  * Return value: (transfer none): the header image for @page,
1999  *     or %NULL if there's no header image for the page
2000  *
2001  * Since: 2.10
2002  *
2003  * Deprecated: 3.2: Since GTK+ 3.2, a header is no longer shown;
2004  *     add your header decoration to the page content instead.
2005  */
2006 GdkPixbuf*
2007 gtk_assistant_get_page_header_image (GtkAssistant *assistant,
2008                                      GtkWidget    *page)
2009 {
2010   GtkAssistantPage *page_info;
2011   GList *child;
2012
2013   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2014   g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2015
2016   child = find_page (assistant, page);
2017
2018   g_return_val_if_fail (child != NULL, NULL);
2019
2020   page_info = (GtkAssistantPage*) child->data;
2021
2022   return page_info->header_image;
2023 }
2024
2025 /**
2026  * gtk_assistant_set_page_side_image:
2027  * @assistant: a #GtkAssistant
2028  * @page: a page of @assistant
2029  * @pixbuf: (allow-none): the new side image @page
2030  *
2031  * Sets a side image for @page.
2032  *
2033  * This image used to be displayed in the side area of the assistant
2034  * when @page is the current page.
2035  *
2036  * Since: 2.10
2037  *
2038  * Deprecated: 3.2: Since GTK+ 3.2, sidebar images are not
2039  *     shown anymore.
2040  */
2041 void
2042 gtk_assistant_set_page_side_image (GtkAssistant *assistant,
2043                                    GtkWidget    *page,
2044                                    GdkPixbuf    *pixbuf)
2045 {
2046   GtkAssistantPage *page_info;
2047   GList *child;
2048
2049   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2050   g_return_if_fail (GTK_IS_WIDGET (page));
2051   g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2052
2053   child = find_page (assistant, page);
2054
2055   g_return_if_fail (child != NULL);
2056
2057   page_info = (GtkAssistantPage*) child->data;
2058
2059   if (pixbuf != page_info->sidebar_image)
2060     {
2061       if (page_info->sidebar_image)
2062         {
2063           g_object_unref (page_info->sidebar_image);
2064           page_info->sidebar_image = NULL;
2065         }
2066
2067       if (pixbuf)
2068         page_info->sidebar_image = g_object_ref (pixbuf);
2069
2070       gtk_container_child_notify (GTK_CONTAINER (assistant), page, "sidebar-image");
2071     }
2072 }
2073
2074 /**
2075  * gtk_assistant_get_page_side_image:
2076  * @assistant: a #GtkAssistant
2077  * @page: a page of @assistant
2078  *
2079  * Gets the side image for @page.
2080  *
2081  * Return value: (transfer none): the side image for @page,
2082  *     or %NULL if there's no side image for the page
2083  *
2084  * Since: 2.10
2085  *
2086  * Deprecated: 3.2: Since GTK+ 3.2, sidebar images are not
2087  *     shown anymore.
2088  */
2089 GdkPixbuf*
2090 gtk_assistant_get_page_side_image (GtkAssistant *assistant,
2091                                    GtkWidget    *page)
2092 {
2093   GtkAssistantPage *page_info;
2094   GList *child;
2095
2096   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2097   g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2098
2099   child = find_page (assistant, page);
2100
2101   g_return_val_if_fail (child != NULL, NULL);
2102
2103   page_info = (GtkAssistantPage*) child->data;
2104
2105   return page_info->sidebar_image;
2106 }
2107
2108 /**
2109  * gtk_assistant_set_page_complete:
2110  * @assistant: a #GtkAssistant
2111  * @page: a page of @assistant
2112  * @complete: the completeness status of the page
2113  *
2114  * Sets whether @page contents are complete.
2115  *
2116  * This will make @assistant update the buttons state
2117  * to be able to continue the task.
2118  *
2119  * Since: 2.10
2120  */
2121 void
2122 gtk_assistant_set_page_complete (GtkAssistant *assistant,
2123                                  GtkWidget    *page,
2124                                  gboolean      complete)
2125 {
2126   GtkAssistantPage *page_info;
2127   GList *child;
2128
2129   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2130   g_return_if_fail (GTK_IS_WIDGET (page));
2131
2132   child = find_page (assistant, page);
2133
2134   g_return_if_fail (child != NULL);
2135
2136   page_info = (GtkAssistantPage*) child->data;
2137
2138   if (complete != page_info->complete)
2139     {
2140       page_info->complete = complete;
2141       page_info->complete_set = TRUE;
2142
2143       /* Always set buttons state, a change in a future page
2144        * might change current page buttons
2145        */
2146       update_buttons_state (assistant);
2147
2148       gtk_container_child_notify (GTK_CONTAINER (assistant), page, "complete");
2149     }
2150 }
2151
2152 /**
2153  * gtk_assistant_get_page_complete:
2154  * @assistant: a #GtkAssistant
2155  * @page: a page of @assistant
2156  *
2157  * Gets whether @page is complete.
2158  *
2159  * Return value: %TRUE if @page is complete.
2160  *
2161  * Since: 2.10
2162  */
2163 gboolean
2164 gtk_assistant_get_page_complete (GtkAssistant *assistant,
2165                                  GtkWidget    *page)
2166 {
2167   GtkAssistantPage *page_info;
2168   GList *child;
2169
2170   g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), FALSE);
2171   g_return_val_if_fail (GTK_IS_WIDGET (page), FALSE);
2172
2173   child = find_page (assistant, page);
2174
2175   g_return_val_if_fail (child != NULL, FALSE);
2176
2177   page_info = (GtkAssistantPage*) child->data;
2178
2179   return page_info->complete;
2180 }
2181
2182 /**
2183  * gtk_assistant_update_buttons_state:
2184  * @assistant: a #GtkAssistant
2185  *
2186  * Forces @assistant to recompute the buttons state.
2187  *
2188  * GTK+ automatically takes care of this in most situations,
2189  * e.g. when the user goes to a different page, or when the
2190  * visibility or completeness of a page changes.
2191  *
2192  * One situation where it can be necessary to call this
2193  * function is when changing a value on the current page
2194  * affects the future page flow of the assistant.
2195  *
2196  * Since: 2.10
2197  */
2198 void
2199 gtk_assistant_update_buttons_state (GtkAssistant *assistant)
2200 {
2201   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2202
2203   update_buttons_state (assistant);
2204 }
2205
2206 /**
2207  * gtk_assistant_commit:
2208  * @assistant: a #GtkAssistant
2209  *
2210  * Erases the visited page history so the back button is not
2211  * shown on the current page, and removes the cancel button
2212  * from subsequent pages.
2213  *
2214  * Use this when the information provided up to the current
2215  * page is hereafter deemed permanent and cannot be modified
2216  * or undone. For example, showing a progress page to track
2217  * a long-running, unreversible operation after the user has
2218  * clicked apply on a confirmation page.
2219  *
2220  * Since: 2.22
2221  */
2222 void
2223 gtk_assistant_commit (GtkAssistant *assistant)
2224 {
2225   g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2226
2227   g_slist_free (assistant->priv->visited_pages);
2228   assistant->priv->visited_pages = NULL;
2229
2230   assistant->priv->committed = TRUE;
2231
2232   update_buttons_state (assistant);
2233 }
2234
2235 /* accessible implementation */
2236
2237 /* dummy typedefs */
2238 typedef GtkWindowAccessible      GtkAssistantAccessible;
2239 typedef GtkWindowAccessibleClass GtkAssistantAccessibleClass;
2240
2241 G_DEFINE_TYPE (GtkAssistantAccessible, _gtk_assistant_accessible, GTK_TYPE_WINDOW_ACCESSIBLE);
2242
2243 static gint
2244 gtk_assistant_accessible_get_n_children (AtkObject *accessible)
2245 {
2246   GtkWidget *widget;
2247
2248   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2249   if (widget == NULL)
2250     return 0;
2251
2252   return g_list_length (GTK_ASSISTANT (widget)->priv->pages) + 1;
2253 }
2254
2255 static AtkObject *
2256 gtk_assistant_accessible_ref_child (AtkObject *accessible,
2257                                     gint       index)
2258 {
2259   GtkAssistant *assistant;
2260   GtkAssistantPrivate *priv;
2261   GtkWidget *widget, *child;
2262   gint n_pages;
2263   AtkObject *obj;
2264   const gchar *title;
2265
2266   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2267   if (widget == NULL)
2268     return NULL;
2269
2270   assistant = GTK_ASSISTANT (widget);
2271   priv = assistant->priv;
2272   n_pages = g_list_length (priv->pages);
2273
2274   if (index < 0)
2275     return NULL;
2276   else if (index < n_pages)
2277     {
2278       GtkAssistantPage *page = g_list_nth_data (priv->pages, index);
2279
2280       child = page->page;
2281       title = gtk_assistant_get_page_title (assistant, child);
2282     }
2283   else if (index == n_pages)
2284     {
2285       child = priv->action_area;
2286       title = NULL;
2287     }
2288   else
2289     return NULL;
2290
2291   obj = gtk_widget_get_accessible (child);
2292
2293   if (title)
2294     atk_object_set_name (obj, title);
2295
2296   return g_object_ref (obj);
2297 }
2298
2299 static void
2300 _gtk_assistant_accessible_class_init (GtkAssistantAccessibleClass *klass)
2301 {
2302   AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
2303
2304   atk_class->get_n_children = gtk_assistant_accessible_get_n_children;
2305   atk_class->ref_child = gtk_assistant_accessible_ref_child;
2306 }
2307
2308 static void
2309 _gtk_assistant_accessible_init (GtkAssistantAccessible *self)
2310 {
2311 }
2312
2313 /* buildable implementation */
2314
2315 static GtkBuildableIface *parent_buildable_iface;
2316
2317 static void
2318 gtk_assistant_buildable_interface_init (GtkBuildableIface *iface)
2319 {
2320   parent_buildable_iface = g_type_interface_peek_parent (iface);
2321   iface->get_internal_child = gtk_assistant_buildable_get_internal_child;
2322   iface->custom_tag_start = gtk_assistant_buildable_custom_tag_start;
2323   iface->custom_finished = gtk_assistant_buildable_custom_finished;
2324 }
2325
2326 static GObject *
2327 gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
2328                                             GtkBuilder   *builder,
2329                                             const gchar  *childname)
2330 {
2331     if (strcmp (childname, "action_area") == 0)
2332       return G_OBJECT (GTK_ASSISTANT (buildable)->priv->action_area);
2333
2334     return parent_buildable_iface->get_internal_child (buildable,
2335                                                        builder,
2336                                                        childname);
2337 }
2338
2339 gboolean
2340 gtk_assistant_buildable_custom_tag_start (GtkBuildable  *buildable,
2341                                           GtkBuilder    *builder,
2342                                           GObject       *child,
2343                                           const gchar   *tagname,
2344                                           GMarkupParser *parser,
2345                                           gpointer      *data)
2346 {
2347   return parent_buildable_iface->custom_tag_start (buildable, builder, child,
2348                                                    tagname, parser, data);
2349 }
2350
2351 static void
2352 gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
2353                                          GtkBuilder   *builder,
2354                                          GObject      *child,
2355                                          const gchar  *tagname,
2356                                          gpointer      user_data)
2357 {
2358   parent_buildable_iface->custom_finished (buildable, builder, child,
2359                                            tagname, user_data);
2360 }