summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--gui/view.c130
-rw-r--r--gui/view.h28
3 files changed, 159 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index f4a42af..fb1ec41 100644
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,7 @@ EESHOW_OBJS = main/eeshow.o main/common.o \
gui/gui.o gui/over.o gui/style.o gui/aoi.o gui/fmt-pango.o gui/input.o \
gui/progress.o gui/glabel.o gui/sheet.o gui/history.o gui/render.o \
gui/help.o gui/icons.o gui/index.o gui/timer.o gui/pop.o gui/comp.o \
- gui/viewer.o gui/clipboard.o \
+ gui/viewer.o gui/clipboard.o gui/view.o \
$(OBJS_FILE) \
gfx/style.o gfx/fig.o gfx/record.o gfx/cro.o gfx/diff.o gfx/gfx.o \
gfx/text.o gfx/misc.o gfx/pdftoc.o \
diff --git a/gui/view.c b/gui/view.c
new file mode 100644
index 0000000..c970a8d
--- /dev/null
+++ b/gui/view.c
@@ -0,0 +1,130 @@
+/*
+ * gui/view.c - Text view window
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * 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.
+ */
+
+#include <stdbool.h>
+
+#include <gtk/gtk.h>
+
+#include "misc/util.h"
+#include "gui/view.h"
+
+
+struct view {
+ GtkWidget *window;
+ GtkWidget *label;
+ bool visible;
+ bool destroyed;
+ void (*key_press)(void *user, struct view *view, guint keyval);
+ void *user;
+};
+
+
+static void destroy_view(GtkWidget *object, gpointer user_data)
+{
+ struct view *view = user_data;
+
+ gtk_widget_destroy(view->window);
+ view->destroyed = 1;
+}
+
+
+static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event,
+ gpointer data)
+{
+ struct view *view = data;
+
+ view->key_press(view->user, view, event->keyval);
+ return TRUE;
+}
+
+
+struct view *view_open(
+ void (*key_press)(void *user, struct view *view, guint keyval), void *user)
+{
+ struct view *view;
+ GtkWidget *scroll;
+
+ view = alloc_type(struct view);
+ view->visible = 1;
+ view->destroyed = 0;
+ view->key_press = key_press;
+ view->user = user;
+
+ view->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ scroll = gtk_scrolled_window_new(NULL, NULL);
+ view->label = gtk_label_new(NULL);
+
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
+ GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+
+ gtk_label_set_line_wrap(GTK_LABEL(view->label), TRUE);
+ gtk_label_set_selectable(GTK_LABEL(view->label), TRUE);
+
+ gtk_container_add(GTK_CONTAINER(scroll), view->label);
+
+ gtk_container_add(GTK_CONTAINER(view->window), scroll);
+ gtk_window_set_default_size(GTK_WINDOW(view->window), 480, 360);
+ gtk_widget_show_all(view->window);
+
+ gtk_widget_set_can_focus(scroll, TRUE);
+ gtk_widget_add_events(scroll, GDK_KEY_PRESS_MASK);
+
+ g_signal_connect(G_OBJECT(scroll), "key_press_event",
+ G_CALLBACK(key_press_event), view);
+ g_signal_connect(view->window, "destroy", G_CALLBACK(destroy_view),
+ view);
+
+ gtk_widget_show_all(view->window);
+
+ return view;
+}
+
+
+bool view_visible(struct view *view, bool visible)
+{
+ if (view->destroyed)
+ return 0;
+ if (view->visible == visible)
+ return 1;
+ if (visible)
+ gtk_widget_show(view->window);
+ else
+ gtk_widget_hide(view->window);
+ view->visible = visible;
+ return 1;
+}
+
+
+bool view_visible_toggle(struct view *view)
+{
+ return view_visible(view, !view->visible);
+}
+
+
+void view_close(struct view *view)
+{
+ if (!view->destroyed)
+ gtk_widget_destroy(view->window);
+ free(view);
+}
+
+
+bool view_update(struct view *view, const char *s, bool markup)
+{
+ if (view->destroyed)
+ return 0;
+ if (markup)
+ gtk_label_set_markup(GTK_LABEL(view->label), s);
+ else
+ gtk_label_set_text(GTK_LABEL(view->label), s);
+ return 1;
+}
diff --git a/gui/view.h b/gui/view.h
new file mode 100644
index 0000000..7802c5d
--- /dev/null
+++ b/gui/view.h
@@ -0,0 +1,28 @@
+/*
+ * gui/view.h - Text view window
+ *
+ * Written 2016 by Werner Almesberger
+ * Copyright 2016 by Werner Almesberger
+ *
+ * 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.
+ */
+
+#ifndef GUI_VIEW_H
+#define GUI_VIEW_H
+
+#include <stdbool.h>
+
+
+struct view;
+
+struct view *view_open(
+ void (*key_press)(void *user, struct view *view, guint keyval), void *user);
+bool view_visible(struct view *view, bool visible);
+bool view_visible_toggle(struct view *view);
+void view_close(struct view *view);
+bool view_update(struct view *view, const char *s, bool markup);
+
+#endif /* !GUI_VIEW_H */