[ghex/gtk4-port: 54/91] Cleanup to prepare for 4.alpha.1 proposed MR.
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ghex/gtk4-port: 54/91] Cleanup to prepare for 4.alpha.1 proposed MR.
- Date: Thu, 12 Aug 2021 23:35:11 +0000 (UTC)
commit f50aec9fac855f9d56e6e68f003ec8000504d692
Author: Logan Rathbone <poprocks gmail com>
Date: Mon Jan 25 15:26:43 2021 -0500
Cleanup to prepare for 4.alpha.1 proposed MR.
AUTHORS | 3 -
MAINTAINERS | 8 -
NEWS | 59 +++
README | 24 +-
meson.build | 2 +-
src/Makefile | 24 --
src/chartable.c | 13 +-
src/common-ui.c | 799 +------------------------------------
src/common-ui.h | 6 +
src/configuration.c | 7 +
src/configuration.h | 8 +-
src/context-menu.ui | 20 +
src/converter.c | 16 +-
src/converter.h | 10 +-
src/debug-test.sh | 8 -
src/findreplace.c | 29 +-
src/findreplace.h | 12 +-
src/ghex-application-window.c | 99 +++--
src/ghex-application-window.h | 31 +-
src/ghex-application-window.ui | 22 +-
src/ghex.gresource.xml | 20 +
src/gtkhex-layout-manager.c | 3 -
src/gtkhex-layout-manager.h | 6 +-
src/gtkhex.c | 874 +++++++++++++++++------------------------
src/gtkhex.h | 4 +-
src/hex-dialog.c | 9 +-
src/hex-dialog.h | 7 +
src/hex-document-ui.c | 170 --------
src/hex-document.c | 29 +-
src/hex-document.h | 12 +-
src/main.c | 8 +-
src/meson.build | 6 -
src/preferences.c | 10 +-
src/preferences.h | 8 +-
src/preferences.ui | 22 +-
src/print.c | 3 -
src/print.h | 6 +-
37 files changed, 762 insertions(+), 1635 deletions(-)
---
diff --git a/NEWS b/NEWS
index b7120685..e8e05312 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,62 @@
+==============
+GHex 4.alpha.1
+==============
+
+This is the first alpha GHex release featuring GTK 4 support. It is close to a
+rewrite in most areas, but some areas, such as the hex-document portion of the
+gtkhex library, are more or less straight ports to the new APIs.
+
+As a result, this will require some substantial testing and translation
+updates.
+
+I have tried to write new GHex code in such a way that it is cleaner, easier
+to follow, and more commented than the old code that has been straight-ported.
+I was not able to do as substantial a reorganization of the old code as I
+would have liked for this alpha, but efforts will be ongoing. One of my goals
+is to make this code more hacker-friendly in general, especially to newcomers.
+
+Visibly to the end user, some new features include:
+
+ - More modern and up-to-date look and feel, consistent with the GNOME HIG.
+ - Tabbed interface.
+ - Dark Mode (by default, the GTK system default is used, but can be
+ overridden with a checkbox and a switch in the Preferences dialog).
+ - Custom clipboard data, for less error-prone copying and pasting of binary
+ data; this will fall back to plaintext when unavailable.
+
+I'll break up the known issues into two categories: items I would consider to
+be blockers for beta, and other known issues, which will be earmarked for
+priority after 4.0 (ie, 4.2).
+
+Blockers for Beta:
+ - I believe we require a "New Document" feature. This will not be difficult
+ to implement, but I have not got around to it yet. This will be greatly
+ beneficial, if nothing other than to provide a "scratchpad" for users to copy
+ and paste binary data, while reaping the benefit of the new custom copy/paste
+ data code.
+ - Drag and drop support.
+ - Fixes for lots of UI imperfections, including widgets not grabbing focus
+ when they should; also there are some obvious missing keybindings.
+ - The ability to select a single hex byte is not intuitive; it works, but
+ better visible feedback is needed (this is not different from GHex3, in
+ fairness).
+ - Fix the many compiler warnings that currently ensue, mostly from old code
+ that has been straight-ported.
+
+Other known issues:
+ - Some GTK failed assertion warnings upon closing of tabs without saving, and
+ reordering of tabs. These seem harmless and it is possible some are just
+ papercuts of a GTK 4.0 release, so I only monitor these for now.
+ - The hex-document portion of the gtkhex library is a relic of code written
+ in the 90s, and it shows. Some more sophisticated caching and memory
+ management is in order as opposed to simply calling g_malloc on basically
+ the entirety of the file being opened.
+ - The gtkhex library contains a lot of duplicitous code. In my view
+ substantial function "pairs" should be merged into one, or made more
+ generic. I will work on this post-4.0.
+
+(Logan Rathbone <poprocks gmail com>)
+
===========
GHex 3.18.4
===========
diff --git a/README b/README
index 2c0b885a..c78ff9a7 100644
--- a/README
+++ b/README
@@ -1,13 +1,19 @@
-ghex gtk4-port
-==============
+GHex - 4.alpha.1 - GTK4 port
+============================
-This is an ongoing effort to port the venerable ghex application to GTK4.
+This is an ongoing effort to port the venerable GNOME hex editor, GHex, to
+GTK4.
-Please note that this is NOT working code! Work so far has mostly been on the
-GtkHex widget itself.
+By trying out this pre-release of GHex 4.x, you are in effect volunteering
+yourself to be part of the testing community. Welcome!
-If you are brave enough to test the WIP, first run meson as per usual, and
-then head into the 'src' directory, and run `make STUB`.
+If that is not something you would like to do, you should stick with GHex 3.x
+for the time being.
-You can then run ./STUB or ./debug-test.sh to try out the port of the GtkHex
-widget thus far.
+Please see the NEWS file for important information on this alpha release.
+
+Please report any issues at https://gitlab.gnome.org/GNOME/ghex/issues/ - and
+kindly ensure you report the issue specifically against the "gtk4-port"
+branch.
+
+Thanks in advance for your anticipated understanding.
diff --git a/meson.build b/meson.build
index 171f3762..f8bca0b9 100644
--- a/meson.build
+++ b/meson.build
@@ -1,6 +1,6 @@
project(
'ghex', 'c',
- version: '4.alpha.0',
+ version: '4.alpha.1',
meson_version: '>=0.50.0',
license: 'GPL2'
)
diff --git a/src/chartable.c b/src/chartable.c
index 769372e4..bba0661a 100644
--- a/src/chartable.c
+++ b/src/chartable.c
@@ -3,9 +3,14 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* chartable.c - a window with a character table
- Copyright (C) 1998 - 2004 Free Software Foundation
- Copyright © 2005-2020 FIXME
- Copyright © Logan Rathbone <poprocks gmail com>
+ Copyright © 1998 - 2004 Free Software Foundation
+
+ Copyright © 2005-2020 Various individual contributors, including
+ but not limited to: Jonathon Jongsma, Kalev Lember, who continued
+ to maintain the source code under the licensing terms described
+ herein and below.
+
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
GHex is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -93,7 +98,7 @@ insert_char (GtkTreeView *treeview, GtkTreeModel *model)
(guchar)atoi(g_value_get_string(&value)),
gtk_hex_get_cursor (gh_glob),
gtk_hex_get_insert_mode (gh_glob),
- TRUE); // undoable
+ TRUE); /* undoable */
gtk_hex_set_cursor (gh_glob, gtk_hex_get_cursor (gh_glob) + 1);
}
diff --git a/src/common-ui.c b/src/common-ui.c
index 876cb655..b3a983d4 100644
--- a/src/common-ui.c
+++ b/src/common-ui.c
@@ -4,7 +4,13 @@
/* common-ui.c - Common UI utility functions
Copyright © 1998 - 2004 Free Software Foundation
- Copyright © 2021 Logan Rathbone
+
+ Copyright © 2005-2020 Various individual contributors, including
+ but not limited to: Jonathon Jongsma, Kalev Lember, who continued
+ to maintain the source code under the licensing terms described
+ herein and below.
+
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
GHex is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -29,174 +35,6 @@
/* Not optional. */
#include <config.h>
-#if 0
-static void ghex_print(GtkHex *gh, gboolean preview);
-
-
-guint group_type[3] = {
- GROUP_BYTE,
- GROUP_WORD,
- GROUP_LONG,
-};
-
-gchar *group_type_label[3] = {
- N_("_Bytes"),
- N_("_Words"),
- N_("_Longwords"),
-};
-
-guint search_type = 0;
-gchar *search_type_label[] = {
- N_("hex data"),
- N_("ASCII data"),
-};
-
-void
-cancel_cb(GtkWidget *w, GtkWidget *me)
-{
- gtk_widget_hide(me);
-}
-
-gint
-delete_event_cb(GtkWidget *w, GdkEventAny *e, GtkWindow *win)
-{
- gtk_widget_hide(w);
-
- return TRUE;
-}
-
-gint
-ask_user(GtkMessageDialog *message_box)
-{
- return gtk_dialog_run(GTK_DIALOG(message_box));
-}
-
-GtkWidget *
-create_button(GtkWidget *window, const gchar *type, gchar *text)
-{
- GtkWidget *button, *pixmap, *label, *hbox;
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
-
- label = gtk_label_new_with_mnemonic(text);
-
- pixmap = gtk_image_new_from_stock (type, GTK_ICON_SIZE_BUTTON);
-
- gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, FALSE, 1);
- gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 1);
-
- button = gtk_button_new();
- gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(button));
- gtk_container_add(GTK_CONTAINER(button), hbox);
-
- gtk_widget_show(label);
- gtk_widget_show(pixmap);
- gtk_widget_show(hbox);
-
- return button;
-}
-
-void
-create_dialog_title(GtkWidget *window, gchar *title)
-{
- gchar *full_title;
- GHexWindow *win;
-
- if(!window)
- return;
-
- win = ghex_window_get_active();
-#endif
-
-//#if defined(__GNUC__) && (__GNUC__ > 4)
-//#pragma GCC diagnostic push
-//#pragma GCC diagnostic ignored "-Wformat-nonliteral"
-//#endif
-// if(win != NULL && win->gh != NULL)
-// full_title = g_strdup_printf(title, win->gh->document->path_end);
-// else
-// full_title = g_strdup_printf(title, "");
-//#if defined(__GNUC__) && (__GNUC__ > 4)
-//#pragma GCC diagnostic pop
-//#endif
-
-#if 0
- if(full_title) {
- gtk_window_set_title(GTK_WINDOW(window), full_title);
- g_free(full_title);
- }
-}
-
-/*
- * callbacks for global menus
- */
-void
-about_cb (GtkAction *action,
- GHexWindow *window)
-{
- gchar *copyright;
- gchar *license_translated;
-
- const gchar *authors[] = {
- "Jaka Mo\304\215nik",
- "Chema Celorio",
- "Shivram Upadhyayula",
- "Rodney Dawes",
- "Jonathon Jongsma",
- "Kalev Lember",
- NULL
- };
-
- const gchar *documentation_credits[] = {
- "Jaka Mo\304\215nik",
- "Sun GNOME Documentation Team",
- NULL
- };
-
- const gchar *license[] = {
- N_("This program is free software; you can redistribute it and/or modify "
- "it under the terms of the GNU General Public License as published by "
- "the Free Software Foundation; either version 2 of the License, or "
- "(at your option) any later version."),
- N_("This program is distributed in the hope that it will be useful, "
- "but WITHOUT ANY WARRANTY; without even the implied warranty of "
- "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
- "GNU General Public License for more details."),
- N_("You should have received a copy of the GNU General Public License "
- "along with this program; if not, write to the Free Software Foundation, Inc., "
- "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA")
- };
- license_translated = g_strjoin ("\n\n",
- _(license[0]),
- _(license[1]),
- _(license[2]),
- NULL);
-
- /* Translators: these two strings here indicate the copyright time span,
- e.g. 1998-2018. */
- copyright = g_strdup_printf (_("Copyright © %Id–%Id The GHex authors"), 1998, 2018);
-
- gtk_show_about_dialog (GTK_WINDOW (window),
- "authors", authors,
- "comments", _("A binary file editor"),
- "copyright", copyright,
- "documenters", documentation_credits,
- "license", license_translated,
- "logo-icon-name", "org.gnome.GHex",
- "program-name", "GHex",
- "title", _("About GHex"),
- "translator-credits", _("translator-credits"),
- "version", PACKAGE_VERSION,
- "website", "https://wiki.gnome.org/Apps/Ghex",
- "website-label", _("GHex Website"),
- "wrap-license", TRUE,
- NULL);
-
- g_free (license_translated);
- g_free (copyright);
-}
-#endif
-
void
common_help_cb (GtkWindow *parent)
{
@@ -205,7 +43,6 @@ common_help_cb (GtkWindow *parent)
GDK_CURRENT_TIME);
}
-
void
common_about_cb (GtkWindow *parent)
{
@@ -276,560 +113,13 @@ common_about_cb (GtkWindow *parent)
}
-#if 0
-void
-paste_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win = GHEX_WINDOW(user_data);
-
- if(win->gh)
- gtk_hex_paste_from_clipboard(win->gh);
-}
-
-void
-copy_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win = GHEX_WINDOW(user_data);
-
- if(win->gh)
- gtk_hex_copy_to_clipboard(win->gh);
-}
-
-void
-cut_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win = GHEX_WINDOW(user_data);
-
- if(win->gh)
- gtk_hex_cut_to_clipboard(win->gh);
-}
-
-void
-quit_app_cb (GtkAction *action,
- gpointer user_data)
-{
- const GList *doc_node;
- GHexWindow *win;
- HexDocument *doc;
-
- doc_node = hex_document_get_list();
- while(doc_node) {
- doc = HEX_DOCUMENT(doc_node->data);
- win = ghex_window_find_for_doc(doc);
- if(win && !ghex_window_ok_to_close(win))
- return;
- doc_node = doc_node->next;
- }
- g_application_quit (g_application_get_default ());
-}
-
-void
-save_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win = GHEX_WINDOW(user_data);
- HexDocument *doc;
-
- if(win->gh)
- doc = win->gh->document;
- else
- doc = NULL;
-
- if(doc == NULL)
- return;
-
- if(!hex_document_is_writable(doc)) {
- display_error_dialog (win, _("You don't have the permissions to save the file!"));
- return;
- }
-
- if(!hex_document_write(doc))
- display_error_dialog (win, _("An error occurred while saving file!"));
- else {
- gchar *flash;
- gchar *gtk_file_name;
-
- gtk_file_name = g_filename_to_utf8 (doc->file_name, -1,
- NULL, NULL, NULL);
- flash = g_strdup_printf(_("Saved buffer to file %s"), gtk_file_name);
-
- ghex_window_flash (win, flash);
- g_free(gtk_file_name);
- g_free(flash);
- }
-}
-
-void
-open_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win;
- GtkWidget *file_sel;
- GtkResponseType resp;
-
- win = GHEX_WINDOW(user_data);
-
- file_sel = gtk_file_chooser_dialog_new(_("Select a file to open"),
- GTK_WINDOW(win),
-
GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN,
GTK_RESPONSE_OK,
- NULL);
- gtk_window_set_modal (GTK_WINDOW(file_sel), TRUE);
- gtk_window_set_position (GTK_WINDOW (file_sel), GTK_WIN_POS_MOUSE);
- gtk_widget_show (file_sel);
-
- resp = gtk_dialog_run(GTK_DIALOG(file_sel));
-
- if(resp == GTK_RESPONSE_OK) {
- gchar *flash;
-
- if(GHEX_WINDOW(win)->gh != NULL) {
- win = GHEX_WINDOW (ghex_window_new_from_file (GTK_APPLICATION
(g_application_get_default ()),
- gtk_file_chooser_get_filename
(GTK_FILE_CHOOSER (file_sel))));
- if(win != NULL)
- gtk_widget_show(GTK_WIDGET(win));
- }
- else {
- if(!ghex_window_load(GHEX_WINDOW(win),
- gtk_file_chooser_get_filename
(GTK_FILE_CHOOSER (file_sel))))
- win = NULL;
- }
-
- if(win != NULL) {
- gchar *gtk_file_name;
- gtk_file_name = g_filename_to_utf8
- (GHEX_WINDOW(win)->gh->document->file_name, -1,
- NULL, NULL, NULL);
- flash = g_strdup_printf(_("Loaded file %s"), gtk_file_name);
- ghex_window_flash(GHEX_WINDOW(win), flash);
- g_free(gtk_file_name);
- g_free(flash);
- if (converter_get)
- gtk_widget_set_sensitive(converter_get, TRUE);
- }
- else
- display_error_dialog (ghex_window_get_active(), _("Can not open file!"));
- }
-
- gtk_widget_destroy(file_sel);
-}
-
-void
-save_as_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win = GHEX_WINDOW(user_data);
- HexDocument *doc;
-
- if(win->gh)
- doc = win->gh->document;
- else
- doc = NULL;
-
- if(doc == NULL)
- return;
-
- ghex_window_save_as(win);
-}
-
-void
-print_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win = GHEX_WINDOW(user_data);
-
- if(win->gh == NULL)
- return;
-
- ghex_print(win->gh, FALSE);
-}
-
-void
-print_preview_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win = GHEX_WINDOW(user_data);
-
- if(win->gh == NULL)
- return;
-
- ghex_print(win->gh, TRUE);
-}
-
-void
-export_html_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win = GHEX_WINDOW(user_data);
- HexDocument *doc;
- GtkWidget *file_sel;
- GtkResponseType resp;
-
- if(win->gh)
- doc = win->gh->document;
- else
- doc = NULL;
-
- if(doc == NULL)
- return;
-
- file_sel = gtk_file_chooser_dialog_new(_("Select path and file name for the HTML source"),
- GTK_WINDOW(win),
-
GTK_FILE_CHOOSER_ACTION_SAVE,
- GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
- GTK_STOCK_SAVE,
GTK_RESPONSE_OK,
- NULL);
- gtk_window_set_modal(GTK_WINDOW(file_sel), TRUE);
- gtk_window_set_position(GTK_WINDOW (file_sel), GTK_WIN_POS_MOUSE);
- gtk_widget_show(file_sel);
-
- resp = gtk_dialog_run(GTK_DIALOG(file_sel));
-
- if(resp == GTK_RESPONSE_OK) {
- gchar *html_path;
- gchar *sep, *base_name, *check_path;
- GtkHex *view = win->gh;
-
- html_path = g_path_get_dirname (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_sel)));
- base_name = g_path_get_basename (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_sel)));
-
- gtk_widget_destroy(file_sel);
-
- sep = strstr(base_name, ".htm");
- if(sep)
- *sep = 0;
-
- if(*base_name == 0) {
- g_free(html_path);
- g_free(base_name);
- display_error_dialog(win, _("You need to specify a base name for "
- "the HTML files."));
- return;
- }
-
- check_path = g_strdup_printf("%s/%s.html", html_path, base_name);
- if(access(check_path, F_OK) == 0) {
- gint reply;
- GtkWidget *mbox;
-
- if(access(check_path, W_OK) != 0) {
- display_error_dialog(win, _("You don't have the permission to write to the
selected path.\n"));
- g_free(html_path);
- g_free(base_name);
- g_free(check_path);
- return;
- }
-
- mbox = gtk_message_dialog_new(GTK_WINDOW(win),
- GTK_DIALOG_MODAL|
-
GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_YES_NO,
- _("Saving to HTML will
overwrite some files.\n"
- "Do you want to
proceed?"));
- gtk_dialog_set_default_response(GTK_DIALOG(mbox), GTK_RESPONSE_NO);
- reply = ask_user(GTK_MESSAGE_DIALOG(mbox));
- gtk_widget_destroy(mbox);
- if(reply != GTK_RESPONSE_YES) {
- g_free(html_path);
- g_free(base_name);
- g_free(check_path);
- return;
- }
- }
- else {
- if(access(html_path, W_OK) != 0) {
- display_error_dialog(win, _("You don't have the permission to write to the
selected path.\n"));
- g_free(html_path);
- g_free(base_name);
- g_free(check_path);
- return;
- }
- }
- g_free(check_path);
-
- hex_document_export_html(doc, html_path, base_name, 0, doc->file_size,
- view->cpl, view->vis_lines,
view->group_type);
- g_free(html_path);
- g_free(base_name);
- }
- else
- gtk_widget_destroy(GTK_WIDGET(file_sel));
-}
-
-void
-close_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win = GHEX_WINDOW(user_data), *other_win;
- HexDocument *doc;
- const GList *window_list;
-
- if(win->gh == NULL) {
- if(ghex_window_get_list()->next != NULL)
- gtk_widget_destroy(GTK_WIDGET(win));
- return;
- }
-
- doc = win->gh->document;
-
- if(!ghex_window_ok_to_close(win))
- return;
-
- window_list = ghex_window_get_list();
- while(window_list) {
- other_win = GHEX_WINDOW(window_list->data);
- ghex_window_remove_doc_from_list(other_win, doc);
- window_list = window_list->next;
- if(other_win->gh && other_win->gh->document == doc && other_win != win)
- gtk_widget_destroy(GTK_WIDGET(other_win));
- }
-
-
- /* If we have created the converter window disable the
- * "Get cursor value" button
- */
- if (converter_get)
- gtk_widget_set_sensitive(converter_get, FALSE);
-
- if(ghex_window_get_list()->next == NULL) {
- ghex_window_destroy_contents (win);
- win->gh = NULL;
- ghex_window_set_sensitivity(win);
- ghex_window_set_doc_name(win, NULL);
-
- /* Clear the contents of status bar after closing the files */
- ghex_window_show_status (win, " ");
- }
- else
- gtk_widget_destroy(GTK_WIDGET(win));
-
- /* this implicitly destroys all views including this one */
- g_object_unref(G_OBJECT(doc));
-}
-
-void
-raise_and_focus_widget (GtkWidget *widget)
-{
- if(!gtk_widget_get_realized (widget))
- return;
-
- gtk_window_present(GTK_WINDOW(widget));
-}
-
-void
-file_list_activated_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win;
- HexDocument *doc = HEX_DOCUMENT(user_data);
- const GList *window_list;
-
- window_list = ghex_window_get_list();
- while(window_list) {
- win = GHEX_WINDOW(window_list->data);
- if(win->gh && win->gh->document == doc)
- break;
- window_list = window_list->next;
- }
-
- if(window_list) {
- win = GHEX_WINDOW(window_list->data);
- raise_and_focus_widget(GTK_WIDGET(win));
- }
-}
-
-void
-insert_mode_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win;
- gboolean active;
-
- win = GHEX_WINDOW (user_data);
- active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
-
- if (win->gh != NULL)
- gtk_hex_set_insert_mode (win->gh, active);
-}
-
-void
-character_table_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win;
- gboolean active;
-
- win = GHEX_WINDOW (user_data);
- active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
-
- if (!char_table)
- char_table = create_char_table ();
-
- if (active) {
- if (!gtk_widget_get_visible (char_table)) {
- gtk_window_set_position (GTK_WINDOW (char_table), GTK_WIN_POS_MOUSE);
- gtk_widget_show (char_table);
- }
- raise_and_focus_widget (char_table);
- }
- else {
- if (gtk_widget_get_visible (char_table))
- gtk_widget_hide (GTK_WIDGET (char_table));
- }
- ghex_window_sync_char_table_item (win, active ? 1 : 0);
-}
-
-void
-converter_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win;
- gboolean active;
-
- win = GHEX_WINDOW (user_data);
- active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
-
- if (!converter)
- converter = create_converter ();
-
- if (active) {
- if (!gtk_widget_get_visible (converter->window)) {
- gtk_window_set_position (GTK_WINDOW (converter->window), GTK_WIN_POS_MOUSE);
- gtk_widget_show (converter->window);
- }
- raise_and_focus_widget (converter->window);
-
- if (!ghex_window_get_active () && converter_get)
- gtk_widget_set_sensitive (converter_get, FALSE);
- else
- gtk_widget_set_sensitive (converter_get, TRUE);
- }
- else {
- if (gtk_widget_get_visible (converter->window))
- gtk_widget_hide (converter->window);
- }
- ghex_window_sync_converter_item (win, active ? 1 : 0);
-}
-
-void
-type_dialog_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win;
- gboolean active;
-
- win = GHEX_WINDOW (user_data);
- active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
-
- if (!win->dialog)
- return;
- if (active) {
- if (!gtk_widget_get_visible (win->dialog_widget)) {
- gtk_widget_show (win->dialog_widget);
- }
- }
- else if (gtk_widget_get_visible (win->dialog_widget)) {
- gtk_widget_hide (GTK_WIDGET (win->dialog_widget));
- }
-}
-
-void
-group_data_cb (GtkAction *action,
- GtkRadioAction *current,
- gpointer user_data)
-{
- GHexWindow *win;
- gint value;
-
- win = GHEX_WINDOW (user_data);
- value = gtk_radio_action_get_current_value (current);
-
- if (win->gh != NULL)
- gtk_hex_set_group_type (win->gh, value);
-}
-
-void
-prefs_cb (GtkAction *action,
- gpointer user_data)
-{
- if(!prefs_ui)
- prefs_ui = create_prefs_dialog();
-
- set_current_prefs(prefs_ui);
-
- if(ghex_window_get_active() != NULL)
- gtk_window_set_transient_for(GTK_WINDOW(prefs_ui->pbox),
-
GTK_WINDOW(ghex_window_get_active()));
- if(!gtk_widget_get_visible(prefs_ui->pbox)) {
- gtk_window_set_position (GTK_WINDOW(prefs_ui->pbox), GTK_WIN_POS_MOUSE);
- gtk_widget_show(GTK_WIDGET(prefs_ui->pbox));
- }
- raise_and_focus_widget(GTK_WIDGET(prefs_ui->pbox));
-}
-
-
-void
-revert_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win;
- HexDocument *doc;
- GtkWidget *mbox;
- gint reply;
-
- win = GHEX_WINDOW(user_data);
- if(win->gh)
- doc = win->gh->document;
- else
- doc = NULL;
-
- if(doc == NULL)
- return;
-
- if(doc->changed) {
- mbox = gtk_message_dialog_new(GTK_WINDOW(win),
- GTK_DIALOG_MODAL|
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_YES_NO,
- _("Really revert file %s?"),
- doc->path_end);
- gtk_dialog_set_default_response(GTK_DIALOG(mbox), GTK_RESPONSE_NO);
-
- reply = ask_user(GTK_MESSAGE_DIALOG(mbox));
-
- if(reply == GTK_RESPONSE_YES) {
- gchar *flash;
- gchar *gtk_file_name;
-
- gtk_file_name = g_filename_to_utf8 (doc->file_name, -1,
- NULL, NULL,
NULL);
- win->changed = FALSE;
- hex_document_read(doc);
- flash = g_strdup_printf(_("Reverted buffer from file %s"), gtk_file_name);
- ghex_window_flash(win, flash);
- ghex_window_set_sensitivity(win);
- g_free(gtk_file_name);
- g_free(flash);
- }
-
- gtk_widget_destroy (mbox);
- }
-}
-#endif
-
-/**
- * ghex_print
- * @preview: Indicates whether to show only a print preview (TRUE) or
-to display the print dialog.
+/* common_print
*
* Prints or previews the current document.
- **/
+ *
+ * @preview: Indicates whether to show only a print preview (TRUE) or to
+ * display the print dialog.
+ */
void
common_print (GtkWindow *parent, GtkHex *gh, gboolean preview)
{
@@ -927,68 +217,3 @@ display_info_dialog (GtkWindow *parent, const char *msg)
{
display_dialog (parent, msg, GTK_MESSAGE_INFO);
}
-
-#if 0
-void
-display_info_dialog (GHexWindow *win, const gchar *msg, ...)
-{
- GtkWidget *info_dlg;
- gchar *real_msg;
- va_list args;
-
- g_return_if_fail (win != NULL);
- g_return_if_fail (msg != NULL);
- va_start(args, msg);
- real_msg = g_strdup_vprintf(msg, args);
- va_end(args);
- info_dlg = gtk_message_dialog_new (
- GTK_WINDOW (win),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- "%s",
- real_msg);
- g_free(real_msg);
-
- gtk_dialog_set_default_response (GTK_DIALOG (info_dlg), GTK_RESPONSE_OK);
- gtk_window_set_resizable (GTK_WINDOW (info_dlg), FALSE);
- gtk_dialog_run (GTK_DIALOG (info_dlg));
- gtk_widget_destroy (info_dlg);
-}
-
-void
-update_dialog_titles()
-{
- if(jump_dialog)
- create_dialog_title(jump_dialog->window, _("GHex (%s): Jump To Byte"));
- if(replace_dialog)
- create_dialog_title(replace_dialog->window, _("GHex (%s): Find & Replace Data"));
- if(find_dialog)
- create_dialog_title(find_dialog->window, _("GHex (%s): Find Data"));
-}
-
-void
-add_view_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win = GHEX_WINDOW(user_data);
- GtkWidget *newwin;
-
- if(win->gh == NULL)
- return;
-
- newwin = ghex_window_new_from_doc (GTK_APPLICATION (g_application_get_default ()),
- win->gh->document);
- gtk_widget_show(newwin);
-}
-
-void
-remove_view_cb (GtkAction *action,
- gpointer user_data)
-{
- GHexWindow *win = GHEX_WINDOW(user_data);
-
- ghex_window_close(win);
-}
-#endif
-
diff --git a/src/common-ui.h b/src/common-ui.h
index cbbca4ad..c01de8fb 100644
--- a/src/common-ui.h
+++ b/src/common-ui.h
@@ -4,6 +4,12 @@
/* common-ui.h - Common UI utility functions
Copyright © 2004 Free Software Foundation
+
+ Copyright © 2005-2020 Various individual contributors, including
+ but not limited to: Jonathon Jongsma, Kalev Lember, who continued
+ to maintain the source code under the licensing terms described
+ herein and below.
+
Copyright © 2021 Logan Rathbone
GHex is free software; you can redistribute it and/or
diff --git a/src/configuration.c b/src/configuration.c
index 91b4d931..491b14c9 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -5,6 +5,13 @@
Copyright (C) 1997 - 2004 Free Software Foundation
+ Copyright © 2005-2020 Various individual contributors, including
+ but not limited to: Jonathon Jongsma, Kalev Lember, who continued
+ to maintain the source code under the licensing terms described
+ herein and below.
+
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
+
GHex is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
diff --git a/src/configuration.h b/src/configuration.h
index fba191f2..f9ce06d9 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -4,7 +4,13 @@
/* configuration.h - constants and declarations for GSettings
Copyright (C) 1998 - 2004 Free Software Foundation
- Copyright © 2021 Logan Rathbone
+
+ Copyright © 2005-2020 Various individual contributors, including
+ but not limited to: Jonathon Jongsma, Kalev Lember, who continued
+ to maintain the source code under the licensing terms described
+ herein and below.
+
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
GHex is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
diff --git a/src/context-menu.ui b/src/context-menu.ui
index 7996bdc7..b657328a 100644
--- a/src/context-menu.ui
+++ b/src/context-menu.ui
@@ -2,6 +2,26 @@
<!-- vim: colorcolumn=80 ts=4 sw=4
-->
+<!--
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
+
+ GHex is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ GHex is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GHex; see the file COPYING.
+ If not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ Original GHex Author: Jaka Mocnik <jaka gnu org>
+-->
<interface>
<menu id='context-menu'>
diff --git a/src/converter.c b/src/converter.c
index ecb2af2e..76a7b68c 100644
--- a/src/converter.c
+++ b/src/converter.c
@@ -5,6 +5,13 @@
Copyright (C) 1998 - 2004 Free Software Foundation
+ Copyright © 2005-2020 Various individual contributors, including
+ but not limited to: Jonathon Jongsma, Kalev Lember, who continued
+ to maintain the source code under the licensing terms described
+ herein and below.
+
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
+
GHex is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
@@ -20,8 +27,8 @@
If not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- Authors:
- Jaka Mocnik <jaka gnu org>
+ Original authors of this file:
+ Jaka Mocnik <jaka gnu org> (Original GHex author)
Chema Celorio <chema gnome org>
*/
@@ -38,7 +45,6 @@
#include "gtkhex.h"
#include "converter.h"
-//#include "ghex-window.h"
/* OPAQUE DATATYPES */
@@ -150,7 +156,7 @@ create_converter_entry(const gchar *name, GtkWidget *grid, gint pos, gint base)
gtk_widget_set_hexpand (entry, TRUE);
gtk_grid_attach (GTK_GRID (grid), entry, 1, pos, 1, 1);
- // A11Y - REWRITE IF REQUIRED
+ /* TODO: A11Y - REWRITE IF REQUIRED */
#if 0
if (GTK_IS_ACCESSIBLE (gtk_widget_get_accessible (entry))) {
g_snprintf (str, BUFFER_LEN, "Displays the value at cursor in %s", name+1);
@@ -229,7 +235,7 @@ GtkWidget *create_converter (GtkWindow *parent_win, /* can-NULL */
gtk_grid_attach (GTK_GRID (grid), converter_get, 0, 5, 2, 1);
- // A11Y - REWRITE IF REQUIRED
+ /* TODO - A11Y - REWRITE IF REQUIRED */
#if 0
if (GTK_IS_ACCESSIBLE(gtk_widget_get_accessible(converter_get))) {
add_atk_namedesc (converter_get, _("Get cursor value"), _("Gets the value at cursor in
binary, octal, decimal, hex and ASCII"));
diff --git a/src/converter.h b/src/converter.h
index bd3f0dd7..0348fac9 100644
--- a/src/converter.h
+++ b/src/converter.h
@@ -5,6 +5,13 @@
Copyright (C) 2004 Free Software Foundation
+ Copyright © 2005-2020 Various individual contributors, including
+ but not limited to: Jonathon Jongsma, Kalev Lember, who continued
+ to maintain the source code under the licensing terms described
+ herein and below.
+
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
+
GHex is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
@@ -20,7 +27,7 @@
If not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- Author: Jaka Mocnik <jaka gnu org>
+ Original Author: Jaka Mocnik <jaka gnu org>
*/
#ifndef GHEX_CONVERTER_H
@@ -33,7 +40,6 @@ G_BEGIN_DECLS
GtkWidget *create_converter (GtkWindow *parent_win, /* can-NULL */
GtkHex *gh);
-
G_END_DECLS
#endif /* GHEX_CONVERTER_H */
diff --git a/src/findreplace.c b/src/findreplace.c
index 70de85d0..c54e6b6c 100644
--- a/src/findreplace.c
+++ b/src/findreplace.c
@@ -10,7 +10,7 @@
to maintain the source code under the licensing terms described
herein and below.
- Copyright © 2021 Logan Rathbone
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
GHex is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -113,13 +113,14 @@ static gint get_search_string(HexDocument *doc, gchar **str);
static GtkWidget *
create_hex_view(HexDocument *doc)
{
+ /* Not going to bother reffing, since add_view does this internally. */
GtkWidget *gh = hex_document_add_view (doc);
gtk_widget_set_hexpand (gh, TRUE);
gtk_hex_set_group_type (GTK_HEX(gh), def_group_type);
- // FIXME - JUST DELETE?
+ /* FIXME - FONT - not implemented. */
#if 0
if (def_metrics && def_font_desc) {
gtk_hex_set_font(GTK_HEX(gh), def_metrics, def_font_desc);
@@ -153,7 +154,7 @@ replace_cancel_cb (GtkButton *button, gpointer user_data)
g_signal_emit(self,
replace_signals[CLOSED],
- 0); // GQuark detail (just set to 0 if unknown)
+ 0); /* GQuark detail (just set to 0 if unknown) */
}
static void
@@ -165,7 +166,7 @@ jump_cancel_cb (GtkButton *button, gpointer user_data)
g_signal_emit(self,
jump_signals[CLOSED],
- 0); // GQuark detail (just set to 0 if unknown)
+ 0); /* GQuark detail (just set to 0 if unknown) */
}
static void
@@ -186,7 +187,7 @@ find_cancel_cb(GtkButton *button, gpointer user_data)
g_signal_emit(self,
find_signals[CLOSED],
- 0); // GQuark detail (just set to 0 if unknown)
+ 0); /* GQuark detail (just set to 0 if unknown) */
}
static void
@@ -224,9 +225,10 @@ find_next_cb(GtkButton *button, gpointer user_data)
self->auto_highlight = NULL;
self->auto_highlight = gtk_hex_insert_autohighlight(self->gh,
str, str_len);
- // FIXME - oh dang maybe I shouldn't gave got rid of this - maybe
- // there's a way to replicate this with states. :(
-// , "red");
+ /* FIXME - due to the restructuring we lost our ability to add custom
+ * colour - maybe there's a way to replicate this with states. :(
+ , "red");
+ */
if (hex_document_find_forward(doc,
cursor_pos + 1,
@@ -276,8 +278,9 @@ find_prev_cb(GtkButton *button, gpointer user_data)
self->auto_highlight = NULL;
self->auto_highlight = gtk_hex_insert_autohighlight(self->gh,
str, str_len);
- // FIXME - restore our purdy colours
- //, "red");
+ /* FIXME - restore our purdy colours
+ , "red");
+ */
if (hex_document_find_backward(doc,
cursor_pos, str, str_len, &offset))
@@ -599,6 +602,8 @@ find_dialog_dispose(GObject *object)
{
FindDialog *self = FIND_DIALOG(object);
+ g_clear_pointer (&self->vbox, gtk_widget_unparent);
+
/* Boilerplate: chain up
*/
G_OBJECT_CLASS(find_dialog_parent_class)->dispose(object);
@@ -744,6 +749,8 @@ replace_dialog_dispose(GObject *object)
{
ReplaceDialog *self = REPLACE_DIALOG(object);
+ g_clear_pointer (&self->vbox, gtk_widget_unparent);
+
/* Boilerplate: chain up
*/
G_OBJECT_CLASS(replace_dialog_parent_class)->dispose(object);
@@ -881,6 +888,8 @@ jump_dialog_dispose(GObject *object)
{
JumpDialog *self = JUMP_DIALOG(object);
+ g_clear_pointer (&self->box, gtk_widget_unparent);
+
/* Boilerplate: chain up
*/
G_OBJECT_CLASS(jump_dialog_parent_class)->dispose(object);
diff --git a/src/findreplace.h b/src/findreplace.h
index 327328f2..c419ae2c 100644
--- a/src/findreplace.h
+++ b/src/findreplace.h
@@ -4,8 +4,13 @@
/* findreplace.h - types related to find and replace dialogs
Copyright (C) 2004 Free Software Foundation
- Copyright (C) 2005-2020 FIXME
- Copyright © 2021 Logan Rathbone
+
+ Copyright © 2005-2020 Various individual contributors, including
+ but not limited to: Jonathon Jongsma, Kalev Lember, who continued
+ to maintain the source code under the licensing terms described
+ herein and below.
+
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
GHex is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -44,7 +49,8 @@ G_DECLARE_FINAL_TYPE (JumpDialog, jump_dialog, JUMP, DIALOG, GtkWidget)
G_DECLARE_FINAL_TYPE (FindDialog, find_dialog, FIND, DIALOG, GtkWidget)
#define REPLACE_TYPE_DIALOG (replace_dialog_get_type ())
-G_DECLARE_FINAL_TYPE (ReplaceDialog, replace_dialog, REPLACE, DIALOG, GtkWidget)
+G_DECLARE_FINAL_TYPE (ReplaceDialog, replace_dialog, REPLACE, DIALOG,
+ GtkWidget)
/* PUBLIC METHOD DECLARATIONS */
diff --git a/src/ghex-application-window.c b/src/ghex-application-window.c
index 118bbd68..10e81960 100644
--- a/src/ghex-application-window.c
+++ b/src/ghex-application-window.c
@@ -26,10 +26,6 @@
/* DEFINES */
-/* FIXME/TODO - this was an option before. Not sure I see the point in
- * it. Will consider keeping it hardcoded - but if I do, it might need to
- * be moved.
- */
#define offset_fmt "0x%X"
/* GHexNotebookTab GOBJECT DEFINITION */
@@ -1143,12 +1139,12 @@ save_as (GtkWidget *widget,
gtk_file_chooser_native_new (_("Select a file to save buffer as"),
GTK_WINDOW(self),
GTK_FILE_CHOOSER_ACTION_SAVE,
- NULL, // const char *accept_label } NULL == default.
- NULL); // const char *cancel_label }
+ NULL, /* const char *accept_label } NULL == default. */
+ NULL); /* const char *cancel_label } */
/* Default suggested file == existing file. */
gtk_file_chooser_set_file (GTK_FILE_CHOOSER(file_sel), existing_file,
- NULL); // GError **error
+ NULL); /* GError **error */
g_signal_connect (file_sel, "response",
G_CALLBACK(save_as_response_cb), self);
@@ -1269,8 +1265,8 @@ new_gh_from_gfile (GFile *file)
path = g_file_get_path (my_file);
info = g_file_query_info (my_file,
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
- G_FILE_QUERY_INFO_NONE, // GFileQueryInfoFlags flags
- NULL, // GCancellable
*cancellable
+ G_FILE_QUERY_INFO_NONE, /* GFileQueryInfoFlags flags */
+ NULL, /* GCancellable *cancellable
*/
&error);
g_debug("%s: path acc. to GFile: %s",
@@ -1279,6 +1275,8 @@ new_gh_from_gfile (GFile *file)
doc = hex_document_new_from_file (path);
gh = GTK_HEX(gtk_hex_new (doc));
+ g_return_val_if_fail (GTK_IS_HEX (gh), NULL);
+
if (error) g_error_free (error);
g_clear_object (&info);
g_object_unref (my_file);
@@ -1322,8 +1320,8 @@ open_file (GtkWidget *widget,
gtk_file_chooser_native_new (_("Select a file to open"),
GTK_WINDOW(self),
GTK_FILE_CHOOSER_ACTION_OPEN,
- NULL, // const char *accept_label } NULL == default.
- NULL); // const char *cancel_label }
+ NULL, /* const char *accept_label } NULL == default. */
+ NULL); /* const char *cancel_label } */
g_signal_connect (file_sel, "response",
G_CALLBACK(open_response_cb), self);
@@ -1610,12 +1608,9 @@ ghex_notebook_tab_close_click_cb (GtkButton *button,
{
GHexNotebookTab *self = GHEX_NOTEBOOK_TAB(user_data);
- g_debug("%s: clicked btn: %p - EMITTING CLOSED SIGNAL",
- __func__, (void *)button);
-
g_signal_emit(self,
notebook_signals[CLOSED],
- 0); // GQuark detail (just set to 0 if unknown)
+ 0); /* GQuark detail (just set to 0 if unknown) */
}
@@ -1658,6 +1653,16 @@ static void
ghex_notebook_tab_dispose (GObject *object)
{
GHexNotebookTab *self = GHEX_NOTEBOOK_TAB(object);
+ GtkWidget *widget = GTK_WIDGET(self);
+ GtkWidget *child;
+
+ /* Unparent children
+ */
+ g_clear_pointer (&self->label, gtk_widget_unparent);
+ g_clear_pointer (&self->close_btn, gtk_widget_unparent);
+
+ /* Unref GtkHex widget associated with tab */
+ g_object_unref (self->gh);
/* Boilerplate: chain up
*/
@@ -1743,6 +1748,7 @@ ghex_notebook_tab_add_hex (GHexNotebookTab *self, GtkHex *gh)
g_return_if_fail (HEX_IS_DOCUMENT (doc));
/* Associate this notebook tab with a GtkHex widget. */
+ g_object_ref (gh);
self->gh = gh;
/* Set name of tab. */
@@ -1893,6 +1899,22 @@ static void
ghex_application_window_dispose(GObject *object)
{
GHexApplicationWindow *self = GHEX_APPLICATION_WINDOW(object);
+ GtkWidget *widget = GTK_WIDGET(self);
+ GtkWidget *child;
+
+ /* Unparent children
+ */
+ g_clear_pointer (&self->find_dialog, gtk_widget_unparent);
+ g_clear_pointer (&self->replace_dialog, gtk_widget_unparent);
+ g_clear_pointer (&self->jump_dialog, gtk_widget_unparent);
+ g_clear_pointer (&self->chartable, gtk_widget_unparent);
+ g_clear_pointer (&self->converter, gtk_widget_unparent);
+
+ /* Clear CSS provider */
+ g_clear_object (&self->provider);
+
+ /* Unref GtkHex */
+ g_list_free_full (g_steal_pointer (&self->gh_list), g_object_unref);
/* Boilerplate: chain up
*/
@@ -1935,57 +1957,54 @@ ghex_application_window_class_init(GHexApplicationWindowClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
-// GApplicationClass *app_class = G_APPLICATION_CLASS (class);
object_class->dispose = ghex_application_window_dispose;
object_class->finalize = ghex_application_window_finalize;
object_class->get_property = ghex_application_window_get_property;
object_class->set_property = ghex_application_window_set_property;
-// app_class->startup = ghex_application_window_startup;
-
/* PROPERTIES */
properties[PROP_CHARTABLE_OPEN] =
g_param_spec_boolean ("chartable-open",
"Character table open",
"Whether the character table dialog is currently open",
- FALSE, // gboolean default_value
+ FALSE, /* gboolean default_value */
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
properties[PROP_CONVERTER_OPEN] =
g_param_spec_boolean ("converter-open",
"Base converter open",
"Whether the base converter dialog is currently open",
- FALSE, // gboolean default_value
+ FALSE, /* gboolean default_value */
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
properties[PROP_FIND_OPEN] =
g_param_spec_boolean ("find-open",
"Find pane open",
"Whether the Find pane is currently open",
- FALSE, // gboolean default_value
+ FALSE, /* gboolean default_value */
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
properties[PROP_REPLACE_OPEN] =
g_param_spec_boolean ("replace-open",
"Replace pane open",
"Whether the Find and Replace pane is currently open",
- FALSE, // gboolean default_value
+ FALSE, /* gboolean default_value */
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
properties[PROP_JUMP_OPEN] =
g_param_spec_boolean ("jump-open",
"Jump pane open",
"Whether the Jump to Byte pane is currently open",
- FALSE, // gboolean default_value
+ FALSE, /* gboolean default_value */
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
properties[PROP_CAN_SAVE] =
g_param_spec_boolean ("can-save",
"Can save",
"Whether the Save (or Revert) button should currently be clickable",
- FALSE, // gboolean default_value
+ FALSE, /* gboolean default_value */
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
@@ -1994,43 +2013,43 @@ ghex_application_window_class_init(GHexApplicationWindowClass *klass)
/* ACTIONS */
gtk_widget_class_install_action (widget_class, "ghex.open",
- NULL, // GVariant string param_type
+ NULL, /* GVariant string param_type */
open_file);
gtk_widget_class_install_action (widget_class, "ghex.save",
- NULL, // GVariant string param_type
+ NULL, /* GVariant string param_type */
save_action);
gtk_widget_class_install_action (widget_class, "ghex.save-as",
- NULL, // GVariant string param_type
+ NULL, /* GVariant string param_type */
save_as);
gtk_widget_class_install_action (widget_class, "ghex.revert",
- NULL, // GVariant string param_type
+ NULL, /* GVariant string param_type */
revert);
gtk_widget_class_install_action (widget_class, "ghex.print",
- NULL, // GVariant string param_type
+ NULL, /* GVariant string param_type */
do_print);
gtk_widget_class_install_action (widget_class, "ghex.print-preview",
- NULL, // GVariant string param_type
+ NULL, /* GVariant string param_type */
print_preview);
gtk_widget_class_install_action (widget_class, "ghex.show-conversions",
- NULL, // GVariant string param_type
+ NULL, /* GVariant string param_type */
toggle_conversions);
gtk_widget_class_install_action (widget_class, "ghex.insert-mode",
- NULL, // GVariant string param_type
+ NULL, /* GVariant string param_type */
toggle_insert_mode);
gtk_widget_class_install_action (widget_class, "ghex.preferences",
- NULL, // GVariant string param_type
+ NULL, /* GVariant string param_type */
open_preferences);
gtk_widget_class_install_action (widget_class, "ghex.about",
- NULL, // GVariant string param_type
+ NULL, /* GVariant string param_type */
open_about);
@@ -2119,9 +2138,11 @@ ghex_application_window_add_hex (GHexApplicationWindow *self,
GtkHex *gh)
{
GtkWidget *tab;
- HexDocument *doc = gtk_hex_get_document (gh);
+ HexDocument *doc;
g_return_if_fail (GTK_IS_HEX(gh));
+
+ doc = gtk_hex_get_document (gh);
g_return_if_fail (HEX_IS_DOCUMENT(doc));
/* Setup GtkHex based on settings. */
@@ -2130,12 +2151,14 @@ ghex_application_window_add_hex (GHexApplicationWindow *self,
set_gtkhex_offsets_column_from_settings (gh);
set_gtkhex_group_type_from_settings (gh);
- /* Add this GtkHex to our internal list */
- // FIXME / TODO - used for nothing rn.
+ /* Add this GtkHex to our internal list
+ */
self->gh_list = g_list_append (self->gh_list, gh);
+ g_object_ref (gh);
/* Set this GtkHex as the current viewed gh if there is no currently
- * open document */
+ * open document
+ */
if (! self->gh)
ghex_application_window_set_hex (self, gh);
diff --git a/src/ghex-application-window.h b/src/ghex-application-window.h
index 0079116a..e89cbe32 100644
--- a/src/ghex-application-window.h
+++ b/src/ghex-application-window.h
@@ -1,13 +1,34 @@
-/* vim: colorcolumn=80 tw=4 ts=4
- */
+/* vim: ts=4 sw=4 colorcolumn=80
+ * -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* ghex-application-window.c - GHex main application window
+
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
+
+ GHex is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ GHex is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GHex; see the file COPYING.
+ If not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ Original GHex Author: Jaka Mocnik <jaka gnu org>
+*/
#ifndef GHEX_APPLICATION_WINDOW_H
#define GHEX_APPLICATION_WINDOW_H
#include <gtk/gtk.h>
-#include <gtkhex.h>
#include <glib/gi18n.h>
+#include "gtkhex.h"
#include "configuration.h"
#include "hex-dialog.h"
#include "findreplace.h"
@@ -16,6 +37,8 @@
#include "preferences.h"
#include "common-ui.h"
+G_BEGIN_DECLS
+
#define GHEX_TYPE_APPLICATION_WINDOW (ghex_application_window_get_type ())
G_DECLARE_FINAL_TYPE (GHexApplicationWindow, ghex_application_window,
GHEX, APPLICATION_WINDOW,
@@ -32,4 +55,6 @@ GList * ghex_application_window_get_list (GHexApplicationWindow *self);
void ghex_application_window_open_file (GHexApplicationWindow *self,
GFile *file);
+G_END_DECLS
+
#endif
diff --git a/src/ghex-application-window.ui b/src/ghex-application-window.ui
index 0bd3a1ca..b206b597 100644
--- a/src/ghex-application-window.ui
+++ b/src/ghex-application-window.ui
@@ -1,6 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- vim:ts=4 sw=4 foldmethod=indent
+<!-- vim:ts=4 sw=4
+-->
+<!--
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
+
+ GHex is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ GHex is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GHex; see the file COPYING.
+ If not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ Original GHex Author: Jaka Mocnik <jaka gnu org>
-->
<interface>
diff --git a/src/ghex.gresource.xml b/src/ghex.gresource.xml
index b0759631..9db15156 100644
--- a/src/ghex.gresource.xml
+++ b/src/ghex.gresource.xml
@@ -2,6 +2,26 @@
<!-- vim:ts=4 sw=4
-->
+<!--
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
+
+ GHex is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ GHex is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GHex; see the file COPYING.
+ If not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ Original GHex Author: Jaka Mocnik <jaka gnu org>
+-->
<gresources>
<gresource prefix="/org/gnome/ghex">
diff --git a/src/gtkhex-layout-manager.c b/src/gtkhex-layout-manager.c
index 51cecae2..fcb18a1e 100644
--- a/src/gtkhex-layout-manager.c
+++ b/src/gtkhex-layout-manager.c
@@ -36,7 +36,6 @@ struct _GtkHexLayout {
GtkWidget *ascii;
guint char_width;
-// guint group_type;
int hex_width;
int ascii_width;
@@ -206,8 +205,6 @@ gtk_hex_layout_measure (GtkLayoutManager *layout_manager,
natural_size = MAX (natural_size, child_nat);
}
- // TEST - I have no idea what I'm supposed to be doing here.
-
if (minimum != NULL)
*minimum = minimum_size;
if (natural != NULL)
diff --git a/src/gtkhex-layout-manager.h b/src/gtkhex-layout-manager.h
index 58fce879..3decd4de 100644
--- a/src/gtkhex-layout-manager.h
+++ b/src/gtkhex-layout-manager.h
@@ -27,6 +27,8 @@
#include <gtk/gtk.h>
+G_BEGIN_DECLS
+
#define GTK_TYPE_HEX_LAYOUT (gtk_hex_layout_get_type ())
G_DECLARE_FINAL_TYPE (GtkHexLayout, gtk_hex_layout, GTK, HEX_LAYOUT,
GtkLayoutManager)
@@ -49,4 +51,6 @@ void gtk_hex_layout_set_char_width (GtkHexLayout *layout,
void gtk_hex_layout_child_set_column (GtkHexLayoutChild *child,
GtkHexLayoutColumn column);
-#endif
+G_END_DECLS
+
+#endif /* GTK_HEX_LAYOUT_MANAGER_H */
diff --git a/src/gtkhex.c b/src/gtkhex.c
index 9cac21a6..1080c48b 100644
--- a/src/gtkhex.c
+++ b/src/gtkhex.c
@@ -10,7 +10,7 @@
to maintain the source code under the licensing terms described
herein and below.
- Copyright © 2021 Logan Rathbone
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
GHex is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -42,52 +42,31 @@
*/
#include "gtkhex-layout-manager.h"
-/* LAR - TEMPORARY FOR TESTING ONLY */
+/* DEFINES */
-#ifdef ENABLE_DEBUG
-#define TEST_DEBUG_FUNCTION_START g_debug ("%s: [START]", __func__);
-#else
-#define TEST_DEBUG_FUNCTION_START /* */
-#endif
-
-#ifdef ENABLE_DEBUG
-#define TEST_DEBUG_FUNCTION_END g_debug ("%s: [END]", __func__);
-#else
-#define TEST_DEBUG_FUNCTION_END /* */
-#endif
-
-#define NOT_IMPLEMENTED \
- g_critical("%s: NOT IMPLEMENTED", __func__);
-
-/* LAR - new stuff that wasn't in old code */
#define CSS_NAME "hex"
-//#define CSS_NAME "entry"
-
/* default minimum drawing area size (for ascii and hex widgets) in pixels. */
#define DEFAULT_DA_SIZE 50
-
-/* LAR - defines copied from the old header. */
-
-#define LOWER_NIBBLE TRUE
-#define UPPER_NIBBLE FALSE
-
-/* ------ */
-
-/* LAR - some more defines brought in from the old gtkhex-private.h */
-
-#define VIEW_HEX 1
-#define VIEW_ASCII 2
-
-/* ----- */
-
+/* default characters per line (cpl) */
#define DEFAULT_CPL 32
#define DEFAULT_LINES 10
-
#define SCROLL_TIMEOUT 100
#define is_displayable(c) (((c) >= 0x20) && ((c) < 0x7f))
#define is_copyable(c) (is_displayable(c) || (c) == 0x0a || (c) == 0x0d)
+/* ENUMS */
+
+enum {
+ LOWER_NIBBLE,
+ UPPER_NIBBLE
+};
+
+enum {
+ VIEW_HEX,
+ VIEW_ASCII
+};
+
enum {
CURSOR_MOVED_SIGNAL,
DATA_CHANGED_SIGNAL,
@@ -164,10 +143,6 @@ G_DEFINE_TYPE (GtkHexPasteData, gtk_hex_paste_data, G_TYPE_OBJECT)
/* </GtkHexPasteData Decls> */
-/* TODO / NOTE - 'GtkHexClass' previously had these members:
- * GtkClipboard *clipboard, *primary;
- * so when you see ->clipboard and ->primary, these are related to
- * clipboard stuff that needs to be rewritten. */
/* ------------------------------
* Main GtkHex GObject definition
@@ -181,7 +156,6 @@ struct _GtkHex
HexDocument *document;
GtkLayoutManager *layout_manager;
- GtkWidget *box; /* main box for layout */
GtkWidget *xdisp, *adisp; /* DrawingArea */
GtkWidget *offsets; /* DrawingArea */
@@ -325,8 +299,9 @@ magic_int_array_to_data (int *arr, guint len)
return data;
}
-// TEST - this transforms certain problematic characters for copy/paste
-// to a '?'. Maybe find a home for this guy at some point.
+/* FIXME/TODO - this transforms certain problematic characters for copy/paste
+ * to a '?'. Maybe find a home for this guy at some point.
+ */
#if 0
{
char *cp;
@@ -343,20 +318,11 @@ magic_int_array_to_data (int *arr, guint len)
static void
gtk_hex_paste_data_init (GtkHexPasteData *self)
{
- g_debug ("%s: doc_data: %p - elems: %u",
- __func__, (void *)self->doc_data, self->elems);
-
}
static void
gtk_hex_paste_data_class_init (GtkHexPasteDataClass *klass)
{
- /* <boilerplate> */
-// GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
-// object_class->dispose = demo_widget_dispose;
-// object_class->finalize = demo_widget_finalize;
- /* </boilerplate> */
}
@@ -378,9 +344,6 @@ gtk_hex_paste_data_new (guchar *doc_data, guint elems)
self->paste_data = doc_data_to_magic_int_array (self->doc_data,
self->elems);
- g_debug ("%s: doc_data: %p - elems: %u",
- __func__, (void *)self->doc_data, self->elems);
-
g_assert (self->paste_data);
return self;
@@ -437,7 +400,6 @@ copy_action (GtkWidget *widget,
GtkHex *gh = GTK_HEX(widget);
g_return_if_fail (GTK_IS_HEX(gh));
-
(void)action_name, (void)parameter;
gtk_hex_copy_to_clipboard (gh);
@@ -451,7 +413,6 @@ cut_action (GtkWidget *widget,
GtkHex *gh = GTK_HEX(widget);
g_return_if_fail (GTK_IS_HEX(gh));
-
(void)action_name, (void)parameter;
gtk_hex_cut_to_clipboard (gh);
@@ -465,7 +426,6 @@ paste_action (GtkWidget *widget,
GtkHex *gh = GTK_HEX(widget);
g_return_if_fail (GTK_IS_HEX(gh));
-
(void)action_name, (void)parameter;
gtk_hex_paste_from_clipboard (gh);
@@ -542,7 +502,7 @@ undo_action (GtkWidget *widget,
* to cursor coordinates.
*/
static void
-hex_to_pointer(GtkHex *gh, guint mx, guint my)
+hex_to_pointer (GtkHex *gh, guint mx, guint my)
{
guint cx, cy, x;
@@ -567,13 +527,13 @@ hex_to_pointer(GtkHex *gh, guint mx, guint my)
}
static void
-ascii_to_pointer(GtkHex *gh, gint mx, gint my)
+ascii_to_pointer (GtkHex *gh, gint mx, gint my)
{
int cy;
cy = gh->top_line + my/gh->char_height;
- gtk_hex_set_cursor_xy(gh, mx/gh->char_width, cy);
+ gtk_hex_set_cursor_xy (gh, mx/gh->char_width, cy);
}
@@ -616,12 +576,11 @@ get_char_width (GtkHex *gh)
if (GTK_IS_HEX_LAYOUT(gh->layout_manager)) {
gtk_hex_layout_set_char_width (gh->layout_manager, width);
}
-
return width;
}
-void
-format_xbyte(GtkHex *gh, gint pos, gchar buf[2]) {
+static void
+format_xbyte (GtkHex *gh, gint pos, gchar buf[2]) {
guint low, high;
guchar c;
@@ -654,12 +613,11 @@ format_xblock(GtkHex *gh, gchar *out, guint start, guint end)
if(i%gh->group_type == 0)
out[j++] = ' ';
}
-
return j;
}
-gint
-format_ablock(GtkHex *gh, gchar *out, guint start, guint end)
+static gint
+format_ablock (GtkHex *gh, gchar *out, guint start, guint end)
{
int i, j;
guchar c;
@@ -671,7 +629,6 @@ format_ablock(GtkHex *gh, gchar *out, guint start, guint end)
else
out[j] = '.';
}
-
return end - start;
}
@@ -733,18 +690,12 @@ invalidate_xc (GtkHex *gh)
GtkWidget *widget = gh->xdisp;
gint cx, cy;
- if (get_xcoords (gh, gh->cursor_pos, &cx, &cy)) {
+ if (get_xcoords (gh, gh->cursor_pos, &cx, &cy))
+ {
if (gh->lower_nibble)
cx += gh->char_width;
- /* LAR - TEST */
- gtk_widget_queue_draw (widget);
-#if 0
- gtk_widget_queue_draw_area (widget,
- cx, cy,
- gh->char_width + 1,
- gh->char_height);
-#endif
+ gtk_widget_queue_draw (widget);
}
}
@@ -754,19 +705,13 @@ invalidate_ac (GtkHex *gh)
GtkWidget *widget = gh->adisp;
gint cx, cy;
- if (get_acoords (gh, gh->cursor_pos, &cx, &cy)) {
- /* LAR - TEST */
- gtk_widget_queue_draw (widget);
-#if 0
- gtk_widget_queue_draw_area (widget,
- cx, cy,
- gh->char_width + 1,
- gh->char_height);
-#endif
+ if (get_acoords (gh, gh->cursor_pos, &cx, &cy))
+ {
+ gtk_widget_queue_draw (widget);
}
}
-// FIXME - THE NEXT 2 FUNCTIONS ARE DUPLICITOUS. MERGE INTO ONE.
+/* FIXME - THE NEXT 2 FUNCTIONS ARE DUPLICITOUS. MERGE INTO ONE. */
/*
* the cursor rendering stuff...
*/
@@ -786,8 +731,7 @@ render_ac (GtkHex *gh,
context = gtk_widget_get_style_context (gh->adisp);
state = gtk_widget_get_state_flags (gh->adisp);
-
- if(get_acoords(gh, gh->cursor_pos, &cx, &cy)) {
+ if (get_acoords(gh, gh->cursor_pos, &cx, &cy)) {
c[0] = gtk_hex_get_byte(gh, gh->cursor_pos);
if (! is_displayable (c[0]))
c[0] = '.';
@@ -799,18 +743,19 @@ render_ac (GtkHex *gh,
gtk_style_context_save (context);
- if(gh->active_view == VIEW_ASCII) {
+ if (gh->active_view == VIEW_ASCII)
+ {
state |= GTK_STATE_FLAG_SELECTED;
gtk_style_context_set_state (context, state);
gtk_render_background (context, cr,
- cx, // double x,
- cy, // double y,
- gh->char_width, // double width,
- gh->char_height - 1); // double height
-
- } else {
-
+ cx, /* double x, */
+ cy, /* double y, */
+ gh->char_width, /* double width, */
+ gh->char_height - 1); /* double height */
+ }
+ else
+ {
gtk_style_context_get_color (context, &fg_color);
cairo_save (cr);
cairo_set_source_rgba (cr,
@@ -864,18 +809,19 @@ render_xc (GtkHex *gh,
gtk_style_context_save (context);
- if(gh->active_view == VIEW_HEX) {
-
+ if (gh->active_view == VIEW_HEX)
+ {
state |= GTK_STATE_FLAG_SELECTED;
gtk_style_context_set_state (context, state);
gtk_render_background (context, cr,
- cx, // double x,
- cy, // double y,
- gh->char_width, // double width,
- gh->char_height - 1); // double height
- } else {
-
+ cx, /* double x, */
+ cy, /* double y, */
+ gh->char_width, /* double width, */
+ gh->char_height - 1); /* double height */
+ }
+ else
+ {
gtk_style_context_get_color (context, &fg_color);
cairo_save (cr);
cairo_set_source_rgba (cr,
@@ -895,10 +841,16 @@ render_xc (GtkHex *gh,
gtk_style_context_restore (context);
}
+/* FIXME - next 2 functions are duplicitous. Merge into one.
+ */
static void
-show_cursor(GtkHex *gh) {
- if(!gh->cursor_shown) {
- if (gtk_widget_get_realized (gh->xdisp) || gtk_widget_get_realized (gh->adisp)) {
+show_cursor (GtkHex *gh)
+{
+ if (!gh->cursor_shown)
+ {
+ if (gtk_widget_get_realized (gh->xdisp) ||
+ gtk_widget_get_realized (gh->adisp))
+ {
invalidate_xc (gh);
invalidate_ac (gh);
}
@@ -906,9 +858,14 @@ show_cursor(GtkHex *gh) {
}
}
-static void hide_cursor(GtkHex *gh) {
- if(gh->cursor_shown) {
- if (gtk_widget_get_realized (gh->xdisp) || gtk_widget_get_realized (gh->adisp)) {
+static void
+hide_cursor (GtkHex *gh)
+{
+ if (gh->cursor_shown)
+ {
+ if (gtk_widget_get_realized (gh->xdisp) ||
+ gtk_widget_get_realized (gh->adisp))
+ {
invalidate_xc (gh);
invalidate_ac (gh);
}
@@ -916,6 +873,8 @@ static void hide_cursor(GtkHex *gh) {
}
}
+/* FIXME - Next 2 functions are duplicitous. Merge. */
+
static void
render_hex_highlights (GtkHex *gh,
cairo_t *cr,
@@ -923,7 +882,6 @@ render_hex_highlights (GtkHex *gh,
{
GtkHex_Highlight *curHighlight = &gh->selection;
gint xcpl = gh->cpl*2 + gh->cpl/gh->group_type;
- /* would be nice if we could cache that */
GtkHex_AutoHighlight *nextList = gh->auto_highlight;
GtkStateFlags state;
@@ -1085,6 +1043,11 @@ render_ascii_highlights (GtkHex *gh,
gtk_style_context_restore (context);
}
+/* FIXME - Previously, this function was more sophisticated, and only
+ * redrew part of the drawing area requested. Need to make an executive
+ * decision as to whether that will be feasible to do for ghex4, or just
+ * eliminate those and queue a redraw for the drawing area in question.
+ */
/*
* when calling invalidate_*_lines() the imin and imax arguments are the
* numbers of the first and last line TO BE INVALIDATED in the range
@@ -1096,11 +1059,12 @@ invalidate_lines (GtkHex *gh,
gint imin,
gint imax)
{
- GtkAllocation allocation;
-
+#if 0
gtk_widget_get_allocation (widget, &allocation);
+#endif
+
+ (void)gh, (void)imin, (void)imax; /* unused for now. See comment above. */
- /* LAR - TEST */
gtk_widget_queue_draw (widget);
#if 0
gtk_widget_queue_draw_area (widget,
@@ -1172,9 +1136,7 @@ render_hex_lines (GtkHex *gh,
max_lines = MIN(max_lines, gh->vis_lines);
max_lines = MIN(max_lines, gh->lines);
- /* FIXME - I have no idea what this does. It's too early in the morning
- * and the coffee hasn't kicked in yet. Maybe break this down / comment
- * it to make it clearer?
+ /* FIXME - Maybe break this down/comment it to make it clearer?
*/
frm_len = format_xblock (gh, gh->disp_buffer,
(gh->top_line + min_lines) * gh->cpl,
@@ -1185,13 +1147,13 @@ render_hex_lines (GtkHex *gh,
{
int tmp = frm_len - ((i - min_lines) * xcpl);
- if(tmp <= 0)
+ if (tmp <= 0)
break;
render_hex_highlights (gh, cr, i);
/* Set pango layout to the line of hex to render. */
- // FIXME - make this understandable.
+
pango_layout_set_text (gh->xlayout,
gh->disp_buffer + (i - min_lines) * xcpl,
MIN(xcpl, tmp));
@@ -1299,8 +1261,7 @@ render_offsets (GtkHex *gh,
/* width: */ allocation.width,
/* height: */ (max_lines - min_lines + 1) * gh->char_height);
- /* update max_lines and min_lines - FIXME this is from original code -
- * why?? - test and see. */
+ /* update max_lines and min_lines */
max_lines = MIN(max_lines, gh->vis_lines);
max_lines = MIN(max_lines, gh->lines - gh->top_line - 1);
@@ -1330,23 +1291,18 @@ hex_draw (GtkDrawingArea *drawing_area,
GtkHex *gh = GTK_HEX(user_data);
int xcpl = 0;
- g_return_if_fail(GTK_IS_HEX(gh));
-
- TEST_DEBUG_FUNCTION_START
-
- /* Here's the idea here: the hex drawing widget can expand at will,
- * and we generate our cpl as a whole and to be passed to the ascii draw
- * function based on that.
- *
- * Thus, we need to do some calculations in this function before drawing
- * the hex lines and before proceeding to draw the ascii widget.
- */
+ g_return_if_fail (GTK_IS_HEX(gh));
/* Total number of characters that can be displayed per line on the hex
* widget (xcpl) is the simplest calculation:
*/
xcpl = width / gh->char_width;
+ /* FIXME - This doesn't quite jibe with our new layout manager. Our
+ * calculations here are fine, but the layout manager has no knowledge
+ * of it, so sometimes characters get cut off if using larger group
+ * types.
+ */
/* Next, extrapolate the number of ASCII characters per line; this is
* dependent upon the 'grouping' (ie, hex: 2 characters followed by a
* space, a 'word' (2 hex characters together followed by a space, ie,
@@ -1383,11 +1339,8 @@ hex_draw (GtkDrawingArea *drawing_area,
* lines!
*/
render_hex_lines (gh, cr, 0, gh->vis_lines);
-
- TEST_DEBUG_FUNCTION_END
}
-
static void
ascii_draw (GtkDrawingArea *drawing_area,
cairo_t *cr,
@@ -1396,32 +1349,9 @@ ascii_draw (GtkDrawingArea *drawing_area,
gpointer user_data)
{
GtkHex *gh = GTK_HEX(user_data);
-
g_return_if_fail(GTK_IS_HEX(gh));
- TEST_DEBUG_FUNCTION_START
-
render_ascii_lines (gh, cr, 0, gh->vis_lines);
-
- /* LAR - TEST - I have no idea what the below is trying to
- * accomplish. Keeping here for reference. */
-#if 0
- GdkRectangle rect;
- gint imin, imax;
-
- gdk_cairo_get_clip_rectangle (cr, &rect);
-
- imin = (rect.y) / gh->char_height;
- imax = (rect.y + rect.height) / gh->char_height;
- if ((rect.y + rect.height) % gh->char_height)
- imax++;
-
- imax = MIN(imax, gh->vis_lines);
-
- render_ascii_lines (gh, cr, imin, imax);
-#endif
-
- TEST_DEBUG_FUNCTION_END
}
static void
@@ -1435,28 +1365,8 @@ offsets_draw (GtkDrawingArea *drawing_area,
g_return_if_fail(GTK_IS_HEX(gh));
render_offsets (gh, cr, 0, gh->vis_lines);
-
- /* LAR - TEST - I have no idea what the below is trying to
- * accomplish. Keeping for reference. */
-
-#if 0
- GdkRectangle rect;
- gint imin, imax;
-
- gdk_cairo_get_clip_rectangle (cr, &rect);
-
- imin = (rect.y) / gh->char_height;
- imax = (rect.y + rect.height) / gh->char_height;
- if ((rect.y + rect.height) % gh->char_height)
- imax++;
-
- imax = MIN(imax, gh->vis_lines);
-
- render_offsets (gh, cr, imin, imax);
-#endif
}
-// FIXME - CLEAN UP FURTHER.
/*
* this calculates how many bytes we can stuff into one line and how many
* lines we can display according to the current size of the widget
@@ -1472,7 +1382,6 @@ recalc_displays(GtkHex *gh)
* if the cursor is currently within the displayed portion.
*/
if (gh->document->file_size == 0 || gh->cpl == 0)
-// if (gh->document->file_size == 0)
gh->lines = 1;
else {
gh->lines = gh->document->file_size / gh->cpl;
@@ -1480,8 +1389,9 @@ recalc_displays(GtkHex *gh)
gh->lines++;
}
+ /* FIXME - different than 'xcpl' in hex_draw. confusing.
+ */
/* set number of hex characters per line */
- // FIXME - different than 'xcpl' in hex_draw. confusing.
xcpl = gh->cpl * 2 + (gh->cpl - 1) / gh->group_type;
if (gh->disp_buffer)
@@ -1502,7 +1412,7 @@ recalc_scrolling (GtkHex *gh)
gh->vis_lines - 1));
/* calculate new display position */
- if (gh->cpl == 0) // TEST to avoid divide by zero
+ if (gh->cpl == 0) /* avoid divide by zero (FIXME - feels hackish) */
value = 0;
else
value = MIN (gh->top_line, gh->lines - gh->vis_lines);
@@ -1511,7 +1421,7 @@ recalc_scrolling (GtkHex *gh)
value = MAX (0, value);
/* keep cursor on screen if it was on screen before */
- if (gh->cpl == 0) { // TEST to avoid divide by zero
+ if (gh->cpl == 0) { /* avoid divide by zero (FIXME - feels hackish) */
value = 0;
}
else if (scroll_to_cursor &&
@@ -1641,31 +1551,8 @@ hex_pressed_cb (GtkGestureClick *gesture,
/* Right-click */
else if (button == GDK_BUTTON_SECONDARY)
{
- g_debug("%s: RIGHT CLICK - TRYING TO POPUP CONTEXT MENU.", __func__);
-
popup_context_menu(widget, x, y);
}
- /* Middle-click press. */
- else if (button == GDK_BUTTON_MIDDLE)
- {
- g_debug("%s: MIDDLE CLICK - NOT IMPLEMENTED.", __func__);
-#if 0
- GtkHexClass *klass = GTK_HEX_CLASS(GTK_WIDGET_GET_CLASS(gh));
- gchar *text;
-
- gh->active_view = VIEW_HEX;
- hex_to_pointer(gh, event->x, event->y);
-
- text = gtk_clipboard_wait_for_text(klass->primary);
- if (text) {
- hex_document_set_data(gh->document, gh->cursor_pos,
- strlen(text), 0, text, TRUE);
- gtk_hex_set_cursor(gh, gh->cursor_pos + strlen(text));
- g_free(text);
- }
-#endif
- gh->button = 0;
- }
else
{
gh->button = 0;
@@ -1692,7 +1579,6 @@ hex_released_cb (GtkGestureClick *gesture,
/* Single-click */
if (button == GDK_BUTTON_PRIMARY && n_press == 1)
{
- // TEST - OLD CODE
if (gh->scroll_timeout != -1) {
g_source_remove(gh->scroll_timeout);
gh->scroll_timeout = -1;
@@ -1703,7 +1589,7 @@ hex_released_cb (GtkGestureClick *gesture,
}
}
-// FIXME - UNUSED FOR NOW - HERE'S BOILERPLATE IF NEEDED LATER
+/* FIXME/TODO - UNUSED FOR NOW - HERE'S BOILERPLATE IF NEEDED LATER */
#if 0
static void
hex_drag_begin_cb (GtkGestureDrag *gesture,
@@ -1839,27 +1725,6 @@ ascii_pressed_cb (GtkGestureClick *gesture,
{
popup_context_menu(widget, x, y);
}
- /* Middle-click press. */
- else if (button == GDK_BUTTON_MIDDLE)
- {
- g_debug("%s: MIDDLE CLICK - NOT IMPLEMENTED.", __func__);
-#if 0
- GtkHexClass *klass = GTK_HEX_CLASS(GTK_WIDGET_GET_CLASS(gh));
- gchar *text;
-
- gh->active_view = VIEW_HEX;
- hex_to_pointer(gh, event->x, event->y);
-
- text = gtk_clipboard_wait_for_text(klass->primary);
- if (text) {
- hex_document_set_data(gh->document, gh->cursor_pos,
- strlen(text), 0, text, TRUE);
- gtk_hex_set_cursor(gh, gh->cursor_pos + strlen(text));
- g_free(text);
- }
-#endif
- gh->button = 0;
- }
else
{
gh->button = 0;
@@ -1886,7 +1751,6 @@ ascii_released_cb (GtkGestureClick *gesture,
/* Single-click */
if (button == GDK_BUTTON_PRIMARY && n_press == 1)
{
- // TEST - OLD CODE
if (gh->scroll_timeout != -1) {
g_source_remove(gh->scroll_timeout);
gh->scroll_timeout = -1;
@@ -1895,8 +1759,6 @@ ascii_released_cb (GtkGestureClick *gesture,
gh->selecting = FALSE;
gh->button = 0;
}
-
-
}
static void
@@ -1950,7 +1812,6 @@ ascii_drag_update_cb (GtkGestureDrag *gesture,
}
}
-
static gboolean
key_press_cb (GtkEventControllerKey *controller,
guint keyval,
@@ -1966,7 +1827,6 @@ key_press_cb (GtkEventControllerKey *controller,
/* don't trample over Ctrl */
if (state & GDK_CONTROL_MASK) {
- g_debug("%s: CTRL PRESSED - RETURNING.", __func__);
return FALSE;
}
@@ -1978,12 +1838,9 @@ key_press_cb (GtkEventControllerKey *controller,
gh->selecting = TRUE;
}
+ /* FIXME - This could use a cleanup. Mostly flown in from old code.
+ */
switch(keyval) {
- // FIXME TEST - COPY
- 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,
@@ -2143,16 +2000,14 @@ key_release_cb (GtkEventControllerKey *controller,
GtkWidget *widget = GTK_WIDGET(user_data);
gboolean ret = TRUE;
- /* avoid shift key getting 'stuck' */
-
+ /* avoid shift key getting 'stuck'
+ */
if (state & GDK_SHIFT_MASK) {
gh->selecting = FALSE;
}
-
return ret;
}
-
static void
show_offsets_widget(GtkHex *gh)
{
@@ -2169,7 +2024,8 @@ hide_offsets_widget(GtkHex *gh)
gtk_widget_hide (gh->offsets);
}
-// FIXME - REORGANIZE!
+/* FIXME - Reorganize/clean up. Mostly flown in from old code.
+ */
/*
* default data_changed signal handler
*/
@@ -2179,8 +2035,6 @@ static void gtk_hex_real_data_changed (GtkHex *gh, gpointer data)
gint start_line, end_line;
guint lines;
- TEST_DEBUG_FUNCTION_START
-
if(gh->cpl == 0)
return;
@@ -2224,8 +2078,6 @@ static void gtk_hex_real_data_changed (GtkHex *gh, gpointer data)
{
invalidate_offsets (gh, start_line, end_line);
}
-
- TEST_DEBUG_FUNCTION_END
}
static void
@@ -2234,7 +2086,8 @@ bytes_changed (GtkHex *gh, int start, int end)
int start_line;
int end_line;
- g_return_if_fail (gh->cpl); /* check for divide-by-zero issues */
+ /* check for divide-by-zero issues */
+ g_return_if_fail (gh->cpl);
start_line = start / gh->cpl - gh->top_line;
start_line = MAX (start_line, 0);
@@ -2254,132 +2107,8 @@ bytes_changed (GtkHex *gh, int start, int end)
}
}
-// LAR - REWRITE - COPY/PASTE SHIT
-#if 0
-static void primary_get_cb(GtkClipboard *clipboard,
- GtkSelectionData *data, guint info,
- gpointer user_data)
-{
- GtkHex *gh = GTK_HEX(user_data);
-
- if (gh->selection.start != gh->selection.end)
- {
- gint start_pos;
- gint end_pos;
- guchar *text;
-
- start_pos = MIN(gh->selection.start, gh->selection.end);
- end_pos = MAX(gh->selection.start, gh->selection.end);
-
- text = hex_document_get_data(gh->document, start_pos,
- end_pos - start_pos);
- gtk_selection_data_set_text(data, text, end_pos - start_pos);
- g_free(text);
- }
-}
-
-
-static void primary_clear_cb(GtkClipboard *clipboard,
- gpointer user_data_or_owner) {
-}
-#endif
-
-void
-gtk_hex_set_selection(GtkHex *gh, gint start, gint end)
-{
- gint length = gh->document->file_size;
- gint oe, os, ne, ns;
-// GtkHexClass *klass = GTK_HEX_CLASS(GTK_WIDGET_GET_CLASS(gh));
-
- // API CHANGE - SEE CLIPBOARD STUFF. DEFER.
-#if 0
- static const GtkTargetEntry targets[] = {
- { "STRING", 0, TARGET_STRING }
- };
- static const gint n_targets = sizeof(targets) / sizeof(targets[0]);
-#endif
-
- if (end < 0)
- end = length;
-
- // CLIPBOARD - API CHANGES
-// if (gh->selection.start != gh->selection.end)
-// gtk_clipboard_clear(klass->primary);
-
- 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);
-
- gtk_hex_invalidate_highlight(gh, &gh->selection);
-
- ns = MIN(gh->selection.start, gh->selection.end);
- ne = MAX(gh->selection.start, gh->selection.end);
-
- if(ns != os && ne != oe) {
- bytes_changed(gh, MIN(ns, os), MAX(ne, oe));
- }
- else if(ne != oe) {
- bytes_changed(gh, MIN(ne, oe), MAX(ne, oe));
- }
- else if(ns != os) {
- bytes_changed(gh, MIN(ns, os), MAX(ns, os));
- }
-
- // LAR - REWRITE - COPY/PASTE SHIT
-#if 0
- if(gh->selection.start != gh->selection.end)
- gtk_clipboard_set_with_data(klass->primary, targets, n_targets,
- primary_get_cb, primary_clear_cb,
- gh);
-#endif
-}
-
-gboolean gtk_hex_get_selection(GtkHex *gh, gint *start, gint *end)
-{
- gint ss, se;
-
- if(gh->selection.start > gh->selection.end) {
- se = gh->selection.start;
- ss = gh->selection.end;
- }
- else {
- ss = gh->selection.start;
- se = gh->selection.end;
- }
-
- if(NULL != start)
- *start = ss;
- if(NULL != end)
- *end = se;
-
- return !(ss == se);
-}
-
-void gtk_hex_clear_selection(GtkHex *gh)
-{
- gtk_hex_set_selection(gh, 0, 0);
-}
-
-void gtk_hex_delete_selection(GtkHex *gh)
-{
- guint start;
- guint end;
-
- start = MIN(gh->selection.start, gh->selection.end);
- end = MAX(gh->selection.start, gh->selection.end);
-
- gtk_hex_clear_selection (gh);
-
- if(start != end) {
- if(start < gh->cursor_pos)
- gtk_hex_set_cursor(gh, gh->cursor_pos - end + start);
- hex_document_delete_data(gh->document, MIN(start, end), end - start, TRUE);
- }
-}
-
-static void gtk_hex_validate_highlight(GtkHex *gh, GtkHex_Highlight *hl)
+static void
+gtk_hex_validate_highlight(GtkHex *gh, GtkHex_Highlight *hl)
{
if (!hl->valid)
{
@@ -2389,12 +2118,14 @@ static void gtk_hex_validate_highlight(GtkHex *gh, GtkHex_Highlight *hl)
}
}
-static void gtk_hex_invalidate_highlight(GtkHex *gh, GtkHex_Highlight *hl)
+static void
+gtk_hex_invalidate_highlight (GtkHex *gh, GtkHex_Highlight *hl)
{
hl->valid = FALSE;
}
-static void gtk_hex_invalidate_all_highlights(GtkHex *gh)
+static void
+gtk_hex_invalidate_all_highlights (GtkHex *gh)
{
GtkHex_Highlight *cur = &gh->selection;
GtkHex_AutoHighlight *nextList = gh->auto_highlight;
@@ -2411,7 +2142,8 @@ static void gtk_hex_invalidate_all_highlights(GtkHex *gh)
}
}
-static GtkHex_Highlight *gtk_hex_insert_highlight (GtkHex *gh,
+static GtkHex_Highlight *
+gtk_hex_insert_highlight (GtkHex *gh,
GtkHex_AutoHighlight *ahl,
gint start, gint end)
{
@@ -2437,7 +2169,8 @@ static GtkHex_Highlight *gtk_hex_insert_highlight (GtkHex *gh,
return new;
}
-static void gtk_hex_delete_highlight (GtkHex *gh, GtkHex_AutoHighlight *ahl,
+static void
+gtk_hex_delete_highlight (GtkHex *gh, GtkHex_AutoHighlight *ahl,
GtkHex_Highlight *hl)
{
int start, end;
@@ -2456,7 +2189,8 @@ static void gtk_hex_delete_highlight (GtkHex *gh, GtkHex_AutoHighlight *ahl,
* gtk_hex_* stuff rather than hex_document_* directly
* and simply returns a gboolean.
*/
-static gboolean gtk_hex_compare_data(GtkHex *gh, guchar *cmp, guint pos, gint len)
+static gboolean
+gtk_hex_compare_data (GtkHex *gh, guchar *cmp, guint pos, gint len)
{
int i;
for (i = 0; i < len; i++)
@@ -2468,11 +2202,13 @@ static gboolean gtk_hex_compare_data(GtkHex *gh, guchar *cmp, guint pos, gint le
return TRUE;
}
-static gboolean gtk_hex_find_limited(GtkHex *gh, gchar *find, int findlen,
+static gboolean
+gtk_hex_find_limited (GtkHex *gh, gchar *find, int findlen,
guint lower, guint upper,
guint *found)
{
guint pos = lower;
+
while (pos < upper)
{
if (gtk_hex_compare_data(gh, (guchar *)find, pos, findlen))
@@ -2488,7 +2224,8 @@ static gboolean gtk_hex_find_limited(GtkHex *gh, gchar *find, int findlen,
/* removes any highlights that arn't visible
* adds any new highlights that became visible
*/
-static void gtk_hex_update_auto_highlight(GtkHex *gh, GtkHex_AutoHighlight *ahl,
+static void
+gtk_hex_update_auto_highlight(GtkHex *gh, GtkHex_AutoHighlight *ahl,
gboolean delete, gboolean add)
{
gint del_min, del_max;
@@ -2541,11 +2278,14 @@ static void gtk_hex_update_auto_highlight(GtkHex *gh, GtkHex_AutoHighlight *ahl,
gtk_hex_find_limited(gh, ahl->search_string, ahl->search_len,
MAX(add_min, foundpos+1), add_max, &foundpos))
{
- gtk_hex_insert_highlight(gh, ahl, foundpos, foundpos+(ahl->search_len)-1);
+ gtk_hex_insert_highlight(gh, ahl,
+ foundpos, foundpos+(ahl->search_len)-1);
}
}
-static void gtk_hex_update_all_auto_highlights(GtkHex *gh, gboolean delete, gboolean add)
+static void
+gtk_hex_update_all_auto_highlights (GtkHex *gh,
+ gboolean delete, gboolean add)
{
GtkHex_AutoHighlight *cur = gh->auto_highlight;
@@ -2556,21 +2296,6 @@ static void gtk_hex_update_all_auto_highlights(GtkHex *gh, gboolean delete, gboo
}
}
-void gtk_hex_copy_to_clipboard(GtkHex *gh)
-{
- g_signal_emit_by_name(G_OBJECT(gh), "copy-clipboard");
-}
-
-void gtk_hex_cut_to_clipboard(GtkHex *gh)
-{
- g_signal_emit_by_name(G_OBJECT(gh), "cut-clipboard");
-}
-
-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)
{
@@ -2583,8 +2308,6 @@ gtk_hex_real_copy_to_clipboard (GtkHex *gh)
guchar *doc_data;
char *string;
- TEST_DEBUG_FUNCTION_START
-
clipboard = gtk_widget_get_clipboard (widget);
start_pos = MIN(gh->selection.start, gh->selection.end);
@@ -2613,8 +2336,6 @@ gtk_hex_real_copy_to_clipboard (GtkHex *gh)
/* Finally, set our content to our newly created union. */
gdk_clipboard_set_content (clipboard, provider_union);
-
- TEST_DEBUG_FUNCTION_END
}
static void
@@ -2667,7 +2388,6 @@ plaintext_paste_received_cb (GObject *source_object,
}
}
-
static void
gtk_hex_real_paste_from_clipboard (GtkHex *gh,
gpointer user_data)
@@ -2679,9 +2399,7 @@ gtk_hex_real_paste_from_clipboard (GtkHex *gh,
GtkHexPasteData *paste;
gboolean have_hex_paste_data = FALSE;
- TEST_DEBUG_FUNCTION_START
-
- (void)user_data;
+ (void)user_data; /* unused */
clipboard = gtk_widget_get_clipboard (widget);
content = gdk_clipboard_get_content (clipboard);
@@ -2724,42 +2442,15 @@ gtk_hex_real_paste_from_clipboard (GtkHex *gh,
plaintext_paste_received_cb,
gh);
}
-
- TEST_DEBUG_FUNCTION_END
}
-
static void
gtk_hex_real_draw_complete (GtkHex *gh,
gpointer user_data)
{
- TEST_DEBUG_FUNCTION_START
-
(void)user_data;
- recalc_scrolling (gh);
-
- TEST_DEBUG_FUNCTION_END
-}
-static void
-gtk_hex_finalize (GObject *gobject) {
- GtkHex *gh = GTK_HEX(gobject);
-
- if (gh->disp_buffer)
- g_free (gh->disp_buffer);
-
- if (gh->xlayout)
- g_object_unref (G_OBJECT (gh->xlayout));
-
- if (gh->alayout)
- g_object_unref (G_OBJECT (gh->alayout));
-
- if (gh->olayout)
- g_object_unref (G_OBJECT (gh->olayout));
-
- /* Boilerplate; keep here. Chain up to the parent class.
- */
- G_OBJECT_CLASS(gtk_hex_parent_class)->finalize(gobject);
+ recalc_scrolling (gh);
}
static void
@@ -2771,8 +2462,6 @@ gtk_hex_snapshot (GtkWidget *widget, GtkSnapshot *snapshot)
cairo_t *cr;
GtkWidget *child;
- TEST_DEBUG_FUNCTION_START
-
/* Update character width & height */
gh->char_width = get_char_width(gh);
gh->char_height = get_char_height(gh);
@@ -2805,8 +2494,6 @@ gtk_hex_snapshot (GtkWidget *widget, GtkSnapshot *snapshot)
}
g_signal_emit_by_name(G_OBJECT(gh), "draw-complete");
-
- TEST_DEBUG_FUNCTION_END
}
static void
@@ -2824,13 +2511,62 @@ gtk_hex_document_changed (HexDocument* doc, gpointer change_data,
"gtkhex.redo", hex_document_can_redo (doc));
}
+static void
+gtk_hex_dispose (GObject *object)
+{
+ GtkHex *gh = GTK_HEX(object);
+ GtkWidget *widget = GTK_WIDGET(gh);
+ GtkWidget *child;
+
+ /* Unparent children
+ */
+ g_clear_pointer (&gh->xdisp, gtk_widget_unparent);
+ g_clear_pointer (&gh->adisp, gtk_widget_unparent);
+ g_clear_pointer (&gh->offsets, gtk_widget_unparent);
+ g_clear_pointer (&gh->scrollbar, gtk_widget_unparent);
+
+ /* Clear layout manager
+ */
+ g_clear_object (&gh->layout_manager);
+
+ /* Clear pango layouts
+ */
+ g_clear_object (&gh->xlayout);
+ g_clear_object (&gh->alayout);
+ g_clear_object (&gh->olayout);
+
+ /* Chain up */
+ G_OBJECT_CLASS(gtk_hex_parent_class)->dispose(object);
+}
+
+static void
+gtk_hex_finalize (GObject *gobject)
+{
+ GtkHex *gh = GTK_HEX(gobject);
+
+ if (gh->disp_buffer)
+ g_free (gh->disp_buffer);
+
+ /* Boilerplate; keep here. Chain up to the parent class.
+ */
+ G_OBJECT_CLASS(gtk_hex_parent_class)->finalize(gobject);
+}
+
+
static void
gtk_hex_class_init (GtkHexClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ /* vfuncs */
+
+ object_class->dispose = gtk_hex_dispose;
+ object_class->finalize = gtk_hex_finalize;
+ widget_class->snapshot = gtk_hex_snapshot;
+
/* Layout manager: box-style layout. */
+
gtk_widget_class_set_layout_manager_type (widget_class,
GTK_TYPE_HEX_LAYOUT);
@@ -2909,23 +2645,23 @@ gtk_hex_class_init (GtkHexClass *klass)
/* ACTIONS */
gtk_widget_class_install_action (widget_class, "gtkhex.copy",
- NULL, // GVariant string param_type
+ NULL, /* GVariant string param_type */
copy_action);
gtk_widget_class_install_action (widget_class, "gtkhex.cut",
- NULL, // GVariant string param_type
+ NULL,
cut_action);
gtk_widget_class_install_action (widget_class, "gtkhex.paste",
- NULL, // GVariant string param_type
+ NULL,
paste_action);
gtk_widget_class_install_action (widget_class, "gtkhex.undo",
- NULL, // GVariant string param_type
+ NULL,
undo_action);
gtk_widget_class_install_action (widget_class, "gtkhex.redo",
- NULL, // GVariant string param_type
+ NULL,
redo_action);
/* SHORTCUTS FOR ACTIONS (not to be confused with keybindings, which are
@@ -2936,38 +2672,35 @@ gtk_hex_class_init (GtkHexClass *klass)
GDK_KEY_c,
GDK_CONTROL_MASK,
"gtkhex.copy",
- NULL); // no args.
+ NULL); /* no args. */
/* Ctrl+x - cut */
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_x,
GDK_CONTROL_MASK,
"gtkhex.cut",
- NULL); // no args.
+ NULL);
/* Ctrl+v - paste */
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_v,
GDK_CONTROL_MASK,
"gtkhex.paste",
- NULL); // no args.
+ NULL);
/* Ctrl+z - undo */
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_z,
GDK_CONTROL_MASK,
"gtkhex.undo",
- NULL); // no args.
+ NULL);
/* Ctrl+y - redo */
gtk_widget_class_add_binding_action (widget_class,
GDK_KEY_y,
GDK_CONTROL_MASK,
"gtkhex.redo",
- NULL); // no args.
-
- widget_class->snapshot = gtk_hex_snapshot;
- object_class->finalize = gtk_hex_finalize;
+ NULL);
}
static void
@@ -3017,10 +2750,6 @@ 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);
-
-
/* Init CSS */
/* Set context var to the widget's context at large. */
@@ -3034,14 +2763,6 @@ gtk_hex_init(GtkHex *gh)
" font-size: 12pt;\n"
" padding-left: 12px;\n"
" padding-right: 12px;\n"
-// example of how to style a specific widget:
-#if 0
- "}\n"
- "#asciidisplay {\n"
- " border-style: solid;\n"
- " border-width: 2px;\n"
- " border-color: blue;\n"
-#endif
"}\n", -1);
/* add the provider to our widget's style context. */
@@ -3057,20 +2778,14 @@ gtk_hex_init(GtkHex *gh)
(gh->layout_manager, gh->offsets));
gtk_hex_layout_child_set_column (child_info, OFFSETS_COLUMN);
-// gtk_widget_set_halign (gh->offsets, GTK_ALIGN_START);
-// gtk_widget_set_hexpand (gh->offsets, FALSE);
-
/* Create the pango layout for the widget */
gh->olayout = gtk_widget_create_pango_layout (gh->offsets, "");
-// gtk_widget_set_events (gh->offsets, GDK_EXPOSURE_MASK);
-
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (gh->offsets),
- offsets_draw, // GtkDrawingAreaDrawFunc draw_func,
- gh, // gpointer user_data,
- NULL); // GDestroyNotify destroy);
+ offsets_draw,
+ gh,
+ NULL); /* GDestroyNotify destroy); */
- // FIXME - not sure what this buys us. Monitor. - header class?
context = gtk_widget_get_style_context (GTK_WIDGET (gh->offsets));
gtk_style_context_add_class (context, "header");
@@ -3090,12 +2805,11 @@ gtk_hex_init(GtkHex *gh)
gh->xlayout = gtk_widget_create_pango_layout (gh->xdisp, "");
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (gh->xdisp),
- hex_draw, // GtkDrawingAreaDrawFunc draw_func,
- gh, // gpointer user_data,
- NULL); // GDestroyNotify destroy);
-
+ hex_draw,
+ gh,
+ NULL); /* GDestroyNotify destroy); */
- /* Set context var to hex widget's context... */
+ /* Set context var to hex widget's context */
context = gtk_widget_get_style_context (GTK_WIDGET (gh->xdisp));
/* ... and add view class so we get certain theme colours for free. */
gtk_style_context_add_class (context, "view");
@@ -3110,14 +2824,12 @@ gtk_hex_init(GtkHex *gh)
(gh->layout_manager, gh->adisp));
gtk_hex_layout_child_set_column (child_info, ASCII_COLUMN);
- gtk_widget_set_name (gh->adisp, "asciidisplay");
-
/* Create the pango layout for the widget */
gh->alayout = gtk_widget_create_pango_layout (gh->adisp, "");
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (gh->adisp),
- ascii_draw, /* GtkDrawingAreaDrawFunc draw_func, */
- gh, /* gpointer user_data, */
+ ascii_draw,
+ gh,
NULL); /* GDestroyNotify destroy); */
/* Rinse and repeat as above for ascii widget / context / view. */
@@ -3135,7 +2847,6 @@ gtk_hex_init(GtkHex *gh)
DEFAULT_DA_SIZE, DEFAULT_DA_SIZE);
/* Initialize Adjustment */
-
gh->adj = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
/* Setup scrollbar. */
@@ -3170,7 +2881,8 @@ gtk_hex_init(GtkHex *gh)
/* drag gestures */
gesture = gtk_gesture_drag_new ();
- // TODO - IF NEEDED
+ /* FIXME/TODO - Some boilerplate if decide to use these signals. If
+ * still unused by 4.0 beta, just remove. */
#if 0
g_signal_connect (gesture, "drag-begin",
G_CALLBACK(hex_drag_begin_cb),
@@ -3205,7 +2917,8 @@ gtk_hex_init(GtkHex *gh)
/* drag gestures */
gesture = gtk_gesture_drag_new ();
-// TODO IF NEEDED
+ /* FIXME/TODO - Some boilerplate if decide to use these signals. If
+ * still unused by 4.0 beta, just remove. */
#if 0
g_signal_connect (gesture, "drag-begin",
G_CALLBACK(ascii_drag_begin_cb),
@@ -3261,7 +2974,9 @@ gtk_hex_init(GtkHex *gh)
"gtkhex.redo", FALSE);
}
-GtkWidget *gtk_hex_new(HexDocument *owner) {
+GtkWidget *
+gtk_hex_new (HexDocument *owner)
+{
GtkHex *gh;
gh = GTK_HEX (g_object_new (GTK_TYPE_HEX, NULL));
@@ -3269,8 +2984,8 @@ GtkWidget *gtk_hex_new(HexDocument *owner) {
gh->document = owner;
- /* Setup document signals (can't do in _init because we don't have
- * access to that object yet.
+ /* Setup document signals
+ * (can't do in _init because we don't have access to that object yet).
*/
g_signal_connect (G_OBJECT (gh->document), "document-changed",
G_CALLBACK (gtk_hex_document_changed), gh);
@@ -3287,15 +3002,113 @@ GtkWidget *gtk_hex_new(HexDocument *owner) {
/*-------- public API starts here --------*/
+void
+gtk_hex_copy_to_clipboard (GtkHex *gh)
+{
+ g_signal_emit_by_name(G_OBJECT(gh), "copy-clipboard");
+}
+
+void
+gtk_hex_cut_to_clipboard (GtkHex *gh)
+{
+ g_signal_emit_by_name(G_OBJECT(gh), "cut-clipboard");
+}
+
+void
+gtk_hex_paste_from_clipboard (GtkHex *gh)
+{
+ g_signal_emit_by_name(G_OBJECT(gh), "paste-clipboard");
+}
+
+void
+gtk_hex_set_selection (GtkHex *gh, gint start, gint end)
+{
+ gint length = gh->document->file_size;
+ gint oe, os, ne, ns;
+
+ if (end < 0)
+ end = length;
+
+ 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);
+
+ gtk_hex_invalidate_highlight(gh, &gh->selection);
+
+ ns = MIN(gh->selection.start, gh->selection.end);
+ ne = MAX(gh->selection.start, gh->selection.end);
+
+ if (ns != os && ne != oe) {
+ bytes_changed(gh, MIN(ns, os), MAX(ne, oe));
+ }
+ else if (ne != oe) {
+ bytes_changed(gh, MIN(ne, oe), MAX(ne, oe));
+ }
+ else if (ns != os) {
+ bytes_changed(gh, MIN(ns, os), MAX(ns, os));
+ }
+}
+
+gboolean
+gtk_hex_get_selection (GtkHex *gh, gint *start, gint *end)
+{
+ gint ss, se;
+
+ if(gh->selection.start > gh->selection.end) {
+ se = gh->selection.start;
+ ss = gh->selection.end;
+ }
+ else {
+ ss = gh->selection.start;
+ se = gh->selection.end;
+ }
+
+ if (start)
+ *start = ss;
+ if (end)
+ *end = se;
+
+ return !(ss == se);
+}
+
+void
+gtk_hex_clear_selection(GtkHex *gh)
+{
+ gtk_hex_set_selection(gh, 0, 0);
+}
+
+void
+gtk_hex_delete_selection(GtkHex *gh)
+{
+ guint start;
+ guint end;
+
+ start = MIN(gh->selection.start, gh->selection.end);
+ end = MAX(gh->selection.start, gh->selection.end);
+
+ gtk_hex_clear_selection (gh);
+
+ if (start != end)
+ {
+ if (start < gh->cursor_pos)
+ gtk_hex_set_cursor (gh, gh->cursor_pos - end + start);
+
+ hex_document_delete_data (gh->document,
+ MIN(start, end), end - start, TRUE);
+ }
+}
/*
* moves cursor to UPPER_NIBBLE or LOWER_NIBBLE of the current byte
*/
-void gtk_hex_set_nibble(GtkHex *gh, gint lower_nibble) {
- g_return_if_fail(gh != NULL);
- g_return_if_fail(GTK_IS_HEX(gh));
+void
+gtk_hex_set_nibble (GtkHex *gh, gint lower_nibble)
+{
+ g_return_if_fail (GTK_IS_HEX(gh));
- if(gh->selecting) {
+ if (gh->selecting) {
bytes_changed(gh, gh->cursor_pos, gh->cursor_pos);
gh->lower_nibble = lower_nibble;
}
@@ -3324,7 +3137,8 @@ gtk_hex_set_cursor(GtkHex *gh, gint index) {
g_return_if_fail(gh != NULL);
g_return_if_fail(GTK_IS_HEX(gh));
- if((index >= 0) && (index <= gh->document->file_size)) {
+ if ((index >= 0) && (index <= gh->document->file_size))
+ {
if(!gh->insert && index == gh->document->file_size)
index--;
@@ -3339,9 +3153,10 @@ gtk_hex_set_cursor(GtkHex *gh, gint index) {
y = index / gh->cpl;
if(y >= gh->top_line + gh->vis_lines) {
- gtk_adjustment_set_value(gh->adj, MIN(y - gh->vis_lines + 1, gh->lines -
gh->vis_lines));
- gtk_adjustment_set_value(gh->adj, MAX(gtk_adjustment_get_value(gh->adj), 0));
-
+ gtk_adjustment_set_value(gh->adj,
+ MIN(y - gh->vis_lines + 1, gh->lines - gh->vis_lines));
+ gtk_adjustment_set_value(gh->adj,
+ MAX(gtk_adjustment_get_value(gh->adj), 0));
}
else if (y < gh->top_line) {
gtk_adjustment_set_value(gh->adj, y);
@@ -3352,7 +3167,9 @@ gtk_hex_set_cursor(GtkHex *gh, gint index) {
if(gh->selecting) {
gtk_hex_set_selection(gh, gh->selection.start, gh->cursor_pos);
- bytes_changed(gh, MIN(gh->cursor_pos, old_pos), MAX(gh->cursor_pos, old_pos));
+ bytes_changed (gh,
+ MIN(gh->cursor_pos, old_pos), MAX(gh->cursor_pos,
+ old_pos));
}
else {
guint start = MIN(gh->selection.start, gh->selection.end);
@@ -3369,9 +3186,12 @@ gtk_hex_set_cursor(GtkHex *gh, gint index) {
}
/*
- * moves cursor to column x in line y (in the whole buffer, not just the currently visible part)
+ * moves cursor to column x in line y (in the whole buffer, not just the
+ * currently visible part)
*/
-void gtk_hex_set_cursor_xy(GtkHex *gh, gint x, gint y) {
+void
+gtk_hex_set_cursor_xy (GtkHex *gh, gint x, gint y)
+{
gint cp;
guint old_pos = gh->cursor_pos;
@@ -3380,9 +3200,10 @@ void gtk_hex_set_cursor_xy(GtkHex *gh, gint x, gint y) {
cp = y*gh->cpl + x;
- if((y >= 0) && (y < gh->lines) && (x >= 0) &&
- (x < gh->cpl) && (cp <= gh->document->file_size)) {
- if(!gh->insert && cp == gh->document->file_size)
+ if ((y >= 0) && (y < gh->lines) && (x >= 0) &&
+ (x < gh->cpl) && (cp <= gh->document->file_size))
+ {
+ if (!gh->insert && cp == gh->document->file_size)
cp--;
cp = MAX(cp, 0);
@@ -3391,9 +3212,11 @@ void gtk_hex_set_cursor_xy(GtkHex *gh, gint x, gint y) {
gh->cursor_pos = cp;
- if(y >= gh->top_line + gh->vis_lines) {
- gtk_adjustment_set_value(gh->adj, MIN(y - gh->vis_lines + 1, gh->lines -
gh->vis_lines));
- gtk_adjustment_set_value(gh->adj, MAX(0, gtk_adjustment_get_value(gh->adj)));
+ if (y >= gh->top_line + gh->vis_lines) {
+ gtk_adjustment_set_value (gh->adj,
+ MIN(y - gh->vis_lines + 1, gh->lines - gh->vis_lines));
+ gtk_adjustment_set_value (gh->adj,
+ MAX(0, gtk_adjustment_get_value(gh->adj)));
}
else if (y < gh->top_line) {
gtk_adjustment_set_value(gh->adj, y);
@@ -3401,11 +3224,13 @@ void gtk_hex_set_cursor_xy(GtkHex *gh, gint x, gint y) {
g_signal_emit_by_name(G_OBJECT(gh), "cursor-moved");
- if(gh->selecting) {
+ if (gh->selecting) {
gtk_hex_set_selection(gh, gh->selection.start, gh->cursor_pos);
- bytes_changed(gh, MIN(gh->cursor_pos, old_pos), MAX(gh->cursor_pos, old_pos));
+ bytes_changed(gh,
+ MIN(gh->cursor_pos, old_pos), MAX(gh->cursor_pos,
+ old_pos));
}
- else if(gh->selection.end != gh->selection.start) {
+ else if (gh->selection.end != gh->selection.start) {
guint start = MIN(gh->selection.start, gh->selection.end);
guint end = MAX(gh->selection.start, gh->selection.end);
gh->selection.end = gh->selection.start = 0;
@@ -3419,7 +3244,9 @@ void gtk_hex_set_cursor_xy(GtkHex *gh, gint x, gint y) {
/*
* returns cursor position
*/
-guint gtk_hex_get_cursor(GtkHex *gh) {
+guint
+gtk_hex_get_cursor(GtkHex *gh)
+{
g_return_val_if_fail(gh != NULL, -1);
g_return_val_if_fail(GTK_IS_HEX(gh), -1);
@@ -3429,7 +3256,9 @@ guint gtk_hex_get_cursor(GtkHex *gh) {
/*
* returns value of the byte at position offset
*/
-guchar gtk_hex_get_byte(GtkHex *gh, guint offset) {
+guchar
+gtk_hex_get_byte (GtkHex *gh, guint offset)
+{
g_return_val_if_fail(gh != NULL, 0);
g_return_val_if_fail(GTK_IS_HEX(gh), 0);
@@ -3442,17 +3271,23 @@ guchar gtk_hex_get_byte(GtkHex *gh, guint offset) {
/*
* sets data group type (see GROUP_* defines at top of file)
*/
-void gtk_hex_set_group_type(GtkHex *gh, guint gt) {
+void
+gtk_hex_set_group_type (GtkHex *gh, guint gt)
+{
+ /* FIXME - See comment above about redraws. */
+#if 0
GtkAllocation allocation;
+#endif
g_return_if_fail(gh != NULL);
g_return_if_fail(GTK_IS_HEX(gh));
hide_cursor(gh);
gh->group_type = gt;
+#if 0
gtk_widget_get_allocation(GTK_WIDGET(gh), &allocation);
- // TEST
-// recalc_displays(gh, allocation.width, allocation.height);
+ recalc_displays(gh, allocation.width, allocation.height);
+#endif
recalc_displays(gh);
gtk_widget_queue_resize(GTK_WIDGET(gh));
show_cursor(gh);
@@ -3461,29 +3296,32 @@ void gtk_hex_set_group_type(GtkHex *gh, guint gt) {
/*
* do we show the offsets of lines?
*/
-void gtk_hex_show_offsets(GtkHex *gh, gboolean show)
+void
+gtk_hex_show_offsets(GtkHex *gh, gboolean show)
{
g_return_if_fail(gh != NULL);
g_return_if_fail(GTK_IS_HEX(gh));
- if(gh->show_offsets == show)
+ if (gh->show_offsets == show)
return;
gh->show_offsets = show;
- if(show)
+ if (show)
show_offsets_widget(gh);
else
hide_offsets_widget(gh);
}
-void gtk_hex_set_starting_offset(GtkHex *gh, gint starting_offset)
+void
+gtk_hex_set_starting_offset (GtkHex *gh, gint starting_offset)
{
g_return_if_fail (gh != NULL);
g_return_if_fail(GTK_IS_HEX(gh));
gh->starting_offset = starting_offset;
}
-void gtk_hex_set_insert_mode(GtkHex *gh, gboolean insert)
+void
+gtk_hex_set_insert_mode (GtkHex *gh, gboolean insert)
{
g_return_if_fail(gh != NULL);
g_return_if_fail(GTK_IS_HEX(gh));
diff --git a/src/gtkhex.h b/src/gtkhex.h
index bfd77bca..124bbd6d 100644
--- a/src/gtkhex.h
+++ b/src/gtkhex.h
@@ -9,7 +9,7 @@
to maintain the source code under the licensing terms described
herein and below.
- Copyright © 2021 Logan Rathbone
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
GHex is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -43,12 +43,14 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE(GtkHex, gtk_hex, GTK, HEX, GtkWidget)
/* DEFINES */
+
/* how to group bytes? */
#define GROUP_BYTE 1
#define GROUP_WORD 2
#define GROUP_LONG 4
/* OPAQUE DATATYPES */
+
typedef struct _GtkHex_AutoHighlight GtkHex_AutoHighlight;
/* PUBLIC METHOD DECLARATIONS */
diff --git a/src/hex-dialog.c b/src/hex-dialog.c
index 29b31f58..6fa6dc3a 100644
--- a/src/hex-dialog.c
+++ b/src/hex-dialog.c
@@ -1,8 +1,15 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
- * Copright (c) David Hammerton 2003
+ * Copright © David Hammerton 2003
* David Hammerton <crazney crazney net>
*
+ * Copyright © 2004-2020 Various individual contributors, including
+ * but not limited to: Jonathon Jongsma, Kalev Lember, who continued to
+ * maintain the source code under the licensing terms described
+ * herein and below.
+ *
+ * Copyright © 2021 Logan Rathbone <poprocks gmail com>
+ *
* GHex is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
diff --git a/src/hex-dialog.h b/src/hex-dialog.h
index 14b6456a..eae8133e 100644
--- a/src/hex-dialog.h
+++ b/src/hex-dialog.h
@@ -3,6 +3,13 @@
* Copright (c) David Hammerton 2003
* David Hammerton <crazney crazney net>
*
+ * Copyright © 2004-2020 Various individual contributors, including
+ * but not limited to: Jonathon Jongsma, Kalev Lember, who continued to
+ * maintain the source code under the licensing terms described
+ * herein and below.
+ *
+ * Copyright © 2021 Logan Rathbone <poprocks gmail com>
+ *
* GHex is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
diff --git a/src/hex-document.c b/src/hex-document.c
index 1da6dcd9..22506517 100644
--- a/src/hex-document.c
+++ b/src/hex-document.c
@@ -5,6 +5,13 @@
Copyright (C) 1998 - 2004 Free Software Foundation
+ Copyright © 2005-2020 Various individual contributors, including
+ but not limited to: Jonathon Jongsma, Kalev Lember, who continued
+ to maintain the source code under the licensing terms described
+ herein and below.
+
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
+
GHex is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
@@ -264,10 +271,7 @@ hex_document_add_view(HexDocument *doc)
new_view = gtk_hex_new(doc);
- // LAR - I DON'T THINK GTK4 HAS THIS CONCEPT ANYMORE.
-// gtk_widget_set_has_window (GTK_WIDGET (new_view), TRUE);
-
- g_object_ref(new_view);
+ g_object_ref (new_view);
doc->views = g_list_append(doc->views, new_view);
@@ -821,21 +825,17 @@ hex_document_export_html(HexDocument *doc, gchar *html_path, gchar *base_name,
progress_dialog = gtk_dialog_new();
gtk_window_set_resizable(GTK_WINDOW(progress_dialog), FALSE);
gtk_window_set_modal(GTK_WINDOW(progress_dialog), TRUE);
- // LAR - TEST - API CHANGE
+
g_signal_connect(G_OBJECT(progress_dialog), "close",
G_CALLBACK(ignore_dialog_cb), NULL);
-// g_signal_connect(G_OBJECT(progress_dialog), "delete-event",
-// G_CALLBACK(ignore_cb), NULL);
gtk_window_set_title(GTK_WINDOW(progress_dialog),
_("Saving to HTML..."));
+
progress_bar = gtk_progress_bar_new();
gtk_widget_show(progress_bar);
- // LAR - TEST FOR GTK4 - API CHANGE
+
gtk_box_append (GTK_BOX (gtk_dialog_get_content_area(GTK_DIALOG (progress_dialog))),
progress_bar);
-// gtk_widget_set_parent (progress_bar, progress_dialog);
-// gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(progress_dialog))),
-// progress_bar);
gtk_widget_show(progress_dialog);
pos = start;
@@ -848,13 +848,11 @@ hex_document_export_html(HexDocument *doc, gchar *html_path, gchar *base_name,
gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar),
progress_str);
g_free(progress_str);
- // LAR - ABI CHANGE - TEST FOR GTK4
+
while (g_main_context_pending (NULL)) { /* GMainContext - NULL == default */
g_main_context_iteration (NULL, /* " " */
FALSE); /* gboolean may_block */
}
-// while(gtk_events_pending())
-// gtk_main_iteration();
}
/* write page header */
page_name = g_strdup_printf("%s/%s%08d.html",
@@ -956,9 +954,7 @@ hex_document_export_html(HexDocument *doc, gchar *html_path, gchar *base_name,
fclose(file);
}
g_object_unref(G_OBJECT(doc));
- // LAR - TEST FOR GTK4 - API CHANGE
gtk_window_destroy(GTK_WINDOW (progress_dialog));
-// gtk_widget_destroy(progress_dialog);
return TRUE;
}
@@ -1182,4 +1178,3 @@ hex_document_can_redo (HexDocument *doc)
else
return FALSE;
}
-
diff --git a/src/hex-document.h b/src/hex-document.h
index 9067cbec..b4158113 100644
--- a/src/hex-document.h
+++ b/src/hex-document.h
@@ -1,8 +1,17 @@
+/* vim: colorcolumn=80 ts=4 sw=4
+ */
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* hex-document.h
Copyright (C) 1998 - 2002 Free Software Foundation
+ Copyright © 2003-2020 Various individual contributors, including
+ but not limited to: Jonathon Jongsma, Kalev Lember, who continued
+ to maintain the source code under the licensing terms described
+ herein and below.
+
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
+
GHex is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
@@ -130,7 +139,8 @@ 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);
+gboolean hex_document_change_file_name (HexDocument *doc,
+ const char *new_file_name);
gboolean hex_document_can_undo (HexDocument *doc);
gboolean hex_document_can_redo (HexDocument *doc);
diff --git a/src/main.c b/src/main.c
index c2747bf6..3e933c1d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4,7 +4,13 @@
/* main.c - genesis of a GHex application
Copyright © 1998 - 2004 Free Software Foundation
- Copyright © 2021 Logan Rathbone
+
+ Copyright © 2005-2020 Various individual contributors, including
+ but not limited to: Jonathon Jongsma, Kalev Lember, who continued
+ to maintain the source code under the licensing terms described
+ herein and below.
+
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
GHex is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
diff --git a/src/meson.build b/src/meson.build
index 9861eab3..9e3ef1f3 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -59,14 +59,8 @@ ghex_sources = [
'findreplace.h',
'ghex-application-window.c',
'ghex-application-window.h',
- 'gtkhex.c',
- 'gtkhex.h',
- 'gtkhex-layout-manager.c',
- 'gtkhex-layout-manager.h',
'hex-dialog.c',
'hex-dialog.h',
- 'hex-document.c',
- 'hex-document.h',
'main.c',
'preferences.c',
'preferences.h',
diff --git a/src/preferences.c b/src/preferences.c
index f7989f69..8883a60c 100644
--- a/src/preferences.c
+++ b/src/preferences.c
@@ -1,10 +1,16 @@
/* vim: colorcolumn=80 ts=4 sw=4
*/
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
-/* FIXME.c - a window with a character table
+/* preferences.c - Preferences dialog for GHex
Copyright © 1998 - 2004 Free Software Foundation
- Copyright © 2021 Logan Rathbone
+
+ Copyright © 2005-2020 Various individual contributors, including
+ but not limited to: Jonathon Jongsma, Kalev Lember, who continued
+ to maintain the source code under the licensing terms described
+ herein and below.
+
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
GHex is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
diff --git a/src/preferences.h b/src/preferences.h
index 47756f5f..fd6d43f7 100644
--- a/src/preferences.h
+++ b/src/preferences.h
@@ -4,7 +4,13 @@
/* preferences.h - Declarations pertaining to preferences
Copyright (C) 2004 Free Software Foundation
- Copyright © 2021 Logan Rathbone
+
+ Copyright © 2005-2020 Various individual contributors, including
+ but not limited to: Jonathon Jongsma, Kalev Lember, who continued
+ to maintain the source code under the licensing terms described
+ herein and below.
+
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
GHex is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
diff --git a/src/preferences.ui b/src/preferences.ui
index 2751f678..86b2b219 100644
--- a/src/preferences.ui
+++ b/src/preferences.ui
@@ -1,6 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- vim: ts=2 sw=2 foldmethod=indent
+<!-- vim: ts=2 sw=2
+-->
+<!--
+ Copyright © 2021 Logan Rathbone <poprocks gmail com>
+
+ GHex is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ GHex is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GHex; see the file COPYING.
+ If not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ Original GHex Author: Jaka Mocnik <jaka gnu org>
-->
<interface>
diff --git a/src/print.c b/src/print.c
index 9f057faa..37505d95 100644
--- a/src/print.c
+++ b/src/print.c
@@ -32,9 +32,6 @@
#define is_printable(c) (((((guchar)c)>=0x20) && (((guchar)c)<0x7F))?1:0)
-char *data_font_name, *header_font_name;
-guint shaded_box_size;
-
static void print_header(GHexPrintJobInfo *pji, unsigned int page);
static void print_row(GHexPrintJobInfo *pji, unsigned int offset,
unsigned int bytes, int row);
diff --git a/src/print.h b/src/print.h
index 46290f3d..cf32c46a 100644
--- a/src/print.h
+++ b/src/print.h
@@ -28,8 +28,10 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
-#include <gtkhex.h>
-#include <hex-document.h>
+
+#include "gtkhex.h"
+#include "hex-document.h"
+#include "configuration.h"
G_BEGIN_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]