testgtk.c 402 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4
/* GTK - The GIMP Toolkit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
Elliot Lee's avatar
Elliot Lee committed
6 7 8 9 10 11
 * 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
12
 * Lesser General Public License for more details.
Elliot Lee's avatar
Elliot Lee committed
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15 16 17
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
18
 */
19 20

/*
21
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22 23 24 25 26
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

27 28
#undef GTK_DISABLE_DEPRECATED

29
#include <config.h>
30

31
#undef	G_LOG_DOMAIN
32

Elliot Lee's avatar
Elliot Lee committed
33 34
#include <stdio.h>
#include <stdlib.h>
35
#include <string.h>
36
#include <sys/stat.h>
37
#include <math.h>
38
#include <time.h>
39
#ifdef HAVE_UNISTD_H
40
#include <unistd.h>
41 42
#endif

43
#define GTK_ENABLE_BROKEN
Owen Taylor's avatar
Owen Taylor committed
44
#include "gtk/gtk.h"
45 46
#include "gdk/gdk.h"
#include "gdk/gdkkeysyms.h"
Elliot Lee's avatar
Elliot Lee committed
47

48 49 50 51
#ifdef G_OS_WIN32
#define sleep(n) _sleep(n)
#endif

52 53
#include "prop-editor.h"

Owen Taylor's avatar
Owen Taylor committed
54
#include "circles.xbm"
55
#include "test.xpm"
Owen Taylor's avatar
Owen Taylor committed
56

57 58 59 60 61 62 63 64
gboolean
file_exists (const char *filename)
{
  struct stat statbuf;

  return stat (filename, &statbuf) == 0;
}

65
GtkWidget *
66 67 68 69 70 71 72
shape_create_icon (GdkScreen *screen,
		   char      *xpm_file,
		   gint       x,
		   gint       y,
		   gint       px,
		   gint       py,
		   gint       window_type);
73 74

static GtkWidget *
75 76 77
build_option_menu (gchar           *items[],
		   gint             num_items,
		   gint             history,
Tim Janik's avatar
Tim Janik committed
78
		   void           (*func) (GtkWidget *widget, gpointer data),
79
		   gpointer         data);
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

/* macro, structure and variables used by tree window demos */
#define DEFAULT_NUMBER_OF_ITEM  3
#define DEFAULT_RECURSION_LEVEL 3

struct {
  GSList* selection_mode_group;
  GtkWidget* single_button;
  GtkWidget* browse_button;
  GtkWidget* multiple_button;
  GtkWidget* draw_line_button;
  GtkWidget* view_line_button;
  GtkWidget* no_root_item_button;
  GtkWidget* nb_item_spinner;
  GtkWidget* recursion_spinner;
} sTreeSampleSelection;

typedef struct sTreeButtons {
  guint nb_item_add;
  GtkWidget* add_button;
  GtkWidget* remove_button;
101
  GtkWidget* subtree_button;
102 103 104
} sTreeButtons;
/* end of tree section */

105
static GtkWidget *
106 107 108 109 110
build_option_menu (gchar           *items[],
		   gint             num_items,
		   gint             history,
		   void           (*func)(GtkWidget *widget, gpointer data),
		   gpointer         data)
111 112 113 114
{
  GtkWidget *omenu;
  GtkWidget *menu;
  GtkWidget *menu_item;
115
  GSList *group;
116 117 118
  gint i;

  omenu = gtk_option_menu_new ();
Manish Singh's avatar
Manish Singh committed
119 120
  g_signal_connect (omenu, "changed",
		    G_CALLBACK (func), data);
121 122
      
  menu = gtk_menu_new ();
123
  group = NULL;
124 125 126
  
  for (i = 0; i < num_items; i++)
    {
127
      menu_item = gtk_radio_menu_item_new_with_label (group, items[i]);
Manish Singh's avatar
Manish Singh committed
128
      group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (menu_item));
129
      gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
130 131
      if (i == history)
	gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), TRUE);
132 133 134 135 136 137 138 139 140
      gtk_widget_show (menu_item);
    }

  gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu);
  gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), history);
  
  return omenu;
}

141
static void
142 143
destroy_tooltips (GtkWidget *widget, GtkWindow **window)
{
Manish Singh's avatar
Manish Singh committed
144 145
  GtkTooltips *tt = g_object_get_data (G_OBJECT (*window), "tooltips");
  g_object_unref (tt);
146 147 148
  *window = NULL;
}

149

150 151 152 153 154 155 156 157 158 159 160 161 162
/*
 * Windows with an alpha channel
 */


static gboolean
on_alpha_window_expose (GtkWidget      *widget,
			GdkEventExpose *expose)
{
  cairo_t *cr;
  cairo_pattern_t *pattern;
  int radius;

163
  cr = gdk_cairo_create (widget->window);
164 165 166 167 168 169 170 171 172

  radius = MIN (widget->allocation.width, widget->allocation.height) / 2;
  pattern = cairo_pattern_create_radial (widget->allocation.width / 2,
					 widget->allocation.height / 2,
					 0.0,
					 widget->allocation.width / 2,
					 widget->allocation.height / 2,
					 radius * 1.33);

Søren Sandmann's avatar
Søren Sandmann committed
173 174
  if (gdk_screen_get_rgba_colormap (gtk_widget_get_screen (widget)) &&
      gtk_widget_is_composited (widget))
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 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 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 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
    cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); /* transparent */
  else
    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); /* opaque white */
    
  cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
  cairo_paint (cr);
  
  cairo_pattern_add_color_stop_rgba (pattern, 0.0,
				     1.0, 0.75, 0.0, 1.0); /* solid orange */
  cairo_pattern_add_color_stop_rgba (pattern, 1.0,
				     1.0, 0.75, 0.0, 0.0); /* transparent orange */

  cairo_set_source (cr, pattern);
  cairo_pattern_destroy (pattern);
  
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
  cairo_paint (cr);

  cairo_destroy (cr);

  return FALSE;
}

