[ghex/gtk4-port: 25/91] (Heavily) WIP on new application window &c.




commit 8c47b313eb73c50ddac27afb741ff86f98e64137
Author: Logan Rathbone <poprocks gmail com>
Date:   Tue Jan 12 10:19:26 2021 -0500

    (Heavily) WIP on new application window &c.
    
    Quite frankly I'm committing so I can easily pick this work up on
    another machine. It's a good snapshot of some progress though, including
    implementing objects for a new application window, conversions pane, and
    some actions starting to be implemented.

 src/Makefile                                       |  15 +-
 src/STUB.c                                         |  64 +++-
 src/conversions-pane.c                             | 122 +++++++
 src/conversions-pane.h                             |  15 +
 src/conversions-pane.ui                            | 394 +++++++++++++++++++++
 src/ghex-application-window.c                      | 167 +++++++++
 src/ghex-application-window.h                      |  18 +
 src/{application.ui => ghex-application-window.ui} | 118 +++---
 src/ghex.gresource.xml                             |  11 +-
 src/gtkhex.c                                       |   7 +-
 src/gtkhex.h                                       |   4 -
 11 files changed, 863 insertions(+), 72 deletions(-)
---
diff --git a/src/Makefile b/src/Makefile
index e6244474..3462c81d 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -8,9 +8,16 @@ CFLAGS=-Wall -Wextra -std=c11 -pedantic \
        -I../build -I. \
        $(DEBUG)
 
-STUB: gtkhex.o hex-document.o
+.PHONY: clean compile-resources
 
-clean:
-       rm -f STUB *.o
+STUB: gtkhex.o hex-document.o ghex-application-window.o conversions-pane.o resources.o
+
+compile-resources:
+       glib-compile-resources ghex.gresource.xml --target=resources.c --generate-source
 
-.PHONY: clean
+resources.o:
+       make compile-resources
+       $(CC) resources.c -c -o resources.o $(CFLAGS)
+
+clean:
+       rm -f STUB *.o resources.c
diff --git a/src/STUB.c b/src/STUB.c
index c48817c3..92b80415 100644
--- a/src/STUB.c
+++ b/src/STUB.c
@@ -1,41 +1,95 @@
-/* vim: colorcolumn=80 tw=4 ts=4
+/* vim: colorcolumn=80 tw=4 sw=4
  */
 
 #include <gtkhex.h>
