2 * GTK - The GIMP Toolkit
3 * Copyright (C) 1999 Red Hat, Inc.
4 * Copyright (C) 2002 Anders Carlsson <andersca@gnu.org>
5 * Copyright (C) 2003 Matthias Clasen <mclasen@redhat.com>
6 * Copyright (C) 2005 Carlos Garnacho Parro <carlosg@gnome.org>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
27 * SECTION:gtkassistant
28 * @Short_description: A widget used to guide users through multi-step operations
29 * @Title: GtkAssistant
31 * A #GtkAssistant is a widget used to represent a generally complex
32 * operation splitted in several steps, guiding the user through its pages
33 * and controlling the page flow to collect the necessary data.
35 * <refsect2 id="GtkAssistant-BUILDER-UI">
36 * <title>GtkAssistant as GtkBuildable</title>
38 * The GtkAssistant implementation of the GtkBuildable interface exposes the
39 * @action_area as internal children with the name "action_area".
41 * To add pages to an assistant in GtkBuilder, simply add it as a
42 * <child> to the GtkAssistant object, and set its child properties
52 #include "gtkassistant.h"
54 #include "gtkaccessible.h"
55 #include "gtkbutton.h"
60 #include "gtksizegroup.h"
61 #include "gtksizerequest.h"
65 #include "gtkprivate.h"
66 #include "gtkbuildable.h"
69 #define HEADER_SPACING 12
70 #define ACTION_AREA_SPACING 12
72 typedef struct _GtkAssistantPage GtkAssistantPage;
74 struct _GtkAssistantPage
77 GtkAssistantPageType type;
79 guint complete_set : 1;
82 GdkPixbuf *header_image;
83 GdkPixbuf *sidebar_image;
86 struct _GtkAssistantPrivate
95 GtkWidget *header_image;
96 GtkWidget *sidebar_image;
98 GtkWidget *action_area;
102 GtkAssistantPage *current_page;
104 GSList *visited_pages;
106 GtkSizeGroup *size_group;
108 GtkAssistantPageFunc forward_function;
109 gpointer forward_function_data;
110 GDestroyNotify forward_data_destroy;
115 static void gtk_assistant_class_init (GtkAssistantClass *class);
116 static void gtk_assistant_init (GtkAssistant *assistant);
117 static void gtk_assistant_destroy (GtkWidget *widget);
118 static void gtk_assistant_style_set (GtkWidget *widget,
119 GtkStyle *old_style);
120 static void gtk_assistant_size_request (GtkWidget *widget,
121 GtkRequisition *requisition);
122 static void gtk_assistant_size_allocate (GtkWidget *widget,
123 GtkAllocation *allocation);
124 static void gtk_assistant_map (GtkWidget *widget);
125 static void gtk_assistant_unmap (GtkWidget *widget);
126 static gboolean gtk_assistant_delete_event (GtkWidget *widget,
128 static gboolean gtk_assistant_draw (GtkWidget *widget,
130 static gboolean gtk_assistant_focus (GtkWidget *widget,
131 GtkDirectionType direction);
132 static void gtk_assistant_add (GtkContainer *container,
134 static void gtk_assistant_remove (GtkContainer *container,
136 static void gtk_assistant_forall (GtkContainer *container,
137 gboolean include_internals,
138 GtkCallback callback,
139 gpointer callback_data);
140 static void gtk_assistant_set_child_property (GtkContainer *container,
145 static void gtk_assistant_get_child_property (GtkContainer *container,
151 static AtkObject *gtk_assistant_get_accessible (GtkWidget *widget);
153 static void gtk_assistant_buildable_interface_init (GtkBuildableIface *iface);
154 static GObject *gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
156 const gchar *childname);
157 static gboolean gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
160 const gchar *tagname,
161 GMarkupParser *parser,
163 static void gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
166 const gchar *tagname,
169 static GList* find_page (GtkAssistant *assistant,
175 CHILD_PROP_PAGE_TYPE,
176 CHILD_PROP_PAGE_TITLE,
177 CHILD_PROP_PAGE_HEADER_IMAGE,
178 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
179 CHILD_PROP_PAGE_COMPLETE
191 static guint signals [LAST_SIGNAL] = { 0 };
194 G_DEFINE_TYPE_WITH_CODE (GtkAssistant, gtk_assistant, GTK_TYPE_WINDOW,
195 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
196 gtk_assistant_buildable_interface_init))
200 gtk_assistant_class_init (GtkAssistantClass *class)
202 GObjectClass *gobject_class;
203 GtkWidgetClass *widget_class;
204 GtkContainerClass *container_class;
206 gobject_class = (GObjectClass *) class;
207 widget_class = (GtkWidgetClass *) class;
208 container_class = (GtkContainerClass *) class;
210 widget_class->destroy = gtk_assistant_destroy;
211 widget_class->style_set = gtk_assistant_style_set;
212 widget_class->size_request = gtk_assistant_size_request;
213 widget_class->size_allocate = gtk_assistant_size_allocate;
214 widget_class->map = gtk_assistant_map;
215 widget_class->unmap = gtk_assistant_unmap;
216 widget_class->delete_event = gtk_assistant_delete_event;
217 widget_class->draw = gtk_assistant_draw;
218 widget_class->focus = gtk_assistant_focus;
219 widget_class->get_accessible = gtk_assistant_get_accessible;
221 container_class->add = gtk_assistant_add;
222 container_class->remove = gtk_assistant_remove;
223 container_class->forall = gtk_assistant_forall;
224 container_class->set_child_property = gtk_assistant_set_child_property;
225 container_class->get_child_property = gtk_assistant_get_child_property;
228 * GtkAssistant::cancel:
229 * @assistant: the #GtkAssistant
231 * The ::cancel signal is emitted when then the cancel button is clicked.
236 g_signal_new (I_("cancel"),
237 G_TYPE_FROM_CLASS (gobject_class),
239 G_STRUCT_OFFSET (GtkAssistantClass, cancel),
241 g_cclosure_marshal_VOID__VOID,
245 * GtkAssistant::prepare:
246 * @assistant: the #GtkAssistant
247 * @page: the current page
249 * The ::prepare signal is emitted when a new page is set as the assistant's
250 * current page, before making the new page visible. A handler for this signal
251 * can do any preparation which are necessary before showing @page.
256 g_signal_new (I_("prepare"),
257 G_TYPE_FROM_CLASS (gobject_class),
259 G_STRUCT_OFFSET (GtkAssistantClass, prepare),
261 g_cclosure_marshal_VOID__OBJECT,
262 G_TYPE_NONE, 1, GTK_TYPE_WIDGET);
265 * GtkAssistant::apply:
266 * @assistant: the #GtkAssistant
268 * The ::apply signal is emitted when the apply button is clicked. The default
269 * behavior of the #GtkAssistant is to switch to the page after the current
270 * page, unless the current page is the last one.
272 * A handler for the ::apply signal should carry out the actions for which
273 * the wizard has collected data. If the action takes a long time to complete,
274 * you might consider putting a page of type %GTK_ASSISTANT_PAGE_PROGRESS
275 * after the confirmation page and handle this operation within the
276 * #GtkAssistant::prepare signal of the progress page.
281 g_signal_new (I_("apply"),
282 G_TYPE_FROM_CLASS (gobject_class),
284 G_STRUCT_OFFSET (GtkAssistantClass, apply),
286 g_cclosure_marshal_VOID__VOID,
290 * GtkAssistant::close:
291 * @assistant: the #GtkAssistant
293 * The ::close signal is emitted either when the close button of
294 * a summary page is clicked, or when the apply button in the last
295 * page in the flow (of type %GTK_ASSISTANT_PAGE_CONFIRM) is clicked.
300 g_signal_new (I_("close"),
301 G_TYPE_FROM_CLASS (gobject_class),
303 G_STRUCT_OFFSET (GtkAssistantClass, close),
305 g_cclosure_marshal_VOID__VOID,
308 gtk_widget_class_install_style_property (widget_class,
309 g_param_spec_int ("header-padding",
310 P_("Header Padding"),
311 P_("Number of pixels around the header."),
315 GTK_PARAM_READABLE));
316 gtk_widget_class_install_style_property (widget_class,
317 g_param_spec_int ("content-padding",
318 P_("Content Padding"),
319 P_("Number of pixels around the content pages."),
323 GTK_PARAM_READABLE));
326 * GtkAssistant:page-type:
328 * The type of the assistant page.
332 gtk_container_class_install_child_property (container_class,
333 CHILD_PROP_PAGE_TYPE,
334 g_param_spec_enum ("page-type",
336 P_("The type of the assistant page"),
337 GTK_TYPE_ASSISTANT_PAGE_TYPE,
338 GTK_ASSISTANT_PAGE_CONTENT,
339 GTK_PARAM_READWRITE));
342 * GtkAssistant:title:
344 * The title that is displayed in the page header.
346 * If title and header-image are both %NULL, no header is displayed.
350 gtk_container_class_install_child_property (container_class,
351 CHILD_PROP_PAGE_TITLE,
352 g_param_spec_string ("title",
354 P_("The title of the assistant page"),
356 GTK_PARAM_READWRITE));
359 * GtkAssistant:header-image:
361 * The image that is displayed next to the title in the page header.
363 * If title and header-image are both %NULL, no header is displayed.
367 gtk_container_class_install_child_property (container_class,
368 CHILD_PROP_PAGE_HEADER_IMAGE,
369 g_param_spec_object ("header-image",
371 P_("Header image for the assistant page"),
373 GTK_PARAM_READWRITE));
376 * GtkAssistant:header-image:
378 * The image that is displayed next to the page.
380 * Set this to %NULL to make the sidebar disappear.
384 gtk_container_class_install_child_property (container_class,
385 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
386 g_param_spec_object ("sidebar-image",
388 P_("Sidebar image for the assistant page"),
390 GTK_PARAM_READWRITE));
392 * GtkAssistant:complete:
394 * Setting the "complete" child property to %TRUE marks a page as complete
395 * (i.e.: all the required fields are filled out). GTK+ uses this information
396 * to control the sensitivity of the navigation buttons.
400 gtk_container_class_install_child_property (container_class,
401 CHILD_PROP_PAGE_COMPLETE,
402 g_param_spec_boolean ("complete",
404 P_("Whether all required fields on the page have been filled out"),
408 g_type_class_add_private (gobject_class, sizeof (GtkAssistantPrivate));
412 default_forward_function (gint current_page, gpointer data)
414 GtkAssistant *assistant;
415 GtkAssistantPrivate *priv;
416 GtkAssistantPage *page_info;
419 assistant = GTK_ASSISTANT (data);
420 priv = assistant->priv;
422 page_node = g_list_nth (priv->pages, ++current_page);
427 page_info = (GtkAssistantPage *) page_node->data;
429 while (page_node && !gtk_widget_get_visible (page_info->page))
431 page_node = page_node->next;
435 page_info = (GtkAssistantPage *) page_node->data;
442 compute_last_button_state (GtkAssistant *assistant)
444 GtkAssistantPrivate *priv = assistant->priv;
445 GtkAssistantPage *page_info, *current_page_info;
446 gint count, page_num, n_pages;
449 page_num = gtk_assistant_get_current_page (assistant);
450 n_pages = gtk_assistant_get_n_pages (assistant);
451 current_page_info = page_info = g_list_nth_data (priv->pages, page_num);
453 while (page_num >= 0 && page_num < n_pages &&
454 page_info->type == GTK_ASSISTANT_PAGE_CONTENT &&
455 (count == 0 || page_info->complete) &&
458 page_num = (priv->forward_function) (page_num, priv->forward_function_data);
459 page_info = g_list_nth_data (priv->pages, page_num);
464 /* make the last button visible if we can skip multiple
465 * pages and end on a confirmation or summary page
467 if (count > 1 && page_info &&
468 (page_info->type == GTK_ASSISTANT_PAGE_CONFIRM ||
469 page_info->type == GTK_ASSISTANT_PAGE_SUMMARY))
471 gtk_widget_show (priv->last);
472 gtk_widget_set_sensitive (priv->last,
473 current_page_info->complete);
476 gtk_widget_hide (priv->last);
480 compute_progress_state (GtkAssistant *assistant)
482 GtkAssistantPrivate *priv = assistant->priv;
483 gint page_num, n_pages;
485 n_pages = gtk_assistant_get_n_pages (assistant);
486 page_num = gtk_assistant_get_current_page (assistant);
488 page_num = (priv->forward_function) (page_num, priv->forward_function_data);
490 if (page_num >= 0 && page_num < n_pages)
491 gtk_widget_show (priv->forward);
493 gtk_widget_hide (priv->forward);
497 set_assistant_header_image (GtkAssistant *assistant)
499 GtkAssistantPrivate *priv = assistant->priv;
501 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->header_image),
502 priv->current_page->header_image);
506 set_assistant_sidebar_image (GtkAssistant *assistant)
508 GtkAssistantPrivate *priv = assistant->priv;
510 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->sidebar_image),
511 priv->current_page->sidebar_image);
513 if (priv->current_page->sidebar_image)
514 gtk_widget_show (priv->sidebar_image);
516 gtk_widget_hide (priv->sidebar_image);
520 set_assistant_buttons_state (GtkAssistant *assistant)
522 GtkAssistantPrivate *priv = assistant->priv;
524 if (!priv->current_page)
527 switch (priv->current_page->type)
529 case GTK_ASSISTANT_PAGE_INTRO:
530 gtk_widget_set_sensitive (priv->cancel, TRUE);
531 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
532 gtk_widget_grab_default (priv->forward);
533 gtk_widget_show (priv->forward);
534 gtk_widget_hide (priv->back);
535 gtk_widget_hide (priv->apply);
536 gtk_widget_hide (priv->close);
537 compute_last_button_state (assistant);
539 case GTK_ASSISTANT_PAGE_CONFIRM:
540 gtk_widget_set_sensitive (priv->cancel, TRUE);
541 gtk_widget_set_sensitive (priv->back, TRUE);
542 gtk_widget_set_sensitive (priv->apply, priv->current_page->complete);
543 gtk_widget_grab_default (priv->apply);
544 gtk_widget_show (priv->back);
545 gtk_widget_show (priv->apply);
546 gtk_widget_hide (priv->forward);
547 gtk_widget_hide (priv->close);
548 gtk_widget_hide (priv->last);
550 case GTK_ASSISTANT_PAGE_CONTENT:
551 gtk_widget_set_sensitive (priv->cancel, TRUE);
552 gtk_widget_set_sensitive (priv->back, TRUE);
553 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
554 gtk_widget_grab_default (priv->forward);
555 gtk_widget_show (priv->back);
556 gtk_widget_show (priv->forward);
557 gtk_widget_hide (priv->apply);
558 gtk_widget_hide (priv->close);
559 compute_last_button_state (assistant);
561 case GTK_ASSISTANT_PAGE_SUMMARY:
562 gtk_widget_set_sensitive (priv->close, priv->current_page->complete);
563 gtk_widget_grab_default (priv->close);
564 gtk_widget_show (priv->close);
565 gtk_widget_hide (priv->back);
566 gtk_widget_hide (priv->forward);
567 gtk_widget_hide (priv->apply);
568 gtk_widget_hide (priv->last);
570 case GTK_ASSISTANT_PAGE_PROGRESS:
571 gtk_widget_set_sensitive (priv->cancel, priv->current_page->complete);
572 gtk_widget_set_sensitive (priv->back, priv->current_page->complete);
573 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
574 gtk_widget_grab_default (priv->forward);
575 gtk_widget_show (priv->back);
576 gtk_widget_hide (priv->apply);
577 gtk_widget_hide (priv->close);
578 gtk_widget_hide (priv->last);
579 compute_progress_state (assistant);
582 g_assert_not_reached ();
586 gtk_widget_hide (priv->cancel);
587 else if (priv->current_page->type == GTK_ASSISTANT_PAGE_SUMMARY)
588 gtk_widget_hide (priv->cancel);
590 gtk_widget_show (priv->cancel);
592 /* this is quite general, we don't want to
593 * go back if it's the first page */
594 if (!priv->visited_pages)
595 gtk_widget_hide (priv->back);
599 set_current_page (GtkAssistant *assistant,
600 GtkAssistantPage *page)
602 GtkAssistantPrivate *priv = assistant->priv;
603 GtkAssistantPage *old_page;
605 if (priv->current_page &&
606 gtk_widget_is_drawable (priv->current_page->page))
607 old_page = priv->current_page;
611 priv->current_page = page;
613 set_assistant_buttons_state (assistant);
614 set_assistant_header_image (assistant);
615 set_assistant_sidebar_image (assistant);
617 g_signal_emit (assistant, signals [PREPARE], 0, priv->current_page->page);
619 if (gtk_widget_get_visible (priv->current_page->page) && gtk_widget_get_mapped (GTK_WIDGET (assistant)))
621 gtk_widget_set_child_visible (priv->current_page->page, TRUE);
622 gtk_widget_map (priv->current_page->page);
623 gtk_widget_map (priv->current_page->title);
626 if (old_page && gtk_widget_get_mapped (old_page->page))
628 gtk_widget_set_child_visible (old_page->page, FALSE);
629 gtk_widget_unmap (old_page->page);
630 gtk_widget_unmap (old_page->title);
633 if (!gtk_widget_child_focus (priv->current_page->page, GTK_DIR_TAB_FORWARD))
635 GtkWidget *button[6];
638 /* find the best button to focus */
639 button[0] = priv->apply;
640 button[1] = priv->close;
641 button[2] = priv->forward;
642 button[3] = priv->back;
643 button[4] = priv->cancel;
644 button[5] = priv->last;
645 for (i = 0; i < 6; i++)
647 if (gtk_widget_get_visible (button[i]) && gtk_widget_get_sensitive (button[i]))
649 gtk_widget_grab_focus (button[i]);
655 gtk_widget_queue_resize (GTK_WIDGET (assistant));
659 compute_next_step (GtkAssistant *assistant)
661 GtkAssistantPrivate *priv = assistant->priv;
662 GtkAssistantPage *page_info;
663 gint current_page, n_pages, next_page;
665 current_page = gtk_assistant_get_current_page (assistant);
666 page_info = priv->current_page;
667 n_pages = gtk_assistant_get_n_pages (assistant);
669 next_page = (priv->forward_function) (current_page,
670 priv->forward_function_data);
672 if (next_page >= 0 && next_page < n_pages)
674 priv->visited_pages = g_slist_prepend (priv->visited_pages, page_info);
675 set_current_page (assistant, g_list_nth_data (priv->pages, next_page));
684 on_assistant_close (GtkWidget *widget,
685 GtkAssistant *assistant)
687 g_signal_emit (assistant, signals [CLOSE], 0, NULL);
691 on_assistant_apply (GtkWidget *widget,
692 GtkAssistant *assistant)
696 g_signal_emit (assistant, signals [APPLY], 0);
698 success = compute_next_step (assistant);
700 /* if the assistant hasn't switched to another page, just emit
701 * the CLOSE signal, it't the last page in the assistant flow
704 g_signal_emit (assistant, signals [CLOSE], 0);
708 on_assistant_forward (GtkWidget *widget,
709 GtkAssistant *assistant)
711 if (!compute_next_step (assistant))
712 g_critical ("Page flow is broken, you may want to end it with a page of "
713 "type GTK_ASSISTANT_PAGE_CONFIRM or GTK_ASSISTANT_PAGE_SUMMARY");
717 on_assistant_back (GtkWidget *widget,
718 GtkAssistant *assistant)
720 GtkAssistantPrivate *priv = assistant->priv;
721 GtkAssistantPage *page_info;
724 /* skip the progress pages when going back */
727 page_node = priv->visited_pages;
729 g_return_if_fail (page_node != NULL);
731 priv->visited_pages = priv->visited_pages->next;
732 page_info = (GtkAssistantPage *) page_node->data;
733 g_slist_free_1 (page_node);
735 while (page_info->type == GTK_ASSISTANT_PAGE_PROGRESS ||
736 !gtk_widget_get_visible (page_info->page));
738 set_current_page (assistant, page_info);
742 on_assistant_cancel (GtkWidget *widget,
743 GtkAssistant *assistant)
745 g_signal_emit (assistant, signals [CANCEL], 0, NULL);
749 on_assistant_last (GtkWidget *widget,
750 GtkAssistant *assistant)
752 GtkAssistantPrivate *priv = assistant->priv;
754 while (priv->current_page->type == GTK_ASSISTANT_PAGE_CONTENT &&
755 priv->current_page->complete)
756 compute_next_step (assistant);
760 alternative_button_order (GtkAssistant *assistant)
762 GtkSettings *settings;
766 screen = gtk_widget_get_screen (GTK_WIDGET (assistant));
767 settings = gtk_settings_get_for_screen (screen);
769 g_object_get (settings,
770 "gtk-alternative-button-order", &result,
776 gtk_assistant_init (GtkAssistant *assistant)
778 GtkAssistantPrivate *priv;
780 assistant->priv = G_TYPE_INSTANCE_GET_PRIVATE (assistant,
782 GtkAssistantPrivate);
783 priv = assistant->priv;
785 gtk_container_set_reallocate_redraws (GTK_CONTAINER (assistant), TRUE);
786 gtk_container_set_border_width (GTK_CONTAINER (assistant), 12);
788 gtk_widget_push_composite_child ();
791 priv->header_image = gtk_image_new ();
792 gtk_misc_set_alignment (GTK_MISC (priv->header_image), 1., 0.5);
793 gtk_widget_set_parent (priv->header_image, GTK_WIDGET (assistant));
794 gtk_widget_show (priv->header_image);
797 priv->sidebar_image = gtk_image_new ();
798 gtk_misc_set_alignment (GTK_MISC (priv->sidebar_image), 0., 0.);
799 gtk_widget_set_parent (priv->sidebar_image, GTK_WIDGET (assistant));
800 gtk_widget_show (priv->sidebar_image);
803 priv->action_area = gtk_hbox_new (FALSE, 6);
805 priv->close = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
806 priv->apply = gtk_button_new_from_stock (GTK_STOCK_APPLY);
807 priv->forward = gtk_button_new_from_stock (GTK_STOCK_GO_FORWARD);
808 priv->back = gtk_button_new_from_stock (GTK_STOCK_GO_BACK);
809 priv->cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
810 priv->last = gtk_button_new_from_stock (GTK_STOCK_GOTO_LAST);
811 gtk_widget_set_can_default (priv->close, TRUE);
812 gtk_widget_set_can_default (priv->apply, TRUE);
813 gtk_widget_set_can_default (priv->forward, TRUE);
815 priv->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
816 gtk_size_group_add_widget (priv->size_group, priv->close);
817 gtk_size_group_add_widget (priv->size_group, priv->apply);
818 gtk_size_group_add_widget (priv->size_group, priv->forward);
819 gtk_size_group_add_widget (priv->size_group, priv->back);
820 gtk_size_group_add_widget (priv->size_group, priv->cancel);
821 gtk_size_group_add_widget (priv->size_group, priv->last);
823 if (!alternative_button_order (assistant))
825 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
826 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
827 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
828 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
829 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
830 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->close, FALSE, FALSE, 0);
834 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->close, FALSE, FALSE, 0);
835 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
836 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
837 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
838 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
839 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
842 gtk_widget_set_parent (priv->action_area, GTK_WIDGET (assistant));
843 gtk_widget_show (priv->forward);
844 gtk_widget_show (priv->back);
845 gtk_widget_show (priv->cancel);
846 gtk_widget_show (priv->action_area);
848 gtk_widget_pop_composite_child ();
851 priv->current_page = NULL;
852 priv->visited_pages = NULL;
854 priv->forward_function = default_forward_function;
855 priv->forward_function_data = assistant;
856 priv->forward_data_destroy = NULL;
858 g_signal_connect (G_OBJECT (priv->close), "clicked",
859 G_CALLBACK (on_assistant_close), assistant);
860 g_signal_connect (G_OBJECT (priv->apply), "clicked",
861 G_CALLBACK (on_assistant_apply), assistant);
862 g_signal_connect (G_OBJECT (priv->forward), "clicked",
863 G_CALLBACK (on_assistant_forward), assistant);
864 g_signal_connect (G_OBJECT (priv->back), "clicked",
865 G_CALLBACK (on_assistant_back), assistant);
866 g_signal_connect (G_OBJECT (priv->cancel), "clicked",
867 G_CALLBACK (on_assistant_cancel), assistant);
868 g_signal_connect (G_OBJECT (priv->last), "clicked",
869 G_CALLBACK (on_assistant_last), assistant);
873 gtk_assistant_set_child_property (GtkContainer *container,
881 case CHILD_PROP_PAGE_TYPE:
882 gtk_assistant_set_page_type (GTK_ASSISTANT (container), child,
883 g_value_get_enum (value));
885 case CHILD_PROP_PAGE_TITLE:
886 gtk_assistant_set_page_title (GTK_ASSISTANT (container), child,
887 g_value_get_string (value));
889 case CHILD_PROP_PAGE_HEADER_IMAGE:
890 gtk_assistant_set_page_header_image (GTK_ASSISTANT (container), child,
891 g_value_get_object (value));
893 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
894 gtk_assistant_set_page_side_image (GTK_ASSISTANT (container), child,
895 g_value_get_object (value));
897 case CHILD_PROP_PAGE_COMPLETE:
898 gtk_assistant_set_page_complete (GTK_ASSISTANT (container), child,
899 g_value_get_boolean (value));
902 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
908 gtk_assistant_get_child_property (GtkContainer *container,
916 case CHILD_PROP_PAGE_TYPE:
917 g_value_set_enum (value,
918 gtk_assistant_get_page_type (GTK_ASSISTANT (container), child));
920 case CHILD_PROP_PAGE_TITLE:
921 g_value_set_string (value,
922 gtk_assistant_get_page_title (GTK_ASSISTANT (container), child));
924 case CHILD_PROP_PAGE_HEADER_IMAGE:
925 g_value_set_object (value,
926 gtk_assistant_get_page_header_image (GTK_ASSISTANT (container), child));
928 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
929 g_value_set_object (value,
930 gtk_assistant_get_page_side_image (GTK_ASSISTANT (container), child));
932 case CHILD_PROP_PAGE_COMPLETE:
933 g_value_set_boolean (value,
934 gtk_assistant_get_page_complete (GTK_ASSISTANT (container), child));
937 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
943 on_page_notify_visibility (GtkWidget *widget,
947 GtkAssistant *assistant = GTK_ASSISTANT (data);
949 /* update buttons state, flow may have changed */
950 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
951 set_assistant_buttons_state (assistant);
955 remove_page (GtkAssistant *assistant,
958 GtkAssistantPrivate *priv = assistant->priv;
959 GtkAssistantPage *page_info;
962 page_info = element->data;
964 /* If this is the current page, we need to switch away. */
965 if (page_info == priv->current_page)
967 if (!compute_next_step (assistant))
969 /* The best we can do at this point is probably to pick the first
972 page_node = priv->pages;
974 while (page_node && !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
975 page_node = page_node->next;
977 if (page_node == element)
978 page_node = page_node->next;
981 priv->current_page = page_node->data;
983 priv->current_page = NULL;
987 priv->pages = g_list_remove_link (priv->pages, element);
988 priv->visited_pages = g_slist_remove_all (priv->visited_pages, page_info);
990 g_signal_handlers_disconnect_by_func (page_info->page, on_page_notify_visibility, assistant);
991 gtk_widget_unparent (page_info->page);
993 if (page_info->header_image)
994 g_object_unref (page_info->header_image);
996 if (page_info->sidebar_image)
997 g_object_unref (page_info->sidebar_image);
999 gtk_widget_destroy (page_info->title);
1000 g_slice_free (GtkAssistantPage, page_info);
1001 g_list_free_1 (element);
1005 gtk_assistant_destroy (GtkWidget *widget)
1007 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1008 GtkAssistantPrivate *priv = assistant->priv;
1010 if (priv->header_image)
1012 gtk_widget_destroy (priv->header_image);
1013 priv->header_image = NULL;
1016 if (priv->sidebar_image)
1018 gtk_widget_destroy (priv->sidebar_image);
1019 priv->sidebar_image = NULL;
1022 if (priv->action_area)
1024 gtk_widget_destroy (priv->action_area);
1025 priv->action_area = NULL;
1028 if (priv->size_group)
1030 g_object_unref (priv->size_group);
1031 priv->size_group = NULL;
1034 if (priv->forward_function)
1036 if (priv->forward_function_data &&
1037 priv->forward_data_destroy)
1038 priv->forward_data_destroy (priv->forward_function_data);
1040 priv->forward_function = NULL;
1041 priv->forward_function_data = NULL;
1042 priv->forward_data_destroy = NULL;
1045 if (priv->visited_pages)
1047 g_slist_free (priv->visited_pages);
1048 priv->visited_pages = NULL;
1051 /* We set current to NULL so that the remove code doesn't try
1052 * to do anything funny */
1053 priv->current_page = NULL;
1056 remove_page (assistant, priv->pages);
1058 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->destroy (widget);
1062 find_page (GtkAssistant *assistant,
1065 GtkAssistantPrivate *priv = assistant->priv;
1066 GList *child = priv->pages;
1070 GtkAssistantPage *page_info = child->data;
1071 if (page_info->page == page)
1074 child = child->next;
1081 set_title_colors (GtkWidget *assistant,
1082 GtkWidget *title_label)
1086 gtk_widget_ensure_style (assistant);
1087 style = gtk_widget_get_style (assistant);
1089 /* change colors schema, for making the header text visible */
1090 gtk_widget_modify_bg (title_label, GTK_STATE_NORMAL, &style->bg[GTK_STATE_SELECTED]);
1091 gtk_widget_modify_fg (title_label, GTK_STATE_NORMAL, &style->fg[GTK_STATE_SELECTED]);
1095 set_title_font (GtkWidget *assistant,
1096 GtkWidget *title_label)
1098 PangoFontDescription *desc;
1101 desc = pango_font_description_new ();
1102 size = pango_font_description_get_size (gtk_widget_get_style (assistant)->font_desc);
1104 pango_font_description_set_weight (desc, PANGO_WEIGHT_ULTRABOLD);
1105 pango_font_description_set_size (desc, size * PANGO_SCALE_XX_LARGE);
1107 gtk_widget_modify_font (title_label, desc);
1108 pango_font_description_free (desc);
1112 gtk_assistant_style_set (GtkWidget *widget,
1113 GtkStyle *old_style)
1115 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1116 GtkAssistantPrivate *priv = assistant->priv;
1123 GtkAssistantPage *page = list->data;
1125 set_title_colors (widget, page->title);
1126 set_title_font (widget, page->title);
1133 gtk_assistant_size_request (GtkWidget *widget,
1134 GtkRequisition *requisition)
1136 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1137 GtkAssistantPrivate *priv = assistant->priv;
1138 GtkRequisition child_requisition;
1139 gint header_padding, content_padding;
1140 gint width, height, header_width, header_height;
1144 gtk_widget_style_get (widget,
1145 "header-padding", &header_padding,
1146 "content-padding", &content_padding,
1149 header_width = header_height = 0;
1154 GtkAssistantPage *page = list->data;
1157 gtk_widget_get_preferred_size (page->page,
1158 &child_requisition, NULL);
1159 width = MAX (width, child_requisition.width);
1160 height = MAX (height, child_requisition.height);
1162 gtk_widget_get_preferred_size (page->title,
1163 &child_requisition, NULL);
1164 w = child_requisition.width;
1165 h = child_requisition.height;
1167 if (page->header_image)
1169 w += gdk_pixbuf_get_width (page->header_image) + HEADER_SPACING;
1170 h = MAX (h, gdk_pixbuf_get_height (page->header_image));
1173 header_width = MAX (header_width, w);
1174 header_height = MAX (header_height, h);
1179 gtk_widget_get_preferred_size (priv->sidebar_image,
1180 &child_requisition, NULL);
1181 width += child_requisition.width;
1182 height = MAX (height, child_requisition.height);
1184 gtk_widget_set_size_request (priv->header_image, header_width, header_height);
1185 gtk_widget_get_preferred_size (priv->header_image,
1186 &child_requisition, NULL);
1187 width = MAX (width, header_width) + 2 * header_padding;
1188 height += header_height + 2 * header_padding;
1190 gtk_widget_get_preferred_size (priv->action_area,
1191 &child_requisition, NULL);
1192 width = MAX (width, child_requisition.width);
1193 height += child_requisition.height + ACTION_AREA_SPACING;
1195 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1196 width += border_width * 2 + content_padding * 2;
1197 height += border_width * 2 + content_padding * 2;
1199 requisition->width = width;
1200 requisition->height = height;
1205 gtk_assistant_size_allocate (GtkWidget *widget,
1206 GtkAllocation *allocation)
1208 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1209 GtkAssistantPrivate *priv = assistant->priv;
1210 GtkRequisition header_requisition, action_requisition, sidebar_requisition;
1211 GtkAllocation child_allocation, header_allocation;
1212 GtkAllocation action_area_allocation, header_image_allocation;
1213 gint header_padding, content_padding;
1218 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1219 pages = priv->pages;
1221 gtk_widget_style_get (widget,
1222 "header-padding", &header_padding,
1223 "content-padding", &content_padding,
1226 gtk_widget_set_allocation (widget, allocation);
1227 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1230 gtk_widget_get_preferred_size (priv->header_image,
1231 &header_requisition, NULL);
1233 header_allocation.x = border_width + header_padding;
1234 header_allocation.y = border_width + header_padding;
1235 header_allocation.width = allocation->width - 2 * border_width - 2 * header_padding;
1236 header_allocation.height = header_requisition.height;
1238 gtk_widget_size_allocate (priv->header_image, &header_allocation);
1241 gtk_widget_get_preferred_size (priv->action_area,
1242 &action_requisition, NULL);
1244 child_allocation.x = border_width;
1245 child_allocation.y = allocation->height - border_width - action_requisition.height;
1246 child_allocation.width = allocation->width - 2 * border_width;
1247 child_allocation.height = action_requisition.height;
1249 gtk_widget_size_allocate (priv->action_area, &child_allocation);
1251 gtk_widget_get_allocation (priv->header_image, &header_image_allocation);
1252 gtk_widget_get_allocation (priv->action_area, &action_area_allocation);
1255 gtk_widget_get_preferred_size (priv->sidebar_image,
1256 &sidebar_requisition, NULL);
1259 child_allocation.x = allocation->width - border_width - sidebar_requisition.width;
1261 child_allocation.x = border_width;
1263 child_allocation.y = border_width + header_image_allocation.height + 2 * header_padding;
1264 child_allocation.width = sidebar_requisition.width;
1265 child_allocation.height = allocation->height - 2 * border_width -
1266 header_image_allocation.height - 2 * header_padding - action_area_allocation.height;
1268 gtk_widget_size_allocate (priv->sidebar_image, &child_allocation);
1271 child_allocation.x = border_width + content_padding;
1272 child_allocation.y = border_width +
1273 header_image_allocation.height + 2 * header_padding + content_padding;
1274 child_allocation.width = allocation->width - 2 * border_width - 2 * content_padding;
1275 child_allocation.height = allocation->height - 2 * border_width -
1276 header_image_allocation.height - 2 * header_padding - ACTION_AREA_SPACING - action_area_allocation.height - 2 * content_padding;
1278 if (gtk_widget_get_visible (priv->sidebar_image))
1280 GtkAllocation sidebar_image_allocation;
1282 gtk_widget_get_allocation (priv->sidebar_image, &sidebar_image_allocation);
1285 child_allocation.x += sidebar_image_allocation.width;
1287 child_allocation.width -= sidebar_image_allocation.width;
1292 GtkAssistantPage *page = pages->data;
1294 gtk_widget_size_allocate (page->page, &child_allocation);
1295 gtk_widget_size_allocate (page->title, &header_allocation);
1296 pages = pages->next;
1301 gtk_assistant_map (GtkWidget *widget)
1303 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1304 GtkAssistantPrivate *priv = assistant->priv;
1306 GtkAssistantPage *page;
1308 gtk_widget_set_mapped (widget, TRUE);
1310 gtk_widget_map (priv->header_image);
1311 gtk_widget_map (priv->action_area);
1313 if (gtk_widget_get_visible (priv->sidebar_image) &&
1314 !gtk_widget_get_mapped (priv->sidebar_image))
1315 gtk_widget_map (priv->sidebar_image);
1317 /* if there's no default page, pick the first one */
1319 if (!priv->current_page)
1321 page_node = priv->pages;
1323 while (page_node && !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
1324 page_node = page_node->next;
1327 page = page_node->data;
1331 gtk_widget_get_visible (page->page) &&
1332 !gtk_widget_get_mapped (page->page))
1333 set_current_page (assistant, page);
1335 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->map (widget);
1339 gtk_assistant_unmap (GtkWidget *widget)
1341 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1342 GtkAssistantPrivate *priv = assistant->priv;
1344 gtk_widget_set_mapped (widget, FALSE);
1346 gtk_widget_unmap (priv->header_image);
1347 gtk_widget_unmap (priv->action_area);
1349 if (gtk_widget_is_drawable (priv->sidebar_image))
1350 gtk_widget_unmap (priv->sidebar_image);
1352 if (priv->current_page &&
1353 gtk_widget_is_drawable (priv->current_page->page))
1354 gtk_widget_unmap (priv->current_page->page);
1356 g_slist_free (priv->visited_pages);
1357 priv->visited_pages = NULL;
1358 priv->current_page = NULL;
1360 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->unmap (widget);
1364 gtk_assistant_delete_event (GtkWidget *widget,
1367 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1368 GtkAssistantPrivate *priv = assistant->priv;
1370 /* Do not allow cancelling in the middle of a progress page */
1371 if (priv->current_page &&
1372 (priv->current_page->type != GTK_ASSISTANT_PAGE_PROGRESS ||
1373 priv->current_page->complete))
1374 g_signal_emit (widget, signals [CANCEL], 0, NULL);
1380 assistant_paint_colored_box (GtkWidget *widget,
1383 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1384 GtkAssistantPrivate *priv = assistant->priv;
1385 GtkAllocation allocation, action_area_allocation, header_image_allocation;
1387 gint border_width, header_padding, content_padding;
1388 gint content_x, content_width;
1391 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1392 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1394 gtk_widget_style_get (widget,
1395 "header-padding", &header_padding,
1396 "content-padding", &content_padding,
1399 style = gtk_widget_get_style (widget);
1400 gtk_widget_get_allocation (widget, &allocation);
1401 gtk_widget_get_allocation (priv->action_area, &action_area_allocation);
1402 gtk_widget_get_allocation (priv->header_image, &header_image_allocation);
1405 gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_SELECTED]);
1406 cairo_rectangle (cr,
1409 allocation.width - 2 * border_width,
1410 allocation.height - action_area_allocation.height - 2 * border_width - ACTION_AREA_SPACING);
1414 content_x = content_padding + border_width;
1415 content_width = allocation.width - 2 * content_padding - 2 * border_width;
1417 if (gtk_widget_get_visible (priv->sidebar_image))
1419 GtkAllocation sidebar_image_allocation;
1421 gtk_widget_get_allocation (priv->sidebar_image, &sidebar_image_allocation);
1424 content_x += sidebar_image_allocation.width;
1425 content_width -= sidebar_image_allocation.width;
1428 gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
1430 cairo_rectangle (cr,
1432 header_image_allocation.height + content_padding + 2 * header_padding + border_width,
1434 allocation.height - 2 * border_width - action_area_allocation.height -
1435 header_image_allocation.height - 2 * content_padding - 2 * header_padding - ACTION_AREA_SPACING);
1440 gtk_assistant_draw (GtkWidget *widget,
1443 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1444 GtkAssistantPrivate *priv = assistant->priv;
1445 GtkContainer *container = GTK_CONTAINER (widget);
1447 if (GTK_WIDGET_CLASS (gtk_assistant_parent_class)->draw)
1448 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->draw (widget, cr);
1450 assistant_paint_colored_box (widget, cr);
1452 gtk_container_propagate_draw (container, priv->header_image, cr);
1453 gtk_container_propagate_draw (container, priv->sidebar_image, cr);
1454 gtk_container_propagate_draw (container, priv->action_area, cr);
1456 if (priv->current_page)
1458 gtk_container_propagate_draw (container, priv->current_page->page, cr);
1459 gtk_container_propagate_draw (container, priv->current_page->title, cr);
1466 gtk_assistant_focus (GtkWidget *widget,
1467 GtkDirectionType direction)
1469 GtkAssistantPrivate *priv;
1470 GtkContainer *container;
1472 container = GTK_CONTAINER (widget);
1473 priv = GTK_ASSISTANT (widget)->priv;
1475 /* we only have to care about 2 widgets, action area and the current page */
1476 if (gtk_container_get_focus_child (container) == priv->action_area)
1478 if (!gtk_widget_child_focus (priv->action_area, direction) &&
1479 (priv->current_page == NULL ||
1480 !gtk_widget_child_focus (priv->current_page->page, direction)))
1482 /* if we're leaving the action area and the current page hasn't
1483 any focusable widget, clear focus and go back to the action area */
1484 gtk_container_set_focus_child (GTK_CONTAINER (priv->action_area), NULL);
1485 gtk_widget_child_focus (priv->action_area, direction);
1490 if ((priv->current_page == NULL ||
1491 !gtk_widget_child_focus (priv->current_page->page, direction)) &&
1492 !gtk_widget_child_focus (priv->action_area, direction))
1494 /* if we're leaving the current page and there isn't nothing focusable
1495 in the action area, try to clear focus and go back to the page */
1496 gtk_window_set_focus (GTK_WINDOW (widget), NULL);
1497 if (priv->current_page != NULL)
1498 gtk_widget_child_focus (priv->current_page->page, direction);
1506 gtk_assistant_add (GtkContainer *container,
1509 gtk_assistant_append_page (GTK_ASSISTANT (container), page);
1513 gtk_assistant_remove (GtkContainer *container,
1516 GtkAssistant *assistant = (GtkAssistant*) container;
1519 element = find_page (assistant, page);
1523 remove_page (assistant, element);
1524 gtk_widget_queue_resize ((GtkWidget *) container);
1529 gtk_assistant_forall (GtkContainer *container,
1530 gboolean include_internals,
1531 GtkCallback callback,
1532 gpointer callback_data)
1534 GtkAssistant *assistant = (GtkAssistant*) container;
1535 GtkAssistantPrivate *priv = assistant->priv;
1538 if (include_internals)
1540 (*callback) (priv->header_image, callback_data);
1541 (*callback) (priv->sidebar_image, callback_data);
1542 (*callback) (priv->action_area, callback_data);
1545 pages = priv->pages;
1549 GtkAssistantPage *page = (GtkAssistantPage *) pages->data;
1551 (*callback) (page->page, callback_data);
1553 if (include_internals)
1554 (*callback) (page->title, callback_data);
1556 pages = pages->next;
1561 * gtk_assistant_new:
1563 * Creates a new #GtkAssistant.
1565 * Return value: a newly created #GtkAssistant
1570 gtk_assistant_new (void)
1572 GtkWidget *assistant;
1574 assistant = g_object_new (GTK_TYPE_ASSISTANT, NULL);
1580 * gtk_assistant_get_current_page:
1581 * @assistant: a #GtkAssistant
1583 * Returns the page number of the current page
1585 * Return value: The index (starting from 0) of the current page in
1586 * the @assistant, if the @assistant has no pages, -1 will be returned
1591 gtk_assistant_get_current_page (GtkAssistant *assistant)
1593 GtkAssistantPrivate *priv;
1595 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), -1);
1597 priv = assistant->priv;
1599 if (!priv->pages || !priv->current_page)
1602 return g_list_index (priv->pages, priv->current_page);
1606 * gtk_assistant_set_current_page:
1607 * @assistant: a #GtkAssistant
1608 * @page_num: index of the page to switch to, starting from 0.
1609 * If negative, the last page will be used. If greater
1610 * than the number of pages in the @assistant, nothing
1613 * Switches the page to @page_num. Note that this will only be necessary
1614 * in custom buttons, as the @assistant flow can be set with
1615 * gtk_assistant_set_forward_page_func().
1620 gtk_assistant_set_current_page (GtkAssistant *assistant,
1623 GtkAssistantPrivate *priv;
1624 GtkAssistantPage *page;
1626 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1628 priv = assistant->priv;
1631 page = (GtkAssistantPage *) g_list_nth_data (priv->pages, page_num);
1633 page = (GtkAssistantPage *) g_list_last (priv->pages)->data;
1635 g_return_if_fail (page != NULL);
1637 if (priv->current_page == page)
1640 /* only add the page to the visited list if the
1641 * assistant is mapped, if not, just use it as an
1642 * initial page setting, for the cases where the
1643 * initial page is != to 0
1645 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1646 priv->visited_pages = g_slist_prepend (priv->visited_pages,
1647 priv->current_page);
1649 set_current_page (assistant, page);
1653 * gtk_assistant_get_n_pages:
1654 * @assistant: a #GtkAssistant
1656 * Returns the number of pages in the @assistant
1658 * Return value: The number of pages in the @assistant.
1663 gtk_assistant_get_n_pages (GtkAssistant *assistant)
1665 GtkAssistantPrivate *priv;
1667 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1669 priv = assistant->priv;
1671 return g_list_length (priv->pages);
1675 * gtk_assistant_get_nth_page:
1676 * @assistant: a #GtkAssistant
1677 * @page_num: The index of a page in the @assistant, or -1 to get the last page;
1679 * Returns the child widget contained in page number @page_num.
1681 * Return value: (transfer none): The child widget, or %NULL
1682 * if @page_num is out of bounds.
1687 gtk_assistant_get_nth_page (GtkAssistant *assistant,
1690 GtkAssistantPrivate *priv;
1691 GtkAssistantPage *page;
1694 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1695 g_return_val_if_fail (page_num >= -1, NULL);
1697 priv = assistant->priv;
1700 elem = g_list_last (priv->pages);
1702 elem = g_list_nth (priv->pages, page_num);
1707 page = (GtkAssistantPage *) elem->data;
1713 * gtk_assistant_prepend_page:
1714 * @assistant: a #GtkAssistant
1715 * @page: a #GtkWidget
1717 * Prepends a page to the @assistant.
1719 * Return value: the index (starting at 0) of the inserted page
1724 gtk_assistant_prepend_page (GtkAssistant *assistant,
1727 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1728 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1730 return gtk_assistant_insert_page (assistant, page, 0);
1734 * gtk_assistant_append_page:
1735 * @assistant: a #GtkAssistant
1736 * @page: a #GtkWidget
1738 * Appends a page to the @assistant.
1740 * Return value: the index (starting at 0) of the inserted page
1745 gtk_assistant_append_page (GtkAssistant *assistant,
1748 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1749 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1751 return gtk_assistant_insert_page (assistant, page, -1);
1755 * gtk_assistant_insert_page:
1756 * @assistant: a #GtkAssistant
1757 * @page: a #GtkWidget
1758 * @position: the index (starting at 0) at which to insert the page,
1759 * or -1 to append the page to the @assistant
1761 * Inserts a page in the @assistant at a given position.
1763 * Return value: the index (starting from 0) of the inserted page
1768 gtk_assistant_insert_page (GtkAssistant *assistant,
1772 GtkAssistantPrivate *priv;
1773 GtkAssistantPage *page_info;
1776 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1777 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1778 g_return_val_if_fail (gtk_widget_get_parent (page) == NULL, 0);
1779 g_return_val_if_fail (!gtk_widget_is_toplevel (page), 0);
1781 priv = assistant->priv;
1783 page_info = g_slice_new0 (GtkAssistantPage);
1784 page_info->page = page;
1785 page_info->title = gtk_label_new (NULL);
1787 g_signal_connect (G_OBJECT (page), "notify::visible",
1788 G_CALLBACK (on_page_notify_visibility), assistant);
1790 gtk_misc_set_alignment (GTK_MISC (page_info->title), 0.,0.5);
1791 set_title_colors (GTK_WIDGET (assistant), page_info->title);
1792 set_title_font (GTK_WIDGET (assistant), page_info->title);
1793 gtk_widget_show (page_info->title);
1795 n_pages = g_list_length (priv->pages);
1797 if (position < 0 || position > n_pages)
1800 priv->pages = g_list_insert (priv->pages, page_info, position);
1802 gtk_widget_set_child_visible (page_info->page, FALSE);
1803 gtk_widget_set_parent (page_info->page, GTK_WIDGET (assistant));
1804 gtk_widget_set_parent (page_info->title, GTK_WIDGET (assistant));
1806 if (gtk_widget_get_realized (GTK_WIDGET (assistant)))
1808 gtk_widget_realize (page_info->page);
1809 gtk_widget_realize (page_info->title);
1812 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1818 * gtk_assistant_set_forward_page_func:
1819 * @assistant: a #GtkAssistant
1820 * @page_func: (allow-none): the #GtkAssistantPageFunc, or %NULL to use the default one
1821 * @data: user data for @page_func
1822 * @destroy: destroy notifier for @data
1824 * Sets the page forwarding function to be @page_func, this function will
1825 * be used to determine what will be the next page when the user presses
1826 * the forward button. Setting @page_func to %NULL will make the assistant
1827 * to use the default forward function, which just goes to the next visible
1833 gtk_assistant_set_forward_page_func (GtkAssistant *assistant,
1834 GtkAssistantPageFunc page_func,
1836 GDestroyNotify destroy)
1838 GtkAssistantPrivate *priv;
1840 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1842 priv = assistant->priv;
1844 if (priv->forward_data_destroy &&
1845 priv->forward_function_data)
1846 (*priv->forward_data_destroy) (priv->forward_function_data);
1850 priv->forward_function = page_func;
1851 priv->forward_function_data = data;
1852 priv->forward_data_destroy = destroy;
1856 priv->forward_function = default_forward_function;
1857 priv->forward_function_data = assistant;
1858 priv->forward_data_destroy = NULL;
1861 /* Page flow has possibly changed, so the
1862 buttons state might need to change too */
1863 set_assistant_buttons_state (assistant);
1867 * gtk_assistant_add_action_widget:
1868 * @assistant: a #GtkAssistant
1869 * @child: a #GtkWidget
1871 * Adds a widget to the action area of a #GtkAssistant.
1876 gtk_assistant_add_action_widget (GtkAssistant *assistant,
1879 GtkAssistantPrivate *priv;
1881 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1882 g_return_if_fail (GTK_IS_WIDGET (child));
1884 priv = assistant->priv;
1886 if (GTK_IS_BUTTON (child))
1887 gtk_size_group_add_widget (priv->size_group, child);
1889 gtk_box_pack_end (GTK_BOX (priv->action_area), child, FALSE, FALSE, 0);
1893 * gtk_assistant_remove_action_widget:
1894 * @assistant: a #GtkAssistant
1895 * @child: a #GtkWidget
1897 * Removes a widget from the action area of a #GtkAssistant.
1902 gtk_assistant_remove_action_widget (GtkAssistant *assistant,
1905 GtkAssistantPrivate *priv;
1907 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1908 g_return_if_fail (GTK_IS_WIDGET (child));
1910 priv = assistant->priv;
1912 if (GTK_IS_BUTTON (child))
1913 gtk_size_group_remove_widget (priv->size_group, child);
1915 gtk_container_remove (GTK_CONTAINER (priv->action_area), child);
1919 * gtk_assistant_set_page_title:
1920 * @assistant: a #GtkAssistant
1921 * @page: a page of @assistant
1922 * @title: the new title for @page
1924 * Sets a title for @page. The title is displayed in the header
1925 * area of the assistant when @page is the current page.
1930 gtk_assistant_set_page_title (GtkAssistant *assistant,
1934 GtkAssistantPage *page_info;
1937 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1938 g_return_if_fail (GTK_IS_WIDGET (page));
1940 child = find_page (assistant, page);
1942 g_return_if_fail (child != NULL);
1944 page_info = (GtkAssistantPage*) child->data;
1946 gtk_label_set_text ((GtkLabel*) page_info->title, title);
1947 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1948 gtk_widget_child_notify (page, "title");
1952 * gtk_assistant_get_page_title:
1953 * @assistant: a #GtkAssistant
1954 * @page: a page of @assistant
1956 * Gets the title for @page.
1958 * Return value: the title for @page.
1962 G_CONST_RETURN gchar*
1963 gtk_assistant_get_page_title (GtkAssistant *assistant,
1966 GtkAssistantPage *page_info;
1969 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1970 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1972 child = find_page (assistant, page);
1974 g_return_val_if_fail (child != NULL, NULL);
1976 page_info = (GtkAssistantPage*) child->data;
1978 return gtk_label_get_text ((GtkLabel*) page_info->title);
1982 * gtk_assistant_set_page_type:
1983 * @assistant: a #GtkAssistant
1984 * @page: a page of @assistant
1985 * @type: the new type for @page
1987 * Sets the page type for @page. The page type determines the page
1988 * behavior in the @assistant.
1993 gtk_assistant_set_page_type (GtkAssistant *assistant,
1995 GtkAssistantPageType type)
1997 GtkAssistantPrivate *priv;
1998 GtkAssistantPage *page_info;
2001 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2002 g_return_if_fail (GTK_IS_WIDGET (page));
2004 priv = assistant->priv;
2005 child = find_page (assistant, page);
2007 g_return_if_fail (child != NULL);
2009 page_info = (GtkAssistantPage*) child->data;
2011 if (type != page_info->type)
2013 page_info->type = type;
2015 /* backwards compatibility to the era before fixing bug 604289 */
2016 if (type == GTK_ASSISTANT_PAGE_SUMMARY && !page_info->complete_set)
2018 gtk_assistant_set_page_complete (assistant, page, TRUE);
2019 page_info->complete_set = FALSE;
2022 /* Always set buttons state, a change in a future page
2023 might change current page buttons */
2024 set_assistant_buttons_state (assistant);
2026 gtk_widget_child_notify (page, "page-type");
2031 * gtk_assistant_get_page_type:
2032 * @assistant: a #GtkAssistant
2033 * @page: a page of @assistant
2035 * Gets the page type of @page.
2037 * Return value: the page type of @page.
2041 GtkAssistantPageType
2042 gtk_assistant_get_page_type (GtkAssistant *assistant,
2045 GtkAssistantPage *page_info;
2048 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), GTK_ASSISTANT_PAGE_CONTENT);
2049 g_return_val_if_fail (GTK_IS_WIDGET (page), GTK_ASSISTANT_PAGE_CONTENT);
2051 child = find_page (assistant, page);
2053 g_return_val_if_fail (child != NULL, GTK_ASSISTANT_PAGE_CONTENT);
2055 page_info = (GtkAssistantPage*) child->data;
2057 return page_info->type;
2061 * gtk_assistant_set_page_header_image:
2062 * @assistant: a #GtkAssistant
2063 * @page: a page of @assistant
2064 * @pixbuf: (allow-none): the new header image @page
2066 * Sets a header image for @page. This image is displayed in the header
2067 * area of the assistant when @page is the current page.
2072 gtk_assistant_set_page_header_image (GtkAssistant *assistant,
2076 GtkAssistantPrivate *priv;
2077 GtkAssistantPage *page_info;
2080 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2081 g_return_if_fail (GTK_IS_WIDGET (page));
2082 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2084 priv = assistant->priv;
2085 child = find_page (assistant, page);
2087 g_return_if_fail (child != NULL);
2089 page_info = (GtkAssistantPage*) child->data;
2091 if (pixbuf != page_info->header_image)
2093 if (page_info->header_image)
2095 g_object_unref (page_info->header_image);
2096 page_info->header_image = NULL;
2100 page_info->header_image = g_object_ref (pixbuf);
2102 if (page_info == priv->current_page)
2103 set_assistant_header_image (assistant);
2105 gtk_widget_child_notify (page, "header-image");
2110 * gtk_assistant_get_page_header_image:
2111 * @assistant: a #GtkAssistant
2112 * @page: a page of @assistant
2114 * Gets the header image for @page.
2116 * Return value: (transfer none): the header image for @page, or %NULL
2117 * if there's no header image for the page.
2122 gtk_assistant_get_page_header_image (GtkAssistant *assistant,
2125 GtkAssistantPage *page_info;
2128 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2129 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2131 child = find_page (assistant, page);
2133 g_return_val_if_fail (child != NULL, NULL);
2135 page_info = (GtkAssistantPage*) child->data;
2137 return page_info->header_image;
2141 * gtk_assistant_set_page_side_image:
2142 * @assistant: a #GtkAssistant
2143 * @page: a page of @assistant
2144 * @pixbuf: (allow-none): the new header image @page
2146 * Sets a header image for @page. This image is displayed in the side
2147 * area of the assistant when @page is the current page.
2152 gtk_assistant_set_page_side_image (GtkAssistant *assistant,
2156 GtkAssistantPrivate *priv;
2157 GtkAssistantPage *page_info;
2160 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2161 g_return_if_fail (GTK_IS_WIDGET (page));
2162 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2164 priv = assistant->priv;
2165 child = find_page (assistant, page);
2167 g_return_if_fail (child != NULL);
2169 page_info = (GtkAssistantPage*) child->data;
2171 if (pixbuf != page_info->sidebar_image)
2173 if (page_info->sidebar_image)
2175 g_object_unref (page_info->sidebar_image);
2176 page_info->sidebar_image = NULL;
2180 page_info->sidebar_image = g_object_ref (pixbuf);
2182 if (page_info == priv->current_page)
2183 set_assistant_sidebar_image (assistant);
2185 gtk_widget_child_notify (page, "sidebar-image");
2190 * gtk_assistant_get_page_side_image:
2191 * @assistant: a #GtkAssistant
2192 * @page: a page of @assistant
2194 * Gets the header image for @page.
2196 * Return value: (transfer none): the side image for @page, or %NULL
2197 * if there's no side image for the page.
2202 gtk_assistant_get_page_side_image (GtkAssistant *assistant,
2205 GtkAssistantPage *page_info;
2208 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2209 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2211 child = find_page (assistant, page);
2213 g_return_val_if_fail (child != NULL, NULL);
2215 page_info = (GtkAssistantPage*) child->data;
2217 return page_info->sidebar_image;
2221 * gtk_assistant_set_page_complete:
2222 * @assistant: a #GtkAssistant
2223 * @page: a page of @assistant
2224 * @complete: the completeness status of the page
2226 * Sets whether @page contents are complete. This will make
2227 * @assistant update the buttons state to be able to continue the task.
2232 gtk_assistant_set_page_complete (GtkAssistant *assistant,
2236 GtkAssistantPrivate *priv;
2237 GtkAssistantPage *page_info;
2240 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2241 g_return_if_fail (GTK_IS_WIDGET (page));
2243 priv = assistant->priv;
2244 child = find_page (assistant, page);
2246 g_return_if_fail (child != NULL);
2248 page_info = (GtkAssistantPage*) child->data;
2250 if (complete != page_info->complete)
2252 page_info->complete = complete;
2253 page_info->complete_set = TRUE;
2255 /* Always set buttons state, a change in a future page
2256 might change current page buttons */
2257 set_assistant_buttons_state (assistant);
2259 gtk_widget_child_notify (page, "complete");
2264 * gtk_assistant_get_page_complete:
2265 * @assistant: a #GtkAssistant
2266 * @page: a page of @assistant
2268 * Gets whether @page is complete.
2270 * Return value: %TRUE if @page is complete.
2275 gtk_assistant_get_page_complete (GtkAssistant *assistant,
2278 GtkAssistantPage *page_info;
2281 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), FALSE);
2282 g_return_val_if_fail (GTK_IS_WIDGET (page), FALSE);
2284 child = find_page (assistant, page);
2286 g_return_val_if_fail (child != NULL, FALSE);
2288 page_info = (GtkAssistantPage*) child->data;
2290 return page_info->complete;
2294 * gtk_assistant_update_buttons_state:
2295 * @assistant: a #GtkAssistant
2297 * Forces @assistant to recompute the buttons state.
2299 * GTK+ automatically takes care of this in most situations,
2300 * e.g. when the user goes to a different page, or when the
2301 * visibility or completeness of a page changes.
2303 * One situation where it can be necessary to call this
2304 * function is when changing a value on the current page
2305 * affects the future page flow of the assistant.
2310 gtk_assistant_update_buttons_state (GtkAssistant *assistant)
2312 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2314 set_assistant_buttons_state (assistant);
2318 * gtk_assistant_commit:
2319 * @assistant: a #GtkAssistant
2321 * Erases the visited page history so the back button is not
2322 * shown on the current page, and removes the cancel button
2323 * from subsequent pages.
2325 * Use this when the information provided up to the current
2326 * page is hereafter deemed permanent and cannot be modified
2327 * or undone. For example, showing a progress page to track
2328 * a long-running, unreversible operation after the user has
2329 * clicked apply on a confirmation page.
2334 gtk_assistant_commit (GtkAssistant *assistant)
2336 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2338 g_slist_free (assistant->priv->visited_pages);
2339 assistant->priv->visited_pages = NULL;
2341 assistant->priv->committed = TRUE;
2343 set_assistant_buttons_state (assistant);
2348 /* accessible implementation */
2351 gtk_assistant_accessible_get_n_children (AtkObject *accessible)
2353 GtkAssistant *assistant;
2356 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2361 assistant = GTK_ASSISTANT (widget);
2363 return g_list_length (assistant->priv->pages) + 1;
2368 gtk_assistant_accessible_ref_child (AtkObject *accessible,
2371 GtkAssistant *assistant;
2372 GtkAssistantPrivate *priv;
2373 GtkWidget *widget, *child;
2378 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2382 assistant = GTK_ASSISTANT (widget);
2383 priv = assistant->priv;
2384 n_pages = g_list_length (priv->pages);
2388 else if (index < n_pages)
2390 GtkAssistantPage *page = g_list_nth_data (priv->pages, index);
2393 title = gtk_assistant_get_page_title (assistant, child);
2395 else if (index == n_pages)
2397 child = priv->action_area;
2403 obj = gtk_widget_get_accessible (child);
2406 atk_object_set_name (obj, title);
2408 return g_object_ref (obj);
2412 gtk_assistant_accessible_class_init (AtkObjectClass *class)
2414 class->get_n_children = gtk_assistant_accessible_get_n_children;
2415 class->ref_child = gtk_assistant_accessible_ref_child;
2419 gtk_assistant_accessible_get_type (void)
2421 static GType type = 0;
2426 * Figure out the size of the class and instance
2427 * we are deriving from
2429 AtkObjectFactory *factory;
2432 GType derived_atk_type;
2434 derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
2435 factory = atk_registry_get_factory (atk_get_default_registry (),
2437 derived_atk_type = atk_object_factory_get_accessible_type (factory);
2438 g_type_query (derived_atk_type, &query);
2440 type = g_type_register_static_simple (derived_atk_type,
2441 I_("GtkAssistantAccessible"),
2443 (GClassInitFunc) gtk_assistant_accessible_class_init,
2444 query.instance_size,
2452 gtk_assistant_accessible_new (GObject *obj)
2454 AtkObject *accessible;
2456 g_return_val_if_fail (GTK_IS_ASSISTANT (obj), NULL);
2458 accessible = g_object_new (gtk_assistant_accessible_get_type (), NULL);
2459 atk_object_initialize (accessible, obj);
2465 gtk_assistant_accessible_factory_get_accessible_type (void)
2467 return gtk_assistant_accessible_get_type ();
2471 gtk_assistant_accessible_factory_create_accessible (GObject *obj)
2473 return gtk_assistant_accessible_new (obj);
2477 gtk_assistant_accessible_factory_class_init (AtkObjectFactoryClass *class)
2479 class->create_accessible = gtk_assistant_accessible_factory_create_accessible;
2480 class->get_accessible_type = gtk_assistant_accessible_factory_get_accessible_type;
2484 gtk_assistant_accessible_factory_get_type (void)
2486 static GType type = 0;
2490 type = g_type_register_static_simple (ATK_TYPE_OBJECT_FACTORY,
2491 I_("GtkAssistantAccessibleFactory"),
2492 sizeof (AtkObjectFactoryClass),
2493 (GClassInitFunc) gtk_assistant_accessible_factory_class_init,
2494 sizeof (AtkObjectFactory),
2502 gtk_assistant_get_accessible (GtkWidget *widget)
2504 static gboolean first_time = TRUE;
2508 AtkObjectFactory *factory;
2509 AtkRegistry *registry;
2511 GType derived_atk_type;
2514 * Figure out whether accessibility is enabled by looking at the
2515 * type of the accessible object which would be created for
2516 * the parent type of GtkAssistant.
2518 derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
2520 registry = atk_get_default_registry ();
2521 factory = atk_registry_get_factory (registry,
2523 derived_atk_type = atk_object_factory_get_accessible_type (factory);
2524 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
2526 atk_registry_set_factory_type (registry,
2528 gtk_assistant_accessible_factory_get_type ());
2533 return GTK_WIDGET_CLASS (gtk_assistant_parent_class)->get_accessible (widget);
2537 static GtkBuildableIface *parent_buildable_iface;
2540 gtk_assistant_buildable_interface_init (GtkBuildableIface *iface)
2542 parent_buildable_iface = g_type_interface_peek_parent (iface);
2543 iface->get_internal_child = gtk_assistant_buildable_get_internal_child;
2544 iface->custom_tag_start = gtk_assistant_buildable_custom_tag_start;
2545 iface->custom_finished = gtk_assistant_buildable_custom_finished;
2549 gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
2550 GtkBuilder *builder,
2551 const gchar *childname)
2553 if (strcmp (childname, "action_area") == 0)
2554 return G_OBJECT (GTK_ASSISTANT (buildable)->priv->action_area);
2556 return parent_buildable_iface->get_internal_child (buildable,
2562 gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
2563 GtkBuilder *builder,
2565 const gchar *tagname,
2566 GMarkupParser *parser,
2569 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
2570 tagname, parser, data);
2574 gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
2575 GtkBuilder *builder,
2577 const gchar *tagname,
2580 parent_buildable_iface->custom_finished (buildable, builder, child,
2581 tagname, user_data);