cleanup scaffolding a bit

This commit is contained in:
Vincent Sanders 2019-09-01 15:43:19 +01:00 committed by Daniel Silverstone
parent 2e8861dc05
commit 85b65921ed
6 changed files with 182 additions and 166 deletions

View File

@ -17,67 +17,32 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "utils/utils.h"
#include "utils/dirent.h"
#include "utils/messages.h"
#include "utils/corestrings.h"
#include "utils/log.h"
#include "utils/nsoption.h"
#include "utils/file.h"
#include "utils/nsurl.h"
#include "netsurf/content.h"
#include "netsurf/keypress.h"
#include "utils/messages.h"
#include "utils/nsoption.h"
#include "netsurf/browser_window.h"
#include "netsurf/plotters.h"
#include "desktop/browser_history.h"
#include "desktop/hotlist.h"
#include "desktop/print.h"
#include "desktop/save_complete.h"
#ifdef WITH_PDF_EXPORT
#include "desktop/font_haru.h"
#include "desktop/save_pdf.h"
#endif
#include "desktop/save_text.h"
#include "desktop/searchweb.h"
#include "desktop/search.h"
#include "gtk/compat.h"
#include "gtk/warn.h"
#include "gtk/cookies.h"
#include "gtk/completion.h"
#include "gtk/preferences.h"
#include "gtk/about.h"
#include "gtk/viewsource.h"
#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"
#include "gtk/plotters.h"
#include "gtk/print.h"
#include "gtk/search.h"
#include "gtk/throbber.h"
#include "gtk/toolbar_items.h"
#include "gtk/toolbar.h"
#include "gtk/menu.h"
#include "gtk/local_history.h"
#include "gtk/download.h"
#include "gtk/gui.h"
#include "gtk/window.h"
#include "gtk/gdk.h"
#include "gtk/scaffolding.h"
#include "gtk/completion.h"
#include "gtk/tabs.h"
#include "gtk/viewdata.h"
#include "gtk/search.h"
#include "gtk/resources.h"
#include "gtk/layout_pango.h"
#include "gtk/scaffolding.h"
/**
@ -131,7 +96,9 @@ struct nsgtk_scaffolding {
*/
static struct nsgtk_scaffolding *scaf_current;
/** global list for interface changes */
/**
* global list for interface changes
*/
static struct nsgtk_scaffolding *scaf_list = NULL;
/**
@ -410,6 +377,7 @@ nsgtk_window_edit_menu_hidden(GtkWidget *widget,
return TRUE;
}
/**
* gtk event handler for popup menu being hidden.
*
@ -417,43 +385,14 @@ nsgtk_window_edit_menu_hidden(GtkWidget *widget,
* \param g scaffolding handle
* \return TRUE to indicate event handled
*/
static gboolean nsgtk_window_popup_menu_hidden(GtkWidget *widget,
struct nsgtk_scaffolding *g)
static gboolean
nsgtk_window_popup_menu_hidden(GtkWidget *widget, struct nsgtk_scaffolding *g)
{
nsgtk_scaffolding_enable_edit_actions_sensitivity(g);
return TRUE;
}
/**
* update handler for URL entry widget
*
* \param widget The widget receiving the delete event
* \param event The event
* \param data The context pointer passed when the connection was made.
* \return TRUE to indicate signal handled.
*/
gboolean
nsgtk_window_url_changed(GtkWidget *widget,
GdkEventKey *event,
gpointer data)
{
return nsgtk_completion_update(GTK_ENTRY(widget));
}
/* exported interface documented in gtk/scaffolding.h */
nserror nsgtk_scaffolding_toolbar_context_menu(struct nsgtk_scaffolding *gs)
{
/* set visibility for right-click popup menu */
popup_menu_hide(gs->menu_popup, true, false, true, false);
popup_menu_show(gs->menu_popup, false, false, false, true);
nsgtk_menu_popup_at_pointer(gs->menu_popup->popup_menu, NULL);
return NSERROR_OK;
}
/**
* Update the menus when the number of tabs changes.
*
@ -615,8 +554,6 @@ MENUHANDLER(paste, PASTE_BUTTON);
*/
MENUHANDLER(delete, DELETE_BUTTON);
/**
* menu signal handler for activation on selectall item
*/
@ -1092,6 +1029,7 @@ nsgtk_new_scaffolding_popup(struct nsgtk_scaffolding *g, GtkAccelGroup *group)
return nmenu;
}
/**
* Create and connect handlers to link popup menu.
*
@ -1139,14 +1077,6 @@ nsgtk_new_scaffolding_link_popup(struct nsgtk_scaffolding *g,
return nmenu;
}
/* exported interface documented in gtk/scaffolding.h */
struct nsgtk_scaffolding *nsgtk_current_scaffolding(void)
{
if (scaf_current == NULL) {
scaf_current = scaf_list;
}
return scaf_current;
}
/**
* initialiase the menu signal handlers ready for connection
@ -1273,6 +1203,49 @@ static void nsgtk_menu_set_sensitivity(struct nsgtk_scaffolding *g)
gtk_widget_set_sensitive(GTK_WIDGET(g->menu_bar->view_submenu->images_menuitem), FALSE);
}
/**
* create and initialise menus
*/
nserror nsgtk_menus_create(struct nsgtk_scaffolding *gs)
{
GtkMenuShell *menushell;
GtkAccelGroup *group;
menushell = GTK_MENU_SHELL(gtk_builder_get_object(gs->builder,
"menubar"));
group = gtk_accel_group_new();
gtk_window_add_accel_group(gs->window, group);
gs->menu_bar = nsgtk_menu_bar_create(menushell, group);
/* toolbar URL bar menu bar search bar signal handlers */
g_signal_connect(gs->menu_bar->edit_submenu->edit,
"show",
G_CALLBACK(nsgtk_window_edit_menu_shown),
gs);
g_signal_connect(gs->menu_bar->edit_submenu->edit,
"hide",
G_CALLBACK(nsgtk_window_edit_menu_hidden),
gs);
/* create popup menu */
gs->menu_popup = nsgtk_new_scaffolding_popup(gs, group);
gs->link_menu = nsgtk_new_scaffolding_link_popup(gs, group);
/* set up the menu signal handlers */
nsgtk_menu_initialise(gs);
nsgtk_menu_connect_signals(gs);
nsgtk_menu_set_sensitivity(gs);
return NSERROR_OK;
}
/**
* update search toolbar size and style
*/
@ -1388,6 +1361,16 @@ static nserror nsgtk_search_connect_signals(struct nsgtk_scaffolding *gs)
}
/* exported interface documented in gtk/scaffolding.h */
struct nsgtk_scaffolding *nsgtk_current_scaffolding(void)
{
if (scaf_current == NULL) {
scaf_current = scaf_list;
}
return scaf_current;
}
/* exported interface documented in gtk/scaffolding.h */
void nsgtk_scaffolding_toolbars(struct nsgtk_scaffolding *g)
{
@ -1396,7 +1379,6 @@ void nsgtk_scaffolding_toolbars(struct nsgtk_scaffolding *g)
}
/* exported function documented in gtk/scaffolding.h */
void nsgtk_window_set_title(struct gui_window *gw, const char *title)
{
@ -1515,6 +1497,7 @@ struct nsgtk_scaffolding *nsgtk_scaffolding_iterate(struct nsgtk_scaffolding *g)
return g->next;
}
/* exported interface documented in gtk/scaffolding.h */
void nsgtk_scaffolding_reset_offset(struct nsgtk_scaffolding *g)
{
@ -1522,6 +1505,13 @@ void nsgtk_scaffolding_reset_offset(struct nsgtk_scaffolding *g)
}
/* exported interface documented in gtk/scaffolding.h */
struct gui_window *nsgtk_scaffolding_top_level(struct nsgtk_scaffolding *g)
{
return g->top_level;
}
/* exported interface documented in gtk/scaffolding.h */
void nsgtk_scaffolding_toggle_search_bar_visibility(struct nsgtk_scaffolding *g)
{
@ -1541,11 +1531,6 @@ void nsgtk_scaffolding_toggle_search_bar_visibility(struct nsgtk_scaffolding *g)
}
}
/* exported interface documented in gtk/scaffolding.h */
struct gui_window *nsgtk_scaffolding_top_level(struct nsgtk_scaffolding *g)
{
return g->top_level;
}
/* exported interface documented in gtk/scaffolding.h */
void nsgtk_scaffolding_set_top_level(struct gui_window *gw)
@ -1572,9 +1557,9 @@ void nsgtk_scaffolding_set_top_level(struct gui_window *gw)
/* Ensure the window's title bar is updated */
nsgtk_window_set_title(gw, browser_window_get_title(bw));
}
/* exported interface documented in scaffolding.h */
void nsgtk_scaffolding_set_sensitivity(struct nsgtk_scaffolding *g)
{
@ -1607,9 +1592,23 @@ void nsgtk_scaffolding_set_sensitivity(struct nsgtk_scaffolding *g)
/* exported interface documented in gtk/scaffolding.h */
void nsgtk_scaffolding_context_menu(struct nsgtk_scaffolding *g,
gdouble x,
gdouble y)
nserror nsgtk_scaffolding_toolbar_context_menu(struct nsgtk_scaffolding *gs)
{
/* set visibility for right-click popup menu */
popup_menu_hide(gs->menu_popup, true, false, true, false);
popup_menu_show(gs->menu_popup, false, false, false, true);
nsgtk_menu_popup_at_pointer(gs->menu_popup->popup_menu, NULL);
return NSERROR_OK;
}
/* exported interface documented in gtk/scaffolding.h */
void
nsgtk_scaffolding_context_menu(struct nsgtk_scaffolding *g,
gdouble x,
gdouble y)
{
GtkMenu *gtkmenu;
struct browser_window *bw;
@ -1653,13 +1652,11 @@ void nsgtk_scaffolding_context_menu(struct nsgtk_scaffolding *g,
}
/* exported interface documented in gtk/scaffolding.h */
struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
{
nserror res;
struct nsgtk_scaffolding *gs;
GtkAccelGroup *group;
gs = calloc(1, sizeof(*gs));
if (gs == NULL) {
@ -1679,25 +1676,13 @@ struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
gtk_builder_connect_signals(gs->builder, NULL);
/* containing window setup */
gs->window = GTK_WINDOW(gtk_builder_get_object(gs->builder,
"wndBrowser"));
gs->notebook = GTK_NOTEBOOK(gtk_builder_get_object(gs->builder,
"notebook"));
res = nsgtk_search_create(gs->builder, &gs->search);
if (res != NSERROR_OK) {
free(gs);
return NULL;
}
group = gtk_accel_group_new();
gtk_window_add_accel_group(gs->window, group);
gs->menu_bar = nsgtk_menu_bar_create(GTK_MENU_SHELL(gtk_builder_get_object(gs->builder, "menubar")), group);
/* set this window's size and position to what's in the options, or
* or some sensible default if they're not set yet.
/**
* set this window's size and position to what's in the options, or
* some sensible default if they are not set yet.
*/
if (nsoption_int(window_width) > 0) {
gtk_window_move(gs->window,
@ -1714,19 +1699,6 @@ struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
gtk_window_set_default_size(gs->window, 1000, 700);
}
nsgtk_tab_init(gs);
g_signal_connect_after(gs->notebook,
"page-added",
G_CALLBACK(nsgtk_window_tabs_add),
gs);
g_signal_connect_after(gs->notebook,
"page-removed",
G_CALLBACK(nsgtk_window_tabs_remove),
gs);
/* connect main window signals to their handlers. */
g_signal_connect(gs->window,
"delete-event",
G_CALLBACK(scaffolding_window_delete_event),
@ -1737,28 +1709,38 @@ struct nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
G_CALLBACK(scaffolding_window_destroy),
gs);
/* toolbar URL bar menu bar search bar signal handlers */
g_signal_connect(gs->menu_bar->edit_submenu->edit,
"show",
G_CALLBACK(nsgtk_window_edit_menu_shown),
gs);
g_signal_connect(gs->menu_bar->edit_submenu->edit,
"hide",
G_CALLBACK(nsgtk_window_edit_menu_hidden),
gs);
/* notebook */
res = nsgtk_notebook_create(gs->builder, &gs->notebook);
if (res != NSERROR_OK) {
free(gs);
return NULL;
}
g_signal_connect_after(gs->notebook,
"page-added",
G_CALLBACK(nsgtk_window_tabs_add),
gs);
g_signal_connect_after(gs->notebook,
"page-removed",
G_CALLBACK(nsgtk_window_tabs_remove),
gs);
/* local page text search */
res = nsgtk_search_create(gs->builder, &gs->search);
if (res != NSERROR_OK) {
free(gs);
return NULL;
}
nsgtk_search_connect_signals(gs);
/* create popup menu */
gs->menu_popup = nsgtk_new_scaffolding_popup(gs, group);
gs->link_menu = nsgtk_new_scaffolding_link_popup(gs, group);
/* set up the menu signal handlers */
nsgtk_menu_initialise(gs);
nsgtk_menu_connect_signals(gs);
nsgtk_menu_set_sensitivity(gs);
res = nsgtk_menus_create(gs);
if (res != NSERROR_OK) {
free(gs);
return NULL;
}
/* attach to the list */
if (scaf_list) {

View File

@ -163,8 +163,6 @@ void nsgtk_scaffolding_set_sensitivity(struct nsgtk_scaffolding *g);
*/
void nsgtk_scaffolding_context_menu(struct nsgtk_scaffolding *g, gdouble x, gdouble y);
gboolean nsgtk_window_url_changed(GtkWidget *, GdkEventKey *, gpointer);
/* core acessors */
/**
* set the title in the window

View File

@ -318,28 +318,40 @@ void nsgtk_tab_options_changed(GtkNotebook *notebook)
/* exported interface documented in gtk/tabs.h */
void nsgtk_tab_init(struct nsgtk_scaffolding *gs)
nserror nsgtk_notebook_create(GtkBuilder *builder, GtkNotebook **notebook_out)
{
GtkNotebook *notebook;
notebook = nsgtk_scaffolding_notebook(gs);
notebook = GTK_NOTEBOOK(gtk_builder_get_object(builder, "notebook"));
nsgtk_tab_add_newtab(notebook);
g_signal_connect(notebook, "switch-page",
G_CALLBACK(nsgtk_tab_switch_page), NULL);
g_signal_connect_after(notebook, "switch-page",
G_CALLBACK(nsgtk_tab_switch_page_after), NULL);
g_signal_connect(notebook, "page-removed",
G_CALLBACK(nsgtk_tab_visibility_update), NULL);
g_signal_connect(notebook, "page-added",
G_CALLBACK(nsgtk_tab_visibility_update), NULL);
g_signal_connect(notebook, "page-reordered",
G_CALLBACK(nsgtk_tab_page_reordered), NULL);
g_signal_connect(notebook,
"switch-page",
G_CALLBACK(nsgtk_tab_switch_page),
NULL);
g_signal_connect_after(notebook,
"switch-page",
G_CALLBACK(nsgtk_tab_switch_page_after),
NULL);
g_signal_connect(notebook,
"page-removed",
G_CALLBACK(nsgtk_tab_visibility_update),
NULL);
g_signal_connect(notebook,
"page-added",
G_CALLBACK(nsgtk_tab_visibility_update),
NULL);
g_signal_connect(notebook,
"page-reordered",
G_CALLBACK(nsgtk_tab_page_reordered),
NULL);
nsgtk_tab_options_changed(notebook);
*notebook_out = notebook;
return NSERROR_OK;
}
/* exported interface documented in gtk/tabs.h */

View File

@ -21,7 +21,17 @@
struct gui_window;
void nsgtk_tab_init(struct nsgtk_scaffolding *gs);
/**
* create notebook
*
* creates a notebook for use inside a window, creates the special add
* page(tab) and attaches all signals.
*
* \param builder the gtk builder object to create notbook from
* \param notebook_out reciveds the created notebook
* \return NSERROR_OK and notebook_out updated else error code
*/
nserror nsgtk_notebook_create(GtkBuilder *builder, GtkNotebook **notebook_out);
/**
* Add new tab to notebook.

View File

@ -196,6 +196,10 @@ struct nsgtk_theme {
GtkImage *searchimage[SEARCH_BUTTONS_COUNT];
};
/* forward declaration */
void nsgtk_toolbar_connect_all(struct nsgtk_scaffolding *g);
int nsgtk_toolbar_get_id_from_widget(GtkWidget *widget, struct nsgtk_scaffolding *g);
/* define data plus and data minus handlers */
#define TOOLBAR_ITEM(identifier, name, sensitivity, clicked) \

View File

@ -23,7 +23,7 @@
* control toolbar context
*/
struct nsgtk_toolbar;
struct nsgtk_scaffolding;
/**
* create a control toolbar
@ -52,6 +52,7 @@ nserror nsgtk_toolbar_destroy(struct nsgtk_toolbar *toolbar);
*/
nserror nsgtk_toolbar_update(struct nsgtk_toolbar *tb);
/**
* Start or stop a throbber in a toolbar
*
@ -61,6 +62,7 @@ nserror nsgtk_toolbar_update(struct nsgtk_toolbar *tb);
*/
nserror nsgtk_toolbar_throbber(struct nsgtk_toolbar *tb, bool active);
/**
* Update the toolbar url entry
*
@ -70,16 +72,22 @@ nserror nsgtk_toolbar_throbber(struct nsgtk_toolbar *tb, bool active);
*/
nserror nsgtk_toolbar_set_url(struct nsgtk_toolbar *tb, nsurl *url);
/**
* set the websearch image
*
* \param toolbar A toolbar returned from a creation
* \param pixbuf The pixel buffer data to use to set the web search icon
* \return NSERROR_OK on success
*/
nserror nsgtk_toolbar_set_websearch_image(struct nsgtk_toolbar *tb, GdkPixbuf *pixbuf);
/**
* activate the handler for a toolbar item
*
* This allows the same action to be performed for menu enties as if
* the user had clicked the toolbar widget.
* the user had clicked the toolbar widget.
*
* \param toolbar A toolbar returned from a creation
* \param itemid the id of the item to activate
@ -87,14 +95,16 @@ nserror nsgtk_toolbar_set_websearch_image(struct nsgtk_toolbar *tb, GdkPixbuf *p
*/
nserror nsgtk_toolbar_item_activate(struct nsgtk_toolbar *tb, nsgtk_toolbar_button itemid);
/**
* sets up the images for scaffolding.
*/
void nsgtk_theme_implement(struct nsgtk_scaffolding *g);
/**
* Initialise customization of toolbar entries
*/
void nsgtk_toolbar_customization_init(struct nsgtk_scaffolding *g);
void nsgtk_toolbar_connect_all(struct nsgtk_scaffolding *g);
int nsgtk_toolbar_get_id_from_widget(GtkWidget *widget, struct nsgtk_scaffolding *g);
#endif