title: Drawing with cairo in gtk and C
body: <p>I am trying to load a png image into a cairo surface. I want to put it in a gtk interface and draw over it. 
  The problem is that I don't know how to include this surface into the interface. The <code>gtk_container_add</code> function doesn't work? or does it?
  Here's the code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;gtk/gtk.h&gt;
  #include &lt;gdk/gdk.h&gt;
  #include &lt;cairo.h&gt;
  
  cairo_surface_t *surface=NULL;
  gint surface_ret_value=0;
  
  static gboolean draw_points(GtkWidget *widget, cairo_t *cr, gpointer data)
  {
      gint i=0;
      //Draw .png
      g_print("png\n");
      guint png_width=0;
      guint png_height=0;
      guint da_width=gtk_widget_get_allocated_width(GTK_WIDGET(widget));
      guint da_height=gtk_widget_get_allocated_height(GTK_WIDGET(widget));
      if(surface_ret_value==CAIRO_STATUS_SUCCESS)
      {
        png_width=cairo_image_surface_get_width(surface);
        png_height=cairo_image_surface_get_height(surface);
        cairo_scale(cr, (float)da_width/(float)png_width,      (float)da_height/(float)png_height);
        cairo_set_source_surface(cr, surface, 0, 0);
        cairo_paint(cr);
        cairo_scale(cr, (float)png_width/(float)da_width, (float)png_height/(float)da_height);
      }
     else
     {
        g_print("Need a PNG file.\n");
     }
   }
  
  int main(int argc, char *argv[])
  {
     gtk_init(&amp;argc, &amp;argv);
     GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
     gtk_window_set_default_size(GTK_WINDOW(window), 500, 500);
     gtk_window_set_title(GTK_WINDOW(window), "Draw Points");
     g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
     //Get a PNG file.
    surface=cairo_image_surface_create_from_png("/Users/imadmesselmani/Desktop/Marianne.png");
    surface_ret_value = cairo_surface_status(surface);
    if(surface_ret_value!=CAIRO_STATUS_SUCCESS)
    {
       const char *surface_status=cairo_status_to_string(surface_ret_value);
       g_print("%s\n", surface_status);
       return 1;
    }
  
      GtkWidget *drawing_area = gtk_drawing_area_new();
      gtk_widget_set_size_request(drawing_area, 500, 500);
  
      g_signal_connect(G_OBJECT(drawing_area), "draw", G_CALLBACK(draw_points), NULL);
  
      gtk_container_add(GTK_CONTAINER(window), drawing_area);
  
      gtk_widget_show_all(window);
  
      gtk_main();
  
      return 0;
  }
  </code></pre>