testgtk.c 361 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
#include "config.h"

29
#undef	G_LOG_DOMAIN
30

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

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

Tor Lillqvist's avatar
Tor Lillqvist committed
46
47
48
49
#ifdef G_OS_WIN32
#define sleep(n) _sleep(n)
#endif

50
51
#include "prop-editor.h"

Owen Taylor's avatar
Owen Taylor committed
52
#include "circles.xbm"
53
#include "test.xpm"
Owen Taylor's avatar
Owen Taylor committed
54

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

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

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

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

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

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

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

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

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

/*
 * 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
170
      g_object_unref (tmp_gc);
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
    }

  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
187
  g_object_set_data (G_OBJECT (child), "pattern-color", (gpointer) &colors[level]);
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
  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 
284
create_big_windows (GtkWidget *widget)
285
286
287
288
289
290
291
292
{
  static GtkWidget *window = NULL;
  GtkWidget *darea, *table, *scrollbar;
  GtkWidget *eventbox;
  GtkAdjustment *hadj;
  GtkAdjustment *vadj;
  static gint current_x;
  static gint current_y;
293
 
294
295
296
297
298
299
300
301
302
303
  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);
304
305
306
 
      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));
307
308
309

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

Manish Singh's avatar
Manish Singh committed
310
311
312
      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
313

Manish Singh's avatar
Manish Singh committed
314
315
316
      g_signal_connect (window, "response",
                        G_CALLBACK (gtk_widget_destroy),
                        NULL);
317
318
319
320
321
322
323
324

      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
325
326
      g_signal_connect (hadj, "value_changed",
			G_CALLBACK (pattern_hadj_changed), darea);
327
328
329
      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
330
331
      g_signal_connect (vadj, "value_changed",
			G_CALLBACK (pattern_vadj_changed), darea);
332
333
      g_object_set_data (G_OBJECT (vadj), "old-value", &current_y);
      
Manish Singh's avatar
Manish Singh committed
334
335
336
337
338
339
      g_signal_connect (darea, "realize",
                        G_CALLBACK (pattern_realize),
                        NULL);
      g_signal_connect (darea, "expose_event",
                        G_CALLBACK (pattern_expose),
                        NULL);
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368

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

369
370
371
372
/*
 * GtkButton
 */

373
static void
Elliot Lee's avatar
Elliot Lee committed
374
375
376
377
378
379
380
381
382
button_window (GtkWidget *widget,
	       GtkWidget *button)
{
  if (!GTK_WIDGET_VISIBLE (button))
    gtk_widget_show (button);
  else
    gtk_widget_hide (button);
}

383
static void
384
create_buttons (GtkWidget *widget)
Elliot Lee's avatar
Elliot Lee committed
385
386
387
388
389
390
391
392
393
394
395
{
  static GtkWidget *window = NULL;
  GtkWidget *box1;
  GtkWidget *box2;
  GtkWidget *table;
  GtkWidget *button[10];
  GtkWidget *separator;

  if (!window)
    {
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
396
397
      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));
Elliot Lee's avatar
Elliot Lee committed
398

Manish Singh's avatar
Manish Singh committed
399
400
401
      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
Elliot Lee's avatar
Elliot Lee committed
402

403
      gtk_window_set_title (GTK_WINDOW (window), "GtkButton");
404
      gtk_container_set_border_width (GTK_CONTAINER (window), 0);
Elliot Lee's avatar
Elliot Lee committed
405
406
407
408
409
410
411

      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);
412
      gtk_container_set_border_width (GTK_CONTAINER (table), 10);
Elliot Lee's avatar
Elliot Lee committed
413
414
415
      gtk_box_pack_start (GTK_BOX (box1), table, TRUE, TRUE, 0);

      button[0] = gtk_button_new_with_label ("button1");
416
      button[1] = gtk_button_new_with_mnemonic ("_button2");
417
      button[2] = gtk_button_new_with_mnemonic ("_button3");
418
      button[3] = gtk_button_new_from_stock (GTK_STOCK_OK);
Elliot Lee's avatar
Elliot Lee committed
419
420
421
      button[4] = gtk_button_new_with_label ("button5");
      button[5] = gtk_button_new_with_label ("button6");
      button[6] = gtk_button_new_with_label ("button7");
422
      button[7] = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
Elliot Lee's avatar
Elliot Lee committed
423
      button[8] = gtk_button_new_with_label ("button9");
424
      
