summaryrefslogtreecommitdiff
path: root/frontends/gtk
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2017-02-16 22:15:49 +0000
committerVincent Sanders <vince@kyllikki.org>2017-02-17 09:06:32 +0000
commit8ddb9df3778abadc095505d5711b08e9cd9f270a (patch)
tree422652ed6324ed1ff9ed2600596448d383cbabcc /frontends/gtk
parentc60cb335f21b602eeee84c7865db4b2bbfe87cfe (diff)
downloadnetsurf-8ddb9df3778abadc095505d5711b08e9cd9f270a.tar.gz
netsurf-8ddb9df3778abadc095505d5711b08e9cd9f270a.tar.bz2
update gtk frontend to use corewindow local history
Diffstat (limited to 'frontends/gtk')
-rw-r--r--frontends/gtk/Makefile10
-rw-r--r--frontends/gtk/global_history.c8
-rw-r--r--frontends/gtk/local_history.c284
-rw-r--r--frontends/gtk/local_history.h49
-rw-r--r--frontends/gtk/res/globalhistory.gtk2.ui (renamed from frontends/gtk/res/history.gtk2.ui)0
-rw-r--r--frontends/gtk/res/globalhistory.gtk3.ui (renamed from frontends/gtk/res/history.gtk3.ui)0
-rw-r--r--frontends/gtk/res/localhistory.gtk2.ui45
-rw-r--r--frontends/gtk/res/localhistory.gtk3.ui45
-rw-r--r--frontends/gtk/res/netsurf.gresource.xml42
-rw-r--r--frontends/gtk/resources.c3
-rw-r--r--frontends/gtk/scaffolding.c178
-rw-r--r--frontends/gtk/window.c4
12 files changed, 466 insertions, 202 deletions
diff --git a/frontends/gtk/Makefile b/frontends/gtk/Makefile
index afbfcd791..6c2f06f06 100644
--- a/frontends/gtk/Makefile
+++ b/frontends/gtk/Makefile
@@ -165,11 +165,11 @@ endif
# S_FRONTEND are sources purely for the GTK frontend
S_FRONTEND := gui.c schedule.c layout_pango.c bitmap.c plotters.c \
- scaffolding.c gdk.c completion.c login.c throbber.c \
- selection.c global_history.c window.c fetch.c download.c menu.c \
- print.c search.c tabs.c toolbar.c gettext.c \
- compat.c cookies.c hotlist.c viewdata.c viewsource.c \
- preferences.c about.c ssl_cert.c resources.c corewindow.c
+ scaffolding.c gdk.c completion.c login.c throbber.c \
+ selection.c window.c fetch.c download.c menu.c print.c \
+ search.c tabs.c toolbar.c gettext.c compat.c viewdata.c \
+ viewsource.c preferences.c about.c resources.c corewindow.c \
+ local_history.c global_history.c cookies.c hotlist.c ssl_cert.c
# This is the final source build list
# Note this is deliberately *not* expanded here as common and image
diff --git a/frontends/gtk/global_history.c b/frontends/gtk/global_history.c
index 7d647057b..66ba1a666 100644
--- a/frontends/gtk/global_history.c
+++ b/frontends/gtk/global_history.c
@@ -228,7 +228,7 @@ nsgtk_global_history_init_menu(struct nsgtk_global_history_window *ghwin)
/**
- * callback for mouse action on cookie window
+ * callback for mouse action on global history window
*
* \param nsgtk_cw The nsgtk core window structure.
* \param mouse_state netsurf mouse state on event
@@ -248,7 +248,7 @@ nsgtk_global_history_mouse(struct nsgtk_corewindow *nsgtk_cw,
/**
- * callback for keypress on cookie window
+ * callback for keypress on global history window
*
* \param nsgtk_cw The nsgtk core window structure.
* \param nskey The netsurf key code
@@ -265,7 +265,7 @@ nsgtk_global_history_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
/**
- * callback on draw event for cookie window
+ * callback on draw event for global history window
*
* \param nsgtk_cw The nsgtk core window structure.
* \param r The rectangle of the window that needs updating.
@@ -304,7 +304,7 @@ static nserror nsgtk_global_history_init(void)
return NSERROR_NOMEM;
}
- res = nsgtk_builder_new_from_resname("history", &ncwin->builder);
+ res = nsgtk_builder_new_from_resname("globalhistory", &ncwin->builder);
if (res != NSERROR_OK) {
LOG("History UI builder init failed");
free(ncwin);
diff --git a/frontends/gtk/local_history.c b/frontends/gtk/local_history.c
new file mode 100644
index 000000000..db13aa4da
--- /dev/null
+++ b/frontends/gtk/local_history.c
@@ -0,0 +1,284 @@
+/*
+ * Copyright 2017 Vincent Sanders <vince@netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf 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; version 2 of the License.
+ *
+ * NetSurf 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * Implementation of GTK local history manager.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <gtk/gtk.h>
+
+#include "utils/log.h"
+#include "netsurf/keypress.h"
+#include "netsurf/plotters.h"
+#include "desktop/local_history.h"
+
+#include "gtk/compat.h"
+#include "gtk/plotters.h"
+#include "gtk/resources.h"
+#include "gtk/corewindow.h"
+#include "gtk/local_history.h"
+
+struct nsgtk_local_history_window {
+ struct nsgtk_corewindow core;
+
+ GtkBuilder *builder;
+
+ GtkWindow *wnd;
+
+ struct local_history_session *session;
+};
+
+static struct nsgtk_local_history_window *local_history_window = NULL;
+
+
+
+/**
+ * callback for mouse action on local history window
+ *
+ * \param nsgtk_cw The nsgtk core window structure.
+ * \param mouse_state netsurf mouse state on event
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+nsgtk_local_history_mouse(struct nsgtk_corewindow *nsgtk_cw,
+ browser_mouse_state mouse_state,
+ int x, int y)
+{
+ struct nsgtk_local_history_window *lhw;
+ /* technically degenerate container of */
+ lhw = (struct nsgtk_local_history_window *)nsgtk_cw;
+
+ local_history_mouse_action(lhw->session, mouse_state, x, y);
+
+ return NSERROR_OK;
+}
+
+
+/**
+ * callback for keypress on local history window
+ *
+ * \param nsgtk_cw The nsgtk core window structure.
+ * \param nskey The netsurf key code
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+nsgtk_local_history_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
+{
+ struct nsgtk_local_history_window *lhw;
+ /* technically degenerate container of */
+ lhw = (struct nsgtk_local_history_window *)nsgtk_cw;
+
+ if (local_history_keypress(lhw->session, nskey)) {
+ return NSERROR_OK;
+ }
+ return NSERROR_NOT_IMPLEMENTED;
+}
+
+
+/**
+ * callback on draw event for local history window
+ *
+ * \param nsgtk_cw The nsgtk core window structure.
+ * \param r The rectangle of the window that needs updating.
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+static nserror
+nsgtk_local_history_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
+{
+ struct redraw_context ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = &nsgtk_plotters
+ };
+ struct nsgtk_local_history_window *lhw;
+ GtkAdjustment *vscroll;
+ GtkAdjustment *hscroll;
+ struct rect c;
+ int vscroll_val;
+ int hscroll_val;
+
+ vscroll = gtk_scrolled_window_get_vadjustment(nsgtk_cw->scrolled);
+ hscroll = gtk_scrolled_window_get_hadjustment(nsgtk_cw->scrolled);
+ vscroll_val = gtk_adjustment_get_value(vscroll);
+ hscroll_val = gtk_adjustment_get_value(hscroll);
+
+
+ /* technically degenerate container of */
+ lhw = (struct nsgtk_local_history_window *)nsgtk_cw;
+ c.x0 = r->x0 + hscroll_val;
+ c.y0 = r->y0 + vscroll_val;
+ c.x1 = r->x1 + hscroll_val;
+ c.y1 = r->y1 + vscroll_val;
+
+ ctx.plot->clip(&ctx, r);
+ local_history_redraw(lhw->session, r->x0, r->y0, r, &ctx);
+
+ return NSERROR_OK;
+}
+
+/**
+ * Creates the window for the local history view.
+ *
+ * \return NSERROR_OK on success else appropriate error code on faliure.
+ */
+static nserror
+nsgtk_local_history_init(struct browser_window *bw,
+ struct nsgtk_local_history_window **win_out)
+{
+ struct nsgtk_local_history_window *ncwin;
+ nserror res;
+
+ /* memoise window so it can be represented when necessary
+ * instead of recreating every time.
+ */
+ if ((*win_out) != NULL) {
+ res = local_history_set((*win_out)->session, bw);
+ return res;
+ }
+
+ ncwin = malloc(sizeof(struct nsgtk_local_history_window));
+ if (ncwin == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ res = nsgtk_builder_new_from_resname("localhistory", &ncwin->builder);
+ if (res != NSERROR_OK) {
+ LOG("Local history UI builder init failed");
+ free(ncwin);
+ return res;
+ }
+
+ gtk_builder_connect_signals(ncwin->builder, NULL);
+
+ ncwin->wnd = GTK_WINDOW(gtk_builder_get_object(ncwin->builder,
+ "wndHistory"));
+
+ ncwin->core.scrolled = GTK_SCROLLED_WINDOW(
+ gtk_builder_get_object(ncwin->builder,
+ "HistoryScrolled"));
+
+ ncwin->core.drawing_area = GTK_DRAWING_AREA(
+ gtk_builder_get_object(ncwin->builder,
+ "HistoryDrawingArea"));
+
+ /* make the delete event hide the window */
+ g_signal_connect(G_OBJECT(ncwin->wnd),
+ "delete_event",
+ G_CALLBACK(gtk_widget_hide_on_delete),
+ NULL);
+
+ ncwin->core.draw = nsgtk_local_history_draw;
+ ncwin->core.key = nsgtk_local_history_key;
+ ncwin->core.mouse = nsgtk_local_history_mouse;
+
+ res = nsgtk_corewindow_init(&ncwin->core);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ res = local_history_init(ncwin->core.cb_table,
+ (struct core_window *)ncwin,
+ bw,
+ &ncwin->session);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ *win_out = ncwin;
+
+ return NSERROR_OK;
+}
+
+
+/* exported function documented gtk/history.h */
+nserror nsgtk_local_history_present(GtkWindow *parent,
+ struct browser_window *bw)
+{
+ nserror res;
+ int prnt_width, prnt_height;
+ int width, height;
+ res = nsgtk_local_history_init(bw, &local_history_window);
+ if (res == NSERROR_OK) {
+ gtk_window_set_transient_for(local_history_window->wnd, parent);
+
+ gtk_window_get_size(parent, &prnt_width, &prnt_height);
+
+ /* resize history widget ensureing the drawing area is
+ * no larger than parent window
+ */
+ res = local_history_get_size(local_history_window->session,
+ &width,
+ &height);
+ if (width > prnt_width) {
+ width = prnt_width;
+ }
+ if (height > prnt_height) {
+ height = prnt_height;
+ }
+ gtk_window_resize(local_history_window->wnd, width, height);
+
+ gtk_window_present(local_history_window->wnd);
+ }
+
+ return res;
+}
+
+
+/* exported function documented gtk/history.h */
+nserror nsgtk_local_history_hide(void)
+{
+ nserror res = NSERROR_OK;
+
+ if (local_history_window != NULL) {
+ gtk_widget_hide(GTK_WIDGET(local_history_window->wnd));
+
+ res = local_history_set(local_history_window->session, NULL);
+ }
+
+ return res;
+}
+
+
+/* exported function documented gtk/history.h */
+nserror nsgtk_local_history_destroy(void)
+{
+ nserror res;
+
+ if (local_history_window == NULL) {
+ return NSERROR_OK;
+ }
+
+ res = local_history_fini(local_history_window->session);
+ if (res == NSERROR_OK) {
+ res = nsgtk_corewindow_fini(&local_history_window->core);
+ gtk_widget_destroy(GTK_WIDGET(local_history_window->wnd));
+ g_object_unref(G_OBJECT(local_history_window->builder));
+ free(local_history_window);
+ local_history_window = NULL;
+ }
+
+ return res;
+
+}
diff --git a/frontends/gtk/local_history.h b/frontends/gtk/local_history.h
new file mode 100644
index 000000000..605405ddf
--- /dev/null
+++ b/frontends/gtk/local_history.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2017 Vincent Sanders <vince@kyllikki.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf 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; version 2 of the License.
+ *
+ * NetSurf 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * Interface to GTK local history manager
+ */
+
+#ifndef NSGTK_LOCAL_HISTORY_H
+#define NSGTK_LOCAL_HISTORY_H
+
+struct browser_window;
+
+/**
+ * make the local history window visible.
+ *
+ * \return NSERROR_OK on success else appropriate error code on faliure.
+ */
+nserror nsgtk_local_history_present(GtkWindow *parent, struct browser_window *bw);
+
+/**
+ * hide the local history window from being visible.
+ *
+ * \return NSERROR_OK on success else appropriate error code on faliure.
+ */
+nserror nsgtk_local_history_hide(void);
+
+/**
+ * Destroys the local history window and performs any other necessary cleanup
+ * actions.
+ */
+nserror nsgtk_local_history_destroy(void);
+
+#endif
diff --git a/frontends/gtk/res/history.gtk2.ui b/frontends/gtk/res/globalhistory.gtk2.ui
index 2b89ecb4b..2b89ecb4b 100644
--- a/frontends/gtk/res/history.gtk2.ui
+++ b/frontends/gtk/res/globalhistory.gtk2.ui
diff --git a/frontends/gtk/res/history.gtk3.ui b/frontends/gtk/res/globalhistory.gtk3.ui
index 7fa598f1e..7fa598f1e 100644
--- a/frontends/gtk/res/history.gtk3.ui
+++ b/frontends/gtk/res/globalhistory.gtk3.ui
diff --git a/frontends/gtk/res/localhistory.gtk2.ui b/frontends/gtk/res/localhistory.gtk2.ui
new file mode 100644
index 000000000..9512b6289
--- /dev/null
+++ b/frontends/gtk/res/localhistory.gtk2.ui
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <object class="GtkWindow" id="wndHistory">
+ <property name="can_focus">False</property>
+ <property name="title" translatable="yes">NetSurf Local History</property>
+ <property name="window_position">center</property>
+ <property name="default_width">20</property>
+ <property name="default_height">20</property>
+ <property name="type_hint">utility</property>
+ <property name="decorated">False</property>
+ <child>
+ <object class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkScrolledWindow" id="HistoryScrolled">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <child>
+ <object class="GtkViewport" id="HistoryViewport">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="resize_mode">queue</property>
+ <child>
+ <object class="GtkDrawingArea" id="HistoryDrawingArea">
+ <property name="visible">True</property>
+ <property name="app_paintable">True</property>
+ <property name="can_focus">True</property>
+ <property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/frontends/gtk/res/localhistory.gtk3.ui b/frontends/gtk/res/localhistory.gtk3.ui
new file mode 100644
index 000000000..1a4b9004d
--- /dev/null
+++ b/frontends/gtk/res/localhistory.gtk3.ui
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <object class="GtkWindow" id="wndHistory">
+ <property name="can_focus">False</property>
+ <property name="title" translatable="yes">NetSurf Local History</property>
+ <property name="window_position">center</property>
+ <property name="default_width">20</property>
+ <property name="default_height">20</property>
+ <property name="type_hint">utility</property>
+ <property name="decorated">False</property>
+ <child>
+ <object class="GtkBox" id="box1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkScrolledWindow" id="HistoryScrolled">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <object class="GtkViewport" id="HistoryViewport">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkDrawingArea" id="HistoryDrawingArea">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/frontends/gtk/res/netsurf.gresource.xml b/frontends/gtk/res/netsurf.gresource.xml
index c7626b053..5bae777f3 100644
--- a/frontends/gtk/res/netsurf.gresource.xml
+++ b/frontends/gtk/res/netsurf.gresource.xml
@@ -2,30 +2,32 @@
<gresources>
<gresource prefix="/org/netsurf">
<file>cookies.gtk2.ui</file>
- <file>history.gtk3.ui</file>
- <file>netsurf.gtk2.ui</file>
- <file>password.gtk3.ui</file>
- <file>toolbar.gtk2.ui</file>
+ <file>globalhistory.gtk3.ui</file>
+ <file>localhistory.gtk3.ui</file>
+ <file>netsurf.gtk2.ui</file>
+ <file>password.gtk3.ui</file>
+ <file>toolbar.gtk2.ui</file>
<file>warning.gtk3.ui</file>
- <file>cookies.gtk3.ui</file>
- <file>hotlist.gtk2.ui</file>
- <file>netsurf.gtk3.ui</file>
- <file>ssl.gtk2.ui</file>
+ <file>cookies.gtk3.ui</file>
+ <file>hotlist.gtk2.ui</file>
+ <file>netsurf.gtk3.ui</file>
+ <file>ssl.gtk2.ui</file>
<file>toolbar.gtk3.ui</file>
- <file>downloads.gtk2.ui</file>
- <file>hotlist.gtk3.ui</file>
- <file>options.gtk2.ui</file>
- <file>ssl.gtk3.ui</file>
+ <file>downloads.gtk2.ui</file>
+ <file>hotlist.gtk3.ui</file>
+ <file>options.gtk2.ui</file>
+ <file>ssl.gtk3.ui</file>
<file>viewdata.gtk2.ui</file>
- <file>downloads.gtk3.ui</file>
- <file>login.gtk2.ui</file>
- <file>options.gtk3.ui</file>
- <file>tabcontents.gtk2.ui</file>
+ <file>downloads.gtk3.ui</file>
+ <file>login.gtk2.ui</file>
+ <file>options.gtk3.ui</file>
+ <file>tabcontents.gtk2.ui</file>
<file>viewdata.gtk3.ui</file>
- <file>history.gtk2.ui</file>
- <file>login.gtk3.ui</file>
- <file>password.gtk2.ui</file>
- <file>tabcontents.gtk3.ui</file>
+ <file>localhistory.gtk2.ui</file>
+ <file>globalhistory.gtk2.ui</file>
+ <file>login.gtk3.ui</file>
+ <file>password.gtk2.ui</file>
+ <file>tabcontents.gtk3.ui</file>
<file>warning.gtk2.ui</file>
<file preprocess="to-pixdata">favicon.png</file>
<file preprocess="to-pixdata">netsurf.xpm</file>
diff --git a/frontends/gtk/resources.c b/frontends/gtk/resources.c
index dfe3d3dad..4f9afb034 100644
--- a/frontends/gtk/resources.c
+++ b/frontends/gtk/resources.c
@@ -81,7 +81,8 @@ static struct nsgtk_resource_s ui_resource[] = {
RES_ENTRY("ssl"),
RES_ENTRY("toolbar"),
RES_ENTRY("downloads"),
- RES_ENTRY("history"),
+ RES_ENTRY("globalhistory"),
+ RES_ENTRY("localhistory"),
RES_ENTRY("options"),
RES_ENTRY("hotlist"),
RES_ENTRY("cookies"),
diff --git a/frontends/gtk/scaffolding.c b/frontends/gtk/scaffolding.c
index 7a40d6656..7593fc383 100644
--- a/frontends/gtk/scaffolding.c
+++ b/frontends/gtk/scaffolding.c
@@ -61,6 +61,7 @@
#include "gtk/bitmap.h"
#include "gtk/gui.h"
#include "gtk/global_history.h"
+#include "gtk/local_history.h"
#include "gtk/hotlist.h"
#include "gtk/download.h"
#include "gtk/menu.h"
@@ -109,9 +110,6 @@ struct nsgtk_scaffolding {
/** currently active gui browsing context */
struct gui_window *top_level;
- /** local history window */
- struct gtk_history_window *history_window;
-
/** Builder object scaffold was created from */
GtkBuilder *builder;
@@ -247,9 +245,7 @@ static void scaffolding_window_destroy(GtkWidget *widget, gpointer data)
LOG("scaffold:%p", gs);
- if ((gs->history_window) && (gs->history_window->window)) {
- gtk_widget_destroy(GTK_WIDGET(gs->history_window->window));
- }
+ nsgtk_local_history_hide();
if (gs->prev != NULL) {
gs->prev->next = gs->next;
@@ -287,7 +283,6 @@ static gboolean scaffolding_window_delete_event(GtkWidget *widget,
*/
static void scaffolding_update_context(struct nsgtk_scaffolding *g)
{
- int width, height;
struct browser_window *bw = nsgtk_get_browser_window(g->top_level);
g->buttons[BACK_BUTTON]->sensitivity =
@@ -300,13 +295,7 @@ static void scaffolding_update_context(struct nsgtk_scaffolding *g)
/* update the url bar, particularly necessary when tabbing */
browser_window_refresh_url_bar(bw);
- /* update the local history window, as well as queuing a redraw
- * for it.
- */
- browser_window_history_size(bw, &width, &height);
- gtk_widget_set_size_request(GTK_WIDGET(g->history_window->drawing_area),
- width, height);
- gtk_widget_queue_draw(GTK_WIDGET(g->history_window->drawing_area));
+ nsgtk_local_history_hide();
}
/**
@@ -1466,31 +1455,12 @@ MULTIHANDLER(home)
MULTIHANDLER(localhistory)
{
struct browser_window *bw = nsgtk_get_browser_window(g->top_level);
+ nserror res;
- int x,y, width, height, mainwidth, mainheight, margin = 20;
- /* if entries of the same url but different frag_ids have been added
- * the history needs redrawing (what throbber code normally does)
- */
-
- scaffolding_update_context(g);
- gtk_window_get_position(g->window, &x, &y);
- gtk_window_get_size(g->window, &mainwidth, &mainheight);
- browser_window_history_size(bw, &width, &height);
- width = (width + g->historybase + margin > mainwidth) ?
- mainwidth - g->historybase : width + margin;
- height = (height + g->toolbarbase + margin > mainheight) ?
- mainheight - g->toolbarbase : height + margin;
- gtk_window_set_default_size(g->history_window->window, width, height);
- gtk_widget_set_size_request(GTK_WIDGET(g->history_window->window),
- -1, -1);
- gtk_window_resize(g->history_window->window, width, height);
- gtk_window_set_transient_for(g->history_window->window, g->window);
- nsgtk_window_set_opacity(g->history_window->window, 0.9);
- gtk_widget_show(GTK_WIDGET(g->history_window->window));
- gtk_window_move(g->history_window->window, x + g->historybase, y +
- g->toolbarbase);
- gdk_window_raise(nsgtk_widget_get_window(GTK_WIDGET(g->history_window->window)));
-
+ res = nsgtk_local_history_present(g->window, bw);
+ if (res != NSERROR_OK) {
+ LOG("Unable to initialise local history window.");
+ }
return TRUE;
}
@@ -1643,91 +1613,6 @@ BUTTONHANDLER(history)
#undef CHECKHANDLER
#undef BUTTONHANDLER
-#if GTK_CHECK_VERSION(3,0,0)
-
-static gboolean
-nsgtk_history_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data)
-{
- struct rect clip;
- struct gtk_history_window *hw = (struct gtk_history_window *)data;
- struct browser_window *bw =
- nsgtk_get_browser_window(hw->g->top_level);
-
- struct redraw_context ctx = {
- .interactive = true,
- .background_images = true,
- .plot = &nsgtk_plotters
- };
- double x1;
- double y1;
- double x2;
- double y2;
-
- current_cr = cr;
-
- cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
-
- clip.x0 = x1;
- clip.y0 = y1;
- clip.x1 = x2;
- clip.y1 = y2;
-
- ctx.plot->clip(&ctx, &clip);
-
- browser_window_history_redraw(bw, &ctx);
-
- return FALSE;
-}
-#else
-
-/* signal handler functions for the local history window */
-static gboolean
-nsgtk_history_draw_event(GtkWidget *widget, GdkEventExpose *event, gpointer g)
-{
- struct rect clip;
- struct gtk_history_window *hw = (struct gtk_history_window *)g;
- struct browser_window *bw =
- nsgtk_get_browser_window(hw->g->top_level);
-
- struct redraw_context ctx = {
- .interactive = true,
- .background_images = true,
- .plot = &nsgtk_plotters
- };
-
- current_cr = gdk_cairo_create(nsgtk_widget_get_window(widget));
-
- clip.x0 = event->area.x;
- clip.y0 = event->area.y;
- clip.x1 = event->area.x + event->area.width;
- clip.y1 = event->area.y + event->area.height;
- ctx.plot->clip(&ctx, &clip);
-
- browser_window_history_redraw(bw, &ctx);
-
- cairo_destroy(current_cr);
-
- return FALSE;
-}
-
-#endif /* GTK_CHECK_VERSION(3,0,0) */
-
-static gboolean nsgtk_history_button_press_event(GtkWidget *widget,
- GdkEventButton *event, gpointer g)
-{
- struct gtk_history_window *hw = (struct gtk_history_window *)g;
- struct browser_window *bw =
- nsgtk_get_browser_window(hw->g->top_level);
-
- LOG("X=%g, Y=%g", event->x, event->y);
-
- browser_window_history_click(bw, event->x, event->y, false);
-
- return TRUE;
-}
-
-
-
static void nsgtk_attach_menu_handlers(struct nsgtk_scaffolding *g)
{
for (int i = BACK_BUTTON; i < PLACEHOLDER_BUTTON; i++) {
@@ -2181,35 +2066,6 @@ struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
gtk_widget_set_size_request(GTK_WIDGET(
gs->buttons[HISTORY_BUTTON]->button), 20, -1);
- /* create the local history window to be associated with this scaffold */
- gs->history_window = malloc(sizeof(struct gtk_history_window));
- gs->history_window->g = gs;
- gs->history_window->window =
- GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
- gtk_window_set_transient_for(gs->history_window->window, gs->window);
- gtk_window_set_title(gs->history_window->window, "NetSurf History");
- gtk_window_set_type_hint(gs->history_window->window,
- GDK_WINDOW_TYPE_HINT_UTILITY);
- gs->history_window->scrolled =
- GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(0, 0));
- gtk_container_add(GTK_CONTAINER(gs->history_window->window),
- GTK_WIDGET(gs->history_window->scrolled));
-
- gtk_widget_show(GTK_WIDGET(gs->history_window->scrolled));
- gs->history_window->drawing_area =
- GTK_DRAWING_AREA(gtk_drawing_area_new());
-
- gtk_widget_set_events(GTK_WIDGET(gs->history_window->drawing_area),
- GDK_EXPOSURE_MASK |
- GDK_POINTER_MOTION_MASK |
- GDK_BUTTON_PRESS_MASK);
- nsgtk_widget_override_background_color(GTK_WIDGET(gs->history_window->drawing_area),
- GTK_STATE_NORMAL,
- 0, 0xffff, 0xffff, 0xffff);
- nsgtk_scrolled_window_add_with_viewport(gs->history_window->scrolled,
- GTK_WIDGET(gs->history_window->drawing_area));
- gtk_widget_show(GTK_WIDGET(gs->history_window->drawing_area));
-
/* set up URL bar completion */
gs->url_bar_completion = nsgtk_url_entry_completion_new(gs);
@@ -2221,17 +2077,6 @@ struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
#define CONNECT(obj, sig, callback, ptr) \
g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
- /* connect history window signals to their handlers */
- nsgtk_connect_draw_event(GTK_WIDGET(gs->history_window->drawing_area),
- G_CALLBACK(nsgtk_history_draw_event),
- gs->history_window);
- /*CONNECT(gs->history_window->drawing_area, "motion_notify_event",
- nsgtk_history_motion_notify_event, gs->history_window);*/
- CONNECT(gs->history_window->drawing_area, "button_press_event",
- nsgtk_history_button_press_event, gs->history_window);
- CONNECT(gs->history_window->window, "delete_event",
- gtk_widget_hide_on_delete, NULL);
-
g_signal_connect_after(gs->notebook, "page-added",
G_CALLBACK(nsgtk_window_tabs_add), gs);
g_signal_connect_after(gs->notebook, "page-removed",
@@ -2592,13 +2437,6 @@ GtkMenuBar *nsgtk_scaffolding_menu_bar(struct nsgtk_scaffolding *g)
}
/* exported interface documented in gtk/scaffolding.h */
-struct gtk_history_window *
-nsgtk_scaffolding_history_window(struct nsgtk_scaffolding *g)
-{
- return g->history_window;
-}
-
-/* exported interface documented in gtk/scaffolding.h */
struct nsgtk_scaffolding *nsgtk_scaffolding_iterate(struct nsgtk_scaffolding *g)
{
if (g == NULL) {
diff --git a/frontends/gtk/window.c b/frontends/gtk/window.c
index 7432e301e..40e5580b5 100644
--- a/frontends/gtk/window.c
+++ b/frontends/gtk/window.c
@@ -52,6 +52,7 @@
#include "gtk/compat.h"
#include "gtk/gui.h"
#include "gtk/scaffolding.h"
+#include "gtk/local_history.h"
#include "gtk/plotters.h"
#include "gtk/schedule.h"
#include "gtk/tabs.h"
@@ -339,8 +340,7 @@ static gboolean nsgtk_window_button_press_event(GtkWidget *widget,
gtk_im_context_reset(g->input_method);
gtk_widget_grab_focus(GTK_WIDGET(g->layout));
- gtk_widget_hide(GTK_WIDGET(nsgtk_scaffolding_history_window(
- g->scaffold)->window));
+ nsgtk_local_history_hide();
g->mouse.pressed_x = event->x / browser_window_get_scale(g->bw);
g->mouse.pressed_y = event->y / browser_window_get_scale(g->bw);