[ghex/gtk4-port: 22/91] gtkhex: further tweaks; started application.ui
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ghex/gtk4-port: 22/91] gtkhex: further tweaks; started application.ui
- Date: Thu, 12 Aug 2021 23:35:09 +0000 (UTC)
commit fa62b1621b72b05137da92531e4ed51423cd94fb
Author: Logan Rathbone <poprocks gmail com>
Date: Fri Jan 8 23:11:16 2021 -0500
gtkhex: further tweaks; started application.ui
(You can test application.ui with STUB.c via 'make STUB'.)
src/STUB.c | 57 ++++++++++++++++-------------
src/application.ui | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gtkhex.c | 59 +++++++++++++++++++++++++-----
3 files changed, 188 insertions(+), 32 deletions(-)
---
diff --git a/src/STUB.c b/src/STUB.c
index 5f01a73e..129ac097 100644
--- a/src/STUB.c
+++ b/src/STUB.c
@@ -1,40 +1,49 @@
+/* vim: colorcolumn=80 tw=4 ts=4
+ */
+
#include <gtkhex.h>
static void
activate (GtkApplication *app,
- gpointer user_data)
+ gpointer user_data)
{
- GtkWidget *window;
- HexDocument *doc;
- GtkWidget *hex;
+ GtkWidget *window;
+ GtkWidget *box;
+ GtkBuilder *builder;
+ GtkWidget *hex;
+ HexDocument *doc;
+
+ (void)user_data; /* unused for now. */
+
+ builder = gtk_builder_new_from_file ("application.ui");
+ doc = hex_document_new_from_file ("main.c");
+ hex = gtk_hex_new (doc);
+ gtk_hex_show_offsets (GTK_HEX(hex), TRUE);
- window = gtk_application_window_new (app);
- gtk_window_set_title (GTK_WINDOW (window), "Window");
- gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
+ box = GTK_WIDGET(gtk_builder_get_object(builder, "child_box"));
+ window = GTK_WIDGET(gtk_builder_get_object(builder, "main_window"));
- doc = hex_document_new_from_file ("main.c");
- hex = gtk_hex_new (doc);
-// gtk_hex_set_geometry (GTK_HEX (hex), 32, 1024);
- gtk_hex_show_offsets (GTK_HEX (hex), TRUE);
- gtk_hex_set_cursor (GTK_HEX(hex), 25);
-// gtk_hex_set_selection (GTK_HEX(hex), 20, 30);
+ gtk_box_append (GTK_BOX(box), hex);
- gtk_window_set_child (GTK_WINDOW (window), hex);
+ gtk_window_set_application (GTK_WINDOW(window), app);
- gtk_widget_show (window);
+ gtk_widget_show (window);
+
+ g_object_unref (builder);
}
int
-main (int argc,
- char **argv)
+main (int argc, char *argv[])
{
- GtkApplication *app;
- int status;
+ GtkApplication *app;
+ int status;
+
+ app = gtk_application_new("org.gtk.example", G_APPLICATION_FLAGS_NONE);
+ g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
+
+ status = g_application_run (G_APPLICATION(app), argc, argv);
- app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
- g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
- status = g_application_run (G_APPLICATION (app), argc, argv);
- g_object_unref (app);
+ g_object_unref(app);
- return status;
+ return status;
}
diff --git a/src/application.ui b/src/application.ui
new file mode 100644
index 00000000..f4be1394
--- /dev/null
+++ b/src/application.ui
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vim:ts=4 sw=4
+-->
+
+<!-- just a test. -->
+<interface>
+ <menu id="hamburger_menu">
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_Open</attribute>
+ <attribute name="action">ghex.open</attribute>
+ </item>
+ <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>
+ </item>
+ </section>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">_About GHex</attribute>
+ <attribute name="action">app.about</attribute>
+ </item>
+ </section>
+ </menu>
+
+ <object class="GtkApplicationWindow" id="main_window">
+ <property name="title" translatable="yes">GHex</property>
+ <property name="default-width">800</property>
+ <property name="default-height">600</property>
+ <!-- FIXME - this is a standard XDG icon name as a placeholder for now.
+ Replace with the GHex icon. -->
+ <property name="icon-name">document-open</property>
+
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+
+ <child>
+ <object class="GtkHeaderBar" id="headerbar">
+ <property name="show-title-buttons">false</property>
+
+ <child>
+ <object class="GtkButton">
+ <property name="valign">center</property>
+ <property
name="icon-name">document-open</property>
+ <property
name="action-name">ghex.open</property>
+ <property name="tooltip-text"
translatable="yes">Open a file for hex editing</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkButton">
+ <property name="valign">center</property>
+ <property
name="icon-name">document-save</property>
+ <property
name="action-name">ghex.save</property>
+ <property name="tooltip-text"
translatable="yes">Save file to disk</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkButton">
+ <property name="valign">center</property>
+ <property
name="icon-name">edit-undo</property>
+ <property
name="action-name">ghex.undo</property>
+ <property name="tooltip-text"
translatable="yes">Undo last action</property>
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkButton">
+ <property name="valign">center</property>
+ <property
name="icon-name">edit-redo</property>
+ <property
name="action-name">ghex.redo</property>
+ <property name="tooltip-text"
translatable="yes">Redo last action</property>
+ </object>
+ </child>
+
+ <child type="end">
+ <object class="GtkMenuButton"
id="hamburger_menu_button">
+ <property name="valign">center</property>
+ <property
name="menu-model">hamburger_menu</property>
+ <property
name="icon-name">open-menu-symbolic</property>
+ <accessibility>
+ <property name="label"
translatable="yes">Main menu</property>
+ </accessibility>
+ </object>
+ </child>
+
+ </object>
+ </child>
+
+ <child>
+ <object class="GtkBox" id="child_box">
+ <property name="homogeneous">true</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/src/gtkhex.c b/src/gtkhex.c
index 98c6330c..0bbe8255 100644
--- a/src/gtkhex.c
+++ b/src/gtkhex.c
@@ -1848,6 +1848,11 @@ key_press_cb (GtkEventControllerKey *controller,
}
switch(keyval) {
+ // TEST
+ case GDK_KEY_F12:
+ g_debug("F12 PRESSED - TESTING CLIPBOARD COPY");
+ gtk_hex_copy_to_clipboard (gh);
+ break;
case GDK_KEY_BackSpace:
if(gh->cursor_pos > 0) {
hex_document_set_data(gh->document, gh->cursor_pos - 1,
@@ -2076,15 +2081,20 @@ static void gtk_hex_real_data_changed(GtkHex *gh, gpointer data) {
}
static void
-bytes_changed(GtkHex *gh, gint start, gint end)
+bytes_changed(GtkHex *gh, int start, int end)
{
- gint start_line = start/gh->cpl - gh->top_line;
- gint end_line = end/gh->cpl - gh->top_line;
+ int start_line;
+ int end_line;
- g_return_if_fail(end_line >=0 && start_line <= gh->vis_lines);
+ g_return_if_fail(gh->cpl); /* check for divide-by-zero issues */
+ start_line = start/gh->cpl - gh->top_line;
start_line = MAX(start_line, 0);
+ end_line = end/gh->cpl - gh->top_line;
+
+ g_return_if_fail(end_line >=0 && start_line <= gh->vis_lines);
+
invalidate_hex_lines (gh, start_line, end_line);
invalidate_ascii_lines (gh, start_line, end_line);
@@ -2411,12 +2421,42 @@ void gtk_hex_paste_from_clipboard(GtkHex *gh)
g_signal_emit_by_name(G_OBJECT(gh), "paste-clipboard");
}
-static void gtk_hex_real_copy_to_clipboard(GtkHex *gh)
+static void
+gtk_hex_real_copy_to_clipboard (GtkHex *gh)
{
- // LAR - REWRITE FOR GTK4
- (void)gh;
+ GtkWidget *widget = GTK_WIDGET(gh);
+ GdkClipboard *clipboard;
+ int start_pos, end_pos;
+
+ TEST_DEBUG_FUNCTION_START
+
+ start_pos = MIN(gh->selection.start, gh->selection.end);
+ end_pos = MAX(gh->selection.start, gh->selection.end);
+
+ clipboard = gtk_widget_get_clipboard (widget);
- NOT_IMPLEMENTED
+ if(start_pos != end_pos) {
+ char *text;
+ char *cp;
+
+ text = hex_document_get_data(gh->document,
+ start_pos,
+ end_pos - start_pos);
+
+ // TEST
+
+ for (cp = text; *cp != '\0'; ++cp)
+ {
+ if (! is_displayable(*cp))
+ *cp = '?';
+ }
+
+ printf("%s\n", text);
+
+ gdk_clipboard_set_text (clipboard, text);
+
+ g_free(text);
+ }
#if 0
gint start_pos;
@@ -3022,6 +3062,9 @@ gtk_hex_init(GtkHex *gh)
gtk_widget_set_can_focus (widget, TRUE);
gtk_widget_set_focusable (widget, TRUE);
+ gtk_widget_set_vexpand (widget, TRUE);
+ gtk_widget_set_hexpand (widget, TRUE);
+
// API CHANGE - FIXME REWRITE.
// gtk_widget_set_events(GTK_WIDGET(gh), GDK_KEY_PRESS_MASK);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]