2011-01-20 06:30:34 +00:00
|
|
|
#include <gtk/gtk.h>
|
2017-03-12 20:13:10 +00:00
|
|
|
#include <glib/gstdio.h>
|
2011-01-20 06:30:34 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
print_hello (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
g_print ("Hello World\n");
|
|
|
|
}
|
|
|
|
|
2020-02-10 01:06:58 +00:00
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget, gpointer data)
|
|
|
|
{
|
2020-10-21 21:44:53 +00:00
|
|
|
GtkWindow *window = data;
|
2020-02-10 01:06:58 +00:00
|
|
|
|
2020-10-21 21:44:53 +00:00
|
|
|
gtk_window_close (window);
|
2020-02-10 01:06:58 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 21:44:53 +00:00
|
|
|
static void
|
|
|
|
activate (GtkApplication *app,
|
|
|
|
gpointer user_data)
|
2011-01-20 06:30:34 +00:00
|
|
|
{
|
|
|
|
/* Construct a GtkBuilder instance and load our UI description */
|
2020-10-21 21:44:53 +00:00
|
|
|
GtkBuilder *builder = gtk_builder_new ();
|
2011-01-20 06:30:34 +00:00
|
|
|
gtk_builder_add_from_file (builder, "builder.ui", NULL);
|
|
|
|
|
|
|
|
/* Connect signal handlers to the constructed widgets. */
|
2020-10-21 21:44:53 +00:00
|
|
|
GObject *window = gtk_builder_get_object (builder, "window");
|
|
|
|
gtk_window_set_application (GTK_WINDOW (window), app);
|
2011-01-20 06:30:34 +00:00
|
|
|
|
2020-10-21 21:44:53 +00:00
|
|
|
GObject *button = gtk_builder_get_object (builder, "button1");
|
2011-01-20 06:30:34 +00:00
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
|
|
|
|
|
|
|
|
button = gtk_builder_get_object (builder, "button2");
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
|
|
|
|
|
|
|
|
button = gtk_builder_get_object (builder, "quit");
|
2020-10-21 21:44:53 +00:00
|
|
|
g_signal_connect_swapped (button, "clicked", G_CALLBACK (quit_cb), window);
|
2020-02-10 01:06:58 +00:00
|
|
|
|
2022-11-29 11:35:40 +00:00
|
|
|
gtk_window_present (GTK_WINDOW (window));
|
2020-10-21 21:44:53 +00:00
|
|
|
g_object_unref (builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char *argv[])
|
|
|
|
{
|
|
|
|
#ifdef GTK_SRCDIR
|
|
|
|
g_chdir (GTK_SRCDIR);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GtkApplication *app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
|
|
|
|
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
2011-01-20 06:30:34 +00:00
|
|
|
|
2020-10-21 21:44:53 +00:00
|
|
|
int status = g_application_run (G_APPLICATION (app), argc, argv);
|
|
|
|
g_object_unref (app);
|
2011-01-20 06:30:34 +00:00
|
|
|
|
2020-10-21 21:44:53 +00:00
|
|
|
return status;
|
2011-01-20 06:30:34 +00:00
|
|
|
}
|