static GtkWidget *
build_alpha_widgets (void)
{
  GtkWidget *table;
  GtkWidget *radio_button;
  GtkWidget *hbox;
  GtkWidget *label;
  GtkWidget *entry;

  table = gtk_table_new (1, 1, FALSE);

  radio_button = gtk_radio_button_new_with_label (NULL, "Red");
  gtk_table_attach (GTK_TABLE (table),
		    radio_button,
		    0, 1,                  0, 1,
		    GTK_EXPAND | GTK_FILL, 0,
		    0,                     0);

  radio_button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_button), "Green");
  gtk_table_attach (GTK_TABLE (table),
		    radio_button,
		    0, 1,                  1, 2,
		    GTK_EXPAND | GTK_FILL, 0,
		    0,                     0);

  radio_button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_button), "Blue"),
  gtk_table_attach (GTK_TABLE (table),
		    radio_button,
		    0, 1,                  2, 3,
		    GTK_EXPAND | GTK_FILL, 0,
		    0,                     0);

  gtk_table_attach (GTK_TABLE (table),
		    gtk_check_button_new_with_label ("Sedentary"),
		    1, 2,                  0, 1,
		    GTK_EXPAND | GTK_FILL, 0,
		    0,                     0);
  gtk_table_attach (GTK_TABLE (table),
		    gtk_check_button_new_with_label ("Nocturnal"),
		    1, 2,                  1, 2,
		    GTK_EXPAND | GTK_FILL, 0,
		    0,                     0);
  gtk_table_attach (GTK_TABLE (table),
		    gtk_check_button_new_with_label ("Compulsive"),
		    1, 2,                  2, 3,
		    GTK_EXPAND | GTK_FILL, 0,
		    0,                     0);

  radio_button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_button), "Green");
  gtk_table_attach (GTK_TABLE (table),
		    radio_button,
		    0, 1,                  1, 2,
		    GTK_EXPAND | GTK_FILL, 0,
		    0,                     0);

  radio_button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_button), "Blue"),
  gtk_table_attach (GTK_TABLE (table),
		    radio_button,
		    0, 1,                  2, 3,
		    GTK_EXPAND | GTK_FILL, 0,
		    0,                     0);
  
  hbox = gtk_hbox_new (FALSE, 0);
  label = gtk_label_new (NULL);
  gtk_label_set_markup (GTK_LABEL (label), "<i>Entry: </i>");
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
  entry = gtk_entry_new ();
  gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
  gtk_table_attach (GTK_TABLE (table),
		    hbox,
		    0, 1,                  3, 4,
		    GTK_EXPAND | GTK_FILL, 0,
		    0,                     0);
  
  return table;
}

static gboolean
on_alpha_drawing_expose (GtkWidget      *widget,
			 GdkEventExpose *expose)
{
  int x = widget->allocation.x;
  int y = widget->allocation.y;
  int width = widget->allocation.width;
  int height = widget->allocation.height;
  GdkPixbuf *pixbuf;
  guchar *buffer;
  guchar *p;
  int i, j;

  buffer = g_malloc (64 * 64 * 4);
  
  gdk_draw_rectangle (widget->window, widget->style->black_gc, FALSE,
		      x,         y,
		      width - 1, height - 1);

  p = buffer;
  for (i = 0; i < 64; i++) {
    for (j = 0; j < 64; j++) {
      *(p++) = i * 4 + 3;
      *(p++) = 0;
      *(p++) = j + 4 + 3;
      *(p++) = MIN (255, ((32 - i) * (32 - i) + (32 - j) * (32 - j)) / 8);
    }
  }
  p++;

  gdk_draw_rgb_32_image (widget->window, widget->style->black_gc,
			 x + 18, y + (height - 64) /2,
			 64, 64, GDK_RGB_DITHER_NORMAL, buffer, 64 * 4);

  pixbuf = gdk_pixbuf_new_from_data (buffer, GDK_COLORSPACE_RGB, TRUE,
				     8, 64, 64, 4 * 64, NULL, NULL);

  gdk_draw_pixbuf (widget->window, widget->style->black_gc, pixbuf,
		   0, 0, x + width - 18 - 64, y + (height - 64) /2,
		   64, 64, GDK_RGB_DITHER_NORMAL, 0, 0);

  g_object_unref (pixbuf);

  g_free (buffer);
  
  return FALSE;
}

static GtkWidget *
build_alpha_drawing ()
{
  GtkWidget *hbox;

  hbox = gtk_hbox_new (FALSE, 0);
  gtk_widget_set_size_request (hbox, 100, 100);

  g_signal_connect (hbox, "expose-event",
		    G_CALLBACK (on_alpha_drawing_expose), NULL);

  return hbox;
}

static void
on_alpha_screen_changed (GtkWidget *widget,
			 GdkScreen *old_screen,
			 GtkWidget *label)
{
  GdkScreen *screen = gtk_widget_get_screen (widget);
  GdkColormap *colormap = gdk_screen_get_rgba_colormap (screen);

  if (!colormap)
    {
      colormap = gdk_screen_get_rgb_colormap (screen);
      gtk_label_set_markup (GTK_LABEL (label), "<b>Screen doesn't support alpha</b>");
    }
  else
    {
      gtk_label_set_markup (GTK_LABEL (label), "<b>Screen supports alpha</b>");
    }

  gtk_widget_set_colormap (widget, colormap);
}

Søren Sandmann's avatar
Søren Sandmann committed
358 359 360 361 362 363 364 365 366 367 368 369
static void
on_composited_changed (GtkWidget *window,
		      GtkLabel *label)
{
  gboolean is_composited = gtk_widget_is_composited (window);

  if (is_composited)
    gtk_label_set_text (label, "Composited");
  else
    gtk_label_set_text (label, "Not composited");
}

370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
void
create_alpha_window (GtkWidget *widget)
{
  static GtkWidget *window;

  if (!window)
    {
      GtkWidget *vbox;
      GtkWidget *label;
      
      window = gtk_dialog_new_with_buttons ("Alpha Window",
					    GTK_WINDOW (gtk_widget_get_toplevel (widget)), 0,
					    GTK_STOCK_CLOSE, 0,
					    NULL);

      gtk_widget_set_app_paintable (window, TRUE);
      g_signal_connect (window, "expose-event",
			G_CALLBACK (on_alpha_window_expose), NULL);
      
      vbox = gtk_vbox_new (FALSE, 8);
      gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
      gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox,
			  TRUE, TRUE, 0);

      label = gtk_label_new (NULL);
      gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
      on_alpha_screen_changed (window, NULL, label);
      g_signal_connect (window, "screen-changed",
			G_CALLBACK (on_alpha_screen_changed), label);
      
Søren Sandmann's avatar
Søren Sandmann committed
400 401 402 403 404 405 406 407
      label = gtk_label_new (NULL);
      gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
      on_composited_changed (window, GTK_LABEL (label));
      g_signal_connect (window, "composited_changed", G_CALLBACK (on_composited_changed), label);
      
      gtk_box_pack_start (GTK_BOX (vbox), build_alpha_widgets (), TRUE, TRUE, 0);
      gtk_box_pack_start (GTK_BOX (vbox), build_alpha_drawing (), TRUE, TRUE, 0);

408 409 410
      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
411 412 413
      
      g_signal_connect (window, "response",
                        G_CALLBACK (gtk_widget_destroy),
Søren Sandmann's avatar
Søren Sandmann committed
414
                        NULL); 
415 416 417 418 419 420 421 422
    }

  if (!GTK_WIDGET_VISIBLE (window))
    gtk_widget_show_all (window);
  else
    gtk_widget_destroy (window);
}

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 513 514 515 516
/*
 * Composited non-toplevel window
 */

