#include <gtk/gtk.h>

static void button_clicked (GtkButton *button,
                gpointer   user_data)
{
   g_print("The Button was clicked!");
}
static gboolean delete_event( GtkWidget *widget,
                              GdkEvent  *event,
                              gpointer   data )
{
    /* If you return FALSE in the "delete-event" signal handler,
     * GTK will emit the "destroy" signal. Returning TRUE means
     * you don't want the window to be destroyed.
     * This is useful for popping up 'are you sure you want to quit?'
     * type dialogs. */
    g_print ("delete event occurred\n");

    return FALSE;
}

/* Another callback */
static void destroy( GtkWidget *widget,
                     gpointer   data )
{
    gtk_main_quit ();
}
int main( int   argc,
          char *argv[] )
{
    GtkWidget *window;
    GtkWidget *button1; 
    GtkWidget *button2; 
    GtkWidget *button3; 
    GtkWidget *button4; 
    GtkWidget *box;
    GtkWidget *table;
    GtkWidget *image;

    gtk_init (&argc, &argv);
    
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    gtk_window_set_default_size (GTK_WINDOW (window), 800, 600); 

    button1 = gtk_button_new_with_label(""); 
    image = gtk_image_new_from_file ("hidden.jpg");
    gtk_button_set_image(GTK_BUTTON(button1),image); 

    button2 = gtk_button_new_with_label("");
    image = gtk_image_new_from_file ("hidden.jpg");
    gtk_button_set_image(GTK_BUTTON(button2),image);
 
    button3 = gtk_button_new_with_label("");
    image = gtk_image_new_from_file ("hidden.jpg");
    gtk_button_set_image(GTK_BUTTON(button3),image); 

    button4 = gtk_button_new_with_label("");
    image = gtk_image_new_from_file ("hidden.jpg");
    gtk_button_set_image(GTK_BUTTON(button4),image); 

    /* Create a 2x2 table */
    table = gtk_table_new (2, 2, TRUE);

    /* Put the table in the main window */
    gtk_container_add (GTK_CONTAINER (window), table);

    /* Set the spacing of the container within its window */ 
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);

    /* Place the first button at the top left corner */ 
    gtk_table_attach(GTK_TABLE (table), 
                     button1,
                     0, 1, 0, 1, 
                     GTK_SHRINK,
                     GTK_SHRINK,
                     0,
                     0);

    //gtk_table_attach_defaults (GTK_TABLE (table), button1, 0, 1, 0, 1);

    /* Place the second button at the top right corner */ 
    gtk_table_attach(GTK_TABLE (table), 
                     button2,
                     1, 2, 0, 1, 
                     GTK_SHRINK,
                     GTK_SHRINK,
                     0,
                     0);


    /* Place the third button at the bottom right corner */ 
    gtk_table_attach(GTK_TABLE (table), 
                     button3,
                     0, 1, 1, 2,
                     GTK_SHRINK,
                     GTK_SHRINK,
                     0,
                     0);
    
    /* Place the fourth button at the bottom right corner */ 
    gtk_table_attach(GTK_TABLE (table), 
                     button4,
                     1,2, 1, 2,
                     GTK_SHRINK,
                     GTK_SHRINK,
                     0,
                     0);

    /* Setting the spacing between the rows in the grid */ 
    gtk_table_set_row_spacings(GTK_TABLE (table),
                                10 );

    /* Setting the spacing between the columns in the grid */ 
    gtk_table_set_col_spacings(GTK_TABLE (table),
                                 20);

    g_signal_connect(button1,"clicked", G_CALLBACK(button_clicked),NULL);
    
    /* Here we connect the "destroy" event to a signal handler.  
     * This event occurs when we call gtk_widget_destroy() on the window,
     * or if we return FALSE in the "delete-event" callback. */
    g_signal_connect (window, "destroy",
		      G_CALLBACK (destroy), NULL);


    /* Here we connect the "destroy" event to a signal handler.  
     * This event occurs when we call gtk_widget_destroy() on the window,
     * or if we return FALSE in the "delete-event" callback. */
    g_signal_connect (window, "destroy",
		      G_CALLBACK (destroy), NULL);


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