I'm using gtk+-3.2.4 on Ubuntu 11.04 (Natty). I'm trying to draw in a GtkDrawingArea with Cairo and have the drawing area be scrollable. The code runs without errors but no drawing is done. What am I doing wrong ?
// gcc -Wextra -o scrol `pkg-config --cflags --libs gtk+-3.0` scrol1.c
#include <gtk/gtk.h>
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
static gboolean draw_cb (GtkWidget *widget, GdkEventExpose *event)
{
cairo_t *cr;
cr = gdk_cairo_create (gtk_widget_get_window (widget));
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_paint(cr);
cairo_set_source_rgb (cr, 0.42, 0.65, 0.80);
cairo_set_line_width (cr,6);
cairo_rectangle (cr, 3, 3, 100, 100);
cairo_stroke (cr);
cairo_destroy(cr);
return FALSE;
}
int main (int argc, char *argv[])
{
gtk_init (&argc, &argv);
GtkWidget *window;
GtkWidget *grid;
GtkWidget *swindow;
GtkWidget *viewport;
GtkWidget *darea;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
grid = gtk_grid_new();
swindow = gtk_scrolled_window_new (NULL,NULL);
viewport = gtk_viewport_new (NULL,NULL);
darea = gtk_drawing_area_new();
gtk_container_add (GTK_CONTAINER(viewport), darea);
gtk_container_add (GTK_CONTAINER(swindow), viewport);
gtk_grid_attach (GTK_GRID(grid), swindow, 0, 1, 1, 2);
gtk_container_add (GTK_CONTAINER(window), grid);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
g_signal_connect (darea, "draw", G_CALLBACK(draw_cb), NULL);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}