/* The expose event handler for the event box.
 *
 * This function simply draws a transparency onto a widget on the area
 * for which it receives expose events.  This is intended to give the
 * event box a "transparent" background.
 *
 * In order for this to work properly, the widget must have an RGBA
 * colourmap.  The widget should also be set as app-paintable since it
 * doesn't make sense for GTK to draw a background if we are drawing it
 * (and because GTK might actually replace our transparency with its
 * default background colour).
 */
static gboolean
transparent_expose (GtkWidget *widget,
                    GdkEventExpose *event)
{
  cairo_t *cr;

  cr = gdk_cairo_create (widget->window);
  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
  gdk_cairo_region (cr, event->region);
  cairo_fill (cr);
  cairo_destroy (cr);

  return FALSE;
}

/* The expose event handler for the window.
 *
 * This function performs the actual compositing of the event box onto
 * the already-existing background of the window at 50% normal opacity.
 *
 * In this case we do not want app-paintable to be set on the widget
 * since we want it to draw its own (red) background.  Because of this,
 * however, we must ensure that we use g_signal_register_after so that
 * this handler is called after the red has been drawn.  If it was
 * called before then GTK would just blindly paint over our work.
 */
static gboolean
window_expose_event (GtkWidget *widget,
                     GdkEventExpose *event)
{
  GdkRegion *region;
  GtkWidget *child;
  cairo_t *cr;

  /* get our child (in this case, the event box) */ 
  child = gtk_bin_get_child (GTK_BIN (widget));

  /* create a cairo context to draw to the window */
  cr = gdk_cairo_create (widget->window);

  /* the source data is the (composited) event box */
  gdk_cairo_set_source_pixmap (cr, child->window,
                               child->allocation.x,
                               child->allocation.y);

  /* draw no more than our expose event intersects our child */
  region = gdk_region_rectangle (&child->allocation);
  gdk_region_intersect (region, event->region);
  gdk_cairo_region (cr, region);
  cairo_clip (cr);

  /* composite, with a 50% opacity */
  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
  cairo_paint_with_alpha (cr, 0.5);

  /* we're done */
  cairo_destroy (cr);

  return FALSE;
}

void
create_composited_window (GtkWidget *widget)
{
  static GtkWidget *window;

  if (!window)
    {
      GtkWidget *event, *button;
      GdkScreen *screen;
      GdkColormap *rgba;
      GdkColor red;

      /* make the widgets */
      button = gtk_button_new_with_label ("A Button");
      event = gtk_event_box_new ();
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

517 518 519 520
      g_signal_connect (window, "destroy",
                        G_CALLBACK (gtk_widget_destroyed),
                        &window);

521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
      /* put a red background on the window */
      gdk_color_parse ("red", &red);
      gtk_widget_modify_bg (window, GTK_STATE_NORMAL, &red);

      /* set the colourmap for the event box.
       * must be done before the event box is realised.
       */
      screen = gtk_widget_get_screen (event);
      rgba = gdk_screen_get_rgba_colormap (screen);
      gtk_widget_set_colormap (event, rgba);

      /* set our event box to have a fully-transparent background
       * drawn on it.  currently there is no way to simply tell gtk
       * that "transparency" is the background colour for a widget.
       */
      gtk_widget_set_app_paintable (GTK_WIDGET (event), TRUE);
      g_signal_connect (event, "expose-event",
                        G_CALLBACK (transparent_expose), NULL);

      /* put them inside one another */
      gtk_container_set_border_width (GTK_CONTAINER (window), 10);
      gtk_container_add (GTK_CONTAINER (window), event);
      gtk_container_add (GTK_CONTAINER (event), button);

      /* realise and show everything */
      gtk_widget_realize (button);

      /* set the event box GdkWindow to be composited.
       * obviously must be performed after event box is realised.
       */
      gdk_window_set_composited (event->window, TRUE);

      /* set up the compositing handler.
       * note that we do _after so that the normal (red) background is drawn
       * by gtk before our compositing occurs.
       */
      g_signal_connect_after (window, "expose-event",
                              G_CALLBACK (window_expose_event), NULL);
    }

  if (!GTK_WIDGET_VISIBLE (window))
    gtk_widget_show_all (window);
  else
    gtk_widget_destroy (window);
}

567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
/*
 * Big windows and guffaw scrolling
 */

static gboolean
pattern_expose (GtkWidget      *widget,
		GdkEventExpose *event,
		gpointer        data)
{
  GdkColor *color;
  GdkWindow *window = event->window;

  color = g_object_get_data (G_OBJECT (window), "pattern-color");
  if (color)
    {
      GdkGC *tmp_gc = gdk_gc_new (window);
      gdk_gc_set_rgb_fg_color (tmp_gc, color);

      gdk_draw_rectangle (window, tmp_gc, TRUE,
			  event->area.x, event->area.y,
			  event->area.width, event->area.height);

Manish Singh's avatar
Manish Singh committed
589
      g_object_unref (tmp_gc);
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605
    }

  return FALSE;
}

static void
pattern_set_bg (GtkWidget   *widget,
		GdkWindow   *child,
		gint         level)
{
  static const GdkColor colors[] = {
    { 0, 0x4444, 0x4444, 0xffff },
    { 0, 0x8888, 0x8888, 0xffff },
    { 0, 0xaaaa, 0xaaaa, 0xffff }
  };
    
Manish Singh's avatar
Manish Singh committed
606
  g_object_set_data (G_OBJECT (child), "pattern-color", (gpointer) &colors[level]);
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
  gdk_window_set_user_data (child, widget);
}

static void
create_pattern (GtkWidget   *widget,
		GdkWindow   *parent,
		gint         level,
		gint         width,
		gint         height)
{
  gint h = 1;
  gint i = 0;
    
  GdkWindow *child;

  while (2 * h <= height)
    {
      gint w = 1;
      gint j = 0;
      
      while (2 * w <= width)
	{
	  if ((i + j) % 2 == 0)
	    {
	      gint x = w  - 1;
	      gint y = h - 1;
	      
	      GdkWindowAttr attributes;

	      attributes.window_type = GDK_WINDOW_CHILD;
	      attributes.x = x;
	      attributes.y = y;
	      attributes.width = w;
	      attributes.height = h;
	      attributes.wclass = GDK_INPUT_OUTPUT;
	      attributes.event_mask = GDK_EXPOSURE_MASK;
	      attributes.visual = gtk_widget_get_visual (widget);
	      attributes.colormap = gtk_widget_get_colormap (widget);
	      
	      child = gdk_window_new (parent, &attributes,
				      GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP);

	      pattern_set_bg (widget, child, level);

	      if (level < 2)
		create_pattern (widget, child, level + 1, w, h);

	      gdk_window_show (child);
	    }
	  j++;
	  w *= 2;
	}
      i++;
      h *= 2;
    }
}

#define PATTERN_SIZE (1 << 18)

