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 (gtk_widget_get_style (assistant)->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 GtkAllocation action_area_allocation, header_image_allocation;
1210 gint header_padding, content_padding;
1215 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1216 pages = priv->pages;
1218 gtk_widget_style_get (widget,
1219 "header-padding", &header_padding,
1220 "content-padding", &content_padding,
1223 gtk_widget_set_allocation (widget, allocation);
1224 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1227 gtk_widget_get_child_requisition (priv->header_image, &header_requisition);
1229 header_allocation.x = border_width + header_padding;
1230 header_allocation.y = border_width + header_padding;
1231 header_allocation.width = allocation->width - 2 * border_width - 2 * header_padding;
1232 header_allocation.height = header_requisition.height;
1234 gtk_widget_size_allocate (priv->header_image, &header_allocation);
1237 gtk_widget_get_child_requisition (priv->action_area, &action_requisition);
1239 child_allocation.x = border_width;
1240 child_allocation.y = allocation->height - border_width - action_requisition.height;
1241 child_allocation.width = allocation->width - 2 * border_width;
1242 child_allocation.height = action_requisition.height;
1244 gtk_widget_size_allocate (priv->action_area, &child_allocation);
1246 gtk_widget_get_allocation (priv->header_image, &header_image_allocation);
1247 gtk_widget_get_allocation (priv->action_area, &action_area_allocation);
1250 gtk_widget_get_child_requisition (priv->sidebar_image, &sidebar_requisition);
1253 child_allocation.x = allocation->width - border_width - sidebar_requisition.width;
1255 child_allocation.x = border_width;
1257 child_allocation.y = border_width + header_image_allocation.height + 2 * header_padding;
1258 child_allocation.width = sidebar_requisition.width;
1259 child_allocation.height = allocation->height - 2 * border_width -
1260 header_image_allocation.height - 2 * header_padding - action_area_allocation.height;
1262 gtk_widget_size_allocate (priv->sidebar_image, &child_allocation);
1265 child_allocation.x = border_width + content_padding;
1266 child_allocation.y = border_width +
1267 header_image_allocation.height + 2 * header_padding + content_padding;
1268 child_allocation.width = allocation->width - 2 * border_width - 2 * content_padding;
1269 child_allocation.height = allocation->height - 2 * border_width -
1270 header_image_allocation.height - 2 * header_padding - ACTION_AREA_SPACING - action_area_allocation.height - 2 * content_padding;
1272 if (gtk_widget_get_visible (priv->sidebar_image))
1274 GtkAllocation sidebar_image_allocation;
1276 gtk_widget_get_allocation (priv->sidebar_image, &sidebar_image_allocation);
1279 child_allocation.x += sidebar_image_allocation.width;
1281 child_allocation.width -= sidebar_image_allocation.width;
1286 GtkAssistantPage *page = pages->data;
1288 gtk_widget_size_allocate (page->page, &child_allocation);
1289 gtk_widget_size_allocate (page->title, &header_allocation);
1290 pages = pages->next;
1295 gtk_assistant_map (GtkWidget *widget)
1297 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1298 GtkAssistantPrivate *priv = assistant->priv;
1300 GtkAssistantPage *page;
1302 gtk_widget_set_mapped (widget, TRUE);
1304 gtk_widget_map (priv->header_image);
1305 gtk_widget_map (priv->action_area);
1307 if (gtk_widget_get_visible (priv->sidebar_image) &&
1308 !gtk_widget_get_mapped (priv->sidebar_image))
1309 gtk_widget_map (priv->sidebar_image);
1311 /* if there's no default page, pick the first one */
1313 if (!priv->current_page)
1315 page_node = priv->pages;
1317 while (page_node && !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
1318 page_node = page_node->next;
1321 page = page_node->data;
1325 gtk_widget_get_visible (page->page) &&
1326 !gtk_widget_get_mapped (page->page))
1327 set_current_page (assistant, page);
1329 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->map (widget);
1333 gtk_assistant_unmap (GtkWidget *widget)
1335 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1336 GtkAssistantPrivate *priv = assistant->priv;
1338 gtk_widget_set_mapped (widget, FALSE);
1340 gtk_widget_unmap (priv->header_image);
1341 gtk_widget_unmap (priv->action_area);
1343 if (gtk_widget_is_drawable (priv->sidebar_image))
1344 gtk_widget_unmap (priv->sidebar_image);
1346 if (priv->current_page &&
1347 gtk_widget_is_drawable (priv->current_page->page))
1348 gtk_widget_unmap (priv->current_page->page);
1350 g_slist_free (priv->visited_pages);
1351 priv->visited_pages = NULL;
1352 priv->current_page = NULL;
1354 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->unmap (widget);
1358 gtk_assistant_delete_event (GtkWidget *widget,
1361 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1362 GtkAssistantPrivate *priv = assistant->priv;
1364 /* Do not allow cancelling in the middle of a progress page */
1365 if (priv->current_page &&
1366 (priv->current_page->type != GTK_ASSISTANT_PAGE_PROGRESS ||
1367 priv->current_page->complete))
1368 g_signal_emit (widget, signals [CANCEL], 0, NULL);
1374 assistant_paint_colored_box (GtkWidget *widget)
1376 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1377 GtkAssistantPrivate *priv = assistant->priv;
1378 GtkAllocation allocation, action_area_allocation, header_image_allocation;
1380 gint border_width, header_padding, content_padding;
1382 gint content_x, content_width;
1385 cr = gdk_cairo_create (gtk_widget_get_window (widget));
1386 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1387 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1389 gtk_widget_style_get (widget,
1390 "header-padding", &header_padding,
1391 "content-padding", &content_padding,
1394 style = gtk_widget_get_style (widget);
1395 gtk_widget_get_allocation (widget, &allocation);
1396 gtk_widget_get_allocation (priv->action_area, &action_area_allocation);
1397 gtk_widget_get_allocation (priv->header_image, &header_image_allocation);
1400 gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_SELECTED]);
1401 cairo_rectangle (cr,
1404 allocation.width - 2 * border_width,
1405 allocation.height - action_area_allocation.height - 2 * border_width - ACTION_AREA_SPACING);
1409 content_x = content_padding + border_width;
1410 content_width = allocation.width - 2 * content_padding - 2 * border_width;
1412 if (gtk_widget_get_visible (priv->sidebar_image))
1414 GtkAllocation sidebar_image_allocation;
1416 gtk_widget_get_allocation (priv->sidebar_image, &sidebar_image_allocation);
1419 content_x += sidebar_image_allocation.width;
1420 content_width -= sidebar_image_allocation.width;
1423 gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
1425 cairo_rectangle (cr,
1427 header_image_allocation.height + content_padding + 2 * header_padding + border_width,
1429 allocation.height - 2 * border_width - action_area_allocation.height -
1430 header_image_allocation.height - 2 * content_padding - 2 * header_padding - ACTION_AREA_SPACING);
1437 gtk_assistant_expose (GtkWidget *widget,
1438 GdkEventExpose *event)
1440 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1441 GtkAssistantPrivate *priv = assistant->priv;
1442 GtkContainer *container;
1444 if (gtk_widget_is_drawable (widget))
1446 container = GTK_CONTAINER (widget);
1448 assistant_paint_colored_box (widget);
1450 gtk_container_propagate_expose (container, priv->header_image, event);
1451 gtk_container_propagate_expose (container, priv->sidebar_image, event);
1452 gtk_container_propagate_expose (container, priv->action_area, event);
1454 if (priv->current_page)
1456 gtk_container_propagate_expose (container, priv->current_page->page, event);
1457 gtk_container_propagate_expose (container, priv->current_page->title, event);
1465 gtk_assistant_focus (GtkWidget *widget,
1466 GtkDirectionType direction)
1468 GtkAssistantPrivate *priv;
1469 GtkContainer *container;
1471 container = GTK_CONTAINER (widget);
1472 priv = GTK_ASSISTANT (widget)->priv;
1474 /* we only have to care about 2 widgets, action area and the current page */
1475 if (gtk_container_get_focus_child (container) == priv->action_area)
1477 if (!gtk_widget_child_focus (priv->action_area, direction) &&
1478 (priv->current_page == NULL ||
1479 !gtk_widget_child_focus (priv->current_page->page, direction)))
1481 /* if we're leaving the action area and the current page hasn't
1482 any focusable widget, clear focus and go back to the action area */
1483 gtk_container_set_focus_child (GTK_CONTAINER (priv->action_area), NULL);
1484 gtk_widget_child_focus (priv->action_area, direction);
1489 if ((priv->current_page == NULL ||
1490 !gtk_widget_child_focus (priv->current_page->page, direction)) &&
1491 !gtk_widget_child_focus (priv->action_area, direction))
1493 /* if we're leaving the current page and there isn't nothing focusable
1494 in the action area, try to clear focus and go back to the page */
1495 gtk_window_set_focus (GTK_WINDOW (widget), NULL);
1496 if (priv->current_page != NULL)
1497 gtk_widget_child_focus (priv->current_page->page, direction);
1505 gtk_assistant_add (GtkContainer *container,
1508 gtk_assistant_append_page (GTK_ASSISTANT (container), page);
1512 gtk_assistant_remove (GtkContainer *container,
1515 GtkAssistant *assistant = (GtkAssistant*) container;
1518 element = find_page (assistant, page);
1522 remove_page (assistant, element);
1523 gtk_widget_queue_resize ((GtkWidget *) container);
1528 gtk_assistant_forall (GtkContainer *container,
1529 gboolean include_internals,
1530 GtkCallback callback,
1531 gpointer callback_data)
1533 GtkAssistant *assistant = (GtkAssistant*) container;
1534 GtkAssistantPrivate *priv = assistant->priv;
1537 if (include_internals)
1539 (*callback) (priv->header_image, callback_data);
1540 (*callback) (priv->sidebar_image, callback_data);
1541 (*callback) (priv->action_area, callback_data);
1544 pages = priv->pages;
1548 GtkAssistantPage *page = (GtkAssistantPage *) pages->data;
1550 (*callback) (page->page, callback_data);
1552 if (include_internals)
1553 (*callback) (page->title, callback_data);
1555 pages = pages->next;
1560 * gtk_assistant_new:
1562 * Creates a new #GtkAssistant.
1564 * Return value: a newly created #GtkAssistant
1569 gtk_assistant_new (void)
1571 GtkWidget *assistant;
1573 assistant = g_object_new (GTK_TYPE_ASSISTANT, NULL);
1579 * gtk_assistant_get_current_page:
1580 * @assistant: a #GtkAssistant
1582 * Returns the page number of the current page
1584 * Return value: The index (starting from 0) of the current page in
1585 * the @assistant, if the @assistant has no pages, -1 will be returned
1590 gtk_assistant_get_current_page (GtkAssistant *assistant)
1592 GtkAssistantPrivate *priv;
1594 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), -1);
1596 priv = assistant->priv;
1598 if (!priv->pages || !priv->current_page)
1601 return g_list_index (priv->pages, priv->current_page);
1605 * gtk_assistant_set_current_page:
1606 * @assistant: a #GtkAssistant
1607 * @page_num: index of the page to switch to, starting from 0.
1608 * If negative, the last page will be used. If greater
1609 * than the number of pages in the @assistant, nothing
1612 * Switches the page to @page_num. Note that this will only be necessary
1613 * in custom buttons, as the @assistant flow can be set with
1614 * gtk_assistant_set_forward_page_func().
1619 gtk_assistant_set_current_page (GtkAssistant *assistant,
1622 GtkAssistantPrivate *priv;
1623 GtkAssistantPage *page;
1625 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1627 priv = assistant->priv;
1630 page = (GtkAssistantPage *) g_list_nth_data (priv->pages, page_num);
1632 page = (GtkAssistantPage *) g_list_last (priv->pages)->data;
1634 g_return_if_fail (page != NULL);
1636 if (priv->current_page == page)
1639 /* only add the page to the visited list if the
1640 * assistant is mapped, if not, just use it as an
1641 * initial page setting, for the cases where the
1642 * initial page is != to 0
1644 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1645 priv->visited_pages = g_slist_prepend (priv->visited_pages,
1646 priv->current_page);
1648 set_current_page (assistant, page);
1652 * gtk_assistant_get_n_pages:
1653 * @assistant: a #GtkAssistant
1655 * Returns the number of pages in the @assistant
1657 * Return value: The number of pages in the @assistant.
1662 gtk_assistant_get_n_pages (GtkAssistant *assistant)
1664 GtkAssistantPrivate *priv;
1666 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1668 priv = assistant->priv;
1670 return g_list_length (priv->pages);
1674 * gtk_assistant_get_nth_page:
1675 * @assistant: a #GtkAssistant
1676 * @page_num: The index of a page in the @assistant, or -1 to get the last page;
1678 * Returns the child widget contained in page number @page_num.
1680 * Return value: The child widget, or %NULL if @page_num is out of bounds.
1685 gtk_assistant_get_nth_page (GtkAssistant *assistant,
1688 GtkAssistantPrivate *priv;
1689 GtkAssistantPage *page;
1692 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1693 g_return_val_if_fail (page_num >= -1, NULL);
1695 priv = assistant->priv;
1698 elem = g_list_last (priv->pages);
1700 elem = g_list_nth (priv->pages, page_num);
1705 page = (GtkAssistantPage *) elem->data;
1711 * gtk_assistant_prepend_page:
1712 * @assistant: a #GtkAssistant
1713 * @page: a #GtkWidget
1715 * Prepends a page to the @assistant.
1717 * Return value: the index (starting at 0) of the inserted page
1722 gtk_assistant_prepend_page (GtkAssistant *assistant,
1725 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1726 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1728 return gtk_assistant_insert_page (assistant, page, 0);
1732 * gtk_assistant_append_page:
1733 * @assistant: a #GtkAssistant
1734 * @page: a #GtkWidget
1736 * Appends a page to the @assistant.
1738 * Return value: the index (starting at 0) of the inserted page
1743 gtk_assistant_append_page (GtkAssistant *assistant,
1746 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1747 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1749 return gtk_assistant_insert_page (assistant, page, -1);
1753 * gtk_assistant_insert_page:
1754 * @assistant: a #GtkAssistant
1755 * @page: a #GtkWidget
1756 * @position: the index (starting at 0) at which to insert the page,
1757 * or -1 to append the page to the @assistant
1759 * Inserts a page in the @assistant at a given position.
1761 * Return value: the index (starting from 0) of the inserted page
1766 gtk_assistant_insert_page (GtkAssistant *assistant,
1770 GtkAssistantPrivate *priv;
1771 GtkAssistantPage *page_info;
1774 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1775 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1776 g_return_val_if_fail (gtk_widget_get_parent (page) == NULL, 0);
1777 g_return_val_if_fail (!gtk_widget_is_toplevel (page), 0);
1779 priv = assistant->priv;
1781 page_info = g_slice_new0 (GtkAssistantPage);
1782 page_info->page = page;
1783 page_info->title = gtk_label_new (NULL);
1785 g_signal_connect (G_OBJECT (page), "notify::visible",
1786 G_CALLBACK (on_page_notify_visibility), assistant);
1788 gtk_misc_set_alignment (GTK_MISC (page_info->title), 0.,0.5);
1789 set_title_colors (GTK_WIDGET (assistant), page_info->title);
1790 set_title_font (GTK_WIDGET (assistant), page_info->title);
1791 gtk_widget_show (page_info->title);
1793 n_pages = g_list_length (priv->pages);
1795 if (position < 0 || position > n_pages)
1798 priv->pages = g_list_insert (priv->pages, page_info, position);
1800 gtk_widget_set_child_visible (page_info->page, FALSE);
1801 gtk_widget_set_parent (page_info->page, GTK_WIDGET (assistant));
1802 gtk_widget_set_parent (page_info->title, GTK_WIDGET (assistant));
1804 if (gtk_widget_get_realized (GTK_WIDGET (assistant)))
1806 gtk_widget_realize (page_info->page);
1807 gtk_widget_realize (page_info->title);
1810 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1816 * gtk_assistant_set_forward_page_func:
1817 * @assistant: a #GtkAssistant
1818 * @page_func: (allow-none): the #GtkAssistantPageFunc, or %NULL to use the default one
1819 * @data: user data for @page_func
1820 * @destroy: destroy notifier for @data
1822 * Sets the page forwarding function to be @page_func, this function will
1823 * be used to determine what will be the next page when the user presses
1824 * the forward button. Setting @page_func to %NULL will make the assistant
1825 * to use the default forward function, which just goes to the next visible
1831 gtk_assistant_set_forward_page_func (GtkAssistant *assistant,
1832 GtkAssistantPageFunc page_func,
1834 GDestroyNotify destroy)
1836 GtkAssistantPrivate *priv;
1838 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1840 priv = assistant->priv;
1842 if (priv->forward_data_destroy &&
1843 priv->forward_function_data)
1844 (*priv->forward_data_destroy) (priv->forward_function_data);
1848 priv->forward_function = page_func;
1849 priv->forward_function_data = data;
1850 priv->forward_data_destroy = destroy;
1854 priv->forward_function = default_forward_function;
1855 priv->forward_function_data = assistant;
1856 priv->forward_data_destroy = NULL;
1859 /* Page flow has possibly changed, so the
1860 buttons state might need to change too */
1861 set_assistant_buttons_state (assistant);
1865 * gtk_assistant_add_action_widget:
1866 * @assistant: a #GtkAssistant
1867 * @child: a #GtkWidget
1869 * Adds a widget to the action area of a #GtkAssistant.
1874 gtk_assistant_add_action_widget (GtkAssistant *assistant,
1877 GtkAssistantPrivate *priv;
1879 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1880 g_return_if_fail (GTK_IS_WIDGET (child));
1882 priv = assistant->priv;
1884 if (GTK_IS_BUTTON (child))
1885 gtk_size_group_add_widget (priv->size_group, child);
1887 gtk_box_pack_end (GTK_BOX (priv->action_area), child, FALSE, FALSE, 0);
1891 * gtk_assistant_remove_action_widget:
1892 * @assistant: a #GtkAssistant
1893 * @child: a #GtkWidget
1895 * Removes a widget from the action area of a #GtkAssistant.
1900 gtk_assistant_remove_action_widget (GtkAssistant *assistant,
1903 GtkAssistantPrivate *priv;
1905 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1906 g_return_if_fail (GTK_IS_WIDGET (child));
1908 priv = assistant->priv;
1910 if (GTK_IS_BUTTON (child))
1911 gtk_size_group_remove_widget (priv->size_group, child);
1913 gtk_container_remove (GTK_CONTAINER (priv->action_area), child);
1917 * gtk_assistant_set_page_title:
1918 * @assistant: a #GtkAssistant
1919 * @page: a page of @assistant
1920 * @title: the new title for @page
1922 * Sets a title for @page. The title is displayed in the header
1923 * area of the assistant when @page is the current page.
1928 gtk_assistant_set_page_title (GtkAssistant *assistant,
1932 GtkAssistantPage *page_info;
1935 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1936 g_return_if_fail (GTK_IS_WIDGET (page));
1938 child = find_page (assistant, page);
1940 g_return_if_fail (child != NULL);
1942 page_info = (GtkAssistantPage*) child->data;
1944 gtk_label_set_text ((GtkLabel*) page_info->title, title);
1945 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1946 gtk_widget_child_notify (page, "title");
1950 * gtk_assistant_get_page_title:
1951 * @assistant: a #GtkAssistant
1952 * @page: a page of @assistant
1954 * Gets the title for @page.
1956 * Return value: the title for @page.
1960 G_CONST_RETURN gchar*
1961 gtk_assistant_get_page_title (GtkAssistant *assistant,
1964 GtkAssistantPage *page_info;
1967 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1968 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1970 child = find_page (assistant, page);
1972 g_return_val_if_fail (child != NULL, NULL);
1974 page_info = (GtkAssistantPage*) child->data;
1976 return gtk_label_get_text ((GtkLabel*) page_info->title);
1980 * gtk_assistant_set_page_type:
1981 * @assistant: a #GtkAssistant
1982 * @page: a page of @assistant
1983 * @type: the new type for @page
1985 * Sets the page type for @page. The page type determines the page
1986 * behavior in the @assistant.
1991 gtk_assistant_set_page_type (GtkAssistant *assistant,
1993 GtkAssistantPageType type)
1995 GtkAssistantPrivate *priv;
1996 GtkAssistantPage *page_info;
1999 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2000 g_return_if_fail (GTK_IS_WIDGET (page));
2002 priv = assistant->priv;
2003 child = find_page (assistant, page);
2005 g_return_if_fail (child != NULL);
2007 page_info = (GtkAssistantPage*) child->data;
2009 if (type != page_info->type)
2011 page_info->type = type;
2013 /* backwards compatibility to the era before fixing bug 604289 */
2014 if (type == GTK_ASSISTANT_PAGE_SUMMARY && !page_info->complete_set)
2016 gtk_assistant_set_page_complete (assistant, page, TRUE);
2017 page_info->complete_set = FALSE;
2020 /* Always set buttons state, a change in a future page
2021 might change current page buttons */
2022 set_assistant_buttons_state (assistant);
2024 gtk_widget_child_notify (page, "page-type");
2029 * gtk_assistant_get_page_type:
2030 * @assistant: a #GtkAssistant
2031 * @page: a page of @assistant
2033 * Gets the page type of @page.
2035 * Return value: the page type of @page.
2039 GtkAssistantPageType
2040 gtk_assistant_get_page_type (GtkAssistant *assistant,
2043 GtkAssistantPage *page_info;
2046 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), GTK_ASSISTANT_PAGE_CONTENT);
2047 g_return_val_if_fail (GTK_IS_WIDGET (page), GTK_ASSISTANT_PAGE_CONTENT);
2049 child = find_page (assistant, page);
2051 g_return_val_if_fail (child != NULL, GTK_ASSISTANT_PAGE_CONTENT);
2053 page_info = (GtkAssistantPage*) child->data;
2055 return page_info->type;
2059 * gtk_assistant_set_page_header_image:
2060 * @assistant: a #GtkAssistant
2061 * @page: a page of @assistant
2062 * @pixbuf: (allow-none): the new header image @page
2064 * Sets a header image for @page. This image is displayed in the header
2065 * area of the assistant when @page is the current page.
2070 gtk_assistant_set_page_header_image (GtkAssistant *assistant,
2074 GtkAssistantPrivate *priv;
2075 GtkAssistantPage *page_info;
2078 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2079 g_return_if_fail (GTK_IS_WIDGET (page));
2080 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2082 priv = assistant->priv;
2083 child = find_page (assistant, page);
2085 g_return_if_fail (child != NULL);
2087 page_info = (GtkAssistantPage*) child->data;
2089 if (pixbuf != page_info->header_image)
2091 if (page_info->header_image)
2093 g_object_unref (page_info->header_image);
2094 page_info->header_image = NULL;
2098 page_info->header_image = g_object_ref (pixbuf);
2100 if (page_info == priv->current_page)
2101 set_assistant_header_image (assistant);
2103 gtk_widget_child_notify (page, "header-image");
2108 * gtk_assistant_get_page_header_image:
2109 * @assistant: a #GtkAssistant
2110 * @page: a page of @assistant
2112 * Gets the header image for @page.
2114 * Return value: the header image for @page, or %NULL
2115 * if there's no header image for the page.
2120 gtk_assistant_get_page_header_image (GtkAssistant *assistant,
2123 GtkAssistantPage *page_info;
2126 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2127 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2129 child = find_page (assistant, page);
2131 g_return_val_if_fail (child != NULL, NULL);
2133 page_info = (GtkAssistantPage*) child->data;
2135 return page_info->header_image;
2139 * gtk_assistant_set_page_side_image:
2140 * @assistant: a #GtkAssistant
2141 * @page: a page of @assistant
2142 * @pixbuf: (allow-none): the new header image @page
2144 * Sets a header image for @page. This image is displayed in the side
2145 * area of the assistant when @page is the current page.
2150 gtk_assistant_set_page_side_image (GtkAssistant *assistant,
2154 GtkAssistantPrivate *priv;
2155 GtkAssistantPage *page_info;
2158 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2159 g_return_if_fail (GTK_IS_WIDGET (page));
2160 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2162 priv = assistant->priv;
2163 child = find_page (assistant, page);
2165 g_return_if_fail (child != NULL);
2167 page_info = (GtkAssistantPage*) child->data;
2169 if (pixbuf != page_info->sidebar_image)
2171 if (page_info->sidebar_image)
2173 g_object_unref (page_info->sidebar_image);
2174 page_info->sidebar_image = NULL;
2178 page_info->sidebar_image = g_object_ref (pixbuf);
2180 if (page_info == priv->current_page)
2181 set_assistant_sidebar_image (assistant);
2183 gtk_widget_child_notify (page, "sidebar-image");
2188 * gtk_assistant_get_page_side_image:
2189 * @assistant: a #GtkAssistant
2190 * @page: a page of @assistant
2192 * Gets the header image for @page.
2194 * Return value: the side image for @page, or %NULL
2195 * if there's no side image for the page.
2200 gtk_assistant_get_page_side_image (GtkAssistant *assistant,
2203 GtkAssistantPage *page_info;
2206 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2207 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2209 child = find_page (assistant, page);
2211 g_return_val_if_fail (child != NULL, NULL);
2213 page_info = (GtkAssistantPage*) child->data;
2215 return page_info->sidebar_image;
2219 * gtk_assistant_set_page_complete:
2220 * @assistant: a #GtkAssistant
2221 * @page: a page of @assistant
2222 * @complete: the completeness status of the page
2224 * Sets whether @page contents are complete. This will make
2225 * @assistant update the buttons state to be able to continue the task.
2230 gtk_assistant_set_page_complete (GtkAssistant *assistant,
2234 GtkAssistantPrivate *priv;
2235 GtkAssistantPage *page_info;
2238 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2239 g_return_if_fail (GTK_IS_WIDGET (page));
2241 priv = assistant->priv;
2242 child = find_page (assistant, page);
2244 g_return_if_fail (child != NULL);
2246 page_info = (GtkAssistantPage*) child->data;
2248 if (complete != page_info->complete)
2250 page_info->complete = complete;
2251 page_info->complete_set = TRUE;
2253 /* Always set buttons state, a change in a future page
2254 might change current page buttons */
2255 set_assistant_buttons_state (assistant);
2257 gtk_widget_child_notify (page, "complete");
2262 * gtk_assistant_get_page_complete:
2263 * @assistant: a #GtkAssistant
2264 * @page: a page of @assistant
2266 * Gets whether @page is complete.
2268 * Return value: %TRUE if @page is complete.
2273 gtk_assistant_get_page_complete (GtkAssistant *assistant,
2276 GtkAssistantPage *page_info;
2279 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), FALSE);
2280 g_return_val_if_fail (GTK_IS_WIDGET (page), FALSE);
2282 child = find_page (assistant, page);
2284 g_return_val_if_fail (child != NULL, FALSE);
2286 page_info = (GtkAssistantPage*) child->data;
2288 return page_info->complete;
2292 * gtk_assistant_update_buttons_state:
2293 * @assistant: a #GtkAssistant
2295 * Forces @assistant to recompute the buttons state.
2297 * GTK+ automatically takes care of this in most situations,
2298 * e.g. when the user goes to a different page, or when the
2299 * visibility or completeness of a page changes.
2301 * One situation where it can be necessary to call this
2302 * function is when changing a value on the current page
2303 * affects the future page flow of the assistant.
2308 gtk_assistant_update_buttons_state (GtkAssistant *assistant)
2310 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2312 set_assistant_buttons_state (assistant);
2316 * gtk_assistant_commit:
2317 * @assistant: a #GtkAssistant
2319 * Erases the visited page history so the back button is not
2320 * shown on the current page, and removes the cancel button
2321 * from subsequent pages.
2323 * Use this when the information provided up to the current
2324 * page is hereafter deemed permanent and cannot be modified
2325 * or undone. For example, showing a progress page to track
2326 * a long-running, unreversible operation after the user has
2327 * clicked apply on a confirmation page.
2332 gtk_assistant_commit (GtkAssistant *assistant)
2334 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2336 g_slist_free (assistant->priv->visited_pages);
2337 assistant->priv->visited_pages = NULL;
2339 assistant->priv->committed = TRUE;
2341 set_assistant_buttons_state (assistant);
2346 /* accessible implementation */
2349 gtk_assistant_accessible_get_n_children (AtkObject *accessible)
2351 GtkAssistant *assistant;
2354 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2359 assistant = GTK_ASSISTANT (widget);
2361 return g_list_length (assistant->priv->pages) + 1;
2366 gtk_assistant_accessible_ref_child (AtkObject *accessible,
2369 GtkAssistant *assistant;
2370 GtkAssistantPrivate *priv;
2371 GtkWidget *widget, *child;
2376 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
2380 assistant = GTK_ASSISTANT (widget);
2381 priv = assistant->priv;
2382 n_pages = g_list_length (priv->pages);
2386 else if (index < n_pages)
2388 GtkAssistantPage *page = g_list_nth_data (priv->pages, index);
2391 title = gtk_assistant_get_page_title (assistant, child);
2393 else if (index == n_pages)
2395 child = priv->action_area;
2401 obj = gtk_widget_get_accessible (child);
2404 atk_object_set_name (obj, title);
2406 return g_object_ref (obj);
2410 gtk_assistant_accessible_class_init (AtkObjectClass *class)
2412 class->get_n_children = gtk_assistant_accessible_get_n_children;
2413 class->ref_child = gtk_assistant_accessible_ref_child;
2417 gtk_assistant_accessible_get_type (void)
2419 static GType type = 0;
2424 * Figure out the size of the class and instance
2425 * we are deriving from
2427 AtkObjectFactory *factory;
2430 GType derived_atk_type;
2432 derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
2433 factory = atk_registry_get_factory (atk_get_default_registry (),
2435 derived_atk_type = atk_object_factory_get_accessible_type (factory);
2436 g_type_query (derived_atk_type, &query);
2438 type = g_type_register_static_simple (derived_atk_type,
2439 I_("GtkAssistantAccessible"),
2441 (GClassInitFunc) gtk_assistant_accessible_class_init,
2442 query.instance_size,
2450 gtk_assistant_accessible_new (GObject *obj)
2452 AtkObject *accessible;
2454 g_return_val_if_fail (GTK_IS_ASSISTANT (obj), NULL);
2456 accessible = g_object_new (gtk_assistant_accessible_get_type (), NULL);
2457 atk_object_initialize (accessible, obj);
2463 gtk_assistant_accessible_factory_get_accessible_type (void)
2465 return gtk_assistant_accessible_get_type ();
2469 gtk_assistant_accessible_factory_create_accessible (GObject *obj)
2471 return gtk_assistant_accessible_new (obj);
2475 gtk_assistant_accessible_factory_class_init (AtkObjectFactoryClass *class)
2477 class->create_accessible = gtk_assistant_accessible_factory_create_accessible;
2478 class->get_accessible_type = gtk_assistant_accessible_factory_get_accessible_type;
2482 gtk_assistant_accessible_factory_get_type (void)
2484 static GType type = 0;
2488 type = g_type_register_static_simple (ATK_TYPE_OBJECT_FACTORY,
2489 I_("GtkAssistantAccessibleFactory"),
2490 sizeof (AtkObjectFactoryClass),
2491 (GClassInitFunc) gtk_assistant_accessible_factory_class_init,
2492 sizeof (AtkObjectFactory),
2500 gtk_assistant_get_accessible (GtkWidget *widget)
2502 static gboolean first_time = TRUE;
2506 AtkObjectFactory *factory;
2507 AtkRegistry *registry;
2509 GType derived_atk_type;
2512 * Figure out whether accessibility is enabled by looking at the
2513 * type of the accessible object which would be created for
2514 * the parent type of GtkAssistant.
2516 derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
2518 registry = atk_get_default_registry ();
2519 factory = atk_registry_get_factory (registry,
2521 derived_atk_type = atk_object_factory_get_accessible_type (factory);
2522 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
2524 atk_registry_set_factory_type (registry,
2526 gtk_assistant_accessible_factory_get_type ());
2531 return GTK_WIDGET_CLASS (gtk_assistant_parent_class)->get_accessible (widget);
2535 static GtkBuildableIface *parent_buildable_iface;
2538 gtk_assistant_buildable_interface_init (GtkBuildableIface *iface)
2540 parent_buildable_iface = g_type_interface_peek_parent (iface);
2541 iface->get_internal_child = gtk_assistant_buildable_get_internal_child;
2542 iface->custom_tag_start = gtk_assistant_buildable_custom_tag_start;
2543 iface->custom_finished = gtk_assistant_buildable_custom_finished;
2547 gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
2548 GtkBuilder *builder,
2549 const gchar *childname)
2551 if (strcmp (childname, "action_area") == 0)
2552 return G_OBJECT (GTK_ASSISTANT (buildable)->priv->action_area);
2554 return parent_buildable_iface->get_internal_child (buildable,
2560 gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
2561 GtkBuilder *builder,
2563 const gchar *tagname,
2564 GMarkupParser *parser,
2567 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
2568 tagname, parser, data);
2572 gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
2573 GtkBuilder *builder,
2575 const gchar *tagname,
2578 parent_buildable_iface->custom_finished (buildable, builder, child,
2579 tagname, user_data);