testgtk.c 299 KB
Newer Older
Cody Russell's avatar
Cody Russell committed
1
/* GTK - The GIMP Toolkit
Emmanuele Bassi's avatar
Emmanuele Bassi committed
2 3 4 5 6 7 8 9 10 11 12 13 14
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * 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
15
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
Emmanuele Bassi's avatar
Emmanuele Bassi committed
16
 */
17

Emmanuele Bassi's avatar
Emmanuele Bassi committed
18 19 20 21 22 23 24 25
/*
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
 * 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/. 
 */


26
#include "config.h"
Emmanuele Bassi's avatar
Emmanuele Bassi committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

#undef	G_LOG_DOMAIN

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <math.h>
#include <time.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#include "gtk/gtk.h"
#include "gdk/gdk.h"
#include "gdk/gdkkeysyms.h"

#ifdef G_OS_WIN32
#define sleep(n) _sleep(n)
#endif

#include "test.xpm"

gboolean
file_exists (const char *filename)
{
  struct stat statbuf;

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

GtkWidget *
shape_create_icon (GdkScreen *screen,
		   char      *xpm_file,
		   gint       x,
		   gint       y,
		   gint       px,
		   gint       py,
		   gint       window_type);

static GtkWidget *
build_option_menu (gchar           *items[],
		   gint             num_items,
		   gint             history,
		   void           (*func) (GtkWidget *widget, gpointer data),
		   gpointer         data);

/* 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;
  GtkWidget* subtree_button;
} sTreeButtons;
/* end of tree section */

static GtkWidget *
build_option_menu (gchar           *items[],
		   gint             num_items,
		   gint             history,
		   void           (*func)(GtkWidget *widget, gpointer data),
		   gpointer         data)
{
  GtkWidget *omenu;
  gint i;

108
  omenu = gtk_combo_box_text_new ();
Emmanuele Bassi's avatar
Emmanuele Bassi committed
109 110 111 112
  g_signal_connect (omenu, "changed",
		    G_CALLBACK (func), data);
      
  for (i = 0; i < num_items; i++)
113
      gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (omenu), items[i]);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
114

115
  gtk_combo_box_set_active (GTK_COMBO_BOX (omenu), history);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
116 117 118 119 120 121 122 123 124 125
  
  return omenu;
}

/*
 * Windows with an alpha channel
 */


static gboolean
126 127
on_alpha_window_draw (GtkWidget *widget,
                      cairo_t   *cr)
Emmanuele Bassi's avatar
Emmanuele Bassi committed
128 129
{
  cairo_pattern_t *pattern;
130
  int radius, width, height;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
131

132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
  /* Get the child allocation to avoid painting over the borders */
  GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
  GtkAllocation child_allocation;
  int border_width = gtk_container_get_border_width (GTK_CONTAINER (child));

  gtk_widget_get_allocation (child, &child_allocation);
  child_allocation.x -= border_width;
  child_allocation.y -= border_width;
  child_allocation.width += 2 * border_width;
  child_allocation.height += 2 * border_width;

  cairo_translate (cr, child_allocation.x, child_allocation.y);

  cairo_rectangle (cr, 0, 0, child_allocation.width, child_allocation.height);
  cairo_clip (cr);

148 149 150 151 152
  width = gtk_widget_get_allocated_width (widget);
  height = gtk_widget_get_allocated_height (widget);
  radius = MIN (width, height) / 2;
  pattern = cairo_pattern_create_radial (width / 2,
                                         height / 2,
Emmanuele Bassi's avatar
Emmanuele Bassi committed
153
					 0.0,
154 155
                                         width / 2,
                                         height / 2,
Emmanuele Bassi's avatar
Emmanuele Bassi committed
156 157
					 radius * 1.33);

158
  if (gdk_screen_get_rgba_visual (gtk_widget_get_screen (widget)) &&
Emmanuele Bassi's avatar
Emmanuele Bassi committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
      gtk_widget_is_composited (widget))
    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);

  return FALSE;
}

static GtkWidget *
build_alpha_widgets (void)
{
184
  GtkWidget *grid;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
185
  GtkWidget *radio_button;
186
  GtkWidget *check_button;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
187 188 189 190
  GtkWidget *hbox;
  GtkWidget *label;
  GtkWidget *entry;

191
  grid = gtk_grid_new ();
Emmanuele Bassi's avatar
Emmanuele Bassi committed
192 193

  radio_button = gtk_radio_button_new_with_label (NULL, "Red");
194 195
  gtk_widget_set_hexpand (radio_button, TRUE);
  gtk_grid_attach (GTK_GRID (grid), radio_button, 0, 0, 1, 1);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
196 197

  radio_button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_button), "Green");
198 199
  gtk_widget_set_hexpand (radio_button, TRUE);
  gtk_grid_attach (GTK_GRID (grid), radio_button, 0, 1, 1, 1);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
200 201

  radio_button = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio_button), "Blue"),
202 203
  gtk_widget_set_hexpand (radio_button, TRUE);
  gtk_grid_attach (GTK_GRID (grid), radio_button, 0, 2, 1, 1);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
204

205 206 207 208 209 210 211 212 213 214 215
  check_button = gtk_check_button_new_with_label ("Sedentary"),
  gtk_widget_set_hexpand (check_button, TRUE);
  gtk_grid_attach (GTK_GRID (grid), check_button, 1, 0, 1, 1);

  check_button = gtk_check_button_new_with_label ("Nocturnal"),
  gtk_widget_set_hexpand (check_button, TRUE);
  gtk_grid_attach (GTK_GRID (grid), check_button, 1, 1, 1, 1);

  check_button = gtk_check_button_new_with_label ("Compulsive"),
  gtk_widget_set_hexpand (check_button, TRUE);
  gtk_grid_attach (GTK_GRID (grid), check_button, 1, 2, 1, 1);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
216

217
  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
218 219 220 221 222
  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);
223 224
  gtk_widget_set_hexpand (hbox, TRUE);
  gtk_grid_attach (GTK_GRID (grid), hbox, 0, 3, 2, 1);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
225
  
226
  return grid;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
227 228 229
}

static void
230
on_alpha_screen_changed (GtkWindow *window,
Emmanuele Bassi's avatar
Emmanuele Bassi committed
231 232 233
			 GdkScreen *old_screen,
			 GtkWidget *label)
{
234 235
  GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (window));
  GdkVisual *visual = gdk_screen_get_rgba_visual (screen);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
236

237
  if (!visual)
Emmanuele Bassi's avatar
Emmanuele Bassi committed
238
    {
239
      visual = gdk_screen_get_system_visual (screen);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
240 241 242 243 244 245 246
      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>");
    }

247
  gtk_widget_set_visual (GTK_WIDGET (window), visual);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
}

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");
}

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

  if (!window)
    {
269
      GtkWidget *content_area;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
270 271 272 273 274
      GtkWidget *vbox;
      GtkWidget *label;
      
      window = gtk_dialog_new_with_buttons ("Alpha Window",
					    GTK_WINDOW (gtk_widget_get_toplevel (widget)), 0,
275
					    "_Close", 0,
Emmanuele Bassi's avatar
Emmanuele Bassi committed
276 277 278
					    NULL);

      gtk_widget_set_app_paintable (window, TRUE);
279 280
      g_signal_connect (window, "draw",
			G_CALLBACK (on_alpha_window_draw), NULL);
281 282

      content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));