static void
pattern_hadj_changed (GtkAdjustment *adj,
		      GtkWidget     *darea)
{
  gint *old_value = g_object_get_data (G_OBJECT (adj), "old-value");
  gint new_value = adj->value;

  if (GTK_WIDGET_REALIZED (darea))
    {
      gdk_window_scroll (darea->window, *old_value - new_value, 0);
      *old_value = new_value;
    }
}

static void
pattern_vadj_changed (GtkAdjustment *adj,
		      GtkWidget *darea)
{
  gint *old_value = g_object_get_data (G_OBJECT (adj), "old-value");
  gint new_value = adj->value;

  if (GTK_WIDGET_REALIZED (darea))
    {
      gdk_window_scroll (darea->window, 0, *old_value - new_value);
      *old_value = new_value;
    }
}

static void
pattern_realize (GtkWidget *widget,
		 gpointer   data)
{
  pattern_set_bg (widget, widget->window, 0);
  create_pattern (widget, widget->window, 1, PATTERN_SIZE, PATTERN_SIZE);
}

static void 
703
create_big_windows (GtkWidget *widget)
704 705 706 707 708 709 710 711
{
  static GtkWidget *window = NULL;
  GtkWidget *darea, *table, *scrollbar;
  GtkWidget *eventbox;
  GtkAdjustment *hadj;
  GtkAdjustment *vadj;
  static gint current_x;
  static gint current_y;
712
 
713 714 715 716 717 718 719 720 721 722
  if (!window)
    {
      current_x = 0;
      current_y = 0;
      
      window = gtk_dialog_new_with_buttons ("Big Windows",
                                            NULL, 0,
                                            GTK_STOCK_CLOSE,
                                            GTK_RESPONSE_NONE,
                                            NULL);
723 724 725
 
      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));
726 727 728

      gtk_window_set_default_size (GTK_WINDOW (window), 200, 300);

Manish Singh's avatar
Manish Singh committed
729 730 731
      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
732

Manish Singh's avatar
Manish Singh committed
733 734 735
      g_signal_connect (window, "response",
                        G_CALLBACK (gtk_widget_destroy),
                        NULL);
736 737 738 739 740 741 742 743

      table = gtk_table_new (2, 2, FALSE);
      gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox),
			  table, TRUE, TRUE, 0);

      darea = gtk_drawing_area_new ();

      hadj = (GtkAdjustment *)gtk_adjustment_new (0, 0, PATTERN_SIZE, 10, 100, 100);
Manish Singh's avatar
Manish Singh committed
744 745
      g_signal_connect (hadj, "value_changed",
			G_CALLBACK (pattern_hadj_changed), darea);
746 747 748
      g_object_set_data (G_OBJECT (hadj), "old-value", &current_x);
      
      vadj = (GtkAdjustment *)gtk_adjustment_new (0, 0, PATTERN_SIZE, 10, 100, 100);
Manish Singh's avatar
Manish Singh committed
749 750
      g_signal_connect (vadj, "value_changed",
			G_CALLBACK (pattern_vadj_changed), darea);
751 752
      g_object_set_data (G_OBJECT (vadj), "old-value", &current_y);
      
Manish Singh's avatar
Manish Singh committed
753 754 755 756 757 758
      g_signal_connect (darea, "realize",
                        G_CALLBACK (pattern_realize),
                        NULL);
      g_signal_connect (darea, "expose_event",
                        G_CALLBACK (pattern_expose),
                        NULL);
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787

      eventbox = gtk_event_box_new ();
      gtk_table_attach (GTK_TABLE (table), eventbox,
			0, 1,                  0, 1,
			GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND,
			0,                     0);

      gtk_container_add (GTK_CONTAINER (eventbox), darea);

      scrollbar = gtk_hscrollbar_new (hadj);
      gtk_table_attach (GTK_TABLE (table), scrollbar,
			0, 1,                  1, 2,
			GTK_FILL | GTK_EXPAND, GTK_FILL,
			0,                     0);

      scrollbar = gtk_vscrollbar_new (vadj);
      gtk_table_attach (GTK_TABLE (table), scrollbar,
			1, 2,                  0, 1,
			GTK_FILL,              GTK_EXPAND | GTK_FILL,
			0,                     0);

    }

  if (!GTK_WIDGET_VISIBLE (window))
    gtk_widget_show_all (window);
  else
    gtk_widget_hide (window);
}

788 789 790 791
/*
 * GtkButton
 */

792
static void
Elliot Lee's avatar
Elliot Lee committed
793 794 795 796 797 798 799 800 801
button_window (GtkWidget *widget,
	       GtkWidget *button)
{
  if (!GTK_WIDGET_VISIBLE (button))
    gtk_widget_show (button);
  else
    gtk_widget_hide (button);
}

802
static void
803
create_buttons (GtkWidget *widget)
Elliot Lee's avatar
Elliot Lee committed
804 805 806 807 808 809 810 811 812 813 814
{
  static GtkWidget *window = NULL;
  GtkWidget *box1;
  GtkWidget *box2;
  GtkWidget *table;
  GtkWidget *button[10];
  GtkWidget *separator;

  if (!window)
    {
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
815 816
      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));
Elliot Lee's avatar
Elliot Lee committed
817

Manish Singh's avatar
Manish Singh committed
818 819 820
      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
Elliot Lee's avatar
Elliot Lee committed
821

822
      gtk_window_set_title (GTK_WINDOW (window), "GtkButton");
823
      gtk_container_set_border_width (GTK_CONTAINER (window), 0);
Elliot Lee's avatar
Elliot Lee committed
824 825 826 827 828 829 830

      box1 = gtk_vbox_new (FALSE, 0);
      gtk_container_add (GTK_CONTAINER (window), box1);

      table = gtk_table_new (3, 3, FALSE);
      gtk_table_set_row_spacings (GTK_TABLE (table), 5);
      gtk_table_set_col_spacings (GTK_TABLE (table), 5);
831
      gtk_container_set_border_width (GTK_CONTAINER (table), 10);
Elliot Lee's avatar
Elliot Lee committed
832 833 834
      gtk_box_pack_start (GTK_BOX (box1), table, TRUE, TRUE, 0);

      button[0] = gtk_button_new_with_label ("button1");
835
      button[1] = gtk_button_new_with_mnemonic ("_button2");
836
      button[2] = gtk_button_new_with_mnemonic ("_button3");
837
      button[3] = gtk_button_new_from_stock (GTK_STOCK_OK);
Elliot Lee's avatar
Elliot Lee committed
838 839 840
      button[4] = gtk_button_new_with_label ("button5");
      button[5] = gtk_button_new_with_label ("button6");
      button[6] = gtk_button_new_with_label ("button7");
841
      button[7] = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
Elliot Lee's avatar
Elliot Lee committed
842
      button[8] = gtk_button_new_with_label ("button9");
843
      
