diff options
author | Bastian Ilsø <bastianilso@src.gnome.org> | 2015-02-19 15:53:35 +0100 |
---|---|---|
committer | Bastian Ilsø <bastianilso@src.gnome.org> | 2015-02-23 16:00:36 +0100 |
commit | ec07987a90137677533c42515a326bb049d237c7 (patch) | |
tree | 354b2c5db27010f54d060fb5f05248d1f5121c20 | |
parent | c73ab94d3f22b6d1b4a2860ed8f4b795ac7d610f (diff) | |
download | gtk+-ec07987a90137677533c42515a326bb049d237c7.tar.gz |
Getting-started: port drawing.c to GtkApplication
-rw-r--r-- | examples/drawing.c | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/examples/drawing.c b/examples/drawing.c index 68fb81eabc..a496bcabf4 100644 --- a/examples/drawing.c +++ b/examples/drawing.c @@ -129,17 +129,15 @@ close_window (void) gtk_main_quit (); } -int -main (int argc, - char *argv[]) +static void +activate (GtkApplication *app, + gpointer user_data) { GtkWidget *window; GtkWidget *frame; - GtkWidget *da; + GtkWidget *drawing_area; - gtk_init (&argc, &argv); - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + window = gtk_application_window_new (app); gtk_window_set_title (GTK_WINDOW (window), "Drawing Area"); g_signal_connect (window, "destroy", G_CALLBACK (close_window), NULL); @@ -150,35 +148,46 @@ main (int argc, gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); gtk_container_add (GTK_CONTAINER (window), frame); - da = gtk_drawing_area_new (); + drawing_area = gtk_drawing_area_new (); /* set a minimum size */ - gtk_widget_set_size_request (da, 100, 100); + gtk_widget_set_size_request (drawing_area, 100, 100); - gtk_container_add (GTK_CONTAINER (frame), da); + gtk_container_add (GTK_CONTAINER (frame), drawing_area); /* Signals used to handle the backing surface */ - g_signal_connect (da, "draw", + g_signal_connect (drawing_area, "draw", G_CALLBACK (draw_cb), NULL); - g_signal_connect (da,"configure-event", + g_signal_connect (drawing_area,"configure-event", G_CALLBACK (configure_event_cb), NULL); /* Event signals */ - g_signal_connect (da, "motion-notify-event", + g_signal_connect (drawing_area, "motion-notify-event", G_CALLBACK (motion_notify_event_cb), NULL); - g_signal_connect (da, "button-press-event", + g_signal_connect (drawing_area, "button-press-event", G_CALLBACK (button_press_event_cb), NULL); /* Ask to receive events the drawing area doesn't normally * subscribe to. In particular, we need to ask for the * button press and motion notify events that want to handle. */ - gtk_widget_set_events (da, gtk_widget_get_events (da) - | GDK_BUTTON_PRESS_MASK - | GDK_POINTER_MOTION_MASK); + gtk_widget_set_events (drawing_area, gtk_widget_get_events (drawing_area) + | GDK_BUTTON_PRESS_MASK + | GDK_POINTER_MOTION_MASK); gtk_widget_show_all (window); +} + +int +main (int argc, + char **argv) +{ + GtkApplication *app; + int status; - gtk_main (); + app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); - return 0; + return status; } |