#include <gtk/gtk.h>


gboolean    allocate_cb   (GtkWidget *widget,
                         GtkAllocation *allocation,
                         gpointer data)
{
 g_message ("Allocate event recieved for %s", g_type_name (G_OBJECT_TYPE(data)));
 g_message ("     Rectangle %d %d %d %d", allocation->x, allocation->y, allocation->width, allocation->height);
 
 return FALSE;
}

gboolean    expose_cb   (GtkWidget *widget,
                         GdkEventExpose *event,
                          gpointer data)
{
 gint i, n;
 GdkRectangle *rects;
 
 gdk_region_get_rectangles (event->region, &rects, &n);
 
 g_message ("Expose event recieved %d rects for %s", n, g_type_name (G_OBJECT_TYPE(data)));
 for (i=0; i< n; i++)
    {
     g_message ("     Rectangle %d %d %d %d", rects[i].x, rects[i].y, rects[i].width, rects[i].height);
    }
 
 return FALSE;
}

void clicked_cb (GtkWidget *widget, gpointer data)
{
 GtkWidget *image = GTK_WIDGET(data);
 if (GTK_WIDGET_MAPPED (image))
  {
    gtk_widget_hide (image);
  }
  else
  {
    gtk_widget_show (image);
  }
  return;
}

int main( int   argc,
          char *argv[] )
{
    GtkWidget *window;
    GtkWidget *image;
    GtkWidget *button;
    GtkWidget *vbox;
    GtkWidget *foo;
    
    gtk_init (&argc, &argv);
    
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_resizable (GTK_WINDOW(window), FALSE);

// This shows bug and note that it is related to incorrect region values
// Second region has the same height
    vbox = gtk_vbox_new (FALSE, 1);
// This works fine
//  vbox = gtk_vbox_new (FALSE, 0);

    image = gtk_image_new_from_stock ("gtk-open", GTK_ICON_SIZE_DIALOG);
    foo = gtk_label_new ("temp");
    button = gtk_button_new_with_label ("push");
    
    g_signal_connect (G_OBJECT(button), "clicked", G_CALLBACK(clicked_cb), image);
    g_signal_connect (G_OBJECT(window), "expose_event", G_CALLBACK(expose_cb), window);
    g_signal_connect (G_OBJECT(window), "size_allocate", G_CALLBACK(allocate_cb), window);
    
    gtk_box_pack_start_defaults (GTK_BOX (vbox), image);
    gtk_box_pack_start_defaults (GTK_BOX (vbox), foo);
    gtk_box_pack_start_defaults (GTK_BOX (vbox), button);
    gtk_container_add (GTK_CONTAINER (window), vbox);

    gtk_widget_show_all  (window);
    
    gtk_main ();
    
    return 0;
}