Manish Singh's avatar
Manish Singh committed
844 845 846
      g_signal_connect (button[0], "clicked",
			G_CALLBACK (button_window),
			button[1]);
Elliot Lee's avatar
Elliot Lee committed
847 848 849 850

      gtk_table_attach (GTK_TABLE (table), button[0], 0, 1, 0, 1,
			GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);

Manish Singh's avatar
Manish Singh committed
851 852 853
      g_signal_connect (button[1], "clicked",
			G_CALLBACK (button_window),
			button[2]);
Elliot Lee's avatar
Elliot Lee committed
854 855 856 857

      gtk_table_attach (GTK_TABLE (table), button[1], 1, 2, 1, 2,
			GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);

Manish Singh's avatar
Manish Singh committed
858 859 860
      g_signal_connect (button[2], "clicked",
			G_CALLBACK (button_window),
			button[3]);
Elliot Lee's avatar
Elliot Lee committed
861 862 863
      gtk_table_attach (GTK_TABLE (table), button[2], 2, 3, 2, 3,
			GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);

Manish Singh's avatar
Manish Singh committed
864 865 866
      g_signal_connect (button[3], "clicked",
			G_CALLBACK (button_window),
			button[4]);
Elliot Lee's avatar
Elliot Lee committed
867 868 869
      gtk_table_attach (GTK_TABLE (table), button[3], 0, 1, 2, 3,
			GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);

Manish Singh's avatar
Manish Singh committed
870 871 872
      g_signal_connect (button[4], "clicked",
			G_CALLBACK (button_window),
			button[5]);
Elliot Lee's avatar
Elliot Lee committed
873 874 875
      gtk_table_attach (GTK_TABLE (table), button[4], 2, 3, 0, 1,
			GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);

Manish Singh's avatar
Manish Singh committed
876 877 878
      g_signal_connect (button[5], "clicked",
			G_CALLBACK (button_window),
			button[6]);
Elliot Lee's avatar
Elliot Lee committed
879 880 881
      gtk_table_attach (GTK_TABLE (table), button[5], 1, 2, 2, 3,
			GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);

Manish Singh's avatar
Manish Singh committed
882 883 884
      g_signal_connect (button[6], "clicked",
			G_CALLBACK (button_window),
			button[7]);
Elliot Lee's avatar
Elliot Lee committed
885 886 887
      gtk_table_attach (GTK_TABLE (table), button[6], 1, 2, 0, 1,
			GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);

Manish Singh's avatar
Manish Singh committed
888 889 890
      g_signal_connect (button[7], "clicked",
			G_CALLBACK (button_window),
			button[8]);
Elliot Lee's avatar
Elliot Lee committed
891 892 893
      gtk_table_attach (GTK_TABLE (table), button[7], 2, 3, 1, 2,
			GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);

Manish Singh's avatar
Manish Singh committed
894 895 896
      g_signal_connect (button[8], "clicked",
			G_CALLBACK (button_window),
			button[0]);
Elliot Lee's avatar
Elliot Lee committed
897 898 899 900 901 902 903
      gtk_table_attach (GTK_TABLE (table), button[8], 0, 1, 1, 2,
			GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);

      separator = gtk_hseparator_new ();
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);

      box2 = gtk_vbox_new (FALSE, 10);
904
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
Elliot Lee's avatar
Elliot Lee committed
905 906 907
      gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);

      button[9] = gtk_button_new_with_label ("close");
Manish Singh's avatar
Manish Singh committed
908 909 910
      g_signal_connect_swapped (button[9], "clicked",
				G_CALLBACK (gtk_widget_destroy),
				window);
Elliot Lee's avatar
Elliot Lee committed
911 912 913 914 915 916
      gtk_box_pack_start (GTK_BOX (box2), button[9], TRUE, TRUE, 0);
      GTK_WIDGET_SET_FLAGS (button[9], GTK_CAN_DEFAULT);
      gtk_widget_grab_default (button[9]);
    }

  if (!GTK_WIDGET_VISIBLE (window))
917
    gtk_widget_show_all (window);
Elliot Lee's avatar
Elliot Lee committed
918
  else
919
    gtk_widget_destroy (window);
Elliot Lee's avatar
Elliot Lee committed
920 921
}

922 923 924 925
/*
 * GtkToggleButton
 */

926
static void
927
create_toggle_buttons (GtkWidget *widget)
Elliot Lee's avatar
Elliot Lee committed
928 929 930 931 932 933 934 935 936 937
{
  static GtkWidget *window = NULL;
  GtkWidget *box1;
  GtkWidget *box2;
  GtkWidget *button;
  GtkWidget *separator;

  if (!window)
    {
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
938 939
      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));
Elliot Lee's avatar
Elliot Lee committed
940

Manish Singh's avatar
Manish Singh committed
941 942 943
      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
Elliot Lee's avatar
Elliot Lee committed
944

945
      gtk_window_set_title (GTK_WINDOW (window), "GtkToggleButton");
946
      gtk_container_set_border_width (GTK_CONTAINER (window), 0);
Elliot Lee's avatar
Elliot Lee committed
947 948 949 950 951

      box1 = gtk_vbox_new (FALSE, 0);
      gtk_container_add (GTK_CONTAINER (window), box1);

      box2 = gtk_vbox_new (FALSE, 10);
952
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
Elliot Lee's avatar
Elliot Lee committed
953 954 955 956 957 958 959 960 961 962 963
      gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);

      button = gtk_toggle_button_new_with_label ("button1");
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);

      button = gtk_toggle_button_new_with_label ("button2");
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);

      button = gtk_toggle_button_new_with_label ("button3");
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);

964 965 966 967
      button = gtk_toggle_button_new_with_label ("inconsistent");
      gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button), TRUE);
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
      
Elliot Lee's avatar
Elliot Lee committed
968 969 970 971
      separator = gtk_hseparator_new ();
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);

      box2 = gtk_vbox_new (FALSE, 10);
972
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
Elliot Lee's avatar
Elliot Lee committed
973 974 975
      gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);

      button = gtk_button_new_with_label ("close");
Manish Singh's avatar
Manish Singh committed
976 977 978
      g_signal_connect_swapped (button, "clicked",
			        G_CALLBACK (gtk_widget_destroy),
				window);
Elliot Lee's avatar
Elliot Lee committed
979 980 981 982 983 984
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
      GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
      gtk_widget_grab_default (button);
    }

  if (!GTK_WIDGET_VISIBLE (window))
985
    gtk_widget_show_all (window);
Elliot Lee's avatar
Elliot Lee committed
986 987 988 989
  else
    gtk_widget_destroy (window);
}

