Start tidying up Amiga event-handling code

As we used a shared message port, we call different event-handling functions for different window types.
This changes that so we register the event-handler as a callback so we can handle event processing for all windows generically.
Currently the main browser window and find window use the new approach, so the handling still has a long list of window types.
This should also make window_list private to gui.c
This commit is contained in:
Chris Young 2016-12-30 00:59:12 +00:00
parent 7ca75a4cee
commit 9379a64c6d
4 changed files with 686 additions and 613 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
/*
* Copyright 2008-2015 Chris Young <chris@unsatisfactorysoftware.co.uk>
* Copyright 2008-2016 Chris Young <chris@unsatisfactorysoftware.co.uk>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@ -91,8 +91,27 @@ struct history_window;
#define AMI_GUI_TOOLBAR_MAX 20
struct gui_window_2 {
struct ami_win_event_table {
/* callback to handle events when using a shared msgport
*
* @param pointer to our window structure (must start with ami_generic_window)
* @return TRUE if window was destroyed during event processing
*/
BOOL (*event)(void *w);
/* callback for explicit window closure
* some windows are implicitly closed by the browser and should set this to NULL
*/
void (*close)(void *w);
};
struct ami_generic_window {
struct nsObject *node;
struct ami_win_event_table *tbl;
};
struct gui_window_2 {
struct ami_generic_window w;
struct Window *win;
Object *restrict objects[GID_LAST];
struct gui_window *gw; /* currently-displayed gui_window */
@ -203,9 +222,9 @@ void ami_gui_set_scale(struct gui_window *gw, float scale);
/**
* Close a window and all tabs attached to it.
*
* @param gwin gui_window_2 to act upon.
* @param w gui_window_2 to act upon.
*/
void ami_gui_close_window(struct gui_window_2 *gwin);
void ami_gui_close_window(void *w);
/**
* Close all tabs in a window except the active one.
@ -253,5 +272,15 @@ void ami_gui_set_default_gg(void);
* Switch to the most-recently-opened tab
*/
void ami_gui_switch_to_new_tab(struct gui_window_2 *gwin);
/**
* Add a window to the NetSurf window list (to enable event processing)
*/
nserror ami_gui_win_list_add(void *win, int type, struct ami_win_event_table *table);
/**
* Remove a window from the NetSurf window list
*/
void ami_gui_win_list_remove(void *win);
#endif

View File

@ -69,7 +69,7 @@
static bool search_insert;
struct find_window {
struct nsObject *node;
struct ami_generic_window w;
struct Window *win;
Object *objects[GID_LAST];
struct gui_window *gwin;
@ -84,6 +84,7 @@ static void ami_search_set_hourglass(bool active, void *p);
static void ami_search_add_recent(const char *string, void *p);
static void ami_search_set_forward_state(bool active, void *p);
static void ami_search_set_back_state(bool active, void *p);
static BOOL ami_search_event(void *w);
static struct gui_search_table search_table = {
ami_search_set_status,
@ -93,6 +94,11 @@ static struct gui_search_table search_table = {
ami_search_set_back_state,
};
static struct ami_win_event_table ami_search_table = {
ami_search_event,
NULL, /* we don't explicitly close the search window n the frontend */
};
struct gui_search_table *amiga_search_table = &search_table;
struct gui_window *ami_search_get_gwin(struct find_window *fw)
@ -184,8 +190,7 @@ void ami_search_open(struct gui_window *gwin)
fwin->win = (struct Window *)RA_OpenWindow(fwin->objects[OID_MAIN]);
fwin->gwin = gwin;
fwin->node = AddObject(window_list,AMINS_FINDWINDOW);
fwin->node->objstruct = fwin;
ami_gui_win_list_add(fwin, AMINS_FINDWINDOW, &ami_search_table);
gwin->shared->searchwin = fwin;
ActivateLayoutGadget((struct Gadget *)fwin->objects[GID_MAIN], fwin->win,
@ -197,11 +202,11 @@ void ami_search_close(void)
browser_window_search_clear(fwin->gwin->bw);
fwin->gwin->shared->searchwin = NULL;
DisposeObject(fwin->objects[OID_MAIN]);
DelObject(fwin->node);
fwin=NULL;
ami_gui_win_list_remove(fwin);
fwin = NULL;
}
BOOL ami_search_event(void)
static BOOL ami_search_event(void *w)
{
/* return TRUE if window destroyed */
ULONG result;

View File

@ -31,11 +31,6 @@ struct gui_search_table *amiga_search_table;
*/
void ami_search_open(struct gui_window *gwin);
/**
* Process search events
*/
BOOL ami_search_event(void);
/**
* Close search
*/