Manish Singh's avatar
Manish Singh committed
425
426
427
      g_signal_connect (button[0], "clicked",
			G_CALLBACK (button_window),
			button[1]);
Elliot Lee's avatar
Elliot Lee committed
428
429
430
431

      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
432
433
434
      g_signal_connect (button[1], "clicked",
			G_CALLBACK (button_window),
			button[2]);
Elliot Lee's avatar
Elliot Lee committed
435
436
437
438

      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
439
440
441
      g_signal_connect (button[2], "clicked",
			G_CALLBACK (button_window),
			button[3]);
Elliot Lee's avatar
Elliot Lee committed
442
443
444
      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
445
446
447
      g_signal_connect (button[3], "clicked",
			G_CALLBACK (button_window),
			button[4]);
Elliot Lee's avatar
Elliot Lee committed
448
449
450
      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
451
452
453
      g_signal_connect (button[4], "clicked",
			G_CALLBACK (button_window),
			button[5]);
Elliot Lee's avatar
Elliot Lee committed
454
455
456
      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
457
458
459
      g_signal_connect (button[5], "clicked",
			G_CALLBACK (button_window),
			button[6]);
Elliot Lee's avatar
Elliot Lee committed
460
461
462
      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
463
464
465
      g_signal_connect (button[6], "clicked",
			G_CALLBACK (button_window),
			button[7]);
Elliot Lee's avatar
Elliot Lee committed
466
467
468
      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
469
470
471
      g_signal_connect (button[7], "clicked",
			G_CALLBACK (button_window),
			button[8]);
Elliot Lee's avatar
Elliot Lee committed
472
473
474
      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
475
476
477
      g_signal_connect (button[8], "clicked",
			G_CALLBACK (button_window),
			button[0]);
Elliot Lee's avatar
Elliot Lee committed
478
479
480
481
482
483
484
      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);
485
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
Elliot Lee's avatar
Elliot Lee committed
486
487
488
      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
489
490
491
      g_signal_connect_swapped (button[9], "clicked",
				G_CALLBACK (gtk_widget_destroy),
				window);
Elliot Lee's avatar
Elliot Lee committed
492
493
494
495
496
497
      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))
498
    gtk_widget_show_all (window);
Elliot Lee's avatar
Elliot Lee committed
499
  else
500
    gtk_widget_destroy (window);
Elliot Lee's avatar
Elliot Lee committed
501
502
}

503
504
505
506
/*
 * GtkToggleButton
 */

507
static void
508
create_toggle_buttons (GtkWidget *widget)
Elliot Lee's avatar
Elliot Lee committed
509
510
511
512
513
514
515
516
517
518
{
  static GtkWidget *window = NULL;
  GtkWidget *box1;
  GtkWidget *box2;
  GtkWidget *button;
  GtkWidget *separator;

  if (!window)
    {
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
519
520
      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));
Elliot Lee's avatar
Elliot Lee committed
521

Manish Singh's avatar
Manish Singh committed
522
523
524
      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
Elliot Lee's avatar
Elliot Lee committed
525

526
      gtk_window_set_title (GTK_WINDOW (window), "GtkToggleButton");
527
      gtk_container_set_border_width (GTK_CONTAINER (window), 0);
Elliot Lee's avatar
Elliot Lee committed
528
529
530
531
532

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

      box2 = gtk_vbox_new (FALSE, 10);
533
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
Elliot Lee's avatar
Elliot Lee committed
534
535
536
537
538
539
540
541
542
543
544
      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);

545
546
547
548
      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
549
550
551
552
      separator = gtk_hseparator_new ();
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);

      box2 = gtk_vbox_new (FALSE, 10);
553
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
Elliot Lee's avatar
Elliot Lee committed
554
555
556
      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
557
558
559
      g_signal_connect_swapped (button, "clicked",
			        G_CALLBACK (gtk_widget_destroy),
				window);
Elliot Lee's avatar
Elliot Lee committed
560
561
562
563
564
565
      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))
566
    gtk_widget_show_all (window);
Elliot Lee's avatar
Elliot Lee committed
567
568
569
570
  else
    gtk_widget_destroy (window);
}

571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
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;
}

627
628
629
630
/*
 * GtkCheckButton
 */

