/*******************************************************************************
 *  PROJECT: 
 *
 *  AUTHOR: Jonathon Jongsma
 *
 *  Copyright (c) 2007 Jonathon Jongsma
 *
 *  License:
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the
 *    Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 *    Boston, MA  02111-1307  USA
 *
 *******************************************************************************/
#include <gtk/gtk.h>
#include <gtkhex/hex-document.h>
#include <gtkhex/gtkhex.h>

static void on_document_changed(HexDocument* doc, gpointer change_data, gboolean push_undo)
{
    g_debug ("Docuement changed");
}

static void on_button_clicked(GtkButton* button, gpointer user_data)
{
    // just some arbitrary data
    static guchar data[] = {
        70, 71, 72, 73, 73, 75, 76, 77, 78, 79,
        80, 81, 82, 83, 83, 85, 86, 87, 88, 89,
        90, 91, 92, 93, 93, 95, 96, 97, 98, 99,
        100, 101, 102, 103, 104, 105, 106, 107
    };
    HexDocument* doc = HEX_DOCUMENT(user_data);
    hex_document_set_data (doc,
            0 /*offset*/,
            sizeof(data),
            0 /*rep_len -- what the hell is this?*/,
            data,
            TRUE/*undoable*/);
}

int main (int argc, char** argv)
{
    gtk_init (&argc, &argv);
    HexDocument* doc = hex_document_new ();
    GtkWidget *hex_editor = gtk_hex_new (doc);
    GtkWidget *vbox = gtk_vbox_new (FALSE, 6);
    gtk_hex_show_offsets(GTK_HEX (hex_editor), TRUE);
    g_signal_connect(G_OBJECT (doc), "document_changed",
            G_CALLBACK (on_document_changed), NULL);
    GtkWidget *win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    GtkWidget *button = gtk_button_new_with_label ("Click to Set Data");
    g_signal_connect (G_OBJECT(button), "clicked",
            G_CALLBACK(on_button_clicked), doc);

    gtk_box_pack_start_defaults (GTK_BOX (vbox), hex_editor);
    gtk_box_pack_start_defaults (GTK_BOX (vbox), button);
    gtk_container_add (GTK_CONTAINER (win), vbox);
    g_signal_connect (G_OBJECT(win), "delete_event",
            G_CALLBACK(gtk_main_quit), NULL);
    gtk_widget_show_all (win);
    gtk_main ();

    return 0;
}