Emmanuele Bassi's avatar
Emmanuele Bassi committed
283
      
284
      vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
285
      gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
286
      gtk_box_pack_start (GTK_BOX (content_area), vbox,
Emmanuele Bassi's avatar
Emmanuele Bassi committed
287 288 289 290
			  TRUE, TRUE, 0);

      label = gtk_label_new (NULL);
      gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
291
      on_alpha_screen_changed (GTK_WINDOW (window), NULL, label);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
      g_signal_connect (window, "screen-changed",
			G_CALLBACK (on_alpha_screen_changed), label);
      
      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);

      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
      
      g_signal_connect (window, "response",
                        G_CALLBACK (gtk_widget_destroy),
                        NULL); 
    }

311
  if (!gtk_widget_get_visible (window))
Emmanuele Bassi's avatar
Emmanuele Bassi committed
312 313 314 315 316 317 318 319 320
    gtk_widget_show_all (window);
  else
    gtk_widget_destroy (window);
}

/*
 * Composited non-toplevel window
 */

321
/* The draw event handler for the event box.
Emmanuele Bassi's avatar
Emmanuele Bassi committed
322 323 324 325 326 327 328 329 330 331 332 333
 *
 * 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
334 335
transparent_draw (GtkWidget *widget,
                  cairo_t   *cr)
Emmanuele Bassi's avatar
Emmanuele Bassi committed
336 337
{
  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
338
  cairo_paint (cr);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354

  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
355 356
window_draw (GtkWidget *widget,
             cairo_t   *cr)
Emmanuele Bassi's avatar
Emmanuele Bassi committed
357
{
358
  GtkAllocation allocation;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
359 360
  GtkWidget *child;

361 362 363 364
  /* put a red background on the window */
  cairo_set_source_rgb (cr, 1, 0, 0);
  cairo_paint (cr);

Emmanuele Bassi's avatar
Emmanuele Bassi committed
365 366 367
  /* get our child (in this case, the event box) */ 
  child = gtk_bin_get_child (GTK_BIN (widget));

368
  gtk_widget_get_allocation (child, &allocation);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
369 370

  /* the source data is the (composited) event box */
371
  gdk_cairo_set_source_window (cr, gtk_widget_get_window (child),
372 373
                               allocation.x,
                               allocation.y);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
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 400 401 402 403

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

  return FALSE;
}

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

  if (!window)
    {
      GtkWidget *event, *button;

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

      g_signal_connect (window, "destroy",
                        G_CALLBACK (gtk_widget_destroyed),
                        &window);

      /* 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);
404 405
      g_signal_connect (event, "draw",
                        G_CALLBACK (transparent_draw), NULL);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
406 407 408 409 410 411 412 413 414 415 416 417

      /* 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.
       */
418
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
419 420
      gdk_window_set_composited (gtk_widget_get_window (event),
                                 TRUE);
421
G_GNUC_END_IGNORE_DEPRECATIONS
Emmanuele Bassi's avatar
Emmanuele Bassi committed
422 423 424 425 426

      /* set up the compositing handler.
       * note that we do _after so that the normal (red) background is drawn
       * by gtk before our compositing occurs.
       */
427 428
      g_signal_connect_after (window, "draw",
                              G_CALLBACK (window_draw), NULL);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
429 430
    }

431
  if (!gtk_widget_get_visible (window))
Emmanuele Bassi's avatar
Emmanuele Bassi committed
432 433 434 435 436 437 438 439 440 441 442 443 444 445
    gtk_widget_show_all (window);
  else
    gtk_widget_destroy (window);
}

/*
 * Big windows and guffaw scrolling
 */

static void
pattern_set_bg (GtkWidget   *widget,
		GdkWindow   *child,
		gint         level)
{
446
  static GdkRGBA colors[] = {
447 448 449
    { 0.27, 0.27, 1.0, 1.0 },
    { 0.53, 0.53, 1.0, 1.0},
    { 0.67, 0.67, 1.0, 1.0 }
Emmanuele Bassi's avatar
Emmanuele Bassi committed
450 451 452
  };
    
  gdk_window_set_user_data (child, widget);
453
  gdk_window_set_background_rgba (child, &colors[level]);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
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
}

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);
	      
	      child = gdk_window_new (parent, &attributes,
492
				      GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511

	      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
512
pattern_hadj_changed (GtkAdjustment *adjustment,
Emmanuele Bassi's avatar
Emmanuele Bassi committed
513 514
		      GtkWidget     *darea)
{
515
  gint *old_value = g_object_get_data (G_OBJECT (adjustment), "old-value");
516
  gint new_value = gtk_adjustment_get_value (adjustment);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
517

518
  if (gtk_widget_get_realized (darea))
Emmanuele Bassi's avatar
Emmanuele Bassi committed
519
    {
520 521
      gdk_window_scroll (gtk_widget_get_window (darea),
                         *old_value - new_value, 0);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
522 523 524 525 526
      *old_value = new_value;
    }
}

static void
527
pattern_vadj_changed (GtkAdjustment *adjustment,
Emmanuele Bassi's avatar
Emmanuele Bassi committed
528 529
		      GtkWidget *darea)
{
530
  gint *old_value = g_object_get_data (G_OBJECT (adjustment), "old-value");
531
  gint new_value = gtk_adjustment_get_value (adjustment);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
532

533
  if (gtk_widget_get_realized (darea))
Emmanuele Bassi's avatar
Emmanuele Bassi committed
534
    {
535 536
      gdk_window_scroll (gtk_widget_get_window (darea),
                         0, *old_value - new_value);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
537 538 539 540 541 542 543 544
      *old_value = new_value;
    }
}

static void
pattern_realize (GtkWidget *widget,
		 gpointer   data)
{
545 546 547 548 549
  GdkWindow *window;

  window = gtk_widget_get_window (widget);
  pattern_set_bg (widget, window, 0);
  create_pattern (widget, window, 1, PATTERN_SIZE, PATTERN_SIZE);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
550 551 552 553 554 555
}

static void 
create_big_windows (GtkWidget *widget)
{
  static GtkWidget *window = NULL;
556
  GtkWidget *content_area;
557
  GtkWidget *darea, *grid, *scrollbar;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
558
  GtkWidget *eventbox;
559 560
  GtkAdjustment *hadjustment;
  GtkAdjustment *vadjustment;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
561 562 563 564 565 566 567 568 569 570
  static gint current_x;
  static gint current_y;
 
  if (!window)
    {
      current_x = 0;
      current_y = 0;
      
      window = gtk_dialog_new_with_buttons ("Big Windows",
                                            NULL, 0,
571
                                            "_Close",
Emmanuele Bassi's avatar
Emmanuele Bassi committed
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
                                            GTK_RESPONSE_NONE,
                                            NULL);
 
      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));

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

      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);

      g_signal_connect (window, "response",
                        G_CALLBACK (gtk_widget_destroy),
                        NULL);

588 589
      content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));

590 591
      grid = gtk_grid_new ();
      gtk_box_pack_start (GTK_BOX (content_area), grid, TRUE, TRUE, 0);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
592 593 594

      darea = gtk_drawing_area_new ();

