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