631
static void
632
create_check_buttons (GtkWidget *widget)
Elliot Lee's avatar
Elliot Lee committed
633
634
635
636
637
638
{
  static GtkWidget *window = NULL;
  GtkWidget *box1;
  GtkWidget *box2;
  GtkWidget *button;
  GtkWidget *separator;
639
  GtkWidget *table;
640
  
Elliot Lee's avatar
Elliot Lee committed
641
642
  if (!window)
    {
643
644
645
646
647
648
      window = gtk_dialog_new_with_buttons ("Check Buttons",
                                            NULL, 0,
                                            GTK_STOCK_CLOSE,
                                            GTK_RESPONSE_NONE,
                                            NULL);

649
650
      gtk_window_set_screen (GTK_WINDOW (window), 
			     gtk_widget_get_screen (widget));
Elliot Lee's avatar
Elliot Lee committed
651

Manish Singh's avatar
Manish Singh committed
652
653
654
      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
655
656
657
      g_signal_connect (window, "response",
                        G_CALLBACK (gtk_widget_destroy),
                        NULL);
Elliot Lee's avatar
Elliot Lee committed
658

659
660
      box1 = GTK_DIALOG (window)->vbox;
      
Elliot Lee's avatar
Elliot Lee committed
661
      box2 = gtk_vbox_new (FALSE, 10);
662
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
Elliot Lee's avatar
Elliot Lee committed
663
664
      gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);

665
      button = gtk_check_button_new_with_mnemonic ("_button1");
Elliot Lee's avatar
Elliot Lee committed
666
667
668
669
670
671
672
673
      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);

674
675
676
      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);
677

Elliot Lee's avatar
Elliot Lee committed
678
679
680
      separator = gtk_hseparator_new ();
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);

681
682
683
      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
684
685
686
    }

  if (!GTK_WIDGET_VISIBLE (window))
687
    gtk_widget_show_all (window);
Elliot Lee's avatar
Elliot Lee committed
688
689
690
691
  else
    gtk_widget_destroy (window);
}

692
693
694
695
/*
 * GtkRadioButton
 */

696
static void
697
create_radio_buttons (GtkWidget *widget)
Elliot Lee's avatar
Elliot Lee committed
698
699
700
701
702
703
{
  static GtkWidget *window = NULL;
  GtkWidget *box1;
  GtkWidget *box2;
  GtkWidget *button;
  GtkWidget *separator;
704
  GtkWidget *table;
Elliot Lee's avatar
Elliot Lee committed
705
706
707

  if (!window)
    {
708
709
710
711
712
      window = gtk_dialog_new_with_buttons ("Radio Buttons",
                                            NULL, 0,
                                            GTK_STOCK_CLOSE,
                                            GTK_RESPONSE_NONE,
                                            NULL);
Elliot Lee's avatar
Elliot Lee committed
713

714
715
716
      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));

Manish Singh's avatar
Manish Singh committed
717
718
719
      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
720
721
722
      g_signal_connect (window, "response",
                        G_CALLBACK (gtk_widget_destroy),
                        NULL);
Elliot Lee's avatar
Elliot Lee committed
723

724
      box1 = GTK_DIALOG (window)->vbox;
Elliot Lee's avatar
Elliot Lee committed
725
726

      box2 = gtk_vbox_new (FALSE, 10);
727
      gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
Elliot Lee's avatar
Elliot Lee committed
728
729
730
731
732
733
      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 (
734
	         gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
Elliot Lee's avatar
Elliot Lee committed
735
		 "button2");
736
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
Elliot Lee's avatar
Elliot Lee committed
737
738
739
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);

      button = gtk_radio_button_new_with_label (
740
                 gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
Elliot Lee's avatar
Elliot Lee committed
741
742
743
		 "button3");
      gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);

744
      button = gtk_radio_button_new_with_label (
745
                 gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)),
746
747
748
749
		 "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
750
751
752
      separator = gtk_hseparator_new ();
      gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);

753
754
755
756
      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);

757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
      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);

777
778
779
      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
780
781
782
    }

  if (!GTK_WIDGET_VISIBLE (window))
783
    gtk_widget_show_all (window);
Elliot Lee's avatar
Elliot Lee committed
784
785
786
787
  else
    gtk_widget_destroy (window);
}

788
789
790
/*
 * GtkButtonBox
 */
Elliot Lee's avatar
Elliot Lee committed
791

792
793
794
795
static GtkWidget *
create_bbox (gint  horizontal,
	     char* title, 
	     gint  spacing,
Manish Singh's avatar
Manish Singh committed
796
797
	     gint  child_w,
	     gint  child_h,
798
	     gint  layout)
