summaryrefslogtreecommitdiff
path: root/frontends
diff options
context:
space:
mode:
Diffstat (limited to 'frontends')
-rw-r--r--frontends/gtk/gui.c13
-rw-r--r--frontends/gtk/history.c373
-rw-r--r--frontends/gtk/history.h22
-rw-r--r--frontends/gtk/scaffolding.c8
4 files changed, 274 insertions, 142 deletions
diff --git a/frontends/gtk/gui.c b/frontends/gtk/gui.c
index 0ed32e9d6..1f22b6076 100644
--- a/frontends/gtk/gui.c
+++ b/frontends/gtk/gui.c
@@ -301,12 +301,6 @@ static nserror nsgtk_init(int argc, char** argv, char **respath)
LOG("Set CSS DPI to %d", browser_get_dpi());
/* Initialise top level UI elements */
- error = nsgtk_history_init();
- if (error != NSERROR_OK) {
- LOG("Unable to initialise global history window.");
- return error;
- }
-
error = nsgtk_download_init();
if (error != NSERROR_OK) {
LOG("Unable to initialise download window.");
@@ -449,7 +443,12 @@ static void gui_quit(void)
messages_get_errorcode(res));
}
- nsgtk_history_destroy();
+ res = nsgtk_global_history_destroy();
+ if (res != NSERROR_OK) {
+ LOG("Error finalising global history viewer: %s",
+ messages_get_errorcode(res));
+ }
+
nsgtk_hotlist_destroy();
free(nsgtk_config_home);
diff --git a/frontends/gtk/history.c b/frontends/gtk/history.c
index 0148f37b6..22cf1e889 100644
--- a/frontends/gtk/history.c
+++ b/frontends/gtk/history.c
@@ -17,22 +17,35 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <stdlib.h>
+/**
+ * \file
+ * Implementation of GTK global 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/global_history.h"
-#include "desktop/plot_style.h"
-#include "desktop/tree.h"
+#include "desktop/treeview.h"
+#include "gtk/compat.h"
+#include "gtk/history.h"
#include "gtk/plotters.h"
#include "gtk/scaffolding.h"
-#include "gtk/treeview.h"
-#include "gtk/compat.h"
#include "gtk/resources.h"
-#include "gtk/history.h"
+#include "gtk/corewindow.h"
+
+struct nsgtk_global_history_window {
+ struct nsgtk_corewindow core;
+ GtkBuilder *builder;
+ GtkWindow *wnd;
+};
+
+static struct nsgtk_global_history_window *global_history_window = NULL;
#define MENUPROTO(x) static gboolean nsgtk_on_##x##_activate( \
GtkMenuItem *widget, gpointer g)
@@ -87,100 +100,85 @@ static struct menu_events menu_events[] = {
{NULL, NULL}
};
-static struct nsgtk_treeview *global_history_window;
-static GtkBuilder *history_builder;
-GtkWindow *wndHistory;
-
-/**
- * Connects menu events in the global history window.
- */
-static void nsgtk_history_init_menu(void)
+/* edit menu */
+MENUHANDLER(delete_selected)
{
- struct menu_events *event = menu_events;
- GtkWidget *w;
-
- while (event->widget != NULL) {
- w = GTK_WIDGET(gtk_builder_get_object(history_builder,
- event->widget));
- if (w == NULL) {
- LOG("Unable to connect menu widget ""%s""",
- event->widget);
- } else {
- g_signal_connect(G_OBJECT(w),
- "activate",
- event->handler,
- global_history_window);
- }
- event++;
- }
+ global_history_keypress(NS_KEY_DELETE_LEFT);
+ return TRUE;
}
-/* exported interface, documented in gtk/history.h */
-nserror nsgtk_history_init(void)
+MENUHANDLER(delete_all)
{
- GtkWindow *window;
- GtkScrolledWindow *scrolled;
- GtkDrawingArea *drawing_area;
- nserror res;
-
- res = nsgtk_builder_new_from_resname("history", &history_builder);
- if (res != NSERROR_OK) {
- LOG("History UI builder init failed");
- return res;
- }
- gtk_builder_connect_signals(history_builder, NULL);
-
- wndHistory = GTK_WINDOW(gtk_builder_get_object(history_builder,
- "wndHistory"));
-
- window = wndHistory;
-
- scrolled = GTK_SCROLLED_WINDOW(gtk_builder_get_object(history_builder,
- "globalHistoryScrolled"));
-
- drawing_area = GTK_DRAWING_AREA(gtk_builder_get_object(history_builder,
- "globalHistoryDrawingArea"));
-
- global_history_window = nsgtk_treeview_create(TREE_HISTORY,
- window,
- scrolled,
- drawing_area,
- NULL);
- if (global_history_window == NULL) {
- return NSERROR_INIT_FAILED;
- }
+ global_history_keypress(NS_KEY_SELECT_ALL);
+ global_history_keypress(NS_KEY_DELETE_LEFT);
+ return TRUE;
+}
-#define CONNECT(obj, sig, callback, ptr) \
- g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
+MENUHANDLER(select_all)
+{
+ global_history_keypress(NS_KEY_SELECT_ALL);
+ return TRUE;
+}
- CONNECT(window, "delete_event", gtk_widget_hide_on_delete, NULL);
- CONNECT(window, "hide", nsgtk_tree_window_hide, global_history_window);
+MENUHANDLER(clear_selection)
+{
+ global_history_keypress(NS_KEY_CLEAR_SELECTION);
+ return TRUE;
+}
- nsgtk_history_init_menu();
+/* view menu*/
+MENUHANDLER(expand_all)
+{
+ global_history_expand(false);
+ return TRUE;
+}
- return NSERROR_OK;
+MENUHANDLER(expand_directories)
+{
+ global_history_expand(true);
+ return TRUE;
}
+MENUHANDLER(expand_addresses)
+{
+ global_history_expand(false);
+ return TRUE;
+}
+MENUHANDLER(collapse_all)
+{
+ global_history_contract(true);
+ return TRUE;
+}
+MENUHANDLER(collapse_directories)
+{
+ global_history_contract(true);
+ return TRUE;
+}
-/**
- * Destroys the global history window and performs any other necessary cleanup
- * actions.
- */
-void nsgtk_history_destroy(void)
+MENUHANDLER(collapse_addresses)
{
- /** \todo what about history_builder? */
- nsgtk_treeview_destroy(global_history_window);
+ global_history_contract(false);
+ return TRUE;
}
+MENUHANDLER(launch)
+{
+ global_history_keypress(NS_KEY_CR);
+ return TRUE;
+}
/* file menu */
MENUHANDLER(export)
{
+ struct nsgtk_global_history_window *ghwin;
GtkWidget *save_dialog;
+
+ ghwin = (struct nsgtk_global_history_window *)g;
+
save_dialog = gtk_file_chooser_dialog_new("Save File",
- wndHistory,
+ ghwin->wnd,
GTK_FILE_CHOOSER_ACTION_SAVE,
NSGTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NSGTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
@@ -205,71 +203,202 @@ MENUHANDLER(export)
return TRUE;
}
-/* edit menu */
-MENUHANDLER(delete_selected)
+/**
+ * Connects menu events in the global history window.
+ */
+static void
+nsgtk_global_history_init_menu(struct nsgtk_global_history_window *ghwin)
{
- global_history_keypress(NS_KEY_DELETE_LEFT);
- return TRUE;
-}
+ struct menu_events *event = menu_events;
+ GtkWidget *w;
-MENUHANDLER(delete_all)
-{
- global_history_keypress(NS_KEY_SELECT_ALL);
- global_history_keypress(NS_KEY_DELETE_LEFT);
- return TRUE;
+ while (event->widget != NULL) {
+ w = GTK_WIDGET(gtk_builder_get_object(ghwin->builder,
+ event->widget));
+ if (w == NULL) {
+ LOG("Unable to connect menu widget ""%s""",
+ event->widget);
+ } else {
+ g_signal_connect(G_OBJECT(w),
+ "activate",
+ event->handler,
+ ghwin);
+ }
+ event++;
+ }
}
-MENUHANDLER(select_all)
-{
- global_history_keypress(NS_KEY_SELECT_ALL);
- return TRUE;
-}
-MENUHANDLER(clear_selection)
+/**
+ * callback for mouse action on cookie 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_global_history_mouse(struct nsgtk_corewindow *nsgtk_cw,
+ browser_mouse_state mouse_state,
+ int x, int y)
{
- global_history_keypress(NS_KEY_CLEAR_SELECTION);
- return TRUE;
-}
+ global_history_mouse_action(mouse_state, x, y);
-/* view menu*/
-MENUHANDLER(expand_all)
-{
- global_history_expand(false);
- return TRUE;
+ return NSERROR_OK;
}
-MENUHANDLER(expand_directories)
-{
- global_history_expand(true);
- return TRUE;
-}
-MENUHANDLER(expand_addresses)
+/**
+ * callback for keypress on cookie 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_global_history_key(struct nsgtk_corewindow *nsgtk_cw, uint32_t nskey)
{
- global_history_expand(false);
- return TRUE;
+ if (global_history_keypress(nskey)) {
+ return NSERROR_OK;
+ }
+ return NSERROR_NOT_IMPLEMENTED;
}
-MENUHANDLER(collapse_all)
+
+/**
+ * callback on draw event for cookie 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_global_history_draw(struct nsgtk_corewindow *nsgtk_cw, struct rect *r)
{
- global_history_contract(true);
- return TRUE;
+ struct redraw_context ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = &nsgtk_plotters
+ };
+
+ global_history_redraw(0, 0, r, &ctx);
+
+ return NSERROR_OK;
}
-MENUHANDLER(collapse_directories)
+/**
+ * Creates the window for the global history tree.
+ *
+ * \return NSERROR_OK on success else appropriate error code on faliure.
+ */
+static nserror nsgtk_global_history_init(void)
{
- global_history_contract(true);
- return TRUE;
+ struct nsgtk_global_history_window *ncwin;
+ nserror res;
+
+ if (global_history_window != NULL) {
+ return NSERROR_OK;
+ }
+
+ res = treeview_init(0);
+ if (res != NSERROR_OK) {
+ return res;
+ }
+
+ ncwin = malloc(sizeof(struct nsgtk_global_history_window));
+ if (ncwin == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ res = nsgtk_builder_new_from_resname("history", &ncwin->builder);
+ if (res != NSERROR_OK) {
+ LOG("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,
+ "globalHistoryScrolled"));
+
+ ncwin->core.drawing_area = GTK_DRAWING_AREA(
+ gtk_builder_get_object(ncwin->builder,
+ "globalHistoryDrawingArea"));
+
+ /* make the delete event hide the window */
+ g_signal_connect(G_OBJECT(ncwin->wnd),
+ "delete_event",
+ G_CALLBACK(gtk_widget_hide_on_delete),
+ NULL);
+
+ nsgtk_global_history_init_menu(ncwin);
+
+ ncwin->core.draw = nsgtk_global_history_draw;
+ ncwin->core.key = nsgtk_global_history_key;
+ ncwin->core.mouse = nsgtk_global_history_mouse;
+
+ res = nsgtk_corewindow_init(&ncwin->core);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ res = global_history_init(ncwin->core.cb_table,
+ (struct core_window *)ncwin);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ /* memoise window so it can be represented when necessary
+ * instead of recreating every time.
+ */
+ global_history_window = ncwin;
+
+ return NSERROR_OK;
}
-MENUHANDLER(collapse_addresses)
+
+/* exported function documented gtk/history.h */
+nserror nsgtk_global_history_present(void)
{
- global_history_contract(false);
- return TRUE;
+ nserror res;
+
+ res = nsgtk_global_history_init();
+ if (res == NSERROR_OK) {
+ gtk_window_present(global_history_window->wnd);
+ }
+ return res;
}
-MENUHANDLER(launch)
+
+/* exported function documented gtk/history.h */
+nserror nsgtk_global_history_destroy(void)
{
- global_history_keypress(NS_KEY_CR);
- return TRUE;
+ nserror res;
+
+ if (global_history_window == NULL) {
+ return NSERROR_OK;
+ }
+
+ res = global_history_fini();
+ if (res == NSERROR_OK) {
+ res = nsgtk_corewindow_fini(&global_history_window->core);
+ gtk_widget_destroy(GTK_WIDGET(global_history_window->wnd));
+ g_object_unref(G_OBJECT(global_history_window->builder));
+ free(global_history_window);
+ global_history_window = NULL;
+ }
+
+ return res;
+
}
+
+
+
diff --git a/frontends/gtk/history.h b/frontends/gtk/history.h
index c0f7db2bd..996e0fdd8 100644
--- a/frontends/gtk/history.h
+++ b/frontends/gtk/history.h
@@ -17,23 +17,25 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file
+ * Interface to GTK global history manager
+ */
+
#ifndef __NSGTK_HISTORY_H__
#define __NSGTK_HISTORY_H__
-#include <gtk/gtk.h>
-
-extern GtkWindow *wndHistory;
-
/**
- * Creates the window for the global history tree.
+ * make the global history window visible.
*
- * \return NSERROR_OK on sucess else appropriate error code.
+ * \return NSERROR_OK on success else appropriate error code on faliure.
*/
-nserror nsgtk_history_init(void);
+nserror nsgtk_global_history_present(void);
/**
- * Free global resources associated with the gtk history window.
+ * Destroys the global history window and performs any other necessary cleanup
+ * actions.
*/
-void nsgtk_history_destroy(void);
+nserror nsgtk_global_history_destroy(void);
-#endif /* __NSGTK_HISTORY_H__ */
+#endif
diff --git a/frontends/gtk/scaffolding.c b/frontends/gtk/scaffolding.c
index 811c84444..3c47b4df1 100644
--- a/frontends/gtk/scaffolding.c
+++ b/frontends/gtk/scaffolding.c
@@ -1496,9 +1496,11 @@ MULTIHANDLER(localhistory)
MULTIHANDLER(globalhistory)
{
- gtk_widget_show(GTK_WIDGET(wndHistory));
- gdk_window_raise(nsgtk_widget_get_window(GTK_WIDGET(wndHistory)));
-
+ nserror res;
+ res = nsgtk_global_history_present();
+ if (res != NSERROR_OK) {
+ LOG("Unable to initialise global history window.");
+ }
return TRUE;
}