990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
static GtkWidget *
create_widget_grid (GType widget_type)
{
  GtkWidget *table;
  GtkWidget *group_widget = NULL;
  gint i, j;
  
  table = gtk_table_new (FALSE, 3, 3);
  
  for (i = 0; i < 5; i++)
    {
      for (j = 0; j < 5; j++)
	{
	  GtkWidget *widget;
	  char *tmp;
	  
	  if (i == 0 && j == 0)
	    {
	      widget = NULL;
	    }
	  else if (i == 0)
	    {
	      tmp = g_strdup_printf ("%d", j);
	      widget = gtk_label_new (tmp);
	      g_free (tmp);
	    }
	  else if (j == 0)
	    {
	      tmp = g_strdup_printf ("%c", 'A' + i - 1);
	      widget = gtk_label_new (tmp);
	      g_free (tmp);
	    }
	  else
	    {
	      widget = g_object_new (widget_type, NULL);
	      
	      if (g_type_is_a (widget_type, GTK_TYPE_RADIO_BUTTON))
		{
		  if (!group_widget)
		    group_widget = widget;
		  else
		    g_object_set (widget, "group", group_widget, NULL);
		}
	    }
	  
	  if (widget)
	    gtk_table_attach (GTK_TABLE (table), widget,
			      i, i + 1, j, j + 1,
			      0,        0,
			      0,        0);
	}
    }

  return table;
}

1046 1047 1048 1049
/*
 * GtkCheckButton
 */

1050
static void
1051
create_check_buttons (GtkWidget *widget)
Elliot Lee's avatar
Elliot Lee committed
1052 1053 1054 1055 1056 1057
{
  static GtkWidget *window = NULL;
  GtkWidget *box1;
  GtkWidget *box2;
  GtkWidget *button;
  GtkWidget *separator;
1058
  GtkWidget *table;
1059
  
Elliot Lee's avatar
Elliot Lee committed
1060 1061
  if (!window)
    {
1062 1063 1064 1065 1066 1067
      window = gtk_dialog_new_with_buttons ("Check Buttons",
                                            NULL, 0,
                                            GTK_STOCK_CLOSE,
                                            GTK_RESPONSE_NONE,
                                            NULL);

1068 1069
      gtk_window_set_screen (GTK_WINDOW (window), 
			     gtk_widget_get_screen (widget));
Elliot Lee's avatar
Elliot Lee committed
1070

Manish Singh's avatar
Manish Singh committed
1071 1072 1073
      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
1074 1075 1076
      g_signal_connect (window, "response",
                        G_CALLBACK (gtk_widget_destroy),
                        NULL);
Elliot Lee's avatar
Elliot Lee committed
1077

1078 1079
      box1 = GTK_DIALOG (window)->vbox;
      
Elliot Lee's avatar
Elliot Lee committed
1080
      box2 = gtk_vbox_new (FALSE, 10);
1081
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
Elliot Lee's avatar
Elliot Lee committed
1082 1083
      gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);

1084
      button = gtk_check_button_new_with_mnemonic ("_button1");
Elliot Lee's avatar
Elliot Lee committed
1085 1086 1087 1088 1089 1090 1091 1092
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);

      button = gtk_check_button_new_with_label ("button2");
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);

      button = gtk_check_button_new_with_label ("button3");
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);

1093 1094 1095
      button = gtk_check_button_new_with_label ("inconsistent");
      gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button), TRUE);
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1096

Elliot Lee's avatar
Elliot Lee committed
1097 1098 1099
      separator = gtk_hseparator_new ();
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);

1100 1101 1102
      table = create_widget_grid (GTK_TYPE_CHECK_BUTTON);
      gtk_container_set_border_width (GTK_CONTAINER (table), 10);
      gtk_box_pack_start (GTK_BOX (box1), table, TRUE, TRUE, 0);
Elliot Lee's avatar
Elliot Lee committed
1103 1104 1105
    }

  if (!GTK_WIDGET_VISIBLE (window))
1106
    gtk_widget_show_all (window);
Elliot Lee's avatar
Elliot Lee committed
1107 1108 1109 1110
  else
    gtk_widget_destroy (window);
}

1111 1112 1113 1114
/*
 * GtkRadioButton
 */

1115
static void
1116
create_radio_buttons (GtkWidget *widget)
Elliot Lee's avatar
Elliot Lee committed
1117 1118 1119 1120 1121 1122
{
  static GtkWidget *window = NULL;
  GtkWidget *box1;
  GtkWidget *box2;
  GtkWidget *button;
  GtkWidget *separator;
1123
  GtkWidget *table;
Elliot Lee's avatar
Elliot Lee committed
1124 1125 1126

  if (!window)
    {
1127 1128 1129 1130 1131
      window = gtk_dialog_new_with_buttons ("Radio Buttons",
                                            NULL, 0,
                                            GTK_STOCK_CLOSE,
                                            GTK_RESPONSE_NONE,
                                            NULL);
Elliot Lee's avatar
Elliot Lee committed
1132

1133 1134 1135
      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));

Manish Singh's avatar
Manish Singh committed
1136 1137 1138
      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
1139 1140 1141
      g_signal_connect (window, "response",
                        G_CALLBACK (gtk_widget_destroy),
                        NULL);
Elliot Lee's avatar
Elliot Lee committed
1142

1143
      box1 = GTK_DIALOG (window)->vbox;
Elliot Lee's avatar
Elliot Lee committed
1144 1145

      box2 = gtk_vbox_new (FALSE, 10);
1146
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
Elliot Lee's avatar
Elliot Lee committed
1147 1148 1149 1150 1151 1152
      gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);

      button = gtk_radio_button_new_with_label (NULL, "button1");
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);

      button = gtk_radio_button_new_with_label (
1153
	         gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
Elliot Lee's avatar
Elliot Lee committed
1154
		 "button2");
1155
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
Elliot Lee's avatar
Elliot Lee committed
1156 1157 1158
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);

      button = gtk_radio_button_new_with_label (
1159
                 gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
Elliot Lee's avatar
Elliot Lee committed
1160 1161 1162
		 "button3");
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);

1163
      button = gtk_radio_button_new_with_label (
1164
                 gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
1165 1166 1167 1168
		 "inconsistent");
      gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button), TRUE);
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
      
Elliot Lee's avatar
Elliot Lee committed
1169 1170 1171
      separator = gtk_hseparator_new ();
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);

1172 1173 1174 1175
      box2 = gtk_vbox_new (FALSE, 10);
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
      gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);

1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
      button = gtk_radio_button_new_with_label (NULL, "button4");
      gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);

      button = gtk_radio_button_new_with_label (
	         gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
		 "button5");
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
      gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);

      button = gtk_radio_button_new_with_label (
                 gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
		 "button6");
      gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);

      separator = gtk_hseparator_new ();
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);

1196 1197 1198
      table = create_widget_grid (GTK_TYPE_RADIO_BUTTON);
      gtk_container_set_border_width (GTK_CONTAINER (table), 10);
      gtk_box_pack_start (GTK_BOX (box1), table, TRUE, TRUE, 0);
Elliot Lee's avatar
Elliot Lee committed
1199 1200 1201
    }

  if (!GTK_WIDGET_VISIBLE (window))
