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"
67 #define GTK_ASSISTANT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_ASSISTANT, GtkAssistantPrivate))
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
88 GtkWidget *header_image;
89 GtkWidget *sidebar_image;
91 GtkWidget *action_area;
95 GtkAssistantPage *current_page;
97 GSList *visited_pages;
99 GtkSizeGroup *size_group;
101 GtkAssistantPageFunc forward_function;
102 gpointer forward_function_data;
103 GDestroyNotify forward_data_destroy;
108 static void gtk_assistant_class_init (GtkAssistantClass *class);
109 static void gtk_assistant_init (GtkAssistant *assistant);
110 static void gtk_assistant_destroy (GtkObject *object);
111 static void gtk_assistant_style_set (GtkWidget *widget,
112 GtkStyle *old_style);
113 static void gtk_assistant_size_request (GtkWidget *widget,
114 GtkRequisition *requisition);
115 static void gtk_assistant_size_allocate (GtkWidget *widget,
116 GtkAllocation *allocation);
117 static void gtk_assistant_map (GtkWidget *widget);
118 static void gtk_assistant_unmap (GtkWidget *widget);
119 static gboolean gtk_assistant_delete_event (GtkWidget *widget,
121 static gboolean gtk_assistant_expose (GtkWidget *widget,
122 GdkEventExpose *event);
123 static gboolean gtk_assistant_focus (GtkWidget *widget,
124 GtkDirectionType direction);
125 static void gtk_assistant_add (GtkContainer *container,
127 static void gtk_assistant_remove (GtkContainer *container,
129 static void gtk_assistant_forall (GtkContainer *container,
130 gboolean include_internals,
131 GtkCallback callback,
132 gpointer callback_data);
133 static void gtk_assistant_set_child_property (GtkContainer *container,
138 static void gtk_assistant_get_child_property (GtkContainer *container,
144 static AtkObject *gtk_assistant_get_accessible (GtkWidget *widget);
146 static void gtk_assistant_buildable_interface_init (GtkBuildableIface *iface);
147 static GObject *gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
149 const gchar *childname);
150 static gboolean gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
153 const gchar *tagname,
154 GMarkupParser *parser,
156 static void gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
159 const gchar *tagname,
162 static GList* find_page (GtkAssistant *assistant,
168 CHILD_PROP_PAGE_TYPE,
169 CHILD_PROP_PAGE_TITLE,
170 CHILD_PROP_PAGE_HEADER_IMAGE,
171 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
172 CHILD_PROP_PAGE_COMPLETE
184 static guint signals [LAST_SIGNAL] = { 0 };
187 G_DEFINE_TYPE_WITH_CODE (GtkAssistant, gtk_assistant, GTK_TYPE_WINDOW,
188 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
189 gtk_assistant_buildable_interface_init))
193 gtk_assistant_class_init (GtkAssistantClass *class)
195 GObjectClass *gobject_class;
196 GtkObjectClass *object_class;
197 GtkWidgetClass *widget_class;
198 GtkContainerClass *container_class;
200 gobject_class = (GObjectClass *) class;
201 object_class = (GtkObjectClass *) class;
202 widget_class = (GtkWidgetClass *) class;
203 container_class = (GtkContainerClass *) class;
205 object_class->destroy = gtk_assistant_destroy;
207 widget_class->style_set = gtk_assistant_style_set;
208 widget_class->size_request = gtk_assistant_size_request;
209 widget_class->size_allocate = gtk_assistant_size_allocate;
210 widget_class->map = gtk_assistant_map;
211 widget_class->unmap = gtk_assistant_unmap;
212 widget_class->delete_event = gtk_assistant_delete_event;
213 widget_class->expose_event = gtk_assistant_expose;
214 widget_class->focus = gtk_assistant_focus;
215 widget_class->get_accessible = gtk_assistant_get_accessible;
217 container_class->add = gtk_assistant_add;
218 container_class->remove = gtk_assistant_remove;
219 container_class->forall = gtk_assistant_forall;
220 container_class->set_child_property = gtk_assistant_set_child_property;
221 container_class->get_child_property = gtk_assistant_get_child_property;
224 * GtkAssistant::cancel:
225 * @assistant: the #GtkAssistant
227 * The ::cancel signal is emitted when then the cancel button is clicked.
232 g_signal_new (I_("cancel"),
233 G_TYPE_FROM_CLASS (gobject_class),
235 G_STRUCT_OFFSET (GtkAssistantClass, cancel),
237 g_cclosure_marshal_VOID__VOID,
241 * GtkAssistant::prepare:
242 * @assistant: the #GtkAssistant
243 * @page: the current page
245 * The ::prepare signal is emitted when a new page is set as the assistant's
246 * current page, before making the new page visible. A handler for this signal
247 * can do any preparation which are necessary before showing @page.
252 g_signal_new (I_("prepare"),
253 G_TYPE_FROM_CLASS (gobject_class),
255 G_STRUCT_OFFSET (GtkAssistantClass, prepare),
257 g_cclosure_marshal_VOID__OBJECT,
258 G_TYPE_NONE, 1, GTK_TYPE_WIDGET);
261 * GtkAssistant::apply:
262 * @assistant: the #GtkAssistant
264 * The ::apply signal is emitted when the apply button is clicked. The default
265 * behavior of the #GtkAssistant is to switch to the page after the current
266 * page, unless the current page is the last one.
268 * A handler for the ::apply signal should carry out the actions for which
269 * the wizard has collected data. If the action takes a long time to complete,
270 * you might consider putting a page of type %GTK_ASSISTANT_PAGE_PROGRESS
271 * after the confirmation page and handle this operation within the
272 * #GtkAssistant::prepare signal of the progress page.
277 g_signal_new (I_("apply"),
278 G_TYPE_FROM_CLASS (gobject_class),
280 G_STRUCT_OFFSET (GtkAssistantClass, apply),
282 g_cclosure_marshal_VOID__VOID,
286 * GtkAssistant::close:
287 * @assistant: the #GtkAssistant
289 * The ::close signal is emitted either when the close button of
290 * a summary page is clicked, or when the apply button in the last
291 * page in the flow (of type %GTK_ASSISTANT_PAGE_CONFIRM) is clicked.
296 g_signal_new (I_("close"),
297 G_TYPE_FROM_CLASS (gobject_class),
299 G_STRUCT_OFFSET (GtkAssistantClass, close),
301 g_cclosure_marshal_VOID__VOID,
304 gtk_widget_class_install_style_property (widget_class,
305 g_param_spec_int ("header-padding",
306 P_("Header Padding"),
307 P_("Number of pixels around the header."),
311 GTK_PARAM_READABLE));
312 gtk_widget_class_install_style_property (widget_class,
313 g_param_spec_int ("content-padding",
314 P_("Content Padding"),
315 P_("Number of pixels around the content pages."),
319 GTK_PARAM_READABLE));
322 * GtkAssistant:page-type:
324 * The type of the assistant page.
328 gtk_container_class_install_child_property (container_class,
329 CHILD_PROP_PAGE_TYPE,
330 g_param_spec_enum ("page-type",
332 P_("The type of the assistant page"),
333 GTK_TYPE_ASSISTANT_PAGE_TYPE,
334 GTK_ASSISTANT_PAGE_CONTENT,
335 GTK_PARAM_READWRITE));
338 * GtkAssistant:title:
340 * The title that is displayed in the page header.
342 * If title and header-image are both %NULL, no header is displayed.
346 gtk_container_class_install_child_property (container_class,
347 CHILD_PROP_PAGE_TITLE,
348 g_param_spec_string ("title",
350 P_("The title of the assistant page"),
352 GTK_PARAM_READWRITE));
355 * GtkAssistant:header-image:
357 * The image that is displayed next to the title in the page header.
359 * If title and header-image are both %NULL, no header is displayed.
363 gtk_container_class_install_child_property (container_class,
364 CHILD_PROP_PAGE_HEADER_IMAGE,
365 g_param_spec_object ("header-image",
367 P_("Header image for the assistant page"),
369 GTK_PARAM_READWRITE));
372 * GtkAssistant:header-image:
374 * The image that is displayed next to the page.
376 * Set this to %NULL to make the sidebar disappear.
380 gtk_container_class_install_child_property (container_class,
381 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
382 g_param_spec_object ("sidebar-image",
384 P_("Sidebar image for the assistant page"),
386 GTK_PARAM_READWRITE));
388 * GtkAssistant:complete:
390 * Setting the "complete" child property to %TRUE marks a page as complete
391 * (i.e.: all the required fields are filled out). GTK+ uses this information
392 * to control the sensitivity of the navigation buttons.
396 gtk_container_class_install_child_property (container_class,
397 CHILD_PROP_PAGE_COMPLETE,
398 g_param_spec_boolean ("complete",
400 P_("Whether all required fields on the page have been filled out"),
404 g_type_class_add_private (gobject_class, sizeof (GtkAssistantPrivate));
408 default_forward_function (gint current_page, gpointer data)
410 GtkAssistant *assistant;
411 GtkAssistantPrivate *priv;
412 GtkAssistantPage *page_info;
415 assistant = GTK_ASSISTANT (data);
416 priv = assistant->priv;
418 page_node = g_list_nth (priv->pages, ++current_page);
423 page_info = (GtkAssistantPage *) page_node->data;
425 while (page_node && !gtk_widget_get_visible (page_info->page))
427 page_node = page_node->next;
431 page_info = (GtkAssistantPage *) page_node->data;
438 compute_last_button_state (GtkAssistant *assistant)
440 GtkAssistantPrivate *priv = assistant->priv;
441 GtkAssistantPage *page_info, *current_page_info;
442 gint count, page_num, n_pages;
445 page_num = gtk_assistant_get_current_page (assistant);
446 n_pages = gtk_assistant_get_n_pages (assistant);
447 current_page_info = page_info = g_list_nth_data (priv->pages, page_num);
449 while (page_num >= 0 && page_num < n_pages &&
450 page_info->type == GTK_ASSISTANT_PAGE_CONTENT &&
451 (count == 0 || page_info->complete) &&
454 page_num = (priv->forward_function) (page_num, priv->forward_function_data);
455 page_info = g_list_nth_data (priv->pages, page_num);
460 /* make the last button visible if we can skip multiple
461 * pages and end on a confirmation or summary page
463 if (count > 1 && page_info &&
464 (page_info->type == GTK_ASSISTANT_PAGE_CONFIRM ||
465 page_info->type == GTK_ASSISTANT_PAGE_SUMMARY))
467 gtk_widget_show (assistant->last);
468 gtk_widget_set_sensitive (assistant->last,
469 current_page_info->complete);
472 gtk_widget_hide (assistant->last);
476 compute_progress_state (GtkAssistant *assistant)
478 GtkAssistantPrivate *priv = assistant->priv;
479 gint page_num, n_pages;
481 n_pages = gtk_assistant_get_n_pages (assistant);
482 page_num = gtk_assistant_get_current_page (assistant);
484 page_num = (priv->forward_function) (page_num, priv->forward_function_data);
486 if (page_num >= 0 && page_num < n_pages)
487 gtk_widget_show (assistant->forward);
489 gtk_widget_hide (assistant->forward);
493 set_assistant_header_image (GtkAssistant *assistant)
495 GtkAssistantPrivate *priv = assistant->priv;
497 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->header_image),
498 priv->current_page->header_image);
502 set_assistant_sidebar_image (GtkAssistant *assistant)
504 GtkAssistantPrivate *priv = assistant->priv;
506 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->sidebar_image),
507 priv->current_page->sidebar_image);
509 if (priv->current_page->sidebar_image)
510 gtk_widget_show (priv->sidebar_image);
512 gtk_widget_hide (priv->sidebar_image);
516 set_assistant_buttons_state (GtkAssistant *assistant)
518 GtkAssistantPrivate *priv = assistant->priv;
520 if (!priv->current_page)
523 switch (priv->current_page->type)
525 case GTK_ASSISTANT_PAGE_INTRO:
526 gtk_widget_set_sensitive (assistant->cancel, TRUE);
527 gtk_widget_set_sensitive (assistant->forward, priv->current_page->complete);
528 gtk_widget_grab_default (assistant->forward);
529 gtk_widget_show (assistant->forward);
530 gtk_widget_hide (assistant->back);
531 gtk_widget_hide (assistant->apply);
532 gtk_widget_hide (assistant->close);
533 compute_last_button_state (assistant);
535 case GTK_ASSISTANT_PAGE_CONFIRM:
536 gtk_widget_set_sensitive (assistant->cancel, TRUE);
537 gtk_widget_set_sensitive (assistant->back, TRUE);
538 gtk_widget_set_sensitive (assistant->apply, priv->current_page->complete);
539 gtk_widget_grab_default (assistant->apply);
540 gtk_widget_show (assistant->back);
541 gtk_widget_show (assistant->apply);
542 gtk_widget_hide (assistant->forward);
543 gtk_widget_hide (assistant->close);
544 gtk_widget_hide (assistant->last);
546 case GTK_ASSISTANT_PAGE_CONTENT:
547 gtk_widget_set_sensitive (assistant->cancel, TRUE);
548 gtk_widget_set_sensitive (assistant->back, TRUE);
549 gtk_widget_set_sensitive (assistant->forward, priv->current_page->complete);
550 gtk_widget_grab_default (assistant->forward);
551 gtk_widget_show (assistant->back);
552 gtk_widget_show (assistant->forward);
553 gtk_widget_hide (assistant->apply);
554 gtk_widget_hide (assistant->close);
555 compute_last_button_state (assistant);
557 case GTK_ASSISTANT_PAGE_SUMMARY:
558 gtk_widget_set_sensitive (assistant->close, priv->current_page->complete);
559 gtk_widget_grab_default (assistant->close);
560 gtk_widget_show (assistant->close);
561 gtk_widget_hide (assistant->back);
562 gtk_widget_hide (assistant->forward);
563 gtk_widget_hide (assistant->apply);
564 gtk_widget_hide (assistant->last);
566 case GTK_ASSISTANT_PAGE_PROGRESS:
567 gtk_widget_set_sensitive (assistant->cancel, priv->current_page->complete);
568 gtk_widget_set_sensitive (assistant->back, priv->current_page->complete);
569 gtk_widget_set_sensitive (assistant->forward, priv->current_page->complete);
570 gtk_widget_grab_default (assistant->forward);
571 gtk_widget_show (assistant->back);
572 gtk_widget_hide (assistant->apply);
573 gtk_widget_hide (assistant->close);
574 gtk_widget_hide (assistant->last);
575 compute_progress_state (assistant);
578 g_assert_not_reached ();
582 gtk_widget_hide (assistant->cancel);
583 else if (priv->current_page->type == GTK_ASSISTANT_PAGE_SUMMARY)
584 gtk_widget_hide (assistant->cancel);
586 gtk_widget_show (assistant->cancel);
588 /* this is quite general, we don't want to
589 * go back if it's the first page */
590 if (!priv->visited_pages)
591 gtk_widget_hide (assistant->back);
595 set_current_page (GtkAssistant *assistant,
596 GtkAssistantPage *page)
598 GtkAssistantPrivate *priv = assistant->priv;
599 GtkAssistantPage *old_page;
601 if (priv->current_page &&
602 gtk_widget_is_drawable (priv->current_page->page))
603 old_page = priv->current_page;
607 priv->current_page = page;
609 set_assistant_buttons_state (assistant);
610 set_assistant_header_image (assistant);
611 set_assistant_sidebar_image (assistant);
613 g_signal_emit (assistant, signals [PREPARE], 0, priv->current_page->page);
615 if (gtk_widget_get_visible (priv->current_page->page) && gtk_widget_get_mapped (GTK_WIDGET (assistant)))
617 gtk_widget_set_child_visible (priv->current_page->page, TRUE);
618 gtk_widget_map (priv->current_page->page);
619 gtk_widget_map (priv->current_page->title);
622 if (old_page && gtk_widget_get_mapped (old_page->page))
624 gtk_widget_set_child_visible (old_page->page, FALSE);
625 gtk_widget_unmap (old_page->page);
626 gtk_widget_unmap (old_page->title);
629 if (!gtk_widget_child_focus (priv->current_page->page, GTK_DIR_TAB_FORWARD))
631 GtkWidget *button[6];
634 /* find the best button to focus */
635 button[0] = assistant->apply;
636 button[1] = assistant->close;
637 button[2] = assistant->forward;
638 button[3] = assistant->back;
639 button[4] = assistant->cancel;
640 button[5] = assistant->last;
641 for (i = 0; i < 6; i++)
643 if (gtk_widget_get_visible (button[i]) && gtk_widget_get_sensitive (button[i]))
645 gtk_widget_grab_focus (button[i]);
651 gtk_widget_queue_resize (GTK_WIDGET (assistant));
655 compute_next_step (GtkAssistant *assistant)
657 GtkAssistantPrivate *priv = assistant->priv;
658 GtkAssistantPage *page_info;
659 gint current_page, n_pages, next_page;
661 current_page = gtk_assistant_get_current_page (assistant);
662 page_info = priv->current_page;
663 n_pages = gtk_assistant_get_n_pages (assistant);
665 next_page = (priv->forward_function) (current_page,
666 priv->forward_function_data);
668 if (next_page >= 0 && next_page < n_pages)
670 priv->visited_pages = g_slist_prepend (priv->visited_pages, page_info);
671 set_current_page (assistant, g_list_nth_data (priv->pages, next_page));
680 on_assistant_close (GtkWidget *widget,
681 GtkAssistant *assistant)
683 g_signal_emit (assistant, signals [CLOSE], 0, NULL);
687 on_assistant_apply (GtkWidget *widget,
688 GtkAssistant *assistant)
692 g_signal_emit (assistant, signals [APPLY], 0);
694 success = compute_next_step (assistant);
696 /* if the assistant hasn't switched to another page, just emit
697 * the CLOSE signal, it't the last page in the assistant flow
700 g_signal_emit (assistant, signals [CLOSE], 0);
704 on_assistant_forward (GtkWidget *widget,
705 GtkAssistant *assistant)
707 if (!compute_next_step (assistant))
708 g_critical ("Page flow is broken, you may want to end it with a page of "
709 "type GTK_ASSISTANT_PAGE_CONFIRM or GTK_ASSISTANT_PAGE_SUMMARY");
713 on_assistant_back (GtkWidget *widget,
714 GtkAssistant *assistant)
716 GtkAssistantPrivate *priv = assistant->priv;
717 GtkAssistantPage *page_info;
720 /* skip the progress pages when going back */
723 page_node = priv->visited_pages;
725 g_return_if_fail (page_node != NULL);
727 priv->visited_pages = priv->visited_pages->next;
728 page_info = (GtkAssistantPage *) page_node->data;
729 g_slist_free_1 (page_node);
731 while (page_info->type == GTK_ASSISTANT_PAGE_PROGRESS ||
732 !gtk_widget_get_visible (page_info->page));
734 set_current_page (assistant, page_info);
738 on_assistant_cancel (GtkWidget *widget,
739 GtkAssistant *assistant)
741 g_signal_emit (assistant, signals [CANCEL], 0, NULL);
745 on_assistant_last (GtkWidget *widget,
746 GtkAssistant *assistant)
748 GtkAssistantPrivate *priv = assistant->priv;
750 while (priv->current_page->type == GTK_ASSISTANT_PAGE_CONTENT &&
751 priv->current_page->complete)
752 compute_next_step (assistant);
756 alternative_button_order (GtkAssistant *assistant)
758 GtkSettings *settings;
762 screen = gtk_widget_get_screen (GTK_WIDGET (assistant));
763 settings = gtk_settings_get_for_screen (screen);
765 g_object_get (settings,
766 "gtk-alternative-button-order", &result,
772 gtk_assistant_init (GtkAssistant *assistant)
774 GtkAssistantPrivate *priv;
776 priv = assistant->priv = GTK_ASSISTANT_GET_PRIVATE (assistant);
778 gtk_container_set_reallocate_redraws (GTK_CONTAINER (assistant), TRUE);
779 gtk_container_set_border_width (GTK_CONTAINER (assistant), 12);
781 gtk_widget_push_composite_child ();
784 priv->header_image = gtk_image_new ();
785 gtk_misc_set_alignment (GTK_MISC (priv->header_image), 1., 0.5);
786 gtk_widget_set_parent (priv->header_image, GTK_WIDGET (assistant));
787 gtk_widget_show (priv->header_image);
790 priv->sidebar_image = gtk_image_new ();
791 gtk_misc_set_alignment (GTK_MISC (priv->sidebar_image), 0., 0.);
792 gtk_widget_set_parent (priv->sidebar_image, GTK_WIDGET (assistant));
793 gtk_widget_show (priv->sidebar_image);
796 priv->action_area = gtk_hbox_new (FALSE, 6);
798 assistant->close = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
799 assistant->apply = gtk_button_new_from_stock (GTK_STOCK_APPLY);
800 assistant->forward = gtk_button_new_from_stock (GTK_STOCK_GO_FORWARD);
801 assistant->back = gtk_button_new_from_stock (GTK_STOCK_GO_BACK);
802 assistant->cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
803 assistant->last = gtk_button_new_from_stock (GTK_STOCK_GOTO_LAST);
804 gtk_widget_set_can_default (assistant->close, TRUE);
805 gtk_widget_set_can_default (assistant->apply, TRUE);
806 gtk_widget_set_can_default (assistant->forward, TRUE);
808 priv->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
809 gtk_size_group_add_widget (priv->size_group, assistant->close);
810 gtk_size_group_add_widget (priv->size_group, assistant->apply);
811 gtk_size_group_add_widget (priv->size_group, assistant->forward);
812 gtk_size_group_add_widget (priv->size_group, assistant->back);
813 gtk_size_group_add_widget (priv->size_group, assistant->cancel);
814 gtk_size_group_add_widget (priv->size_group, assistant->last);
816 if (!alternative_button_order (assistant))
818 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->apply, FALSE, FALSE, 0);
819 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->forward, FALSE, FALSE, 0);
820 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->back, FALSE, FALSE, 0);
821 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->last, FALSE, FALSE, 0);
822 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->cancel, FALSE, FALSE, 0);
823 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->close, FALSE, FALSE, 0);
827 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->close, FALSE, FALSE, 0);
828 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->cancel, FALSE, FALSE, 0);
829 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->apply, FALSE, FALSE, 0);
830 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->forward, FALSE, FALSE, 0);
831 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->back, FALSE, FALSE, 0);
832 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->last, FALSE, FALSE, 0);
835 gtk_widget_set_parent (priv->action_area, GTK_WIDGET (assistant));
836 gtk_widget_show (assistant->forward);
837 gtk_widget_show (assistant->back);
838 gtk_widget_show (assistant->cancel);
839 gtk_widget_show (priv->action_area);
841 gtk_widget_pop_composite_child ();
844 priv->current_page = NULL;
845 priv->visited_pages = NULL;
847 priv->forward_function = default_forward_function;
848 priv->forward_function_data = assistant;
849 priv->forward_data_destroy = NULL;
851 g_signal_connect (G_OBJECT (assistant->close), "clicked",
852 G_CALLBACK (on_assistant_close), assistant);
853 g_signal_connect (G_OBJECT (assistant->apply), "clicked",
854 G_CALLBACK (on_assistant_apply), assistant);
855 g_signal_connect (G_OBJECT (assistant->forward), "clicked",
856 G_CALLBACK (on_assistant_forward), assistant);
857 g_signal_connect (G_OBJECT (assistant->back), "clicked",
858 G_CALLBACK (on_assistant_back), assistant);
859 g_signal_connect (G_OBJECT (assistant->cancel), "clicked",
860 G_CALLBACK (on_assistant_cancel), assistant);
861 g_signal_connect (G_OBJECT (assistant->last), "clicked",
862 G_CALLBACK (on_assistant_last), assistant);
866 gtk_assistant_set_child_property (GtkContainer *container,
874 case CHILD_PROP_PAGE_TYPE:
875 gtk_assistant_set_page_type (GTK_ASSISTANT (container), child,
876 g_value_get_enum (value));
878 case CHILD_PROP_PAGE_TITLE:
879 gtk_assistant_set_page_title (GTK_ASSISTANT (container), child,
880 g_value_get_string (value));
882 case CHILD_PROP_PAGE_HEADER_IMAGE:
883 gtk_assistant_set_page_header_image (GTK_ASSISTANT (container), child,
884 g_value_get_object (value));
886 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
887 gtk_assistant_set_page_side_image (GTK_ASSISTANT (container), child,
888 g_value_get_object (value));
890 case CHILD_PROP_PAGE_COMPLETE:
891 gtk_assistant_set_page_complete (GTK_ASSISTANT (container), child,
892 g_value_get_boolean (value));
895 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
901 gtk_assistant_get_child_property (GtkContainer *container,
909 case CHILD_PROP_PAGE_TYPE:
910 g_value_set_enum (value,
911 gtk_assistant_get_page_type (GTK_ASSISTANT (container), child));
913 case CHILD_PROP_PAGE_TITLE:
914 g_value_set_string (value,
915 gtk_assistant_get_page_title (GTK_ASSISTANT (container), child));
917 case CHILD_PROP_PAGE_HEADER_IMAGE:
918 g_value_set_object (value,
919 gtk_assistant_get_page_header_image (GTK_ASSISTANT (container), child));
921 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
922 g_value_set_object (value,
923 gtk_assistant_get_page_side_image (GTK_ASSISTANT (container), child));
925 case CHILD_PROP_PAGE_COMPLETE:
926 g_value_set_boolean (value,
927 gtk_assistant_get_page_complete (GTK_ASSISTANT (container), child));
930 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
936 on_page_notify_visibility (GtkWidget *widget,
940 GtkAssistant *assistant = GTK_ASSISTANT (data);
942 /* update buttons state, flow may have changed */
943 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
944 set_assistant_buttons_state (assistant);
948 remove_page (GtkAssistant *assistant,
951 GtkAssistantPrivate *priv = assistant->priv;
952 GtkAssistantPage *page_info;
955 page_info = element->data;
957 /* If this is the current page, we need to switch away. */
958 if (page_info == priv->current_page)
960 if (!compute_next_step (assistant))
962 /* The best we can do at this point is probably to pick the first
965 page_node = priv->pages;
967 while (page_node && !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
968 page_node = page_node->next;
970 if (page_node == element)
971 page_node = page_node->next;
974 priv->current_page = page_node->data;
976 priv->current_page = NULL;
980 priv->pages = g_list_remove_link (priv->pages, element);
981 priv->visited_pages = g_slist_remove_all (priv->visited_pages, page_info);
983 g_signal_handlers_disconnect_by_func (page_info->page, on_page_notify_visibility, assistant);
984 gtk_widget_unparent (page_info->page);
986 if (page_info->header_image)
987 g_object_unref (page_info->header_image);
989 if (page_info->sidebar_image)
990 g_object_unref (page_info->sidebar_image);
992 gtk_widget_destroy (page_info->title);
993 g_slice_free (GtkAssistantPage, page_info);
994 g_list_free_1 (element);
998 gtk_assistant_destroy (GtkObject *object)
1000 GtkAssistant *assistant = GTK_ASSISTANT (object);
1001 GtkAssistantPrivate *priv = assistant->priv;
1003 if (priv->header_image)
1005 gtk_widget_destroy (priv->header_image);
1006 priv->header_image = NULL;
1009 if (priv->sidebar_image)
1011 gtk_widget_destroy (priv->sidebar_image);
1012 priv->sidebar_image = NULL;
1015 if (priv->action_area)
1017 gtk_widget_destroy (priv->action_area);
1018 priv->action_area = NULL;
1021 if (priv->size_group)
1023 g_object_unref (priv->size_group);
1024 priv->size_group = NULL;
1027 if (priv->forward_function)
1029 if (priv->forward_function_data &&
1030 priv->forward_data_destroy)
1031 priv->forward_data_destroy (priv->forward_function_data);
1033 priv->forward_function = NULL;
1034 priv->forward_function_data = NULL;
1035 priv->forward_data_destroy = NULL;
1038 if (priv->visited_pages)
1040 g_slist_free (priv->visited_pages);
1041 priv->visited_pages = NULL;
1044 /* We set current to NULL so that the remove code doesn't try
1045 * to do anything funny */
1046 priv->current_page = NULL;
1049 remove_page (GTK_ASSISTANT (object), priv->pages);
1051 GTK_OBJECT_CLASS (gtk_assistant_parent_class)->destroy (object);
1055 find_page (GtkAssistant *assistant,
1058 GtkAssistantPrivate *priv = assistant->priv;
1059 GList *child = priv->pages;
1063 GtkAssistantPage *page_info = child->data;
1064 if (page_info->page == page)
1067 child = child->next;
1074 set_title_colors (GtkWidget *assistant,
1075 GtkWidget *title_label)
1079 gtk_widget_ensure_style (assistant);
1080 style = gtk_widget_get_style (assistant);
1082 /* change colors schema, for making the header text visible */
1083 gtk_widget_modify_bg (title_label, GTK_STATE_NORMAL, &style->bg[GTK_STATE_SELECTED]);
1084 gtk_widget_modify_fg (title_label, GTK_STATE_NORMAL, &style->fg[GTK_STATE_SELECTED]);
1088 set_title_font (GtkWidget *assistant,
1089 GtkWidget *title_label)
1091 PangoFontDescription *desc;
1094 desc = pango_font_description_new ();
1095 size = pango_font_description_get_size (assistant->style->font_desc);
1097 pango_font_description_set_weight (desc, PANGO_WEIGHT_ULTRABOLD);
1098 pango_font_description_set_size (desc, size * PANGO_SCALE_XX_LARGE);
1100 gtk_widget_modify_font (title_label, desc);
1101 pango_font_description_free (desc);
1105 gtk_assistant_style_set (GtkWidget *widget,
1106 GtkStyle *old_style)
1108 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1109 GtkAssistantPrivate *priv = assistant->priv;
1116 GtkAssistantPage *page = list->data;
1118 set_title_colors (widget, page->title);
1119 set_title_font (widget, page->title);
1126 gtk_assistant_size_request (GtkWidget *widget,
1127 GtkRequisition *requisition)
1129 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1130 GtkAssistantPrivate *priv = assistant->priv;
1131 GtkRequisition child_requisition;
1132 gint header_padding, content_padding;
1133 gint width, height, header_width, header_height;
1136 gtk_widget_style_get (widget,
1137 "header-padding", &header_padding,
1138 "content-padding", &content_padding,
1141 header_width = header_height = 0;
1146 GtkAssistantPage *page = list->data;
1149 gtk_widget_size_request (page->page, &child_requisition);
1150 width = MAX (width, child_requisition.width);
1151 height = MAX (height, child_requisition.height);
1153 gtk_widget_size_request (page->title, &child_requisition);
1154 w = child_requisition.width;
1155 h = child_requisition.height;
1157 if (page->header_image)
1159 w += gdk_pixbuf_get_width (page->header_image) + HEADER_SPACING;
1160 h = MAX (h, gdk_pixbuf_get_height (page->header_image));
1163 header_width = MAX (header_width, w);
1164 header_height = MAX (header_height, h);
1169 gtk_widget_size_request (priv->sidebar_image, &child_requisition);
1170 width += child_requisition.width;
1171 height = MAX (height, child_requisition.height);
1173 gtk_widget_set_size_request (priv->header_image, header_width, header_height);
1174 gtk_widget_size_request (priv->header_image, &child_requisition);
1175 width = MAX (width, header_width) + 2 * header_padding;
1176 height += header_height + 2 * header_padding;
1178 gtk_widget_size_request (priv->action_area, &child_requisition);
1179 width = MAX (width, child_requisition.width);
1180 height += child_requisition.height + ACTION_AREA_SPACING;
1182 width += GTK_CONTAINER (widget)->border_width * 2 + content_padding * 2;
1183 height += GTK_CONTAINER (widget)->border_width * 2 + content_padding * 2;
1185 requisition->width = width;
1186 requisition->height = height;
1191 gtk_assistant_size_allocate (GtkWidget *widget,
1192 GtkAllocation *allocation)
1194 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1195 GtkAssistantPrivate *priv = assistant->priv;
1196 GtkRequisition header_requisition, action_requisition, sidebar_requisition;
1197 GtkAllocation child_allocation, header_allocation;
1198 gint header_padding, content_padding;
1202 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1203 pages = priv->pages;
1205 gtk_widget_style_get (widget,
1206 "header-padding", &header_padding,
1207 "content-padding", &content_padding,
1210 widget->allocation = *allocation;
1213 gtk_widget_get_child_requisition (priv->header_image, &header_requisition);
1215 header_allocation.x = GTK_CONTAINER (widget)->border_width + header_padding;
1216 header_allocation.y = GTK_CONTAINER (widget)->border_width + header_padding;
1217 header_allocation.width = allocation->width - 2 * GTK_CONTAINER (widget)->border_width - 2 * header_padding;
1218 header_allocation.height = header_requisition.height;
1220 gtk_widget_size_allocate (priv->header_image, &header_allocation);
1223 gtk_widget_get_child_requisition (priv->action_area, &action_requisition);
1225 child_allocation.x = GTK_CONTAINER (widget)->border_width;
1226 child_allocation.y = allocation->height -
1227 GTK_CONTAINER (widget)->border_width - action_requisition.height;
1228 child_allocation.width = allocation->width - 2 * GTK_CONTAINER (widget)->border_width;
1229 child_allocation.height = action_requisition.height;
1231 gtk_widget_size_allocate (priv->action_area, &child_allocation);
1234 gtk_widget_get_child_requisition (priv->sidebar_image, &sidebar_requisition);
1237 child_allocation.x = allocation->width -
1238 GTK_CONTAINER (widget)->border_width - sidebar_requisition.width;
1240 child_allocation.x = GTK_CONTAINER (widget)->border_width;
1242 child_allocation.y = GTK_CONTAINER (widget)->border_width +
1243 priv->header_image->allocation.height + 2 * header_padding;
1244 child_allocation.width = sidebar_requisition.width;
1245 child_allocation.height = allocation->height - 2 * GTK_CONTAINER (widget)->border_width -
1246 priv->header_image->allocation.height - 2 * header_padding - priv->action_area->allocation.height;
1248 gtk_widget_size_allocate (priv->sidebar_image, &child_allocation);
1251 child_allocation.x = GTK_CONTAINER (widget)->border_width + content_padding;
1252 child_allocation.y = GTK_CONTAINER (widget)->border_width +
1253 priv->header_image->allocation.height + 2 * header_padding + content_padding;
1254 child_allocation.width = allocation->width - 2 * GTK_CONTAINER (widget)->border_width - 2 * content_padding;
1255 child_allocation.height = allocation->height - 2 * GTK_CONTAINER (widget)->border_width -
1256 priv->header_image->allocation.height - 2 * header_padding - ACTION_AREA_SPACING - priv->action_area->allocation.height - 2 * content_padding;
1258 if (gtk_widget_get_visible (priv->sidebar_image))
1261 child_allocation.x += priv->sidebar_image->allocation.width;
1263 child_allocation.width -= priv->sidebar_image->allocation.width;
1268 GtkAssistantPage *page = pages->data;
1270 gtk_widget_size_allocate (page->page, &child_allocation);
1271 gtk_widget_size_allocate (page->title, &header_allocation);
1272 pages = pages->next;
1277 gtk_assistant_map (GtkWidget *widget)
1279 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1280 GtkAssistantPrivate *priv = assistant->priv;
1282 GtkAssistantPage *page;
1284 gtk_widget_set_mapped (widget, TRUE);
1286 gtk_widget_map (priv->header_image);
1287 gtk_widget_map (priv->action_area);
1289 if (gtk_widget_get_visible (priv->sidebar_image) &&
1290 !gtk_widget_get_mapped (priv->sidebar_image))
1291 gtk_widget_map (priv->sidebar_image);
1293 /* if there's no default page, pick the first one */
1295 if (!priv->current_page)
1297 page_node = priv->pages;
1299 while (page_node && !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
1300 page_node = page_node->next;
1303 page = page_node->data;
1307 gtk_widget_get_visible (page->page) &&
1308 !gtk_widget_get_mapped (page->page))
1309 set_current_page (assistant, page);
1311 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->map (widget);
1315 gtk_assistant_unmap (GtkWidget *widget)
1317 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1318 GtkAssistantPrivate *priv = assistant->priv;
1320 gtk_widget_set_mapped (widget, FALSE);
1322 gtk_widget_unmap (priv->header_image);
1323 gtk_widget_unmap (priv->action_area);
1325 if (gtk_widget_is_drawable (priv->sidebar_image))
1326 gtk_widget_unmap (priv->sidebar_image);
1328 if (priv->current_page &&
1329 gtk_widget_is_drawable (priv->current_page->page))
1330 gtk_widget_unmap (priv->current_page->page);
1332 g_slist_free (priv->visited_pages);
1333 priv->visited_pages = NULL;
1334 priv->current_page = NULL;
1336 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->unmap (widget);
1340 gtk_assistant_delete_event (GtkWidget *widget,
1343 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1344 GtkAssistantPrivate *priv = assistant->priv;
1346 /* Do not allow cancelling in the middle of a progress page */
1347 if (priv->current_page &&
1348 (priv->current_page->type != GTK_ASSISTANT_PAGE_PROGRESS ||
1349 priv->current_page->complete))
1350 g_signal_emit (widget, signals [CANCEL], 0, NULL);
1356 assistant_paint_colored_box (GtkWidget *widget)
1358 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1359 GtkAssistantPrivate *priv = assistant->priv;
1360 gint border_width, header_padding, content_padding;
1362 gint content_x, content_width;
1365 cr = gdk_cairo_create (widget->window);
1366 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1367 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1369 gtk_widget_style_get (widget,
1370 "header-padding", &header_padding,
1371 "content-padding", &content_padding,
1375 gdk_cairo_set_source_color (cr, &widget->style->bg[GTK_STATE_SELECTED]);
1376 cairo_rectangle (cr,
1379 widget->allocation.width - 2 * border_width,
1380 widget->allocation.height - priv->action_area->allocation.height - 2 * border_width - ACTION_AREA_SPACING);
1384 content_x = content_padding + border_width;
1385 content_width = widget->allocation.width - 2 * content_padding - 2 * border_width;
1387 if (gtk_widget_get_visible (priv->sidebar_image))
1390 content_x += priv->sidebar_image->allocation.width;
1391 content_width -= priv->sidebar_image->allocation.width;
1394 gdk_cairo_set_source_color (cr, &widget->style->bg[GTK_STATE_NORMAL]);
1396 cairo_rectangle (cr,
1398 priv->header_image->allocation.height + content_padding + 2 * header_padding + border_width,
1400 widget->allocation.height - 2 * border_width - priv->action_area->allocation.height -
1401 priv->header_image->allocation.height - 2 * content_padding - 2 * header_padding - ACTION_AREA_SPACING);
1408 gtk_assistant_expose (GtkWidget *widget,
1409 GdkEventExpose *event)
1411 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1412 GtkAssistantPrivate *priv = assistant->priv;
1413 GtkContainer *container;
1415 if (gtk_widget_is_drawable (widget))
1417 container = GTK_CONTAINER (widget);
1419 assistant_paint_colored_box (widget);
1421 gtk_container_propagate_expose (container, priv->header_image, event);
1422 gtk_container_propagate_expose (container, priv->sidebar_image, event);
1423 gtk_container_propagate_expose (container, priv->action_area, event);
1425 if (priv->current_page)
1427 gtk_container_propagate_expose (container, priv->current_page->page, event);
1428 gtk_container_propagate_expose (container, priv->current_page->title, event);
1436 gtk_assistant_focus (GtkWidget *widget,
1437 GtkDirectionType direction)
1439 GtkAssistantPrivate *priv;
1440 GtkContainer *container;
1442 container = GTK_CONTAINER (widget);
1443 priv = GTK_ASSISTANT (widget)->priv;
1445 /* we only have to care about 2 widgets, action area and the current page */
1446 if (container->focus_child == priv->action_area)
1448 if (!gtk_widget_child_focus (priv->action_area, direction) &&
1449 (priv->current_page == NULL ||
1450 !gtk_widget_child_focus (priv->current_page->page, direction)))
1452 /* if we're leaving the action area and the current page hasn't
1453 any focusable widget, clear focus and go back to the action area */
1454 gtk_container_set_focus_child (GTK_CONTAINER (priv->action_area), NULL);
1455 gtk_widget_child_focus (priv->action_area, direction);
1460 if ((priv->current_page == NULL ||
1461 !gtk_widget_child_focus (priv->current_page->page, direction)) &&
1462 !gtk_widget_child_focus (priv->action_area, direction))
1464 /* if we're leaving the current page and there isn't nothing focusable
1465 in the action area, try to clear focus and go back to the page */
1466 gtk_window_set_focus (GTK_WINDOW (widget), NULL);
1467 if (priv->current_page != NULL)
1468 gtk_widget_child_focus (priv->current_page->page, direction);
1476 gtk_assistant_add (GtkContainer *container,
1479 gtk_assistant_append_page (GTK_ASSISTANT (container), page);
1483 gtk_assistant_remove (GtkContainer *container,
1486 GtkAssistant *assistant = (GtkAssistant*) container;
1489 element = find_page (assistant, page);
1493 remove_page (assistant, element);
1494 gtk_widget_queue_resize ((GtkWidget *) container);
1499 gtk_assistant_forall (GtkContainer *container,
1500 gboolean include_internals,
1501 GtkCallback callback,
1502 gpointer callback_data)
1504 GtkAssistant *assistant = (GtkAssistant*) container;
1505 GtkAssistantPrivate *priv = assistant->priv;
1508 if (include_internals)
1510 (*callback) (priv->header_image, callback_data);
1511 (*callback) (priv->sidebar_image, callback_data);
1512 (*callback) (priv->action_area, callback_data);
1515 pages = priv->pages;
1519 GtkAssistantPage *page = (GtkAssistantPage *) pages->data;
1521 (*callback) (page->page, callback_data);
1523 if (include_internals)
1524 (*callback) (page->title, callback_data);
1526 pages = pages->next;
1531 * gtk_assistant_new:
1533 * Creates a new #GtkAssistant.
1535 * Return value: a newly created #GtkAssistant
1540 gtk_assistant_new (void)
1542 GtkWidget *assistant;
1544 assistant = g_object_new (GTK_TYPE_ASSISTANT, NULL);
1550 * gtk_assistant_get_current_page:
1551 * @assistant: a #GtkAssistant
1553 * Returns the page number of the current page
1555 * Return value: The index (starting from 0) of the current page in
1556 * the @assistant, if the @assistant has no pages, -1 will be returned
1561 gtk_assistant_get_current_page (GtkAssistant *assistant)
1563 GtkAssistantPrivate *priv;
1565 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), -1);
1567 priv = assistant->priv;
1569 if (!priv->pages || !priv->current_page)
1572 return g_list_index (priv->pages, priv->current_page);
1576 * gtk_assistant_set_current_page:
1577 * @assistant: a #GtkAssistant
1578 * @page_num: index of the page to switch to, starting from 0.
1579 * If negative, the last page will be used. If greater
1580 * than the number of pages in the @assistant, nothing
1583 * Switches the page to @page_num. Note that this will only be necessary
1584 * in custom buttons, as the @assistant flow can be set with
1585 * gtk_assistant_set_forward_page_func().
1590 gtk_assistant_set_current_page (GtkAssistant *assistant,
1593 GtkAssistantPrivate *priv;
1594 GtkAssistantPage *page;
1596 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1598 priv = assistant->priv;
1601 page = (GtkAssistantPage *) g_list_nth_data (priv->pages, page_num);
1603 page = (GtkAssistantPage *) g_list_last (priv->pages)->data;
1605 g_return_if_fail (page != NULL);
1607 if (priv->current_page == page)
1610 /* only add the page to the visited list if the
1611 * assistant is mapped, if not, just use it as an
1612 * initial page setting, for the cases where the
1613 * initial page is != to 0
1615 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1616 priv->visited_pages = g_slist_prepend (priv->visited_pages,
1617 priv->current_page);
1619 set_current_page (assistant, page);
1623 * gtk_assistant_get_n_pages:
1624 * @assistant: a #GtkAssistant
1626 * Returns the number of pages in the @assistant
1628 * Return value: The number of pages in the @assistant.
1633 gtk_assistant_get_n_pages (GtkAssistant *assistant)
1635 GtkAssistantPrivate *priv;
1637 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1639 priv = assistant->priv;
1641 return g_list_length (priv->pages);
1645 * gtk_assistant_get_nth_page:
1646 * @assistant: a #GtkAssistant
1647 * @page_num: The index of a page in the @assistant, or -1 to get the last page;
1649 * Returns the child widget contained in page number @page_num.
1651 * Return value: The child widget, or %NULL if @page_num is out of bounds.
1656 gtk_assistant_get_nth_page (GtkAssistant *assistant,
1659 GtkAssistantPrivate *priv;
1660 GtkAssistantPage *page;
1663 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1664 g_return_val_if_fail (page_num >= -1, NULL);
1666 priv = assistant->priv;
1669 elem = g_list_last (priv->pages);
1671 elem = g_list_nth (priv->pages, page_num);
1676 page = (GtkAssistantPage *) elem->data;
1682 * gtk_assistant_prepend_page:
1683 * @assistant: a #GtkAssistant
1684 * @page: a #GtkWidget
1686 * Prepends a page to the @assistant.
1688 * Return value: the index (starting at 0) of the inserted page
1693 gtk_assistant_prepend_page (GtkAssistant *assistant,
1696 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1697 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1699 return gtk_assistant_insert_page (assistant, page, 0);
1703 * gtk_assistant_append_page:
1704 * @assistant: a #GtkAssistant
1705 * @page: a #GtkWidget
1707 * Appends a page to the @assistant.
1709 * Return value: the index (starting at 0) of the inserted page
1714 gtk_assistant_append_page (GtkAssistant *assistant,
1717 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1718 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1720 return gtk_assistant_insert_page (assistant, page, -1);
1724 * gtk_assistant_insert_page:
1725 * @assistant: a #GtkAssistant
1726 * @page: a #GtkWidget
1727 * @position: the index (starting at 0) at which to insert the page,
1728 * or -1 to append the page to the @assistant
1730 * Inserts a page in the @assistant at a given position.
1732 * Return value: the index (starting from 0) of the inserted page
1737 gtk_assistant_insert_page (GtkAssistant *assistant,
1741 GtkAssistantPrivate *priv;
1742 GtkAssistantPage *page_info;
1745 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1746 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1747 g_return_val_if_fail (page->parent == NULL, 0);
1748 g_return_val_if_fail (!gtk_widget_is_toplevel (page), 0);
1750 priv = assistant->priv;
1752 page_info = g_slice_new0 (GtkAssistantPage);
1753 page_info->page = page;
1754 page_info->title = gtk_label_new (NULL);
1756 g_signal_connect (G_OBJECT (page), "notify::visible",
1757 G_CALLBACK (on_page_notify_visibility), assistant);
1759 gtk_misc_set_alignment (GTK_MISC (page_info->title), 0.,0.5);
1760 set_title_colors (GTK_WIDGET (assistant), page_info->title);
1761 set_title_font (GTK_WIDGET (assistant), page_info->title);
1762 gtk_widget_show (page_info->title);
1764 n_pages = g_list_length (priv->pages);
1766 if (position < 0 || position > n_pages)
1769 priv->pages = g_list_insert (priv->pages, page_info, position);
1771 gtk_widget_set_child_visible (page_info->page, FALSE);
1772 gtk_widget_set_parent (page_info->page, GTK_WIDGET (assistant));
1773 gtk_widget_set_parent (page_info->title, GTK_WIDGET (assistant));
1775 if (gtk_widget_get_realized (GTK_WIDGET (assistant)))
1777 gtk_widget_realize (page_info->page);
1778 gtk_widget_realize (page_info->title);
1781 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1787 * gtk_assistant_set_forward_page_func:
1788 * @assistant: a #GtkAssistant
1789 * @page_func: (allow-none): the #GtkAssistantPageFunc, or %NULL to use the default one
1790 * @data: user data for @page_func
1791 * @destroy: destroy notifier for @data
1793 * Sets the page forwarding function to be @page_func, this function will
1794 * be used to determine what will be the next page when the user presses
1795 * the forward button. Setting @page_func to %NULL will make the assistant
1796 * to use the default forward function, which just goes to the next visible
1802 gtk_assistant_set_forward_page_func (GtkAssistant *assistant,
1803 GtkAssistantPageFunc page_func,
1805 GDestroyNotify destroy)
1807 GtkAssistantPrivate *priv;
1809 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1811 priv = assistant->priv;
1813 if (priv->forward_data_destroy &&
1814 priv->forward_function_data)
1815 (*priv->forward_data_destroy) (priv->forward_function_data);
1819 priv->forward_function = page_func;
1820 priv->forward_function_data = data;
1821 priv->forward_data_destroy = destroy;
1825 priv->forward_function = default_forward_function;
1826 priv->forward_function_data = assistant;
1827 priv->forward_data_destroy = NULL;
1830 /* Page flow has possibly changed, so the
1831 buttons state might need to change too */
1832 set_assistant_buttons_state (assistant);
1836 * gtk_assistant_add_action_widget:
1837 * @assistant: a #GtkAssistant
1838 * @child: a #GtkWidget
1840 * Adds a widget to the action area of a #GtkAssistant.
1845 gtk_assistant_add_action_widget (GtkAssistant *assistant,
1848 GtkAssistantPrivate *priv;
1850 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1851 g_return_if_fail (GTK_IS_WIDGET (child));
1853 priv = assistant->priv;
1855 if (GTK_IS_BUTTON (child))
1856 gtk_size_group_add_widget (priv->size_group, child);
1858 gtk_box_pack_end (GTK_BOX (priv->action_area), child, FALSE, FALSE, 0);
1862 * gtk_assistant_remove_action_widget:
1863 * @assistant: a #GtkAssistant
1864 * @child: a #GtkWidget
1866 * Removes a widget from the action area of a #GtkAssistant.
1871 gtk_assistant_remove_action_widget (GtkAssistant *assistant,
1874 GtkAssistantPrivate *priv;
1876 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1877 g_return_if_fail (GTK_IS_WIDGET (child));
1879 priv = assistant->priv;
1881 if (GTK_IS_BUTTON (child))
1882 gtk_size_group_remove_widget (priv->size_group, child);
1884 gtk_container_remove (GTK_CONTAINER (priv->action_area), child);
1888 * gtk_assistant_set_page_title:
1889 * @assistant: a #GtkAssistant
1890 * @page: a page of @assistant
1891 * @title: the new title for @page
1893 * Sets a title for @page. The title is displayed in the header
1894 * area of the assistant when @page is the current page.
1899 gtk_assistant_set_page_title (GtkAssistant *assistant,
1903 GtkAssistantPage *page_info;
1906 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1907 g_return_if_fail (GTK_IS_WIDGET (page));
1909 child = find_page (assistant, page);
1911 g_return_if_fail (child != NULL);
1913 page_info = (GtkAssistantPage*) child->data;
1915 gtk_label_set_text ((GtkLabel*) page_info->title, title);
1916 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1917 gtk_widget_child_notify (page, "title");
1921 * gtk_assistant_get_page_title:
1922 * @assistant: a #GtkAssistant
1923 * @page: a page of @assistant
1925 * Gets the title for @page.
1927 * Return value: the title for @page.
1931 G_CONST_RETURN gchar*
1932 gtk_assistant_get_page_title (GtkAssistant *assistant,
1935 GtkAssistantPage *page_info;
1938 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1939 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1941 child = find_page (assistant, page);
1943 g_return_val_if_fail (child != NULL, NULL);
1945 page_info = (GtkAssistantPage*) child->data;
1947 return gtk_label_get_text ((GtkLabel*) page_info->title);
1951 * gtk_assistant_set_page_type:
1952 * @assistant: a #GtkAssistant
1953 * @page: a page of @assistant
1954 * @type: the new type for @page
1956 * Sets the page type for @page. The page type determines the page
1957 * behavior in the @assistant.
1962 gtk_assistant_set_page_type (GtkAssistant *assistant,
1964 GtkAssistantPageType type)
1966 GtkAssistantPrivate *priv;
1967 GtkAssistantPage *page_info;
1970 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1971 g_return_if_fail (GTK_IS_WIDGET (page));
1973 priv = assistant->priv;
1974 child = find_page (assistant, page);
1976 g_return_if_fail (child != NULL);
1978 page_info = (GtkAssistantPage*) child->data;
1980 if (type != page_info->type)
1982 page_info->type = type;
1984 /* backwards compatibility to the era before fixing bug 604289 */
1985 if (type == GTK_ASSISTANT_PAGE_SUMMARY && !page_info->complete_set)
1987 gtk_assistant_set_page_complete (assistant, page, TRUE);
1988 page_info->complete_set = FALSE;
1991 /* Always set buttons state, a change in a future page
1992 might change current page buttons */
1993 set_assistant_buttons_state (assistant);
1995 gtk_widget_child_notify (page, "page-type");
2000 * gtk_assistant_get_page_type:
2001 * @assistant: a #GtkAssistant
2002 * @page: a page of @assistant
2004 * Gets the page type of @page.
2006 * Return value: the page type of @page.
2010 GtkAssistantPageType
2011 gtk_assistant_get_page_type (GtkAssistant *assistant,
2014 GtkAssistantPage *page_info;
2017 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), GTK_ASSISTANT_PAGE_CONTENT);
2018 g_return_val_if_fail (GTK_IS_WIDGET (page), GTK_ASSISTANT_PAGE_CONTENT);
2020 child = find_page (assistant, page);
2022 g_return_val_if_fail (child != NULL, GTK_ASSISTANT_PAGE_CONTENT);
2024 page_info = (GtkAssistantPage*) child->data;
2026 return page_info->type;
2030 * gtk_assistant_set_page_header_image:
2031 * @assistant: a #GtkAssistant
2032 * @page: a page of @assistant
2033 * @pixbuf: (allow-none): the new header image @page
2035 * Sets a header image for @page. This image is displayed in the header
2036 * area of the assistant when @page is the current page.
2041 gtk_assistant_set_page_header_image (GtkAssistant *assistant,
2045 GtkAssistantPrivate *priv;
2046 GtkAssistantPage *page_info;
2049 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2050 g_return_if_fail (GTK_IS_WIDGET (page));
2051 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2053 priv = assistant->priv;
2054 child = find_page (assistant, page);
2056 g_return_if_fail (child != NULL);
2058 page_info = (GtkAssistantPage*) child->data;
2060 if (pixbuf != page_info->header_image)
2062 if (page_info->header_image)
2064 g_object_unref (page_info->header_image);
2065 page_info->header_image = NULL;
2069 page_info->header_image = g_object_ref (pixbuf);
2071 if (page_info == priv->current_page)
2072 set_assistant_header_image (assistant);
2074 gtk_widget_child_notify (page, "header-image");
2079 * gtk_assistant_get_page_header_image:
2080 * @assistant: a #GtkAssistant
2081 * @page: a page of @assistant
2083 * Gets the header image for @page.
2085 * Return value: the header image for @page, or %NULL
2086 * if there's no header image for the page.
2091 gtk_assistant_get_page_header_image (GtkAssistant *assistant,
2094 GtkAssistantPage *page_info;
2097 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2098 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2100 child = find_page (assistant, page);
2102 g_return_val_if_fail (child != NULL, NULL);
2104 page_info = (GtkAssistantPage*) child->data;
2106 return page_info->header_image;
2110 * gtk_assistant_set_page_side_image:
2111 * @assistant: a #GtkAssistant
2112 * @page: a page of @assistant
2113 * @pixbuf: (allow-none): the new header image @page
2115 * Sets a header image for @page. This image is displayed in the side
2116 * area of the assistant when @page is the current page.
2121 gtk_assistant_set_page_side_image (GtkAssistant *assistant,
2125 GtkAssistantPrivate *priv;
2126 GtkAssistantPage *page_info;
2129 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2130 g_return_if_fail (GTK_IS_WIDGET (page));
2131 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2133 priv = assistant->priv;
2134 child = find_page (assistant, page);
2136 g_return_if_fail (child != NULL);
2138 page_info = (GtkAssistantPage*) child->data;
2140 if (pixbuf != page_info->sidebar_image)
2142 if (page_info->sidebar_image)
2144 g_object_unref (page_info->sidebar_image);
2145 page_info->sidebar_image = NULL;
2149 page_info->sidebar_image = g_object_ref (pixbuf);
2151 if (page_info == priv->current_page)
2152 set_assistant_sidebar_image (assistant);
2154 gtk_widget_child_notify (page, "sidebar-image");
2159 * gtk_assistant_get_page_side_image:
2160 * @assistant: a #GtkAssistant
2161 * @page: a page of @assistant
2163 * Gets the header image for @page.
2165 * Return value: the side image for @page, or %NULL
2166 * if there's no side image for the page.
2171 gtk_assistant_get_page_side_image (GtkAssistant *assistant,
2174 GtkAssistantPage *page_info;
2177 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2178 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2180 child = find_page (assistant, page);
2182 g_return_val_if_fail (child != NULL, NULL);
2184 page_info = (GtkAssistantPage*) child->data;
2186 return page_info->sidebar_image;
2190 * gtk_assistant_set_page_complete:
2191 * @assistant: a #GtkAssistant
2192 * @page: a page of @assistant
2193 * @complete: the completeness status of the page
2195 * Sets whether @page contents are complete. This will make
2196 * @assistant update the buttons state to be able to continue the task.
2201 gtk_assistant_set_page_complete (GtkAssistant *assistant,
2205 GtkAssistantPrivate *priv;
2206 GtkAssistantPage *page_info;
2209 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2210 g_return_if_fail (GTK_IS_WIDGET (page));
2212 priv = assistant->priv;
2213 child = find_page (assistant, page);
2215 g_return_if_fail (child != NULL);
2217 page_info = (GtkAssistantPage*) child->data;
2219 if (complete != page_info->complete)
2221 page_info->complete = complete;
2222 page_info->complete_set = TRUE;
2224 /* Always set buttons state, a change in a future page
2225 might change current page buttons */
2226 set_assistant_buttons_state (assistant);
2228 gtk_widget_child_notify (page, "complete");
2233 * gtk_assistant_get_page_complete:
2234 * @assistant: a #GtkAssistant
2235 * @page: a page of @assistant
2237 * Gets whether @page is complete.
2239 * Return value: %TRUE if @page is complete.
2244 gtk_assistant_get_page_complete (GtkAssistant *assistant,
2247 GtkAssistantPage *page_info;
2250 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), FALSE);
2251 g_return_val_if_fail (GTK_IS_WIDGET (page), FALSE);
2253 child = find_page (assistant, page);
2255 g_return_val_if_fail (child != NULL, FALSE);
2257 page_info = (GtkAssistantPage*) child->data;
2259 return page_info->complete;
2263 * gtk_assistant_update_buttons_state:
2264 * @assistant: a #GtkAssistant
2266 * Forces @assistant to recompute the buttons state.
2268 * GTK+ automatically takes care of this in most situations,
2269 * e.g. when the user goes to a different page, or when the
2270 * visibility or completeness of a page changes.
2272 * One situation where it can be necessary to call this
2273 * function is when changing a value on the current page
2274 * affects the future page flow of the assistant.
2279 gtk_assistant_update_buttons_state (GtkAssistant *assistant)
2281 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2283 set_assistant_buttons_state (assistant);
2287 * gtk_assistant_commit:
2288 * @assistant: a #GtkAssistant
2290 * Erases the visited page history so the back button is not
2291 * shown on the current page, and removes the cancel button
2292 * from subsequent pages.
2294 * Use this when the information provided up to the current
2295 * page is hereafter deemed permanent and cannot be modified
2296 * or undone. For example, showing a progress page to track
2297 * a long-running, unreversible operation after the user has
2298 * clicked apply on a confirmation page.
2303 gtk_assistant_commit (GtkAssistant *assistant)
2305 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2307 g_slist_free (assistant->priv->visited_pages);
2308 assistant->priv->visited_pages = NULL;
2310 assistant->priv->committed = TRUE;
2312 set_assistant_buttons_state (assistant);
2317 /* accessible implementation */
2320 gtk_assistant_accessible_get_n_children (AtkObject *accessible)
2322 GtkAssistant *assistant;
2325 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2330 assistant = GTK_ASSISTANT (widget);
2332 return g_list_length (assistant->priv->pages) + 1;
2337 gtk_assistant_accessible_ref_child (AtkObject *accessible,
2340 GtkAssistant *assistant;
2341 GtkAssistantPrivate *priv;
2342 GtkWidget *widget, *child;
2347 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2351 assistant = GTK_ASSISTANT (widget);
2352 priv = assistant->priv;
2353 n_pages = g_list_length (priv->pages);
2357 else if (index < n_pages)
2359 GtkAssistantPage *page = g_list_nth_data (priv->pages, index);
2362 title = gtk_assistant_get_page_title (assistant, child);
2364 else if (index == n_pages)
2366 child = priv->action_area;
2372 obj = gtk_widget_get_accessible (child);
2375 atk_object_set_name (obj, title);
2377 return g_object_ref (obj);
2381 gtk_assistant_accessible_class_init (AtkObjectClass *class)
2383 class->get_n_children = gtk_assistant_accessible_get_n_children;
2384 class->ref_child = gtk_assistant_accessible_ref_child;
2388 gtk_assistant_accessible_get_type (void)
2390 static GType type = 0;
2395 * Figure out the size of the class and instance
2396 * we are deriving from
2398 AtkObjectFactory *factory;
2401 GType derived_atk_type;
2403 derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
2404 factory = atk_registry_get_factory (atk_get_default_registry (),
2406 derived_atk_type = atk_object_factory_get_accessible_type (factory);
2407 g_type_query (derived_atk_type, &query);
2409 type = g_type_register_static_simple (derived_atk_type,
2410 I_("GtkAssistantAccessible"),
2412 (GClassInitFunc) gtk_assistant_accessible_class_init,
2413 query.instance_size,
2421 gtk_assistant_accessible_new (GObject *obj)
2423 AtkObject *accessible;
2425 g_return_val_if_fail (GTK_IS_ASSISTANT (obj), NULL);
2427 accessible = g_object_new (gtk_assistant_accessible_get_type (), NULL);
2428 atk_object_initialize (accessible, obj);
2434 gtk_assistant_accessible_factory_get_accessible_type (void)
2436 return gtk_assistant_accessible_get_type ();
2440 gtk_assistant_accessible_factory_create_accessible (GObject *obj)
2442 return gtk_assistant_accessible_new (obj);
2446 gtk_assistant_accessible_factory_class_init (AtkObjectFactoryClass *class)
2448 class->create_accessible = gtk_assistant_accessible_factory_create_accessible;
2449 class->get_accessible_type = gtk_assistant_accessible_factory_get_accessible_type;
2453 gtk_assistant_accessible_factory_get_type (void)
2455 static GType type = 0;
2459 type = g_type_register_static_simple (ATK_TYPE_OBJECT_FACTORY,
2460 I_("GtkAssistantAccessibleFactory"),
2461 sizeof (AtkObjectFactoryClass),
2462 (GClassInitFunc) gtk_assistant_accessible_factory_class_init,
2463 sizeof (AtkObjectFactory),
2471 gtk_assistant_get_accessible (GtkWidget *widget)
2473 static gboolean first_time = TRUE;
2477 AtkObjectFactory *factory;
2478 AtkRegistry *registry;
2480 GType derived_atk_type;
2483 * Figure out whether accessibility is enabled by looking at the
2484 * type of the accessible object which would be created for
2485 * the parent type of GtkAssistant.
2487 derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
2489 registry = atk_get_default_registry ();
2490 factory = atk_registry_get_factory (registry,
2492 derived_atk_type = atk_object_factory_get_accessible_type (factory);
2493 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
2495 atk_registry_set_factory_type (registry,
2497 gtk_assistant_accessible_factory_get_type ());
2502 return GTK_WIDGET_CLASS (gtk_assistant_parent_class)->get_accessible (widget);
2506 static GtkBuildableIface *parent_buildable_iface;
2509 gtk_assistant_buildable_interface_init (GtkBuildableIface *iface)
2511 parent_buildable_iface = g_type_interface_peek_parent (iface);
2512 iface->get_internal_child = gtk_assistant_buildable_get_internal_child;
2513 iface->custom_tag_start = gtk_assistant_buildable_custom_tag_start;
2514 iface->custom_finished = gtk_assistant_buildable_custom_finished;
2518 gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
2519 GtkBuilder *builder,
2520 const gchar *childname)
2522 if (strcmp (childname, "action_area") == 0)
2523 return G_OBJECT (GTK_ASSISTANT (buildable)->priv->action_area);
2525 return parent_buildable_iface->get_internal_child (buildable,
2531 gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
2532 GtkBuilder *builder,
2534 const gchar *tagname,
2535 GMarkupParser *parser,
2538 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
2539 tagname, parser, data);
2543 gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
2544 GtkBuilder *builder,
2546 const gchar *tagname,
2549 parent_buildable_iface->custom_finished (buildable, builder, child,
2550 tagname, user_data);