+#include "ghex-application-window.h"
+#include "conversions-pane.h"
 
 static void
 activate (GtkApplication *app,
                                gpointer user_data)
 {
-       GtkAdjustment *adj;
        GtkWidget *window;
-       GtkWidget *box;
+       GtkWidget *hex;
+       HexDocument *doc;
+
+       window = ghex_application_window_new ();
+       doc = hex_document_new_from_file ("main.c");
+       hex = gtk_hex_new (doc);
+       gtk_hex_show_offsets (GTK_HEX(hex), TRUE);
+
+       ghex_application_window_add_hex (GHEX_APPLICATION_WINDOW(window), GTK_HEX(hex));
+
+
+#if 0
        GtkBuilder *builder;
+       GtkWidget *window;
+       GtkWidget *box;
+       GtkBox *conversions_box;
+       GtkWidget *conversions_pane;
        GtkWidget *hex;
+       GtkHeaderBar *headerbar;
+       GtkWidget *label;
+       GtkStatusbar *statusbar;
+       guint id;
+       GtkAdjustment *adj;
        GtkScrollbar *scrollbar;
+       GtkStyleContext *context;
+       GtkCssProvider *provider;
        HexDocument *doc;
 
        (void)user_data;        /* unused for now. */
 
-       builder = gtk_builder_new_from_file ("application.ui");
+       builder = gtk_builder_new_from_resource ("/org/gnome/ghex/application.ui");
        doc = hex_document_new_from_file ("main.c");
        hex = gtk_hex_new (doc);
        gtk_hex_show_offsets (GTK_HEX(hex), TRUE);
 
        box = GTK_WIDGET(gtk_builder_get_object (builder, "child_box"));
+       conversions_box = GTK_BOX(gtk_builder_get_object (builder, "conversions_box"));
+       gtk_widget_set_name (GTK_WIDGET(conversions_box), "conversions_box");
        window = GTK_WIDGET(gtk_builder_get_object (builder, "main_window"));
        scrollbar = GTK_SCROLLBAR(gtk_builder_get_object (builder, "scrollbar"));
+       headerbar = GTK_HEADER_BAR (gtk_builder_get_object (builder, "headerbar"));
+       statusbar = GTK_STATUSBAR (gtk_builder_get_object (builder, "statusbar"));
+
+       conversions_pane = conversions_pane_new ();
+
+       label = gtk_label_new (NULL);
+
+       provider = gtk_css_provider_new ();
+       gtk_css_provider_load_from_path (provider, "style.css");
+       context = gtk_widget_get_style_context (GTK_WIDGET(conversions_box));
+       gtk_style_context_add_provider (context,
+                                       GTK_STYLE_PROVIDER(provider),
+                                       GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
+       context = gtk_widget_get_style_context (label);
+       gtk_style_context_add_class (context, "title");
+       gtk_label_set_markup (GTK_LABEL(label), "main.c");
+
+       gtk_header_bar_set_title_widget (headerbar, label);
+       
+       id = gtk_statusbar_get_context_id (statusbar, "offset");
+       gtk_statusbar_push (statusbar, id, "Offset: 0x0");
+
        adj = gtk_hex_get_adjustment (GTK_HEX(hex));
 
        gtk_scrollbar_set_adjustment (scrollbar, adj);
 
+       gtk_box_append (conversions_box, conversions_pane);
        gtk_box_prepend (GTK_BOX(box), hex);
+#endif
+
 
        gtk_window_set_application (GTK_WINDOW(window), app);
 
-       gtk_widget_show (window);
+       gtk_window_present (GTK_WINDOW(window));
+//     gtk_widget_show (window);
 
+#if 0
        g_object_unref (builder);
+#endif
 }
 
 int
diff --git a/src/conversions-pane.c b/src/conversions-pane.c
new file mode 100644
index 00000000..6980206b
--- /dev/null
+++ b/src/conversions-pane.c
@@ -0,0 +1,122 @@
+/* vim: ts=4 sw=4 colorcolumn=80
+ */
+
+#include "conversions-pane.h"
+
+struct _ConversionsPane
+{
+       GtkWidget parent_instance;
+
+/*
+ * for i in `cat conversions-pane.ui |grep -i 'id=' |sed -e 's,^\s*,,g' |sed -e 's,.*id=",,' |sed -e 
's,">,,'`; do echo $i >> tmp.txt; done
+ */
+
+/* for i in `cat tmp.txt`; do echo GtkWidget *${i}; done
+ */
+       GtkWidget *conversions_pane;
+       GtkWidget *signed_8bit_label;
+       GtkWidget *signed_32bit_label;
+       GtkWidget *signed_hexadecimal_label;
+       GtkWidget *unsigned_8bit_label;
+       GtkWidget *unsigned_32bit_label;
+       GtkWidget *octal_label;
+       GtkWidget *signed_16bit_label;
+       GtkWidget *signed_64bit_label;
+       GtkWidget *binary_label;
+       GtkWidget *unsigned_16bit_label;
+       GtkWidget *unsigned_64bit_label;
+       GtkWidget *float_32bit_label;
+       GtkWidget *float_64bit_label;
+       GtkWidget *stream_length_spin_button;
+       GtkWidget *little_endian_check_button;
+       GtkWidget *unsigned_and_float_as_hex_check_button;
+};
+
+G_DEFINE_TYPE (ConversionsPane, conversions_pane,
+               GTK_TYPE_WIDGET)
+
+static void
+conversions_pane_init(ConversionsPane *self)
+{
+       GtkWidget *widget = GTK_WIDGET(self);
+       GtkCssProvider *provider;
+       GtkStyleContext *context;
+
+       gtk_widget_init_template (widget);
+
+       /* css */
+
+       provider = gtk_css_provider_new ();
+       gtk_css_provider_load_from_path (provider, "style.css");
+       context = gtk_widget_get_style_context (widget);
+       gtk_style_context_add_provider (context,
+                       GTK_STYLE_PROVIDER(provider),
+                       GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+}
+
+static void
+conversions_pane_dispose(GObject *object)
+{
+       ConversionsPane *self = CONVERSIONS_PANE(object);
+
+       /* Boilerplate: chain up
+        */
+       G_OBJECT_CLASS(conversions_pane_parent_class)->dispose(object);
+}
+
+static void
+conversions_pane_finalize(GObject *gobject)
+{
+       /* here, you would free stuff. I've got nuthin' for ya. */
+
+       /* --- */
+
+       /* Boilerplate: chain up
+        */
+       G_OBJECT_CLASS(conversions_pane_parent_class)->finalize(gobject);
+}
+
+static void
+conversions_pane_class_init(ConversionsPaneClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS(klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
+
+       /* <boilerplate> */
+       object_class->dispose = conversions_pane_dispose;
+       object_class->finalize = conversions_pane_finalize;
+       /* </boilerplate> */
+
+       gtk_widget_class_set_layout_manager_type (widget_class,
+                                       GTK_TYPE_BOX_LAYOUT);
+
+       gtk_widget_class_set_template_from_resource (widget_class,
+                                       "/org/gnome/ghex/conversions-pane.ui");
+
+       /* 
+        * for i in `cat tmp.txt`; do echo "gtk_widget_class_bind_template_child (widget_class, 
ConversionsPane, ${i});"; done
+        */
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, conversions_pane);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, signed_8bit_label);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, signed_32bit_label);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, signed_hexadecimal_label);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, unsigned_8bit_label);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, unsigned_32bit_label);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, octal_label);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, signed_16bit_label);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, signed_64bit_label);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, binary_label);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, unsigned_16bit_label);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, unsigned_64bit_label);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, float_32bit_label);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, float_64bit_label);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, stream_length_spin_button);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, little_endian_check_button);
+       gtk_widget_class_bind_template_child (widget_class, ConversionsPane, 
unsigned_and_float_as_hex_check_button);
+}
+
+GtkWidget *
+conversions_pane_new(void)
+{
+       return g_object_new(CONVERSIONS_TYPE_PANE, NULL);
+}
diff --git a/src/conversions-pane.h b/src/conversions-pane.h
new file mode 100644
index 00000000..d6c3ef15
--- /dev/null
+++ b/src/conversions-pane.h
@@ -0,0 +1,15 @@
+/* vim: colorcolumn=80 tw=4 ts=4
+ */
+
+#ifndef CONVERSIONS_PANE_H
+#define CONVERSIONS_PANE_H
+
+#include <gtk/gtk.h>
+
+#define CONVERSIONS_TYPE_PANE (conversions_pane_get_type ())
+G_DECLARE_FINAL_TYPE (ConversionsPane, conversions_pane, CONVERSIONS, PANE,
+                               GtkWidget)
+
+GtkWidget *conversions_pane_new(void);
+
+#endif
diff --git a/src/conversions-pane.ui b/src/conversions-pane.ui
new file mode 100644
index 00000000..a50bf868
--- /dev/null
+++ b/src/conversions-pane.ui
@@ -0,0 +1,394 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- vim: ts=4 sw=4 foldmethod=indent
+-->
+
+<interface>
+       <requires lib="gtk" version="4.0"/>
+
+       <template class="ConversionsPane">
+               <child>
+                       <object class="GtkBox" id="conversions_pane">
+                               <property name="can_focus">0</property>
+                               <property name="orientation">vertical</property>
+                               <property name="spacing">24</property>
+                               <child>
+                                       <object class="GtkGrid">
+                                               <property name="can_focus">0</property>
+                                               <property name="hexpand">1</property>
+                                               <property name="row_spacing">12</property>
+                                               <property name="column_spacing">18</property>
+                                               <property name="column_homogeneous">1</property>
+                                               <child>
+                                                       <object class="GtkBox">
+                                                               <property name="can_focus">0</property>
+                                                               <child>
+                                                                       <object class="GtkLabel">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property name="label" 
translatable="yes">Signed 8 bit:</property>
+                                                                       </object>
+                                                               </child>
+                                                               <child>
+                                                                       <object class="GtkLabel" 
id="signed_8bit_label">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property 
name="halign">end</property>
+                                                                               <property 
name="hexpand">1</property>
+                                                                               <property name="label" 
translatable="no">&lt;tt&gt;0&lt;/tt&gt;</property>
+                                                                               <property 
name="use_markup">1</property>
+                                                                               <property 
name="selectable">1</property>
+                                                                       </object>
+                                                               </child>
+                                                               <layout>
+                                                                       <property name="column">0</property>
+                                                                       <property name="row">0</property>
+                                                               </layout>
+                                                       </object>
+                                               </child>
+                                               <child>
+                                                       <object class="GtkBox">
+                                                               <property name="can_focus">0</property>
+                                                               <child>
+                                                                       <object class="GtkLabel">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property name="label" 
translatable="yes">Signed 32 bit:</property>
+                                                                       </object>
+                                                               </child>
+                                                               <child>
+                                                                       <object class="GtkLabel" 
id="signed_32bit_label">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property 
name="halign">end</property>
+                                                                               <property 
name="hexpand">1</property>
+                                                                               <property name="label" 
translatable="no">&lt;tt&gt;0&lt;/tt&gt;</property>
+                                                                               <property 
name="use_markup">1</property>
+                                                                               <property 
name="selectable">1</property>
+                                                                       </object>
+                                                               </child>
+                                                               <layout>
+                                                                       <property name="column">1</property>
+                                                                       <property name="row">0</property>
+                                                               </layout>
+                                                       </object>
+                                               </child>
+                                               <child>
+                                                       <object class="GtkBox">
+                                                               <property name="can_focus">0</property>
+                                                               <child>
+                                                                       <object class="GtkLabel">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property name="label" 
translatable="yes">Hexadecimal:</property>
+                                                                       </object>
+                                                               </child>
+                                                               <child>
+                                                                       <object class="GtkLabel" 
id="signed_hexadecimal_label">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property 
name="halign">end</property>
+                                                                               <property 
name="hexpand">1</property>
+                                                                               <property name="label" 
translatable="no">&lt;tt&gt;0&lt;/tt&gt;</property>
+                                                                               <property 
name="use_markup">1</property>
+                                                                               <property 
name="selectable">1</property>
+                                                                       </object>
+                                                               </child>
+                                                               <layout>
+                                                                       <property name="column">2</property>
+                                                                       <property name="row">0</property>
+                                                               </layout>
+                                                       </object>
+                                               </child>
+                                               <child>
+                                                       <object class="GtkBox">
+                                                               <property name="can_focus">0</property>
+                                                               <child>
+                                                                       <object class="GtkLabel">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property name="label" 
translatable="yes">Unsigned 8 bit:</property>
+                                                                       </object>
+                                                               </child>
+                                                               <child>
+                                                                       <object class="GtkLabel" 
id="unsigned_8bit_label">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property 
name="halign">end</property>
+                                                                               <property 
name="hexpand">1</property>
+                                                                               <property name="label" 
translatable="no">&lt;tt&gt;0&lt;/tt&gt;</property>
+                                                                               <property 
name="use_markup">1</property>
+                                                                               <property 
name="selectable">1</property>
+                                                                       </object>
+                                                               </child>
+                                                               <layout>
+                                                                       <property name="column">0</property>
+                                                                       <property name="row">1</property>
+                                                               </layout>
+                                                       </object>
+                                               </child>
+                                               <child>
+                                                       <object class="GtkBox">
+                                                               <property name="can_focus">0</property>
+                                                               <child>
+                                                                       <object class="GtkLabel">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property name="label" 
translatable="yes">Unsigned 32 bit:</property>
+                                                                       </object>
+                                                               </child>
+                                                               <child>
+                                                                       <object class="GtkLabel" 
id="unsigned_32bit_label">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property 
name="halign">end</property>
+                                                                               <property 
name="hexpand">1</property>
+                                                                               <property name="label" 
translatable="no">&lt;tt&gt;0&lt;/tt&gt;</property>
+                                                                               <property 
name="use_markup">1</property>
+                                                                               <property 
name="selectable">1</property>
+                                                                       </object>
+                                                               </child>
+                                                               <layout>
+                                                                       <property name="column">1</property>
+                                                                       <property name="row">1</property>
+                                                               </layout>
+                                                       </object>
+                                               </child>
+                                               <child>
+                                                       <object class="GtkBox">
+                                                               <property name="can_focus">0</property>
+                                                               <child>
+                                                                       <object class="GtkLabel">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property name="label" 
translatable="yes">Octal:</property>
+                                                                       </object>
+                                                               </child>
+                                                               <child>
+                                                                       <object class="GtkLabel" 
id="octal_label">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property 
name="halign">end</property>
+                                                                               <property 
name="hexpand">1</property>
+                                                                               <property name="label" 
translatable="no">&lt;tt&gt;0&lt;/tt&gt;</property>
+                                                                               <property 
name="use_markup">1</property>
+                                                                               <property 
name="selectable">1</property>
+                                                                       </object>
+                                                               </child>
+                                                               <layout>
+                                                                       <property name="column">2</property>
+                                                                       <property name="row">1</property>
+                                                               </layout>
+                                                       </object>
+                                               </child>
+                                               <child>
+                                                       <object class="GtkBox">
+                                                               <property name="can_focus">0</property>
+                                                               <child>
+                                                                       <object class="GtkLabel">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property name="label" 
translatable="yes">Signed 16 bit:</property>
+                                                                       </object>
+                                                               </child>
+                                                               <child>
+                                                                       <object class="GtkLabel" 
id="signed_16bit_label">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property 
name="halign">end</property>
+                                                                               <property 
name="hexpand">1</property>
+                                                                               <property name="label" 
translatable="no">&lt;tt&gt;0&lt;/tt&gt;</property>
+                                                                               <property 
name="use_markup">1</property>
+                                                                               <property 
name="selectable">1</property>
+                                                                       </object>
+                                                               </child>
+                                                               <layout>
+                                                                       <property name="column">0</property>
+                                                                       <property name="row">2</property>
+                                                               </layout>
+                                                       </object>
+                                               </child>
+                                               <child>
+                                                       <object class="GtkBox">
+                                                               <property name="can_focus">0</property>
+                                                               <child>
+                                                                       <object class="GtkLabel">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property name="label" 
translatable="yes">Signed 64 bit:</property>
+                                                                       </object>
+                                                               </child>
+                                                               <child>
+                                                                       <object class="GtkLabel" 
id="signed_64bit_label">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property 
name="halign">end</property>
+                                                                               <property 
name="hexpand">1</property>
+                                                                               <property name="label" 
translatable="no">&lt;tt&gt;0&lt;/tt&gt;</property>
+                                                                               <property 
name="use_markup">1</property>
+                                                                               <property 
name="selectable">1</property>
+                                                                       </object>
+                                                               </child>
+                                                               <layout>
+                                                                       <property name="column">1</property>
+                                                                       <property name="row">2</property>
+                                                               </layout>
+                                                       </object>
+                                               </child>
+                                               <child>
+                                                       <object class="GtkBox">
+                                                               <property name="can_focus">0</property>
+                                                               <child>
+                                                                       <object class="GtkLabel">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property name="label" 
translatable="yes">Binary:</property>
+                                                                       </object>
+                                                               </child>
+                                                               <child>
+                                                                       <object class="GtkLabel" 
id="binary_label">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property 
name="halign">end</property>
+                                                                               <property 
name="hexpand">1</property>
+                                                                               <property name="label" 
translatable="no">&lt;tt&gt;0&lt;/tt&gt;</property>
+                                                                               <property 
name="use_markup">1</property>
+                                                                               <property 
name="selectable">1</property>
+                                                                       </object>
+                                                               </child>
+                                                               <layout>
+                                                                       <property name="column">2</property>
+                                                                       <property name="row">2</property>
+                                                               </layout>
+                                                       </object>
+                                               </child>
+                                               <child>
+                                                       <object class="GtkBox">
+                                                               <property name="can_focus">0</property>
+                                                               <child>
+                                                                       <object class="GtkLabel">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property name="label" 
translatable="yes">Unsigned 16 bit:</property>
+                                                                       </object>
+                                                               </child>
+                                                               <child>
+                                                                       <object class="GtkLabel" 
id="unsigned_16bit_label">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property 
name="halign">end</property>
+                                                                               <property 
name="hexpand">1</property>
+                                                                               <property name="label" 
translatable="no">&lt;tt&gt;0&lt;/tt&gt;</property>
+                                                                               <property 
name="use_markup">1</property>
+                                                                               <property 
name="selectable">1</property>
+                                                                       </object>
+                                                               </child>
+                                                               <layout>
+                                                                       <property name="column">0</property>
+                                                                       <property name="row">3</property>
+                                                               </layout>
+                                                       </object>
+                                               </child>
+                                               <child>
+                                                       <object class="GtkBox">
+                                                               <property name="can_focus">0</property>
+                                                               <child>
+                                                                       <object class="GtkLabel">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property name="label" 
translatable="yes">Unsigned 64 bit:</property>
+                                                                       </object>
+                                                               </child>
+                                                               <child>
+                                                                       <object class="GtkLabel" 
id="unsigned_64bit_label">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property 
name="halign">end</property>
+                                                                               <property 
name="hexpand">1</property>
+                                                                               <property name="label" 
translatable="no">&lt;tt&gt;0&lt;/tt&gt;</property>
+                                                                               <property 
name="use_markup">1</property>
+                                                                               <property 
name="selectable">1</property>
+                                                                       </object>
+                                                               </child>
+                                                               <layout>
+                                                                       <property name="column">1</property>
+                                                                       <property name="row">3</property>
+                                                               </layout>
+                                                       </object>
+                                               </child>
+                                               <child>
+                                                       <object class="GtkBox">
+                                                               <property name="can_focus">0</property>
+                                                               <child>
+                                                                       <object class="GtkLabel">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property name="label" 
translatable="yes">Float 32 bit:</property>
+                                                                       </object>
+                                                               </child>
+                                                               <child>
+                                                                       <object class="GtkLabel" 
id="float_32bit_label">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property 
name="halign">end</property>
+                                                                               <property 
name="hexpand">1</property>
+                                                                               <property name="label" 
translatable="no">&lt;tt&gt;0&lt;/tt&gt;</property>
+                                                                               <property 
name="use_markup">1</property>
+                                                                               <property 
name="selectable">1</property>
+                                                                       </object>
+                                                               </child>
+                                                               <layout>
+                                                                       <property name="column">0</property>
+                                                                       <property name="row">4</property>
+                                                               </layout>
+                                                       </object>
+                                               </child>
+                                               <child>
+                                                       <object class="GtkBox">
+                                                               <property name="can_focus">0</property>
+                                                               <child>
+                                                                       <object class="GtkLabel">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property name="label" 
translatable="yes">Float 64 bit:</property>
+                                                                       </object>
+                                                               </child>
+                                                               <child>
+                                                                       <object class="GtkLabel" 
id="float_64bit_label">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property 
name="halign">end</property>
+                                                                               <property 
name="hexpand">1</property>
+                                                                               <property name="label" 
translatable="no">&lt;tt&gt;0&lt;/tt&gt;</property>
+                                                                               <property 
name="use_markup">1</property>
+                                                                               <property 
name="selectable">1</property>
+                                                                       </object>
+                                                               </child>
+                                                               <layout>
+                                                                       <property name="column">1</property>
+                                                                       <property name="row">4</property>
+                                                               </layout>
+                                                       </object>
+                                               </child>
+                                               <child>
+                                                       <object class="GtkBox">
+                                                               <property name="can_focus">0</property>
+                                                               <property name="spacing">6</property>
+                                                               <child>
+                                                                       <object class="GtkLabel">
+                                                                               <property 
name="can_focus">0</property>
+                                                                               <property name="label" 
translatable="yes">Stream length:</property>
+                                                                       </object>
+                                                               </child>
+                                                               <child>
+                                                                       <object class="GtkSpinButton" 
id="stream_length_spin_button">
+                                                                               <property 
name="halign">end</property>
+                                                                               <property 
name="hexpand">1</property>
+                                                                               <property name="text" 
translatable="yes">8</property>
+                                                                       </object>
+                                                               </child>
+                                                               <layout>
+                                                                       <property name="column">2</property>
+                                                                       <property name="row">3</property>
+                                                               </layout>
+                                                       </object>
+                                               </child>
+                                               <child>
+                                                       <placeholder/>
+                                               </child>
+                                       </object>
+                               </child>
+                               <child>
+                                       <object class="GtkBox">
+                                               <property name="can_focus">0</property>
+                                               <property name="homogeneous">1</property>
+                                               <child>
+                                                       <object class="GtkCheckButton" 
id="little_endian_check_button">
+                                                               <property name="label" 
translatable="yes">Show little endian decoding</property>
+                                                       </object>
+                                               </child>
+                                               <child>
+                                                       <object class="GtkCheckButton" 
id="unsigned_and_float_as_hex_check_button">
+                                                               <property name="label" 
translatable="yes">Show unsigned and float as hexadecimal</property>
+                                                       </object>
+                                               </child>
+                                       </object>
+                               </child>
+                       </object>
+               </child>
+       </template>
+</interface>
diff --git a/src/ghex-application-window.c b/src/ghex-application-window.c
new file mode 100644
index 00000000..ef04d8d4
--- /dev/null
+++ b/src/ghex-application-window.c
@@ -0,0 +1,167 @@
+/* vim: ts=4 sw=4 colorcolumn=80
+ */
+
+#include <gtkhex.h>
+#include "ghex-application-window.h"
+#include "conversions-pane.h"
+
+struct _GHexApplicationWindow
+{
+       GtkApplicationWindow parent_instance;
+
+       GtkWidget *conversions_pane;
+       guint statusbar_id;
+       GtkAdjustment *adj;
+/*
+ * for i in `cat ghex-application-window.ui |grep -i 'id=' |sed -e 's,^\s*,,g' |sed -e 's,.*id=",,' |sed -e 
's,">,,'`; do echo $i >> tmp.txt; done
+ */
+
+/* for i in `cat tmp.txt`; do echo GtkWidget *${i}; done
+ */
+       GtkWidget *child_box;
+       GtkWidget *conversions_box;
+       GtkWidget *pane_toggle_button;
+       GtkWidget *statusbar;
+       GtkWidget *scrollbar;
+};
+
+G_DEFINE_TYPE (GHexApplicationWindow, ghex_application_window,
+               GTK_TYPE_APPLICATION_WINDOW)
+
+
+static void
+toggle_conversions (GtkWidget *widget,
+               const char *action_name,
+               GVariant *parameter)
+{
+       GHexApplicationWindow *self = GHEX_APPLICATION_WINDOW(widget);
+
+       (void)parameter, (void)action_name;             /* unused */
+
+       if (gtk_widget_is_visible (self->conversions_box)) {
+               gtk_widget_set_visible (self->conversions_box, FALSE);
+               gtk_button_set_icon_name (GTK_BUTTON(self->pane_toggle_button),
+                               "pan-up-symbolic");
+       } else {
+               gtk_widget_set_visible (self->conversions_box, TRUE);
+               gtk_button_set_icon_name (GTK_BUTTON(self->pane_toggle_button),
+                               "pan-down-symbolic");
+       }
+}
+
+static void
+set_statusbar(GHexApplicationWindow *self, const char *str)
+{
+       guint id = 
+               gtk_statusbar_get_context_id (GTK_STATUSBAR(self->statusbar),
+                               "status");
+
+       gtk_statusbar_push (GTK_STATUSBAR(self->statusbar), id, str);
+}
+
+static void
+ghex_application_window_init(GHexApplicationWindow *self)
+{
+       GtkWidget *widget = GTK_WIDGET(self);
+       GtkStyleContext *context;
+       GtkCssProvider *provider;
+
+       gtk_widget_init_template (widget);
+
+       /* Setup conversions box and pane */
+       self->conversions_pane = conversions_pane_new ();
+       gtk_box_append (GTK_BOX(self->conversions_box), self->conversions_pane);
+       gtk_widget_set_visible (self->conversions_box, FALSE);
+
+       /* CSS - conversions_box */
+       context = gtk_widget_get_style_context (self->conversions_box);
+       provider = gtk_css_provider_new ();
+
+       gtk_css_provider_load_from_data (provider,
+                                                                        "box {\n"
+                                                                        "   padding: 20px;\n"
+                                                                        "}\n", -1);
+
+       /* add the provider to our widget's style context. */
+       gtk_style_context_add_provider (context,
+                                       GTK_STYLE_PROVIDER (provider),
+                                       GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
+
+
+
+       // TEST
+       set_statusbar(self, "Offset: 0x0");
+}
+
+static void
+ghex_application_window_dispose(GObject *object)
+{
+       GHexApplicationWindow *self = GHEX_APPLICATION_WINDOW(object);
+
+       /* Boilerplate: chain up
+        */
+       G_OBJECT_CLASS(ghex_application_window_parent_class)->dispose(object);
+}
+
+static void
+ghex_application_window_finalize(GObject *gobject)
+{
+       /* here, you would free stuff. I've got nuthin' for ya. */
+
+       /* --- */
+
+       /* Boilerplate: chain up
+        */
+       G_OBJECT_CLASS(ghex_application_window_parent_class)->finalize(gobject);
+}
+
+static void
+ghex_application_window_class_init(GHexApplicationWindowClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS(klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
+
+       /* <boilerplate> */
+       object_class->dispose = ghex_application_window_dispose;
+       object_class->finalize = ghex_application_window_finalize;
+       /* </boilerplate> */
+
+       gtk_widget_class_set_template_from_resource (widget_class,
+                                       "/org/gnome/ghex/ghex-application-window.ui");
+
+       gtk_widget_class_install_action (widget_class, "ghex.show-conversions",
+                       NULL,   // GVariant string param_type
+                       toggle_conversions);
+       /* 
+        * for i in `cat tmp.txt`; do echo "gtk_widget_class_bind_template_child (widget_class, 
GHexApplicationWindow, ${i});"; done
+        */
+       gtk_widget_class_bind_template_child (widget_class, GHexApplicationWindow,
+                       child_box);
+       gtk_widget_class_bind_template_child (widget_class, GHexApplicationWindow,
+                       conversions_box);
+       gtk_widget_class_bind_template_child (widget_class, GHexApplicationWindow,
+                       pane_toggle_button);
+       gtk_widget_class_bind_template_child (widget_class, GHexApplicationWindow,
+                       statusbar);
+       gtk_widget_class_bind_template_child (widget_class, GHexApplicationWindow,
+                       scrollbar);
+}
+
+GtkWidget *
+ghex_application_window_new(void)
+{
+       return g_object_new(GHEX_TYPE_APPLICATION_WINDOW, NULL);
+}
+
+void
+ghex_application_window_add_hex(GHexApplicationWindow *self, GtkHex *gh)
+{
+       g_return_if_fail (GTK_IS_HEX(gh));
+
+       gtk_box_prepend (GTK_BOX(self->child_box), GTK_WIDGET(gh));
+
+       /* Setup scrollbar */
+       self->adj = gtk_hex_get_adjustment(gh);
+       gtk_scrollbar_set_adjustment (GTK_SCROLLBAR(self->scrollbar), self->adj);
+}
diff --git a/src/ghex-application-window.h b/src/ghex-application-window.h
new file mode 100644
index 00000000..4c8ce4d2
--- /dev/null
+++ b/src/ghex-application-window.h
@@ -0,0 +1,18 @@
+/* vim: colorcolumn=80 tw=4 ts=4
+ */
+
+#ifndef GHEX_APPLICATION_WINDOW_H
+#define GHEX_APPLICATION_WINDOW_H
+
+#include <gtk/gtk.h>
+
+#define GHEX_TYPE_APPLICATION_WINDOW (ghex_application_window_get_type ())
+G_DECLARE_FINAL_TYPE (GHexApplicationWindow, ghex_application_window,
+                               GHEX, APPLICATION_WINDOW,
+                               GtkApplicationWindow)
+
+GtkWidget *    ghex_application_window_new(void);
+void           ghex_application_window_add_hex(GHexApplicationWindow *self,
+                               GtkHex *gh);
+
+#endif
diff --git a/src/application.ui b/src/ghex-application-window.ui
similarity index 65%
rename from src/application.ui
rename to src/ghex-application-window.ui
index bfcacf43..7a0bc2a3 100644
--- a/src/application.ui
+++ b/src/ghex-application-window.ui
@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
+
 <!-- vim:ts=4 sw=4 foldmethod=indent
 -->
 
@@ -6,10 +7,6 @@
        <menu id="hamburger_menu">
                <!-- "FILE" -->
                <section>
-                       <item>
-                               <attribute name="label" translatable="yes">_Save</attribute>
-                               <attribute name="action">ghex.save</attribute>
-                       </item>
                        <item>
                                <attribute name="label" translatable="yes">Save _As</attribute>
                                <attribute name="action">ghex.save-as</attribute>
@@ -33,12 +30,6 @@
 
                <!-- OTHER COMMON TASKS -->
                <section>
-                       <item>
-                               <attribute name="label" translatable="yes">_Insert Mode</attribute>
-                               <attribute name="icon">insert-text-symbolic</attribute>
-                               <attribute name="action">ghex.insert</attribute>
-                       </item>
-
                        <item>
                                <attribute name="label" translatable="yes">_Go to Byte</attribute>
                                <attribute name="icon">go-jump-symbolic</attribute>
@@ -101,10 +92,10 @@
                </section>
        </menu>
 
-       <object class="GtkApplicationWindow" id="main_window">
+       <template class="GHexApplicationWindow" parent="GtkApplicationWindow">
                <property name="title" translatable="yes">GHex</property>
-               <property name="default-width">800</property>
-               <property name="default-height">600</property>
+               <property name="default-width">600</property>
+               <property name="default-height">400</property>
                <property name="icon-name">org.gnome.GHex</property>
 
                <child type="titlebar">
@@ -140,43 +131,21 @@
                                        </object>
                                </child>
 
-                       </object>
-               </child>
-
-               <child>
-                       <object class="GtkBox">
-                               <property name="orientation">vertical</property>
-
-                               <!-- IF WANNA ADD A TABBED INTERFACE - DO SOMETHING LIKE THIS
-                               <child>
-                                       <object class="GtkNotebook">
-                                               <property name="visible">false</property>
-                                               <child>
-                                                       <object class="GtkLabel" id="notebook-content">
-                                                               <property name="label">Content</property>
-                                                       </object>
-                                               </child>
-                                               <child type="tab">
-                                                       <object class="GtkLabel" id="notebook-tab">
-                                                               <property name="label">Tab</property>
-                                                       </object>
-                                               </child>
-
-                                               <child>
-                                                       <object class="GtkLabel" id="notebook-content2">
-                                                               <property 
name="label">Contentasdfafdf</property>
-                                                       </object>
-                                               </child>
-                                               <child type="tab">
-                                                       <object class="GtkLabel" id="notebook-tab2">
-                                                               <property name="label">Tabasfasd</property>
-                                                       </object>
-                                               </child>
+                               <child type="end">
+                                       <object class="GtkButton">
+                                               <property name="valign">center</property>
+                                               <property name="icon-name">document-save-symbolic</property>
+                                               <property name="action-name">ghex.save</property>
+                                               <property name="tooltip-text" translatable="yes">Save 
document</property>
                                        </object>
                                </child>
-                               -->
+                       </object> <!-- headerbar -->
+               </child> <!-- titlebar -->
 
-                               <child>
+               <child> <!-- main vert gtkbox -->
+                       <object class="GtkBox"> <!-- main vert gtkbox -->
+                               <property name="orientation">vertical</property>
+                               <child> <!-- child_box for gtkhex widget and scrollbar -->
                                        <object class="GtkBox" id="child_box">
                                                <property name="orientation">horizontal</property>
                                                <property name="homogeneous">false</property>
@@ -187,15 +156,60 @@
                                                                <property name="halign">end</property>
                                                        </object>
                                                </child>
+                                       </object> <!-- child_box -->
+                               </child> <!-- child_box -->
+
+                               <child>
+                                       <object class="GtkSeparator">
+                                               <property name="orientation">horizontal</property>
                                        </object>
                                </child>
 
-                               <child>
-                                       <object class="GtkStatusbar" id="statusbar" />
+                               <child> <!-- box just to put the conversions_pane; APPEND -->
+                                       <object class="GtkBox" id="conversions_box" />
                                </child>
-                       </object>
 
-               </child>
-       </object>
+
+                               <child> <!-- status_box -->
+                                       <object class="GtkBox" id="status_box">
+                                               <property name="orientation">horizontal</property>
+                                               <property name="homogeneous">false</property>
+
+
+                                               <child>
+                                                       <object class="GtkStatusbar" id="statusbar">
+                                                               <property name="hexpand">true</property>
+                                                       </object>
+                                               </child>
+
+                                               <child> <!-- insert_mode_button -->
+                                                       <object class="GtkButton" id="insert_mode_button">
+                                                               <property name="valign">center</property>
+                                                               <property name="halign">end</property>
+                                                               <property 
name="icon-name">insert-text-symbolic</property>
+                                                               <property name="has-frame">false</property>
+                                                               <property 
name="action-name">ghex.insert-mode</property>
+                                                               <property name="tooltip-text" 
translatable="yes">Toggle insert mode (add data to file rather than replace existing data)</property>
+                                                       </object>
+                                               </child> <!-- insert_mode_button -->
+
+                                               <!-- pane toggle btn -->
+                                               <child>
+                                                       <object class="GtkButton" id="pane_toggle_button">
+                                                               <property name="valign">center</property>
+                                                               <property name="halign">end</property>
+                                                               <property 
name="icon-name">pan-up-symbolic</property>
+                                                               <property name="has-frame">false</property>
+                                                               <property 
name="action-name">ghex.show-conversions</property>
+                                                               <property name="tooltip-text" 
translatable="yes">Toggle a pane showing various numeric conversions</property>
+                                                       </object>
+                                               </child>
+
+                                       </object> <!-- status_box -->
+                               </child> <!-- status_box -->
+
+                       </object> <!-- main vert gtkbox -->
+               </child> <!-- main vert gtkbox -->
+       </template>
 
 </interface>
diff --git a/src/ghex.gresource.xml b/src/ghex.gresource.xml
index 9ab23a88..ec2534b9 100644
--- a/src/ghex.gresource.xml
+++ b/src/ghex.gresource.xml
@@ -1,6 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
+
+<!-- vim:ts=4 sw=4
+-->
+
 <gresources>
-  <gresource prefix="/org/gnome/ghex">
-    <file preprocess="xml-stripblanks" compressed="true">ghex-ui.xml</file>
-  </gresource>
+       <gresource prefix="/org/gnome/ghex">
+               <file preprocess="xml-stripblanks" compressed="true">ghex-application-window.ui</file>
+               <file preprocess="xml-stripblanks" compressed="true">conversions-pane.ui</file>
+       </gresource>
 </gresources>
diff --git a/src/gtkhex.c b/src/gtkhex.c
index 7d0740ae..000ddc1c 100644
--- a/src/gtkhex.c
+++ b/src/gtkhex.c
@@ -2885,10 +2885,9 @@ gtk_hex_init(GtkHex *gh)
                                                                        CSS_NAME " {\n"
                                                                         "   font-family: Monospace;\n"
                                                                         "   font-size: 12pt;\n"
-//                                      "   border-style: solid;\n"
-//                                      "   border-width: 1px;\n"
-                                        "   padding: 6px;\n"
-//                                                                      "   border-color: black;\n"
+                                        "   padding-left: 12px;\n"
+                                        "   padding-right: 12px;\n"
+// example of how to style a specific widget:
 #if 0
                                                                         "}\n"
                                                                         "#asciidisplay {\n"
diff --git a/src/gtkhex.h b/src/gtkhex.h
index 63442ef6..ca1d18da 100644
--- a/src/gtkhex.h
+++ b/src/gtkhex.h
@@ -39,10 +39,6 @@
 
 G_BEGIN_DECLS
 
-/* Declare GtkHex as a *final* type, meaning you cannot derive from it.
- * This is a change from prior versions of libgtkhex <= 3.x, and is in
- * line with changes made to GTK 4 at large.
- */
 #define GTK_TYPE_HEX (gtk_hex_get_type ())
 G_DECLARE_FINAL_TYPE(GtkHex, gtk_hex, GTK, HEX, GtkWidget)
 


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