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