595 596
      hadjustment = gtk_adjustment_new (0, 0, PATTERN_SIZE, 10, 100, 100);
      g_signal_connect (hadjustment, "value_changed",
Emmanuele Bassi's avatar
Emmanuele Bassi committed
597
			G_CALLBACK (pattern_hadj_changed), darea);
598
      g_object_set_data (G_OBJECT (hadjustment), "old-value", &current_x);
Javier Jardón's avatar
Javier Jardón committed
599

600 601
      vadjustment = gtk_adjustment_new (0, 0, PATTERN_SIZE, 10, 100, 100);
      g_signal_connect (vadjustment, "value_changed",
Emmanuele Bassi's avatar
Emmanuele Bassi committed
602
			G_CALLBACK (pattern_vadj_changed), darea);
603
      g_object_set_data (G_OBJECT (vadjustment), "old-value", &current_y);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
604 605 606 607 608 609
      
      g_signal_connect (darea, "realize",
                        G_CALLBACK (pattern_realize),
                        NULL);

      eventbox = gtk_event_box_new ();
610 611 612
      gtk_widget_set_hexpand (eventbox, TRUE);
      gtk_widget_set_vexpand (eventbox, TRUE);
      gtk_grid_attach (GTK_GRID (grid), eventbox, 0, 0, 1, 1);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
613 614 615

      gtk_container_add (GTK_CONTAINER (eventbox), darea);

616
      scrollbar = gtk_scrollbar_new (GTK_ORIENTATION_HORIZONTAL, hadjustment);
617 618
      gtk_widget_set_hexpand (scrollbar, TRUE);
      gtk_grid_attach (GTK_GRID (grid), scrollbar, 0, 1, 1, 1);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
619

620
      scrollbar = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, vadjustment);
621 622
      gtk_widget_set_vexpand (scrollbar, TRUE);
      gtk_grid_attach (GTK_GRID (grid), scrollbar, 1, 0, 1, 1);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
623 624
    }

625
  if (!gtk_widget_get_visible (window))
Emmanuele Bassi's avatar
Emmanuele Bassi committed
626 627 628 629 630 631 632 633 634 635 636 637 638
    gtk_widget_show_all (window);
  else
    gtk_widget_hide (window);
}

/*
 * GtkButton
 */

static void
button_window (GtkWidget *widget,
	       GtkWidget *button)
{
639
  if (!gtk_widget_get_visible (button))
Emmanuele Bassi's avatar
Emmanuele Bassi committed
640 641 642 643 644 645 646 647 648 649 650
    gtk_widget_show (button);
  else
    gtk_widget_hide (button);
}

static void
create_buttons (GtkWidget *widget)
{
  static GtkWidget *window = NULL;
  GtkWidget *box1;
  GtkWidget *box2;
651
  GtkWidget *grid;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
652
  GtkWidget *separator;
653 654 655 656
  GtkWidget *button[10];
  int button_x[9] = { 0, 1, 2, 0, 2, 1, 1, 2, 0 };
  int button_y[9] = { 0, 1, 2, 2, 0, 2, 0, 1, 1 };
  guint i;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
657 658 659 660 661 662 663 664 665 666 667 668 669 670

  if (!window)
    {
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));

      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);

      gtk_window_set_title (GTK_WINDOW (window), "GtkButton");
      gtk_container_set_border_width (GTK_CONTAINER (window), 0);

671
      box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
672 673
      gtk_container_add (GTK_CONTAINER (window), box1);

674 675 676 677 678
      grid = gtk_grid_new ();
      gtk_grid_set_row_spacing (GTK_GRID (grid), 5);
      gtk_grid_set_column_spacing (GTK_GRID (grid), 5);
      gtk_container_set_border_width (GTK_CONTAINER (grid), 10);
      gtk_box_pack_start (GTK_BOX (box1), grid, TRUE, TRUE, 0);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
679

680
      G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
681 682 683 684 685 686 687 688 689
      button[0] = gtk_button_new_with_label ("button1");
      button[1] = gtk_button_new_with_mnemonic ("_button2");
      button[2] = gtk_button_new_with_mnemonic ("_button3");
      button[3] = gtk_button_new_from_stock (GTK_STOCK_OK);
      button[4] = gtk_button_new_with_label ("button5");
      button[5] = gtk_button_new_with_label ("button6");
      button[6] = gtk_button_new_with_label ("button7");
      button[7] = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
      button[8] = gtk_button_new_with_label ("button9");
690
      G_GNUC_END_IGNORE_DEPRECATIONS;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
691
      
692 693 694 695 696
      for (i = 0; i < 9; i++)
        {
          g_signal_connect (button[i], "clicked",
                            G_CALLBACK (button_window),
                            button[(i + 1) % 9]);
697 698
          gtk_widget_set_hexpand (button[i], TRUE);
          gtk_widget_set_vexpand (button[i], TRUE);
699

700 701
          gtk_grid_attach (GTK_GRID (grid), button[i],
                           button_x[i], button_y[i] + 1, 1, 1);
702
        }
Emmanuele Bassi's avatar
Emmanuele Bassi committed
703

704
      separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
705 706
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);

707
      box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
708 709 710 711 712 713 714 715
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
      gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);

      button[9] = gtk_button_new_with_label ("close");
      g_signal_connect_swapped (button[9], "clicked",
				G_CALLBACK (gtk_widget_destroy),
				window);
      gtk_box_pack_start (GTK_BOX (box2), button[9], TRUE, TRUE, 0);
716
      gtk_widget_set_can_default (button[9], TRUE);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
717 718 719
      gtk_widget_grab_default (button[9]);
    }

720
  if (!gtk_widget_get_visible (window))
Emmanuele Bassi's avatar
Emmanuele Bassi committed
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
    gtk_widget_show_all (window);
  else
    gtk_widget_destroy (window);
}

/*
 * GtkToggleButton
 */

static void
create_toggle_buttons (GtkWidget *widget)
{
  static GtkWidget *window = NULL;
  GtkWidget *box1;
  GtkWidget *box2;
  GtkWidget *button;
  GtkWidget *separator;

  if (!window)
    {
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));

      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);

      gtk_window_set_title (GTK_WINDOW (window), "GtkToggleButton");
      gtk_container_set_border_width (GTK_CONTAINER (window), 0);

752
      box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
753 754
      gtk_container_add (GTK_CONTAINER (window), box1);

755
      box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
      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);

      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);
      
772
      separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
773 774
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);

775
      box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
776 777 778 779 780 781 782 783
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
      gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);

      button = gtk_button_new_with_label ("close");
      g_signal_connect_swapped (button, "clicked",
			        G_CALLBACK (gtk_widget_destroy),
				window);
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
784
      gtk_widget_set_can_default (button, TRUE);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
785 786 787
      gtk_widget_grab_default (button);
    }

788
  if (!gtk_widget_get_visible (window))
Emmanuele Bassi's avatar
Emmanuele Bassi committed
789 790 791 792 793 794 795 796
    gtk_widget_show_all (window);
  else
    gtk_widget_destroy (window);
}

static GtkWidget *
create_widget_grid (GType widget_type)
{
797
  GtkWidget *grid;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
798 799 800
  GtkWidget *group_widget = NULL;
  gint i, j;
  
801
  grid = gtk_grid_new ();
Emmanuele Bassi's avatar
Emmanuele Bassi committed
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
  
  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)
