testassistant.c 20.6 KB
Newer Older
Matthias Clasen's avatar
Matthias Clasen committed
1
/* 
Cody Russell's avatar
Cody Russell committed
2
 * GTK - The GIMP Toolkit
Matthias Clasen's avatar
Matthias Clasen committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * Copyright (C) 1999  Red Hat, Inc.
 * Copyright (C) 2002  Anders Carlsson <andersca@gnu.org>
 * Copyright (C) 2003  Matthias Clasen <mclasen@redhat.com>
 * Copyright (C) 2005  Carlos Garnacho Parro <carlosg@gnome.org>
 *
 * All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
Javier Jardón's avatar
Javier Jardón committed
21
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
Matthias Clasen's avatar
Matthias Clasen committed
22 23 24 25 26 27 28 29 30 31
 */

#include <gtk/gtk.h>

static GtkWidget*
get_test_page (const gchar *text)
{
  return gtk_label_new (text);
}

Matthias Clasen's avatar
Matthias Clasen committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
typedef struct {
  GtkAssistant *assistant;
  GtkWidget    *page;
} PageData;

static void
complete_cb (GtkWidget *check, 
	     gpointer   data)
{
  PageData *pdata = data;
  gboolean complete;

  complete = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));

  gtk_assistant_set_page_complete (pdata->assistant,
				   pdata->page,
				   complete);
}
	     
51
static GtkWidget *
Matthias Clasen's avatar
Matthias Clasen committed
52 53 54 55 56 57 58 59 60
add_completion_test_page (GtkWidget   *assistant,
			  const gchar *text, 
			  gboolean     visible,
			  gboolean     complete)
{
  GtkWidget *page;
  GtkWidget *check;
  PageData *pdata;

61
  page = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
Matthias Clasen's avatar
Matthias Clasen committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
  check = gtk_check_button_new_with_label ("Complete");

  gtk_container_add (GTK_CONTAINER (page), gtk_label_new (text));
  gtk_container_add (GTK_CONTAINER (page), check);
  
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), complete);

  pdata = g_new (PageData, 1);
  pdata->assistant = GTK_ASSISTANT (assistant);
  pdata->page = page;
  g_signal_connect (G_OBJECT (check), "toggled", 
		    G_CALLBACK (complete_cb), pdata);


  if (visible)
    gtk_widget_show_all (page);

  gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
  gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, text);
  gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, complete);
82 83

  return page;
Matthias Clasen's avatar
Matthias Clasen committed
84 85
}

Matthias Clasen's avatar
Matthias Clasen committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
static void
cancel_callback (GtkWidget *widget)
{
  g_print ("cancel\n");

  gtk_widget_hide (widget);
}

static void
close_callback (GtkWidget *widget)
{
  g_print ("close\n");

  gtk_widget_hide (widget);
}

static void
apply_callback (GtkWidget *widget)
{
  g_print ("apply\n");
}

static gboolean
progress_timeout (GtkWidget *assistant)
{
111
  GtkWidget *progress;
Matthias Clasen's avatar
Matthias Clasen committed
112 113 114 115
  gint current_page;
  gdouble value;

  current_page = gtk_assistant_get_current_page (GTK_ASSISTANT (assistant));
116
  progress = gtk_assistant_get_nth_page (GTK_ASSISTANT (assistant), current_page);
Matthias Clasen's avatar
Matthias Clasen committed
117 118 119 120 121 122 123

  value  = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (progress));
  value += 0.1;
  gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress), value);

  if (value >= 1.0)
    {
124
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), progress, TRUE);
Matthias Clasen's avatar
Matthias Clasen committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138
      return FALSE;
    }

  return TRUE;
}

static void
prepare_callback (GtkWidget *widget, GtkWidget *page)
{
  if (GTK_IS_LABEL (page))
    g_print ("prepare: %s\n", gtk_label_get_text (GTK_LABEL (page)));
  else if (gtk_assistant_get_page_type (GTK_ASSISTANT (widget), page) == GTK_ASSISTANT_PAGE_PROGRESS)
    {
      gtk_assistant_set_page_complete (GTK_ASSISTANT (widget), page, FALSE);
139
      gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (page), 0.0);
140
      gdk_threads_add_timeout (300, (GSourceFunc) progress_timeout, widget);
Matthias Clasen's avatar
Matthias Clasen committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
    }
  else
    g_print ("prepare: %d\n", gtk_assistant_get_current_page (GTK_ASSISTANT (widget)));
}