Elliot Lee's avatar
Elliot Lee committed
799
{
800
801
802
  GtkWidget *frame;
  GtkWidget *bbox;
  GtkWidget *button;
Elliot Lee's avatar
Elliot Lee committed
803
	
804
  frame = gtk_frame_new (title);
Elliot Lee's avatar
Elliot Lee committed
805
806

  if (horizontal)
807
    bbox = gtk_hbutton_box_new ();
Elliot Lee's avatar
Elliot Lee committed
808
  else
809
810
    bbox = gtk_vbutton_box_new ();

811
  gtk_container_set_border_width (GTK_CONTAINER (bbox), 5);
812
813
  gtk_container_add (GTK_CONTAINER (frame), bbox);

Elliot Lee's avatar
Elliot Lee committed
814
  gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), layout);
815
  gtk_box_set_spacing (GTK_BOX (bbox), spacing);
Elliot Lee's avatar
Elliot Lee committed
816
817
818
  gtk_button_box_set_child_size (GTK_BUTTON_BOX (bbox), child_w, child_h);
  
  button = gtk_button_new_with_label ("OK");
819
  gtk_container_add (GTK_CONTAINER (bbox), button);
Elliot Lee's avatar
Elliot Lee committed
820
821
  
  button = gtk_button_new_with_label ("Cancel");
822
  gtk_container_add (GTK_CONTAINER (bbox), button);
Elliot Lee's avatar
Elliot Lee committed
823
824
  
  button = gtk_button_new_with_label ("Help");
825
  gtk_container_add (GTK_CONTAINER (bbox), button);
Elliot Lee's avatar
Elliot Lee committed
826

827
  return frame;
Elliot Lee's avatar
Elliot Lee committed
828
829
}

830
static void
831
create_button_box (GtkWidget *widget)
Elliot Lee's avatar
Elliot Lee committed
832
833
{
  static GtkWidget* window = NULL;
834
835
836
837
838
  GtkWidget *main_vbox;
  GtkWidget *vbox;
  GtkWidget *hbox;
  GtkWidget *frame_horz;
  GtkWidget *frame_vert;
839

Elliot Lee's avatar
Elliot Lee committed
840
841
842
  if (!window)
  {
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
843
    gtk_window_set_screen (GTK_WINDOW (window), gtk_widget_get_screen (widget));
844
    gtk_window_set_title (GTK_WINDOW (window), "Button Boxes");
Elliot Lee's avatar
Elliot Lee committed
845
    
Manish Singh's avatar
Manish Singh committed
846
847
848
    g_signal_connect (window, "destroy",
		      G_CALLBACK (gtk_widget_destroyed),
		      &window);
Elliot Lee's avatar
Elliot Lee committed
849
    
850
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
851
852
853

    main_vbox = gtk_vbox_new (FALSE, 0);
    gtk_container_add (GTK_CONTAINER (window), main_vbox);
Elliot Lee's avatar
Elliot Lee committed
854
    
855
856
    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
857
    
858
    vbox = gtk_vbox_new (FALSE, 0);
859
    gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
    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);

    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
880
    
881
    hbox = gtk_hbox_new (FALSE, 0);
882
    gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
    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);
Elliot Lee's avatar
Elliot Lee committed
900
901
902
  }

  if (!GTK_WIDGET_VISIBLE (window))
903
    gtk_widget_show_all (window);
Elliot Lee's avatar
Elliot Lee committed
904
905
906
907
  else
    gtk_widget_destroy (window);
}

908
909
910
911
/*
 * GtkToolBar
 */

912
static GtkWidget*
913
914
915
new_pixmap (char      *filename,
	    GdkWindow *window,
	    GdkColor  *background)
916
917
918
919
920
{
  GtkWidget *wpixmap;
  GdkPixmap *pixmap;
  GdkBitmap *mask;

921
922
923
924
925
926
927
928
929
930
931
932
  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
933
  wpixmap = gtk_image_new_from_pixmap (pixmap, mask);
934
935
936
937

  return wpixmap;
}

938
939
940
941
942
943
944
945
946
947
948
949
950
951
952

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

953
static void
954
955
956
957
958
959
set_toolbar_horizontal (GtkWidget *widget,
			gpointer   data)
{
  gtk_toolbar_set_orientation (GTK_TOOLBAR (data), GTK_ORIENTATION_HORIZONTAL);
}

960
static void
961
962
963
964
965
966
set_toolbar_vertical (GtkWidget *widget,
		      gpointer   data)
{
  gtk_toolbar_set_orientation (GTK_TOOLBAR (data), GTK_ORIENTATION_VERTICAL);
}

