-
Notifications
You must be signed in to change notification settings - Fork 0
/
native-gnome.pl
99 lines (77 loc) · 2.24 KB
/
native-gnome.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
use v6;
use NativeCall;
constant GTKLIB = 'gtk-3';
sub gtk_init(int32, CArray[Str])
returns int32
is native(GTKLIB)
{*}
sub gtk_window_new(int32)
returns Pointer
is native(GTKLIB)
{*}
sub gtk_button_new_with_label (Str)
returns Pointer
is native(GTKLIB)
{*}
sub gtk_container_add(Pointer, Pointer)
returns int32
is native(GTKLIB)
{*}
sub gtk_widget_show_all(Pointer)
returns int32
is native(GTKLIB)
{*}
sub gtk_main()
is native(GTKLIB)
{*}
sub g_signal_connect_object (Pointer, Str, &callback (), Pointer, Pointer)
returns int32
is native(GTKLIB)
{*}
sub gtk_main_quit ()
is native(GTKLIB)
{*}
sub click_handler {
say "clicked";
gtk_main_quit();
}
sub MAIN () {
my @argv := CArray[Str].new;
gtk_init(0, @argv);
my $window = gtk_window_new(0);
my $button = gtk_button_new_with_label("Hallihallo");
g_signal_connect_object($button, "clicked", &click_handler, Nil, Nil);
gtk_container_add($window, $button);
gtk_widget_show_all($window);
gtk_main();
}
=finish
#include <gtk/gtk.h>
/* Rückruffunktion - aufgerufen, wenn die Schaltfläche geklickt wurde */
void on_button_clicked (GtkButton *button, gpointer data)
{
g_print ("Knopf '%s' geklickt!\n", gtk_button_get_label (button));
gtk_main_quit (); /* Beendet das Programm */
}
int main (int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *button;
/* GTK+ initialisieren */
gtk_init (&argc, &argv);
/* Hauptfenster erstellen, Titel setzen, Rahmenabstand setzen */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Hallo Welt!");
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
/* Schaltfläche erstellen und dem Fenster hinzufügen */
button = gtk_button_new_with_label ("Hallo Wikipedia!");
gtk_container_add (GTK_CONTAINER (window), button);
/* Signale mit Rückruffunktionen verbinden */
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
g_signal_connect (button, "clicked", G_CALLBACK (on_button_clicked), NULL);
/* Fenster und all seine Unterelemente anzeigen */
gtk_widget_show_all (window);
/* Haupt-Ereignisschleife starten */
gtk_main ();
return 0;
}