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"
64 #include "gtkprivate.h"
65 #include "gtkbuildable.h"
68 #define HEADER_SPACING 12
69 #define ACTION_AREA_SPACING 12
71 typedef struct _GtkAssistantPage GtkAssistantPage;
73 struct _GtkAssistantPage
76 GtkAssistantPageType type;
78 guint complete_set : 1;
81 GdkPixbuf *header_image;
82 GdkPixbuf *sidebar_image;
85 struct _GtkAssistantPrivate
94 GtkWidget *header_image;
95 GtkWidget *sidebar_image;
97 GtkWidget *action_area;
101 GtkAssistantPage *current_page;
103 GSList *visited_pages;
105 GtkSizeGroup *size_group;
107 GtkAssistantPageFunc forward_function;
108 gpointer forward_function_data;
109 GDestroyNotify forward_data_destroy;
114 static void gtk_assistant_class_init (GtkAssistantClass *class);
115 static void gtk_assistant_init (GtkAssistant *assistant);
116 static void gtk_assistant_destroy (GtkObject *object);
117 static void gtk_assistant_style_set (GtkWidget *widget,
118 GtkStyle *old_style);
119 static void gtk_assistant_size_request (GtkWidget *widget,
120 GtkRequisition *requisition);
121 static void gtk_assistant_size_allocate (GtkWidget *widget,
122 GtkAllocation *allocation);
123 static void gtk_assistant_map (GtkWidget *widget);
124 static void gtk_assistant_unmap (GtkWidget *widget);
125 static gboolean gtk_assistant_delete_event (GtkWidget *widget,
127 static gboolean gtk_assistant_expose (GtkWidget *widget,
128 GdkEventExpose *event);
129 static gboolean gtk_assistant_focus (GtkWidget *widget,
130 GtkDirectionType direction);
131 static void gtk_assistant_add (GtkContainer *container,
133 static void gtk_assistant_remove (GtkContainer *container,
135 static void gtk_assistant_forall (GtkContainer *container,
136 gboolean include_internals,
137 GtkCallback callback,
138 gpointer callback_data);
139 static void gtk_assistant_set_child_property (GtkContainer *container,
144 static void gtk_assistant_get_child_property (GtkContainer *container,
150 static AtkObject *gtk_assistant_get_accessible (GtkWidget *widget);
152 static void gtk_assistant_buildable_interface_init (GtkBuildableIface *iface);
153 static GObject *gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
155 const gchar *childname);
156 static gboolean gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
159 const gchar *tagname,
160 GMarkupParser *parser,
162 static void gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
165 const gchar *tagname,
168 static GList* find_page (GtkAssistant *assistant,
174 CHILD_PROP_PAGE_TYPE,
175 CHILD_PROP_PAGE_TITLE,
176 CHILD_PROP_PAGE_HEADER_IMAGE,
177 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
178 CHILD_PROP_PAGE_COMPLETE
190 static guint signals [LAST_SIGNAL] = { 0 };
193 G_DEFINE_TYPE_WITH_CODE (GtkAssistant, gtk_assistant, GTK_TYPE_WINDOW,
194 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
195 gtk_assistant_buildable_interface_init))
199 gtk_assistant_class_init (GtkAssistantClass *class)
201 GObjectClass *gobject_class;
202 GtkObjectClass *object_class;
203 GtkWidgetClass *widget_class;
204 GtkContainerClass *container_class;
206 gobject_class = (GObjectClass *) class;
207 object_class = (GtkObjectClass *) class;
208 widget_class = (GtkWidgetClass *) class;
209 container_class = (GtkContainerClass *) class;
211 object_class->destroy = gtk_assistant_destroy;
213 widget_class->style_set = gtk_assistant_style_set;
214 widget_class->size_request = gtk_assistant_size_request;
215 widget_class->size_allocate = gtk_assistant_size_allocate;
216 widget_class->map = gtk_assistant_map;
217 widget_class->unmap = gtk_assistant_unmap;
218 widget_class->delete_event = gtk_assistant_delete_event;
219 widget_class->expose_event = gtk_assistant_expose;
220 widget_class->focus = gtk_assistant_focus;
221 widget_class->get_accessible = gtk_assistant_get_accessible;
223 container_class->add = gtk_assistant_add;
224 container_class->remove = gtk_assistant_remove;
225 container_class->forall = gtk_assistant_forall;
226 container_class->set_child_property = gtk_assistant_set_child_property;
227 container_class->get_child_property = gtk_assistant_get_child_property;
230 * GtkAssistant::cancel:
231 * @assistant: the #GtkAssistant
233 * The ::cancel signal is emitted when then the cancel button is clicked.
238 g_signal_new (I_("cancel"),
239 G_TYPE_FROM_CLASS (gobject_class),
241 G_STRUCT_OFFSET (GtkAssistantClass, cancel),
243 g_cclosure_marshal_VOID__VOID,
247 * GtkAssistant::prepare:
248 * @assistant: the #GtkAssistant
249 * @page: the current page
251 * The ::prepare signal is emitted when a new page is set as the assistant's
252 * current page, before making the new page visible. A handler for this signal
253 * can do any preparation which are necessary before showing @page.
258 g_signal_new (I_("prepare"),
259 G_TYPE_FROM_CLASS (gobject_class),
261 G_STRUCT_OFFSET (GtkAssistantClass, prepare),
263 g_cclosure_marshal_VOID__OBJECT,
264 G_TYPE_NONE, 1, GTK_TYPE_WIDGET);
267 * GtkAssistant::apply:
268 * @assistant: the #GtkAssistant
270 * The ::apply signal is emitted when the apply button is clicked. The default
271 * behavior of the #GtkAssistant is to switch to the page after the current
272 * page, unless the current page is the last one.
274 * A handler for the ::apply signal should carry out the actions for which
275 * the wizard has collected data. If the action takes a long time to complete,
276 * you might consider putting a page of type %GTK_ASSISTANT_PAGE_PROGRESS
277 * after the confirmation page and handle this operation within the
278 * #GtkAssistant::prepare signal of the progress page.
283 g_signal_new (I_("apply"),
284 G_TYPE_FROM_CLASS (gobject_class),
286 G_STRUCT_OFFSET (GtkAssistantClass, apply),
288 g_cclosure_marshal_VOID__VOID,
292 * GtkAssistant::close:
293 * @assistant: the #GtkAssistant
295 * The ::close signal is emitted either when the close button of
296 * a summary page is clicked, or when the apply button in the last
297 * page in the flow (of type %GTK_ASSISTANT_PAGE_CONFIRM) is clicked.
302 g_signal_new (I_("close"),
303 G_TYPE_FROM_CLASS (gobject_class),
305 G_STRUCT_OFFSET (GtkAssistantClass, close),
307 g_cclosure_marshal_VOID__VOID,
310 gtk_widget_class_install_style_property (widget_class,
311 g_param_spec_int ("header-padding",
312 P_("Header Padding"),
313 P_("Number of pixels around the header."),
317 GTK_PARAM_READABLE));
318 gtk_widget_class_install_style_property (widget_class,
319 g_param_spec_int ("content-padding",
320 P_("Content Padding"),
321 P_("Number of pixels around the content pages."),
325 GTK_PARAM_READABLE));
328 * GtkAssistant:page-type:
330 * The type of the assistant page.
334 gtk_container_class_install_child_property (container_class,
335 CHILD_PROP_PAGE_TYPE,
336 g_param_spec_enum ("page-type",
338 P_("The type of the assistant page"),
339 GTK_TYPE_ASSISTANT_PAGE_TYPE,
340 GTK_ASSISTANT_PAGE_CONTENT,
341 GTK_PARAM_READWRITE));
344 * GtkAssistant:title:
346 * The title that is displayed in the page header.
348 * If title and header-image are both %NULL, no header is displayed.
352 gtk_container_class_install_child_property (container_class,
353 CHILD_PROP_PAGE_TITLE,
354 g_param_spec_string ("title",
356 P_("The title of the assistant page"),
358 GTK_PARAM_READWRITE));
361 * GtkAssistant:header-image:
363 * The image that is displayed next to the title in the page header.
365 * If title and header-image are both %NULL, no header is displayed.
369 gtk_container_class_install_child_property (container_class,
370 CHILD_PROP_PAGE_HEADER_IMAGE,
371 g_param_spec_object ("header-image",
373 P_("Header image for the assistant page"),
375 GTK_PARAM_READWRITE));
378 * GtkAssistant:header-image:
380 * The image that is displayed next to the page.
382 * Set this to %NULL to make the sidebar disappear.
386 gtk_container_class_install_child_property (container_class,
387 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
388 g_param_spec_object ("sidebar-image",
390 P_("Sidebar image for the assistant page"),
392 GTK_PARAM_READWRITE));
394 * GtkAssistant:complete:
396 * Setting the "complete" child property to %TRUE marks a page as complete
397 * (i.e.: all the required fields are filled out). GTK+ uses this information
398 * to control the sensitivity of the navigation buttons.
402 gtk_container_class_install_child_property (container_class,
403 CHILD_PROP_PAGE_COMPLETE,
404 g_param_spec_boolean ("complete",
406 P_("Whether all required fields on the page have been filled out"),
410 g_type_class_add_private (gobject_class, sizeof (GtkAssistantPrivate));
414 default_forward_function (gint current_page, gpointer data)
416 GtkAssistant *assistant;
417 GtkAssistantPrivate *priv;
418 GtkAssistantPage *page_info;
421 assistant = GTK_ASSISTANT (data);
422 priv = assistant->priv;
424 page_node = g_list_nth (priv->pages, ++current_page);
429 page_info = (GtkAssistantPage *) page_node->data;
431 while (page_node && !gtk_widget_get_visible (page_info->page))
433 page_node = page_node->next;
437 page_info = (GtkAssistantPage *) page_node->data;
444 compute_last_button_state (GtkAssistant *assistant)
446 GtkAssistantPrivate *priv = assistant->priv;
447 GtkAssistantPage *page_info, *current_page_info;
448 gint count, page_num, n_pages;
451 page_num = gtk_assistant_get_current_page (assistant);
452 n_pages = gtk_assistant_get_n_pages (assistant);
453 current_page_info = page_info = g_list_nth_data (priv->pages, page_num);
455 while (page_num >= 0 && page_num < n_pages &&
456 page_info->type == GTK_ASSISTANT_PAGE_CONTENT &&
457 (count == 0 || page_info->complete) &&
460 page_num = (priv->forward_function) (page_num, priv->forward_function_data);
461 page_info = g_list_nth_data (priv->pages, page_num);
466 /* make the last button visible if we can skip multiple
467 * pages and end on a confirmation or summary page
469 if (count > 1 && page_info &&
470 (page_info->type == GTK_ASSISTANT_PAGE_CONFIRM ||
471 page_info->type == GTK_ASSISTANT_PAGE_SUMMARY))
473 gtk_widget_show (priv->last);
474 gtk_widget_set_sensitive (priv->last,
475 current_page_info->complete);
478 gtk_widget_hide (priv->last);
482 compute_progress_state (GtkAssistant *assistant)
484 GtkAssistantPrivate *priv = assistant->priv;
485 gint page_num, n_pages;
487 n_pages = gtk_assistant_get_n_pages (assistant);
488 page_num = gtk_assistant_get_current_page (assistant);
490 page_num = (priv->forward_function) (page_num, priv->forward_function_data);
492 if (page_num >= 0 && page_num < n_pages)
493 gtk_widget_show (priv->forward);
495 gtk_widget_hide (priv->forward);
499 set_assistant_header_image (GtkAssistant *assistant)
501 GtkAssistantPrivate *priv = assistant->priv;
503 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->header_image),
504 priv->current_page->header_image);
508 set_assistant_sidebar_image (GtkAssistant *assistant)
510 GtkAssistantPrivate *priv = assistant->priv;
512 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->sidebar_image),
513 priv->current_page->sidebar_image);
515 if (priv->current_page->sidebar_image)
516 gtk_widget_show (priv->sidebar_image);
518 gtk_widget_hide (priv->sidebar_image);
522 set_assistant_buttons_state (GtkAssistant *assistant)
524 GtkAssistantPrivate *priv = assistant->priv;
526 if (!priv->current_page)
529 switch (priv->current_page->type)
531 case GTK_ASSISTANT_PAGE_INTRO:
532 gtk_widget_set_sensitive (priv->cancel, TRUE);
533 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
534 gtk_widget_grab_default (priv->forward);
535 gtk_widget_show (priv->forward);
536 gtk_widget_hide (priv->back);
537 gtk_widget_hide (priv->apply);
538 gtk_widget_hide (priv->close);
539 compute_last_button_state (assistant);
541 case GTK_ASSISTANT_PAGE_CONFIRM:
542 gtk_widget_set_sensitive (priv->cancel, TRUE);
543 gtk_widget_set_sensitive (priv->back, TRUE);
544 gtk_widget_set_sensitive (priv->apply, priv->current_page->complete);
545 gtk_widget_grab_default (priv->apply);
546 gtk_widget_show (priv->back);
547 gtk_widget_show (priv->apply);
548 gtk_widget_hide (priv->forward);
549 gtk_widget_hide (priv->close);
550 gtk_widget_hide (priv->last);
552 case GTK_ASSISTANT_PAGE_CONTENT:
553 gtk_widget_set_sensitive (priv->cancel, TRUE);
554 gtk_widget_set_sensitive (priv->back, TRUE);
555 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
556 gtk_widget_grab_default (priv->forward);
557 gtk_widget_show (priv->back);
558 gtk_widget_show (priv->forward);
559 gtk_widget_hide (priv->apply);
560 gtk_widget_hide (priv->close);
561 compute_last_button_state (assistant);
563 case GTK_ASSISTANT_PAGE_SUMMARY:
564 gtk_widget_set_sensitive (priv->close, priv->current_page->complete);
565 gtk_widget_grab_default (priv->close);
566 gtk_widget_show (priv->close);
567 gtk_widget_hide (priv->back);
568 gtk_widget_hide (priv->forward);
569 gtk_widget_hide (priv->apply);
570 gtk_widget_hide (priv->last);
572 case GTK_ASSISTANT_PAGE_PROGRESS:
573 gtk_widget_set_sensitive (priv->cancel, priv->current_page->complete);
574 gtk_widget_set_sensitive (priv->back, priv->current_page->complete);
575 gtk_widget_set_sensitive (priv->forward, priv->current_page->complete);
576 gtk_widget_grab_default (priv->forward);
577 gtk_widget_show (priv->back);
578 gtk_widget_hide (priv->apply);
579 gtk_widget_hide (priv->close);
580 gtk_widget_hide (priv->last);
581 compute_progress_state (assistant);
584 g_assert_not_reached ();
588 gtk_widget_hide (priv->cancel);
589 else if (priv->current_page->type == GTK_ASSISTANT_PAGE_SUMMARY)
590 gtk_widget_hide (priv->cancel);
592 gtk_widget_show (priv->cancel);
594 /* this is quite general, we don't want to
595 * go back if it's the first page */
596 if (!priv->visited_pages)
597 gtk_widget_hide (priv->back);
601 set_current_page (GtkAssistant *assistant,
602 GtkAssistantPage *page)
604 GtkAssistantPrivate *priv = assistant->priv;
605 GtkAssistantPage *old_page;
607 if (priv->current_page &&
608 gtk_widget_is_drawable (priv->current_page->page))
609 old_page = priv->current_page;
613 priv->current_page = page;
615 set_assistant_buttons_state (assistant);
616 set_assistant_header_image (assistant);
617 set_assistant_sidebar_image (assistant);
619 g_signal_emit (assistant, signals [PREPARE], 0, priv->current_page->page);
621 if (gtk_widget_get_visible (priv->current_page->page) && gtk_widget_get_mapped (GTK_WIDGET (assistant)))
623 gtk_widget_set_child_visible (priv->current_page->page, TRUE);
624 gtk_widget_map (priv->current_page->page);
625 gtk_widget_map (priv->current_page->title);
628 if (old_page && gtk_widget_get_mapped (old_page->page))
630 gtk_widget_set_child_visible (old_page->page, FALSE);
631 gtk_widget_unmap (old_page->page);
632 gtk_widget_unmap (old_page->title);
635 if (!gtk_widget_child_focus (priv->current_page->page, GTK_DIR_TAB_FORWARD))
637 GtkWidget *button[6];
640 /* find the best button to focus */
641 button[0] = priv->apply;
642 button[1] = priv->close;
643 button[2] = priv->forward;
644 button[3] = priv->back;
645 button[4] = priv->cancel;
646 button[5] = priv->last;
647 for (i = 0; i < 6; i++)
649 if (gtk_widget_get_visible (button[i]) && gtk_widget_get_sensitive (button[i]))
651 gtk_widget_grab_focus (button[i]);
657 gtk_widget_queue_resize (GTK_WIDGET (assistant));
661 compute_next_step (GtkAssistant *assistant)
663 GtkAssistantPrivate *priv = assistant->priv;
664 GtkAssistantPage *page_info;
665 gint current_page, n_pages, next_page;
667 current_page = gtk_assistant_get_current_page (assistant);
668 page_info = priv->current_page;
669 n_pages = gtk_assistant_get_n_pages (assistant);
671 next_page = (priv->forward_function) (current_page,
672 priv->forward_function_data);
674 if (next_page >= 0 && next_page < n_pages)
676 priv->visited_pages = g_slist_prepend (priv->visited_pages, page_info);
677 set_current_page (assistant, g_list_nth_data (priv->pages, next_page));
686 on_assistant_close (GtkWidget *widget,
687 GtkAssistant *assistant)
689 g_signal_emit (assistant, signals [CLOSE], 0, NULL);
693 on_assistant_apply (GtkWidget *widget,
694 GtkAssistant *assistant)
698 g_signal_emit (assistant, signals [APPLY], 0);
700 success = compute_next_step (assistant);
702 /* if the assistant hasn't switched to another page, just emit
703 * the CLOSE signal, it't the last page in the assistant flow
706 g_signal_emit (assistant, signals [CLOSE], 0);
710 on_assistant_forward (GtkWidget *widget,
711 GtkAssistant *assistant)
713 if (!compute_next_step (assistant))
714 g_critical ("Page flow is broken, you may want to end it with a page of "
715 "type GTK_ASSISTANT_PAGE_CONFIRM or GTK_ASSISTANT_PAGE_SUMMARY");
719 on_assistant_back (GtkWidget *widget,
720 GtkAssistant *assistant)
722 GtkAssistantPrivate *priv = assistant->priv;
723 GtkAssistantPage *page_info;
726 /* skip the progress pages when going back */
729 page_node = priv->visited_pages;
731 g_return_if_fail (page_node != NULL);
733 priv->visited_pages = priv->visited_pages->next;
734 page_info = (GtkAssistantPage *) page_node->data;
735 g_slist_free_1 (page_node);
737 while (page_info->type == GTK_ASSISTANT_PAGE_PROGRESS ||
738 !gtk_widget_get_visible (page_info->page));
740 set_current_page (assistant, page_info);
744 on_assistant_cancel (GtkWidget *widget,
745 GtkAssistant *assistant)
747 g_signal_emit (assistant, signals [CANCEL], 0, NULL);
751 on_assistant_last (GtkWidget *widget,
752 GtkAssistant *assistant)
754 GtkAssistantPrivate *priv = assistant->priv;
756 while (priv->current_page->type == GTK_ASSISTANT_PAGE_CONTENT &&
757 priv->current_page->complete)
758 compute_next_step (assistant);
762 alternative_button_order (GtkAssistant *assistant)
764 GtkSettings *settings;
768 screen = gtk_widget_get_screen (GTK_WIDGET (assistant));
769 settings = gtk_settings_get_for_screen (screen);
771 g_object_get (settings,
772 "gtk-alternative-button-order", &result,
778 gtk_assistant_init (GtkAssistant *assistant)
780 GtkAssistantPrivate *priv;
782 assistant->priv = G_TYPE_INSTANCE_GET_PRIVATE (assistant,
784 GtkAssistantPrivate);
785 priv = assistant->priv;
787 gtk_container_set_reallocate_redraws (GTK_CONTAINER (assistant), TRUE);
788 gtk_container_set_border_width (GTK_CONTAINER (assistant), 12);
790 gtk_widget_push_composite_child ();
793 priv->header_image = gtk_image_new ();
794 gtk_misc_set_alignment (GTK_MISC (priv->header_image), 1., 0.5);
795 gtk_widget_set_parent (priv->header_image, GTK_WIDGET (assistant));
796 gtk_widget_show (priv->header_image);
799 priv->sidebar_image = gtk_image_new ();
800 gtk_misc_set_alignment (GTK_MISC (priv->sidebar_image), 0., 0.);
801 gtk_widget_set_parent (priv->sidebar_image, GTK_WIDGET (assistant));
802 gtk_widget_show (priv->sidebar_image);
805 priv->action_area = gtk_hbox_new (FALSE, 6);
807 priv->close = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
808 priv->apply = gtk_button_new_from_stock (GTK_STOCK_APPLY);
809 priv->forward = gtk_button_new_from_stock (GTK_STOCK_GO_FORWARD);
810 priv->back = gtk_button_new_from_stock (GTK_STOCK_GO_BACK);
811 priv->cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
812 priv->last = gtk_button_new_from_stock (GTK_STOCK_GOTO_LAST);
813 gtk_widget_set_can_default (priv->close, TRUE);
814 gtk_widget_set_can_default (priv->apply, TRUE);
815 gtk_widget_set_can_default (priv->forward, TRUE);
817 priv->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
818 gtk_size_group_add_widget (priv->size_group, priv->close);
819 gtk_size_group_add_widget (priv->size_group, priv->apply);
820 gtk_size_group_add_widget (priv->size_group, priv->forward);
821 gtk_size_group_add_widget (priv->size_group, priv->back);
822 gtk_size_group_add_widget (priv->size_group, priv->cancel);
823 gtk_size_group_add_widget (priv->size_group, priv->last);
825 if (!alternative_button_order (assistant))
827 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
828 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
829 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
830 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
831 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
832 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->close, FALSE, FALSE, 0);
836 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->close, FALSE, FALSE, 0);
837 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->cancel, FALSE, FALSE, 0);
838 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->apply, FALSE, FALSE, 0);
839 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->forward, FALSE, FALSE, 0);
840 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->back, FALSE, FALSE, 0);
841 gtk_box_pack_end (GTK_BOX (priv->action_area), priv->last, FALSE, FALSE, 0);
844 gtk_widget_set_parent (priv->action_area, GTK_WIDGET (assistant));
845 gtk_widget_show (priv->forward);
846 gtk_widget_show (priv->back);
847 gtk_widget_show (priv->cancel);
848 gtk_widget_show (priv->action_area);
850 gtk_widget_pop_composite_child ();
853 priv->current_page = NULL;
854 priv->visited_pages = NULL;
856 priv->forward_function = default_forward_function;
857 priv->forward_function_data = assistant;
858 priv->forward_data_destroy = NULL;
860 g_signal_connect (G_OBJECT (priv->close), "clicked",
861 G_CALLBACK (on_assistant_close), assistant);
862 g_signal_connect (G_OBJECT (priv->apply), "clicked",
863 G_CALLBACK (on_assistant_apply), assistant);
864 g_signal_connect (G_OBJECT (priv->forward), "clicked",
865 G_CALLBACK (on_assistant_forward), assistant);
866 g_signal_connect (G_OBJECT (priv->back), "clicked",
867 G_CALLBACK (on_assistant_back), assistant);
868 g_signal_connect (G_OBJECT (priv->cancel), "clicked",
869 G_CALLBACK (on_assistant_cancel), assistant);
870 g_signal_connect (G_OBJECT (priv->last), "clicked",
871 G_CALLBACK (on_assistant_last), assistant);
875 gtk_assistant_set_child_property (GtkContainer *container,
883 case CHILD_PROP_PAGE_TYPE:
884 gtk_assistant_set_page_type (GTK_ASSISTANT (container), child,
885 g_value_get_enum (value));
887 case CHILD_PROP_PAGE_TITLE:
888 gtk_assistant_set_page_title (GTK_ASSISTANT (container), child,
889 g_value_get_string (value));
891 case CHILD_PROP_PAGE_HEADER_IMAGE:
892 gtk_assistant_set_page_header_image (GTK_ASSISTANT (container), child,
893 g_value_get_object (value));
895 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
896 gtk_assistant_set_page_side_image (GTK_ASSISTANT (container), child,
897 g_value_get_object (value));
899 case CHILD_PROP_PAGE_COMPLETE:
900 gtk_assistant_set_page_complete (GTK_ASSISTANT (container), child,
901 g_value_get_boolean (value));
904 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
910 gtk_assistant_get_child_property (GtkContainer *container,
918 case CHILD_PROP_PAGE_TYPE:
919 g_value_set_enum (value,
920 gtk_assistant_get_page_type (GTK_ASSISTANT (container), child));
922 case CHILD_PROP_PAGE_TITLE:
923 g_value_set_string (value,
924 gtk_assistant_get_page_title (GTK_ASSISTANT (container), child));
926 case CHILD_PROP_PAGE_HEADER_IMAGE:
927 g_value_set_object (value,
928 gtk_assistant_get_page_header_image (GTK_ASSISTANT (container), child));
930 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
931 g_value_set_object (value,
932 gtk_assistant_get_page_side_image (GTK_ASSISTANT (container), child));
934 case CHILD_PROP_PAGE_COMPLETE:
935 g_value_set_boolean (value,
936 gtk_assistant_get_page_complete (GTK_ASSISTANT (container), child));
939 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
945 on_page_notify_visibility (GtkWidget *widget,
949 GtkAssistant *assistant = GTK_ASSISTANT (data);
951 /* update buttons state, flow may have changed */
952 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
953 set_assistant_buttons_state (assistant);
957 remove_page (GtkAssistant *assistant,
960 GtkAssistantPrivate *priv = assistant->priv;
961 GtkAssistantPage *page_info;
964 page_info = element->data;
966 /* If this is the current page, we need to switch away. */
967 if (page_info == priv->current_page)
969 if (!compute_next_step (assistant))
971 /* The best we can do at this point is probably to pick the first
974 page_node = priv->pages;
976 while (page_node && !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
977 page_node = page_node->next;
979 if (page_node == element)
980 page_node = page_node->next;
983 priv->current_page = page_node->data;
985 priv->current_page = NULL;
989 priv->pages = g_list_remove_link (priv->pages, element);
990 priv->visited_pages = g_slist_remove_all (priv->visited_pages, page_info);
992 g_signal_handlers_disconnect_by_func (page_info->page, on_page_notify_visibility, assistant);
993 gtk_widget_unparent (page_info->page);
995 if (page_info->header_image)
996 g_object_unref (page_info->header_image);
998 if (page_info->sidebar_image)
999 g_object_unref (page_info->sidebar_image);
1001 gtk_widget_destroy (page_info->title);
1002 g_slice_free (GtkAssistantPage, page_info);
1003 g_list_free_1 (element);
1007 gtk_assistant_destroy (GtkObject *object)
1009 GtkAssistant *assistant = GTK_ASSISTANT (object);
1010 GtkAssistantPrivate *priv = assistant->priv;
1012 if (priv->header_image)
1014 gtk_widget_destroy (priv->header_image);
1015 priv->header_image = NULL;
1018 if (priv->sidebar_image)
1020 gtk_widget_destroy (priv->sidebar_image);
1021 priv->sidebar_image = NULL;
1024 if (priv->action_area)
1026 gtk_widget_destroy (priv->action_area);
1027 priv->action_area = NULL;
1030 if (priv->size_group)
1032 g_object_unref (priv->size_group);
1033 priv->size_group = NULL;
1036 if (priv->forward_function)
1038 if (priv->forward_function_data &&
1039 priv->forward_data_destroy)
1040 priv->forward_data_destroy (priv->forward_function_data);
1042 priv->forward_function = NULL;
1043 priv->forward_function_data = NULL;
1044 priv->forward_data_destroy = NULL;
1047 if (priv->visited_pages)
1049 g_slist_free (priv->visited_pages);
1050 priv->visited_pages = NULL;
1053 /* We set current to NULL so that the remove code doesn't try
1054 * to do anything funny */
1055 priv->current_page = NULL;
1058 remove_page (GTK_ASSISTANT (object), priv->pages);
1060 GTK_OBJECT_CLASS (gtk_assistant_parent_class)->destroy (object);
1064 find_page (GtkAssistant *assistant,
1067 GtkAssistantPrivate *priv = assistant->priv;
1068 GList *child = priv->pages;
1072 GtkAssistantPage *page_info = child->data;
1073 if (page_info->page == page)
1076 child = child->next;
1083 set_title_colors (GtkWidget *assistant,
1084 GtkWidget *title_label)
1088 gtk_widget_ensure_style (assistant);
1089 style = gtk_widget_get_style (assistant);
1091 /* change colors schema, for making the header text visible */
1092 gtk_widget_modify_bg (title_label, GTK_STATE_NORMAL, &style->bg[GTK_STATE_SELECTED]);
1093 gtk_widget_modify_fg (title_label, GTK_STATE_NORMAL, &style->fg[GTK_STATE_SELECTED]);
1097 set_title_font (GtkWidget *assistant,
1098 GtkWidget *title_label)
1100 PangoFontDescription *desc;
1103 desc = pango_font_description_new ();
1104 size = pango_font_description_get_size (assistant->style->font_desc);
1106 pango_font_description_set_weight (desc, PANGO_WEIGHT_ULTRABOLD);
1107 pango_font_description_set_size (desc, size * PANGO_SCALE_XX_LARGE);
1109 gtk_widget_modify_font (title_label, desc);
1110 pango_font_description_free (desc);
1114 gtk_assistant_style_set (GtkWidget *widget,
1115 GtkStyle *old_style)
1117 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1118 GtkAssistantPrivate *priv = assistant->priv;
1125 GtkAssistantPage *page = list->data;
1127 set_title_colors (widget, page->title);
1128 set_title_font (widget, page->title);
1135 gtk_assistant_size_request (GtkWidget *widget,
1136 GtkRequisition *requisition)
1138 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1139 GtkAssistantPrivate *priv = assistant->priv;
1140 GtkRequisition child_requisition;
1141 gint header_padding, content_padding;
1142 gint width, height, header_width, header_height;
1146 gtk_widget_style_get (widget,
1147 "header-padding", &header_padding,
1148 "content-padding", &content_padding,
1151 header_width = header_height = 0;
1156 GtkAssistantPage *page = list->data;
1159 gtk_widget_size_request (page->page, &child_requisition);
1160 width = MAX (width, child_requisition.width);
1161 height = MAX (height, child_requisition.height);
1163 gtk_widget_size_request (page->title, &child_requisition);
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_size_request (priv->sidebar_image, &child_requisition);
1180 width += child_requisition.width;
1181 height = MAX (height, child_requisition.height);
1183 gtk_widget_set_size_request (priv->header_image, header_width, header_height);
1184 gtk_widget_size_request (priv->header_image, &child_requisition);
1185 width = MAX (width, header_width) + 2 * header_padding;
1186 height += header_height + 2 * header_padding;
1188 gtk_widget_size_request (priv->action_area, &child_requisition);
1189 width = MAX (width, child_requisition.width);
1190 height += child_requisition.height + ACTION_AREA_SPACING;
1192 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1193 width += border_width * 2 + content_padding * 2;
1194 height += border_width * 2 + content_padding * 2;
1196 requisition->width = width;
1197 requisition->height = height;
1202 gtk_assistant_size_allocate (GtkWidget *widget,
1203 GtkAllocation *allocation)
1205 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1206 GtkAssistantPrivate *priv = assistant->priv;
1207 GtkRequisition header_requisition, action_requisition, sidebar_requisition;
1208 GtkAllocation child_allocation, header_allocation;
1209 gint header_padding, content_padding;
1214 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1215 pages = priv->pages;
1217 gtk_widget_style_get (widget,
1218 "header-padding", &header_padding,
1219 "content-padding", &content_padding,
1222 widget->allocation = *allocation;
1223 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1226 gtk_widget_get_child_requisition (priv->header_image, &header_requisition);
1228 header_allocation.x = border_width + header_padding;
1229 header_allocation.y = border_width + header_padding;
1230 header_allocation.width = allocation->width - 2 * border_width - 2 * header_padding;
1231 header_allocation.height = header_requisition.height;
1233 gtk_widget_size_allocate (priv->header_image, &header_allocation);
1236 gtk_widget_get_child_requisition (priv->action_area, &action_requisition);
1238 child_allocation.x = border_width;
1239 child_allocation.y = allocation->height - border_width - action_requisition.height;
1240 child_allocation.width = allocation->width - 2 * border_width;
1241 child_allocation.height = action_requisition.height;
1243 gtk_widget_size_allocate (priv->action_area, &child_allocation);
1246 gtk_widget_get_child_requisition (priv->sidebar_image, &sidebar_requisition);
1249 child_allocation.x = allocation->width - border_width - sidebar_requisition.width;
1251 child_allocation.x = border_width;
1253 child_allocation.y = border_width + priv->header_image->allocation.height + 2 * header_padding;
1254 child_allocation.width = sidebar_requisition.width;
1255 child_allocation.height = allocation->height - 2 * border_width -
1256 priv->header_image->allocation.height - 2 * header_padding - priv->action_area->allocation.height;
1258 gtk_widget_size_allocate (priv->sidebar_image, &child_allocation);
1261 child_allocation.x = border_width + content_padding;
1262 child_allocation.y = border_width +
1263 priv->header_image->allocation.height + 2 * header_padding + content_padding;
1264 child_allocation.width = allocation->width - 2 * border_width - 2 * content_padding;
1265 child_allocation.height = allocation->height - 2 * border_width -
1266 priv->header_image->allocation.height - 2 * header_padding - ACTION_AREA_SPACING - priv->action_area->allocation.height - 2 * content_padding;
1268 if (gtk_widget_get_visible (priv->sidebar_image))
1271 child_allocation.x += priv->sidebar_image->allocation.width;
1273 child_allocation.width -= priv->sidebar_image->allocation.width;
1278 GtkAssistantPage *page = pages->data;
1280 gtk_widget_size_allocate (page->page, &child_allocation);
1281 gtk_widget_size_allocate (page->title, &header_allocation);
1282 pages = pages->next;
1287 gtk_assistant_map (GtkWidget *widget)
1289 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1290 GtkAssistantPrivate *priv = assistant->priv;
1292 GtkAssistantPage *page;
1294 gtk_widget_set_mapped (widget, TRUE);
1296 gtk_widget_map (priv->header_image);
1297 gtk_widget_map (priv->action_area);
1299 if (gtk_widget_get_visible (priv->sidebar_image) &&
1300 !gtk_widget_get_mapped (priv->sidebar_image))
1301 gtk_widget_map (priv->sidebar_image);
1303 /* if there's no default page, pick the first one */
1305 if (!priv->current_page)
1307 page_node = priv->pages;
1309 while (page_node && !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
1310 page_node = page_node->next;
1313 page = page_node->data;
1317 gtk_widget_get_visible (page->page) &&
1318 !gtk_widget_get_mapped (page->page))
1319 set_current_page (assistant, page);
1321 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->map (widget);
1325 gtk_assistant_unmap (GtkWidget *widget)
1327 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1328 GtkAssistantPrivate *priv = assistant->priv;
1330 gtk_widget_set_mapped (widget, FALSE);
1332 gtk_widget_unmap (priv->header_image);
1333 gtk_widget_unmap (priv->action_area);
1335 if (gtk_widget_is_drawable (priv->sidebar_image))
1336 gtk_widget_unmap (priv->sidebar_image);
1338 if (priv->current_page &&
1339 gtk_widget_is_drawable (priv->current_page->page))
1340 gtk_widget_unmap (priv->current_page->page);
1342 g_slist_free (priv->visited_pages);
1343 priv->visited_pages = NULL;
1344 priv->current_page = NULL;
1346 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->unmap (widget);
1350 gtk_assistant_delete_event (GtkWidget *widget,
1353 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1354 GtkAssistantPrivate *priv = assistant->priv;
1356 /* Do not allow cancelling in the middle of a progress page */
1357 if (priv->current_page &&
1358 (priv->current_page->type != GTK_ASSISTANT_PAGE_PROGRESS ||
1359 priv->current_page->complete))
1360 g_signal_emit (widget, signals [CANCEL], 0, NULL);
1366 assistant_paint_colored_box (GtkWidget *widget)
1368 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1369 GtkAssistantPrivate *priv = assistant->priv;
1370 gint border_width, header_padding, content_padding;
1372 gint content_x, content_width;
1375 cr = gdk_cairo_create (widget->window);
1376 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1377 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1379 gtk_widget_style_get (widget,
1380 "header-padding", &header_padding,
1381 "content-padding", &content_padding,
1385 gdk_cairo_set_source_color (cr, &widget->style->bg[GTK_STATE_SELECTED]);
1386 cairo_rectangle (cr,
1389 widget->allocation.width - 2 * border_width,
1390 widget->allocation.height - priv->action_area->allocation.height - 2 * border_width - ACTION_AREA_SPACING);
1394 content_x = content_padding + border_width;
1395 content_width = widget->allocation.width - 2 * content_padding - 2 * border_width;
1397 if (gtk_widget_get_visible (priv->sidebar_image))
1400 content_x += priv->sidebar_image->allocation.width;
1401 content_width -= priv->sidebar_image->allocation.width;
1404 gdk_cairo_set_source_color (cr, &widget->style->bg[GTK_STATE_NORMAL]);
1406 cairo_rectangle (cr,
1408 priv->header_image->allocation.height + content_padding + 2 * header_padding + border_width,
1410 widget->allocation.height - 2 * border_width - priv->action_area->allocation.height -
1411 priv->header_image->allocation.height - 2 * content_padding - 2 * header_padding - ACTION_AREA_SPACING);
1418 gtk_assistant_expose (GtkWidget *widget,
1419 GdkEventExpose *event)
1421 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1422 GtkAssistantPrivate *priv = assistant->priv;
1423 GtkContainer *container;
1425 if (gtk_widget_is_drawable (widget))
1427 container = GTK_CONTAINER (widget);
1429 assistant_paint_colored_box (widget);
1431 gtk_container_propagate_expose (container, priv->header_image, event);
1432 gtk_container_propagate_expose (container, priv->sidebar_image, event);
1433 gtk_container_propagate_expose (container, priv->action_area, event);
1435 if (priv->current_page)
1437 gtk_container_propagate_expose (container, priv->current_page->page, event);
1438 gtk_container_propagate_expose (container, priv->current_page->title, event);
1446 gtk_assistant_focus (GtkWidget *widget,
1447 GtkDirectionType direction)
1449 GtkAssistantPrivate *priv;
1450 GtkContainer *container;
1452 container = GTK_CONTAINER (widget);
1453 priv = GTK_ASSISTANT (widget)->priv;
1455 /* we only have to care about 2 widgets, action area and the current page */
1456 if (gtk_container_get_focus_child (container) == priv->action_area)
1458 if (!gtk_widget_child_focus (priv->action_area, direction) &&
1459 (priv->current_page == NULL ||
1460 !gtk_widget_child_focus (priv->current_page->page, direction)))
1462 /* if we're leaving the action area and the current page hasn't
1463 any focusable widget, clear focus and go back to the action area */
1464 gtk_container_set_focus_child (GTK_CONTAINER (priv->action_area), NULL);
1465 gtk_widget_child_focus (priv->action_area, direction);
1470 if ((priv->current_page == NULL ||
1471 !gtk_widget_child_focus (priv->current_page->page, direction)) &&
1472 !gtk_widget_child_focus (priv->action_area, direction))
1474 /* if we're leaving the current page and there isn't nothing focusable
1475 in the action area, try to clear focus and go back to the page */
1476 gtk_window_set_focus (GTK_WINDOW (widget), NULL);
1477 if (priv->current_page != NULL)
1478 gtk_widget_child_focus (priv->current_page->page, direction);
1486 gtk_assistant_add (GtkContainer *container,
1489 gtk_assistant_append_page (GTK_ASSISTANT (container), page);
1493 gtk_assistant_remove (GtkContainer *container,
1496 GtkAssistant *assistant = (GtkAssistant*) container;
1499 element = find_page (assistant, page);
1503 remove_page (assistant, element);
1504 gtk_widget_queue_resize ((GtkWidget *) container);
1509 gtk_assistant_forall (GtkContainer *container,
1510 gboolean include_internals,
1511 GtkCallback callback,
1512 gpointer callback_data)
1514 GtkAssistant *assistant = (GtkAssistant*) container;
1515 GtkAssistantPrivate *priv = assistant->priv;
1518 if (include_internals)
1520 (*callback) (priv->header_image, callback_data);
1521 (*callback) (priv->sidebar_image, callback_data);
1522 (*callback) (priv->action_area, callback_data);
1525 pages = priv->pages;
1529 GtkAssistantPage *page = (GtkAssistantPage *) pages->data;
1531 (*callback) (page->page, callback_data);
1533 if (include_internals)
1534 (*callback) (page->title, callback_data);
1536 pages = pages->next;
1541 * gtk_assistant_new:
1543 * Creates a new #GtkAssistant.
1545 * Return value: a newly created #GtkAssistant
1550 gtk_assistant_new (void)
1552 GtkWidget *assistant;
1554 assistant = g_object_new (GTK_TYPE_ASSISTANT, NULL);
1560 * gtk_assistant_get_current_page:
1561 * @assistant: a #GtkAssistant
1563 * Returns the page number of the current page
1565 * Return value: The index (starting from 0) of the current page in
1566 * the @assistant, if the @assistant has no pages, -1 will be returned
1571 gtk_assistant_get_current_page (GtkAssistant *assistant)
1573 GtkAssistantPrivate *priv;
1575 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), -1);
1577 priv = assistant->priv;
1579 if (!priv->pages || !priv->current_page)
1582 return g_list_index (priv->pages, priv->current_page);
1586 * gtk_assistant_set_current_page:
1587 * @assistant: a #GtkAssistant
1588 * @page_num: index of the page to switch to, starting from 0.
1589 * If negative, the last page will be used. If greater
1590 * than the number of pages in the @assistant, nothing
1593 * Switches the page to @page_num. Note that this will only be necessary
1594 * in custom buttons, as the @assistant flow can be set with
1595 * gtk_assistant_set_forward_page_func().
1600 gtk_assistant_set_current_page (GtkAssistant *assistant,
1603 GtkAssistantPrivate *priv;
1604 GtkAssistantPage *page;
1606 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1608 priv = assistant->priv;
1611 page = (GtkAssistantPage *) g_list_nth_data (priv->pages, page_num);
1613 page = (GtkAssistantPage *) g_list_last (priv->pages)->data;
1615 g_return_if_fail (page != NULL);
1617 if (priv->current_page == page)
1620 /* only add the page to the visited list if the
1621 * assistant is mapped, if not, just use it as an
1622 * initial page setting, for the cases where the
1623 * initial page is != to 0
1625 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1626 priv->visited_pages = g_slist_prepend (priv->visited_pages,
1627 priv->current_page);
1629 set_current_page (assistant, page);
1633 * gtk_assistant_get_n_pages:
1634 * @assistant: a #GtkAssistant
1636 * Returns the number of pages in the @assistant
1638 * Return value: The number of pages in the @assistant.
1643 gtk_assistant_get_n_pages (GtkAssistant *assistant)
1645 GtkAssistantPrivate *priv;
1647 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1649 priv = assistant->priv;
1651 return g_list_length (priv->pages);
1655 * gtk_assistant_get_nth_page:
1656 * @assistant: a #GtkAssistant
1657 * @page_num: The index of a page in the @assistant, or -1 to get the last page;
1659 * Returns the child widget contained in page number @page_num.
1661 * Return value: The child widget, or %NULL if @page_num is out of bounds.
1666 gtk_assistant_get_nth_page (GtkAssistant *assistant,
1669 GtkAssistantPrivate *priv;
1670 GtkAssistantPage *page;
1673 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1674 g_return_val_if_fail (page_num >= -1, NULL);
1676 priv = assistant->priv;
1679 elem = g_list_last (priv->pages);
1681 elem = g_list_nth (priv->pages, page_num);
1686 page = (GtkAssistantPage *) elem->data;
1692 * gtk_assistant_prepend_page:
1693 * @assistant: a #GtkAssistant
1694 * @page: a #GtkWidget
1696 * Prepends a page to the @assistant.
1698 * Return value: the index (starting at 0) of the inserted page
1703 gtk_assistant_prepend_page (GtkAssistant *assistant,
1706 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1707 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1709 return gtk_assistant_insert_page (assistant, page, 0);
1713 * gtk_assistant_append_page:
1714 * @assistant: a #GtkAssistant
1715 * @page: a #GtkWidget
1717 * Appends a page to the @assistant.
1719 * Return value: the index (starting at 0) of the inserted page
1724 gtk_assistant_append_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, -1);
1734 * gtk_assistant_insert_page:
1735 * @assistant: a #GtkAssistant
1736 * @page: a #GtkWidget
1737 * @position: the index (starting at 0) at which to insert the page,
1738 * or -1 to append the page to the @assistant
1740 * Inserts a page in the @assistant at a given position.
1742 * Return value: the index (starting from 0) of the inserted page
1747 gtk_assistant_insert_page (GtkAssistant *assistant,
1751 GtkAssistantPrivate *priv;
1752 GtkAssistantPage *page_info;
1755 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1756 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1757 g_return_val_if_fail (page->parent == NULL, 0);
1758 g_return_val_if_fail (!gtk_widget_is_toplevel (page), 0);
1760 priv = assistant->priv;
1762 page_info = g_slice_new0 (GtkAssistantPage);
1763 page_info->page = page;
1764 page_info->title = gtk_label_new (NULL);
1766 g_signal_connect (G_OBJECT (page), "notify::visible",
1767 G_CALLBACK (on_page_notify_visibility), assistant);
1769 gtk_misc_set_alignment (GTK_MISC (page_info->title), 0.,0.5);
1770 set_title_colors (GTK_WIDGET (assistant), page_info->title);
1771 set_title_font (GTK_WIDGET (assistant), page_info->title);
1772 gtk_widget_show (page_info->title);
1774 n_pages = g_list_length (priv->pages);
1776 if (position < 0 || position > n_pages)
1779 priv->pages = g_list_insert (priv->pages, page_info, position);
1781 gtk_widget_set_child_visible (page_info->page, FALSE);
1782 gtk_widget_set_parent (page_info->page, GTK_WIDGET (assistant));
1783 gtk_widget_set_parent (page_info->title, GTK_WIDGET (assistant));
1785 if (gtk_widget_get_realized (GTK_WIDGET (assistant)))
1787 gtk_widget_realize (page_info->page);
1788 gtk_widget_realize (page_info->title);
1791 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1797 * gtk_assistant_set_forward_page_func:
1798 * @assistant: a #GtkAssistant
1799 * @page_func: (allow-none): the #GtkAssistantPageFunc, or %NULL to use the default one
1800 * @data: user data for @page_func
1801 * @destroy: destroy notifier for @data
1803 * Sets the page forwarding function to be @page_func, this function will
1804 * be used to determine what will be the next page when the user presses
1805 * the forward button. Setting @page_func to %NULL will make the assistant
1806 * to use the default forward function, which just goes to the next visible
1812 gtk_assistant_set_forward_page_func (GtkAssistant *assistant,
1813 GtkAssistantPageFunc page_func,
1815 GDestroyNotify destroy)
1817 GtkAssistantPrivate *priv;
1819 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1821 priv = assistant->priv;
1823 if (priv->forward_data_destroy &&
1824 priv->forward_function_data)
1825 (*priv->forward_data_destroy) (priv->forward_function_data);
1829 priv->forward_function = page_func;
1830 priv->forward_function_data = data;
1831 priv->forward_data_destroy = destroy;
1835 priv->forward_function = default_forward_function;
1836 priv->forward_function_data = assistant;
1837 priv->forward_data_destroy = NULL;
1840 /* Page flow has possibly changed, so the
1841 buttons state might need to change too */
1842 set_assistant_buttons_state (assistant);
1846 * gtk_assistant_add_action_widget:
1847 * @assistant: a #GtkAssistant
1848 * @child: a #GtkWidget
1850 * Adds a widget to the action area of a #GtkAssistant.
1855 gtk_assistant_add_action_widget (GtkAssistant *assistant,
1858 GtkAssistantPrivate *priv;
1860 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1861 g_return_if_fail (GTK_IS_WIDGET (child));
1863 priv = assistant->priv;
1865 if (GTK_IS_BUTTON (child))
1866 gtk_size_group_add_widget (priv->size_group, child);
1868 gtk_box_pack_end (GTK_BOX (priv->action_area), child, FALSE, FALSE, 0);
1872 * gtk_assistant_remove_action_widget:
1873 * @assistant: a #GtkAssistant
1874 * @child: a #GtkWidget
1876 * Removes a widget from the action area of a #GtkAssistant.
1881 gtk_assistant_remove_action_widget (GtkAssistant *assistant,
1884 GtkAssistantPrivate *priv;
1886 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1887 g_return_if_fail (GTK_IS_WIDGET (child));
1889 priv = assistant->priv;
1891 if (GTK_IS_BUTTON (child))
1892 gtk_size_group_remove_widget (priv->size_group, child);
1894 gtk_container_remove (GTK_CONTAINER (priv->action_area), child);
1898 * gtk_assistant_set_page_title:
1899 * @assistant: a #GtkAssistant
1900 * @page: a page of @assistant
1901 * @title: the new title for @page
1903 * Sets a title for @page. The title is displayed in the header
1904 * area of the assistant when @page is the current page.
1909 gtk_assistant_set_page_title (GtkAssistant *assistant,
1913 GtkAssistantPage *page_info;
1916 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1917 g_return_if_fail (GTK_IS_WIDGET (page));
1919 child = find_page (assistant, page);
1921 g_return_if_fail (child != NULL);
1923 page_info = (GtkAssistantPage*) child->data;
1925 gtk_label_set_text ((GtkLabel*) page_info->title, title);
1926 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1927 gtk_widget_child_notify (page, "title");
1931 * gtk_assistant_get_page_title:
1932 * @assistant: a #GtkAssistant
1933 * @page: a page of @assistant
1935 * Gets the title for @page.
1937 * Return value: the title for @page.
1941 G_CONST_RETURN gchar*
1942 gtk_assistant_get_page_title (GtkAssistant *assistant,
1945 GtkAssistantPage *page_info;
1948 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1949 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1951 child = find_page (assistant, page);
1953 g_return_val_if_fail (child != NULL, NULL);
1955 page_info = (GtkAssistantPage*) child->data;
1957 return gtk_label_get_text ((GtkLabel*) page_info->title);
1961 * gtk_assistant_set_page_type:
1962 * @assistant: a #GtkAssistant
1963 * @page: a page of @assistant
1964 * @type: the new type for @page
1966 * Sets the page type for @page. The page type determines the page
1967 * behavior in the @assistant.
1972 gtk_assistant_set_page_type (GtkAssistant *assistant,
1974 GtkAssistantPageType type)
1976 GtkAssistantPrivate *priv;
1977 GtkAssistantPage *page_info;
1980 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1981 g_return_if_fail (GTK_IS_WIDGET (page));
1983 priv = assistant->priv;
1984 child = find_page (assistant, page);
1986 g_return_if_fail (child != NULL);
1988 page_info = (GtkAssistantPage*) child->data;
1990 if (type != page_info->type)
1992 page_info->type = type;
1994 /* backwards compatibility to the era before fixing bug 604289 */
1995 if (type == GTK_ASSISTANT_PAGE_SUMMARY && !page_info->complete_set)
1997 gtk_assistant_set_page_complete (assistant, page, TRUE);
1998 page_info->complete_set = FALSE;
2001 /* Always set buttons state, a change in a future page
2002 might change current page buttons */
2003 set_assistant_buttons_state (assistant);
2005 gtk_widget_child_notify (page, "page-type");
2010 * gtk_assistant_get_page_type:
2011 * @assistant: a #GtkAssistant
2012 * @page: a page of @assistant
2014 * Gets the page type of @page.
2016 * Return value: the page type of @page.
2020 GtkAssistantPageType
2021 gtk_assistant_get_page_type (GtkAssistant *assistant,
2024 GtkAssistantPage *page_info;
2027 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), GTK_ASSISTANT_PAGE_CONTENT);
2028 g_return_val_if_fail (GTK_IS_WIDGET (page), GTK_ASSISTANT_PAGE_CONTENT);
2030 child = find_page (assistant, page);
2032 g_return_val_if_fail (child != NULL, GTK_ASSISTANT_PAGE_CONTENT);
2034 page_info = (GtkAssistantPage*) child->data;
2036 return page_info->type;
2040 * gtk_assistant_set_page_header_image:
2041 * @assistant: a #GtkAssistant
2042 * @page: a page of @assistant
2043 * @pixbuf: (allow-none): the new header image @page
2045 * Sets a header image for @page. This image is displayed in the header
2046 * area of the assistant when @page is the current page.
2051 gtk_assistant_set_page_header_image (GtkAssistant *assistant,
2055 GtkAssistantPrivate *priv;
2056 GtkAssistantPage *page_info;
2059 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2060 g_return_if_fail (GTK_IS_WIDGET (page));
2061 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2063 priv = assistant->priv;
2064 child = find_page (assistant, page);
2066 g_return_if_fail (child != NULL);
2068 page_info = (GtkAssistantPage*) child->data;
2070 if (pixbuf != page_info->header_image)
2072 if (page_info->header_image)
2074 g_object_unref (page_info->header_image);
2075 page_info->header_image = NULL;
2079 page_info->header_image = g_object_ref (pixbuf);
2081 if (page_info == priv->current_page)
2082 set_assistant_header_image (assistant);
2084 gtk_widget_child_notify (page, "header-image");
2089 * gtk_assistant_get_page_header_image:
2090 * @assistant: a #GtkAssistant
2091 * @page: a page of @assistant
2093 * Gets the header image for @page.
2095 * Return value: the header image for @page, or %NULL
2096 * if there's no header image for the page.
2101 gtk_assistant_get_page_header_image (GtkAssistant *assistant,
2104 GtkAssistantPage *page_info;
2107 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2108 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2110 child = find_page (assistant, page);
2112 g_return_val_if_fail (child != NULL, NULL);
2114 page_info = (GtkAssistantPage*) child->data;
2116 return page_info->header_image;
2120 * gtk_assistant_set_page_side_image:
2121 * @assistant: a #GtkAssistant
2122 * @page: a page of @assistant
2123 * @pixbuf: (allow-none): the new header image @page
2125 * Sets a header image for @page. This image is displayed in the side
2126 * area of the assistant when @page is the current page.
2131 gtk_assistant_set_page_side_image (GtkAssistant *assistant,
2135 GtkAssistantPrivate *priv;
2136 GtkAssistantPage *page_info;
2139 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2140 g_return_if_fail (GTK_IS_WIDGET (page));
2141 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2143 priv = assistant->priv;
2144 child = find_page (assistant, page);
2146 g_return_if_fail (child != NULL);
2148 page_info = (GtkAssistantPage*) child->data;
2150 if (pixbuf != page_info->sidebar_image)
2152 if (page_info->sidebar_image)
2154 g_object_unref (page_info->sidebar_image);
2155 page_info->sidebar_image = NULL;
2159 page_info->sidebar_image = g_object_ref (pixbuf);
2161 if (page_info == priv->current_page)
2162 set_assistant_sidebar_image (assistant);
2164 gtk_widget_child_notify (page, "sidebar-image");
2169 * gtk_assistant_get_page_side_image:
2170 * @assistant: a #GtkAssistant
2171 * @page: a page of @assistant
2173 * Gets the header image for @page.
2175 * Return value: the side image for @page, or %NULL
2176 * if there's no side image for the page.
2181 gtk_assistant_get_page_side_image (GtkAssistant *assistant,
2184 GtkAssistantPage *page_info;
2187 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2188 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2190 child = find_page (assistant, page);
2192 g_return_val_if_fail (child != NULL, NULL);
2194 page_info = (GtkAssistantPage*) child->data;
2196 return page_info->sidebar_image;
2200 * gtk_assistant_set_page_complete:
2201 * @assistant: a #GtkAssistant
2202 * @page: a page of @assistant
2203 * @complete: the completeness status of the page
2205 * Sets whether @page contents are complete. This will make
2206 * @assistant update the buttons state to be able to continue the task.
2211 gtk_assistant_set_page_complete (GtkAssistant *assistant,
2215 GtkAssistantPrivate *priv;
2216 GtkAssistantPage *page_info;
2219 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2220 g_return_if_fail (GTK_IS_WIDGET (page));
2222 priv = assistant->priv;
2223 child = find_page (assistant, page);
2225 g_return_if_fail (child != NULL);
2227 page_info = (GtkAssistantPage*) child->data;
2229 if (complete != page_info->complete)
2231 page_info->complete = complete;
2232 page_info->complete_set = TRUE;
2234 /* Always set buttons state, a change in a future page
2235 might change current page buttons */
2236 set_assistant_buttons_state (assistant);
2238 gtk_widget_child_notify (page, "complete");
2243 * gtk_assistant_get_page_complete:
2244 * @assistant: a #GtkAssistant
2245 * @page: a page of @assistant
2247 * Gets whether @page is complete.
2249 * Return value: %TRUE if @page is complete.
2254 gtk_assistant_get_page_complete (GtkAssistant *assistant,
2257 GtkAssistantPage *page_info;
2260 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), FALSE);
2261 g_return_val_if_fail (GTK_IS_WIDGET (page), FALSE);
2263 child = find_page (assistant, page);
2265 g_return_val_if_fail (child != NULL, FALSE);
2267 page_info = (GtkAssistantPage*) child->data;
2269 return page_info->complete;
2273 * gtk_assistant_update_buttons_state:
2274 * @assistant: a #GtkAssistant
2276 * Forces @assistant to recompute the buttons state.
2278 * GTK+ automatically takes care of this in most situations,
2279 * e.g. when the user goes to a different page, or when the
2280 * visibility or completeness of a page changes.
2282 * One situation where it can be necessary to call this
2283 * function is when changing a value on the current page
2284 * affects the future page flow of the assistant.
2289 gtk_assistant_update_buttons_state (GtkAssistant *assistant)
2291 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2293 set_assistant_buttons_state (assistant);
2297 * gtk_assistant_commit:
2298 * @assistant: a #GtkAssistant
2300 * Erases the visited page history so the back button is not
2301 * shown on the current page, and removes the cancel button
2302 * from subsequent pages.
2304 * Use this when the information provided up to the current
2305 * page is hereafter deemed permanent and cannot be modified
2306 * or undone. For example, showing a progress page to track
2307 * a long-running, unreversible operation after the user has
2308 * clicked apply on a confirmation page.
2313 gtk_assistant_commit (GtkAssistant *assistant)
2315 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2317 g_slist_free (assistant->priv->visited_pages);
2318 assistant->priv->visited_pages = NULL;
2320 assistant->priv->committed = TRUE;
2322 set_assistant_buttons_state (assistant);
2327 /* accessible implementation */
2330 gtk_assistant_accessible_get_n_children (AtkObject *accessible)
2332 GtkAssistant *assistant;
2335 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2340 assistant = GTK_ASSISTANT (widget);
2342 return g_list_length (assistant->priv->pages) + 1;
2347 gtk_assistant_accessible_ref_child (AtkObject *accessible,
2350 GtkAssistant *assistant;
2351 GtkAssistantPrivate *priv;
2352 GtkWidget *widget, *child;
2357 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2361 assistant = GTK_ASSISTANT (widget);
2362 priv = assistant->priv;
2363 n_pages = g_list_length (priv->pages);
2367 else if (index < n_pages)
2369 GtkAssistantPage *page = g_list_nth_data (priv->pages, index);
2372 title = gtk_assistant_get_page_title (assistant, child);
2374 else if (index == n_pages)
2376 child = priv->action_area;
2382 obj = gtk_widget_get_accessible (child);
2385 atk_object_set_name (obj, title);
2387 return g_object_ref (obj);
2391 gtk_assistant_accessible_class_init (AtkObjectClass *class)
2393 class->get_n_children = gtk_assistant_accessible_get_n_children;
2394 class->ref_child = gtk_assistant_accessible_ref_child;
2398 gtk_assistant_accessible_get_type (void)
2400 static GType type = 0;
2405 * Figure out the size of the class and instance
2406 * we are deriving from
2408 AtkObjectFactory *factory;
2411 GType derived_atk_type;
2413 derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
2414 factory = atk_registry_get_factory (atk_get_default_registry (),
2416 derived_atk_type = atk_object_factory_get_accessible_type (factory);
2417 g_type_query (derived_atk_type, &query);
2419 type = g_type_register_static_simple (derived_atk_type,
2420 I_("GtkAssistantAccessible"),
2422 (GClassInitFunc) gtk_assistant_accessible_class_init,
2423 query.instance_size,
2431 gtk_assistant_accessible_new (GObject *obj)
2433 AtkObject *accessible;
2435 g_return_val_if_fail (GTK_IS_ASSISTANT (obj), NULL);
2437 accessible = g_object_new (gtk_assistant_accessible_get_type (), NULL);
2438 atk_object_initialize (accessible, obj);
2444 gtk_assistant_accessible_factory_get_accessible_type (void)
2446 return gtk_assistant_accessible_get_type ();
2450 gtk_assistant_accessible_factory_create_accessible (GObject *obj)
2452 return gtk_assistant_accessible_new (obj);
2456 gtk_assistant_accessible_factory_class_init (AtkObjectFactoryClass *class)
2458 class->create_accessible = gtk_assistant_accessible_factory_create_accessible;
2459 class->get_accessible_type = gtk_assistant_accessible_factory_get_accessible_type;
2463 gtk_assistant_accessible_factory_get_type (void)
2465 static GType type = 0;
2469 type = g_type_register_static_simple (ATK_TYPE_OBJECT_FACTORY,
2470 I_("GtkAssistantAccessibleFactory"),
2471 sizeof (AtkObjectFactoryClass),
2472 (GClassInitFunc) gtk_assistant_accessible_factory_class_init,
2473 sizeof (AtkObjectFactory),
2481 gtk_assistant_get_accessible (GtkWidget *widget)
2483 static gboolean first_time = TRUE;
2487 AtkObjectFactory *factory;
2488 AtkRegistry *registry;
2490 GType derived_atk_type;
2493 * Figure out whether accessibility is enabled by looking at the
2494 * type of the accessible object which would be created for
2495 * the parent type of GtkAssistant.
2497 derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
2499 registry = atk_get_default_registry ();
2500 factory = atk_registry_get_factory (registry,
2502 derived_atk_type = atk_object_factory_get_accessible_type (factory);
2503 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
2505 atk_registry_set_factory_type (registry,
2507 gtk_assistant_accessible_factory_get_type ());
2512 return GTK_WIDGET_CLASS (gtk_assistant_parent_class)->get_accessible (widget);
2516 static GtkBuildableIface *parent_buildable_iface;
2519 gtk_assistant_buildable_interface_init (GtkBuildableIface *iface)
2521 parent_buildable_iface = g_type_interface_peek_parent (iface);
2522 iface->get_internal_child = gtk_assistant_buildable_get_internal_child;
2523 iface->custom_tag_start = gtk_assistant_buildable_custom_tag_start;
2524 iface->custom_finished = gtk_assistant_buildable_custom_finished;
2528 gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
2529 GtkBuilder *builder,
2530 const gchar *childname)
2532 if (strcmp (childname, "action_area") == 0)
2533 return G_OBJECT (GTK_ASSISTANT (buildable)->priv->action_area);
2535 return parent_buildable_iface->get_internal_child (buildable,
2541 gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
2542 GtkBuilder *builder,
2544 const gchar *tagname,
2545 GMarkupParser *parser,
2548 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
2549 tagname, parser, data);
2553 gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
2554 GtkBuilder *builder,
2556 const gchar *tagname,
2559 parent_buildable_iface->custom_finished (buildable, builder, child,
2560 tagname, user_data);