static void
create_simple_assistant (GtkWidget *widget)
{
  static GtkWidget *assistant = NULL;

  if (!assistant)
    {
      GtkWidget *page;

      assistant = gtk_assistant_new ();
      gtk_window_set_default_size (GTK_WINDOW (assistant), 400, 300);

      g_signal_connect (G_OBJECT (assistant), "cancel",
			G_CALLBACK (cancel_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "close",
			G_CALLBACK (close_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "apply",
			G_CALLBACK (apply_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "prepare",
			G_CALLBACK (prepare_callback), NULL);

      page = get_test_page ("Page 1");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 1");
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);

      page = get_test_page ("Page 2");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 2");
      gtk_assistant_set_page_type  (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_CONFIRM);
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
    }

181
  if (!gtk_widget_get_visible (assistant))
Matthias Clasen's avatar
Matthias Clasen committed
182 183 184 185 186 187 188 189
    gtk_widget_show (assistant);
  else
    {
      gtk_widget_destroy (assistant);
      assistant = NULL;
    }
}

190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
static void
create_anonymous_assistant (GtkWidget *widget)
{
  static GtkWidget *assistant = NULL;

  if (!assistant)
    {
      GtkWidget *page;

      assistant = gtk_assistant_new ();
      gtk_window_set_default_size (GTK_WINDOW (assistant), 400, 300);

      g_signal_connect (G_OBJECT (assistant), "cancel",
			G_CALLBACK (cancel_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "close",
			G_CALLBACK (close_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "apply",
			G_CALLBACK (apply_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "prepare",
			G_CALLBACK (prepare_callback), NULL);

      page = get_test_page ("Page 1");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);

      page = get_test_page ("Page 2");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_type  (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_CONFIRM);
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
    }

  if (!gtk_widget_get_visible (assistant))
    gtk_widget_show (assistant);
  else
    {
      gtk_widget_destroy (assistant);
      assistant = NULL;
    }
}

232 233 234 235 236 237 238 239 240 241 242 243
static void
visible_cb (GtkWidget *check, 
	    gpointer   data)
{
  GtkWidget *page = data;
  gboolean visible;

  visible = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check));

  g_object_set (G_OBJECT (page), "visible", visible, NULL);
}

Matthias Clasen's avatar
Matthias Clasen committed
244 245 246 247 248 249 250
static void
create_generous_assistant (GtkWidget *widget)
{
  static GtkWidget *assistant = NULL;

  if (!assistant)
    {
251
      GtkWidget *page, *next, *check;
252
      PageData  *pdata;
Matthias Clasen's avatar
Matthias Clasen committed
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272

      assistant = gtk_assistant_new ();
      gtk_window_set_default_size (GTK_WINDOW (assistant), 400, 300);

      g_signal_connect (G_OBJECT (assistant), "cancel",
			G_CALLBACK (cancel_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "close",
			G_CALLBACK (close_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "apply",
			G_CALLBACK (apply_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "prepare",
			G_CALLBACK (prepare_callback), NULL);

      page = get_test_page ("Introduction");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Introduction");
      gtk_assistant_set_page_type  (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_INTRO);
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);

273 274 275 276 277 278 279 280 281 282
      page = add_completion_test_page (assistant, "Content", TRUE, FALSE);
      next = add_completion_test_page (assistant, "More Content", TRUE, TRUE);

      check = gtk_check_button_new_with_label ("Next page visible");
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE);
      g_signal_connect (G_OBJECT (check), "toggled", 
			G_CALLBACK (visible_cb), next);
      gtk_widget_show (check);
      gtk_container_add (GTK_CONTAINER (page), check);
      
Matthias Clasen's avatar
Matthias Clasen committed
283
      add_completion_test_page (assistant, "Even More Content", TRUE, TRUE);
Matthias Clasen's avatar
Matthias Clasen committed
284 285 286 287 288 289 290 291

      page = get_test_page ("Confirmation");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Confirmation");
      gtk_assistant_set_page_type  (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_CONFIRM);
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);

292 293 294 295 296
      page = gtk_progress_bar_new ();
      gtk_widget_set_halign (page, GTK_ALIGN_FILL);
      gtk_widget_set_valign (page, GTK_ALIGN_CENTER);
      gtk_widget_set_margin_start (page, 20);
      gtk_widget_set_margin_end (page, 20);
Matthias Clasen's avatar
Matthias Clasen committed
297 298 299 300 301
      gtk_widget_show_all (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Progress");
      gtk_assistant_set_page_type  (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_PROGRESS);

302
      page = gtk_check_button_new_with_label ("Summary complete");
Matthias Clasen's avatar
Matthias Clasen committed
303 304 305 306
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Summary");
      gtk_assistant_set_page_type  (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_SUMMARY);
307 308 309 310 311 312 313 314 315 316

      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (page),
                                    gtk_assistant_get_page_complete (GTK_ASSISTANT (assistant),
                                                                     page));

      pdata = g_new (PageData, 1);
      pdata->assistant = GTK_ASSISTANT (assistant);
      pdata->page = page;
      g_signal_connect (page, "toggled",
                      G_CALLBACK (complete_cb), pdata);
Matthias Clasen's avatar
Matthias Clasen committed
317 318
    }

319
  if (!gtk_widget_get_visible (assistant))
Matthias Clasen's avatar
Matthias Clasen committed
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
    gtk_widget_show (assistant);
  else
    {
      gtk_widget_destroy (assistant);
      assistant = NULL;
    }
}

static gchar selected_branch = 'A';

static void
select_branch (GtkWidget *widget, gchar branch)
{
  selected_branch = branch;
}

static gint
nonlinear_assistant_forward_page (gint current_page, gpointer data)
{
  switch (current_page)
    {
    case 0:
      if (selected_branch == 'A')
	return 1;
      else
	return 2;
    case 1:
    case 2:
      return 3;
    default:
      return -1;
    }
}

static void
create_nonlinear_assistant (GtkWidget *widget)
{
  static GtkWidget *assistant = NULL;

  if (!assistant)
    {
      GtkWidget *page, *button;

      assistant = gtk_assistant_new ();
      gtk_window_set_default_size (GTK_WINDOW (assistant), 400, 300);

      g_signal_connect (G_OBJECT (assistant), "cancel",
			G_CALLBACK (cancel_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "close",
			G_CALLBACK (close_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "apply",
			G_CALLBACK (apply_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "prepare",
			G_CALLBACK (prepare_callback), NULL);

      gtk_assistant_set_forward_page_func (GTK_ASSISTANT (assistant),
					   nonlinear_assistant_forward_page,
					   NULL, NULL);

379
      page = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
Matthias Clasen's avatar
Matthias Clasen committed
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398

      button = gtk_radio_button_new_with_label (NULL, "branch A");
      gtk_box_pack_start (GTK_BOX (page), button, FALSE, FALSE, 0);
      g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (select_branch), GINT_TO_POINTER ('A'));
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
      
      button = gtk_radio_button_new_with_label (gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
						"branch B");
      gtk_box_pack_start (GTK_BOX (page), button, FALSE, FALSE, 0);
      g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (select_branch), GINT_TO_POINTER ('B'));

      gtk_widget_show_all (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 1");
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
      
      page = get_test_page ("Page 2A");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
399
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 2");
Matthias Clasen's avatar
Matthias Clasen committed
400 401 402 403 404
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);

      page = get_test_page ("Page 2B");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
405
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 2");
Matthias Clasen's avatar
Matthias Clasen committed
406 407 408 409 410 411 412 413 414 415
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);

      page = get_test_page ("Confirmation");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Confirmation");
      gtk_assistant_set_page_type  (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_CONFIRM);
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
    }

416
  if (!gtk_widget_get_visible (assistant))
Matthias Clasen's avatar
Matthias Clasen committed
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
    gtk_widget_show (assistant);
  else
    {
      gtk_widget_destroy (assistant);
      assistant = NULL;
    }
}

static gint
looping_assistant_forward_page (gint current_page, gpointer data)
{
  switch (current_page)
    {
    case 0:
      return 1;
    case 1:
      return 2;
    case 2:
      return 3;
    case 3:
      {
	GtkAssistant *assistant;
	GtkWidget *page;

	assistant = (GtkAssistant*) data;
	page = gtk_assistant_get_nth_page (assistant, current_page);

	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (page)))
	  return 0;
	else
	  return 4;
      }
    case 4:
    default:
      return -1;
    }
}