967
static void
968
969
970
971
972
973
set_toolbar_icons (GtkWidget *widget,
		   gpointer   data)
{
  gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_ICONS);
}

974
static void
975
976
977
978
979
980
set_toolbar_text (GtkWidget *widget,
	          gpointer   data)
{
  gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_TEXT);
}

981
static void
982
983
984
985
986
987
set_toolbar_both (GtkWidget *widget,
		  gpointer   data)
{
  gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_BOTH);
}

988
989
990
991
992
993
994
static void
set_toolbar_both_horiz (GtkWidget *widget,
			gpointer   data)
{
  gtk_toolbar_set_style (GTK_TOOLBAR (data), GTK_TOOLBAR_BOTH_HORIZ);
}

995
static void
996
997
998
999
1000
1001
set_toolbar_enable (GtkWidget *widget,
		    gpointer   data)
{
  gtk_toolbar_set_tooltips (GTK_TOOLBAR (data), TRUE);
}

1002
static void
1003
1004
1005
1006
1007
1008
set_toolbar_disable (GtkWidget *widget,
		     gpointer   data)
{
  gtk_toolbar_set_tooltips (GTK_TOOLBAR (data), FALSE);
}

1009
static void
1010
create_toolbar (GtkWidget *widget)
1011
1012
1013
{
  static GtkWidget *window = NULL;
  GtkWidget *toolbar;
1014
  GtkWidget *entry;
1015
1016
1017
1018

  if (!window)
    {
      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1019
1020
1021
      gtk_window_set_screen (GTK_WINDOW (window),
			     gtk_widget_get_screen (widget));
      
1022
      gtk_window_set_title (GTK_WINDOW (window), "Toolbar test");
1023
      gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
1024

Manish Singh's avatar
Manish Singh committed
1025
1026
1027
      g_signal_connect (window, "destroy",
			G_CALLBACK (gtk_widget_destroyed),
			&window);
1028

1029
      gtk_container_set_border_width (GTK_CONTAINER (window), 0);
1030
1031
      gtk_widget_realize (window);

1032
      toolbar = gtk_toolbar_new ();
1033

1034
1035
1036
      gtk_toolbar_insert_stock (GTK_TOOLBAR (toolbar),
				GTK_STOCK_NEW,
				"Stock icon: New", "Toolbar/New",
Manish Singh's avatar
Manish Singh committed
1037
				G_CALLBACK (set_toolbar_small_stock), toolbar, -1);
1038
1039
1040
1041
      
      gtk_toolbar_insert_stock (GTK_TOOLBAR (toolbar),
				GTK_STOCK_OPEN,
				"Stock icon: Open", "Toolbar/Open",
Manish Singh's avatar
Manish Singh committed
1042
				G_CALLBACK (set_toolbar_large_stock), toolbar, -1);
1043
      
1044
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1045
			       "Horizontal", "Horizontal toolbar layout", "Toolbar/Horizontal",
1046
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1047
			       G_CALLBACK (set_toolbar_horizontal), toolbar);
1048
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1049
			       "Vertical", "Vertical toolbar layout", "Toolbar/Vertical",
1050
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1051
			       G_CALLBACK (set_toolbar_vertical), toolbar);
1052
1053
1054
1055

      gtk_toolbar_append_space (GTK_TOOLBAR(toolbar));

      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1056
			       "Icons", "Only show toolbar icons", "Toolbar/IconsOnly",
1057
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1058
			       G_CALLBACK (set_toolbar_icons), toolbar);
1059
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1060
			       "Text", "Only show toolbar text", "Toolbar/TextOnly",
1061
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1062
			       G_CALLBACK (set_toolbar_text), toolbar);
1063
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1064
			       "Both", "Show toolbar icons and text", "Toolbar/Both",
1065
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1066
			       G_CALLBACK (set_toolbar_both), toolbar);
1067
1068
1069
1070
1071
      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
1072
			       G_CALLBACK (set_toolbar_both_horiz), toolbar);
1073
			       
1074
1075
      gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));

1076
      entry = gtk_entry_new ();
1077

1078
      gtk_toolbar_append_widget (GTK_TOOLBAR (toolbar), entry, "This is an unusable GtkEntry ;)", "Hey don't click me!!!");
1079
1080
1081

      gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));

1082

1083
1084
      gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));

1085
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1086
			       "Enable", "Enable tooltips", NULL,
