3
This file extracted from the GTK 1.2 tutorial.
6
Converted from C to Pascal by Thomas E. Payne
13
glib,gdk,gtk,sysutils;
15
//* Our usual callback function */
17
procedure toggle_callback( widget : pGtkWidget; data : pgpointer );cdecl;
19
writeln ('Hello again - '+pchar(data)+' was pressed');
20
if active(GTK_TOGGLE_BUTTON(widget)^)<>0 then
21
//* If control reaches here, the toggle button is down */
22
writeln('Toggle button is down')
24
//* If control reaches here, the toggle button is up */
25
writeln('Toggle button is up');
28
//* GtkWidget is the storage type for widgets */
29
window,button,box1,label_ : pGtkWidget;
31
gtk_init (@argc, @argv);
32
//* Create a new window */
33
window := gtk_window_new (GTK_WINDOW_TOPLEVEL);
34
gtk_window_set_title (GTK_WINDOW (window), 'Toggle Buttons!');
35
//* It's a good idea to do this for all windows. */
36
gtk_signal_connect (GTK_OBJECT (window), 'destroy',
37
GTK_SIGNAL_FUNC (@gtk_exit), Nil);
38
gtk_signal_connect (GTK_OBJECT (window), 'delete_event',
39
GTK_SIGNAL_FUNC (@gtk_exit), Nil);
40
//* Sets the border width of the window. */
41
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
42
gtk_widget_realize(window);
43
//* Create a new button */
44
button := gtk_toggle_button_new ();
45
//* Connect the "clicked" signal of the button to our callback */
46
gtk_signal_connect (GTK_OBJECT (button), 'clicked',
47
GTK_SIGNAL_FUNC (@toggle_callback), pchar('toggle button'));
48
//* This calls our box creating function */
49
box1 := gtk_hbox_new(False, 0);
50
gtk_container_set_border_width (GTK_CONTAINER (box1), 2);
51
//* Create a label for the button */
52
label_ := gtk_label_new ('toggle button');
53
gtk_box_pack_start (GTK_BOX (box1), label_, FALSE, FALSE, 3);
54
//* Pack and show all our widgets */
55
gtk_widget_show(label_);
56
gtk_widget_show(box1);
57
gtk_container_add (GTK_CONTAINER (button), box1);
58
gtk_widget_show(button);
59
gtk_container_add (GTK_CONTAINER (window), button);
60
gtk_widget_show (window);
61
//* Rest in gtk_main and wait for the fun to begin! */