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"
69 #define GTK_ASSISTANT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_ASSISTANT, GtkAssistantPrivate))
71 #define HEADER_SPACING 12
72 #define ACTION_AREA_SPACING 12
74 typedef struct _GtkAssistantPage GtkAssistantPage;
76 struct _GtkAssistantPage
79 GtkAssistantPageType type;
81 guint complete_set : 1;
84 GdkPixbuf *header_image;
85 GdkPixbuf *sidebar_image;
88 struct _GtkAssistantPrivate
90 GtkWidget *header_image;
91 GtkWidget *sidebar_image;
93 GtkWidget *action_area;
97 GtkAssistantPage *current_page;
99 GSList *visited_pages;
101 GtkSizeGroup *size_group;
103 GtkAssistantPageFunc forward_function;
104 gpointer forward_function_data;
105 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 to put 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 set_assistant_header_image (GtkAssistant *assistant)
478 GtkAssistantPrivate *priv = assistant->priv;
480 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->header_image),
481 priv->current_page->header_image);
485 set_assistant_sidebar_image (GtkAssistant *assistant)
487 GtkAssistantPrivate *priv = assistant->priv;
489 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->sidebar_image),
490 priv->current_page->sidebar_image);
492 if (priv->current_page->sidebar_image)
493 gtk_widget_show (priv->sidebar_image);
495 gtk_widget_hide (priv->sidebar_image);
499 set_assistant_buttons_state (GtkAssistant *assistant)
501 GtkAssistantPrivate *priv = assistant->priv;
503 if (!priv->current_page)
506 switch (priv->current_page->type)
508 case GTK_ASSISTANT_PAGE_INTRO:
509 gtk_widget_set_sensitive (assistant->cancel, TRUE);
510 gtk_widget_set_sensitive (assistant->forward, priv->current_page->complete);
511 gtk_widget_grab_default (assistant->forward);
512 gtk_widget_show (assistant->cancel);
513 gtk_widget_show (assistant->forward);
514 gtk_widget_hide (assistant->back);
515 gtk_widget_hide (assistant->apply);
516 gtk_widget_hide (assistant->close);
517 compute_last_button_state (assistant);
519 case GTK_ASSISTANT_PAGE_CONFIRM:
520 gtk_widget_set_sensitive (assistant->cancel, TRUE);
521 gtk_widget_set_sensitive (assistant->back, TRUE);
522 gtk_widget_set_sensitive (assistant->apply, priv->current_page->complete);
523 gtk_widget_grab_default (assistant->apply);
524 gtk_widget_show (assistant->cancel);
525 gtk_widget_show (assistant->back);
526 gtk_widget_show (assistant->apply);
527 gtk_widget_hide (assistant->forward);
528 gtk_widget_hide (assistant->close);
529 gtk_widget_hide (assistant->last);
531 case GTK_ASSISTANT_PAGE_CONTENT:
532 gtk_widget_set_sensitive (assistant->cancel, TRUE);
533 gtk_widget_set_sensitive (assistant->back, TRUE);
534 gtk_widget_set_sensitive (assistant->forward, priv->current_page->complete);
535 gtk_widget_grab_default (assistant->forward);
536 gtk_widget_show (assistant->cancel);
537 gtk_widget_show (assistant->back);
538 gtk_widget_show (assistant->forward);
539 gtk_widget_hide (assistant->apply);
540 gtk_widget_hide (assistant->close);
541 compute_last_button_state (assistant);
543 case GTK_ASSISTANT_PAGE_SUMMARY:
544 gtk_widget_set_sensitive (assistant->close, priv->current_page->complete);
545 gtk_widget_grab_default (assistant->close);
546 gtk_widget_show (assistant->close);
547 gtk_widget_hide (assistant->cancel);
548 gtk_widget_hide (assistant->back);
549 gtk_widget_hide (assistant->forward);
550 gtk_widget_hide (assistant->apply);
551 gtk_widget_hide (assistant->last);
553 case GTK_ASSISTANT_PAGE_PROGRESS:
554 gtk_widget_set_sensitive (assistant->cancel, priv->current_page->complete);
555 gtk_widget_set_sensitive (assistant->back, priv->current_page->complete);
556 gtk_widget_set_sensitive (assistant->forward, priv->current_page->complete);
557 gtk_widget_grab_default (assistant->forward);
558 gtk_widget_show (assistant->cancel);
559 gtk_widget_show (assistant->back);
560 gtk_widget_show (assistant->forward);
561 gtk_widget_hide (assistant->apply);
562 gtk_widget_hide (assistant->close);
563 gtk_widget_hide (assistant->last);
566 g_assert_not_reached ();
569 /* this is quite general, we don't want to
570 * go back if it's the first page */
571 if (!priv->visited_pages)
572 gtk_widget_hide (assistant->back);
576 set_current_page (GtkAssistant *assistant,
577 GtkAssistantPage *page)
579 GtkAssistantPrivate *priv = assistant->priv;
580 GtkAssistantPage *old_page;
582 if (priv->current_page &&
583 gtk_widget_is_drawable (priv->current_page->page))
584 old_page = priv->current_page;
588 priv->current_page = page;
590 set_assistant_buttons_state (assistant);
591 set_assistant_header_image (assistant);
592 set_assistant_sidebar_image (assistant);
594 g_signal_emit (assistant, signals [PREPARE], 0, priv->current_page->page);
596 if (gtk_widget_get_visible (priv->current_page->page) && gtk_widget_get_mapped (GTK_WIDGET (assistant)))
598 gtk_widget_set_child_visible (priv->current_page->page, TRUE);
599 gtk_widget_map (priv->current_page->page);
600 gtk_widget_map (priv->current_page->title);
603 if (old_page && gtk_widget_get_mapped (old_page->page))
605 gtk_widget_set_child_visible (old_page->page, FALSE);
606 gtk_widget_unmap (old_page->page);
607 gtk_widget_unmap (old_page->title);
610 if (!gtk_widget_child_focus (priv->current_page->page, GTK_DIR_TAB_FORWARD))
612 GtkWidget *button[6];
615 /* find the best button to focus */
616 button[0] = assistant->apply;
617 button[1] = assistant->close;
618 button[2] = assistant->forward;
619 button[3] = assistant->back;
620 button[4] = assistant->cancel;
621 button[5] = assistant->last;
622 for (i = 0; i < 6; i++)
624 if (gtk_widget_get_visible (button[i]) && gtk_widget_get_sensitive (button[i]))
626 gtk_widget_grab_focus (button[i]);
632 gtk_widget_queue_resize (GTK_WIDGET (assistant));
636 compute_next_step (GtkAssistant *assistant)
638 GtkAssistantPrivate *priv = assistant->priv;
639 GtkAssistantPage *page_info;
640 gint current_page, n_pages, next_page;
642 current_page = gtk_assistant_get_current_page (assistant);
643 page_info = priv->current_page;
644 n_pages = gtk_assistant_get_n_pages (assistant);
646 next_page = (priv->forward_function) (current_page,
647 priv->forward_function_data);
649 if (next_page >= 0 && next_page < n_pages)
651 priv->visited_pages = g_slist_prepend (priv->visited_pages, page_info);
652 set_current_page (assistant, g_list_nth_data (priv->pages, next_page));
661 on_assistant_close (GtkWidget *widget,
662 GtkAssistant *assistant)
664 g_signal_emit (assistant, signals [CLOSE], 0, NULL);
668 on_assistant_apply (GtkWidget *widget,
669 GtkAssistant *assistant)
673 g_signal_emit (assistant, signals [APPLY], 0);
675 success = compute_next_step (assistant);
677 /* if the assistant hasn't switched to another page, just emit
678 * the CLOSE signal, it't the last page in the assistant flow
681 g_signal_emit (assistant, signals [CLOSE], 0);
685 on_assistant_forward (GtkWidget *widget,
686 GtkAssistant *assistant)
688 if (!compute_next_step (assistant))
689 g_critical ("Page flow is broken, you may want to end it with a page of "
690 "type GTK_ASSISTANT_PAGE_CONFIRM or GTK_ASSISTANT_PAGE_SUMMARY");
694 on_assistant_back (GtkWidget *widget,
695 GtkAssistant *assistant)
697 GtkAssistantPrivate *priv = assistant->priv;
698 GtkAssistantPage *page_info;
701 /* skip the progress pages when going back */
704 page_node = priv->visited_pages;
706 g_return_if_fail (page_node != NULL);
708 priv->visited_pages = priv->visited_pages->next;
709 page_info = (GtkAssistantPage *) page_node->data;
710 g_slist_free_1 (page_node);
712 while (page_info->type == GTK_ASSISTANT_PAGE_PROGRESS ||
713 !gtk_widget_get_visible (page_info->page));
715 set_current_page (assistant, page_info);
719 on_assistant_cancel (GtkWidget *widget,
720 GtkAssistant *assistant)
722 g_signal_emit (assistant, signals [CANCEL], 0, NULL);
726 on_assistant_last (GtkWidget *widget,
727 GtkAssistant *assistant)
729 GtkAssistantPrivate *priv = assistant->priv;
731 while (priv->current_page->type == GTK_ASSISTANT_PAGE_CONTENT &&
732 priv->current_page->complete)
733 compute_next_step (assistant);
737 alternative_button_order (GtkAssistant *assistant)
739 GtkSettings *settings;
743 screen = gtk_widget_get_screen (GTK_WIDGET (assistant));
744 settings = gtk_settings_get_for_screen (screen);
746 g_object_get (settings,
747 "gtk-alternative-button-order", &result,
753 gtk_assistant_init (GtkAssistant *assistant)
755 GtkAssistantPrivate *priv;
757 priv = assistant->priv = GTK_ASSISTANT_GET_PRIVATE (assistant);
759 gtk_container_set_reallocate_redraws (GTK_CONTAINER (assistant), TRUE);
760 gtk_container_set_border_width (GTK_CONTAINER (assistant), 12);
762 gtk_widget_push_composite_child ();
765 priv->header_image = gtk_image_new ();
766 gtk_misc_set_alignment (GTK_MISC (priv->header_image), 1., 0.5);
767 gtk_widget_set_parent (priv->header_image, GTK_WIDGET (assistant));
768 gtk_widget_show (priv->header_image);
771 priv->sidebar_image = gtk_image_new ();
772 gtk_misc_set_alignment (GTK_MISC (priv->sidebar_image), 0., 0.);
773 gtk_widget_set_parent (priv->sidebar_image, GTK_WIDGET (assistant));
774 gtk_widget_show (priv->sidebar_image);
777 priv->action_area = gtk_hbox_new (FALSE, 6);
779 assistant->close = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
780 assistant->apply = gtk_button_new_from_stock (GTK_STOCK_APPLY);
781 assistant->forward = gtk_button_new_from_stock (GTK_STOCK_GO_FORWARD);
782 assistant->back = gtk_button_new_from_stock (GTK_STOCK_GO_BACK);
783 assistant->cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
784 assistant->last = gtk_button_new_from_stock (GTK_STOCK_GOTO_LAST);
785 gtk_widget_set_can_default (assistant->close, TRUE);
786 gtk_widget_set_can_default (assistant->apply, TRUE);
787 gtk_widget_set_can_default (assistant->forward, TRUE);
789 priv->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
790 gtk_size_group_add_widget (priv->size_group, assistant->close);
791 gtk_size_group_add_widget (priv->size_group, assistant->apply);
792 gtk_size_group_add_widget (priv->size_group, assistant->forward);
793 gtk_size_group_add_widget (priv->size_group, assistant->back);
794 gtk_size_group_add_widget (priv->size_group, assistant->cancel);
795 gtk_size_group_add_widget (priv->size_group, assistant->last);
797 if (!alternative_button_order (assistant))
799 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->apply, FALSE, FALSE, 0);
800 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->forward, FALSE, FALSE, 0);
801 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->back, FALSE, FALSE, 0);
802 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->last, FALSE, FALSE, 0);
803 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->cancel, FALSE, FALSE, 0);
804 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->close, FALSE, FALSE, 0);
808 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->close, FALSE, FALSE, 0);
809 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->cancel, FALSE, FALSE, 0);
810 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->apply, FALSE, FALSE, 0);
811 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->forward, FALSE, FALSE, 0);
812 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->back, FALSE, FALSE, 0);
813 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->last, FALSE, FALSE, 0);
816 gtk_widget_set_parent (priv->action_area, GTK_WIDGET (assistant));
817 gtk_widget_show (assistant->forward);
818 gtk_widget_show (assistant->back);
819 gtk_widget_show (assistant->cancel);
820 gtk_widget_show (priv->action_area);
822 gtk_widget_pop_composite_child ();
825 priv->current_page = NULL;
826 priv->visited_pages = NULL;
828 priv->forward_function = default_forward_function;
829 priv->forward_function_data = assistant;
830 priv->forward_data_destroy = NULL;
832 g_signal_connect (G_OBJECT (assistant->close), "clicked",
833 G_CALLBACK (on_assistant_close), assistant);
834 g_signal_connect (G_OBJECT (assistant->apply), "clicked",
835 G_CALLBACK (on_assistant_apply), assistant);
836 g_signal_connect (G_OBJECT (assistant->forward), "clicked",
837 G_CALLBACK (on_assistant_forward), assistant);
838 g_signal_connect (G_OBJECT (assistant->back), "clicked",
839 G_CALLBACK (on_assistant_back), assistant);
840 g_signal_connect (G_OBJECT (assistant->cancel), "clicked",
841 G_CALLBACK (on_assistant_cancel), assistant);
842 g_signal_connect (G_OBJECT (assistant->last), "clicked",
843 G_CALLBACK (on_assistant_last), assistant);
847 gtk_assistant_set_child_property (GtkContainer *container,
855 case CHILD_PROP_PAGE_TYPE:
856 gtk_assistant_set_page_type (GTK_ASSISTANT (container), child,
857 g_value_get_enum (value));
859 case CHILD_PROP_PAGE_TITLE:
860 gtk_assistant_set_page_title (GTK_ASSISTANT (container), child,
861 g_value_get_string (value));
863 case CHILD_PROP_PAGE_HEADER_IMAGE:
864 gtk_assistant_set_page_header_image (GTK_ASSISTANT (container), child,
865 g_value_get_object (value));
867 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
868 gtk_assistant_set_page_side_image (GTK_ASSISTANT (container), child,
869 g_value_get_object (value));
871 case CHILD_PROP_PAGE_COMPLETE:
872 gtk_assistant_set_page_complete (GTK_ASSISTANT (container), child,
873 g_value_get_boolean (value));
876 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
882 gtk_assistant_get_child_property (GtkContainer *container,
890 case CHILD_PROP_PAGE_TYPE:
891 g_value_set_enum (value,
892 gtk_assistant_get_page_type (GTK_ASSISTANT (container), child));
894 case CHILD_PROP_PAGE_TITLE:
895 g_value_set_string (value,
896 gtk_assistant_get_page_title (GTK_ASSISTANT (container), child));
898 case CHILD_PROP_PAGE_HEADER_IMAGE:
899 g_value_set_object (value,
900 gtk_assistant_get_page_header_image (GTK_ASSISTANT (container), child));
902 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
903 g_value_set_object (value,
904 gtk_assistant_get_page_side_image (GTK_ASSISTANT (container), child));
906 case CHILD_PROP_PAGE_COMPLETE:
907 g_value_set_boolean (value,
908 gtk_assistant_get_page_complete (GTK_ASSISTANT (container), child));
911 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
917 on_page_notify_visibility (GtkWidget *widget,
921 GtkAssistant *assistant = GTK_ASSISTANT (data);
923 /* update buttons state, flow may have changed */
924 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
925 set_assistant_buttons_state (assistant);
929 remove_page (GtkAssistant *assistant,
932 GtkAssistantPrivate *priv = assistant->priv;
933 GtkAssistantPage *page_info;
936 page_info = element->data;
938 /* If this is the current page, we need to switch away. */
939 if (page_info == priv->current_page)
941 if (!compute_next_step (assistant))
943 /* The best we can do at this point is probably to pick the first
946 page_node = priv->pages;
948 while (page_node && !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
949 page_node = page_node->next;
951 if (page_node == element)
952 page_node = page_node->next;
955 priv->current_page = page_node->data;
957 priv->current_page = NULL;
961 priv->pages = g_list_remove_link (priv->pages, element);
962 priv->visited_pages = g_slist_remove_all (priv->visited_pages, page_info);
964 g_signal_handlers_disconnect_by_func (page_info->page, on_page_notify_visibility, assistant);
965 gtk_widget_unparent (page_info->page);
967 if (page_info->header_image)
968 g_object_unref (page_info->header_image);
970 if (page_info->sidebar_image)
971 g_object_unref (page_info->sidebar_image);
973 gtk_widget_destroy (page_info->title);
974 g_slice_free (GtkAssistantPage, page_info);
975 g_list_free_1 (element);
979 gtk_assistant_destroy (GtkObject *object)
981 GtkAssistant *assistant = GTK_ASSISTANT (object);
982 GtkAssistantPrivate *priv = assistant->priv;
984 if (priv->header_image)
986 gtk_widget_destroy (priv->header_image);
987 priv->header_image = NULL;
990 if (priv->sidebar_image)
992 gtk_widget_destroy (priv->sidebar_image);
993 priv->sidebar_image = NULL;
996 if (priv->action_area)
998 gtk_widget_destroy (priv->action_area);
999 priv->action_area = NULL;
1002 if (priv->size_group)
1004 g_object_unref (priv->size_group);
1005 priv->size_group = NULL;
1008 if (priv->forward_function)
1010 if (priv->forward_function_data &&
1011 priv->forward_data_destroy)
1012 priv->forward_data_destroy (priv->forward_function_data);
1014 priv->forward_function = NULL;
1015 priv->forward_function_data = NULL;
1016 priv->forward_data_destroy = NULL;
1019 if (priv->visited_pages)
1021 g_slist_free (priv->visited_pages);
1022 priv->visited_pages = NULL;
1025 /* We set current to NULL so that the remove code doesn't try
1026 * to do anything funny */
1027 priv->current_page = NULL;
1030 remove_page (GTK_ASSISTANT (object), priv->pages);
1032 GTK_OBJECT_CLASS (gtk_assistant_parent_class)->destroy (object);
1036 find_page (GtkAssistant *assistant,
1039 GtkAssistantPrivate *priv = assistant->priv;
1040 GList *child = priv->pages;
1044 GtkAssistantPage *page_info = child->data;
1045 if (page_info->page == page)
1048 child = child->next;
1055 set_title_colors (GtkWidget *assistant,
1056 GtkWidget *title_label)
1060 gtk_widget_ensure_style (assistant);
1061 style = gtk_widget_get_style (assistant);
1063 /* change colors schema, for making the header text visible */
1064 gtk_widget_modify_bg (title_label, GTK_STATE_NORMAL, &style->bg[GTK_STATE_SELECTED]);
1065 gtk_widget_modify_fg (title_label, GTK_STATE_NORMAL, &style->fg[GTK_STATE_SELECTED]);
1069 set_title_font (GtkWidget *assistant,
1070 GtkWidget *title_label)
1072 PangoFontDescription *desc;
1075 desc = pango_font_description_new ();
1076 size = pango_font_description_get_size (assistant->style->font_desc);
1078 pango_font_description_set_weight (desc, PANGO_WEIGHT_ULTRABOLD);
1079 pango_font_description_set_size (desc, size * PANGO_SCALE_XX_LARGE);
1081 gtk_widget_modify_font (title_label, desc);
1082 pango_font_description_free (desc);
1086 gtk_assistant_style_set (GtkWidget *widget,
1087 GtkStyle *old_style)
1089 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1090 GtkAssistantPrivate *priv = assistant->priv;
1097 GtkAssistantPage *page = list->data;
1099 set_title_colors (widget, page->title);
1100 set_title_font (widget, page->title);
1107 gtk_assistant_size_request (GtkWidget *widget,
1108 GtkRequisition *requisition)
1110 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1111 GtkAssistantPrivate *priv = assistant->priv;
1112 GtkRequisition child_requisition;
1113 gint header_padding, content_padding;
1114 gint width, height, header_width, header_height;
1117 gtk_widget_style_get (widget,
1118 "header-padding", &header_padding,
1119 "content-padding", &content_padding,
1122 header_width = header_height = 0;
1127 GtkAssistantPage *page = list->data;
1130 gtk_widget_size_request (page->page, &child_requisition);
1131 width = MAX (width, child_requisition.width);
1132 height = MAX (height, child_requisition.height);
1134 gtk_widget_size_request (page->title, &child_requisition);
1135 w = child_requisition.width;
1136 h = child_requisition.height;
1138 if (page->header_image)
1140 w += gdk_pixbuf_get_width (page->header_image) + HEADER_SPACING;
1141 h = MAX (h, gdk_pixbuf_get_height (page->header_image));
1144 header_width = MAX (header_width, w);
1145 header_height = MAX (header_height, h);
1150 gtk_widget_size_request (priv->sidebar_image, &child_requisition);
1151 width += child_requisition.width;
1152 height = MAX (height, child_requisition.height);
1154 gtk_widget_set_size_request (priv->header_image, header_width, header_height);
1155 gtk_widget_size_request (priv->header_image, &child_requisition);
1156 width = MAX (width, header_width) + 2 * header_padding;
1157 height += header_height + 2 * header_padding;
1159 gtk_widget_size_request (priv->action_area, &child_requisition);
1160 width = MAX (width, child_requisition.width);
1161 height += child_requisition.height + ACTION_AREA_SPACING;
1163 width += GTK_CONTAINER (widget)->border_width * 2 + content_padding * 2;
1164 height += GTK_CONTAINER (widget)->border_width * 2 + content_padding * 2;
1166 requisition->width = width;
1167 requisition->height = height;
1172 gtk_assistant_size_allocate (GtkWidget *widget,
1173 GtkAllocation *allocation)
1175 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1176 GtkAssistantPrivate *priv = assistant->priv;
1177 GtkRequisition header_requisition, action_requisition, sidebar_requisition;
1178 GtkAllocation child_allocation, header_allocation;
1179 gint header_padding, content_padding;
1183 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1184 pages = priv->pages;
1186 gtk_widget_style_get (widget,
1187 "header-padding", &header_padding,
1188 "content-padding", &content_padding,
1191 widget->allocation = *allocation;
1194 gtk_widget_get_child_requisition (priv->header_image, &header_requisition);
1196 header_allocation.x = GTK_CONTAINER (widget)->border_width + header_padding;
1197 header_allocation.y = GTK_CONTAINER (widget)->border_width + header_padding;
1198 header_allocation.width = allocation->width - 2 * GTK_CONTAINER (widget)->border_width - 2 * header_padding;
1199 header_allocation.height = header_requisition.height;
1201 gtk_widget_size_allocate (priv->header_image, &header_allocation);
1204 gtk_widget_get_child_requisition (priv->action_area, &action_requisition);
1206 child_allocation.x = GTK_CONTAINER (widget)->border_width;
1207 child_allocation.y = allocation->height -
1208 GTK_CONTAINER (widget)->border_width - action_requisition.height;
1209 child_allocation.width = allocation->width - 2 * GTK_CONTAINER (widget)->border_width;
1210 child_allocation.height = action_requisition.height;
1212 gtk_widget_size_allocate (priv->action_area, &child_allocation);
1215 gtk_widget_get_child_requisition (priv->sidebar_image, &sidebar_requisition);
1218 child_allocation.x = allocation->width -
1219 GTK_CONTAINER (widget)->border_width - sidebar_requisition.width;
1221 child_allocation.x = GTK_CONTAINER (widget)->border_width;
1223 child_allocation.y = GTK_CONTAINER (widget)->border_width +
1224 priv->header_image->allocation.height + 2 * header_padding;
1225 child_allocation.width = sidebar_requisition.width;
1226 child_allocation.height = allocation->height - 2 * GTK_CONTAINER (widget)->border_width -
1227 priv->header_image->allocation.height - 2 * header_padding - priv->action_area->allocation.height;
1229 gtk_widget_size_allocate (priv->sidebar_image, &child_allocation);
1232 child_allocation.x = GTK_CONTAINER (widget)->border_width + content_padding;
1233 child_allocation.y = GTK_CONTAINER (widget)->border_width +
1234 priv->header_image->allocation.height + 2 * header_padding + content_padding;
1235 child_allocation.width = allocation->width - 2 * GTK_CONTAINER (widget)->border_width - 2 * content_padding;
1236 child_allocation.height = allocation->height - 2 * GTK_CONTAINER (widget)->border_width -
1237 priv->header_image->allocation.height - 2 * header_padding - ACTION_AREA_SPACING - priv->action_area->allocation.height - 2 * content_padding;
1239 if (gtk_widget_get_visible (priv->sidebar_image))
1242 child_allocation.x += priv->sidebar_image->allocation.width;
1244 child_allocation.width -= priv->sidebar_image->allocation.width;
1249 GtkAssistantPage *page = pages->data;
1251 gtk_widget_size_allocate (page->page, &child_allocation);
1252 gtk_widget_size_allocate (page->title, &header_allocation);
1253 pages = pages->next;
1258 gtk_assistant_map (GtkWidget *widget)
1260 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1261 GtkAssistantPrivate *priv = assistant->priv;
1263 GtkAssistantPage *page;
1265 gtk_widget_set_mapped (widget, TRUE);
1267 gtk_widget_map (priv->header_image);
1268 gtk_widget_map (priv->action_area);
1270 if (gtk_widget_get_visible (priv->sidebar_image) &&
1271 !gtk_widget_get_mapped (priv->sidebar_image))
1272 gtk_widget_map (priv->sidebar_image);
1274 /* if there's no default page, pick the first one */
1276 if (!priv->current_page)
1278 page_node = priv->pages;
1280 while (page_node && !gtk_widget_get_visible (((GtkAssistantPage *) page_node->data)->page))
1281 page_node = page_node->next;
1284 page = page_node->data;
1288 gtk_widget_get_visible (page->page) &&
1289 !gtk_widget_get_mapped (page->page))
1290 set_current_page (assistant, page);
1292 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->map (widget);
1296 gtk_assistant_unmap (GtkWidget *widget)
1298 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1299 GtkAssistantPrivate *priv = assistant->priv;
1301 gtk_widget_set_mapped (widget, FALSE);
1303 gtk_widget_unmap (priv->header_image);
1304 gtk_widget_unmap (priv->action_area);
1306 if (gtk_widget_is_drawable (priv->sidebar_image))
1307 gtk_widget_unmap (priv->sidebar_image);
1309 if (priv->current_page &&
1310 gtk_widget_is_drawable (priv->current_page->page))
1311 gtk_widget_unmap (priv->current_page->page);
1313 g_slist_free (priv->visited_pages);
1314 priv->visited_pages = NULL;
1315 priv->current_page = NULL;
1317 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->unmap (widget);
1321 gtk_assistant_delete_event (GtkWidget *widget,
1324 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1325 GtkAssistantPrivate *priv = assistant->priv;
1327 /* Do not allow cancelling in the middle of a progress page */
1328 if (priv->current_page &&
1329 (priv->current_page->type != GTK_ASSISTANT_PAGE_PROGRESS ||
1330 priv->current_page->complete))
1331 g_signal_emit (widget, signals [CANCEL], 0, NULL);
1337 assistant_paint_colored_box (GtkWidget *widget)
1339 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1340 GtkAssistantPrivate *priv = assistant->priv;
1341 gint border_width, header_padding, content_padding;
1343 gint content_x, content_width;
1346 cr = gdk_cairo_create (widget->window);
1347 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1348 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1350 gtk_widget_style_get (widget,
1351 "header-padding", &header_padding,
1352 "content-padding", &content_padding,
1356 gdk_cairo_set_source_color (cr, &widget->style->bg[GTK_STATE_SELECTED]);
1357 cairo_rectangle (cr,
1360 widget->allocation.width - 2 * border_width,
1361 widget->allocation.height - priv->action_area->allocation.height - 2 * border_width - ACTION_AREA_SPACING);
1365 content_x = content_padding + border_width;
1366 content_width = widget->allocation.width - 2 * content_padding - 2 * border_width;
1368 if (gtk_widget_get_visible (priv->sidebar_image))
1371 content_x += priv->sidebar_image->allocation.width;
1372 content_width -= priv->sidebar_image->allocation.width;
1375 gdk_cairo_set_source_color (cr, &widget->style->bg[GTK_STATE_NORMAL]);
1377 cairo_rectangle (cr,
1379 priv->header_image->allocation.height + content_padding + 2 * header_padding + border_width,
1381 widget->allocation.height - 2 * border_width - priv->action_area->allocation.height -
1382 priv->header_image->allocation.height - 2 * content_padding - 2 * header_padding - ACTION_AREA_SPACING);
1389 gtk_assistant_expose (GtkWidget *widget,
1390 GdkEventExpose *event)
1392 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1393 GtkAssistantPrivate *priv = assistant->priv;
1394 GtkContainer *container;
1396 if (gtk_widget_is_drawable (widget))
1398 container = GTK_CONTAINER (widget);
1400 assistant_paint_colored_box (widget);
1402 gtk_container_propagate_expose (container, priv->header_image, event);
1403 gtk_container_propagate_expose (container, priv->sidebar_image, event);
1404 gtk_container_propagate_expose (container, priv->action_area, event);
1406 if (priv->current_page)
1408 gtk_container_propagate_expose (container, priv->current_page->page, event);
1409 gtk_container_propagate_expose (container, priv->current_page->title, event);
1417 gtk_assistant_focus (GtkWidget *widget,
1418 GtkDirectionType direction)
1420 GtkAssistantPrivate *priv;
1421 GtkContainer *container;
1423 container = GTK_CONTAINER (widget);
1424 priv = GTK_ASSISTANT (widget)->priv;
1426 /* we only have to care about 2 widgets, action area and the current page */
1427 if (container->focus_child == priv->action_area)
1429 if (!gtk_widget_child_focus (priv->action_area, direction) &&
1430 (priv->current_page == NULL ||
1431 !gtk_widget_child_focus (priv->current_page->page, direction)))
1433 /* if we're leaving the action area and the current page hasn't
1434 any focusable widget, clear focus and go back to the action area */
1435 gtk_container_set_focus_child (GTK_CONTAINER (priv->action_area), NULL);
1436 gtk_widget_child_focus (priv->action_area, direction);
1441 if ((priv->current_page == NULL ||
1442 !gtk_widget_child_focus (priv->current_page->page, direction)) &&
1443 !gtk_widget_child_focus (priv->action_area, direction))
1445 /* if we're leaving the current page and there isn't nothing focusable
1446 in the action area, try to clear focus and go back to the page */
1447 gtk_window_set_focus (GTK_WINDOW (widget), NULL);
1448 if (priv->current_page != NULL)
1449 gtk_widget_child_focus (priv->current_page->page, direction);
1457 gtk_assistant_add (GtkContainer *container,
1460 gtk_assistant_append_page (GTK_ASSISTANT (container), page);
1464 gtk_assistant_remove (GtkContainer *container,
1467 GtkAssistant *assistant = (GtkAssistant*) container;
1470 element = find_page (assistant, page);
1474 remove_page (assistant, element);
1475 gtk_widget_queue_resize ((GtkWidget *) container);
1480 gtk_assistant_forall (GtkContainer *container,
1481 gboolean include_internals,
1482 GtkCallback callback,
1483 gpointer callback_data)
1485 GtkAssistant *assistant = (GtkAssistant*) container;
1486 GtkAssistantPrivate *priv = assistant->priv;
1489 if (include_internals)
1491 (*callback) (priv->header_image, callback_data);
1492 (*callback) (priv->sidebar_image, callback_data);
1493 (*callback) (priv->action_area, callback_data);
1496 pages = priv->pages;
1500 GtkAssistantPage *page = (GtkAssistantPage *) pages->data;
1502 (*callback) (page->page, callback_data);
1504 if (include_internals)
1505 (*callback) (page->title, callback_data);
1507 pages = pages->next;
1512 * gtk_assistant_new:
1514 * Creates a new #GtkAssistant.
1516 * Return value: a newly created #GtkAssistant
1521 gtk_assistant_new (void)
1523 GtkWidget *assistant;
1525 assistant = g_object_new (GTK_TYPE_ASSISTANT, NULL);
1531 * gtk_assistant_get_current_page:
1532 * @assistant: a #GtkAssistant
1534 * Returns the page number of the current page
1536 * Return value: The index (starting from 0) of the current page in
1537 * the @assistant, if the @assistant has no pages, -1 will be returned
1542 gtk_assistant_get_current_page (GtkAssistant *assistant)
1544 GtkAssistantPrivate *priv;
1546 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), -1);
1548 priv = assistant->priv;
1550 if (!priv->pages || !priv->current_page)
1553 return g_list_index (priv->pages, priv->current_page);
1557 * gtk_assistant_set_current_page:
1558 * @assistant: a #GtkAssistant
1559 * @page_num: index of the page to switch to, starting from 0.
1560 * If negative, the last page will be used. If greater
1561 * than the number of pages in the @assistant, nothing
1564 * Switches the page to @page_num. Note that this will only be necessary
1565 * in custom buttons, as the @assistant flow can be set with
1566 * gtk_assistant_set_forward_page_func().
1571 gtk_assistant_set_current_page (GtkAssistant *assistant,
1574 GtkAssistantPrivate *priv;
1575 GtkAssistantPage *page;
1577 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1579 priv = assistant->priv;
1582 page = (GtkAssistantPage *) g_list_nth_data (priv->pages, page_num);
1584 page = (GtkAssistantPage *) g_list_last (priv->pages)->data;
1586 g_return_if_fail (page != NULL);
1588 if (priv->current_page == page)
1591 /* only add the page to the visited list if the
1592 * assistant is mapped, if not, just use it as an
1593 * initial page setting, for the cases where the
1594 * initial page is != to 0
1596 if (gtk_widget_get_mapped (GTK_WIDGET (assistant)))
1597 priv->visited_pages = g_slist_prepend (priv->visited_pages,
1598 priv->current_page);
1600 set_current_page (assistant, page);
1604 * gtk_assistant_get_n_pages:
1605 * @assistant: a #GtkAssistant
1607 * Returns the number of pages in the @assistant
1609 * Return value: The number of pages in the @assistant.
1614 gtk_assistant_get_n_pages (GtkAssistant *assistant)
1616 GtkAssistantPrivate *priv;
1618 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1620 priv = assistant->priv;
1622 return g_list_length (priv->pages);
1626 * gtk_assistant_get_nth_page:
1627 * @assistant: a #GtkAssistant
1628 * @page_num: The index of a page in the @assistant, or -1 to get the last page;
1630 * Returns the child widget contained in page number @page_num.
1632 * Return value: The child widget, or %NULL if @page_num is out of bounds.
1637 gtk_assistant_get_nth_page (GtkAssistant *assistant,
1640 GtkAssistantPrivate *priv;
1641 GtkAssistantPage *page;
1644 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1645 g_return_val_if_fail (page_num >= -1, NULL);
1647 priv = assistant->priv;
1650 elem = g_list_last (priv->pages);
1652 elem = g_list_nth (priv->pages, page_num);
1657 page = (GtkAssistantPage *) elem->data;
1663 * gtk_assistant_prepend_page:
1664 * @assistant: a #GtkAssistant
1665 * @page: a #GtkWidget
1667 * Prepends a page to the @assistant.
1669 * Return value: the index (starting at 0) of the inserted page
1674 gtk_assistant_prepend_page (GtkAssistant *assistant,
1677 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1678 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1680 return gtk_assistant_insert_page (assistant, page, 0);
1684 * gtk_assistant_append_page:
1685 * @assistant: a #GtkAssistant
1686 * @page: a #GtkWidget
1688 * Appends a page to the @assistant.
1690 * Return value: the index (starting at 0) of the inserted page
1695 gtk_assistant_append_page (GtkAssistant *assistant,
1698 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1699 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1701 return gtk_assistant_insert_page (assistant, page, -1);
1705 * gtk_assistant_insert_page:
1706 * @assistant: a #GtkAssistant
1707 * @page: a #GtkWidget
1708 * @position: the index (starting at 0) at which to insert the page,
1709 * or -1 to append the page to the @assistant
1711 * Inserts a page in the @assistant at a given position.
1713 * Return value: the index (starting from 0) of the inserted page
1718 gtk_assistant_insert_page (GtkAssistant *assistant,
1722 GtkAssistantPrivate *priv;
1723 GtkAssistantPage *page_info;
1726 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1727 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1728 g_return_val_if_fail (page->parent == NULL, 0);
1729 g_return_val_if_fail (!gtk_widget_is_toplevel (page), 0);
1731 priv = assistant->priv;
1733 page_info = g_slice_new0 (GtkAssistantPage);
1734 page_info->page = page;
1735 page_info->title = gtk_label_new (NULL);
1737 g_signal_connect (G_OBJECT (page), "notify::visible",
1738 G_CALLBACK (on_page_notify_visibility), assistant);
1740 gtk_misc_set_alignment (GTK_MISC (page_info->title), 0.,0.5);
1741 set_title_colors (GTK_WIDGET (assistant), page_info->title);
1742 set_title_font (GTK_WIDGET (assistant), page_info->title);
1743 gtk_widget_show (page_info->title);
1745 n_pages = g_list_length (priv->pages);
1747 if (position < 0 || position > n_pages)
1750 priv->pages = g_list_insert (priv->pages, page_info, position);
1752 gtk_widget_set_child_visible (page_info->page, FALSE);
1753 gtk_widget_set_parent (page_info->page, GTK_WIDGET (assistant));
1754 gtk_widget_set_parent (page_info->title, GTK_WIDGET (assistant));
1756 if (gtk_widget_get_realized (GTK_WIDGET (assistant)))
1758 gtk_widget_realize (page_info->page);
1759 gtk_widget_realize (page_info->title);
1762 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1768 * gtk_assistant_set_forward_page_func:
1769 * @assistant: a #GtkAssistant
1770 * @page_func: (allow-none): the #GtkAssistantPageFunc, or %NULL to use the default one
1771 * @data: user data for @page_func
1772 * @destroy: destroy notifier for @data
1774 * Sets the page forwarding function to be @page_func, this function will
1775 * be used to determine what will be the next page when the user presses
1776 * the forward button. Setting @page_func to %NULL will make the assistant
1777 * to use the default forward function, which just goes to the next visible
1783 gtk_assistant_set_forward_page_func (GtkAssistant *assistant,
1784 GtkAssistantPageFunc page_func,
1786 GDestroyNotify destroy)
1788 GtkAssistantPrivate *priv;
1790 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1792 priv = assistant->priv;
1794 if (priv->forward_data_destroy &&
1795 priv->forward_function_data)
1796 (*priv->forward_data_destroy) (priv->forward_function_data);
1800 priv->forward_function = page_func;
1801 priv->forward_function_data = data;
1802 priv->forward_data_destroy = destroy;
1806 priv->forward_function = default_forward_function;
1807 priv->forward_function_data = assistant;
1808 priv->forward_data_destroy = NULL;
1811 /* Page flow has possibly changed, so the
1812 buttons state might need to change too */
1813 set_assistant_buttons_state (assistant);
1817 * gtk_assistant_add_action_widget:
1818 * @assistant: a #GtkAssistant
1819 * @child: a #GtkWidget
1821 * Adds a widget to the action area of a #GtkAssistant.
1826 gtk_assistant_add_action_widget (GtkAssistant *assistant,
1829 GtkAssistantPrivate *priv;
1831 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1832 g_return_if_fail (GTK_IS_WIDGET (child));
1834 priv = assistant->priv;
1836 if (GTK_IS_BUTTON (child))
1837 gtk_size_group_add_widget (priv->size_group, child);
1839 gtk_box_pack_end (GTK_BOX (priv->action_area), child, FALSE, FALSE, 0);
1843 * gtk_assistant_remove_action_widget:
1844 * @assistant: a #GtkAssistant
1845 * @child: a #GtkWidget
1847 * Removes a widget from the action area of a #GtkAssistant.
1852 gtk_assistant_remove_action_widget (GtkAssistant *assistant,
1855 GtkAssistantPrivate *priv;
1857 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1858 g_return_if_fail (GTK_IS_WIDGET (child));
1860 priv = assistant->priv;
1862 if (GTK_IS_BUTTON (child))
1863 gtk_size_group_remove_widget (priv->size_group, child);
1865 gtk_container_remove (GTK_CONTAINER (priv->action_area), child);
1869 * gtk_assistant_set_page_title:
1870 * @assistant: a #GtkAssistant
1871 * @page: a page of @assistant
1872 * @title: the new title for @page
1874 * Sets a title for @page. The title is displayed in the header
1875 * area of the assistant when @page is the current page.
1880 gtk_assistant_set_page_title (GtkAssistant *assistant,
1884 GtkAssistantPage *page_info;
1887 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1888 g_return_if_fail (GTK_IS_WIDGET (page));
1890 child = find_page (assistant, page);
1892 g_return_if_fail (child != NULL);
1894 page_info = (GtkAssistantPage*) child->data;
1896 gtk_label_set_text ((GtkLabel*) page_info->title, title);
1897 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1898 gtk_widget_child_notify (page, "title");
1902 * gtk_assistant_get_page_title:
1903 * @assistant: a #GtkAssistant
1904 * @page: a page of @assistant
1906 * Gets the title for @page.
1908 * Return value: the title for @page.
1912 G_CONST_RETURN gchar*
1913 gtk_assistant_get_page_title (GtkAssistant *assistant,
1916 GtkAssistantPage *page_info;
1919 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1920 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1922 child = find_page (assistant, page);
1924 g_return_val_if_fail (child != NULL, NULL);
1926 page_info = (GtkAssistantPage*) child->data;
1928 return gtk_label_get_text ((GtkLabel*) page_info->title);
1932 * gtk_assistant_set_page_type:
1933 * @assistant: a #GtkAssistant
1934 * @page: a page of @assistant
1935 * @type: the new type for @page
1937 * Sets the page type for @page. The page type determines the page
1938 * behavior in the @assistant.
1943 gtk_assistant_set_page_type (GtkAssistant *assistant,
1945 GtkAssistantPageType type)
1947 GtkAssistantPrivate *priv;
1948 GtkAssistantPage *page_info;
1951 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1952 g_return_if_fail (GTK_IS_WIDGET (page));
1954 priv = assistant->priv;
1955 child = find_page (assistant, page);
1957 g_return_if_fail (child != NULL);
1959 page_info = (GtkAssistantPage*) child->data;
1961 if (type != page_info->type)
1963 page_info->type = type;
1965 /* backwards compatibility to the era before fixing bug 604289 */
1966 if (type == GTK_ASSISTANT_PAGE_SUMMARY && !page_info->complete_set)
1968 gtk_assistant_set_page_complete (assistant, page, TRUE);
1969 page_info->complete_set = FALSE;
1972 /* Always set buttons state, a change in a future page
1973 might change current page buttons */
1974 set_assistant_buttons_state (assistant);
1976 gtk_widget_child_notify (page, "page-type");
1981 * gtk_assistant_get_page_type:
1982 * @assistant: a #GtkAssistant
1983 * @page: a page of @assistant
1985 * Gets the page type of @page.
1987 * Return value: the page type of @page.
1991 GtkAssistantPageType
1992 gtk_assistant_get_page_type (GtkAssistant *assistant,
1995 GtkAssistantPage *page_info;
1998 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), GTK_ASSISTANT_PAGE_CONTENT);
1999 g_return_val_if_fail (GTK_IS_WIDGET (page), GTK_ASSISTANT_PAGE_CONTENT);
2001 child = find_page (assistant, page);
2003 g_return_val_if_fail (child != NULL, GTK_ASSISTANT_PAGE_CONTENT);
2005 page_info = (GtkAssistantPage*) child->data;
2007 return page_info->type;
2011 * gtk_assistant_set_page_header_image:
2012 * @assistant: a #GtkAssistant
2013 * @page: a page of @assistant
2014 * @pixbuf: (allow-none): the new header image @page
2016 * Sets a header image for @page. This image is displayed in the header
2017 * area of the assistant when @page is the current page.
2022 gtk_assistant_set_page_header_image (GtkAssistant *assistant,
2026 GtkAssistantPrivate *priv;
2027 GtkAssistantPage *page_info;
2030 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2031 g_return_if_fail (GTK_IS_WIDGET (page));
2032 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2034 priv = assistant->priv;
2035 child = find_page (assistant, page);
2037 g_return_if_fail (child != NULL);
2039 page_info = (GtkAssistantPage*) child->data;
2041 if (pixbuf != page_info->header_image)
2043 if (page_info->header_image)
2045 g_object_unref (page_info->header_image);
2046 page_info->header_image = NULL;
2050 page_info->header_image = g_object_ref (pixbuf);
2052 if (page_info == priv->current_page)
2053 set_assistant_header_image (assistant);
2055 gtk_widget_child_notify (page, "header-image");
2060 * gtk_assistant_get_page_header_image:
2061 * @assistant: a #GtkAssistant
2062 * @page: a page of @assistant
2064 * Gets the header image for @page.
2066 * Return value: the header image for @page, or %NULL
2067 * if there's no header image for the page.
2072 gtk_assistant_get_page_header_image (GtkAssistant *assistant,
2075 GtkAssistantPage *page_info;
2078 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2079 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2081 child = find_page (assistant, page);
2083 g_return_val_if_fail (child != NULL, NULL);
2085 page_info = (GtkAssistantPage*) child->data;
2087 return page_info->header_image;
2091 * gtk_assistant_set_page_side_image:
2092 * @assistant: a #GtkAssistant
2093 * @page: a page of @assistant
2094 * @pixbuf: (allow-none): the new header image @page
2096 * Sets a header image for @page. This image is displayed in the side
2097 * area of the assistant when @page is the current page.
2102 gtk_assistant_set_page_side_image (GtkAssistant *assistant,
2106 GtkAssistantPrivate *priv;
2107 GtkAssistantPage *page_info;
2110 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2111 g_return_if_fail (GTK_IS_WIDGET (page));
2112 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2114 priv = assistant->priv;
2115 child = find_page (assistant, page);
2117 g_return_if_fail (child != NULL);
2119 page_info = (GtkAssistantPage*) child->data;
2121 if (pixbuf != page_info->sidebar_image)
2123 if (page_info->sidebar_image)
2125 g_object_unref (page_info->sidebar_image);
2126 page_info->sidebar_image = NULL;
2130 page_info->sidebar_image = g_object_ref (pixbuf);
2132 if (page_info == priv->current_page)
2133 set_assistant_sidebar_image (assistant);
2135 gtk_widget_child_notify (page, "sidebar-image");
2140 * gtk_assistant_get_page_side_image:
2141 * @assistant: a #GtkAssistant
2142 * @page: a page of @assistant
2144 * Gets the header image for @page.
2146 * Return value: the side image for @page, or %NULL
2147 * if there's no side image for the page.
2152 gtk_assistant_get_page_side_image (GtkAssistant *assistant,
2155 GtkAssistantPage *page_info;
2158 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2159 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2161 child = find_page (assistant, page);
2163 g_return_val_if_fail (child != NULL, NULL);
2165 page_info = (GtkAssistantPage*) child->data;
2167 return page_info->sidebar_image;
2171 * gtk_assistant_set_page_complete:
2172 * @assistant: a #GtkAssistant
2173 * @page: a page of @assistant
2174 * @complete: the completeness status of the page
2176 * Sets whether @page contents are complete. This will make
2177 * @assistant update the buttons state to be able to continue the task.
2182 gtk_assistant_set_page_complete (GtkAssistant *assistant,
2186 GtkAssistantPrivate *priv;
2187 GtkAssistantPage *page_info;
2190 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2191 g_return_if_fail (GTK_IS_WIDGET (page));
2193 priv = assistant->priv;
2194 child = find_page (assistant, page);
2196 g_return_if_fail (child != NULL);
2198 page_info = (GtkAssistantPage*) child->data;
2200 if (complete != page_info->complete)
2202 page_info->complete = complete;
2203 page_info->complete_set = TRUE;
2205 /* Always set buttons state, a change in a future page
2206 might change current page buttons */
2207 set_assistant_buttons_state (assistant);
2209 gtk_widget_child_notify (page, "complete");
2214 * gtk_assistant_get_page_complete:
2215 * @assistant: a #GtkAssistant
2216 * @page: a page of @assistant
2218 * Gets whether @page is complete.
2220 * Return value: %TRUE if @page is complete.
2225 gtk_assistant_get_page_complete (GtkAssistant *assistant,
2228 GtkAssistantPage *page_info;
2231 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), FALSE);
2232 g_return_val_if_fail (GTK_IS_WIDGET (page), FALSE);
2234 child = find_page (assistant, page);
2236 g_return_val_if_fail (child != NULL, FALSE);
2238 page_info = (GtkAssistantPage*) child->data;
2240 return page_info->complete;
2244 * gtk_assistant_update_buttons_state:
2245 * @assistant: a #GtkAssistant
2247 * Forces @assistant to recompute the buttons state.
2249 * GTK+ automatically takes care of this in most situations,
2250 * e.g. when the user goes to a different page, or when the
2251 * visibility or completeness of a page changes.
2253 * One situation where it can be necessary to call this
2254 * function is when changing a value on the current page
2255 * affects the future page flow of the assistant.
2260 gtk_assistant_update_buttons_state (GtkAssistant *assistant)
2262 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2264 set_assistant_buttons_state (assistant);
2269 /* accessible implementation */
2272 gtk_assistant_accessible_get_n_children (AtkObject *accessible)
2274 GtkAssistant *assistant;
2277 widget = GTK_ACCESSIBLE (accessible)->widget;
2282 assistant = GTK_ASSISTANT (widget);
2284 return g_list_length (assistant->priv->pages) + 1;
2289 gtk_assistant_accessible_ref_child (AtkObject *accessible,
2292 GtkAssistant *assistant;
2293 GtkAssistantPrivate *priv;
2294 GtkWidget *widget, *child;
2299 widget = GTK_ACCESSIBLE (accessible)->widget;
2303 assistant = GTK_ASSISTANT (widget);
2304 priv = assistant->priv;
2305 n_pages = g_list_length (priv->pages);
2309 else if (index < n_pages)
2311 GtkAssistantPage *page = g_list_nth_data (priv->pages, index);
2314 title = gtk_assistant_get_page_title (assistant, child);
2316 else if (index == n_pages)
2318 child = priv->action_area;
2324 obj = gtk_widget_get_accessible (child);
2327 atk_object_set_name (obj, title);
2329 return g_object_ref (obj);
2333 gtk_assistant_accessible_class_init (AtkObjectClass *class)
2335 class->get_n_children = gtk_assistant_accessible_get_n_children;
2336 class->ref_child = gtk_assistant_accessible_ref_child;
2340 gtk_assistant_accessible_get_type (void)
2342 static GType type = 0;
2347 * Figure out the size of the class and instance
2348 * we are deriving from
2350 AtkObjectFactory *factory;
2353 GType derived_atk_type;
2355 derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
2356 factory = atk_registry_get_factory (atk_get_default_registry (),
2358 derived_atk_type = atk_object_factory_get_accessible_type (factory);
2359 g_type_query (derived_atk_type, &query);
2361 type = g_type_register_static_simple (derived_atk_type,
2362 I_("GtkAssistantAccessible"),
2364 (GClassInitFunc) gtk_assistant_accessible_class_init,
2365 query.instance_size,
2373 gtk_assistant_accessible_new (GObject *obj)
2375 AtkObject *accessible;
2377 g_return_val_if_fail (GTK_IS_ASSISTANT (obj), NULL);
2379 accessible = g_object_new (gtk_assistant_accessible_get_type (), NULL);
2380 atk_object_initialize (accessible, obj);
2386 gtk_assistant_accessible_factory_get_accessible_type (void)
2388 return gtk_assistant_accessible_get_type ();
2392 gtk_assistant_accessible_factory_create_accessible (GObject *obj)
2394 return gtk_assistant_accessible_new (obj);
2398 gtk_assistant_accessible_factory_class_init (AtkObjectFactoryClass *class)
2400 class->create_accessible = gtk_assistant_accessible_factory_create_accessible;
2401 class->get_accessible_type = gtk_assistant_accessible_factory_get_accessible_type;
2405 gtk_assistant_accessible_factory_get_type (void)
2407 static GType type = 0;
2411 type = g_type_register_static_simple (ATK_TYPE_OBJECT_FACTORY,
2412 I_("GtkAssistantAccessibleFactory"),
2413 sizeof (AtkObjectFactoryClass),
2414 (GClassInitFunc) gtk_assistant_accessible_factory_class_init,
2415 sizeof (AtkObjectFactory),
2423 gtk_assistant_get_accessible (GtkWidget *widget)
2425 static gboolean first_time = TRUE;
2429 AtkObjectFactory *factory;
2430 AtkRegistry *registry;
2432 GType derived_atk_type;
2435 * Figure out whether accessibility is enabled by looking at the
2436 * type of the accessible object which would be created for
2437 * the parent type of GtkAssistant.
2439 derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
2441 registry = atk_get_default_registry ();
2442 factory = atk_registry_get_factory (registry,
2444 derived_atk_type = atk_object_factory_get_accessible_type (factory);
2445 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
2447 atk_registry_set_factory_type (registry,
2449 gtk_assistant_accessible_factory_get_type ());
2454 return GTK_WIDGET_CLASS (gtk_assistant_parent_class)->get_accessible (widget);
2458 static GtkBuildableIface *parent_buildable_iface;
2461 gtk_assistant_buildable_interface_init (GtkBuildableIface *iface)
2463 parent_buildable_iface = g_type_interface_peek_parent (iface);
2464 iface->get_internal_child = gtk_assistant_buildable_get_internal_child;
2465 iface->custom_tag_start = gtk_assistant_buildable_custom_tag_start;
2466 iface->custom_finished = gtk_assistant_buildable_custom_finished;
2470 gtk_assistant_buildable_get_internal_child (GtkBuildable *buildable,
2471 GtkBuilder *builder,
2472 const gchar *childname)
2474 if (strcmp (childname, "action_area") == 0)
2475 return G_OBJECT (GTK_ASSISTANT (buildable)->priv->action_area);
2477 return parent_buildable_iface->get_internal_child (buildable,
2483 gtk_assistant_buildable_custom_tag_start (GtkBuildable *buildable,
2484 GtkBuilder *builder,
2486 const gchar *tagname,
2487 GMarkupParser *parser,
2490 return parent_buildable_iface->custom_tag_start (buildable, builder, child,
2491 tagname, parser, data);
2495 gtk_assistant_buildable_custom_finished (GtkBuildable *buildable,
2496 GtkBuilder *builder,
2498 const gchar *tagname,
2501 parent_buildable_iface->custom_finished (buildable, builder, child,
2502 tagname, user_data);
2506 #define __GTK_ASSISTANT_C__
2507 #include "gtkaliasdef.c"