1202
    gtk_widget_show_all (window);
Elliot Lee's avatar
Elliot Lee committed
1203 1204 1205 1206
  else
    gtk_widget_destroy (window);
}

1207 1208 1209
/*
 * GtkButtonBox
 */
Elliot Lee's avatar
Elliot Lee committed
1210

1211 1212 1213 1214
static GtkWidget *
create_bbox (gint  horizontal,
	     char* title, 
	     gint  spacing,
Manish Singh's avatar
Manish Singh committed
1215 1216
	     gint  child_w,
	     gint  child_h,
1217
	     gint  layout)
Elliot Lee's avatar
Elliot Lee committed
1218
{
1219 1220 1221
  GtkWidget *frame;
  GtkWidget *bbox;
  GtkWidget *button;
Elliot Lee's avatar
Elliot Lee committed
1222
	
1223
  frame = gtk_frame_new (title);
Elliot Lee's avatar
Elliot Lee committed
1224 1225

  if (horizontal)
1226
    bbox = gtk_hbutton_box_new ();
Elliot Lee's avatar
Elliot Lee committed
1227
  else
1228 1229
    bbox = gtk_vbutton_box_new ();

1230
  gtk_container_set_border_width (GTK_CONTAINER (bbox), 5);
1231 1232
  gtk_container_add (GTK_CONTAINER (frame), bbox);

Elliot Lee's avatar
Elliot Lee committed
1233
  gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
1234
  gtk_box_set_spacing (GTK_BOX (bbox), spacing);
Elliot Lee's avatar
Elliot Lee committed
1235 1236 1237
  gtk_button_box_set_child_size (GTK_BUTTON_BOX (bbox), child_w, child_h);
  
  button = gtk_button_new_with_label ("OK");
1238
  gtk_container_add (GTK_CONTAINER (bbox), button);
Elliot Lee's avatar
Elliot Lee committed
1239 1240
  
  button = gtk_button_new_with_label ("Cancel");
1241
  gtk_container_add (GTK_CONTAINER (bbox), button);
Elliot Lee's avatar
Elliot Lee committed
1242 1243
  
  button = gtk_button_new_with_label ("Help");
1244
  gtk_container_add (GTK_CONTAINER (bbox), button);
Elliot Lee's avatar
Elliot Lee committed
1245

1246
  return frame;
Elliot Lee's avatar
Elliot Lee committed
1247 1248
}

1249
static void
1250
create_button_box (GtkWidget *widget)
Elliot Lee's avatar
Elliot Lee committed
1251 1252
{
  static GtkWidget* window = NULL;
1253 1254 1255 1256 1257
  GtkWidget *main_vbox;
  GtkWidget *vbox;
  GtkWidget *hbox;
  GtkWidget *frame_horz;
  GtkWidget *frame_vert;
1258

Elliot Lee's avatar
Elliot Lee committed
1259 1260 1261
  if (!window)
  {
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1262
    gtk_window_set_screen (GTK_WINDOW (window), gtk_widget_get_screen (widget));
1263
    gtk_window_set_title (GTK_WINDOW (window), "Button Boxes");
Elliot Lee's avatar
Elliot Lee committed
1264
    
Manish Singh's avatar
Manish Singh committed
1265 1266 1267
    g_signal_connect (window, "destroy",
		      G_CALLBACK (gtk_widget_destroyed),
		      &window);
1268

1269
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
1270 1271 1272

    main_vbox = gtk_vbox_new (FALSE, 0);
    gtk_container_add (GTK_CONTAINER (window), main_vbox);
Elliot Lee's avatar
Elliot Lee committed
1273
    
1274 1275
    frame_horz = gtk_frame_new ("Horizontal Button Boxes");
    gtk_box_pack_start (GTK_BOX (main_vbox), frame_horz, TRUE, TRUE, 10);
Elliot Lee's avatar
Elliot Lee committed
1276
    
1277
    vbox = gtk_vbox_new (FALSE, 0);
1278
    gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);
1279
    gtk_container_add (GTK_CONTAINER (frame_horz), vbox);
1280
    
1281
    gtk_box_pack_start (GTK_BOX (vbox), 
1282
                        create_bbox (TRUE, "Spread", 40, 85, 20, GTK_BUTTONBOX_SPREAD),
1283
			TRUE, TRUE, 0);
1284
    
1285
    gtk_box_pack_start (GTK_BOX (vbox), 
1286
                        create_bbox (TRUE, "Edge", 40, 85, 20, GTK_BUTTONBOX_EDGE),
1287
			TRUE, TRUE, 5);
1288
    
1289
    gtk_box_pack_start (GTK_BOX (vbox), 
1290
                        create_bbox (TRUE, "Start", 40, 85, 20, GTK_BUTTONBOX_START),
1291
			TRUE, TRUE, 5);
1292
    
1293
    gtk_box_pack_start (GTK_BOX (vbox), 
1294
                        create_bbox (TRUE, "End", 40, 85, 20, GTK_BUTTONBOX_END),
1295
			TRUE, TRUE, 5);
1296 1297 1298 1299 1300
    
    gtk_box_pack_start (GTK_BOX (vbox),
                        create_bbox (TRUE, "Center", 40, 85, 20, GTK_BUTTONBOX_CENTER),
			TRUE, TRUE, 5);
    
1301 1302
    frame_vert = gtk_frame_new ("Vertical Button Boxes");
    gtk_box_pack_start (GTK_BOX (main_vbox), frame_vert, TRUE, TRUE, 10);
Elliot Lee's avatar
Elliot Lee committed
1303
    
1304
    hbox = gtk_hbox_new (FALSE, 0);
1305
    gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
1306 1307 1308
    gtk_container_add (GTK_CONTAINER (frame_vert), hbox);

    gtk_box_pack_start (GTK_BOX (hbox), 
1309
                        create_bbox (FALSE, "Spread", 30, 85, 20, GTK_BUTTONBOX_SPREAD),
1310
			TRUE, TRUE, 0);
1311
    
1312
    gtk_box_pack_start (GTK_BOX (hbox), 
1313
                        create_bbox (FALSE, "Edge", 30, 85, 20, GTK_BUTTONBOX_EDGE),
1314
			TRUE, TRUE, 5);
1315
    
1316
    gtk_box_pack_start (GTK_BOX (hbox), 
1317
                        create_bbox (FALSE, "Start", 30, 85, 20, GTK_BUTTONBOX_START),
1318
			TRUE, TRUE, 5);
1319
    
1320
    gtk_box_pack_start (GTK_BOX (hbox), 
1321 1322 1323 1324 1325
                        create_bbox (FALSE, "End", 30, 85, 20, GTK_BUTTONBOX_END),
			TRUE, TRUE, 5);
    
    gtk_box_pack_start (GTK_BOX (hbox),
                        create_bbox (FALSE, "Center", 30, 85, 20, GTK_BUTTONBOX_CENTER),
1326
			TRUE, TRUE, 5);
Elliot Lee's avatar
Elliot Lee committed
1327 1328 1329
  }

  if (!GTK_WIDGET_VISIBLE (window))
