[ghex/custom-statusbar] Initial commit: custom statusbar with monospace support
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ghex/custom-statusbar] Initial commit: custom statusbar with monospace support
- Date: Wed, 20 Apr 2022 18:01:48 +0000 (UTC)
commit fdda2944d31a9acdb5fe7d858d3596ffbbf2d630
Author: Logan Rathbone <poprocks gmail com>
Date: Wed Apr 20 13:59:22 2022 -0400
Initial commit: custom statusbar with monospace support
src/ghex-application-window.c | 29 ++--------
src/ghex-application-window.h | 1 +
src/ghex-application-window.ui.in | 2 +-
src/hex-statusbar.c | 109 ++++++++++++++++++++++++++++++++++++++
src/hex-statusbar.h | 38 +++++++++++++
src/meson.build | 1 +
6 files changed, 155 insertions(+), 25 deletions(-)
---
diff --git a/src/ghex-application-window.c b/src/ghex-application-window.c
index 563871e..fecd752 100644
--- a/src/ghex-application-window.c
+++ b/src/ghex-application-window.c
@@ -56,7 +56,6 @@ struct _GHexApplicationWindow
HexDialog *dialog;
GtkWidget *dialog_widget;
GtkCssProvider *conversions_box_provider;
- guint statusbar_id;
GtkAdjustment *adj;
gboolean can_save;
gboolean insert_mode;
@@ -146,7 +145,6 @@ static void ghex_application_window_remove_tab (GHexApplicationWindow *self,
GHexNotebookTab *tab);
static GHexNotebookTab * ghex_application_window_get_current_tab (GHexApplicationWindow *self);
-static void set_statusbar (GHexApplicationWindow *self, const char *str);
static void update_status_message (GHexApplicationWindow *self);
static void update_gui_data (GHexApplicationWindow *self);
static gboolean assess_can_save (HexDocument *doc);
@@ -1432,23 +1430,6 @@ open_preferences (GtkWidget *widget,
/* --- */
-static void
-set_statusbar (GHexApplicationWindow *self, const char *str)
-{
- guint id =
- gtk_statusbar_get_context_id (GTK_STATUSBAR(self->statusbar),
- "status");
-
- gtk_statusbar_pop (GTK_STATUSBAR(self->statusbar), id);
- gtk_statusbar_push (GTK_STATUSBAR(self->statusbar), id, str);
-}
-
-static void
-clear_statusbar (GHexApplicationWindow *self)
-{
- set_statusbar (self, " ");
-}
-
static void
update_status_message (GHexApplicationWindow *self)
{
@@ -1464,19 +1445,19 @@ update_status_message (GHexApplicationWindow *self)
if (hex_widget_get_selection (ACTIVE_GH, &ss, &se))
{
status = g_strdup_printf (
- _("Offset: 0x%lX; 0x%lX bytes from 0x%lX to 0x%lX selected"),
+ _("Offset: <tt>0x%lX</tt>; <tt>0x%lX</tt> bytes from <tt>0x%lX</tt> to
<tt>0x%lX</tt> selected"),
current_pos, se - ss + 1, ss, se);
}
else {
- status = g_strdup_printf (_("Offset: 0x%lX"), current_pos);
+ status = g_strdup_printf (_("Offset: <tt>0x%lX</tt>"), current_pos);
}
- set_statusbar (self, status);
+ hex_statusbar_set_status (HEX_STATUSBAR(self->statusbar), status);
g_free (status);
return;
out:
- clear_statusbar (self);
+ hex_statusbar_clear (HEX_STATUSBAR(self->statusbar));
}
@@ -1691,7 +1672,7 @@ ghex_application_window_init (GHexApplicationWindow *self)
g_signal_connect (self->jump_dialog, "closed",
G_CALLBACK(pane_close_cb), self);
- clear_statusbar (self);
+ hex_statusbar_clear (HEX_STATUSBAR(self->statusbar));
/* Grey out main actions at the beginning */
enable_main_actions (self, FALSE);
diff --git a/src/ghex-application-window.h b/src/ghex-application-window.h
index f5c9c8d..199a16a 100644
--- a/src/ghex-application-window.h
+++ b/src/ghex-application-window.h
@@ -31,6 +31,7 @@
#include "gtkhex.h"
#include "configuration.h"
#include "ghex-notebook-tab.h"
+#include "hex-statusbar.h"
#include "hex-dialog.h"
#include "findreplace.h"
#include "chartable.h"
diff --git a/src/ghex-application-window.ui.in b/src/ghex-application-window.ui.in
index 092228f..4164d7e 100644
--- a/src/ghex-application-window.ui.in
+++ b/src/ghex-application-window.ui.in
@@ -277,7 +277,7 @@
<child>
- <object class="GtkStatusbar" id="statusbar">
+ <object class="HexStatusbar" id="statusbar">
<property name="hexpand">true</property>
</object>
</child>
diff --git a/src/hex-statusbar.c b/src/hex-statusbar.c
new file mode 100644
index 0000000..af8be6a
--- /dev/null
+++ b/src/hex-statusbar.c
@@ -0,0 +1,109 @@
+/* vim: ts=4 sw=4 colorcolumn=80
+ * -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * hex-statusbar.c: definition of HexStatusbar widget
+ *
+ * Copyright © 2022 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.
+ */
+
+#include "hex-statusbar.h"
+
+/* GOBJECT DEFINITION */
+
+struct _HexStatusbar
+{
+ GtkWidget parent_instance;
+
+ GtkWidget *label;
+};
+
+G_DEFINE_TYPE (HexStatusbar, hex_statusbar, GTK_TYPE_WIDGET)
+
+
+/* METHOD DEFINITIONS */
+
+static void
+hex_statusbar_init (HexStatusbar *self)
+{
+ GtkWidget *widget = GTK_WIDGET(self);
+
+ self->label = gtk_label_new (NULL);
+ gtk_widget_set_parent (self->label, widget);
+}
+
+static void
+hex_statusbar_dispose (GObject *object)
+{
+ HexStatusbar *self = HEX_STATUSBAR(object);
+ GtkWidget *widget = GTK_WIDGET(self);
+
+ g_clear_pointer (&self->label, gtk_widget_unparent);
+
+ /* Chain up */
+ G_OBJECT_CLASS(hex_statusbar_parent_class)->dispose (object);
+}
+
+static void
+hex_statusbar_finalize (GObject *object)
+{
+ HexStatusbar *self = HEX_STATUSBAR(object);
+
+ /* Chain up */
+ G_OBJECT_CLASS(hex_statusbar_parent_class)->finalize (object);
+}
+
+static void
+hex_statusbar_class_init (HexStatusbarClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
+
+ object_class->dispose = hex_statusbar_dispose;
+ object_class->finalize = hex_statusbar_finalize;
+
+ gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
+ gtk_widget_class_set_css_name (widget_class, "statusbar");
+}
+
+/* PUBLIC METHOD DEFINITIONS */
+
+GtkWidget *
+hex_statusbar_new (void)
+{
+ return g_object_new (HEX_TYPE_STATUSBAR, NULL);
+}
+
+void
+hex_statusbar_set_status (HexStatusbar *self, const char *msg)
+{
+ g_return_if_fail (HEX_IS_STATUSBAR (self));
+ /* Programmer error to pass null to this. Should use _clear instead. */
+ g_return_if_fail (msg && *msg);
+
+ gtk_label_set_markup (GTK_LABEL(self->label), msg);
+}
+
+void
+hex_statusbar_clear (HexStatusbar *self)
+{
+ g_return_if_fail (HEX_IS_STATUSBAR (self));
+
+ /* Technically nothing in the gtk docs says you can pass NULL to this
+ * function. */
+ gtk_label_set_markup (GTK_LABEL(self->label), "");
+}
diff --git a/src/hex-statusbar.h b/src/hex-statusbar.h
new file mode 100644
index 0000000..9a12a1d
--- /dev/null
+++ b/src/hex-statusbar.h
@@ -0,0 +1,38 @@
+/* vim: ts=4 sw=4 colorcolumn=80
+ * -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * hex-statusbar.h: declaration of HexStatusbar widget
+ *
+ * Copyright © 2022 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.
+ */
+
+#ifndef HEX_STATUSBAR_H
+#define HEX_STATUSBAR_H
+
+#include <gtk/gtk.h>
+
+#define HEX_TYPE_STATUSBAR (hex_statusbar_get_type ())
+G_DECLARE_FINAL_TYPE (HexStatusbar, hex_statusbar, HEX, STATUSBAR, GtkWidget)
+
+/* PUBLIC METHOD DECLARATIONS */
+
+GtkWidget *hex_statusbar_new (void);
+void hex_statusbar_set_status (HexStatusbar *self, const char *msg);
+void hex_statusbar_clear (HexStatusbar *self);
+
+#endif /* HEX_STATUSBAR_H */
diff --git a/src/meson.build b/src/meson.build
index 8484274..60c32d9 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -76,6 +76,7 @@ ghex_sources = [
'ghex-notebook-tab.c',
'gtkhex-paste-data.c',
'hex-dialog.c',
+ 'hex-statusbar.c',
'main.c',
'paste-special.c',
'preferences.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]