diff options
author | Vincent Sanders <vince@kyllikki.org> | 2014-01-11 14:20:30 +0000 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2014-01-11 14:20:30 +0000 |
commit | d3c392c3d3b516f05fbf71020b2f6774ce20ce8c (patch) | |
tree | bad0d50f6d2d7bfc52774745ce10e69ce0ff5bff /desktop | |
parent | a856439afb743c7fa16f51108862b99a1f56c82a (diff) | |
download | netsurf-d3c392c3d3b516f05fbf71020b2f6774ce20ce8c.tar.gz netsurf-d3c392c3d3b516f05fbf71020b2f6774ce20ce8c.tar.bz2 |
Initial conversion of netsurf gui to callback vtable
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/Makefile | 2 | ||||
-rw-r--r-- | desktop/gui.h | 36 | ||||
-rw-r--r-- | desktop/gui_factory.c | 33 | ||||
-rw-r--r-- | desktop/gui_factory.h | 30 | ||||
-rw-r--r-- | desktop/netsurf.c | 12 | ||||
-rw-r--r-- | desktop/netsurf.h | 4 |
6 files changed, 101 insertions, 16 deletions
diff --git a/desktop/Makefile b/desktop/Makefile index f7020074e..0e2e460de 100644 --- a/desktop/Makefile +++ b/desktop/Makefile @@ -13,7 +13,7 @@ desktop/version.c: testament utils/testament.h # S_BROWSER are sources related to full browsers but are common # between RISC OS, GTK, BeOS and AmigaOS builds S_BROWSER := browser.c download.c frames.c local_history.c netsurf.c \ - save_complete.c save_text.c selection.c textinput.c + save_complete.c save_text.c selection.c textinput.c gui_factory.c S_BROWSER := $(addprefix desktop/,$(S_BROWSER)) diff --git a/desktop/gui.h b/desktop/gui.h index 9317e8576..2bda996fd 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -24,6 +24,18 @@ #ifndef _NETSURF_DESKTOP_GUI_H_ #define _NETSURF_DESKTOP_GUI_H_ +#include <stdbool.h> + +#include <libwapcaplet/libwapcaplet.h> +#include <libcss/libcss.h> + +#include "utils/config.h" +#include "content/hlcache.h" +#include "desktop/download.h" +#include "desktop/mouse.h" +#include "desktop/search.h" +#include "utils/errors.h" + typedef enum { GUI_SAVE_SOURCE, GUI_SAVE_DRAW, @@ -53,20 +65,22 @@ struct gui_download_window; struct browser_window; struct form_control; -#include <stdbool.h> +/** Graphical user interface function table + * + * function table implementing GUI interface to browser core + */ +struct gui_table { + /** called to let the frontend update its state and run any + * I/O operations. + */ + void (*poll)(bool active); /* Mandantory */ -#include <libwapcaplet/libwapcaplet.h> -#include <libcss/libcss.h> + /** called to allow the gui to cleanup */ + void (*quit)(void); /* optional */ -#include "utils/config.h" -#include "content/hlcache.h" -#include "desktop/download.h" -#include "desktop/mouse.h" -#include "desktop/search.h" -#include "utils/errors.h" +}; -void gui_poll(bool active); -void gui_quit(void); +extern struct gui_table *guit; /* the gui vtable */ struct gui_window *gui_create_browser_window(struct browser_window *bw, struct browser_window *clone, bool new_tab); diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c new file mode 100644 index 000000000..fe7536353 --- /dev/null +++ b/desktop/gui_factory.c @@ -0,0 +1,33 @@ + +#include "desktop/gui.h" +#include "desktop/gui_factory.h" + +struct gui_table *guit = NULL; + + +static void gui_default_quit(void) +{ +} + +nserror gui_factory_register(struct gui_table *gt) +{ + /* ensure not already initialised */ + if (guit != NULL) { + return NSERROR_INIT_FAILED; + } + + /* check the mandantory fields are set */ + + if (gt->poll == NULL) { + return NSERROR_BAD_PARAMETER; + } + + /* fill in the optional entries with defaults */ + if (gt->quit == NULL) { + gt->quit = &gui_default_quit; + } + + guit = gt; + + return NSERROR_OK; +} diff --git a/desktop/gui_factory.h b/desktop/gui_factory.h new file mode 100644 index 000000000..66303eac1 --- /dev/null +++ b/desktop/gui_factory.h @@ -0,0 +1,30 @@ +/* + * Copyright 2014 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 + * Interface to gui interface factory + */ + +#ifndef _NETSURF_DESKTOP_GUI_FACTORY_H_ +#define _NETSURF_DESKTOP_GUI_FACTORY_H_ + +struct gui_table; + +nserror gui_factory_register(struct gui_table *gt); + +#endif diff --git a/desktop/netsurf.c b/desktop/netsurf.c index 36b0b589a..10dc7ba68 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -41,6 +41,7 @@ #include "desktop/browser.h" #include "desktop/system_colour.h" #include "desktop/gui.h" +#include "desktop/gui_factory.h" #include "utils/nsoption.h" #include "desktop/searchweb.h" @@ -116,7 +117,7 @@ static nserror netsurf_llcache_query_handler(const llcache_query *query, * Initialise components used by gui NetSurf. */ -nserror netsurf_init(const char *messages) +nserror netsurf_init(const char *messages, struct gui_table *gt) { nserror error; struct utsname utsname; @@ -150,6 +151,11 @@ nserror netsurf_init(const char *messages) utsname.nodename, utsname.release, utsname.version, utsname.machine)); + /* register the gui handlers */ + error = gui_factory_register(gt); + if (error != NSERROR_OK) + return error; + messages_load(messages); /* corestrings init */ @@ -228,7 +234,7 @@ nserror netsurf_init(const char *messages) int netsurf_main_loop(void) { while (!netsurf_quit) { - gui_poll(fetch_active); + guit->poll(fetch_active); hlcache_poll(); } @@ -244,7 +250,7 @@ void netsurf_exit(void) hlcache_stop(); LOG(("Closing GUI")); - gui_quit(); + guit->quit(); LOG(("Finalising JavaScript")); js_finalise(); diff --git a/desktop/netsurf.h b/desktop/netsurf.h index aa1796f7c..e6858ad66 100644 --- a/desktop/netsurf.h +++ b/desktop/netsurf.h @@ -28,8 +28,10 @@ extern const char * const netsurf_version; extern const int netsurf_version_major; extern const int netsurf_version_minor; +struct gui_table; + /** Initialise netsurf core */ -nserror netsurf_init(const char *messages); +nserror netsurf_init(const char *messages, struct gui_table *gt); /** Run primary event loop */ extern int netsurf_main_loop(void); |