1330
    gtk_widget_show_all (window);
Elliot Lee's avatar
Elliot Lee committed
1331 1332 1333 1334
  else
    gtk_widget_destroy (window);
}

1335 1336 1337 1338
/*
 * GtkToolBar
 */

1339
static GtkWidget*
1340 1341 1342
new_pixmap (char      *filename,
	    GdkWindow *window,
	    GdkColor  *background)
1343 1344 1345 1346 1347
{
  GtkWidget *wpixmap;
  GdkPixmap *pixmap;
  GdkBitmap *mask;

1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359
  if (strcmp (filename, "test.xpm") == 0 ||
      !file_exists (filename))
    {
      pixmap = gdk_pixmap_create_from_xpm_d (window, &mask,
					     background,
					     openfile);
    }
  else
    pixmap = gdk_pixmap_create_from_xpm (window, &mask,
					 background,
					 filename);
  
Manish Singh's avatar
Manish Singh committed
1360
  wpixmap = gtk_image_new_from_pixmap (pixmap, mask);
1361 1362 1363 1364

  return wpixmap;
}

1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379

static void
set_toolbar_small_stock (GtkWidget *widget,
			 gpointer   data)
{
  gtk_toolbar_set_icon_size (GTK_TOOLBAR (data), GTK_ICON_SIZE_SMALL_TOOLBAR);
}

static void
set_toolbar_large_stock (GtkWidget *widget,
			 gpointer   data)
{
  gtk_toolbar_set_icon_size (GTK_TOOLBAR (data), GTK_ICON_SIZE_LARGE_TOOLBAR);
}

1380
static void
1381 1382 1383 1384 1385 1386
set_toolbar_horizontal (GtkWidget *widget,
			gpointer   data)
{
  gtk_toolbar_set_orientation (GTK_TOOLBAR (data), GTK_ORIENTATION_HORIZONTAL);
}

1387
static void
1388 1389 1390 1391 1392 1393
set_toolbar_vertical (GtkWidget *widget,
		      gpointer   data)
{
  gtk_toolbar_set_orientation (GTK_TOOLBAR (data), GTK_ORIENTATION_VERTICAL);
}

1394
static void
1395 1396 1397 1398 1399 1400
set_toolbar_icons (GtkWidget *widget,
		   gpointer   data)
{
  gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_ICONS);
}

1401
static void
1402 1403 1404 1405 1406 1407
set_toolbar_text (GtkWidget *widget,
	          gpointer   data)
{
  gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_TEXT);
}

1408
static void
1409 1410 1411 1412 1413 1414
set_toolbar_both (GtkWidget *widget,
		  gpointer   data)
{
  gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_BOTH);
}

1415 1416 1417 1418 1419 1420 1421
static void
set_toolbar_both_horiz (GtkWidget *widget,
			gpointer   data)
{
  gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_BOTH_HORIZ);
}

1422
static void
1423 1424 1425 1426 1427 1428
set_toolbar_enable (GtkWidget *widget,
		    gpointer   data)
{
  gtk_toolbar_set_tooltips (GTK_TOOLBAR (data), TRUE);
}

1429
static void
1430 1431 1432 1433 1434 1435
set_toolbar_disable (GtkWidget *widget,
		     gpointer   data)
{
  gtk_toolbar_set_tooltips (GTK_TOOLBAR (data), FALSE);
}

1436
static void
1437
create_toolbar (GtkWidget *widget)
1438 1439 1440
{
  static GtkWidget *window = NULL;
  GtkWidget *toolbar;
1441
  GtkWidget *entry;
1442 1443 1444 1445

  if (!window)
    {
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1446 1447 1448
      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));
      
1449 1450
      gtk_window_set_title (GTK_WINDOW (window), "Toolbar test");

Manish Singh's avatar
Manish Singh committed
1451 1452 1453
      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
1454

1455
      gtk_container_set_border_width (GTK_CONTAINER (window), 0);
1456 1457
      gtk_widget_realize (window);

1458
      toolbar = gtk_toolbar_new ();
1459

1460 1461 1462
      gtk_toolbar_insert_stock (GTK_TOOLBAR (toolbar),
				GTK_STOCK_NEW,
				"Stock icon: New", "Toolbar/New",
Manish Singh's avatar
Manish Singh committed
1463
				G_CALLBACK (set_toolbar_small_stock), toolbar, -1);
1464 1465 1466 1467
      
      gtk_toolbar_insert_stock (GTK_TOOLBAR (toolbar),
				GTK_STOCK_OPEN,
				"Stock icon: Open", "Toolbar/Open",
Manish Singh's avatar
Manish Singh committed
1468
				G_CALLBACK (set_toolbar_large_stock), toolbar, -1);
1469
      
1470
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1471
			       "Horizontal", "Horizontal toolbar layout", "Toolbar/Horizontal",
1472
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1473
			       G_CALLBACK (set_toolbar_horizontal), toolbar);
1474
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1475
			       "Vertical", "Vertical toolbar layout", "Toolbar/Vertical",
1476
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1477
			       G_CALLBACK (set_toolbar_vertical), toolbar);
1478 1479 1480 1481

      gtk_toolbar_append_space (GTK_TOOLBAR(toolbar));

      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1482
			       "Icons", "Only show toolbar icons", "Toolbar/IconsOnly",
1483
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1484
			       G_CALLBACK (set_toolbar_icons), toolbar);
1485
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1486
			       "Text", "Only show toolbar text", "Toolbar/TextOnly",
1487
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1488
			       G_CALLBACK (set_toolbar_text), toolbar);
1489
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1490
			       "Both", "Show toolbar icons and text", "Toolbar/Both",
1491
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1492
			       G_CALLBACK (set_toolbar_both), toolbar);
1493 1494 1495 1496 1497
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
			       "Both (horizontal)",
			       "Show toolbar icons and text in a horizontal fashion",
			       "Toolbar/BothHoriz",
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1498
			       G_CALLBACK (set_toolbar_both_horiz), toolbar);
1499
			       
1500 1501
      gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));

1502
      entry = gtk_entry_new ();
1503

1504
      gtk_toolbar_append_widget (GTK_TOOLBAR (toolbar), entry, "This is an unusable GtkEntry ;)", "Hey don't click me!!!");
1505 1506 1507

      gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));

1508

1509 1510
      gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));

1511
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1512
			       "Enable", "Enable tooltips", NULL,
1513
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1514
			       G_CALLBACK (set_toolbar_enable), toolbar);
1515
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1516
			       "Disable", "Disable tooltips", NULL,
1517
			       new_pixmap ("test.xpm", window->window, &window->style-></