static void
create_looping_assistant (GtkWidget *widget)
{
  static GtkWidget *assistant = NULL;

  if (!assistant)
    {
      GtkWidget *page;

      assistant = gtk_assistant_new ();
      gtk_window_set_default_size (GTK_WINDOW (assistant), 400, 300);

      g_signal_connect (G_OBJECT (assistant), "cancel",
			G_CALLBACK (cancel_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "close",
			G_CALLBACK (close_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "apply",
			G_CALLBACK (apply_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "prepare",
			G_CALLBACK (prepare_callback), NULL);

      gtk_assistant_set_forward_page_func (GTK_ASSISTANT (assistant),
					   looping_assistant_forward_page,
					   assistant, NULL);

      page = get_test_page ("Introduction");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Introduction");
      gtk_assistant_set_page_type  (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_INTRO);
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);

      page = get_test_page ("Content");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Content");
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);

      page = get_test_page ("More content");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "More content");
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);

      page = gtk_check_button_new_with_label ("Loop?");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Loop?");
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
      
      page = get_test_page ("Confirmation");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Confirmation");
      gtk_assistant_set_page_type  (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_CONFIRM);
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
    }

513
  if (!gtk_widget_get_visible (assistant))
Matthias Clasen's avatar
Matthias Clasen committed
514 515 516 517 518 519 520 521
    gtk_widget_show (assistant);
  else
    {
      gtk_widget_destroy (assistant);
      assistant = NULL;
    }
}