840
	    gtk_grid_attach (GTK_GRID (grid), widget, i, j, 1, 1);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
841 842 843
	}
    }

844
  return grid;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
}

/*
 * GtkCheckButton
 */

static void
create_check_buttons (GtkWidget *widget)
{
  static GtkWidget *window = NULL;
  GtkWidget *box1;
  GtkWidget *box2;
  GtkWidget *button;
  GtkWidget *separator;
  GtkWidget *table;
  
  if (!window)
    {
      window = gtk_dialog_new_with_buttons ("Check Buttons",
                                            NULL, 0,
865
                                            "_Close",
Emmanuele Bassi's avatar
Emmanuele Bassi committed
866 867 868 869 870 871 872 873 874 875 876 877 878
                                            GTK_RESPONSE_NONE,
                                            NULL);

      gtk_window_set_screen (GTK_WINDOW (window), 
			     gtk_widget_get_screen (widget));

      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
      g_signal_connect (window, "response",
                        G_CALLBACK (gtk_widget_destroy),
                        NULL);

879
      box1 = gtk_dialog_get_content_area (GTK_DIALOG (window));
Emmanuele Bassi's avatar
Emmanuele Bassi committed
880
      
881
      box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
      gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);

      button = gtk_check_button_new_with_mnemonic ("_button1");
      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);

      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);

898
      separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
899 900 901 902 903 904 905
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);

      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);
    }

906
  if (!gtk_widget_get_visible (window))
Emmanuele Bassi's avatar
Emmanuele Bassi committed
907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
    gtk_widget_show_all (window);
  else
    gtk_widget_destroy (window);
}

/*
 * GtkRadioButton
 */

static void
create_radio_buttons (GtkWidget *widget)
{
  static GtkWidget *window = NULL;
  GtkWidget *box1;
  GtkWidget *box2;
  GtkWidget *button;
  GtkWidget *separator;
  GtkWidget *table;

  if (!window)
    {
      window = gtk_dialog_new_with_buttons ("Radio Buttons",
                                            NULL, 0,
930
                                            "_Close",
Emmanuele Bassi's avatar
Emmanuele Bassi committed
931 932 933 934 935 936 937 938 939 940 941 942 943
                                            GTK_RESPONSE_NONE,
                                            NULL);

      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));

      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
      g_signal_connect (window, "response",
                        G_CALLBACK (gtk_widget_destroy),
                        NULL);

944
      box1 = gtk_dialog_get_content_area (GTK_DIALOG (window));
Emmanuele Bassi's avatar
Emmanuele Bassi committed
945

946
      box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
      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 (
	         gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
		 "button2");
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
      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)),
		 "button3");
      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)),
		 "inconsistent");
      gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (button), TRUE);
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
      
970
      separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
971 972
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);

973
      box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
      gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);

      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);

994
      separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
995 996 997 998 999 1000 1001
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);

      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);
    }

1002
  if (!gtk_widget_get_visible (window))
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
    gtk_widget_show_all (window);
  else
    gtk_widget_destroy (window);
}

/*
 * GtkButtonBox
 */

static GtkWidget *
create_bbox (gint  horizontal,
	     char* title, 
	     gint  spacing,
	     gint  child_w,
	     gint  child_h,
	     gint  layout)
{
  GtkWidget *frame;
  GtkWidget *bbox;
  GtkWidget *button;
	
  frame = gtk_frame_new (title);

  if (horizontal)
1027
    bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1028
  else
1029
    bbox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070

  gtk_container_set_border_width (GTK_CONTAINER (bbox), 5);
  gtk_container_add (GTK_CONTAINER (frame), bbox);

  gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
  gtk_box_set_spacing (GTK_BOX (bbox), spacing);
  
  button = gtk_button_new_with_label ("OK");
  gtk_container_add (GTK_CONTAINER (bbox), button);
  
  button = gtk_button_new_with_label ("Cancel");
  gtk_container_add (GTK_CONTAINER (bbox), button);
  
  button = gtk_button_new_with_label ("Help");
  gtk_container_add (GTK_CONTAINER (bbox), button);

  return frame;
}

static void
create_button_box (GtkWidget *widget)
{
  static GtkWidget* window = NULL;
  GtkWidget *main_vbox;
  GtkWidget *vbox;
  GtkWidget *hbox;
  GtkWidget *frame_horz;
  GtkWidget *frame_vert;

  if (!window)
  {
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_screen (GTK_WINDOW (window), gtk_widget_get_screen (widget));
    gtk_window_set_title (GTK_WINDOW (window), "Button Boxes");
    
    g_signal_connect (window, "destroy",
		      G_CALLBACK (gtk_widget_destroyed),
		      &window);

    gtk_container_set_border_width (GTK_CONTAINER (window), 10);

1071
    main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1072 1073 1074 1075 1076
    gtk_container_add (GTK_CONTAINER (window), main_vbox);
    
    frame_horz = gtk_frame_new ("Horizontal Button Boxes");
    gtk_box_pack_start (GTK_BOX (main_vbox), frame_horz, TRUE, TRUE, 10);
    
1077
    vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
    gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);
    gtk_container_add (GTK_CONTAINER (frame_horz), vbox);
    
    gtk_box_pack_start (GTK_BOX (vbox), 
                        create_bbox (TRUE, "Spread", 40, 85, 20, GTK_BUTTONBOX_SPREAD),
			TRUE, TRUE, 0);
    
    gtk_box_pack_start (GTK_BOX (vbox), 
                        create_bbox (TRUE, "Edge", 40, 85, 20, GTK_BUTTONBOX_EDGE),
			TRUE, TRUE, 5);
    
    gtk_box_pack_start (GTK_BOX (vbox), 
                        create_bbox (TRUE, "Start", 40, 85, 20, GTK_BUTTONBOX_START),
			TRUE, TRUE, 5);
    
    gtk_box_pack_start (GTK_BOX (vbox), 
                        create_bbox (TRUE, "End", 40, 85, 20, GTK_BUTTONBOX_END),
			TRUE, TRUE, 5);
    
    gtk_box_pack_start (GTK_BOX (vbox),
                        create_bbox (TRUE, "Center", 40, 85, 20, GTK_BUTTONBOX_CENTER),
			TRUE, TRUE, 5);
    
    frame_vert = gtk_frame_new ("Vertical Button Boxes");
    gtk_box_pack_start (GTK_BOX (main_vbox), frame_vert, TRUE, TRUE, 10);
    
1104
    hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
    gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
    gtk_container_add (GTK_CONTAINER (frame_vert), hbox);

    gtk_box_pack_start (GTK_BOX (hbox), 
                        create_bbox (FALSE, "Spread", 30, 85, 20, GTK_BUTTONBOX_SPREAD),
			TRUE, TRUE, 0);
    
    gtk_box_pack_start (GTK_BOX (hbox), 
                        create_bbox (FALSE, "Edge", 30, 85, 20, GTK_BUTTONBOX_EDGE),
			TRUE, TRUE, 5);
    
    gtk_box_pack_start (GTK_BOX (hbox), 
                        create_bbox (FALSE, "Start", 30, 85, 20, GTK_BUTTONBOX_START),
			TRUE, TRUE, 5);
    
    gtk_box_pack_start (GTK_BOX (hbox), 
                        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),
			TRUE, TRUE, 5);
  }

