[ghex/gtk4-port: 85/91] HexDocument: convert to final type.




commit 47ff6fd7900bd8e1ac36686ce7a9108c30042996
Author: Logan Rathbone <poprocks gmail com>
Date:   Wed Aug 4 19:32:18 2021 -0400

    HexDocument: convert to final type.
    
    Adjust other gtkhex code accordingly.
    
    Seems to still build with Zarro Woornings(tm) and to run fine.
    
    Some bugs may have crept in though with these major refactorings, so it
    is all worth monitoring.

 src/gtkhex.c       | 117 +++++++++++++++---------
 src/hex-document.c | 262 +++++++++++++++++++++++------------------------------
 src/hex-document.h |  47 +---------
 3 files changed, 187 insertions(+), 239 deletions(-)
---
diff --git a/src/gtkhex.c b/src/gtkhex.c
index 17241dda..fc56f5eb 100644
--- a/src/gtkhex.c
+++ b/src/gtkhex.c
@@ -980,7 +980,7 @@ render_hex_lines (GtkHex *gh,
        frm_len = format_xblock (gh, (char *)gh->disp_buffer,
                        (gh->top_line + min_lines) * gh->cpl,
                        MIN( (gh->top_line + max_lines + 1) * gh->cpl,
-                               (int)gh->document->file_size ));
+                               hex_document_get_file_size (gh->document) ));
        
        for (int i = min_lines; i <= max_lines; i++)
        {
@@ -1042,7 +1042,7 @@ render_ascii_lines (GtkHex *gh,
        frm_len = format_ablock (gh, (char *)gh->disp_buffer,
                        (gh->top_line + min_lines) * gh->cpl,
                        MIN( (gh->top_line + max_lines + 1) * gh->cpl,
-                               (int)gh->document->file_size ));
+                               hex_document_get_file_size (gh->document) ));
        
        for (int i = min_lines; i <= max_lines; i++)
        {
@@ -1173,18 +1173,20 @@ recalc_displays (GtkHex *gh)
 {
        GtkWidget *widget = GTK_WIDGET (gh);
        int hex_cpl;
+       int file_size;
 
        hex_cpl = gtk_hex_layout_get_hex_cpl (GTK_HEX_LAYOUT(gh->layout_manager));
+       file_size = hex_document_get_file_size (gh->document);
 
        /*
         * Only change the value of the adjustment to put the cursor on screen
         * if the cursor is currently within the displayed portion.
         */
-       if (gh->document->file_size == 0 || gh->cpl == 0)
+       if (file_size == 0 || gh->cpl == 0)
                gh->lines = 1;
        else {
-               gh->lines = gh->document->file_size / gh->cpl;
-               if (gh->document->file_size % gh->cpl)
+               gh->lines = file_size / gh->cpl;
+               if (file_size % gh->cpl)
                        gh->lines++;
        }
 
@@ -1273,7 +1275,7 @@ scroll_timeout_handler(GtkHex *gh)
                gtk_hex_set_cursor (gh, MAX(0, (int)(gh->cursor_pos - gh->cpl)));
        }
        else if (gh->scroll_dir > 0) {
-               gtk_hex_set_cursor(gh, MIN((int)gh->document->file_size - 1,
+               gtk_hex_set_cursor(gh, MIN(hex_document_get_file_size (gh->document) - 1,
                                                gh->cursor_pos + gh->cpl));
        }
        return TRUE;
@@ -1616,6 +1618,11 @@ key_press_cb (GtkEventControllerKey *controller,
        GtkHex *gh = GTK_HEX(user_data);
        GtkWidget *widget = GTK_WIDGET(user_data);
        gboolean ret = TRUE;
+       int file_size;
+
+       g_return_val_if_fail (HEX_IS_DOCUMENT (gh->document), FALSE);
+
+       file_size = hex_document_get_file_size (gh->document);
 
        /* don't trample over Ctrl */
        if (state & GDK_CONTROL_MASK) {
@@ -1654,7 +1661,7 @@ key_press_cb (GtkEventControllerKey *controller,
                }
                break;
        case GDK_KEY_Delete:
-               if(gh->cursor_pos < (int)gh->document->file_size) {
+               if (gh->cursor_pos < file_size) {
                        hex_document_set_data(gh->document, gh->cursor_pos,
                                                                  0, 1, NULL, TRUE);
                        gtk_hex_set_cursor(gh, gh->cursor_pos);
@@ -1667,10 +1674,12 @@ key_press_cb (GtkEventControllerKey *controller,
                gtk_hex_set_cursor(gh, gh->cursor_pos + gh->cpl);
                break;
        case GDK_KEY_Page_Up:
-               gtk_hex_set_cursor(gh, MAX(0, (gint)gh->cursor_pos - gh->vis_lines*gh->cpl));
+               gtk_hex_set_cursor(gh, MAX(0, gh->cursor_pos - gh->vis_lines*gh->cpl));
                break;
        case GDK_KEY_Page_Down:
-               gtk_hex_set_cursor(gh, MIN((gint)gh->document->file_size, (gint)gh->cursor_pos + 
gh->vis_lines*gh->cpl));
+               gtk_hex_set_cursor(gh,
+                               MIN(file_size,
+                                       gh->cursor_pos + gh->vis_lines*gh->cpl));
                break;
        default:
                if (state & GDK_ALT_MASK) {
@@ -1690,7 +1699,7 @@ key_press_cb (GtkEventControllerKey *controller,
                                }
                                break;
                        case GDK_KEY_Right:
-                               if(gh->cursor_pos >= (int)gh->document->file_size)
+                               if(gh->cursor_pos >= file_size)
                                        break;
                                if(!(state & GDK_SHIFT_MASK)) {
                                        gh->lower_nibble = !gh->lower_nibble;
@@ -1823,20 +1832,26 @@ hide_offsets_widget(GtkHex *gh)
 /*
  * default data_changed signal handler
  */
-static void gtk_hex_real_data_changed (GtkHex *gh, gpointer data)
+static void
+gtk_hex_real_data_changed (GtkHex *gh, gpointer data)
 {
        HexChangeData *change_data = (HexChangeData *)data;
        int start_line, end_line;
        int lines;
+       int file_size;
 
-       if(gh->cpl == 0)
+       g_return_if_fail (HEX_IS_DOCUMENT (gh->document));
+
+       file_size = hex_document_get_file_size (gh->document);
+
+       if (gh->cpl == 0)
                return;
 
-       if(change_data->start - change_data->end + 1 != change_data->rep_len) {
-               lines = gh->document->file_size / gh->cpl;
-               if(gh->document->file_size % gh->cpl)
+       if (change_data->start - change_data->end + 1 != change_data->rep_len) {
+               lines = file_size / gh->cpl;
+               if (file_size % gh->cpl)
                        lines++;
-               if(lines != gh->lines) {
+               if (lines != gh->lines) {
                        gh->lines = lines;
                        gtk_adjustment_set_value(gh->adj, MIN(gtk_adjustment_get_value(gh->adj), gh->lines - 
gh->vis_lines));
                        gtk_adjustment_set_value(gh->adj, MAX(0, gtk_adjustment_get_value(gh->adj)));
@@ -1942,12 +1957,15 @@ gtk_hex_insert_highlight (GtkHex *gh,
                gint start, gint end)
 {
        GdkRGBA rgba;
-       gint length = gh->document->file_size;
+       int file_size;
+
+       g_return_val_if_fail (HEX_IS_DOCUMENT (gh->document), NULL);
 
+       file_size = hex_document_get_file_size (gh->document);
        GtkHex_Highlight *new = g_malloc0(sizeof(GtkHex_Highlight));
 
-       new->start = CLAMP(MIN(start, end), 0, length);
-       new->end = MIN(MAX(start, end), length);
+       new->start = CLAMP(MIN(start, end), 0, file_size);
+       new->end = MIN(MAX(start, end), file_size);
 
        new->valid = FALSE;
 
@@ -2815,17 +2833,21 @@ gtk_hex_paste_from_clipboard (GtkHex *gh)
 void
 gtk_hex_set_selection (GtkHex *gh, gint start, gint end)
 {
-       gint length = gh->document->file_size;
-       gint oe, os, ne, ns;
+       int file_size;
+       int oe, os, ne, ns;
+
+       g_return_if_fail (HEX_IS_DOCUMENT (gh->document));
+
+       file_size = hex_document_get_file_size (gh->document);
 
        if (end < 0)
-               end = length;
+               end = file_size;
 
        os = MIN(gh->selection.start, gh->selection.end);
        oe = MAX(gh->selection.start, gh->selection.end);
 
-       gh->selection.start = CLAMP(start, 0, length);
-       gh->selection.end = MIN(end, length);
+       gh->selection.start = CLAMP(start, 0, file_size);
+       gh->selection.end = MIN(end, file_size);
 
        gtk_hex_invalidate_highlight(gh, &gh->selection);
 
@@ -2922,16 +2944,20 @@ gtk_hex_set_nibble (GtkHex *gh, gint lower_nibble)
  * moves cursor to byte index
  */
 void
-gtk_hex_set_cursor(GtkHex *gh, int index) {
+gtk_hex_set_cursor(GtkHex *gh, int index)
+{
        int y;
-       int old_pos = gh->cursor_pos;
+       int old_pos;
+       int file_size;
 
-       g_return_if_fail(gh != NULL);
-       g_return_if_fail(GTK_IS_HEX(gh));
+       g_return_if_fail (GTK_IS_HEX (gh));
 
-       if ((index >= 0) && (index <= (int)gh->document->file_size))
+       old_pos = gh->cursor_pos;
+       file_size = hex_document_get_file_size (gh->document);
+
+       if ((index >= 0) && (index <= file_size))
        {
-               if(!gh->insert && index == (int)gh->document->file_size)
+               if(!gh->insert && index == file_size)
                        index--;
 
                index = MAX(index, 0);
@@ -2954,7 +2980,7 @@ gtk_hex_set_cursor(GtkHex *gh, int index) {
                        gtk_adjustment_set_value(gh->adj, y);
                }      
 
-               if(index == (int)gh->document->file_size)
+               if(index == file_size)
                        gh->lower_nibble = FALSE;
 
                if(gh->selecting) {
@@ -2985,17 +3011,19 @@ void
 gtk_hex_set_cursor_xy (GtkHex *gh, int x, int y)
 {
        int cp;
-       int old_pos = gh->cursor_pos;
+       int old_pos;
+       int file_size;
 
-       g_return_if_fail(gh != NULL);
-       g_return_if_fail(GTK_IS_HEX(gh));
+       g_return_if_fail (GTK_IS_HEX(gh));
 
+       old_pos = gh->cursor_pos;
        cp = y*gh->cpl + x;
+       file_size = hex_document_get_file_size (gh->document);
 
        if ((y >= 0) && (y < gh->lines) && (x >= 0) &&
-          (x < gh->cpl) && (cp <= (int)gh->document->file_size))
+          (x < gh->cpl) && (cp <= file_size))
        {
-               if (!gh->insert && cp == (int)gh->document->file_size)
+               if (!gh->insert && cp == file_size)
                        cp--;
 
                cp = MAX(cp, 0);
@@ -3051,10 +3079,9 @@ gtk_hex_get_cursor(GtkHex *gh)
 guchar
 gtk_hex_get_byte (GtkHex *gh, int offset)
 {
-       g_return_val_if_fail(gh != NULL, 0);
-       g_return_val_if_fail(GTK_IS_HEX(gh), 0);
+       g_return_val_if_fail (GTK_IS_HEX(gh), 0);
 
-       if((offset >= 0) && (offset < (int)gh->document->file_size))
+       if ((offset >= 0) && (offset < hex_document_get_file_size (gh->document)))
                return hex_document_get_byte(gh->document, offset);
 
        return 0;
@@ -3110,14 +3137,16 @@ gtk_hex_show_offsets(GtkHex *gh, gboolean show)
 void
 gtk_hex_set_insert_mode (GtkHex *gh, gboolean insert)
 {
-       g_return_if_fail(gh != NULL);
-       g_return_if_fail(GTK_IS_HEX(gh));
+       int file_size;
+
+       g_return_if_fail (HEX_IS_DOCUMENT (gh->document));
 
+       file_size = hex_document_get_file_size (gh->document);
        gh->insert = insert;
 
-       if(!gh->insert && gh->cursor_pos > 0) {
-               if(gh->cursor_pos >= (int)gh->document->file_size)
-                       gh->cursor_pos = (int)gh->document->file_size - 1;
+       if (!gh->insert && gh->cursor_pos > 0) {
+               if (gh->cursor_pos >= file_size)
+                       gh->cursor_pos = file_size - 1;
        }
 }
 
diff --git a/src/hex-document.c b/src/hex-document.c
index 075686bc..ea6a788e 100644
--- a/src/hex-document.c
+++ b/src/hex-document.c
@@ -41,9 +41,9 @@
 #include <sys/stat.h>
 #include <string.h>
 
-static void hex_document_class_init     (HexDocumentClass *);
-static void hex_document_init           (HexDocument *doc);
-static void hex_document_finalize       (GObject *obj);
+//static void hex_document_class_init     (HexDocumentClass *);
+//static void hex_document_init           (HexDocument *doc);
+
 static void hex_document_real_changed   (HexDocument *doc,
                                                                                 gpointer change_data,
                                                                                 gboolean undoable);
@@ -72,11 +72,37 @@ enum {
        LAST_SIGNAL
 };
 
-static gint hex_signals[LAST_SIGNAL];
+static guint hex_signals[LAST_SIGNAL];
+
+
+/* GOBJECT DEFINITION */
+
+struct _HexDocument
+{
+       GObject object;
+
+       GList *views;      /* a list of GtkHex widgets showing this document */
+       
+       char *file_name;
+       char *basename;
 
-static GObjectClass *parent_class = NULL;
+       char *buffer;    /* data buffer */
+       char *gap_pos;   /* pointer to the start of insertion gap */
+       int gap_size;     /* insertion gap size */
+       int buffer_size; /* buffer size = file size + gap size */
+       int file_size;   /* real file size */
 
-static GList *doc_list = NULL;
+       gboolean changed;
+
+       GList *undo_stack; /* stack base */
+       GList *undo_top;   /* top of the stack (for redo) */
+       int undo_depth;  /* number of els on stack */
+       int undo_max;    /* max undo depth */
+};
+
+G_DEFINE_TYPE (HexDocument, hex_document, G_TYPE_OBJECT)
+
+/* ---- */
 
 static void
 free_stack(GList *stack)
@@ -290,33 +316,31 @@ hex_document_remove_view(HexDocument *doc, GtkWidget *view)
 }
 
 static void
-hex_document_finalize(GObject *obj)
+hex_document_finalize (GObject *obj)
 {
-       HexDocument *hex;
+       HexDocument *doc;
        
-       hex = HEX_DOCUMENT(obj);
+       doc = HEX_DOCUMENT(obj);
        
-       if(hex->buffer)
-               g_free(hex->buffer);
+       if (doc->buffer)
+               g_free (doc->buffer);
        
-       if(hex->file_name)
-               g_free(hex->file_name);
-
-       if(hex->basename)
-               g_free(hex->basename);
+       if (doc->file_name)
+               g_free (doc->file_name);
 
-       undo_stack_free(hex);
+       if (doc->basename)
+               g_free (doc->basename);
 
-       while(hex->views)
-               hex_document_remove_view(hex, (GtkWidget *)hex->views->data);
+       undo_stack_free (doc);
 
-       doc_list = g_list_remove(doc_list, hex);
+       while (doc->views)
+               hex_document_remove_view(doc, GTK_WIDGET(doc->views->data));
 
-       G_OBJECT_CLASS (parent_class)->finalize (obj);
+       G_OBJECT_CLASS(hex_document_parent_class)->finalize (obj);
 }
 
 static void
-hex_document_real_changed(HexDocument *doc, gpointer change_data,
+hex_document_real_changed (HexDocument *doc, gpointer change_data,
                                                  gboolean push_undo)
 {
        if(push_undo && doc->undo_max > 0)
@@ -328,141 +352,82 @@ hex_document_class_init (HexDocumentClass *klass)
 {
        GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
        
-       parent_class = g_type_class_peek_parent(klass);
-       
        gobject_class->finalize = hex_document_finalize;
        
-       klass->document_changed = hex_document_real_changed;
-       klass->undo = hex_document_real_undo;
-       klass->redo = hex_document_real_redo;
-       klass->undo_stack_forget = NULL;
-       klass->file_name_changed = NULL;
-
-       hex_signals[DOCUMENT_CHANGED] = 
-               g_signal_new ("document-changed",
-                                         G_TYPE_FROM_CLASS(gobject_class),
-                                         G_SIGNAL_RUN_FIRST,
-                                         G_STRUCT_OFFSET (HexDocumentClass, document_changed),
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         G_TYPE_NONE,
-                                         2, G_TYPE_POINTER, G_TYPE_BOOLEAN);
+       hex_signals[DOCUMENT_CHANGED] =
+               g_signal_new_class_handler ("document-changed",
+                               G_OBJECT_CLASS_TYPE (gobject_class),
+                               G_SIGNAL_RUN_FIRST,
+                               G_CALLBACK(hex_document_real_changed),
+                               NULL, NULL, NULL,
+                               G_TYPE_NONE,
+                               2, G_TYPE_POINTER, G_TYPE_BOOLEAN);
+
        hex_signals[UNDO] = 
-               g_signal_new ("undo",
-                                         G_TYPE_FROM_CLASS(gobject_class),
-                                         G_SIGNAL_RUN_FIRST,
-                                         G_STRUCT_OFFSET (HexDocumentClass, undo),
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         G_TYPE_NONE, 0);
+               g_signal_new_class_handler ("undo",
+                               G_OBJECT_CLASS_TYPE (gobject_class),
+                               G_SIGNAL_RUN_FIRST,
+                               G_CALLBACK(hex_document_real_undo),
+                               NULL, NULL, NULL,
+                               G_TYPE_NONE,
+                               0);
+
        hex_signals[REDO] = 
-               g_signal_new ("redo",
-                                         G_TYPE_FROM_CLASS(gobject_class),
-                                         G_SIGNAL_RUN_FIRST,
-                                         G_STRUCT_OFFSET (HexDocumentClass, redo),
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         G_TYPE_NONE, 0);
+               g_signal_new_class_handler ("redo",
+                               G_OBJECT_CLASS_TYPE (gobject_class),
+                               G_SIGNAL_RUN_FIRST,
+                               G_CALLBACK(hex_document_real_redo),
+                               NULL, NULL, NULL,
+                               G_TYPE_NONE,
+                               0);
+
        hex_signals[UNDO_STACK_FORGET] = 
-               g_signal_new ("undo_stack_forget",
-                                         G_TYPE_FROM_CLASS(gobject_class),
-                                         G_SIGNAL_RUN_FIRST,
-                                         G_STRUCT_OFFSET (HexDocumentClass, undo_stack_forget),
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         G_TYPE_NONE, 0);
+               g_signal_new_class_handler ("undo_stack_forget",
+                               G_OBJECT_CLASS_TYPE (gobject_class),
+                               G_SIGNAL_RUN_FIRST,
+                               NULL,
+                               NULL, NULL, NULL,
+                               G_TYPE_NONE,
+                               0);
 
        hex_signals[FILE_NAME_CHANGED] = 
-               g_signal_new ("file-name-changed",
-                                         G_TYPE_FROM_CLASS(gobject_class),
-                                         G_SIGNAL_RUN_FIRST,
-                                         G_STRUCT_OFFSET (HexDocumentClass, file_name_changed),
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         G_TYPE_NONE, 0);
+               g_signal_new_class_handler ("file-name-changed",
+                               G_OBJECT_CLASS_TYPE (gobject_class),
+                               G_SIGNAL_RUN_FIRST,
+                               NULL,
+                               NULL, NULL, NULL,
+                               G_TYPE_NONE,
+                               0);
 
        hex_signals[FILE_SAVED] =
-               g_signal_new ("file-saved",
-                                         G_TYPE_FROM_CLASS(gobject_class),
-                                         G_SIGNAL_RUN_FIRST,
-                                         G_STRUCT_OFFSET (HexDocumentClass, file_saved),
-                                         NULL,
-                                         NULL,
-                                         NULL,
-                                         G_TYPE_NONE, 0);
+               g_signal_new_class_handler ("file-saved",
+                               G_OBJECT_CLASS_TYPE (gobject_class),
+                               G_SIGNAL_RUN_FIRST,
+                               NULL,
+                               NULL, NULL, NULL,
+                               G_TYPE_NONE,
+                               0);
 }
 
 static void
 hex_document_init (HexDocument *doc)
 {
-       doc->buffer = NULL;
-       doc->buffer_size = 0;
-       doc->file_size = 0;
-       doc->gap_pos = NULL;
-       doc->gap_size = 0;
-       doc->changed = FALSE;
-       doc->undo_stack = NULL;
-       doc->undo_top = NULL;
-       doc->undo_depth = 0;
        doc->undo_max = DEFAULT_UNDO_DEPTH;
-}
-
-/* TODO - reimplement using modern macros. */
-GType
-hex_document_get_type (void)
-{
-       static GType doc_type = 0;
-       
-       if (!doc_type) {
-               static const GTypeInfo doc_info = {
-                       sizeof (HexDocumentClass),
-                       NULL,           /* base_init */
-                       NULL,           /* base_finalize */
-                       (GClassInitFunc)(void (*)(void)) hex_document_class_init,
-                       NULL,           /* class_finalize */
-                       NULL,           /* class_data */
-                       sizeof (HexDocument),
-                       0,
-                       (GInstanceInitFunc)(void (*)(void)) hex_document_init
-               };
-       
-               doc_type = g_type_register_static (G_TYPE_OBJECT,
-                               "HexDocument",
-                               &doc_info,
-                               0);     
-       }
-
-       return doc_type;
-}
-
-
-/*-------- public API starts here --------*/
-
-
-HexDocument *
-hex_document_new()
-{
-       HexDocument *doc;
-
-       doc = HEX_DOCUMENT (g_object_new (hex_document_get_type(), NULL));
-       g_return_val_if_fail (doc != NULL, NULL);
-
        doc->file_name = NULL;
-
        doc->gap_size = 100;
        doc->file_size = 0;
        doc->buffer_size = doc->file_size + doc->gap_size;
        doc->gap_pos = doc->buffer = g_malloc(doc->buffer_size);
-
        doc->basename = g_strdup(_("New document"));
+}
+
+/*-------- public API starts here --------*/
+
 
-       doc_list = g_list_append(doc_list, doc);
-       return doc;
+HexDocument *
+hex_document_new (void)
+{
+       return g_object_new (HEX_TYPE_DOCUMENT, NULL);
 }
 
 HexDocument *
@@ -471,11 +436,14 @@ hex_document_new_from_file(const gchar *name)
        HexDocument *doc;
        char *basename;
 
-       doc = HEX_DOCUMENT (g_object_new (hex_document_get_type(), NULL));
-       g_return_val_if_fail (doc != NULL, NULL);
+       doc = hex_document_new ();
+
+       g_return_val_if_fail (doc, NULL);
 
-       doc->file_name = g_strdup(name);
-       if(get_document_attributes(doc)) {
+       doc->file_name = g_strdup (name);
+
+       if (get_document_attributes (doc))
+       {
                doc->gap_size = 100;
                doc->buffer_size = doc->file_size + doc->gap_size;
                doc->buffer = g_malloc(doc->buffer_size);
@@ -485,12 +453,10 @@ hex_document_new_from_file(const gchar *name)
                doc->basename = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
                g_free (basename);
 
-               if(hex_document_read(doc)) {
-                       doc_list = g_list_append(doc_list, doc);
+               if (hex_document_read (doc))
                        return doc;
-               }
        }
-       g_object_unref(G_OBJECT(doc));
+       g_object_unref (doc);
        
        return NULL;
 }
@@ -1023,7 +989,7 @@ hex_document_find_backward(HexDocument *doc, guint start, char *what,
 }
 
 gboolean
-hex_document_undo(HexDocument *doc)
+hex_document_undo (HexDocument *doc)
 {
        if(doc->undo_top == NULL)
                return FALSE;
@@ -1034,7 +1000,7 @@ hex_document_undo(HexDocument *doc)
 }
 
 static void
-hex_document_real_undo(HexDocument *doc)
+hex_document_real_undo (HexDocument *doc)
 {
        HexChangeData *cd;
        int len;
@@ -1132,12 +1098,6 @@ hex_document_real_redo(HexDocument *doc)
        hex_document_changed(doc, cd, FALSE);
 }
 
-const GList *
-hex_document_get_list()
-{
-       return doc_list;
-}
-
 gboolean
 hex_document_change_file_name (HexDocument *doc, const char *new_file_name)
 {
diff --git a/src/hex-document.h b/src/hex-document.h
index f86334db..35e6500d 100644
--- a/src/hex-document.h
+++ b/src/hex-document.h
@@ -40,20 +40,15 @@
 
 G_BEGIN_DECLS
 
-#define HEX_DOCUMENT_TYPE          (hex_document_get_type())
-#define HEX_DOCUMENT(obj)          G_TYPE_CHECK_INSTANCE_CAST (obj, hex_document_get_type (), HexDocument)
-#define HEX_DOCUMENT_CLASS(klass)  G_TYPE_CHECK_CLASS_CAST (klass, hex_document_get_type (), 
HexDocumentClass)
-#define HEX_IS_DOCUMENT(obj)       G_TYPE_CHECK_INSTANCE_TYPE (obj, hex_document_get_type ())
-
-typedef struct _HexDocument       HexDocument;
-typedef struct _HexDocumentClass  HexDocumentClass;
-typedef struct _HexChangeData     HexChangeData;
+#define HEX_TYPE_DOCUMENT hex_document_get_type ()
+G_DECLARE_FINAL_TYPE (HexDocument, hex_document, HEX, DOCUMENT, GObject)
 
 typedef enum {
        HEX_CHANGE_STRING,
        HEX_CHANGE_BYTE
 } HexChangeType;
 
+typedef struct _HexChangeData HexChangeData;
 struct _HexChangeData
 {
        int start, end;
@@ -66,42 +61,7 @@ struct _HexChangeData
        char v_byte;
 };
 
-struct _HexDocument
-{
-       GObject object;
-
-       GList *views;      /* a list of GtkHex widgets showing this document */
-       
-       char *file_name;
-       char *basename;
-
-       char *buffer;    /* data buffer */
-       char *gap_pos;   /* pointer to the start of insertion gap */
-       int gap_size;     /* insertion gap size */
-       int buffer_size; /* buffer size = file size + gap size */
-       int file_size;   /* real file size */
-
-       gboolean changed;
-
-       GList *undo_stack; /* stack base */
-       GList *undo_top;   /* top of the stack (for redo) */
-       int undo_depth;  /* number of els on stack */
-       int undo_max;    /* max undo depth */
-};
-
-struct _HexDocumentClass
-{
-       GObjectClass parent_class;
-
-       void (*document_changed)(HexDocument *, gpointer, gboolean);
-       void (*undo)(HexDocument *);
-       void (*redo)(HexDocument *);
-       void (*undo_stack_forget)(HexDocument *);
-       void (*file_name_changed)(HexDocument *);
-       void (*file_saved)(HexDocument *);
-};
 
-GType       hex_document_get_type(void);
 HexDocument *hex_document_new(void);
 HexDocument *hex_document_new_from_file(const char *name);
 void        hex_document_set_data(HexDocument *doc, int offset,
@@ -133,7 +93,6 @@ int        hex_document_find_backward(HexDocument *doc, guint start,
                char *what, int len, guint *found);
 void        hex_document_remove_view(HexDocument *doc, GtkWidget *view);
 GtkWidget   *hex_document_add_view(HexDocument *doc);
-const GList *hex_document_get_list(void);
 gboolean    hex_document_is_writable(HexDocument *doc);
 gboolean    hex_document_change_file_name (HexDocument *doc,
                const char *new_file_name);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]