522 523 524 525 526 527 528 529 530 531
static void
toggle_invisible (GtkButton *button, GtkAssistant *assistant)
{
  GtkWidget *page;

  page = gtk_assistant_get_nth_page (assistant, 1);

  gtk_widget_set_visible (page, !gtk_widget_get_visible (page));
}

Matthias Clasen's avatar
Matthias Clasen committed
532 533 534 535 536 537 538 539 540 541 542 543
static void
create_full_featured_assistant (GtkWidget *widget)
{
  static GtkWidget *assistant = NULL;

  if (!assistant)
    {
      GtkWidget *page, *button;

      assistant = gtk_assistant_new ();
      gtk_window_set_default_size (GTK_WINDOW (assistant), 400, 300);

544
      button = gtk_button_new_with_label ("_Stop");
545
      gtk_button_set_use_underline (GTK_BUTTON (button), TRUE);
546 547 548 549
      gtk_widget_show (button);
      gtk_assistant_add_action_widget (GTK_ASSISTANT (assistant), button);
      g_signal_connect (button, "clicked",
                        G_CALLBACK (toggle_invisible), assistant);
Matthias Clasen's avatar
Matthias Clasen committed
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567

      g_signal_connect (G_OBJECT (assistant), "cancel",
			G_CALLBACK (cancel_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "close",
			G_CALLBACK (close_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "apply",
			G_CALLBACK (apply_callback), NULL);
      g_signal_connect (G_OBJECT (assistant), "prepare",
			G_CALLBACK (prepare_callback), NULL);

      page = get_test_page ("Page 1");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 1");
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);

      page = get_test_page ("Invisible page");
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
568 569
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 2");
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
Matthias Clasen's avatar
Matthias Clasen committed
570

571 572 573 574 575
      page = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_OPEN);
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Filechooser");
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
576
      gtk_assistant_set_page_has_padding (GTK_ASSISTANT (assistant), page, FALSE);
577

Matthias Clasen's avatar
Matthias Clasen committed
578 579 580 581 582 583 584 585
      page = get_test_page ("Page 3");
      gtk_widget_show (page);
      gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
      gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Page 3");
      gtk_assistant_set_page_type  (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_CONFIRM);
      gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, TRUE);
    }

586
  if (!gtk_widget_get_visible (assistant))
Matthias Clasen's avatar
Matthias Clasen committed
587 588 589 590 591 592 593 594
    gtk_widget_show (assistant);
  else
    {
      gtk_widget_destroy (assistant);
      assistant = NULL;
    }
}

Matthias Clasen's avatar
Matthias Clasen committed
595 596 597 598 599
struct {
  gchar *text;
  void  (*func) (GtkWidget *widget);
} buttons[] =
  {
Matthias Clasen's avatar
Matthias Clasen committed
600
    { "simple assistant",        create_simple_assistant },
601
    { "anonymous assistant",        create_anonymous_assistant },
Matthias Clasen's avatar
Matthias Clasen committed
602 603 604 605
    { "generous assistant",      create_generous_assistant },
    { "nonlinear assistant",     create_nonlinear_assistant },
    { "looping assistant",       create_looping_assistant },
    { "full featured assistant", create_full_featured_assistant },
Matthias Clasen's avatar
Matthias Clasen committed
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
  };

int
main (int argc, gchar *argv[])
{
  GtkWidget *window, *box, *button;
  gint i;

  gtk_init (&argc, &argv);

  if (g_getenv ("RTL"))
    gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  g_signal_connect (G_OBJECT (window), "destroy",
		    G_CALLBACK (gtk_main_quit), NULL);
  g_signal_connect (G_OBJECT (window), "delete-event",
		    G_CALLBACK (gtk_false), NULL);

626
  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
Matthias Clasen's avatar
Matthias Clasen committed
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
  gtk_container_add (GTK_CONTAINER (window), box);

  for (i = 0; i < G_N_ELEMENTS (buttons); i++)
    {
      button = gtk_button_new_with_label (buttons[i].text);

      if (buttons[i].func)
	g_signal_connect (G_OBJECT (button), "clicked",
			  G_CALLBACK (buttons[i].func), NULL);

      gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0);
    }

  gtk_widget_show_all (window);
  gtk_main ();

  return 0;
}