1129
  if (!gtk_widget_get_visible (window))
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139
    gtk_widget_show_all (window);
  else
    gtk_widget_destroy (window);
}

/*
 * GtkToolBar
 */

static GtkWidget*
1140
new_pixbuf (char      *filename,
1141
	    GdkWindow *window)
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1142
{
1143 1144
  GtkWidget *widget;
  GdkPixbuf *pixbuf;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1145

1146 1147
  if (strcmp (filename, "test.xpm") == 0)
    pixbuf = NULL;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1148
  else
1149 1150 1151 1152
    pixbuf = gdk_pixbuf_new_from_file (filename, NULL);

  if (pixbuf == NULL)
    pixbuf = gdk_pixbuf_new_from_xpm_data ((const char **) openfile);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1153
  
1154 1155 1156
  widget = gtk_image_new_from_pixbuf (pixbuf);

  g_object_unref (pixbuf);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1157

1158
  return widget;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
}


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);
}

static void
set_toolbar_horizontal (GtkWidget *widget,
			gpointer   data)
{
1180
  gtk_orientable_set_orientation (GTK_ORIENTABLE (data), GTK_ORIENTATION_HORIZONTAL);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1181 1182 1183 1184 1185 1186
}

static void
set_toolbar_vertical (GtkWidget *widget,
		      gpointer   data)
{
1187
  gtk_orientable_set_orientation (GTK_ORIENTABLE (data), GTK_ORIENTATION_VERTICAL);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217
}

static void
set_toolbar_icons (GtkWidget *widget,
		   gpointer   data)
{
  gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_ICONS);
}

static void
set_toolbar_text (GtkWidget *widget,
	          gpointer   data)
{
  gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_TEXT);
}

static void
set_toolbar_both (GtkWidget *widget,
		  gpointer   data)
{
  gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_BOTH);
}

static void
set_toolbar_both_horiz (GtkWidget *widget,
			gpointer   data)
{
  gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_BOTH_HORIZ);
}

1218
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
static GtkActionEntry create_toolbar_items[] = {
    { NULL, GTK_STOCK_NEW, NULL, NULL, "Stock icon: New",
      G_CALLBACK (set_toolbar_small_stock) },
    { NULL, GTK_STOCK_OPEN, NULL, NULL, "Stock icon: Open",
      G_CALLBACK (set_toolbar_large_stock) },
    { NULL, NULL, "Horizontal", NULL, "Horizontal toolbar layout",
      G_CALLBACK (set_toolbar_horizontal) },
    { NULL, NULL, "Vertical", NULL, "Vertical toolbar layout",
      G_CALLBACK (set_toolbar_vertical) },
    { NULL },
    { NULL, NULL, "Icons", NULL, "Only show toolbar icons",
      G_CALLBACK (set_toolbar_icons) },
    { NULL, NULL, "Text", NULL, "Only show toolbar text",
      G_CALLBACK (set_toolbar_text) },
    { NULL, NULL, "Both", NULL, "Show toolbar icons and text",
      G_CALLBACK (set_toolbar_both) },
    { NULL, NULL, "Both (horizontal)", NULL, "Show toolbar icons and text in a horizontal fashion",
      G_CALLBACK (set_toolbar_both_horiz) },
    { NULL },
    { "entry", NULL, NULL, "This is an unusable GtkEntry ;)",
      NULL },
    { NULL },
    { NULL },
    { NULL, NULL, "Frobate", NULL, "Frobate tooltip",
      NULL },
    { NULL, NULL, "Baz", NULL, "Baz tooltip",
      NULL },
    { NULL },
    { NULL, NULL, "Blah", NULL, "Blash tooltip",
      NULL },
    { NULL, NULL, "Bar", NULL, "Bar tooltip",
      NULL },
};
1252
G_GNUC_END_IGNORE_DEPRECATIONS;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1253 1254 1255 1256 1257 1258 1259 1260 1261

static void
create_toolbar (GtkWidget *widget)
{
  static GtkWidget *window = NULL;
  GtkWidget *toolbar;

  if (!window)
    {
1262 1263
      guint i;

Emmanuele Bassi's avatar
Emmanuele Bassi committed
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));
      
      gtk_window_set_title (GTK_WINDOW (window), "Toolbar test");

      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);

      gtk_container_set_border_width (GTK_CONTAINER (window), 0);
      gtk_widget_realize (window);

      toolbar = gtk_toolbar_new ();
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292
      for (i = 0; i < G_N_ELEMENTS (create_toolbar_items); i++)
        {
          GtkToolItem *toolitem;

          if (create_toolbar_items[i].tooltip == NULL)
            toolitem = gtk_separator_tool_item_new ();
          else if (g_strcmp0 (create_toolbar_items[i].name, "entry") == 0)
            {
              GtkWidget *entry;

              toolitem = gtk_tool_item_new ();
              entry = gtk_entry_new ();
              gtk_container_add (GTK_CONTAINER (toolitem), entry);
            }
          else if (create_toolbar_items[i].stock_id)
1293 1294 1295 1296 1297
            {
              G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
              toolitem = gtk_tool_button_new_from_stock (create_toolbar_items[i].stock_id);
              G_GNUC_END_IGNORE_DEPRECATIONS;
            }
1298 1299 1300 1301
          else
            {
              GtkWidget *icon;

1302
              icon = new_pixbuf ("test.xpm", gtk_widget_get_window (window));
1303 1304 1305 1306 1307 1308 1309 1310
              toolitem = gtk_tool_button_new (icon, create_toolbar_items[i].label);
            }
          if (create_toolbar_items[i].callback)
            g_signal_connect (toolitem, "clicked",
                              create_toolbar_items[i].callback, toolbar);
          gtk_tool_item_set_tooltip_text (toolitem, create_toolbar_items[i].tooltip);
          gtk_toolbar_insert (GTK_TOOLBAR (toolbar), toolitem, -1);
        }
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1311 1312 1313 1314 1315 1316

      gtk_container_add (GTK_CONTAINER (window), toolbar);

      gtk_widget_set_size_request (toolbar, 200, -1);
    }

1317
  if (!gtk_widget_get_visible (window))
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
    gtk_widget_show_all (window);
  else
    gtk_widget_destroy (window);
}

/*
 * GtkStatusBar
 */

static guint statusbar_counter = 1;

static void
statusbar_push (GtkWidget *button,
		GtkStatusbar *statusbar)
{
  gchar text[1024];

  sprintf (text, "something %d", statusbar_counter++);

  gtk_statusbar_push (statusbar, 1, text);
}

static void
statusbar_push_long (GtkWidget *button,
                     GtkStatusbar *statusbar)
{
  gchar text[1024];

  sprintf (text, "Just because a system has menu choices written with English words, phrases or sentences, that is no guarantee, that it is comprehensible. Individual words may not be familiar to some users (for example, \"repaginate\"), and two menu items may appear to satisfy the users's needs, whereas only one does (for example, \"put away\" or \"eject\").");

  gtk_statusbar_push (statusbar, 1, text);
}

