/*
 * Pack a GtkDrawingArea into a GtkNotebook. See something odd about the
 * background of the notebook but not the label.
 *
 *    gcc `pkg-config --cflags --libs gtk+-2.0` -o drawing drawing.c
 *
 * ought to build this for you.
 */

#include <stdio.h>
#include <gtk/gtk.h>

static void
on_expose_event
(
	GtkWidget* widget,
	GdkEventExpose* event,
	gpointer user_data
)
{
	GdkWindow* underlying;
	cairo_t* cr;

	underlying = gtk_widget_get_window(widget);
	cr = gdk_cairo_create(underlying);
	
	cairo_set_source_rgb(cr, 0.0, 0.2, 1.0);
	cairo_rectangle(cr, 10, 10, 80, 80);
	cairo_fill(cr);

	cairo_destroy(cr);
}

static void
setup
(
	void
)
{
	GtkWindow* window;
	GtkNotebook* notebook;
	GtkVBox* top;
	GtkLabel* label;
	GtkDrawingArea* draw;

	window = (GtkWindow*) gtk_window_new(0);
	top = (GtkVBox*) gtk_vbox_new(FALSE, 6);

	label = (GtkLabel*) gtk_label_new("Hello");
	gtk_box_pack_start((GtkBox*) top, (GtkWidget*) label, FALSE, FALSE, 0);

	draw = (GtkDrawingArea*) gtk_drawing_area_new();
	gtk_widget_set_size_request((GtkWidget*) draw, 200, 120);
	gtk_box_pack_start((GtkBox*) top, (GtkWidget*) draw, TRUE, TRUE, 0);

	notebook = (GtkNotebook*) gtk_notebook_new();
	gtk_notebook_append_page(notebook, (GtkWidget*) top, NULL);
	gtk_notebook_set_show_border(notebook, FALSE);
	gtk_notebook_set_show_tabs(notebook, FALSE);
	gtk_container_add((GtkContainer*) window, (GtkWidget*) notebook);
	gtk_window_set_default_size(window, 150, 150);
	gtk_widget_show_all((GtkWidget*) window);

	g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
	g_signal_connect(draw, "expose-event", G_CALLBACK(on_expose_event), NULL);
}
	
int
main
(
	int argc,
	char** argv
)
{
	gtk_init(&argc, &argv);
	setup();
	gtk_main();
}
