#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(widget)));
 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(widget)));
 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 *label = GTK_WIDGET(data);

 if (GTK_WIDGET_MAPPED (label))
    gtk_widget_hide (label);
  else
    gtk_widget_show (label);

  return;
}

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

    hbox = gtk_hbox_new (FALSE, 0);
    vbox = gtk_vbox_new (FALSE, 5);
    label = gtk_label_new ("B\nU\nG");
    foo = gtk_label_new ("foo");
    button = gtk_button_new_with_label ("baa");
    
    
    gtk_widget_set_size_request (label, 64, 64);
    g_signal_connect (G_OBJECT(button), "clicked", G_CALLBACK(clicked_cb), label);
    g_signal_connect (G_OBJECT(label), "expose_event", G_CALLBACK(expose_cb), NULL);
    g_signal_connect (G_OBJECT(hbox), "expose_event", G_CALLBACK(expose_cb), NULL);
    g_signal_connect (G_OBJECT(label), "size-allocate", G_CALLBACK(allocate_cb), NULL);
    g_signal_connect (G_OBJECT(hbox), "size-allocate", G_CALLBACK(allocate_cb), NULL);
    
    gtk_box_pack_start_defaults (GTK_BOX (hbox), label);
    gtk_box_pack_start_defaults (GTK_BOX (hbox), button);
    gtk_box_pack_start_defaults (GTK_BOX (vbox), hbox);
    gtk_box_pack_start_defaults (GTK_BOX (vbox), foo);
    gtk_container_add (GTK_CONTAINER (window), vbox);

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