static void
statusbar_pop (GtkWidget *button,
	       GtkStatusbar *statusbar)
{
  gtk_statusbar_pop (statusbar, 1);
}

static void
statusbar_steal (GtkWidget *button,
	         GtkStatusbar *statusbar)
{
  gtk_statusbar_remove (statusbar, 1, 4);
}

static void
statusbar_popped (GtkStatusbar  *statusbar,
		  guint          context_id,
		  const gchar	*text)
{
1370
  if (!text)
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427
    statusbar_counter = 1;
}

static void
statusbar_contexts (GtkStatusbar *statusbar)
{
  gchar *string;

  string = "any context";
  g_print ("GtkStatusBar: context=\"%s\", context_id=%d\n",
	   string,
	   gtk_statusbar_get_context_id (statusbar, string));
  
  string = "idle messages";
  g_print ("GtkStatusBar: context=\"%s\", context_id=%d\n",
	   string,
	   gtk_statusbar_get_context_id (statusbar, string));
  
  string = "some text";
  g_print ("GtkStatusBar: context=\"%s\", context_id=%d\n",
	   string,
	   gtk_statusbar_get_context_id (statusbar, string));

  string = "hit the mouse";
  g_print ("GtkStatusBar: context=\"%s\", context_id=%d\n",
	   string,
	   gtk_statusbar_get_context_id (statusbar, string));

  string = "hit the mouse2";
  g_print ("GtkStatusBar: context=\"%s\", context_id=%d\n",
	   string,
	   gtk_statusbar_get_context_id (statusbar, string));
}

static void
create_statusbar (GtkWidget *widget)
{
  static GtkWidget *window = NULL;
  GtkWidget *box1;
  GtkWidget *box2;
  GtkWidget *button;
  GtkWidget *separator;
  GtkWidget *statusbar;

  if (!window)
    {
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));

      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);

      gtk_window_set_title (GTK_WINDOW (window), "statusbar");
      gtk_container_set_border_width (GTK_CONTAINER (window), 0);

1428
      box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1429 1430
      gtk_container_add (GTK_CONTAINER (window), box1);

1431
      box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
      gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);

      statusbar = gtk_statusbar_new ();
      gtk_box_pack_end (GTK_BOX (box1), statusbar, TRUE, TRUE, 0);
      g_signal_connect (statusbar,
			"text_popped",
			G_CALLBACK (statusbar_popped),
			NULL);

1442
      button = g_object_new (gtk_button_get_type (),
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1443 1444 1445 1446 1447 1448 1449 1450
			       "label", "push something",
			       "visible", TRUE,
			       "parent", box2,
			       NULL);
      g_object_connect (button,
			"signal::clicked", statusbar_push, statusbar,
			NULL);

1451
      button = g_object_connect (g_object_new (gtk_button_get_type (),
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1452 1453 1454 1455 1456 1457 1458
						 "label", "pop",
						 "visible", TRUE,
						 "parent", box2,
						 NULL),
				 "signal_after::clicked", statusbar_pop, statusbar,
				 NULL);

1459
      button = g_object_connect (g_object_new (gtk_button_get_type (),
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1460 1461 1462 1463 1464 1465 1466
						 "label", "steal #4",
						 "visible", TRUE,
						 "parent", box2,
						 NULL),
				 "signal_after::clicked", statusbar_steal, statusbar,
				 NULL);

1467
      button = g_object_connect (g_object_new (gtk_button_get_type (),
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1468 1469 1470 1471 1472 1473 1474
						 "label", "test contexts",
						 "visible", TRUE,
						 "parent", box2,
						 NULL),
				 "swapped_signal_after::clicked", statusbar_contexts, statusbar,
				 NULL);

1475
      button = g_object_connect (g_object_new (gtk_button_get_type (),
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1476 1477 1478 1479 1480 1481 1482
						 "label", "push something long",
						 "visible", TRUE,
						 "parent", box2,
						 NULL),
				 "signal_after::clicked", statusbar_push_long, statusbar,
				 NULL);
      
1483
      separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1484 1485
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);

1486
      box2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1487 1488 1489 1490 1491 1492 1493 1494
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
      gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);

      button = gtk_button_new_with_label ("close");
      g_signal_connect_swapped (button, "clicked",
			        G_CALLBACK (gtk_widget_destroy),
				window);
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
1495
      gtk_widget_set_can_default (button, TRUE);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1496 1497 1498
      gtk_widget_grab_default (button);
    }

1499
  if (!gtk_widget_get_visible (window))
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1500 1501 1502 1503 1504
    gtk_widget_show_all (window);
  else
    gtk_widget_destroy (window);
}

1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616
/* Alpha demo */

static void
alpha_changed (GtkRange *range, GtkWidget *widget)
{
  gdouble alpha;

  alpha = gtk_range_get_value (range);

  gtk_widget_set_opacity (widget, alpha / 100.0);
}


void
create_alpha_widgets (GtkWidget *widget)
{
  static GtkWidget *window = NULL;

  if (!window)
    {
      GtkWidget *vbox2, *vbox, *main_hbox;
      GtkWidget *button, *event_box, *label, *scale;
      GtkWidget *alpha1, *alpha2, *alpha3;

      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      gtk_window_set_screen (GTK_WINDOW (window),
                             gtk_widget_get_screen (widget));
      gtk_window_set_default_size (GTK_WINDOW (window),
                                   450, 450);

      g_signal_connect (window, "destroy",
                        G_CALLBACK (gtk_widget_destroyed), &window);

      gtk_window_set_title (GTK_WINDOW (window), "Alpha");
      gtk_container_set_border_width (GTK_CONTAINER (window), 0);

      main_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
      gtk_container_add (GTK_CONTAINER (window), main_hbox);

      vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);

      gtk_box_pack_start (GTK_BOX (main_hbox), vbox, FALSE, FALSE, 0);

      /* Plain button (no gdkwindows */

      label = gtk_label_new ("non-window widget");
      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

      alpha1 = button = gtk_button_new_with_label ("A Button");
      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);

      /* windowed container with both windowed and normal button */
      label = gtk_label_new ("\nwindow widget");
      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

      alpha2 = event_box = gtk_event_box_new ();
      gtk_box_pack_start (GTK_BOX (vbox), event_box, FALSE, FALSE, 0);

      vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
      gtk_container_add (GTK_CONTAINER (event_box), vbox2);

      button = gtk_button_new_with_label ("A Button");
      gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0);

      event_box = gtk_event_box_new ();
      button = gtk_button_new_with_label ("A Button (in window)");
      gtk_container_add (GTK_CONTAINER (event_box), button);
      gtk_box_pack_start (GTK_BOX (vbox2), event_box, FALSE, FALSE, 0);

      /* non-windowed container with both windowed and normal button */
      label = gtk_label_new ("\nnon-window widget with widget child");
      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

      alpha3 = vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
      gtk_box_pack_start (GTK_BOX (vbox), vbox2, FALSE, FALSE, 0);

      button = gtk_button_new_with_label ("A Button");
      gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0);

      event_box = gtk_event_box_new ();
      button = gtk_button_new_with_label ("A Button (in window)");
      gtk_container_add (GTK_CONTAINER (event_box), button);
      gtk_box_pack_start (GTK_BOX (vbox2), event_box, FALSE, FALSE, 0);

      scale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
                                         0, 100, 1);
      gtk_box_pack_start (GTK_BOX (main_hbox), scale, FALSE, FALSE, 0);
      g_signal_connect (scale, "value_changed", G_CALLBACK (alpha_changed), alpha1);
      gtk_range_set_value (GTK_RANGE (scale), 50);

      scale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
                                         0, 100, 1);
      gtk_box_pack_start (GTK_BOX (main_hbox), scale, FALSE, FALSE, 0);
      g_signal_connect (scale, "value_changed", G_CALLBACK (alpha_changed), alpha2);
      gtk_range_set_value (GTK_RANGE (scale), 50);

      scale = gtk_scale_new_with_range (GTK_ORIENTATION_VERTICAL,
                                         0, 100, 1);
      gtk_box_pack_start (GTK_BOX (main_hbox), scale, FALSE, FALSE, 0);
      g_signal_connect (scale, "value_changed", G_CALLBACK (alpha_changed), alpha3);
      gtk_range_set_value (GTK_RANGE (scale), 50);

      gtk_widget_show_all (main_hbox);
    }

  if (!gtk_widget_get_visible (window))
    gtk_widget_show (window);
  else
    gtk_widget_destroy (window);
}


