2
* Copyright (C) 1999 Red Hat, Inc.
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public
16
* License along with this library; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
24
#include "gnome-druid.h"
26
struct _GnomeDruidPrivate
28
GnomeDruidPage *current;
33
gboolean show_finish : 1; /* if TRUE, then we are showing the finish button instead of the next button */
34
gboolean show_help : 1;
49
static void gnome_druid_destroy (GtkObject *object);
50
static void gnome_druid_finalize (GObject *object);
51
static void gnome_druid_set_property (GObject *object,
55
static void gnome_druid_get_property (GObject *object,
59
static void gnome_druid_size_request (GtkWidget *widget,
60
GtkRequisition *requisition);
61
static void gnome_druid_size_allocate (GtkWidget *widget,
62
GtkAllocation *allocation);
63
static gint gnome_druid_expose (GtkWidget *widget,
64
GdkEventExpose *event);
65
static void gnome_druid_map (GtkWidget *widget);
66
static void gnome_druid_unmap (GtkWidget *widget);
67
static GtkType gnome_druid_child_type (GtkContainer *container);
68
static void gnome_druid_add (GtkContainer *widget,
70
static void gnome_druid_remove (GtkContainer *widget,
72
static void gnome_druid_forall (GtkContainer *container,
73
gboolean include_internals,
75
gpointer callback_data);
76
static void gnome_druid_back_callback (GtkWidget *button,
78
static void gnome_druid_next_callback (GtkWidget *button,
80
static void gnome_druid_cancel_callback (GtkWidget *button,
82
static void gnome_druid_help_callback (GtkWidget *button,
86
static guint druid_signals[LAST_SIGNAL] = { 0 };
88
/* define the _get_type method and parent_class */
89
GNOME_CLASS_BOILERPLATE(GnomeDruid, gnome_druid,
90
GtkContainer, GTK_TYPE_CONTAINER, GNOME_REGISTER_TYPE)
93
gnome_druid_class_init (GnomeDruidClass *klass)
95
GtkObjectClass *object_class;
96
GObjectClass *gobject_class;
97
GtkWidgetClass *widget_class;
98
GtkContainerClass *container_class;
100
object_class = (GtkObjectClass*) klass;
101
gobject_class = (GObjectClass*) klass;
102
widget_class = (GtkWidgetClass*) klass;
103
container_class = (GtkContainerClass*) klass;
105
druid_signals[CANCEL] =
106
g_signal_new ("cancel",
107
G_TYPE_FROM_CLASS (gobject_class),
109
G_STRUCT_OFFSET (GnomeDruidClass, cancel),
111
g_cclosure_marshal_VOID__VOID,
114
druid_signals[HELP] =
115
g_signal_new ("help",
116
G_TYPE_FROM_CLASS (gobject_class),
118
G_STRUCT_OFFSET (GnomeDruidClass, help),
120
g_cclosure_marshal_VOID__VOID,
123
object_class->destroy = gnome_druid_destroy;
124
gobject_class->set_property = gnome_druid_set_property;
125
gobject_class->get_property = gnome_druid_get_property;
126
gobject_class->finalize = gnome_druid_finalize;
127
widget_class->size_request = gnome_druid_size_request;
128
widget_class->size_allocate = gnome_druid_size_allocate;
129
widget_class->map = gnome_druid_map;
130
widget_class->unmap = gnome_druid_unmap;
131
widget_class->expose_event = gnome_druid_expose;
133
container_class->forall = gnome_druid_forall;
134
container_class->add = gnome_druid_add;
135
container_class->remove = gnome_druid_remove;
136
container_class->child_type = gnome_druid_child_type;
139
g_object_class_install_property (gobject_class,
141
g_param_spec_boolean ("show_finish",
143
"Show the 'Finish' button instead of the 'Next' button",
147
g_object_class_install_property (gobject_class,
149
g_param_spec_boolean ("show_help",
151
"Show the 'Help' button",
157
gnome_druid_instance_init (GnomeDruid *druid)
159
druid->_priv = g_new0(GnomeDruidPrivate, 1);
161
/* set the default border width */
162
GTK_CONTAINER (druid)->border_width = GNOME_PAD_SMALL;
164
/* set up the buttons */
165
GTK_WIDGET_SET_FLAGS (GTK_WIDGET (druid), GTK_NO_WINDOW);
166
druid->back = gtk_button_new_from_stock (GTK_STOCK_GO_BACK);
167
GTK_WIDGET_SET_FLAGS (druid->back, GTK_CAN_DEFAULT);
168
druid->next = gtk_button_new_from_stock (GTK_STOCK_GO_FORWARD);
169
GTK_WIDGET_SET_FLAGS (druid->next, GTK_CAN_DEFAULT);
170
druid->cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
171
GTK_WIDGET_SET_FLAGS (druid->cancel, GTK_CAN_DEFAULT);
172
druid->finish = gtk_button_new_from_stock (GTK_STOCK_APPLY);
173
GTK_WIDGET_SET_FLAGS (druid->finish, GTK_CAN_DEFAULT);
174
druid->help = gtk_button_new_from_stock (GTK_STOCK_HELP);
175
GTK_WIDGET_SET_FLAGS (druid->help, GTK_CAN_DEFAULT);
176
gtk_widget_show (druid->back);
177
gtk_widget_show (druid->next);
178
gtk_widget_show (druid->cancel);
180
druid->_priv->bbox = gtk_hbutton_box_new ();
181
gtk_button_box_set_layout (GTK_BUTTON_BOX (druid->_priv->bbox),
183
/* FIXME: use a style property for these */
184
gtk_box_set_spacing (GTK_BOX (druid->_priv->bbox), 10);
185
gtk_container_set_border_width (GTK_CONTAINER (druid->_priv->bbox), 5);
186
gtk_widget_set_parent (druid->_priv->bbox, GTK_WIDGET (druid));
187
gtk_widget_show (druid->_priv->bbox);
189
gtk_box_pack_end (GTK_BOX (druid->_priv->bbox), druid->help,
191
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (druid->_priv->bbox),
194
gtk_box_pack_end (GTK_BOX (druid->_priv->bbox), druid->cancel,
197
gtk_box_pack_end (GTK_BOX (druid->_priv->bbox), druid->back,
200
gtk_box_pack_end (GTK_BOX (druid->_priv->bbox), druid->next,
203
gtk_box_pack_end (GTK_BOX (druid->_priv->bbox), druid->finish,
207
druid->_priv->current = NULL;
208
druid->_priv->children = NULL;
209
druid->_priv->show_finish = FALSE;
210
druid->_priv->show_help = FALSE;
212
g_signal_connect (druid->back, "clicked",
213
G_CALLBACK (gnome_druid_back_callback), druid);
214
g_signal_connect (druid->next, "clicked",
215
G_CALLBACK (gnome_druid_next_callback), druid);
216
g_signal_connect (druid->cancel, "clicked",
217
G_CALLBACK (gnome_druid_cancel_callback), druid);
218
g_signal_connect (druid->finish, "clicked",
219
G_CALLBACK (gnome_druid_next_callback), druid);
220
g_signal_connect (druid->help, "clicked",
221
G_CALLBACK (gnome_druid_help_callback), druid);
223
gtk_widget_grab_focus (druid->next);
229
gnome_druid_destroy (GtkObject *object)
233
/* remember, destroy can be run multiple times! */
235
g_return_if_fail (object != NULL);
236
g_return_if_fail (GNOME_IS_DRUID (object));
238
druid = GNOME_DRUID (object);
240
if(druid->_priv->bbox) {
241
gtk_widget_destroy (druid->_priv->bbox);
242
druid->_priv->bbox = NULL;
245
druid->cancel = NULL;
246
druid->finish = NULL;
250
/* Remove all children, we set current to NULL so
251
* that the remove code doesn't try to do anything funny */
252
druid->_priv->current = NULL;
253
while (druid->_priv->children != NULL) {
254
GnomeDruidPage *child = druid->_priv->children->data;
255
gtk_container_remove (GTK_CONTAINER (druid), GTK_WIDGET(child));
258
GNOME_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
262
gnome_druid_finalize (GObject *object)
266
g_return_if_fail (object != NULL);
267
g_return_if_fail (GNOME_IS_DRUID (object));
269
druid = GNOME_DRUID (object);
271
g_free(druid->_priv);
274
GNOME_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
278
gnome_druid_set_property (GObject *object,
285
case PROP_SHOW_FINISH:
286
gnome_druid_set_show_finish (GNOME_DRUID (object), g_value_get_boolean (value));
289
gnome_druid_set_show_help (GNOME_DRUID (object), g_value_get_boolean (value));
297
gnome_druid_get_property (GObject *object,
304
case PROP_SHOW_FINISH:
305
g_value_set_boolean (value, GNOME_DRUID (object)->_priv->show_finish);
308
g_value_set_boolean (value, GNOME_DRUID (object)->_priv->show_help);
311
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
317
gnome_druid_size_request (GtkWidget *widget,
318
GtkRequisition *requisition)
320
guint16 temp_width, temp_height;
323
GtkRequisition child_requisition;
324
GnomeDruidPage *child;
327
g_return_if_fail (widget != NULL);
328
g_return_if_fail (GNOME_IS_DRUID (widget));
330
druid = GNOME_DRUID (widget);
331
temp_height = temp_width = 0;
333
border = GTK_CONTAINER(widget)->border_width;
335
/* We find the maximum size of all children widgets */
336
for (list = druid->_priv->children; list; list = list->next) {
337
child = GNOME_DRUID_PAGE (list->data);
338
if (GTK_WIDGET_VISIBLE (child)) {
339
gtk_widget_size_request (GTK_WIDGET (child), &child_requisition);
340
temp_width = MAX (temp_width, child_requisition.width);
341
temp_height = MAX (temp_height, child_requisition.height);
342
if (GTK_WIDGET_MAPPED (child) && child != druid->_priv->current)
343
gtk_widget_unmap (GTK_WIDGET(child));
347
requisition->width = temp_width + 2 * border;
348
requisition->height = temp_height + 2 * border;
351
/* In an Attempt to show how the widgets are packed,
352
* here's a little diagram.
354
* [ Help ] ------------- [ Back ] [ Next ] [ Cancel ]
356
* This part needs to be at least 1 button width.
357
* In addition, there is 1/4 X Button width between Cancel and Next,
358
* and a GNOME_PAD_SMALL between Next and Back.
360
/* our_button width is temp_width and temp_height */
364
gtk_widget_size_request (druid->back, &child_requisition);
365
temp_width = MAX (temp_width, child_requisition.width);
366
temp_height = MAX (temp_height, child_requisition.height);
368
gtk_widget_size_request (druid->next, &child_requisition);
369
temp_width = MAX (temp_width, child_requisition.width);
370
temp_height = MAX (temp_height, child_requisition.height);
372
gtk_widget_size_request (druid->cancel, &child_requisition);
373
temp_width = MAX (temp_width, child_requisition.width);
374
temp_height = MAX (temp_height, child_requisition.height);
376
gtk_widget_size_request (druid->finish, &child_requisition);
377
temp_width = MAX (temp_width, child_requisition.width);
378
temp_height = MAX (temp_height, child_requisition.height);
380
gtk_widget_size_request (druid->help, &child_requisition);
381
temp_width = MAX (temp_width, child_requisition.width);
382
temp_height = MAX (temp_height, child_requisition.height);
384
temp_width += border * 2;
385
temp_height += GNOME_PAD_SMALL;
387
temp_width = temp_width * 21/4 + GNOME_PAD_SMALL * 3;
390
gtk_widget_size_request (druid->_priv->bbox, &child_requisition);
392
/* pick which is bigger, the buttons, or the GnomeDruidPages */
393
requisition->width = MAX (child_requisition.width, requisition->width);
394
requisition->height += child_requisition.height + GNOME_PAD_SMALL * 2;
398
gnome_druid_size_allocate (GtkWidget *widget,
399
GtkAllocation *allocation)
402
GtkAllocation child_allocation;
407
g_return_if_fail (widget != NULL);
408
g_return_if_fail (GNOME_IS_DRUID (widget));
410
druid = GNOME_DRUID (widget);
411
widget->allocation = *allocation;
413
border = GTK_CONTAINER(widget)->border_width;
416
/* deal with the buttons */
417
child_allocation.width = child_allocation.height = 0;
418
child_allocation.width = druid->back->requisition.width;
419
child_allocation.height = druid->back->requisition.height;
420
child_allocation.width = MAX (child_allocation.width,
421
druid->next->requisition.width);
422
child_allocation.height = MAX (child_allocation.height,
423
druid->next->requisition.height);
424
child_allocation.width = MAX (child_allocation.width,
425
druid->cancel->requisition.width);
426
child_allocation.height = MAX (child_allocation.height,
427
druid->cancel->requisition.height);
428
child_allocation.width = MAX (child_allocation.width,
429
druid->help->requisition.width);
430
child_allocation.height = MAX (child_allocation.height,
431
druid->help->requisition.height);
433
child_allocation.height += GNOME_PAD_SMALL;
434
button_height = child_allocation.height;
435
child_allocation.width += 2 * GNOME_PAD_SMALL;
436
child_allocation.x = allocation->x + allocation->width - GNOME_PAD_SMALL - child_allocation.width;
437
child_allocation.y = allocation->y + allocation->height - GNOME_PAD_SMALL - child_allocation.height;
438
gtk_widget_size_allocate (druid->cancel, &child_allocation);
439
child_allocation.x -= (child_allocation.width * 5 / 4);
440
gtk_widget_size_allocate (druid->next, &child_allocation);
441
gtk_widget_size_allocate (druid->finish, &child_allocation);
442
child_allocation.x -= (GNOME_PAD_SMALL + child_allocation.width);
443
gtk_widget_size_allocate (druid->back, &child_allocation);
444
child_allocation.x = allocation->x + border;
445
gtk_widget_size_allocate (druid->help, &child_allocation);
447
button_height = druid->_priv->bbox->requisition.height;
448
child_allocation.x = allocation->x;
449
child_allocation.y = allocation->y + allocation->height - button_height;
450
child_allocation.height = button_height;
451
child_allocation.width = allocation->width;
452
gtk_widget_size_allocate (druid->_priv->bbox, &child_allocation);
454
/* Put up the GnomeDruidPage */
455
child_allocation.x = allocation->x + border;
456
child_allocation.y = allocation->y + border;
457
child_allocation.width =
458
((allocation->width - 2 * border) > 0) ?
459
(allocation->width - 2 * border):0;
460
child_allocation.height =
461
((allocation->height - 2 * border - GNOME_PAD_SMALL - button_height) > 0) ?
462
(allocation->height - 2 * border - GNOME_PAD_SMALL - button_height):0;
463
for (list = druid->_priv->children; list; list=list->next) {
464
GtkWidget *widget = GTK_WIDGET (list->data);
465
if (GTK_WIDGET_VISIBLE (widget)) {
466
gtk_widget_size_allocate (widget, &child_allocation);
472
gnome_druid_child_type (GtkContainer *container)
474
return GNOME_TYPE_DRUID_PAGE;
478
gnome_druid_map (GtkWidget *widget)
482
g_return_if_fail (widget != NULL);
483
g_return_if_fail (GNOME_IS_DRUID (widget));
485
druid = GNOME_DRUID (widget);
486
GTK_WIDGET_SET_FLAGS (druid, GTK_MAPPED);
489
gtk_widget_map (druid->back);
490
if (druid->_priv->show_finish)
491
gtk_widget_map (druid->finish);
493
gtk_widget_map (druid->next);
494
if (druid->_priv->show_help)
495
gtk_widget_map (druid->help);
496
gtk_widget_map (druid->cancel);
498
gtk_widget_map (druid->_priv->bbox);
499
if (druid->_priv->current &&
500
GTK_WIDGET_VISIBLE (druid->_priv->current) &&
501
!GTK_WIDGET_MAPPED (druid->_priv->current)) {
502
gtk_widget_map (GTK_WIDGET (druid->_priv->current));
507
gnome_druid_unmap (GtkWidget *widget)
511
g_return_if_fail (widget != NULL);
512
g_return_if_fail (GNOME_IS_DRUID (widget));
514
druid = GNOME_DRUID (widget);
515
GTK_WIDGET_UNSET_FLAGS (druid, GTK_MAPPED);
517
gtk_widget_unmap (druid->back);
518
if (druid->_priv->show_finish)
519
gtk_widget_unmap (druid->finish);
521
gtk_widget_unmap (druid->next);
522
gtk_widget_unmap (druid->cancel);
523
if (druid->_priv->show_help)
524
gtk_widget_unmap (druid->help);
526
gtk_widget_unmap (druid->_priv->bbox);
527
if (druid->_priv->current &&
528
GTK_WIDGET_VISIBLE (druid->_priv->current) &&
529
GTK_WIDGET_MAPPED (druid->_priv->current))
530
gtk_widget_unmap (GTK_WIDGET (druid->_priv->current));
533
gnome_druid_add (GtkContainer *widget,
536
g_return_if_fail (widget != NULL);
537
g_return_if_fail (GNOME_IS_DRUID (widget));
538
g_return_if_fail (page != NULL);
539
g_return_if_fail (GNOME_IS_DRUID_PAGE (page));
541
gnome_druid_append_page (GNOME_DRUID (widget), GNOME_DRUID_PAGE (page));
544
gnome_druid_remove (GtkContainer *widget,
550
g_return_if_fail (widget != NULL);
551
g_return_if_fail (GNOME_IS_DRUID (widget));
552
g_return_if_fail (child != NULL);
554
druid = GNOME_DRUID (widget);
556
list = g_list_find (druid->_priv->children, child);
559
/* If we are mapped and visible, we want to deal with changing the page. */
560
if ((GTK_WIDGET_MAPPED (GTK_WIDGET (widget))) &&
561
(list->data == (gpointer) druid->_priv->current) &&
562
(list->next != NULL)) {
563
gnome_druid_set_page (druid, GNOME_DRUID_PAGE (list->next->data));
566
druid->_priv->children = g_list_remove (druid->_priv->children, child);
567
gtk_widget_unparent (child);
571
gnome_druid_forall (GtkContainer *container,
572
gboolean include_internals,
573
GtkCallback callback,
574
gpointer callback_data)
577
GnomeDruidPage *child;
580
g_return_if_fail (container != NULL);
581
g_return_if_fail (GNOME_IS_DRUID (container));
582
g_return_if_fail (callback != NULL);
584
druid = GNOME_DRUID (container);
586
children = druid->_priv->children;
588
child = children->data;
589
children = children->next;
591
(* callback) (GTK_WIDGET (child), callback_data);
593
if (include_internals) {
594
/* FIXME: should this be gtk_contianer_forall() ? */
595
(* callback) (druid->_priv->bbox, callback_data);
597
(* callback) (druid->back, callback_data);
598
(* callback) (druid->next, callback_data);
599
(* callback) (druid->cancel, callback_data);
600
(* callback) (druid->finish, callback_data);
601
(* callback) (druid->help, callback_data);
607
gnome_druid_expose (GtkWidget *widget,
608
GdkEventExpose *event)
614
g_return_val_if_fail (widget != NULL, FALSE);
615
g_return_val_if_fail (GNOME_IS_DRUID (widget), FALSE);
616
g_return_val_if_fail (event != NULL, FALSE);
618
if (GTK_WIDGET_DRAWABLE (widget)) {
619
druid = GNOME_DRUID (widget);
620
children = druid->_priv->children;
623
child = GTK_WIDGET (children->data);
624
children = children->next;
626
gtk_container_propagate_expose (GTK_CONTAINER (widget),
629
gtk_container_propagate_expose (GTK_CONTAINER (widget),
630
druid->_priv->bbox, event);
632
gtk_container_propagate_expose (GTK_CONTAINER (widget),
634
gtk_container_propagate_expose (GTK_CONTAINER (widget),
636
gtk_container_propagate_expose (GTK_CONTAINER (widget),
637
druid->cancel, event);
638
gtk_container_propagate_expose (GTK_CONTAINER (widget),
639
druid->finish, event);
640
gtk_container_propagate_expose (GTK_CONTAINER (widget),
648
gnome_druid_back_callback (GtkWidget *button, GnomeDruid *druid)
651
g_return_if_fail (druid->_priv->current != NULL);
653
if (gnome_druid_page_back (druid->_priv->current))
656
/* Make sure that we have a next list item */
657
list = g_list_find (druid->_priv->children, druid->_priv->current);
658
g_return_if_fail (list->prev != NULL);
659
gnome_druid_set_page (druid, GNOME_DRUID_PAGE (list->prev->data));
662
gnome_druid_next_callback (GtkWidget *button, GnomeDruid *druid)
665
g_return_if_fail (druid->_priv->current != NULL);
667
if (druid->_priv->show_finish == FALSE) {
668
if (gnome_druid_page_next (druid->_priv->current))
671
/* Make sure that we have a next list item */
672
list = g_list_find (druid->_priv->children,
673
druid->_priv->current);
674
/* this would be a bug */
675
g_assert (list != NULL);
678
while (list != NULL &&
679
! GTK_WIDGET_VISIBLE (list->data))
685
gnome_druid_set_page (druid, GNOME_DRUID_PAGE (list->data));
687
gnome_druid_page_finish (druid->_priv->current);
691
gnome_druid_cancel_callback (GtkWidget *button, GtkWidget *druid)
693
if (GNOME_DRUID (druid)->_priv->current) {
694
if (gnome_druid_page_cancel (GNOME_DRUID (druid)->_priv->current))
697
g_signal_emit (druid, druid_signals [CANCEL], 0);
702
gnome_druid_help_callback (GtkWidget *button,
705
g_signal_emit (druid, druid_signals [HELP], 0);
708
/* Public Functions */
712
* Description: Creates a new #GnomeDruid widget. You need to add this
713
* to a dialog yourself, it is not a dialog.
715
* Returns: A new #GnomeDruid widget
718
gnome_druid_new (void)
720
return g_object_new (GNOME_TYPE_DRUID, NULL);
724
* gnome_druid_new_with_window:
725
* @title: A title of the window.
726
* @parent: The parent of this window (transient_for).
727
* @close_on_cancel: %TRUE if the window should be closed when cancel is
729
* @window: Optional return of the #GtkWindow created.
731
* Description: Creates a new #GnomeDruid widget. It also creates a new
732
* toplevel window with the title of @title (which can be %NULL) and a parent
733
* of @parent (which also can be %NULL). The window and the druid will both be
734
* shown. If you need the window widget pointer you can optionally get it
735
* through the last argument. When the druid gets destroyed, so will the
736
* window that is created here.
738
* Returns: A new #GnomeDruid widget.
741
gnome_druid_new_with_window (const char *title,
743
gboolean close_on_cancel,
746
GtkWidget *druid = g_object_new (GNOME_TYPE_DRUID, NULL);
748
/* make sure we always set window to NULL, even in
749
* case of precondition errors */
753
g_return_val_if_fail (parent == NULL ||
754
GTK_IS_WINDOW (parent),
757
gnome_druid_construct_with_window (GNOME_DRUID (druid),
767
* gnome_druid_construct_with_window:
768
* @druid: The #GnomeDruid.
769
* @title: A title of the window.
770
* @parent: The parent of this window (transient_for).
771
* @close_on_cancel: %TRUE if the window should be closed when cancel is
773
* @window: Optional return of the #GtkWindow created.
775
* Description: Creates a new toplevel window with the title of @title (which
776
* can be %NULL) and a parent of @parent (which also can be %NULL). The @druid
777
* will be placed inside this window. The window and the druid will both be
778
* shown. If you need the window widget pointer you can optionally get it
779
* through the last argument. When the druid gets destroyed, so will the
780
* window that is created here.
782
* See also gnome_druid_new_with_window().
785
gnome_druid_construct_with_window (GnomeDruid *druid,
788
gboolean close_on_cancel,
793
/* make sure we always set window to NULL, even in
794
* case of precondition errors */
798
g_return_if_fail (druid != NULL);
799
g_return_if_fail (GNOME_IS_DRUID (druid));
800
g_return_if_fail (parent == NULL ||
801
GTK_IS_WINDOW (parent));
803
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
806
gtk_window_set_title (GTK_WINDOW (win), title);
808
gtk_window_set_transient_for (GTK_WINDOW (win),
811
gtk_widget_show (GTK_WIDGET (druid));
813
gtk_container_add (GTK_CONTAINER (win), GTK_WIDGET (druid));
815
gtk_widget_show (win);
817
if (close_on_cancel) {
818
g_signal_connect_object (druid, "cancel",
819
G_CALLBACK (gtk_widget_destroy),
824
/* When the druid gets destroyed so does the window */
825
g_signal_connect_object (druid, "destroy",
826
G_CALLBACK (gtk_widget_destroy),
830
/* return the window */
837
* gnome_druid_set_buttons_sensitive
839
* @back_sensitive: %TRUE if the back button is sensitive.
840
* @next_sensitive: %TRUE if the next button is sensitive.
841
* @cancel_sensitive: %TRUE if the cancel button is sensitive.
842
* @help_sensitive: %TRUE if the help button is sensitive.
844
* Description: Sets the sensitivity of @druid's control-buttons. If the
845
* variables are %TRUE, then they will be clickable. This function is used
846
* primarily by the actual GnomeDruidPage widgets.
850
gnome_druid_set_buttons_sensitive (GnomeDruid *druid,
851
gboolean back_sensitive,
852
gboolean next_sensitive,
853
gboolean cancel_sensitive,
854
gboolean help_sensitive)
856
g_return_if_fail (druid != NULL);
857
g_return_if_fail (GNOME_IS_DRUID (druid));
859
gtk_widget_set_sensitive (druid->back, back_sensitive);
860
gtk_widget_set_sensitive (druid->next, next_sensitive);
861
gtk_widget_set_sensitive (druid->cancel, cancel_sensitive);
862
gtk_widget_set_sensitive (druid->help, help_sensitive);
866
* gnome_druid_set_show_finish
867
* @druid: A #GnomeDruid widget.
868
* @show_finish: If %TRUE, then the "Next" button is changed to be "Finish"
870
* Used to specify if @druid is currently showing the last page of the sequence
871
* (and hence should display "Finish", rather than "Next").
874
gnome_druid_set_show_finish (GnomeDruid *druid,
875
gboolean show_finish)
877
g_return_if_fail (GNOME_IS_DRUID (druid));
879
if ((show_finish?TRUE:FALSE) == druid->_priv->show_finish)
883
gtk_widget_hide (druid->next);
884
gtk_widget_show (druid->finish);
886
gtk_widget_hide (druid->finish);
887
gtk_widget_show (druid->next);
889
druid->_priv->show_finish = show_finish?TRUE:FALSE;
893
* gnome_druid_set_show_help
894
* @druid: A #GnomeDruid.
895
* @show_help: %TRUE, if the "Help" button is to be shown, %FALSE otherwise.
897
* Sets the "Help" button on the druid to be visible in the lower left corner of
898
* the widget, if @show_help is %TRUE.
901
gnome_druid_set_show_help (GnomeDruid *druid,
904
g_return_if_fail (GNOME_IS_DRUID (druid));
906
if ((show_help?TRUE:FALSE) == druid->_priv->show_help)
910
gtk_widget_show (druid->help);
912
gtk_widget_hide (druid->help);
914
druid->_priv->show_help = show_help?TRUE:FALSE;
919
* gnome_druid_prepend_page:
920
* @druid: A Druid widget.
921
* @page: The page to be inserted.
923
* Description: This will prepend a GnomeDruidPage into the internal list of
924
* pages that the @druid has. Since #GnomeDruid is just a container, you will
925
* need to also call gtk_widget_show() on the page, otherwise the page will not
929
gnome_druid_prepend_page (GnomeDruid *druid,
930
GnomeDruidPage *page)
932
g_return_if_fail (druid != NULL);
933
g_return_if_fail (GNOME_IS_DRUID (druid));
934
g_return_if_fail (page != NULL);
935
g_return_if_fail (GNOME_IS_DRUID_PAGE (page));
937
gnome_druid_insert_page (druid, NULL, page);
940
* gnome_druid_insert_page:
941
* @druid: A #GnomeDruid widget.
942
* @back_page: The page prior to the page to be inserted.
943
* @page: The page to insert.
945
* Description: This will insert @page after @back_page into the list of
946
* internal pages that the @druid has. If @back_page is not present in the
947
* list or %NULL, @page will be prepended to the list. Since #GnomeDruid is
948
* just a container, you will need to also call gtk_widget_show() on the page,
949
* otherwise the page will not be shown.
952
gnome_druid_insert_page (GnomeDruid *druid,
953
GnomeDruidPage *back_page,
954
GnomeDruidPage *page)
958
g_return_if_fail (druid != NULL);
959
g_return_if_fail (GNOME_IS_DRUID (druid));
960
g_return_if_fail (page != NULL);
961
g_return_if_fail (GNOME_IS_DRUID_PAGE (page));
963
list = g_list_find (druid->_priv->children, back_page);
965
druid->_priv->children = g_list_prepend (druid->_priv->children, page);
967
GList *new_el = g_list_alloc ();
968
new_el->next = list->next;
971
new_el->next->prev = new_el;
972
new_el->prev->next = new_el;
973
new_el->data = (gpointer) page;
975
gtk_widget_set_parent (GTK_WIDGET (page), GTK_WIDGET (druid));
977
if (GTK_WIDGET_REALIZED (GTK_WIDGET (druid)))
978
gtk_widget_realize (GTK_WIDGET (page));
980
if (GTK_WIDGET_VISIBLE (GTK_WIDGET (druid)) && GTK_WIDGET_VISIBLE (GTK_WIDGET (page))) {
981
if (GTK_WIDGET_MAPPED (GTK_WIDGET (page)))
982
gtk_widget_unmap (GTK_WIDGET (page));
983
gtk_widget_queue_resize (GTK_WIDGET (druid));
986
/* if it's the first and only page, we want to bring it to the foreground. */
987
if (druid->_priv->children->next == NULL)
988
gnome_druid_set_page (druid, page);
992
* gnome_druid_append_page:
993
* @druid: A #GnomeDruid widget.
994
* @page: The #GnomeDruidPage to be appended.
996
* Description: This will append @page onto the end of the internal list.
997
* Since #GnomeDruid is just a container, you will need to also call
998
* gtk_widget_show() on the page, otherwise the page will not be shown.
1001
gnome_druid_append_page (GnomeDruid *druid,
1002
GnomeDruidPage *page)
1005
g_return_if_fail (druid != NULL);
1006
g_return_if_fail (GNOME_IS_DRUID (druid));
1007
g_return_if_fail (page != NULL);
1008
g_return_if_fail (GNOME_IS_DRUID_PAGE (page));
1010
list = g_list_last (druid->_priv->children);
1012
gnome_druid_insert_page (druid, GNOME_DRUID_PAGE (list->data), page);
1014
gnome_druid_insert_page (druid, NULL, page);
1018
* gnome_druid_set_page:
1019
* @druid: A #GnomeDruid widget.
1020
* @page: The #GnomeDruidPage to be brought to the foreground.
1022
* Description: This will make @page the currently showing page in the druid.
1023
* @page must already be in the druid.
1026
gnome_druid_set_page (GnomeDruid *druid,
1027
GnomeDruidPage *page)
1030
GtkWidget *old = NULL;
1031
g_return_if_fail (druid != NULL);
1032
g_return_if_fail (GNOME_IS_DRUID (druid));
1033
g_return_if_fail (page != NULL);
1034
g_return_if_fail (GNOME_IS_DRUID_PAGE (page));
1036
if (druid->_priv->current == page)
1038
list = g_list_find (druid->_priv->children, page);
1039
g_return_if_fail (list != NULL);
1041
if ((druid->_priv->current) && (GTK_WIDGET_VISIBLE (druid->_priv->current)) && (GTK_WIDGET_MAPPED (druid))) {
1042
old = GTK_WIDGET (druid->_priv->current);
1044
druid->_priv->current = GNOME_DRUID_PAGE (list->data);
1045
gnome_druid_page_prepare (druid->_priv->current);
1046
if (GTK_WIDGET_VISIBLE (druid->_priv->current) && (GTK_WIDGET_MAPPED (druid))) {
1047
gtk_widget_map (GTK_WIDGET (druid->_priv->current));
1049
if (old && GTK_WIDGET_MAPPED (old))
1050
gtk_widget_unmap (old);