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.
30 #include "gtkassistant.h"
32 #include "gtkaccessible.h"
33 #include "gtkbutton.h"
38 #include "gtksizegroup.h"
42 #include "gtkprivate.h"
46 #define GTK_ASSISTANT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_ASSISTANT, GtkAssistantPrivate))
48 #define HEADER_SPACING 12
49 #define ACTION_AREA_SPACING 12
51 typedef struct _GtkAssistantPage GtkAssistantPage;
53 struct _GtkAssistantPage
56 GtkAssistantPageType type;
60 GdkPixbuf *header_image;
61 GdkPixbuf *sidebar_image;
64 struct _GtkAssistantPrivate
66 GtkWidget *header_image;
67 GtkWidget *sidebar_image;
69 GtkWidget *action_area;
73 GtkAssistantPage *current_page;
75 GSList *visited_pages;
77 GtkSizeGroup *size_group;
79 GtkAssistantPageFunc forward_function;
80 gpointer forward_function_data;
81 GDestroyNotify forward_data_destroy;
84 static void gtk_assistant_class_init (GtkAssistantClass *class);
85 static void gtk_assistant_init (GtkAssistant *assistant);
86 static void gtk_assistant_destroy (GtkObject *object);
87 static void gtk_assistant_style_set (GtkWidget *widget,
89 static void gtk_assistant_size_request (GtkWidget *widget,
90 GtkRequisition *requisition);
91 static void gtk_assistant_size_allocate (GtkWidget *widget,
92 GtkAllocation *allocation);
93 static void gtk_assistant_map (GtkWidget *widget);
94 static void gtk_assistant_unmap (GtkWidget *widget);
95 static gboolean gtk_assistant_delete_event (GtkWidget *widget,
97 static gboolean gtk_assistant_expose (GtkWidget *widget,
98 GdkEventExpose *event);
99 static gboolean gtk_assistant_focus (GtkWidget *widget,
100 GtkDirectionType direction);
101 static void gtk_assistant_add (GtkContainer *container,
103 static void gtk_assistant_remove (GtkContainer *container,
105 static void gtk_assistant_forall (GtkContainer *container,
106 gboolean include_internals,
107 GtkCallback callback,
108 gpointer callback_data);
109 static void gtk_assistant_set_child_property (GtkContainer *container,
114 static void gtk_assistant_get_child_property (GtkContainer *container,
120 static AtkObject *gtk_assistant_get_accessible (GtkWidget *widget);
125 CHILD_PROP_PAGE_TYPE,
126 CHILD_PROP_PAGE_TITLE,
127 CHILD_PROP_PAGE_HEADER_IMAGE,
128 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
129 CHILD_PROP_PAGE_COMPLETE
141 static guint signals [LAST_SIGNAL] = { 0 };
144 G_DEFINE_TYPE (GtkAssistant, gtk_assistant, GTK_TYPE_WINDOW)
148 gtk_assistant_class_init (GtkAssistantClass *class)
150 GObjectClass *gobject_class;
151 GtkObjectClass *object_class;
152 GtkWidgetClass *widget_class;
153 GtkContainerClass *container_class;
155 gobject_class = (GObjectClass *) class;
156 object_class = (GtkObjectClass *) class;
157 widget_class = (GtkWidgetClass *) class;
158 container_class = (GtkContainerClass *) class;
160 object_class->destroy = gtk_assistant_destroy;
162 widget_class->style_set = gtk_assistant_style_set;
163 widget_class->size_request = gtk_assistant_size_request;
164 widget_class->size_allocate = gtk_assistant_size_allocate;
165 widget_class->map = gtk_assistant_map;
166 widget_class->unmap = gtk_assistant_unmap;
167 widget_class->delete_event = gtk_assistant_delete_event;
168 widget_class->expose_event = gtk_assistant_expose;
169 widget_class->focus = gtk_assistant_focus;
170 widget_class->get_accessible = gtk_assistant_get_accessible;
172 container_class->add = gtk_assistant_add;
173 container_class->remove = gtk_assistant_remove;
174 container_class->forall = gtk_assistant_forall;
175 container_class->set_child_property = gtk_assistant_set_child_property;
176 container_class->get_child_property = gtk_assistant_get_child_property;
179 * GtkAssistant::cancel:
180 * @assistant: the #GtkAssistant
182 * The ::cancel signal is emitted when then the cancel button is clicked.
187 g_signal_new (I_("cancel"),
188 G_TYPE_FROM_CLASS (gobject_class),
190 G_STRUCT_OFFSET (GtkAssistantClass, cancel),
192 g_cclosure_marshal_VOID__VOID,
196 * GtkAssistant::prepare:
197 * @assistant: the #GtkAssistant
198 * @page: the current page
200 * The ::prepared signal is emitted when a new page is set as the assistant's
201 * current page, before making the new page visible. A handler for this signal
202 * can do any preparation which are necessary before showing @page.
207 g_signal_new (I_("prepare"),
208 G_TYPE_FROM_CLASS (gobject_class),
210 G_STRUCT_OFFSET (GtkAssistantClass, prepare),
212 g_cclosure_marshal_VOID__OBJECT,
213 G_TYPE_NONE, 1, GTK_TYPE_WIDGET);
216 * GtkAssistant::apply:
217 * @assistant: the @GtkAssistant
219 * The ::apply signal is emitted when the apply button is clicked. The default
220 * behavior of the #GtkAssistant is to switch to the page after the current page,
221 * unless the current page is the last one.
223 * A handler for the ::apply signal should carry out the actions for which the
224 * wizard has collected data. If the action takes a long time to complete, you
225 * might consider to put a page of type GTK_ASSISTANT_PAGE_PROGRESS after the
226 * confirmation page and handle this operation within the ::prepare signal of
232 g_signal_new (I_("apply"),
233 G_TYPE_FROM_CLASS (gobject_class),
235 G_STRUCT_OFFSET (GtkAssistantClass, apply),
237 g_cclosure_marshal_VOID__VOID,
241 * GtkAssistant::close:
242 * @assistant: the #GtkAssistant
244 * The ::close signal is emitted either when the close button of
245 * a summary page is clicked, or when the apply button in the last
246 * page in the flow (of type GTK_ASSISTANT_PAGE_CONFIRM) is clicked.
251 g_signal_new (I_("close"),
252 G_TYPE_FROM_CLASS (gobject_class),
254 G_STRUCT_OFFSET (GtkAssistantClass, close),
256 g_cclosure_marshal_VOID__VOID,
259 gtk_widget_class_install_style_property (widget_class,
260 g_param_spec_int ("header-padding",
261 P_("Header Padding"),
262 P_("Number of pixels around the header."),
266 GTK_PARAM_READABLE));
267 gtk_widget_class_install_style_property (widget_class,
268 g_param_spec_int ("content-padding",
269 P_("Content Padding"),
270 P_("Number of pixels around the content pages."),
274 GTK_PARAM_READABLE));
277 * GtkAssistant:page-type:
279 * The type of the assistant page.
283 gtk_container_class_install_child_property (container_class,
284 CHILD_PROP_PAGE_TYPE,
285 g_param_spec_enum ("page-type",
287 P_("The type of the assistant page"),
288 GTK_TYPE_ASSISTANT_PAGE_TYPE,
289 GTK_ASSISTANT_PAGE_CONTENT,
290 GTK_PARAM_READWRITE));
293 * GtkAssistant:title:
295 * The title that is displayed in the page header.
297 * If title and header-image are both %NULL, no header is displayed.
301 gtk_container_class_install_child_property (container_class,
302 CHILD_PROP_PAGE_TITLE,
303 g_param_spec_string ("title",
305 P_("The title of the assistant page"),
307 GTK_PARAM_READWRITE));
310 * GtkAssistant:header-image:
312 * The image that is displayed next to the title in the page header.
314 * If title and header-image are both %NULL, no header is displayed.
318 gtk_container_class_install_child_property (container_class,
319 CHILD_PROP_PAGE_HEADER_IMAGE,
320 g_param_spec_object ("header-image",
322 P_("Header image for the assistant page"),
324 GTK_PARAM_READWRITE));
327 * GtkAssistant:header-image:
329 * The image that is displayed next to the page.
331 * Set this to %NULL to make the sidebar disappear.
335 gtk_container_class_install_child_property (container_class,
336 CHILD_PROP_PAGE_SIDEBAR_IMAGE,
337 g_param_spec_object ("sidebar-image",
339 P_("Sidebar image for the assistant page"),
341 GTK_PARAM_READWRITE));
343 * GtkAssistant:complete:
345 * Setting the "complete" child property to %TRUE marks a page as complete
346 * (i.e.: all the required fields are filled out). GTK+ uses this information
347 * to control the sensitivity of the navigation buttons.
351 gtk_container_class_install_child_property (container_class,
352 CHILD_PROP_PAGE_COMPLETE,
353 g_param_spec_boolean ("complete",
355 P_("Whether all required fields on the page have been filled out"),
359 g_type_class_add_private (gobject_class, sizeof (GtkAssistantPrivate));
363 default_forward_function (gint current_page, gpointer data)
365 GtkAssistant *assistant;
366 GtkAssistantPrivate *priv;
367 GtkAssistantPage *page_info;
370 assistant = GTK_ASSISTANT (data);
371 priv = assistant->priv;
373 page_node = g_list_nth (priv->pages, ++current_page);
378 page_info = (GtkAssistantPage *) page_node->data;
380 while (page_node && !GTK_WIDGET_VISIBLE (page_info->page))
382 page_node = page_node->next;
386 page_info = (GtkAssistantPage *) page_node->data;
393 compute_last_button_state (GtkAssistant *assistant)
395 GtkAssistantPrivate *priv = assistant->priv;
396 GtkAssistantPage *page_info, *current_page_info;
397 gint count, page_num, n_pages;
400 page_num = gtk_assistant_get_current_page (assistant);
401 n_pages = gtk_assistant_get_n_pages (assistant);
402 current_page_info = page_info = g_list_nth_data (priv->pages, page_num);
404 while (page_num >= 0 && page_num < n_pages &&
405 page_info->type == GTK_ASSISTANT_PAGE_CONTENT &&
406 (count == 0 || page_info->complete) &&
409 page_num = (priv->forward_function) (page_num, priv->forward_function_data);
410 page_info = g_list_nth_data (priv->pages, page_num);
414 g_assert (page_info);
417 /* make the last button visible if we can skip multiple
418 * pages and end on a confirmation or summary page
421 (page_info->type == GTK_ASSISTANT_PAGE_CONFIRM ||
422 page_info->type == GTK_ASSISTANT_PAGE_SUMMARY))
424 gtk_widget_show (assistant->last);
425 gtk_widget_set_sensitive (assistant->last,
426 current_page_info->complete);
429 gtk_widget_hide (assistant->last);
433 set_assistant_header_image (GtkAssistant *assistant)
435 GtkAssistantPrivate *priv = assistant->priv;
437 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->header_image),
438 priv->current_page->header_image);
442 set_assistant_sidebar_image (GtkAssistant *assistant)
444 GtkAssistantPrivate *priv = assistant->priv;
446 gtk_image_set_from_pixbuf (GTK_IMAGE (priv->sidebar_image),
447 priv->current_page->sidebar_image);
449 if (priv->current_page->sidebar_image)
450 gtk_widget_show (priv->sidebar_image);
452 gtk_widget_hide (priv->sidebar_image);
456 set_assistant_buttons_state (GtkAssistant *assistant)
458 GtkAssistantPrivate *priv = assistant->priv;
460 switch (priv->current_page->type)
462 case GTK_ASSISTANT_PAGE_INTRO:
463 gtk_widget_set_sensitive (assistant->cancel, TRUE);
464 gtk_widget_set_sensitive (assistant->forward, priv->current_page->complete);
465 gtk_widget_show (assistant->cancel);
466 gtk_widget_show (assistant->forward);
467 gtk_widget_hide (assistant->back);
468 gtk_widget_hide (assistant->apply);
469 gtk_widget_hide (assistant->close);
470 compute_last_button_state (assistant);
472 case GTK_ASSISTANT_PAGE_CONFIRM:
473 gtk_widget_set_sensitive (assistant->cancel, TRUE);
474 gtk_widget_set_sensitive (assistant->back, TRUE);
475 gtk_widget_set_sensitive (assistant->apply, priv->current_page->complete);
476 gtk_widget_show (assistant->cancel);
477 gtk_widget_show (assistant->back);
478 gtk_widget_show (assistant->apply);
479 gtk_widget_hide (assistant->forward);
480 gtk_widget_hide (assistant->close);
481 gtk_widget_hide (assistant->last);
483 case GTK_ASSISTANT_PAGE_CONTENT:
484 gtk_widget_set_sensitive (assistant->cancel, TRUE);
485 gtk_widget_set_sensitive (assistant->back, TRUE);
486 gtk_widget_set_sensitive (assistant->forward, priv->current_page->complete);
487 gtk_widget_show (assistant->cancel);
488 gtk_widget_show (assistant->back);
489 gtk_widget_show (assistant->forward);
490 gtk_widget_hide (assistant->apply);
491 gtk_widget_hide (assistant->close);
492 compute_last_button_state (assistant);
494 case GTK_ASSISTANT_PAGE_SUMMARY:
495 gtk_widget_set_sensitive (assistant->close, TRUE);
496 gtk_widget_show (assistant->close);
497 gtk_widget_hide (assistant->cancel);
498 gtk_widget_hide (assistant->back);
499 gtk_widget_hide (assistant->forward);
500 gtk_widget_hide (assistant->apply);
501 gtk_widget_hide (assistant->last);
503 case GTK_ASSISTANT_PAGE_PROGRESS:
504 gtk_widget_set_sensitive (assistant->cancel, priv->current_page->complete);
505 gtk_widget_set_sensitive (assistant->back, priv->current_page->complete);
506 gtk_widget_set_sensitive (assistant->forward, priv->current_page->complete);
507 gtk_widget_show (assistant->cancel);
508 gtk_widget_show (assistant->back);
509 gtk_widget_show (assistant->forward);
510 gtk_widget_hide (assistant->apply);
511 gtk_widget_hide (assistant->close);
512 gtk_widget_hide (assistant->last);
515 g_assert_not_reached ();
518 /* this is quite general, we don't want to
519 * go back if it's the first page */
520 if (!priv->visited_pages)
521 gtk_widget_hide (assistant->back);
525 set_current_page (GtkAssistant *assistant,
526 GtkAssistantPage *page)
528 GtkAssistantPrivate *priv = assistant->priv;
529 GtkAssistantPage *old_page;
531 if (priv->current_page &&
532 GTK_WIDGET_DRAWABLE (priv->current_page->page))
533 old_page = priv->current_page;
537 priv->current_page = page;
539 set_assistant_buttons_state (assistant);
540 set_assistant_header_image (assistant);
541 set_assistant_sidebar_image (assistant);
543 g_signal_emit (assistant, signals [PREPARE], 0, priv->current_page->page);
545 if (GTK_WIDGET_VISIBLE (priv->current_page->page) && GTK_WIDGET_MAPPED (assistant))
547 gtk_widget_set_child_visible (priv->current_page->page, TRUE);
548 gtk_widget_map (priv->current_page->page);
549 gtk_widget_map (priv->current_page->title);
552 if (old_page && GTK_WIDGET_MAPPED (old_page->page))
554 gtk_widget_set_child_visible (old_page->page, FALSE);
555 gtk_widget_unmap (old_page->page);
556 gtk_widget_unmap (old_page->title);
559 gtk_widget_queue_resize (GTK_WIDGET (assistant));
563 compute_next_step (GtkAssistant *assistant)
565 GtkAssistantPrivate *priv = assistant->priv;
566 GtkAssistantPage *page_info;
567 gint current_page, n_pages, next_page;
569 current_page = gtk_assistant_get_current_page (assistant);
570 page_info = priv->current_page;
571 n_pages = gtk_assistant_get_n_pages (assistant);
573 next_page = (priv->forward_function) (current_page,
574 priv->forward_function_data);
576 if (next_page >= 0 && next_page < n_pages)
578 priv->visited_pages = g_slist_prepend (priv->visited_pages, page_info);
579 set_current_page (assistant, g_list_nth_data (priv->pages, next_page));
588 on_assistant_close (GtkWidget *widget, GtkAssistant *assistant)
590 g_signal_emit (assistant, signals [CLOSE], 0, NULL);
594 on_assistant_apply (GtkWidget *widget, GtkAssistant *assistant)
596 GtkAssistantPrivate *priv = assistant->priv;
599 success = compute_next_step (assistant);
601 g_signal_emit (assistant, signals [APPLY], 0, priv->current_page->page);
603 /* if the assistant hasn't switched to another page, just emit
604 * the CLOSE signal, it't the last page in the assistant flow
607 g_signal_emit (assistant, signals [CLOSE], 0, priv->current_page->page);
611 on_assistant_forward (GtkWidget *widget, GtkAssistant *assistant)
613 if (!compute_next_step (assistant))
614 g_critical ("Page flow is broken, you may want to end it with a page of "
615 "type GTK_ASSISTANT_PAGE_CONFIRM or GTK_ASSISTANT_PAGE_SUMMARY");
619 on_assistant_back (GtkWidget *widget, GtkAssistant *assistant)
621 GtkAssistantPrivate *priv = assistant->priv;
622 GtkAssistantPage *page_info;
625 /* skip the progress pages when going back */
628 page_node = priv->visited_pages;
630 g_return_if_fail (page_node != NULL);
632 priv->visited_pages = priv->visited_pages->next;
633 page_info = (GtkAssistantPage *) page_node->data;
634 g_slist_free_1 (page_node);
636 while (page_info->type == GTK_ASSISTANT_PAGE_PROGRESS ||
637 !GTK_WIDGET_VISIBLE (page_info->page));
639 set_current_page (assistant, page_info);
643 on_assistant_cancel (GtkWidget *widget, GtkAssistant *assistant)
645 g_signal_emit (assistant, signals [CANCEL], 0, NULL);
649 on_assistant_last (GtkWidget *widget, GtkAssistant *assistant)
651 GtkAssistantPrivate *priv = assistant->priv;
653 while (priv->current_page->type == GTK_ASSISTANT_PAGE_CONTENT &&
654 priv->current_page->complete)
655 compute_next_step (assistant);
659 alternative_button_order (GtkAssistant *assistant)
661 GtkSettings *settings;
665 screen = gtk_widget_get_screen (GTK_WIDGET (assistant));
666 settings = gtk_settings_get_for_screen (screen);
668 g_object_get (settings,
669 "gtk-alternative-button-order", &result,
675 gtk_assistant_init (GtkAssistant *assistant)
677 GtkAssistantPrivate *priv;
679 priv = assistant->priv = GTK_ASSISTANT_GET_PRIVATE (assistant);
681 gtk_container_set_reallocate_redraws (GTK_CONTAINER (assistant), TRUE);
683 gtk_widget_push_composite_child ();
686 priv->header_image = gtk_image_new ();
687 gtk_misc_set_alignment (GTK_MISC (priv->header_image), 1., 0.5);
688 gtk_widget_set_parent (priv->header_image, GTK_WIDGET (assistant));
689 gtk_widget_show (priv->header_image);
692 priv->sidebar_image = gtk_image_new ();
693 gtk_misc_set_alignment (GTK_MISC (priv->sidebar_image), 0., 0.);
694 gtk_widget_set_parent (priv->sidebar_image, GTK_WIDGET (assistant));
695 gtk_widget_show (priv->sidebar_image);
698 priv->action_area = gtk_hbox_new (FALSE, 6);
700 assistant->close = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
701 assistant->apply = gtk_button_new_from_stock (GTK_STOCK_APPLY);
702 assistant->forward = gtk_button_new_from_stock (GTK_STOCK_GO_FORWARD);
703 assistant->back = gtk_button_new_from_stock (GTK_STOCK_GO_BACK);
704 assistant->cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
705 assistant->last = gtk_button_new_from_stock (GTK_STOCK_GOTO_LAST);
707 priv->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
708 gtk_size_group_add_widget (priv->size_group, assistant->close);
709 gtk_size_group_add_widget (priv->size_group, assistant->apply);
710 gtk_size_group_add_widget (priv->size_group, assistant->forward);
711 gtk_size_group_add_widget (priv->size_group, assistant->back);
712 gtk_size_group_add_widget (priv->size_group, assistant->cancel);
713 gtk_size_group_add_widget (priv->size_group, assistant->last);
715 if (!alternative_button_order (assistant))
717 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->apply, FALSE, FALSE, 0);
718 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->forward, FALSE, FALSE, 0);
719 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->back, FALSE, FALSE, 0);
720 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->last, FALSE, FALSE, 0);
721 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->cancel, FALSE, FALSE, 0);
722 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->close, FALSE, FALSE, 0);
726 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->close, FALSE, FALSE, 0);
727 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->cancel, FALSE, FALSE, 0);
728 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->last, FALSE, FALSE, 0);
729 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->back, FALSE, FALSE, 0);
730 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->forward, FALSE, FALSE, 0);
731 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->apply, FALSE, FALSE, 0);
734 gtk_widget_set_parent (priv->action_area, GTK_WIDGET (assistant));
735 gtk_widget_show (assistant->forward);
736 gtk_widget_show (assistant->back);
737 gtk_widget_show (assistant->cancel);
738 gtk_widget_show (priv->action_area);
740 gtk_widget_pop_composite_child ();
743 priv->current_page = NULL;
744 priv->visited_pages = NULL;
746 priv->forward_function = default_forward_function;
747 priv->forward_function_data = assistant;
748 priv->forward_data_destroy = NULL;
750 g_signal_connect (G_OBJECT (assistant->close), "clicked",
751 G_CALLBACK (on_assistant_close), assistant);
752 g_signal_connect (G_OBJECT (assistant->apply), "clicked",
753 G_CALLBACK (on_assistant_apply), assistant);
754 g_signal_connect (G_OBJECT (assistant->forward), "clicked",
755 G_CALLBACK (on_assistant_forward), assistant);
756 g_signal_connect (G_OBJECT (assistant->back), "clicked",
757 G_CALLBACK (on_assistant_back), assistant);
758 g_signal_connect (G_OBJECT (assistant->cancel), "clicked",
759 G_CALLBACK (on_assistant_cancel), assistant);
760 g_signal_connect (G_OBJECT (assistant->last), "clicked",
761 G_CALLBACK (on_assistant_last), assistant);
765 gtk_assistant_set_child_property (GtkContainer *container,
773 case CHILD_PROP_PAGE_TYPE:
774 gtk_assistant_set_page_type (GTK_ASSISTANT (container), child,
775 g_value_get_enum (value));
777 case CHILD_PROP_PAGE_TITLE:
778 gtk_assistant_set_page_title (GTK_ASSISTANT (container), child,
779 g_value_get_string (value));
781 case CHILD_PROP_PAGE_HEADER_IMAGE:
782 gtk_assistant_set_page_header_image (GTK_ASSISTANT (container), child,
783 g_value_get_object (value));
785 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
786 gtk_assistant_set_page_side_image (GTK_ASSISTANT (container), child,
787 g_value_get_object (value));
789 case CHILD_PROP_PAGE_COMPLETE:
790 gtk_assistant_set_page_complete (GTK_ASSISTANT (container), child,
791 g_value_get_boolean (value));
794 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
800 gtk_assistant_get_child_property (GtkContainer *container,
808 case CHILD_PROP_PAGE_TYPE:
809 g_value_set_enum (value,
810 gtk_assistant_get_page_type (GTK_ASSISTANT (container), child));
812 case CHILD_PROP_PAGE_TITLE:
813 g_value_set_string (value,
814 gtk_assistant_get_page_title (GTK_ASSISTANT (container), child));
816 case CHILD_PROP_PAGE_HEADER_IMAGE:
817 g_value_set_object (value,
818 gtk_assistant_get_page_header_image (GTK_ASSISTANT (container), child));
820 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
821 g_value_set_object (value,
822 gtk_assistant_get_page_side_image (GTK_ASSISTANT (container), child));
824 case CHILD_PROP_PAGE_COMPLETE:
825 g_value_set_boolean (value,
826 gtk_assistant_get_page_complete (GTK_ASSISTANT (container), child));
829 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
835 on_page_notify_visibility (GtkWidget *widget,
839 GtkAssistant *assistant = GTK_ASSISTANT (data);
841 /* update buttons state, flow may have changed */
842 if (GTK_WIDGET_MAPPED (assistant))
843 set_assistant_buttons_state (assistant);
847 remove_page (GtkAssistant *assistant,
850 GtkAssistantPrivate *priv = assistant->priv;
851 GtkAssistantPage *page_info;
854 page_info = element->data;
856 /* If this is the current page, we need to switch away. */
857 if (page_info == priv->current_page)
859 if (!compute_next_step (assistant))
861 /* The best we can do at this point is probably to pick the first
864 page_node = priv->pages;
866 while (page_node && !GTK_WIDGET_VISIBLE (((GtkAssistantPage *) page_node->data)->page))
867 page_node = page_node->next;
870 priv->current_page = page_node->data;
872 priv->current_page = NULL;
876 priv->pages = g_list_remove_link (priv->pages, element);
877 priv->visited_pages = g_slist_remove_all (priv->visited_pages, page_info);
879 g_signal_handlers_disconnect_by_func (page_info->page, on_page_notify_visibility, assistant);
880 gtk_widget_unparent (page_info->page);
882 if (page_info->header_image)
883 g_object_unref (page_info->header_image);
885 if (page_info->sidebar_image)
886 g_object_unref (page_info->sidebar_image);
888 gtk_widget_destroy (page_info->title);
890 g_list_free_1 (element);
894 gtk_assistant_destroy (GtkObject *object)
896 GtkAssistant *assistant = GTK_ASSISTANT (object);
897 GtkAssistantPrivate *priv = assistant->priv;
899 if (priv->header_image)
901 gtk_widget_destroy (priv->header_image);
902 priv->header_image = NULL;
905 if (priv->sidebar_image)
907 gtk_widget_destroy (priv->sidebar_image);
908 priv->sidebar_image = NULL;
911 if (priv->action_area)
913 gtk_widget_destroy (priv->action_area);
914 priv->action_area = NULL;
917 if (priv->size_group)
919 g_object_unref (priv->size_group);
920 priv->size_group = NULL;
923 if (priv->forward_function)
925 if (priv->forward_function_data &&
926 priv->forward_data_destroy)
927 priv->forward_data_destroy (priv->forward_function_data);
929 priv->forward_function = NULL;
930 priv->forward_function_data = NULL;
931 priv->forward_data_destroy = NULL;
934 if (priv->visited_pages)
936 g_slist_free (priv->visited_pages);
937 priv->visited_pages = NULL;
940 /* We set current to NULL so that the remove code doesn't try
941 * to do anything funny */
942 priv->current_page = NULL;
945 remove_page (GTK_ASSISTANT (object), priv->pages);
947 GTK_OBJECT_CLASS (gtk_assistant_parent_class)->destroy (object);
951 find_page (GtkAssistant *assistant,
954 GtkAssistantPrivate *priv = assistant->priv;
955 GList *child = priv->pages;
959 GtkAssistantPage *page_info = child->data;
960 if (page_info->page == page)
970 set_title_colors (GtkWidget *assistant,
971 GtkWidget *title_label)
975 gtk_widget_ensure_style (assistant);
976 style = gtk_widget_get_style (assistant);
978 /* change colors schema, for making the header text visible */
979 gtk_widget_modify_bg (title_label, GTK_STATE_NORMAL, &style->bg[GTK_STATE_SELECTED]);
980 gtk_widget_modify_fg (title_label, GTK_STATE_NORMAL, &style->fg[GTK_STATE_SELECTED]);
984 set_title_font (GtkWidget *assistant,
985 GtkWidget *title_label)
987 PangoFontDescription *desc;
990 desc = pango_font_description_new ();
991 size = pango_font_description_get_size (assistant->style->font_desc);
993 pango_font_description_set_weight (desc, PANGO_WEIGHT_ULTRABOLD);
994 pango_font_description_set_size (desc, size * PANGO_SCALE_XX_LARGE);
996 gtk_widget_modify_font (title_label, desc);
997 pango_font_description_free (desc);
1001 gtk_assistant_style_set (GtkWidget *widget,
1002 GtkStyle *old_style)
1004 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1005 GtkAssistantPrivate *priv = assistant->priv;
1012 GtkAssistantPage *page = list->data;
1014 set_title_colors (widget, page->title);
1015 set_title_font (widget, page->title);
1022 gtk_assistant_size_request (GtkWidget *widget,
1023 GtkRequisition *requisition)
1025 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1026 GtkAssistantPrivate *priv = assistant->priv;
1027 GtkRequisition child_requisition;
1028 gint header_padding, content_padding;
1029 gint width, height, header_width, header_height;
1032 gtk_widget_style_get (widget,
1033 "header-padding", &header_padding,
1034 "content-padding", &content_padding,
1037 header_width = header_height = 0;
1042 GtkAssistantPage *page = list->data;
1045 gtk_widget_size_request (page->page, &child_requisition);
1046 width = MAX (width, child_requisition.width);
1047 height = MAX (height, child_requisition.height);
1049 gtk_widget_size_request (page->title, &child_requisition);
1050 w = child_requisition.width;
1051 h = child_requisition.height;
1053 if (page->header_image)
1055 w += gdk_pixbuf_get_width (page->header_image) + HEADER_SPACING;
1056 h = MAX (h, gdk_pixbuf_get_height (page->header_image));
1059 header_width = MAX (header_width, w);
1060 header_height = MAX (header_height, h);
1065 gtk_widget_size_request (priv->sidebar_image, &child_requisition);
1066 width += child_requisition.width;
1067 height = MAX (height, child_requisition.height);
1069 gtk_widget_set_size_request (priv->header_image, header_width, header_height);
1070 gtk_widget_size_request (priv->header_image, &child_requisition);
1071 width = MAX (width, header_width) + 2 * header_padding;
1072 height += header_height + 2 * header_padding;
1074 gtk_widget_size_request (priv->action_area, &child_requisition);
1075 width = MAX (width, child_requisition.width);
1076 height += child_requisition.height + ACTION_AREA_SPACING;
1078 width += GTK_CONTAINER (widget)->border_width * 2 + content_padding * 2;
1079 height += GTK_CONTAINER (widget)->border_width * 2 + content_padding * 2;
1081 requisition->width = width;
1082 requisition->height = height;
1086 gtk_assistant_size_allocate (GtkWidget *widget,
1087 GtkAllocation *allocation)
1089 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1090 GtkAssistantPrivate *priv = assistant->priv;
1091 GtkRequisition header_requisition;
1092 GtkAllocation child_allocation, header_allocation;
1093 gint header_padding, content_padding;
1097 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1098 pages = priv->pages;
1100 gtk_widget_style_get (widget,
1101 "header-padding", &header_padding,
1102 "content-padding", &content_padding,
1105 widget->allocation = *allocation;
1108 gtk_widget_get_child_requisition (priv->header_image, &header_requisition);
1110 header_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width + header_padding;
1111 header_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width + header_padding;
1112 header_allocation.width = allocation->width - 2 * GTK_CONTAINER (widget)->border_width - 2 * header_padding;
1113 header_allocation.height = header_requisition.height;
1115 gtk_widget_size_allocate (priv->header_image, &header_allocation);
1118 child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width;
1119 child_allocation.y = allocation->y + allocation->height -
1120 GTK_CONTAINER (widget)->border_width - priv->action_area->requisition.height;
1121 child_allocation.width = allocation->width - 2 * GTK_CONTAINER (widget)->border_width;
1122 child_allocation.height = priv->action_area->requisition.height;
1124 gtk_widget_size_allocate (priv->action_area, &child_allocation);
1128 child_allocation.x = allocation->x + allocation->width -
1129 GTK_CONTAINER (widget)->border_width - priv->sidebar_image->requisition.width;
1131 child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width;
1133 child_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width +
1134 priv->header_image->allocation.height + 2 * header_padding;
1135 child_allocation.width = priv->sidebar_image->requisition.width;
1136 child_allocation.height = allocation->height - 2 * GTK_CONTAINER (widget)->border_width -
1137 priv->header_image->allocation.height - 2 * header_padding - priv->action_area->allocation.height;
1139 gtk_widget_size_allocate (priv->sidebar_image, &child_allocation);
1142 child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width + content_padding;
1143 child_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width +
1144 priv->header_image->allocation.height + 2 * header_padding + content_padding;
1145 child_allocation.width = allocation->width - 2 * GTK_CONTAINER (widget)->border_width - 2 * content_padding;
1146 child_allocation.height = allocation->height - 2 * GTK_CONTAINER (widget)->border_width -
1147 priv->header_image->allocation.height - 2 * header_padding - ACTION_AREA_SPACING - priv->action_area->allocation.height - 2 * content_padding;
1149 if (GTK_WIDGET_VISIBLE (priv->sidebar_image))
1152 child_allocation.x += priv->sidebar_image->allocation.width;
1154 child_allocation.width -= priv->sidebar_image->allocation.width;
1159 GtkAssistantPage *page = pages->data;
1161 gtk_widget_size_allocate (page->page, &child_allocation);
1162 gtk_widget_size_allocate (page->title, &header_allocation);
1163 pages = pages->next;
1168 gtk_assistant_map (GtkWidget *widget)
1170 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1171 GtkAssistantPrivate *priv = assistant->priv;
1174 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
1176 gtk_widget_map (priv->header_image);
1177 gtk_widget_map (priv->action_area);
1179 if (GTK_WIDGET_VISIBLE (priv->sidebar_image) &&
1180 !GTK_WIDGET_MAPPED (priv->sidebar_image))
1181 gtk_widget_map (priv->sidebar_image);
1183 /* if there's no default page, pick the first one */
1184 if (!priv->current_page && priv->pages)
1186 page_node = priv->pages;
1188 while (page_node && !GTK_WIDGET_VISIBLE (((GtkAssistantPage *) page_node->data)->page))
1189 page_node = page_node->next;
1192 priv->current_page = page_node->data;
1195 if (priv->current_page &&
1196 GTK_WIDGET_VISIBLE (priv->current_page->page) &&
1197 !GTK_WIDGET_MAPPED (priv->current_page->page))
1199 set_assistant_buttons_state ((GtkAssistant *) widget);
1200 set_assistant_header_image ((GtkAssistant*) widget);
1201 set_assistant_sidebar_image ((GtkAssistant*) widget);
1203 g_signal_emit (widget, signals [PREPARE], 0, priv->current_page->page);
1204 gtk_widget_set_child_visible (priv->current_page->page, TRUE);
1205 gtk_widget_map (priv->current_page->page);
1206 gtk_widget_map (priv->current_page->title);
1209 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->map (widget);
1213 gtk_assistant_unmap (GtkWidget *widget)
1215 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1216 GtkAssistantPrivate *priv = assistant->priv;
1218 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
1220 gtk_widget_unmap (priv->header_image);
1221 gtk_widget_unmap (priv->action_area);
1223 if (GTK_WIDGET_DRAWABLE (priv->sidebar_image))
1224 gtk_widget_unmap (priv->sidebar_image);
1226 if (priv->current_page &&
1227 GTK_WIDGET_DRAWABLE (priv->current_page->page))
1228 gtk_widget_unmap (priv->current_page->page);
1230 g_slist_free (priv->visited_pages);
1231 priv->visited_pages = NULL;
1232 priv->current_page = NULL;
1234 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->unmap (widget);
1238 gtk_assistant_delete_event (GtkWidget *widget,
1241 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1242 GtkAssistantPrivate *priv = assistant->priv;
1244 /* Do not allow cancelling in the middle of a progress page */
1245 if (priv->current_page &&
1246 (priv->current_page->type != GTK_ASSISTANT_PAGE_PROGRESS ||
1247 priv->current_page->complete))
1248 g_signal_emit (widget, signals [CANCEL], 0, NULL);
1254 assistant_paint_colored_box (GtkWidget *widget)
1256 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1257 GtkAssistantPrivate *priv = assistant->priv;
1258 gint border_width, header_padding, content_padding;
1260 gint content_x, content_width;
1263 cr = gdk_cairo_create (widget->window);
1264 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1265 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1267 gtk_widget_style_get (widget,
1268 "header-padding", &header_padding,
1269 "content-padding", &content_padding,
1273 gdk_cairo_set_source_color (cr, &widget->style->bg[GTK_STATE_SELECTED]);
1274 cairo_rectangle (cr,
1277 widget->allocation.width - 2 * border_width,
1278 widget->allocation.height - priv->action_area->allocation.height - 2 * border_width - ACTION_AREA_SPACING);
1282 content_x = content_padding + border_width;
1283 content_width = widget->allocation.width - 2 * content_padding - 2 * border_width;
1285 if (GTK_WIDGET_VISIBLE (priv->sidebar_image))
1288 content_x += priv->sidebar_image->allocation.width;
1289 content_width -= priv->sidebar_image->allocation.width;
1292 gdk_cairo_set_source_color (cr, &widget->style->bg[GTK_STATE_NORMAL]);
1294 cairo_rectangle (cr,
1296 priv->header_image->allocation.height + content_padding + 2 * header_padding + border_width,
1298 widget->allocation.height - 2 * border_width - priv->action_area->allocation.height -
1299 priv->header_image->allocation.height - 2 * content_padding - 2 * header_padding - ACTION_AREA_SPACING);
1306 gtk_assistant_expose (GtkWidget *widget,
1307 GdkEventExpose *event)
1309 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1310 GtkAssistantPrivate *priv = assistant->priv;
1311 GtkContainer *container;
1313 if (GTK_WIDGET_DRAWABLE (widget))
1315 container = GTK_CONTAINER (widget);
1317 assistant_paint_colored_box (widget);
1319 gtk_container_propagate_expose (container, priv->header_image, event);
1320 gtk_container_propagate_expose (container, priv->sidebar_image, event);
1321 gtk_container_propagate_expose (container, priv->action_area, event);
1323 if (priv->current_page)
1325 gtk_container_propagate_expose (container, priv->current_page->page, event);
1326 gtk_container_propagate_expose (container, priv->current_page->title, event);
1334 gtk_assistant_focus (GtkWidget *widget,
1335 GtkDirectionType direction)
1337 GtkAssistantPrivate *priv;
1338 GtkContainer *container;
1340 container = GTK_CONTAINER (widget);
1341 priv = GTK_ASSISTANT (widget)->priv;
1343 /* we only have to care about 2 widgets, action area and the current page */
1344 if (container->focus_child == priv->action_area)
1346 if (!gtk_widget_child_focus (priv->action_area, direction) &&
1347 (priv->current_page == NULL ||
1348 !gtk_widget_child_focus (priv->current_page->page, direction)))
1350 /* if we're leaving the action area and the current page hasn't
1351 any focusable widget, clear focus and go back to the action area */
1352 gtk_container_set_focus_child (GTK_CONTAINER (priv->action_area), NULL);
1353 gtk_widget_child_focus (priv->action_area, direction);
1358 if ((priv->current_page == NULL ||
1359 !gtk_widget_child_focus (priv->current_page->page, direction)) &&
1360 !gtk_widget_child_focus (priv->action_area, direction))
1362 /* if we're leaving the current page and there isn't nothing focusable
1363 in the action area, try to clear focus and go back to the page */
1364 gtk_window_set_focus (GTK_WINDOW (widget), NULL);
1365 if (priv->current_page != NULL)
1366 gtk_widget_child_focus (priv->current_page->page, direction);
1374 gtk_assistant_add (GtkContainer *container,
1377 g_return_if_fail (GTK_IS_WIDGET (page));
1379 gtk_assistant_append_page (GTK_ASSISTANT (container), page);
1383 gtk_assistant_remove (GtkContainer *container,
1386 GtkAssistant *assistant;
1389 assistant = (GtkAssistant*) container;
1391 element = find_page (assistant, page);
1395 remove_page (assistant, element);
1396 gtk_widget_queue_resize ((GtkWidget *) container);
1401 gtk_assistant_forall (GtkContainer *container,
1402 gboolean include_internals,
1403 GtkCallback callback,
1404 gpointer callback_data)
1406 GtkAssistant *assistant = (GtkAssistant*) container;
1407 GtkAssistantPrivate *priv = assistant->priv;
1410 if (include_internals)
1412 (*callback) (priv->header_image, callback_data);
1413 (*callback) (priv->sidebar_image, callback_data);
1414 (*callback) (priv->action_area, callback_data);
1417 pages = priv->pages;
1421 GtkAssistantPage *page = (GtkAssistantPage *) pages->data;
1423 (*callback) (page->page, callback_data);
1425 if (include_internals)
1426 (*callback) (page->title, callback_data);
1428 pages = pages->next;
1433 * gtk_assistant_new:
1435 * Creates a new #GtkAssistant.
1437 * Return value: a newly created #GtkAssistant
1442 gtk_assistant_new (void)
1444 GtkWidget *assistant;
1446 assistant = g_object_new (GTK_TYPE_ASSISTANT,
1453 * gtk_assistant_get_current_page:
1454 * @assistant: a #GtkAssistant
1456 * Returns the page number of the current page
1458 * Return value: The index (starting from 0) of the current page in
1459 * the @assistant, if the @assistant has no pages, -1 will be returned
1464 gtk_assistant_get_current_page (GtkAssistant *assistant)
1466 GtkAssistantPrivate *priv;
1468 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), -1);
1470 priv = assistant->priv;
1472 if (!priv->pages || !priv->current_page)
1475 return g_list_index (priv->pages, priv->current_page);
1479 * gtk_assistant_set_current_page:
1480 * @assistant: a #GtkAssistant
1481 * @page_num: index of the page to switch to, starting from 0.
1482 * If negative, the last page will be used. If greater
1483 * than the number of pages in the @assistant, nothing
1486 * Switches the page to @page_num. Note that this will only be necessary
1487 * in custom buttons, as the @assistant flow can be set with
1488 * gtk_assistant_set_forward_page_func().
1493 gtk_assistant_set_current_page (GtkAssistant *assistant,
1496 GtkAssistantPrivate *priv;
1497 GtkAssistantPage *page;
1499 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1501 priv = assistant->priv;
1504 page = (GtkAssistantPage *) g_list_nth_data (priv->pages, page_num);
1506 page = (GtkAssistantPage *) g_list_last (priv->pages);
1508 g_return_if_fail (page != NULL);
1510 if (priv->current_page == page)
1513 /* only add the page to the visited list if the
1514 * assistant is mapped, if not, just use it as an
1515 * initial page setting, for the cases where the
1516 * initial page is != to 0
1518 if (GTK_WIDGET_MAPPED (assistant))
1519 priv->visited_pages = g_slist_prepend (priv->visited_pages, page);
1521 set_current_page (assistant, page);
1525 * gtk_assistant_get_n_pages:
1526 * @assistant: a #GtkAssistant
1528 * Returns the number of pages in the @assistant
1530 * Return value: The number of pages in the @assistant.
1535 gtk_assistant_get_n_pages (GtkAssistant *assistant)
1537 GtkAssistantPrivate *priv;
1539 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1541 priv = assistant->priv;
1543 return g_list_length (priv->pages);
1547 * gtk_assistant_get_nth_page:
1548 * @assistant: a #GtkAssistant
1549 * @page_num: The index of a page in the @assistant, or -1 to get the last page;
1551 * Returns the child widget contained in page number @page_num.
1553 * Return value: The child widget, or %NULL if @page_num is out of bounds.
1558 gtk_assistant_get_nth_page (GtkAssistant *assistant,
1561 GtkAssistantPrivate *priv;
1562 GtkAssistantPage *page;
1565 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1567 priv = assistant->priv;
1569 elem = g_list_nth (priv->pages, page_num);
1574 page = (GtkAssistantPage *) elem->data;
1580 * gtk_assistant_prepend_page:
1581 * @assistant: a #GtkAssistant
1582 * @page: a #GtkWidget
1584 * Prepends a page to the @assistant.
1586 * Return value: the index (starting at 0) of the inserted page
1591 gtk_assistant_prepend_page (GtkAssistant *assistant,
1594 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1595 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1597 return gtk_assistant_insert_page (assistant, page, 0);
1601 * gtk_assistant_append_page:
1602 * @assistant: a #GtkAssistant
1603 * @page: a #GtkWidget
1605 * Appends a page to the @assistant.
1607 * Return value: the index (starting at 0) of the inserted page
1612 gtk_assistant_append_page (GtkAssistant *assistant,
1615 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1616 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1618 return gtk_assistant_insert_page (assistant, page, -1);
1622 * gtk_assistant_insert_page:
1623 * @assistant: a #GtkAssistant
1624 * @page: a #GtkWidget
1625 * @position: the index (starting at 0) at which to insert the page,
1626 * or -1 to append the page to the @assistant
1628 * Inserts a page in the @assistant at a given position.
1630 * Return value: the index (starting from 0) of the inserted page
1635 gtk_assistant_insert_page (GtkAssistant *assistant,
1639 GtkAssistantPrivate *priv;
1640 GtkAssistantPage *page_info;
1643 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1644 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1645 g_return_val_if_fail (page->parent == NULL, 0);
1646 g_return_val_if_fail (!GTK_WIDGET_TOPLEVEL (page), 0);
1648 priv = assistant->priv;
1650 page_info = g_new0 (GtkAssistantPage, 1);
1651 page_info->page = page;
1652 page_info->title = gtk_label_new (NULL);
1654 g_signal_connect (G_OBJECT (page), "notify::visible",
1655 G_CALLBACK (on_page_notify_visibility), assistant);
1657 gtk_misc_set_alignment (GTK_MISC (page_info->title), 0.,0.5);
1658 set_title_colors (GTK_WIDGET (assistant), page_info->title);
1659 set_title_font (GTK_WIDGET (assistant), page_info->title);
1660 gtk_widget_show (page_info->title);
1662 n_pages = g_list_length (priv->pages);
1664 if (position < 0 || position > n_pages)
1667 priv->pages = g_list_insert (priv->pages, page_info, position);
1669 gtk_widget_set_child_visible (page_info->page, FALSE);
1670 gtk_widget_set_parent (page_info->page, GTK_WIDGET (assistant));
1671 gtk_widget_set_parent (page_info->title, GTK_WIDGET (assistant));
1673 if (GTK_WIDGET_REALIZED (GTK_WIDGET (assistant)))
1675 gtk_widget_realize (page_info->page);
1676 gtk_widget_realize (page_info->title);
1679 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1685 * gtk_assistant_set_forward_page_func:
1686 * @assistant: a #GtkAssistant
1687 * @page_func: the #GtkAssistantPageFunc, or %NULL to use the default one
1688 * @data: user data for @page_func
1689 * @destroy: destroy notifier for @data
1691 * Sets the page forwarding function to be @page_func, this function will
1692 * be used to determine what will be the next page when the user presses
1693 * the forward button. Setting @page_func to %NULL will make the assistant
1694 * to use the default forward function, which just goes to the next visible
1700 gtk_assistant_set_forward_page_func (GtkAssistant *assistant,
1701 GtkAssistantPageFunc page_func,
1703 GDestroyNotify destroy)
1705 GtkAssistantPrivate *priv;
1707 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1709 priv = assistant->priv;
1711 if (priv->forward_data_destroy &&
1712 priv->forward_function_data)
1713 (*priv->forward_data_destroy) (priv->forward_function_data);
1717 priv->forward_function = page_func;
1718 priv->forward_function_data = data;
1719 priv->forward_data_destroy = destroy;
1723 priv->forward_function = default_forward_function;
1724 priv->forward_function_data = assistant;
1725 priv->forward_data_destroy = NULL;
1728 /* Page flow has possibly changed, so the
1729 buttons state might need to change too */
1730 if (priv->current_page)
1731 set_assistant_buttons_state (assistant);
1735 * gtk_assistant_add_action_widget:
1736 * @assistant: a #GtkAssistant
1737 * @child: a #GtkWidget
1739 * Adds a widget to the action area of a #GtkAssistant.
1744 gtk_assistant_add_action_widget (GtkAssistant *assistant,
1747 GtkAssistantPrivate *priv;
1749 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1750 g_return_if_fail (GTK_IS_WIDGET (child));
1752 priv = assistant->priv;
1754 if (GTK_IS_BUTTON (child))
1755 gtk_size_group_add_widget (priv->size_group, child);
1757 gtk_box_pack_end (GTK_BOX (priv->action_area), child, FALSE, FALSE, 0);
1761 * gtk_assistant_remove_action_widget:
1762 * @assistant: a #GtkAssistant
1763 * @child: a #GtkWidget
1765 * Removes a widget from the action area of a #GtkAssistant.
1770 gtk_assistant_remove_action_widget (GtkAssistant *assistant,
1773 GtkAssistantPrivate *priv;
1775 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1776 g_return_if_fail (GTK_IS_WIDGET (child));
1778 priv = assistant->priv;
1780 if (GTK_IS_BUTTON (child))
1781 gtk_size_group_remove_widget (priv->size_group, child);
1783 gtk_container_remove (GTK_CONTAINER (priv->action_area), child);
1787 * gtk_assistant_set_page_title:
1788 * @assistant: a #GtkAssistant
1789 * @page: a page of @assistant
1790 * @title: the new title for @page
1792 * Sets a title for @page. The title is displayed in the header
1793 * area of the assistant when @page is the current page.
1798 gtk_assistant_set_page_title (GtkAssistant *assistant,
1802 GtkAssistantPage *page_info;
1805 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1806 g_return_if_fail (GTK_IS_WIDGET (page));
1808 child = find_page (assistant, page);
1810 g_return_if_fail (child != NULL);
1812 page_info = (GtkAssistantPage*) child->data;
1814 gtk_label_set_text ((GtkLabel*) page_info->title, title);
1815 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1816 gtk_widget_child_notify (page, "title");
1820 * gtk_assistant_get_page_title:
1821 * @assistant: a #GtkAssistant
1822 * @page: a page of @assistant
1824 * Gets the title for @page.
1826 * Return value: the title for @page.
1830 G_CONST_RETURN gchar*
1831 gtk_assistant_get_page_title (GtkAssistant *assistant,
1834 GtkAssistantPage *page_info;
1837 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1838 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1840 child = find_page (assistant, page);
1842 g_return_val_if_fail (child != NULL, NULL);
1844 page_info = (GtkAssistantPage*) child->data;
1846 return gtk_label_get_text ((GtkLabel*) page_info->title);
1850 * gtk_assistant_set_page_type:
1851 * @assistant: a #GtkAssistant
1852 * @page: a page of @assistant
1853 * @type: the new type for @page
1855 * Sets the page type for @page. The page type determines the page
1856 * behavior in the @assistant.
1861 gtk_assistant_set_page_type (GtkAssistant *assistant,
1863 GtkAssistantPageType type)
1865 GtkAssistantPrivate *priv;
1866 GtkAssistantPage *page_info;
1869 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1870 g_return_if_fail (GTK_IS_WIDGET (page));
1872 priv = assistant->priv;
1873 child = find_page (assistant, page);
1875 g_return_if_fail (child != NULL);
1877 page_info = (GtkAssistantPage*) child->data;
1879 if (type != page_info->type)
1881 page_info->type = type;
1883 /* Always set buttons state, a change in a future page
1884 might change current page buttons */
1885 if (priv->current_page)
1886 set_assistant_buttons_state (assistant);
1888 gtk_widget_child_notify (page, "page-type");
1893 * gtk_assistant_get_page_type:
1894 * @assistant: a #GtkAssistant
1895 * @page: a page of @assistant
1897 * Gets the page type of @page.
1899 * Return value: the page type of @page.
1903 GtkAssistantPageType
1904 gtk_assistant_get_page_type (GtkAssistant *assistant,
1907 GtkAssistantPage *page_info;
1910 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), GTK_ASSISTANT_PAGE_CONTENT);
1911 g_return_val_if_fail (GTK_IS_WIDGET (page), GTK_ASSISTANT_PAGE_CONTENT);
1913 child = find_page (assistant, page);
1915 g_return_val_if_fail (child != NULL, GTK_ASSISTANT_PAGE_CONTENT);
1917 page_info = (GtkAssistantPage*) child->data;
1919 return page_info->type;
1923 * gtk_assistant_set_page_header_image:
1924 * @assistant: a #GtkAssistant
1925 * @page: a page of @assistant
1926 * @pixbuf: the new header image @page
1928 * Sets a header image for @page. This image is displayed in the header
1929 * area of the assistant when @page is the current page.
1934 gtk_assistant_set_page_header_image (GtkAssistant *assistant,
1938 GtkAssistantPrivate *priv;
1939 GtkAssistantPage *page_info;
1942 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1943 g_return_if_fail (GTK_IS_WIDGET (page));
1944 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1946 priv = assistant->priv;
1947 child = find_page (assistant, page);
1949 g_return_if_fail (child != NULL);
1951 page_info = (GtkAssistantPage*) child->data;
1953 if (pixbuf != page_info->header_image)
1955 if (page_info->header_image)
1957 g_object_unref (page_info->header_image);
1958 page_info->header_image = NULL;
1962 page_info->header_image = g_object_ref (pixbuf);
1964 if (page_info == priv->current_page)
1965 set_assistant_header_image (assistant);
1967 gtk_widget_child_notify (page, "header-image");
1972 * gtk_assistant_get_page_header_image:
1973 * @assistant: a #GtkAssistant
1974 * @page: a page of @assistant
1976 * Gets the header image for @page.
1978 * Return value: the header image for @page, or %NULL
1979 * if there's no header image for the page.
1984 gtk_assistant_get_page_header_image (GtkAssistant *assistant,
1987 GtkAssistantPage *page_info;
1990 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1991 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1993 child = find_page (assistant, page);
1995 g_return_val_if_fail (child != NULL, NULL);
1997 page_info = (GtkAssistantPage*) child->data;
1999 return page_info->header_image;
2003 * gtk_assistant_set_page_side_image:
2004 * @assistant: a #GtkAssistant
2005 * @page: a page of @assistant
2006 * @pixbuf: the new header image @page
2008 * Sets a header image for @page. This image is displayed in the side
2009 * area of the assistant when @page is the current page.
2014 gtk_assistant_set_page_side_image (GtkAssistant *assistant,
2018 GtkAssistantPrivate *priv;
2019 GtkAssistantPage *page_info;
2022 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2023 g_return_if_fail (GTK_IS_WIDGET (page));
2024 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2026 priv = assistant->priv;
2027 child = find_page (assistant, page);
2029 g_return_if_fail (child != NULL);
2031 page_info = (GtkAssistantPage*) child->data;
2033 if (pixbuf != page_info->sidebar_image)
2035 if (page_info->sidebar_image)
2037 g_object_unref (page_info->sidebar_image);
2038 page_info->sidebar_image = NULL;
2042 page_info->sidebar_image = g_object_ref (pixbuf);
2044 if (page_info == priv->current_page)
2045 set_assistant_sidebar_image (assistant);
2047 gtk_widget_child_notify (page, "sidebar-image");
2052 * gtk_assistant_get_page_side_image:
2053 * @assistant: a #GtkAssistant
2054 * @page: a page of @assistant
2056 * Gets the header image for @page.
2058 * Return value: the side image for @page, or %NULL
2059 * if there's no side image for the page.
2064 gtk_assistant_get_page_side_image (GtkAssistant *assistant,
2067 GtkAssistantPage *page_info;
2070 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2071 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2073 child = find_page (assistant, page);
2075 g_return_val_if_fail (child != NULL, NULL);
2077 page_info = (GtkAssistantPage*) child->data;
2079 return page_info->sidebar_image;
2083 * gtk_assistant_set_page_complete:
2084 * @assistant: a #GtkAssistant
2085 * @page: a page of @assistant
2086 * @complete: the completeness status of the page
2088 * Sets whether @page contents are complete. This will make
2089 * @assistant update the buttons state to be able to continue the task.
2094 gtk_assistant_set_page_complete (GtkAssistant *assistant,
2098 GtkAssistantPrivate *priv;
2099 GtkAssistantPage *page_info;
2102 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2103 g_return_if_fail (GTK_IS_WIDGET (page));
2105 priv = assistant->priv;
2106 child = find_page (assistant, page);
2108 g_return_if_fail (child != NULL);
2110 page_info = (GtkAssistantPage*) child->data;
2112 if (complete != page_info->complete)
2114 page_info->complete = complete;
2116 /* Always set buttons state, a change in a future page
2117 might change current page buttons */
2118 if (priv->current_page)
2119 set_assistant_buttons_state (assistant);
2121 gtk_widget_child_notify (page, "complete");
2126 * gtk_assistant_get_page_complete:
2127 * @assistant: a #GtkAssistant
2128 * @page: a page of @assistant
2130 * Gets whether @page is complete..
2132 * Return value: %TRUE if @page is complete.
2137 gtk_assistant_get_page_complete (GtkAssistant *assistant,
2140 GtkAssistantPage *page_info;
2143 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), FALSE);
2144 g_return_val_if_fail (GTK_IS_WIDGET (page), FALSE);
2146 child = find_page (assistant, page);
2148 g_return_val_if_fail (child != NULL, FALSE);
2150 page_info = (GtkAssistantPage*) child->data;
2152 return page_info->complete;
2156 * gtk_assistant_update_buttons_state:
2157 * @assistant: a #GtkAssistant
2159 * Forces @assistant to recompute the buttons state.
2161 * GTK+ automatically takes care of this in most situations,
2162 * e.g. when the user goes to a different page, or when the
2163 * visibility or completeness of a page changes.
2165 * One situation where it can be necessary to call this
2166 * function is when changing a value on the current page
2167 * affects the future page flow of the assistant.
2172 gtk_assistant_update_buttons_state (GtkAssistant *assistant)
2174 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2176 set_assistant_buttons_state (assistant);
2181 /* accessible implementation */
2184 gtk_assistant_accessible_get_n_children (AtkObject *accessible)
2186 GtkAssistant *assistant;
2189 widget = GTK_ACCESSIBLE (accessible)->widget;
2194 assistant = GTK_ASSISTANT (widget);
2196 return g_list_length (assistant->priv->pages) + 1;
2201 gtk_assistant_accessible_ref_child (AtkObject *accessible,
2204 GtkAssistant *assistant;
2205 GtkAssistantPrivate *priv;
2206 GtkWidget *widget, *child;
2210 widget = GTK_ACCESSIBLE (accessible)->widget;
2214 assistant = GTK_ASSISTANT (widget);
2215 priv = assistant->priv;
2216 n_pages = g_list_length (priv->pages);
2220 else if (index < n_pages)
2222 GtkAssistantPage *page = g_list_nth_data (priv->pages, index / 2);
2226 else if (index == n_pages)
2228 child = priv->action_area;
2233 obj = gtk_widget_get_accessible (child);
2235 return g_object_ref (obj);
2239 gtk_assistant_accessible_class_init (AtkObjectClass *class)
2241 class->get_n_children = gtk_assistant_accessible_get_n_children;
2242 class->ref_child = gtk_assistant_accessible_ref_child;
2246 gtk_assistant_accessible_get_type (void)
2248 static GType type = 0;
2253 * Figure out the size of the class and instance
2254 * we are deriving from
2256 AtkObjectFactory *factory;
2259 GType derived_atk_type;
2261 derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
2262 factory = atk_registry_get_factory (atk_get_default_registry (),
2264 derived_atk_type = atk_object_factory_get_accessible_type (factory);
2265 g_type_query (derived_atk_type, &query);
2267 type = g_type_register_static_simple (derived_atk_type,
2268 "GtkAssistantAccessible",
2270 (GClassInitFunc) gtk_assistant_accessible_class_init,
2271 query.instance_size,
2279 gtk_assistant_accessible_new (GObject *obj)
2281 AtkObject *accessible;
2283 g_return_val_if_fail (GTK_IS_ASSISTANT (obj), NULL);
2285 accessible = g_object_new (gtk_assistant_accessible_get_type (), NULL);
2286 atk_object_initialize (accessible, obj);
2292 gtk_assistant_accessible_factory_get_accessible_type (void)
2294 return gtk_assistant_accessible_get_type ();
2298 gtk_assistant_accessible_factory_create_accessible (GObject *obj)
2300 return gtk_assistant_accessible_new (obj);
2304 gtk_assistant_accessible_factory_class_init (AtkObjectFactoryClass *class)
2306 class->create_accessible = gtk_assistant_accessible_factory_create_accessible;
2307 class->get_accessible_type = gtk_assistant_accessible_factory_get_accessible_type;
2311 gtk_assistant_accessible_factory_get_type (void)
2313 static GType type = 0;
2317 type = g_type_register_static_simple (ATK_TYPE_OBJECT_FACTORY,
2318 "GtkAssistantAccessibleFactory",
2319 sizeof (AtkObjectFactoryClass),
2320 (GClassInitFunc) gtk_assistant_accessible_factory_class_init,
2321 sizeof (AtkObjectFactory),
2329 gtk_assistant_get_accessible (GtkWidget *widget)
2331 static gboolean first_time = TRUE;
2335 AtkObjectFactory *factory;
2336 AtkRegistry *registry;
2338 GType derived_atk_type;
2341 * Figure out whether accessibility is enabled by looking at the
2342 * type of the accessible object which would be created for
2343 * the parent type of GtkAssistant.
2345 derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
2347 registry = atk_get_default_registry ();
2348 factory = atk_registry_get_factory (registry,
2350 derived_atk_type = atk_object_factory_get_accessible_type (factory);
2351 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
2353 atk_registry_set_factory_type (registry,
2355 gtk_assistant_accessible_factory_get_type ());
2360 return GTK_WIDGET_CLASS (gtk_assistant_parent_class)->get_accessible (widget);
2364 #define __GTK_ASSISTANT_C__
2365 #include "gtkaliasdef.c"