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_widget_push_composite_child ();
684 priv->header_image = gtk_image_new ();
685 gtk_misc_set_alignment (GTK_MISC (priv->header_image), 1., 0.5);
686 gtk_widget_set_parent (priv->header_image, GTK_WIDGET (assistant));
687 gtk_widget_show (priv->header_image);
690 priv->sidebar_image = gtk_image_new ();
691 gtk_misc_set_alignment (GTK_MISC (priv->sidebar_image), 0., 0.);
692 gtk_widget_set_parent (priv->sidebar_image, GTK_WIDGET (assistant));
693 gtk_widget_show (priv->sidebar_image);
696 priv->action_area = gtk_hbox_new (FALSE, 6);
698 assistant->close = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
699 assistant->apply = gtk_button_new_from_stock (GTK_STOCK_APPLY);
700 assistant->forward = gtk_button_new_from_stock (GTK_STOCK_GO_FORWARD);
701 assistant->back = gtk_button_new_from_stock (GTK_STOCK_GO_BACK);
702 assistant->cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
703 assistant->last = gtk_button_new_from_stock (GTK_STOCK_GOTO_LAST);
705 priv->size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
706 gtk_size_group_add_widget (priv->size_group, assistant->close);
707 gtk_size_group_add_widget (priv->size_group, assistant->apply);
708 gtk_size_group_add_widget (priv->size_group, assistant->forward);
709 gtk_size_group_add_widget (priv->size_group, assistant->back);
710 gtk_size_group_add_widget (priv->size_group, assistant->cancel);
711 gtk_size_group_add_widget (priv->size_group, assistant->last);
713 if (!alternative_button_order (assistant))
715 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->apply, FALSE, FALSE, 0);
716 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->forward, FALSE, FALSE, 0);
717 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->back, FALSE, FALSE, 0);
718 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->last, FALSE, FALSE, 0);
719 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->cancel, FALSE, FALSE, 0);
720 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->close, FALSE, FALSE, 0);
724 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->close, FALSE, FALSE, 0);
725 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->cancel, FALSE, FALSE, 0);
726 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->last, FALSE, FALSE, 0);
727 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->back, FALSE, FALSE, 0);
728 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->forward, FALSE, FALSE, 0);
729 gtk_box_pack_end (GTK_BOX (priv->action_area), assistant->apply, FALSE, FALSE, 0);
732 gtk_widget_set_parent (priv->action_area, GTK_WIDGET (assistant));
733 gtk_widget_show (assistant->forward);
734 gtk_widget_show (assistant->back);
735 gtk_widget_show (assistant->cancel);
736 gtk_widget_show (priv->action_area);
738 gtk_widget_pop_composite_child ();
741 priv->current_page = NULL;
742 priv->visited_pages = NULL;
744 priv->forward_function = default_forward_function;
745 priv->forward_function_data = assistant;
746 priv->forward_data_destroy = NULL;
748 g_signal_connect (G_OBJECT (assistant->close), "clicked",
749 G_CALLBACK (on_assistant_close), assistant);
750 g_signal_connect (G_OBJECT (assistant->apply), "clicked",
751 G_CALLBACK (on_assistant_apply), assistant);
752 g_signal_connect (G_OBJECT (assistant->forward), "clicked",
753 G_CALLBACK (on_assistant_forward), assistant);
754 g_signal_connect (G_OBJECT (assistant->back), "clicked",
755 G_CALLBACK (on_assistant_back), assistant);
756 g_signal_connect (G_OBJECT (assistant->cancel), "clicked",
757 G_CALLBACK (on_assistant_cancel), assistant);
758 g_signal_connect (G_OBJECT (assistant->last), "clicked",
759 G_CALLBACK (on_assistant_last), assistant);
763 gtk_assistant_set_child_property (GtkContainer *container,
771 case CHILD_PROP_PAGE_TYPE:
772 gtk_assistant_set_page_type (GTK_ASSISTANT (container), child,
773 g_value_get_enum (value));
775 case CHILD_PROP_PAGE_TITLE:
776 gtk_assistant_set_page_title (GTK_ASSISTANT (container), child,
777 g_value_get_string (value));
779 case CHILD_PROP_PAGE_HEADER_IMAGE:
780 gtk_assistant_set_page_header_image (GTK_ASSISTANT (container), child,
781 g_value_get_object (value));
783 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
784 gtk_assistant_set_page_side_image (GTK_ASSISTANT (container), child,
785 g_value_get_object (value));
787 case CHILD_PROP_PAGE_COMPLETE:
788 gtk_assistant_set_page_complete (GTK_ASSISTANT (container), child,
789 g_value_get_boolean (value));
792 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
798 gtk_assistant_get_child_property (GtkContainer *container,
806 case CHILD_PROP_PAGE_TYPE:
807 g_value_set_enum (value,
808 gtk_assistant_get_page_type (GTK_ASSISTANT (container), child));
810 case CHILD_PROP_PAGE_TITLE:
811 g_value_set_string (value,
812 gtk_assistant_get_page_title (GTK_ASSISTANT (container), child));
814 case CHILD_PROP_PAGE_HEADER_IMAGE:
815 g_value_set_object (value,
816 gtk_assistant_get_page_header_image (GTK_ASSISTANT (container), child));
818 case CHILD_PROP_PAGE_SIDEBAR_IMAGE:
819 g_value_set_object (value,
820 gtk_assistant_get_page_side_image (GTK_ASSISTANT (container), child));
822 case CHILD_PROP_PAGE_COMPLETE:
823 g_value_set_boolean (value,
824 gtk_assistant_get_page_complete (GTK_ASSISTANT (container), child));
827 GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
833 on_page_notify_visibility (GtkWidget *widget,
837 GtkAssistant *assistant = GTK_ASSISTANT (data);
839 /* update buttons state, flow may have changed */
840 if (GTK_WIDGET_MAPPED (assistant))
841 set_assistant_buttons_state (assistant);
845 remove_page (GtkAssistant *assistant,
848 GtkAssistantPrivate *priv = assistant->priv;
849 GtkAssistantPage *page_info;
851 page_info = element->data;
853 /* If we are mapped and visible, we want to deal with changing the page. */
854 if ((GTK_WIDGET_MAPPED (page_info->page)) && (page_info == priv->current_page))
855 compute_next_step (assistant);
857 priv->pages = g_list_remove_link (priv->pages, element);
858 priv->visited_pages = g_slist_remove_all (priv->visited_pages, page_info);
860 g_signal_handlers_disconnect_by_func (page_info->page, on_page_notify_visibility, assistant);
861 gtk_widget_unparent (page_info->page);
863 if (page_info->header_image)
864 g_object_unref (page_info->header_image);
866 if (page_info->sidebar_image)
867 g_object_unref (page_info->sidebar_image);
869 gtk_widget_destroy (page_info->title);
871 g_list_free_1 (element);
875 gtk_assistant_destroy (GtkObject *object)
877 GtkAssistant *assistant = GTK_ASSISTANT (object);
878 GtkAssistantPrivate *priv = assistant->priv;
880 if (priv->header_image)
882 gtk_widget_destroy (priv->header_image);
883 priv->header_image = NULL;
886 if (priv->sidebar_image)
888 gtk_widget_destroy (priv->sidebar_image);
889 priv->sidebar_image = NULL;
892 if (priv->action_area)
894 gtk_widget_destroy (priv->action_area);
895 priv->action_area = NULL;
898 if (priv->size_group)
900 g_object_unref (priv->size_group);
901 priv->size_group = NULL;
904 if (priv->forward_function)
906 if (priv->forward_function_data &&
907 priv->forward_data_destroy)
908 priv->forward_data_destroy (priv->forward_function_data);
910 priv->forward_function = NULL;
911 priv->forward_function_data = NULL;
912 priv->forward_data_destroy = NULL;
915 if (priv->visited_pages)
917 g_slist_free (priv->visited_pages);
918 priv->visited_pages = NULL;
921 /* We set current to NULL so that the remove code doesn't try
922 * to do anything funny */
923 priv->current_page = NULL;
926 remove_page (GTK_ASSISTANT (object), priv->pages);
928 GTK_OBJECT_CLASS (gtk_assistant_parent_class)->destroy (object);
932 find_page (GtkAssistant *assistant,
935 GtkAssistantPrivate *priv = assistant->priv;
936 GList *child = priv->pages;
940 GtkAssistantPage *page_info = child->data;
941 if (page_info->page == page)
951 set_title_colors (GtkWidget *assistant,
952 GtkWidget *title_label)
956 gtk_widget_ensure_style (assistant);
957 style = gtk_widget_get_style (assistant);
959 /* change colors schema, for making the header text visible */
960 gtk_widget_modify_bg (title_label, GTK_STATE_NORMAL, &style->bg[GTK_STATE_SELECTED]);
961 gtk_widget_modify_fg (title_label, GTK_STATE_NORMAL, &style->fg[GTK_STATE_SELECTED]);
965 set_title_font (GtkWidget *assistant,
966 GtkWidget *title_label)
968 PangoFontDescription *desc;
971 desc = pango_font_description_new ();
972 size = pango_font_description_get_size (assistant->style->font_desc);
974 pango_font_description_set_weight (desc, PANGO_WEIGHT_ULTRABOLD);
975 pango_font_description_set_size (desc, size * PANGO_SCALE_XX_LARGE);
977 gtk_widget_modify_font (title_label, desc);
978 pango_font_description_free (desc);
982 gtk_assistant_style_set (GtkWidget *widget,
985 GtkAssistant *assistant = GTK_ASSISTANT (widget);
986 GtkAssistantPrivate *priv = assistant->priv;
993 GtkAssistantPage *page = list->data;
995 set_title_colors (widget, page->title);
996 set_title_font (widget, page->title);
1003 gtk_assistant_size_request (GtkWidget *widget,
1004 GtkRequisition *requisition)
1006 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1007 GtkAssistantPrivate *priv = assistant->priv;
1008 GtkRequisition child_requisition;
1009 gint header_padding, content_padding;
1010 gint width, height, header_width, header_height;
1013 gtk_widget_style_get (widget,
1014 "header-padding", &header_padding,
1015 "content-padding", &content_padding,
1018 header_width = header_height = 0;
1023 GtkAssistantPage *page = list->data;
1026 gtk_widget_size_request (page->page, &child_requisition);
1027 width = MAX (width, child_requisition.width);
1028 height = MAX (height, child_requisition.height);
1030 gtk_widget_size_request (page->title, &child_requisition);
1031 w = child_requisition.width;
1032 h = child_requisition.height;
1034 if (page->header_image)
1036 w += gdk_pixbuf_get_width (page->header_image) + HEADER_SPACING;
1037 h = MAX (h, gdk_pixbuf_get_height (page->header_image));
1040 header_width = MAX (header_width, w);
1041 header_height = MAX (header_height, h);
1046 gtk_widget_size_request (priv->sidebar_image, &child_requisition);
1047 width += child_requisition.width;
1048 height = MAX (height, child_requisition.height);
1050 gtk_widget_set_size_request (priv->header_image, header_width, header_height);
1051 gtk_widget_size_request (priv->header_image, &child_requisition);
1052 width = MAX (width, header_width) + 2 * header_padding;
1053 height += header_height + 2 * header_padding;
1055 gtk_widget_size_request (priv->action_area, &child_requisition);
1056 width = MAX (width, child_requisition.width);
1057 height += child_requisition.height + ACTION_AREA_SPACING;
1059 width += GTK_CONTAINER (widget)->border_width * 2 + content_padding * 2;
1060 height += GTK_CONTAINER (widget)->border_width * 2 + content_padding * 2;
1062 requisition->width = width;
1063 requisition->height = height;
1067 gtk_assistant_size_allocate (GtkWidget *widget,
1068 GtkAllocation *allocation)
1070 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1071 GtkAssistantPrivate *priv = assistant->priv;
1072 GtkRequisition header_requisition;
1073 GtkAllocation child_allocation, header_allocation;
1074 gint header_padding, content_padding;
1078 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1079 pages = priv->pages;
1081 gtk_widget_style_get (widget,
1082 "header-padding", &header_padding,
1083 "content-padding", &content_padding,
1086 widget->allocation = *allocation;
1089 gtk_widget_get_child_requisition (priv->header_image, &header_requisition);
1091 header_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width + header_padding;
1092 header_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width + header_padding;
1093 header_allocation.width = allocation->width - 2 * GTK_CONTAINER (widget)->border_width - 2 * header_padding;
1094 header_allocation.height = header_requisition.height;
1096 gtk_widget_size_allocate (priv->header_image, &header_allocation);
1099 child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width;
1100 child_allocation.y = allocation->y + allocation->height -
1101 GTK_CONTAINER (widget)->border_width - priv->action_area->requisition.height;
1102 child_allocation.width = allocation->width - 2 * GTK_CONTAINER (widget)->border_width;
1103 child_allocation.height = priv->action_area->requisition.height;
1105 gtk_widget_size_allocate (priv->action_area, &child_allocation);
1109 child_allocation.x = allocation->x + allocation->width -
1110 GTK_CONTAINER (widget)->border_width - priv->sidebar_image->requisition.width;
1112 child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width;
1114 child_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width +
1115 priv->header_image->allocation.height + 2 * header_padding;
1116 child_allocation.width = priv->sidebar_image->requisition.width;
1117 child_allocation.height = allocation->height - 2 * GTK_CONTAINER (widget)->border_width -
1118 priv->header_image->allocation.height - 2 * header_padding - priv->action_area->allocation.height;
1120 gtk_widget_size_allocate (priv->sidebar_image, &child_allocation);
1123 child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width + content_padding;
1124 child_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width +
1125 priv->header_image->allocation.height + 2 * header_padding + content_padding;
1126 child_allocation.width = allocation->width - 2 * GTK_CONTAINER (widget)->border_width - 2 * content_padding;
1127 child_allocation.height = allocation->height - 2 * GTK_CONTAINER (widget)->border_width -
1128 priv->header_image->allocation.height - 2 * header_padding - ACTION_AREA_SPACING - priv->action_area->allocation.height - 2 * content_padding;
1130 if (GTK_WIDGET_VISIBLE (priv->sidebar_image))
1133 child_allocation.x += priv->sidebar_image->allocation.width;
1135 child_allocation.width -= priv->sidebar_image->allocation.width;
1140 GtkAssistantPage *page = pages->data;
1142 gtk_widget_size_allocate (page->page, &child_allocation);
1143 gtk_widget_size_allocate (page->title, &header_allocation);
1144 pages = pages->next;
1149 gtk_assistant_map (GtkWidget *widget)
1151 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1152 GtkAssistantPrivate *priv = assistant->priv;
1155 GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
1157 gtk_widget_map (priv->header_image);
1158 gtk_widget_map (priv->action_area);
1160 if (GTK_WIDGET_VISIBLE (priv->sidebar_image) &&
1161 !GTK_WIDGET_MAPPED (priv->sidebar_image))
1162 gtk_widget_map (priv->sidebar_image);
1164 /* if there's no default page, pick the first one */
1165 if (!priv->current_page && priv->pages)
1167 page_node = priv->pages;
1169 while (page_node && !GTK_WIDGET_VISIBLE (((GtkAssistantPage *) page_node->data)->page))
1170 page_node = page_node->next;
1173 priv->current_page = page_node->data;
1176 if (priv->current_page &&
1177 GTK_WIDGET_VISIBLE (priv->current_page->page) &&
1178 !GTK_WIDGET_MAPPED (priv->current_page->page))
1180 set_assistant_buttons_state ((GtkAssistant *) widget);
1181 set_assistant_header_image ((GtkAssistant*) widget);
1182 set_assistant_sidebar_image ((GtkAssistant*) widget);
1184 g_signal_emit (widget, signals [PREPARE], 0, priv->current_page->page);
1185 gtk_widget_set_child_visible (priv->current_page->page, TRUE);
1186 gtk_widget_map (priv->current_page->page);
1187 gtk_widget_map (priv->current_page->title);
1190 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->map (widget);
1194 gtk_assistant_unmap (GtkWidget *widget)
1196 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1197 GtkAssistantPrivate *priv = assistant->priv;
1199 GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
1201 gtk_widget_unmap (priv->header_image);
1202 gtk_widget_unmap (priv->action_area);
1204 if (GTK_WIDGET_DRAWABLE (priv->sidebar_image))
1205 gtk_widget_unmap (priv->sidebar_image);
1207 if (priv->current_page &&
1208 GTK_WIDGET_DRAWABLE (priv->current_page->page))
1209 gtk_widget_unmap (priv->current_page->page);
1211 g_slist_free (priv->visited_pages);
1212 priv->visited_pages = NULL;
1213 priv->current_page = NULL;
1215 GTK_WIDGET_CLASS (gtk_assistant_parent_class)->unmap (widget);
1219 gtk_assistant_delete_event (GtkWidget *widget,
1222 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1223 GtkAssistantPrivate *priv = assistant->priv;
1225 /* Do not allow cancelling in the middle of a progress page */
1226 if (priv->current_page &&
1227 (priv->current_page->type != GTK_ASSISTANT_PAGE_PROGRESS ||
1228 priv->current_page->complete))
1229 g_signal_emit (widget, signals [CANCEL], 0, NULL);
1235 assistant_paint_colored_box (GtkWidget *widget)
1237 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1238 GtkAssistantPrivate *priv = assistant->priv;
1239 gint border_width, header_padding, content_padding;
1241 gint content_x, content_width;
1244 cr = gdk_cairo_create (widget->window);
1245 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1246 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
1248 gtk_widget_style_get (widget,
1249 "header-padding", &header_padding,
1250 "content-padding", &content_padding,
1254 gdk_cairo_set_source_color (cr, &widget->style->bg[GTK_STATE_SELECTED]);
1255 cairo_rectangle (cr,
1258 widget->allocation.width - 2 * border_width,
1259 widget->allocation.height - priv->action_area->allocation.height - 2 * border_width - ACTION_AREA_SPACING);
1263 content_x = content_padding + border_width;
1264 content_width = widget->allocation.width - 2 * content_padding - 2 * border_width;
1266 if (GTK_WIDGET_VISIBLE (priv->sidebar_image))
1269 content_x += priv->sidebar_image->allocation.width;
1270 content_width -= priv->sidebar_image->allocation.width;
1273 gdk_cairo_set_source_color (cr, &widget->style->bg[GTK_STATE_NORMAL]);
1275 cairo_rectangle (cr,
1277 priv->header_image->allocation.height + content_padding + 2 * header_padding + border_width,
1279 widget->allocation.height - 2 * border_width - priv->action_area->allocation.height -
1280 priv->header_image->allocation.height - 2 * content_padding - 2 * header_padding - ACTION_AREA_SPACING);
1287 gtk_assistant_expose (GtkWidget *widget,
1288 GdkEventExpose *event)
1290 GtkAssistant *assistant = GTK_ASSISTANT (widget);
1291 GtkAssistantPrivate *priv = assistant->priv;
1292 GtkContainer *container;
1294 if (GTK_WIDGET_DRAWABLE (widget))
1296 container = GTK_CONTAINER (widget);
1298 assistant_paint_colored_box (widget);
1300 gtk_container_propagate_expose (container, priv->header_image, event);
1301 gtk_container_propagate_expose (container, priv->sidebar_image, event);
1302 gtk_container_propagate_expose (container, priv->action_area, event);
1304 if (priv->current_page)
1306 gtk_container_propagate_expose (container, priv->current_page->page, event);
1307 gtk_container_propagate_expose (container, priv->current_page->title, event);
1315 gtk_assistant_focus (GtkWidget *widget,
1316 GtkDirectionType direction)
1318 GtkAssistantPrivate *priv;
1319 GtkContainer *container;
1321 container = GTK_CONTAINER (widget);
1322 priv = GTK_ASSISTANT (widget)->priv;
1324 /* we only have to care about 2 widgets, action area and the current page */
1325 if (container->focus_child == priv->action_area)
1327 if (!gtk_widget_child_focus (priv->action_area, direction) &&
1328 (priv->current_page == NULL ||
1329 !gtk_widget_child_focus (priv->current_page->page, direction)))
1331 /* if we're leaving the action area and the current page hasn't
1332 any focusable widget, clear focus and go back to the action area */
1333 gtk_container_set_focus_child (GTK_CONTAINER (priv->action_area), NULL);
1334 gtk_widget_child_focus (priv->action_area, direction);
1339 if ((priv->current_page == NULL ||
1340 !gtk_widget_child_focus (priv->current_page->page, direction)) &&
1341 !gtk_widget_child_focus (priv->action_area, direction))
1343 /* if we're leaving the current page and there isn't nothing focusable
1344 in the action area, try to clear focus and go back to the page */
1345 gtk_window_set_focus (GTK_WINDOW (widget), NULL);
1346 if (priv->current_page != NULL)
1347 gtk_widget_child_focus (priv->current_page->page, direction);
1355 gtk_assistant_add (GtkContainer *container,
1358 g_return_if_fail (GTK_IS_WIDGET (page));
1360 gtk_assistant_append_page (GTK_ASSISTANT (container), page);
1364 gtk_assistant_remove (GtkContainer *container,
1367 GtkAssistant *assistant;
1370 assistant = (GtkAssistant*) container;
1372 element = find_page (assistant, page);
1376 remove_page (assistant, element);
1377 gtk_widget_queue_resize ((GtkWidget *) container);
1382 gtk_assistant_forall (GtkContainer *container,
1383 gboolean include_internals,
1384 GtkCallback callback,
1385 gpointer callback_data)
1387 GtkAssistant *assistant = (GtkAssistant*) container;
1388 GtkAssistantPrivate *priv = assistant->priv;
1391 if (include_internals)
1393 (*callback) (priv->header_image, callback_data);
1394 (*callback) (priv->sidebar_image, callback_data);
1395 (*callback) (priv->action_area, callback_data);
1398 pages = priv->pages;
1402 GtkAssistantPage *page = (GtkAssistantPage *) pages->data;
1404 (*callback) (page->page, callback_data);
1406 if (include_internals)
1407 (*callback) (page->title, callback_data);
1409 pages = pages->next;
1414 * gtk_assistant_new:
1416 * Creates a new #GtkAssistant.
1418 * Return value: a newly created #GtkAssistant
1423 gtk_assistant_new (void)
1425 GtkWidget *assistant;
1427 assistant = g_object_new (GTK_TYPE_ASSISTANT,
1434 * gtk_assistant_get_current_page:
1435 * @assistant: a #GtkAssistant
1437 * Returns the page number of the current page
1439 * Return value: The index (starting from 0) of the current page in
1440 * the @assistant, if the @assistant has no pages, -1 will be returned
1445 gtk_assistant_get_current_page (GtkAssistant *assistant)
1447 GtkAssistantPrivate *priv;
1449 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), -1);
1451 priv = assistant->priv;
1453 if (!priv->pages || !priv->current_page)
1456 return g_list_index (priv->pages, priv->current_page);
1460 * gtk_assistant_set_current_page:
1461 * @assistant: a #GtkAssistant
1462 * @page_num: index of the page to switch to, starting from 0.
1463 * If negative, the last page will be used. If greater
1464 * than the number of pages in the @assistant, nothing
1467 * Switches the page to @page_num. Note that this will only be necessary
1468 * in custom buttons, as the @assistant flow can be set with
1469 * gtk_assistant_set_forward_page_func().
1474 gtk_assistant_set_current_page (GtkAssistant *assistant,
1477 GtkAssistantPrivate *priv;
1478 GtkAssistantPage *page;
1480 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1482 priv = assistant->priv;
1485 page = (GtkAssistantPage *) g_list_nth_data (priv->pages, page_num);
1487 page = (GtkAssistantPage *) g_list_last (priv->pages);
1489 g_return_if_fail (page != NULL);
1491 if (priv->current_page == page)
1494 /* only add the page to the visited list if the
1495 * assistant is mapped, if not, just use it as an
1496 * initial page setting, for the cases where the
1497 * initial page is != to 0
1499 if (GTK_WIDGET_MAPPED (assistant))
1500 priv->visited_pages = g_slist_prepend (priv->visited_pages, page);
1502 set_current_page (assistant, page);
1506 * gtk_assistant_get_n_pages:
1507 * @assistant: a #GtkAssistant
1509 * Returns the number of pages in the @assistant
1511 * Return value: The number of pages in the @assistant.
1516 gtk_assistant_get_n_pages (GtkAssistant *assistant)
1518 GtkAssistantPrivate *priv;
1520 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1522 priv = assistant->priv;
1524 return g_list_length (priv->pages);
1528 * gtk_assistant_get_nth_page:
1529 * @assistant: a #GtkAssistant
1530 * @page_num: The index of a page in the @assistant, or -1 to get the last page;
1532 * Returns the child widget contained in page number @page_num.
1534 * Return value: The child widget, or %NULL if @page_num is out of bounds.
1539 gtk_assistant_get_nth_page (GtkAssistant *assistant,
1542 GtkAssistantPrivate *priv;
1543 GtkAssistantPage *page;
1546 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1548 priv = assistant->priv;
1550 elem = g_list_nth (priv->pages, page_num);
1555 page = (GtkAssistantPage *) elem->data;
1561 * gtk_assistant_prepend_page:
1562 * @assistant: a #GtkAssistant
1563 * @page: a #GtkWidget
1565 * Prepends a page to the @assistant.
1567 * Return value: the index (starting at 0) of the inserted page
1572 gtk_assistant_prepend_page (GtkAssistant *assistant,
1575 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1576 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1578 return gtk_assistant_insert_page (assistant, page, 0);
1582 * gtk_assistant_append_page:
1583 * @assistant: a #GtkAssistant
1584 * @page: a #GtkWidget
1586 * Appends a page to the @assistant.
1588 * Return value: the index (starting at 0) of the inserted page
1593 gtk_assistant_append_page (GtkAssistant *assistant,
1596 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1597 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1599 return gtk_assistant_insert_page (assistant, page, -1);
1603 * gtk_assistant_insert_page:
1604 * @assistant: a #GtkAssistant
1605 * @page: a #GtkWidget
1606 * @position: the index (starting at 0) at which to insert the page,
1607 * or -1 to append the page to the @assistant
1609 * Inserts a page in the @assistant at a given position.
1611 * Return value: the index (starting from 0) of the inserted page
1616 gtk_assistant_insert_page (GtkAssistant *assistant,
1620 GtkAssistantPrivate *priv;
1621 GtkAssistantPage *page_info;
1624 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), 0);
1625 g_return_val_if_fail (GTK_IS_WIDGET (page), 0);
1626 g_return_val_if_fail (page->parent == NULL, 0);
1627 g_return_val_if_fail (!GTK_WIDGET_TOPLEVEL (page), 0);
1629 priv = assistant->priv;
1631 page_info = g_new0 (GtkAssistantPage, 1);
1632 page_info->page = page;
1633 page_info->title = gtk_label_new (NULL);
1635 g_signal_connect (G_OBJECT (page), "notify::visible",
1636 G_CALLBACK (on_page_notify_visibility), assistant);
1638 gtk_misc_set_alignment (GTK_MISC (page_info->title), 0.,0.5);
1639 set_title_colors (GTK_WIDGET (assistant), page_info->title);
1640 set_title_font (GTK_WIDGET (assistant), page_info->title);
1641 gtk_widget_show (page_info->title);
1643 n_pages = g_list_length (priv->pages);
1645 if (position < 0 || position > n_pages)
1648 priv->pages = g_list_insert (priv->pages, page_info, position);
1650 gtk_widget_set_child_visible (page_info->page, FALSE);
1651 gtk_widget_set_parent (page_info->page, GTK_WIDGET (assistant));
1652 gtk_widget_set_parent (page_info->title, GTK_WIDGET (assistant));
1654 if (GTK_WIDGET_REALIZED (GTK_WIDGET (assistant)))
1656 gtk_widget_realize (page_info->page);
1657 gtk_widget_realize (page_info->title);
1660 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1666 * gtk_assistant_set_forward_page_func:
1667 * @assistant: a #GtkAssistant
1668 * @page_func: the #GtkAssistantPageFunc, or %NULL to use the default one
1669 * @data: user data for @page_func
1670 * @destroy: destroy notifier for @data
1672 * Sets the page forwarding function to be @page_func, this function will
1673 * be used to determine what will be the next page when the user presses
1674 * the forward button. Setting @page_func to %NULL will make the assistant
1675 * to use the default forward function, which just goes to the next visible
1681 gtk_assistant_set_forward_page_func (GtkAssistant *assistant,
1682 GtkAssistantPageFunc page_func,
1684 GDestroyNotify destroy)
1686 GtkAssistantPrivate *priv;
1688 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1690 priv = assistant->priv;
1692 if (priv->forward_data_destroy &&
1693 priv->forward_function_data)
1694 (*priv->forward_data_destroy) (priv->forward_function_data);
1698 priv->forward_function = page_func;
1699 priv->forward_function_data = data;
1700 priv->forward_data_destroy = destroy;
1704 priv->forward_function = default_forward_function;
1705 priv->forward_function_data = assistant;
1706 priv->forward_data_destroy = NULL;
1709 /* Page flow has possibly changed, so the
1710 buttons state might need to change too */
1711 if (priv->current_page)
1712 set_assistant_buttons_state (assistant);
1716 * gtk_assistant_add_action_widget:
1717 * @assistant: a #GtkAssistant
1718 * @child: a #GtkWidget
1720 * Adds a widget to the action area of a #GtkAssistant.
1725 gtk_assistant_add_action_widget (GtkAssistant *assistant,
1728 GtkAssistantPrivate *priv;
1730 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1731 g_return_if_fail (GTK_IS_WIDGET (child));
1733 priv = assistant->priv;
1735 if (GTK_IS_BUTTON (child))
1736 gtk_size_group_add_widget (priv->size_group, child);
1738 gtk_box_pack_end (GTK_BOX (priv->action_area), child, FALSE, FALSE, 0);
1742 * gtk_assistant_remove_action_widget:
1743 * @assistant: a #GtkAssistant
1744 * @child: a #GtkWidget
1746 * Removes a widget from the action area of a #GtkAssistant.
1751 gtk_assistant_remove_action_widget (GtkAssistant *assistant,
1754 GtkAssistantPrivate *priv;
1756 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1757 g_return_if_fail (GTK_IS_WIDGET (child));
1759 priv = assistant->priv;
1761 if (GTK_IS_BUTTON (child))
1762 gtk_size_group_remove_widget (priv->size_group, child);
1764 gtk_container_remove (GTK_CONTAINER (priv->action_area), child);
1768 * gtk_assistant_set_page_title:
1769 * @assistant: a #GtkAssistant
1770 * @page: a page of @assistant
1771 * @title: the new title for @page
1773 * Sets a title for @page. The title is displayed in the header
1774 * area of the assistant when @page is the current page.
1779 gtk_assistant_set_page_title (GtkAssistant *assistant,
1783 GtkAssistantPrivate *priv;
1784 GtkAssistantPage *page_info;
1787 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1788 g_return_if_fail (GTK_IS_WIDGET (page));
1790 priv = assistant->priv;
1791 child = find_page (assistant, page);
1793 g_return_if_fail (child != NULL);
1795 page_info = (GtkAssistantPage*) child->data;
1797 gtk_label_set_text ((GtkLabel*) page_info->title, title);
1798 gtk_widget_queue_resize (GTK_WIDGET (assistant));
1799 gtk_widget_child_notify (page, "title");
1803 * gtk_assistant_get_page_title:
1804 * @assistant: a #GtkAssistant
1805 * @page: a page of @assistant
1807 * Gets the title for @page.
1809 * Return value: the title for @page.
1813 G_CONST_RETURN gchar*
1814 gtk_assistant_get_page_title (GtkAssistant *assistant,
1817 GtkAssistantPrivate *priv;
1818 GtkAssistantPage *page_info;
1821 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1822 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1824 priv = assistant->priv;
1825 child = find_page (assistant, page);
1827 g_return_val_if_fail (child != NULL, NULL);
1829 page_info = (GtkAssistantPage*) child->data;
1831 return gtk_label_get_text ((GtkLabel*) page_info->title);
1835 * gtk_assistant_set_page_type:
1836 * @assistant: a #GtkAssistant
1837 * @page: a page of @assistant
1838 * @type: the new type for @page
1840 * Sets the page type for @page. The page type determines the page
1841 * behavior in the @assistant.
1846 gtk_assistant_set_page_type (GtkAssistant *assistant,
1848 GtkAssistantPageType type)
1850 GtkAssistantPrivate *priv;
1851 GtkAssistantPage *page_info;
1854 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1855 g_return_if_fail (GTK_IS_WIDGET (page));
1857 priv = assistant->priv;
1858 child = find_page (assistant, page);
1860 g_return_if_fail (child != NULL);
1862 page_info = (GtkAssistantPage*) child->data;
1864 if (type != page_info->type)
1866 page_info->type = type;
1868 /* Always set buttons state, a change in a future page
1869 might change current page buttons */
1870 if (priv->current_page)
1871 set_assistant_buttons_state (assistant);
1873 gtk_widget_child_notify (page, "page-type");
1878 * gtk_assistant_get_page_type:
1879 * @assistant: a #GtkAssistant
1880 * @page: a page of @assistant
1882 * Gets the page type of @page.
1884 * Return value: the page type of @page.
1888 GtkAssistantPageType
1889 gtk_assistant_get_page_type (GtkAssistant *assistant,
1892 GtkAssistantPrivate *priv;
1893 GtkAssistantPage *page_info;
1896 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), GTK_ASSISTANT_PAGE_CONTENT);
1897 g_return_val_if_fail (GTK_IS_WIDGET (page), GTK_ASSISTANT_PAGE_CONTENT);
1899 priv = assistant->priv;
1900 child = find_page (assistant, page);
1902 g_return_val_if_fail (child != NULL, GTK_ASSISTANT_PAGE_CONTENT);
1904 page_info = (GtkAssistantPage*) child->data;
1906 return page_info->type;
1910 * gtk_assistant_set_page_header_image:
1911 * @assistant: a #GtkAssistant
1912 * @page: a page of @assistant
1913 * @pixbuf: the new header image @page
1915 * Sets a header image for @page. This image is displayed in the header
1916 * area of the assistant when @page is the current page.
1921 gtk_assistant_set_page_header_image (GtkAssistant *assistant,
1925 GtkAssistantPrivate *priv;
1926 GtkAssistantPage *page_info;
1929 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
1930 g_return_if_fail (GTK_IS_WIDGET (page));
1931 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
1933 priv = assistant->priv;
1934 child = find_page (assistant, page);
1936 g_return_if_fail (child != NULL);
1938 page_info = (GtkAssistantPage*) child->data;
1940 if (pixbuf != page_info->header_image)
1942 if (page_info->header_image)
1944 g_object_unref (page_info->header_image);
1945 page_info->header_image = NULL;
1949 page_info->header_image = g_object_ref (pixbuf);
1951 if (page_info == priv->current_page)
1952 set_assistant_header_image (assistant);
1954 gtk_widget_child_notify (page, "header-image");
1959 * gtk_assistant_get_page_header_image:
1960 * @assistant: a #GtkAssistant
1961 * @page: a page of @assistant
1963 * Gets the header image for @page.
1965 * Return value: the header image for @page, or %NULL
1966 * if there's no header image for the page.
1971 gtk_assistant_get_page_header_image (GtkAssistant *assistant,
1974 GtkAssistantPrivate *priv;
1975 GtkAssistantPage *page_info;
1978 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
1979 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
1981 priv = assistant->priv;
1982 child = find_page (assistant, page);
1984 g_return_val_if_fail (child != NULL, NULL);
1986 page_info = (GtkAssistantPage*) child->data;
1988 return page_info->header_image;
1992 * gtk_assistant_set_page_side_image:
1993 * @assistant: a #GtkAssistant
1994 * @page: a page of @assistant
1995 * @pixbuf: the new header image @page
1997 * Sets a header image for @page. This image is displayed in the side
1998 * area of the assistant when @page is the current page.
2003 gtk_assistant_set_page_side_image (GtkAssistant *assistant,
2007 GtkAssistantPrivate *priv;
2008 GtkAssistantPage *page_info;
2011 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2012 g_return_if_fail (GTK_IS_WIDGET (page));
2013 g_return_if_fail (pixbuf == NULL || GDK_IS_PIXBUF (pixbuf));
2015 priv = assistant->priv;
2016 child = find_page (assistant, page);
2018 g_return_if_fail (child != NULL);
2020 page_info = (GtkAssistantPage*) child->data;
2022 if (pixbuf != page_info->sidebar_image)
2024 if (page_info->sidebar_image)
2026 g_object_unref (page_info->sidebar_image);
2027 page_info->sidebar_image = NULL;
2031 page_info->sidebar_image = g_object_ref (pixbuf);
2033 if (page_info == priv->current_page)
2034 set_assistant_sidebar_image (assistant);
2036 gtk_widget_child_notify (page, "sidebar-image");
2041 * gtk_assistant_get_page_side_image:
2042 * @assistant: a #GtkAssistant
2043 * @page: a page of @assistant
2045 * Gets the header image for @page.
2047 * Return value: the side image for @page, or %NULL
2048 * if there's no side image for the page.
2053 gtk_assistant_get_page_side_image (GtkAssistant *assistant,
2056 GtkAssistantPrivate *priv;
2057 GtkAssistantPage *page_info;
2060 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), NULL);
2061 g_return_val_if_fail (GTK_IS_WIDGET (page), NULL);
2063 priv = assistant->priv;
2064 child = find_page (assistant, page);
2066 g_return_val_if_fail (child != NULL, NULL);
2068 page_info = (GtkAssistantPage*) child->data;
2070 return page_info->sidebar_image;
2074 * gtk_assistant_set_page_complete:
2075 * @assistant: a #GtkAssistant
2076 * @page: a page of @assistant
2077 * @complete: the completeness status of the page
2079 * Sets whether @page contents are complete. This will make
2080 * @assistant update the buttons state to be able to continue the task.
2085 gtk_assistant_set_page_complete (GtkAssistant *assistant,
2089 GtkAssistantPrivate *priv;
2090 GtkAssistantPage *page_info;
2093 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2094 g_return_if_fail (GTK_IS_WIDGET (page));
2096 priv = assistant->priv;
2097 child = find_page (assistant, page);
2099 g_return_if_fail (child != NULL);
2101 page_info = (GtkAssistantPage*) child->data;
2103 if (complete != page_info->complete)
2105 page_info->complete = complete;
2107 /* Always set buttons state, a change in a future page
2108 might change current page buttons */
2109 if (priv->current_page)
2110 set_assistant_buttons_state (assistant);
2112 gtk_widget_child_notify (page, "complete");
2117 * gtk_assistant_get_page_complete:
2118 * @assistant: a #GtkAssistant
2119 * @page: a page of @assistant
2121 * Gets whether @page is complete..
2123 * Return value: %TRUE if @page is complete.
2128 gtk_assistant_get_page_complete (GtkAssistant *assistant,
2131 GtkAssistantPrivate *priv;
2132 GtkAssistantPage *page_info;
2135 g_return_val_if_fail (GTK_IS_ASSISTANT (assistant), FALSE);
2136 g_return_val_if_fail (GTK_IS_WIDGET (page), FALSE);
2138 priv = assistant->priv;
2139 child = find_page (assistant, page);
2141 g_return_val_if_fail (child != NULL, FALSE);
2143 page_info = (GtkAssistantPage*) child->data;
2145 return page_info->complete;
2149 * gtk_assistant_update_buttons_state:
2150 * @assistant: a #GtkAssistant
2152 * Forces @assistant to recompute the buttons state.
2154 * GTK+ automatically takes care of this in most situations,
2155 * e.g. when the user goes to a different page, or when the
2156 * visibility or completeness of a page changes.
2158 * One situation where it can be necessary to call this
2159 * function is when changing a value on the current page
2160 * affects the future page flow of the assistant.
2165 gtk_assistant_update_buttons_state (GtkAssistant *assistant)
2167 g_return_if_fail (GTK_IS_ASSISTANT (assistant));
2169 set_assistant_buttons_state (assistant);
2174 /* accessible implementation */
2177 gtk_assistant_accessible_get_n_children (AtkObject *accessible)
2179 GtkAssistant *assistant;
2182 widget = GTK_ACCESSIBLE (accessible)->widget;
2187 assistant = GTK_ASSISTANT (widget);
2189 return g_list_length (assistant->priv->pages) + 1;
2194 gtk_assistant_accessible_ref_child (AtkObject *accessible,
2197 GtkAssistant *assistant;
2198 GtkAssistantPrivate *priv;
2199 GtkWidget *widget, *child;
2203 widget = GTK_ACCESSIBLE (accessible)->widget;
2207 assistant = GTK_ASSISTANT (widget);
2208 priv = assistant->priv;
2209 n_pages = g_list_length (priv->pages);
2213 else if (index < n_pages)
2215 GtkAssistantPage *page = g_list_nth_data (priv->pages, index / 2);
2219 else if (index == n_pages)
2221 child = priv->action_area;
2226 obj = gtk_widget_get_accessible (child);
2228 return g_object_ref (obj);
2232 gtk_assistant_accessible_class_init (AtkObjectClass *class)
2234 class->get_n_children = gtk_assistant_accessible_get_n_children;
2235 class->ref_child = gtk_assistant_accessible_ref_child;
2239 gtk_assistant_accessible_get_type (void)
2241 static GType type = 0;
2246 * Figure out the size of the class and instance
2247 * we are deriving from
2249 AtkObjectFactory *factory;
2252 GType derived_atk_type;
2254 derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
2255 factory = atk_registry_get_factory (atk_get_default_registry (),
2257 derived_atk_type = atk_object_factory_get_accessible_type (factory);
2258 g_type_query (derived_atk_type, &query);
2260 type = g_type_register_static_simple (derived_atk_type,
2261 "GtkAssistantAccessible",
2263 (GClassInitFunc) gtk_assistant_accessible_class_init,
2264 query.instance_size,
2272 gtk_assistant_accessible_new (GObject *obj)
2274 AtkObject *accessible;
2276 g_return_val_if_fail (GTK_IS_ASSISTANT (obj), NULL);
2278 accessible = g_object_new (gtk_assistant_accessible_get_type (), NULL);
2279 atk_object_initialize (accessible, obj);
2285 gtk_assistant_accessible_factory_get_accessible_type (void)
2287 return gtk_assistant_accessible_get_type ();
2291 gtk_assistant_accessible_factory_create_accessible (GObject *obj)
2293 return gtk_assistant_accessible_new (obj);
2297 gtk_assistant_accessible_factory_class_init (AtkObjectFactoryClass *class)
2299 class->create_accessible = gtk_assistant_accessible_factory_create_accessible;
2300 class->get_accessible_type = gtk_assistant_accessible_factory_get_accessible_type;
2304 gtk_assistant_accessible_factory_get_type (void)
2306 static GType type = 0;
2310 type = g_type_register_static_simple (ATK_TYPE_OBJECT_FACTORY,
2311 "GtkAssistantAccessibleFactory",
2312 sizeof (AtkObjectFactoryClass),
2313 (GClassInitFunc) gtk_assistant_accessible_factory_class_init,
2314 sizeof (AtkObjectFactory),
2322 gtk_assistant_get_accessible (GtkWidget *widget)
2324 static gboolean first_time = TRUE;
2328 AtkObjectFactory *factory;
2329 AtkRegistry *registry;
2331 GType derived_atk_type;
2334 * Figure out whether accessibility is enabled by looking at the
2335 * type of the accessible object which would be created for
2336 * the parent type of GtkAssistant.
2338 derived_type = g_type_parent (GTK_TYPE_ASSISTANT);
2340 registry = atk_get_default_registry ();
2341 factory = atk_registry_get_factory (registry,
2343 derived_atk_type = atk_object_factory_get_accessible_type (factory);
2344 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
2346 atk_registry_set_factory_type (registry,
2348 gtk_assistant_accessible_factory_get_type ());
2353 return GTK_WIDGET_CLASS (gtk_assistant_parent_class)->get_accessible (widget);
2357 #define __GTK_ASSISTANT_C__
2358 #include "gtkaliasdef.c"