mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-30 15:31:34 +00:00
7ac6e25ffc
Some people read the "Getting Started" section as a series of incremental lessons, and having the examples go from GtkApplication to the old style "init / spin the main loop" confuses them. We should be using GtkApplication everywhere in our examples.
60 lines
1.5 KiB
C
60 lines
1.5 KiB
C
#include <gtk/gtk.h>
|
|
#include <glib/gstdio.h>
|
|
|
|
static void
|
|
print_hello (GtkWidget *widget,
|
|
gpointer data)
|
|
{
|
|
g_print ("Hello World\n");
|
|
}
|
|
|
|
static void
|
|
quit_cb (GtkWidget *widget, gpointer data)
|
|
{
|
|
GtkWindow *window = data;
|
|
|
|
gtk_window_close (window);
|
|
}
|
|
|
|
static void
|
|
activate (GtkApplication *app,
|
|
gpointer user_data)
|
|
{
|
|
/* Construct a GtkBuilder instance and load our UI description */
|
|
GtkBuilder *builder = gtk_builder_new ();
|
|
gtk_builder_add_from_file (builder, "builder.ui", NULL);
|
|
|
|
/* Connect signal handlers to the constructed widgets. */
|
|
GObject *window = gtk_builder_get_object (builder, "window");
|
|
gtk_window_set_application (GTK_WINDOW (window), app);
|
|
|
|
GObject *button = gtk_builder_get_object (builder, "button1");
|
|
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");
|
|
g_signal_connect_swapped (button, "clicked", G_CALLBACK (quit_cb), window);
|
|
|
|
gtk_widget_show (GTK_WIDGET (window));
|
|
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);
|
|
|
|
int status = g_application_run (G_APPLICATION (app), argc, argv);
|
|
g_object_unref (app);
|
|
|
|
return status;
|
|
}
|