/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * gtktest.c: Demonstrate expose events.
 */

#include <gdk/gdk.h>
#include <gtk/gtk.h>

static gint HandleExpose(GtkWidget* widget, GdkEventExpose* event)
{
    printf("Expose\n");
    return TRUE;
}

static gint HandleDelete(GtkWidget* widget, GdkEventKey* 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. */
    gtk_main_quit();
    return TRUE;
}

/* Make a new window, destroying the old one. */
static void NewWindow()
{
    GtkWidget* win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    
    /* Window manager delete */
    gtk_signal_connect(GTK_OBJECT(win), "delete_event",
                       (GtkSignalFunc)HandleDelete, 0);

    /* This event occurs when we call gtk_widget_destroy() on the window,
     * or if we return FALSE in the "delete_event" callback.
    gtk_signal_connect(GTK_OBJECT(sWin), "destroy",
                       (GtkSignalFunc)HandleDestroy, 0);
     */

    GtkWidget* drawingArea = gtk_drawing_area_new();
    gtk_container_add(GTK_CONTAINER(win), drawingArea);
    gtk_widget_show(drawingArea);

    gtk_drawing_area_size(GTK_DRAWING_AREA(drawingArea), 100, 100);

    /* This doesn't seem to make any difference. */
    gtk_widget_set_events(drawingArea, GDK_EXPOSURE_MASK);

    gtk_signal_connect(GTK_OBJECT(drawingArea), "expose_event",
                       (GtkSignalFunc)HandleExpose, 0);


    gtk_widget_show(win);
}

int main(int argc, char** argv)
{
    /* See http://www.gtk.org/tutorial */
    gtk_init(&argc, &argv);

    NewWindow();

    gtk_main();
    return 0;
}