1087
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1088
			       G_CALLBACK (set_toolbar_enable), toolbar);
1089
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1090
			       "Disable", "Disable tooltips", NULL,
1091
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1092
			       G_CALLBACK (set_toolbar_disable), toolbar);
1093

1094
1095
1096
      gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));

      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
Havoc Pennington's avatar
Havoc Pennington committed
1097
			       "Frobate", "Frobate tooltip", NULL,
1098
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1099
			       NULL, toolbar);
1100
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
Havoc Pennington's avatar
Havoc Pennington committed
1101
			       "Baz", "Baz tooltip", NULL,
1102
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1103
			       NULL, toolbar);
1104

1105
1106
1107
      gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
      
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
Havoc Pennington's avatar
Havoc Pennington committed
1108
			       "Blah", "Blah tooltip", NULL,
1109
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1110
			       NULL, toolbar);
1111
      gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
Havoc Pennington's avatar
Havoc Pennington committed
1112
			       "Bar", "Bar tooltip", NULL,
1113
			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1114
			       NULL, toolbar);
1115

1116
1117
1118
1119
      gtk_container_add (GTK_CONTAINER (window), toolbar);
    }

  if (!GTK_WIDGET_VISIBLE (window))
1120
    gtk_widget_show_all (window);
1121
1122
1123
1124
  else
    gtk_widget_destroy (window);
}

1125
static GtkWidget*
1126
1127
1128
1129
1130
1131
1132
make_toolbar (GtkWidget *window)
{
  GtkWidget *toolbar;

  if (!GTK_WIDGET_REALIZED (window))
    gtk_widget_realize (window);

1133
  toolbar = gtk_toolbar_new ();
1134
1135

  gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1136
			   "Horizontal", "Horizontal toolbar layout", NULL,
1137
			   new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1138
			   G_CALLBACK (set_toolbar_horizontal), toolbar);
1139
  gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1140
			   "Vertical", "Vertical toolbar layout", NULL,
1141
			   new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1142
			   G_CALLBACK (set_toolbar_vertical), toolbar);
1143
1144
1145
1146

  gtk_toolbar_append_space (GTK_TOOLBAR(toolbar));

  gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1147
			   "Icons", "Only show toolbar icons", NULL,
1148
			   new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1149
			   G_CALLBACK (set_toolbar_icons), toolbar);
1150
  gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1151
			   "Text", "Only show toolbar text", NULL,
1152
			   new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1153
			   G_CALLBACK (set_toolbar_text), toolbar);
1154
  gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1155
			   "Both", "Show toolbar icons and text", NULL,
1156
			   new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1157
			   G_CALLBACK (set_toolbar_both), toolbar);
1158
1159
1160
1161

  gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));

  gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
Havoc Pennington's avatar
Havoc Pennington committed
1162
			   "Woot", "Woot woot woot", NULL,
1163
			   new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1164
			   NULL, toolbar);
1165
  gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
Havoc Pennington's avatar
Havoc Pennington committed
1166
			   "Blah", "Blah blah blah", "Toolbar/Big",
1167
			   new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1168
			   NULL, toolbar);
1169
1170
1171
1172

  gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));

  gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1173
			   "Enable", "Enable tooltips", NULL,
1174
			   new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1175
			   G_CALLBACK (set_toolbar_enable), toolbar);
1176
  gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
1177
			   "Disable", "Disable tooltips", NULL,
1178
			   new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1179
			   G_CALLBACK (set_toolbar_disable), toolbar);
1180

1181
1182
1183
  gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
  
  gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
Havoc Pennington's avatar
Havoc Pennington committed
1184
			   "Hoo", "Hoo tooltip", NULL,
1185
			   new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1186
			   NULL, toolbar);
1187
  gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
Havoc Pennington's avatar
Havoc Pennington committed
1188
			   "Woo", "Woo tooltip", NULL,
1189
			   new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
Manish Singh's avatar
Manish Singh committed
1190
			   NULL, toolbar);
1191

1192
1193
1194
  return toolbar;
}

1195
1196
1197
1198
/*
 * GtkStatusBar
 */

1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
static guint statusbar_counter = 1;

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

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

1209
  gtk_statusbar_push (statusbar, 1, text);
1210
1211
1212
1213
1214
1215
}

static void
statusbar_pop (GtkWidget *button,
	       GtkStatusbar *statusbar)
{
1216
  gtk_statusbar_pop (statusbar, 1);
1217
1218
1219
1220
1221