Emmanuele Bassi's avatar
Emmanuele Bassi committed
1617 1618 1619 1620 1621 1622 1623
/* 
 * Label Demo
 */
static void
sensitivity_toggled (GtkWidget *toggle,
                     GtkWidget *widget)
{
1624 1625
  gtk_widget_set_sensitive (widget,
                            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle)));
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1626 1627 1628 1629 1630 1631 1632 1633 1634 1635
}

static GtkWidget*
create_sensitivity_control (GtkWidget *widget)
{
  GtkWidget *button;

  button = gtk_toggle_button_new_with_label ("Sensitive");  

  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
1636
                                gtk_widget_is_sensitive (widget));
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677
  
  g_signal_connect (button,
                    "toggled",
                    G_CALLBACK (sensitivity_toggled),
                    widget);
  
  gtk_widget_show_all (button);

  return button;
}

static void
set_selectable_recursive (GtkWidget *widget,
                          gboolean   setting)
{
  if (GTK_IS_CONTAINER (widget))
    {
      GList *children;
      GList *tmp;
      
      children = gtk_container_get_children (GTK_CONTAINER (widget));
      tmp = children;
      while (tmp)
        {
          set_selectable_recursive (tmp->data, setting);

          tmp = tmp->next;
        }
      g_list_free (children);
    }
  else if (GTK_IS_LABEL (widget))
    {
      gtk_label_set_selectable (GTK_LABEL (widget), setting);
    }
}

static void
selectable_toggled (GtkWidget *toggle,
                    GtkWidget *widget)
{
  set_selectable_recursive (widget,
1678
                            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle)));
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700
}

static GtkWidget*
create_selectable_control (GtkWidget *widget)
{
  GtkWidget *button;

  button = gtk_toggle_button_new_with_label ("Selectable");  

  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
                                FALSE);
  
  g_signal_connect (button,
                    "toggled",
                    G_CALLBACK (selectable_toggled),
                    widget);
  
  gtk_widget_show_all (button);

  return button;
}

1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715
static void
dialog_response (GtkWidget *dialog, gint response_id, GtkLabel *label)
{
  const gchar *text;

  gtk_widget_destroy (dialog);

  text = "Some <a href=\"http://en.wikipedia.org/wiki/Text\" title=\"plain text\">text</a> may be marked up\n"
         "as hyperlinks, which can be clicked\n"
         "or activated via <a href=\"keynav\">keynav</a>.\n"
         "The links remain the same.";
  gtk_label_set_markup (label, text);
}

static gboolean
1716
activate_link (GtkWidget *label, const gchar *uri, gpointer data)
1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739
{
  if (g_strcmp0 (uri, "keynav") == 0)
    {
      GtkWidget *dialog;

      dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (gtk_widget_get_toplevel (label)),
                                       GTK_DIALOG_DESTROY_WITH_PARENT,
                                       GTK_MESSAGE_INFO,
                                       GTK_BUTTONS_OK,
                                       "The term <i>keynav</i> is a shorthand for "
                                       "keyboard navigation and refers to the process of using a program "
                                       "(exclusively) via keyboard input.");

      gtk_window_present (GTK_WINDOW (dialog));

      g_signal_connect (dialog, "response", G_CALLBACK (dialog_response), label);

      return TRUE;
    }

  return FALSE;
}

Emmanuele Bassi's avatar
Emmanuele Bassi committed
1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761
void create_labels (GtkWidget *widget)
{
  static GtkWidget *window = NULL;
  GtkWidget *hbox;
  GtkWidget *vbox;
  GtkWidget *frame;
  GtkWidget *label;
  GtkWidget *button;

  if (!window)
    {
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));

      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);

      gtk_window_set_title (GTK_WINDOW (window), "Label");

1762
      vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1763
      
1764
      hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776
      gtk_container_add (GTK_CONTAINER (window), vbox);

      gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);

      button = create_sensitivity_control (hbox);

      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);

      button = create_selectable_control (hbox);

      gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
      
1777
      vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826
      
      gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
      gtk_container_set_border_width (GTK_CONTAINER (window), 5);

      frame = gtk_frame_new ("Normal Label");
      label = gtk_label_new ("This is a Normal label");
      gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_START);
      gtk_container_add (GTK_CONTAINER (frame), label);
      gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

      frame = gtk_frame_new ("Multi-line Label");
      label = gtk_label_new ("This is a Multi-line label.\nSecond line\nThird line");
      gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
      gtk_container_add (GTK_CONTAINER (frame), label);
      gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

      frame = gtk_frame_new ("Left Justified Label");
      label = gtk_label_new ("This is a Left-Justified\nMulti-line label.\nThird      line");
      gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_MIDDLE);
      gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
      gtk_container_add (GTK_CONTAINER (frame), label);
      gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

      frame = gtk_frame_new ("Right Justified Label");
      gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_START);
      label = gtk_label_new ("This is a Right-Justified\nMulti-line label.\nFourth line, (j/k)");
      gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_RIGHT);
      gtk_container_add (GTK_CONTAINER (frame), label);
      gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

      frame = gtk_frame_new ("Internationalized Label");
      label = gtk_label_new (NULL);
      gtk_label_set_markup (GTK_LABEL (label),
			    "French (Fran\303\247ais) Bonjour, Salut\n"
			    "Korean (\355\225\234\352\270\200)   \354\225\210\353\205\225\355\225\230\354\204\270\354\232\224, \354\225\210\353\205\225\355\225\230\354\213\255\353\213\210\352\271\214\n"
			    "Russian (\320\240\321\203\321\201\321\201\320\272\320\270\320\271) \320\227\320\264\321\200\320\260\320\262\321\201\321\202\320\262\321\203\320\271\321\202\320\265!\n"
			    "Chinese (Simplified) <span lang=\"zh-cn\">\345\205\203\346\260\224	\345\274\200\345\217\221</span>\n"
			    "Chinese (Traditional) <span lang=\"zh-tw\">\345\205\203\346\260\243	\351\226\213\347\231\274</span>\n"
			    "Japanese <span lang=\"ja\">\345\205\203\346\260\227	\351\226\213\347\231\272</span>");
      gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
      gtk_container_add (GTK_CONTAINER (frame), label);
      gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

      frame = gtk_frame_new ("Bidirection Label");
      label = gtk_label_new ("\342\200\217Arabic	\330\247\331\204\330\263\331\204\330\247\331\205 \330\271\331\204\331\212\331\203\331\205\n"
			     "\342\200\217Hebrew	\327\251\327\234\327\225\327\235");
      gtk_container_add (GTK_CONTAINER (frame), label);
      gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

