#include <gtk/gtk.h>


static void do_paint (GtkWidget *w)
{
	int width, height;
	GdkWindow *win = gtk_widget_get_window (w);
	cairo_t *cr = gdk_cairo_create (win);

	width = gtk_widget_get_allocated_width (w);
	height = gtk_widget_get_allocated_height (w);
	cairo_rectangle (cr, 0, 0, width, height);
	cairo_set_source_rgb (cr, 1., 0., 0.);
	cairo_fill (cr);
	cairo_destroy (cr);
}

int main (int argc, char *argv[])
{
	GtkWidget *win, *grid, *button, *drawing_area;

	gtk_init (&argc, &argv);
	win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	g_signal_connect (win, "delete-event", G_CALLBACK (gtk_main_quit), NULL);
	grid = gtk_grid_new ();
	drawing_area = gtk_drawing_area_new ();
	gtk_widget_set_size_request (drawing_area, 500, 500);
	gtk_grid_attach (GTK_GRID (grid), drawing_area, 0, 1, 1, 1);
	button = gtk_button_new_with_label ("Paint");
	g_signal_connect_swapped (button, "clicked", G_CALLBACK (do_paint), drawing_area);
	gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1);
	gtk_container_add (GTK_CONTAINER (win), grid);
	gtk_widget_show_all (win);
	gtk_main ();
	return 0;
}

