aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2024-07-04 15:40:07 +0200
committerThomas White <taw@physics.org>2024-07-04 15:49:01 +0200
commit7c35809ca1b59505582d64d1bf353df492b80a7a (patch)
treeda8dc39aa61f28734b048903f5af1732cd8b19ec
parent26441ed1258b01787c78d0081371fcc35e22578b (diff)
Make NarrativeWindow into a proper GTK object
-rw-r--r--src/colloquium.c8
-rw-r--r--src/narrative_window.c64
-rw-r--r--src/narrative_window.h55
3 files changed, 85 insertions, 42 deletions
diff --git a/src/colloquium.c b/src/colloquium.c
index 5a7d4a2..3c40411 100644
--- a/src/colloquium.c
+++ b/src/colloquium.c
@@ -61,11 +61,13 @@ static void colloquium_activate(GApplication *papp)
{
Colloquium *app = COLLOQUIUM(papp);
if ( !app->first_run ) {
+ NarrativeWindow *nw;
Narrative *n = narrative_new();
GFile *file = g_file_new_for_uri("resource:///uk/me/bitwiz/Colloquium/default.ss");
stylesheet_set_from_file(narrative_get_stylesheet(n), file);
narrative_add_empty_item(n);
- narrative_window_new(n, NULL, papp);
+ nw = narrative_window_new(n, NULL, papp);
+ gtk_widget_show_all(GTK_WIDGET(nw));
g_object_unref(file);
}
}
@@ -230,7 +232,9 @@ static void colloquium_open(GApplication *papp, GFile **files, gint n_files,
Narrative *n;
n = narrative_load(files[i]);
if ( n != NULL ) {
- narrative_window_new(n, files[i], papp);
+ NarrativeWindow *nw;
+ nw = narrative_window_new(n, files[i], papp);
+ gtk_widget_show_all(GTK_WIDGET(nw));
} else {
char *uri = g_file_get_uri(files[i]);
fprintf(stderr, _("Failed to load presentation '%s'\n"),
diff --git a/src/narrative_window.c b/src/narrative_window.c
index c8d5e34..3918b42 100644
--- a/src/narrative_window.c
+++ b/src/narrative_window.c
@@ -47,30 +47,13 @@
#include "print.h"
#include "stylesheet_editor.h"
-struct _narrative_window
-{
- GtkWidget *window;
- GtkToolItem *bfirst;
- GtkToolItem *bprev;
- GtkToolItem *bnext;
- GtkToolItem *blast;
- GtkWidget *nv;
- GApplication *app;
- Narrative *n;
- GFile *file;
- SCSlideshow *show;
- int show_no_slides;
- PRClock *pr_clock;
- SlideWindow *slidewindows[16];
- int n_slidewindows;
-};
-
+G_DEFINE_TYPE_WITH_CODE(NarrativeWindow, narrativewindow, GTK_TYPE_APPLICATION_WINDOW, NULL)
static void show_error(NarrativeWindow *nw, const char *err)
{
GtkWidget *mw;
- mw = gtk_message_dialog_new(GTK_WINDOW(nw->window),
+ mw = gtk_message_dialog_new(GTK_WINDOW(nw),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE, "%s", err);
@@ -105,7 +88,7 @@ static void update_titlebar(NarrativeWindow *nw)
if ( narrative_get_unsaved(nw->n) ) strcat(title, " *");
free(filename);
- gtk_window_set_title(GTK_WINDOW(nw->window), title);
+ gtk_window_set_title(GTK_WINDOW(nw), title);
for ( i=0; i<nw->n_slidewindows; i++ ) {
slide_window_update_titlebar(nw->slidewindows[i]);
@@ -194,7 +177,7 @@ static void saveas_sig(GSimpleAction *action, GVariant *parameter, gpointer vp)
NarrativeWindow *nw = vp;
d = gtk_file_chooser_dialog_new(_("Save presentation"),
- GTK_WINDOW(nw->window),
+ GTK_WINDOW(nw),
GTK_FILE_CHOOSER_ACTION_SAVE,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Save"), GTK_RESPONSE_ACCEPT,
@@ -215,7 +198,7 @@ static void saveas_sig(GSimpleAction *action, GVariant *parameter, gpointer vp)
static void nw_about_sig(GSimpleAction *action, GVariant *parameter, gpointer vp)
{
NarrativeWindow *nw = vp;
- open_about_dialog(nw->window);
+ open_about_dialog(GTK_WIDGET(nw));
}
@@ -297,7 +280,7 @@ static void load_ss_sig(GSimpleAction *action, GVariant *parameter,
GtkWidget *d;
d = gtk_file_chooser_dialog_new(_("Load stylesheet"),
- GTK_WINDOW(nw->window),
+ GTK_WINDOW(nw),
GTK_FILE_CHOOSER_ACTION_OPEN,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Open"), GTK_RESPONSE_ACCEPT,
@@ -524,7 +507,7 @@ static gint export_pdf_response_sig(GtkWidget *d, gint response,
static void print_sig(GSimpleAction *action, GVariant *parameter, gpointer vp)
{
NarrativeWindow *nw = vp;
- run_printing(nw->n, nw->window);
+ run_printing(nw->n, GTK_WIDGET(nw));
gtk_narrative_view_redraw(GTK_NARRATIVE_VIEW(nw->nv));
}
@@ -771,7 +754,17 @@ GActionEntry nw_entries[] = {
};
-NarrativeWindow *narrative_window_new(Narrative *n, GFile *file, GApplication *papp)
+static void narrativewindow_class_init(NarrativeWindowClass *klass)
+{
+}
+
+
+static void narrativewindow_init(NarrativeWindow *sw)
+{
+}
+
+
+NarrativeWindow *narrative_window_new(Narrative *n, GFile *file, GApplication *app)
{
NarrativeWindow *nw;
GtkWidget *vbox;
@@ -779,25 +772,23 @@ NarrativeWindow *narrative_window_new(Narrative *n, GFile *file, GApplication *p
GtkWidget *toolbar;
GtkToolItem *button;
GtkWidget *image;
- Colloquium *app = COLLOQUIUM(papp);
- nw = calloc(1, sizeof(NarrativeWindow));
- if ( nw == NULL ) return NULL;
+ nw = g_object_new(GTK_TYPE_NARRATIVE_WINDOW, "application", app, NULL);
+ gtk_window_set_role(GTK_WINDOW(nw), "narrative");
- nw->app = papp;
+ nw->app = app;
nw->n = n;
nw->n_slidewindows = 0;
nw->file = file;
if ( file != NULL ) g_object_ref(file);
- nw->window = gtk_application_window_new(GTK_APPLICATION(app));
update_titlebar(nw);
- g_action_map_add_action_entries(G_ACTION_MAP(nw->window), nw_entries,
+ g_action_map_add_action_entries(G_ACTION_MAP(nw), nw_entries,
G_N_ELEMENTS(nw_entries), nw);
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
- gtk_container_add(GTK_CONTAINER(nw->window), vbox);
+ gtk_container_add(GTK_CONTAINER(nw), vbox);
nw->nv = gtk_narrative_view_new(n);
@@ -895,18 +886,17 @@ NarrativeWindow *narrative_window_new(Narrative *n, GFile *file, GApplication *p
G_CALLBACK(changed_sig), nw);
g_signal_connect(G_OBJECT(nw->nv), "key-press-event",
G_CALLBACK(nw_key_press_sig), nw);
- g_signal_connect(G_OBJECT(nw->window), "destroy",
+ g_signal_connect(G_OBJECT(nw), "destroy",
G_CALLBACK(nw_destroy_sig), nw);
g_signal_connect(G_OBJECT(nw->nv), "slide-double-clicked",
G_CALLBACK(nw_double_click_sig), nw);
- gtk_window_set_default_size(GTK_WINDOW(nw->window), 768, 768);
+ gtk_window_set_default_size(GTK_WINDOW(nw), 768, 768);
gtk_box_pack_start(GTK_BOX(vbox), scroll, TRUE, TRUE, 0);
- gtk_container_set_focus_child(GTK_CONTAINER(nw->window),
+ gtk_container_set_focus_child(GTK_CONTAINER(nw),
GTK_WIDGET(nw->nv));
- gtk_widget_show_all(nw->window);
- g_application_hold(papp);
+ g_application_hold(app);
return nw;
}
diff --git a/src/narrative_window.h b/src/narrative_window.h
index 806924e..2aa2719 100644
--- a/src/narrative_window.h
+++ b/src/narrative_window.h
@@ -27,13 +27,62 @@
#include <config.h>
#endif
-typedef struct _narrative_window NarrativeWindow;
+typedef struct _narrativewindow NarrativeWindow;
+typedef struct _narrativewindowclass NarrativeWindowClass;
+#define GTK_TYPE_NARRATIVE_WINDOW (narrativewindow_get_type())
+
+#define GTK_NARRATIVE_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ GTK_TYPE_NARRATIVE_WINDOW, NarrativeWindow))
+
+#define GTK_IS_NARRATIVE_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ GTK_TYPE_NARRATIVE_WINDOW))
+
+#define GTK_NARRATIVE_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((obj), \
+ GTK_TYPE_NARRATIVE_WINDOW, NarrativeWindowClass))
+
+#define GTK_IS_NARRATIVE_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((obj), \
+ GTK_TYPE_NARRATIVE_WINDOW))
+
+#define GTK_NARRATIVE_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \
+ GTK_TYPE_NARRATIVE_WINDOW, NarrativeWindowClass))
+
+#include "pr_clock.h"
+#include "slideshow.h"
#include "slide_window.h"
-extern NarrativeWindow *narrative_window_new(Narrative *n, GFile *file,
- GApplication *papp);
+struct _narrativewindow
+{
+ GtkApplicationWindow parent_instance;
+
+ /*< private >*/
+ GtkToolItem *bfirst;
+ GtkToolItem *bprev;
+ GtkToolItem *bnext;
+ GtkToolItem *blast;
+ GtkWidget *nv;
+ GApplication *app;
+ Narrative *n;
+ GFile *file;
+ SCSlideshow *show;
+ int show_no_slides;
+ PRClock *pr_clock;
+ SlideWindow *slidewindows[16];
+ int n_slidewindows;
+};
+
+
+struct _narrativewindowclass
+{
+ GtkApplicationWindowClass parent_class;
+};
+
+
+extern GType narrativewindow_get_type(void);
+extern NarrativeWindow *narrative_window_new(Narrative *n,
+ GFile *file,
+ GApplication *app);
extern char *narrative_window_get_filename(NarrativeWindow *nw);