1827 1828 1829 1830 1831 1832 1833 1834 1835
      frame = gtk_frame_new ("Links in a label");
      label = gtk_label_new ("Some <a href=\"http://en.wikipedia.org/wiki/Text\" title=\"plain text\">text</a> may be marked up\n"
                             "as hyperlinks, which can be clicked\n"
                             "or activated via <a href=\"keynav\">keynav</a>");
      gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
      gtk_container_add (GTK_CONTAINER (frame), label);
      gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
      g_signal_connect (label, "activate-link", G_CALLBACK (activate_link), NULL);

1836
      vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893
      gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
      frame = gtk_frame_new ("Line wrapped label");
      label = gtk_label_new ("This is an example of a line-wrapped label.  It should not be taking "\
			     "up the entire             "/* big space to test spacing */\
			     "width allocated to it, but automatically wraps the words to fit.  "\
			     "The time has come, for all good men, to come to the aid of their party.  "\
			     "The sixth sheik's six sheep's sick.\n"\
			     "     It supports multiple paragraphs correctly, and  correctly   adds "\
			     "many          extra  spaces. ");

      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
      gtk_container_add (GTK_CONTAINER (frame), label);
      gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

      frame = gtk_frame_new ("Filled, wrapped label");
      label = gtk_label_new ("This is an example of a line-wrapped, filled label.  It should be taking "\
			     "up the entire              width allocated to it.  Here is a seneance to prove "\
			     "my point.  Here is another sentence. "\
			     "Here comes the sun, do de do de do.\n"\
			     "    This is a new paragraph.\n"\
			     "    This is another newer, longer, better paragraph.  It is coming to an end, "\
			     "unfortunately.");
      gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_FILL);
      gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
      gtk_container_add (GTK_CONTAINER (frame), label);
      gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

      frame = gtk_frame_new ("Underlined label");
      label = gtk_label_new ("This label is underlined!\n"
			     "This one is underlined (\343\201\223\343\202\223\343\201\253\343\201\241\343\201\257) in quite a funky fashion");
      gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
      gtk_label_set_pattern (GTK_LABEL (label), "_________________________ _ _________ _ _____ _ __ __  ___ ____ _____");
      gtk_container_add (GTK_CONTAINER (frame), label);
      gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);

      frame = gtk_frame_new ("Markup label");
      label = gtk_label_new (NULL);

      /* There's also a gtk_label_set_markup() without accel if you
       * don't have an accelerator key
       */
      gtk_label_set_markup_with_mnemonic (GTK_LABEL (label),
					  "This <span foreground=\"blue\" background=\"orange\">label</span> has "
					  "<b>markup</b> _such as "
					  "<big><i>Big Italics</i></big>\n"
					  "<tt>Monospace font</tt>\n"
					  "<u>Underline!</u>\n"
					  "foo\n"
					  "<span foreground=\"green\" background=\"red\">Ugly colors</span>\n"
					  "and nothing on this line,\n"
					  "or this.\n"
					  "or this either\n"
					  "or even on this one\n"
					  "la <big>la <big>la <big>la <big>la</big></big></big></big>\n"
					  "but this _word is <span foreground=\"purple\"><big>purple</big></span>\n"
					  "<span underline=\"double\">We like <sup>superscript</sup> and <sub>subscript</sub> too</span>");

1894
      g_assert (gtk_label_get_mnemonic_keyval (GTK_LABEL (label)) == GDK_KEY_s);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1895 1896 1897 1898 1899
      
      gtk_container_add (GTK_CONTAINER (frame), label);
      gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
    }
  
1900
  if (!gtk_widget_get_visible (window))
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916
    gtk_widget_show_all (window);
  else
    gtk_widget_destroy (window);
}

static void
on_angle_scale_changed (GtkRange *range,
			GtkLabel *label)
{
  gtk_label_set_angle (GTK_LABEL (label), gtk_range_get_value (range));
}

static void
create_rotated_label (GtkWidget *widget)
{
  static GtkWidget *window = NULL;
1917
  GtkWidget *content_area;
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1918 1919 1920 1921 1922 1923 1924 1925 1926 1927
  GtkWidget *vbox;
  GtkWidget *hscale;
  GtkWidget *label;  
  GtkWidget *scale_label;  
  GtkWidget *scale_hbox;  

  if (!window)
    {
      window = gtk_dialog_new_with_buttons ("Rotated Label",
					    GTK_WINDOW (gtk_widget_get_toplevel (widget)), 0,
1928
					    "_Close", GTK_RESPONSE_CLOSE,
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1929 1930 1931 1932 1933 1934 1935 1936
					    NULL);

      gtk_window_set_resizable (GTK_WINDOW (window), TRUE);

      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));

      g_signal_connect (window, "response",
1937
			G_CALLBACK (gtk_widget_destroy), NULL);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1938 1939 1940
      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed), &window);

1941 1942
      content_area = gtk_dialog_get_content_area (GTK_DIALOG (window));

1943
      vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
1944
      gtk_box_pack_start (GTK_BOX (content_area), vbox, TRUE, TRUE, 0);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1945 1946 1947 1948 1949 1950
      gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);

      label = gtk_label_new (NULL);
      gtk_label_set_markup (GTK_LABEL (label), "Hello World\n<i>Rotate</i> <span underline='single' foreground='blue'>me</span>");
      gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);

1951
      scale_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1952 1953 1954 1955 1956 1957
      gtk_box_pack_start (GTK_BOX (vbox), scale_hbox, FALSE, FALSE, 0);
      
      scale_label = gtk_label_new (NULL);
      gtk_label_set_markup (GTK_LABEL (scale_label), "<i>Angle: </i>");
      gtk_box_pack_start (GTK_BOX (scale_hbox), scale_label, FALSE, FALSE, 0);

1958 1959
      hscale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
                                         0, 360, 5);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1960 1961 1962 1963
      g_signal_connect (hscale, "value-changed",
			G_CALLBACK (on_angle_scale_changed), label);
      
      gtk_range_set_value (GTK_RANGE (hscale), 45);
1964
      gtk_widget_set_size_request (hscale, 200, -1);
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1965 1966 1967
      gtk_box_pack_start (GTK_BOX (scale_hbox), hscale, TRUE, TRUE, 0);
    }
  
1968
  if (!gtk_widget_get_visible (window))
Emmanuele Bassi's avatar
Emmanuele Bassi committed
1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982
    gtk_widget_show_all (window);
  else
    gtk_widget_destroy (window);
}

#define DEFAULT_TEXT_RADIUS 200

static void
on_rotated_text_unrealize (GtkWidget *widget)
{
  g_object_set_data (G_OBJECT (widget),