use toolbar_items to generate more boilerplate code through macros

This commit is contained in:
Vincent Sanders 2019-09-03 19:33:22 +01:00 committed by Daniel Silverstone
parent ec62f346e1
commit 64b2f355dc
3 changed files with 90 additions and 269 deletions

View File

@ -459,221 +459,21 @@ nsgtk_window_tabs_remove(GtkNotebook *notebook,
/**
* handle menu activate signals by calling toolbar item activation
*/
#define MENUHANDLER(name, itemid) \
#define TOOLBAR_ITEM_y(identifier, name) \
static gboolean \
nsgtk_on_##name##_activate_menu(GtkMenuItem *widget, gpointer data) \
{ \
struct nsgtk_scaffolding *gs = (struct nsgtk_scaffolding *)data;\
nsgtk_window_item_activate(gs->top_level, itemid); \
nsgtk_window_item_activate(gs->top_level, identifier); \
return TRUE; \
}
/**
* menu signal handler for activation on new window item
*/
MENUHANDLER(newwindow, NEWWINDOW_BUTTON);
/**
* menu signal handler for activation on new tab item
*/
MENUHANDLER(newtab, NEWTAB_BUTTON);
/**
* menu signal handler for activation on open file item
*/
MENUHANDLER(openfile, OPENFILE_BUTTON);
/**
* menu signal handler for activation on export complete page item
*/
MENUHANDLER(savepage, SAVEPAGE_BUTTON);
/**
* menu signal handler for activation on export pdf item
*/
MENUHANDLER(pdf, PDF_BUTTON);
/**
* menu signal handler for activation on export plain text item
*/
MENUHANDLER(plaintext, PLAINTEXT_BUTTON);
/**
* menu signal handler for activation on print preview item
*/
MENUHANDLER(printpreview, PRINTPREVIEW_BUTTON);
/**
* menu signal handler for activation on print item
*/
MENUHANDLER(print, PRINT_BUTTON);
/**
* menu signal handler for activation on close window item
*/
MENUHANDLER(closewindow, CLOSEWINDOW_BUTTON);
/**
* menu signal handler for activation on close window item
*/
MENUHANDLER(quit, QUIT_BUTTON);
/**
* menu signal handler for activation on cut item
*/
MENUHANDLER(cut, CUT_BUTTON);
/**
* menu signal handler for activation on copy item
*/
MENUHANDLER(copy, COPY_BUTTON);
/**
* menu signal handler for activation on paste item
*/
MENUHANDLER(paste, PASTE_BUTTON);
/**
* menu signal handler for activation on delete item
*/
MENUHANDLER(delete, DELETE_BUTTON);
/**
* menu signal handler for activation on selectall item
*/
MENUHANDLER(selectall, SELECTALL_BUTTON);
/**
* menu signal handler for activation on preferences item
*/
MENUHANDLER(preferences, PREFERENCES_BUTTON);
/**
* menu signal handler for activation on zoom plus item
*/
MENUHANDLER(zoomplus, ZOOMPLUS_BUTTON);
/**
* menu signal handler for activation on zoom minus item
*/
MENUHANDLER(zoomminus, ZOOMMINUS_BUTTON);
/**
* menu signal handler for activation on zoom normal item
*/
MENUHANDLER(zoomnormal, ZOOMNORMAL_BUTTON);
/**
* menu signal handler for activation on full screen item
*/
MENUHANDLER(fullscreen, FULLSCREEN_BUTTON);
/**
* menu signal handler for activation on view source item
*/
MENUHANDLER(viewsource, VIEWSOURCE_BUTTON);
/**
* menu signal handler for activation on downloads item
*/
MENUHANDLER(downloads, DOWNLOADS_BUTTON);
/**
* menu signal handler for activation on save window size item
*/
MENUHANDLER(savewindowsize, SAVEWINDOWSIZE_BUTTON);
/**
* menu signal handler for activation on toggle debug render item
*/
MENUHANDLER(toggledebugging, TOGGLEDEBUGGING_BUTTON);
/**
* menu signal handler for activation on debug box tree item
*/
MENUHANDLER(debugboxtree, SAVEBOXTREE_BUTTON);
/**
* menu signal handler for activation on debug dom tree item
*/
MENUHANDLER(debugdomtree, SAVEDOMTREE_BUTTON);
/**
* menu signal handler for activation on stop item
*/
MENUHANDLER(stop, STOP_BUTTON);
/**
* menu signal handler for activation on reload item
*/
MENUHANDLER(reload, RELOAD_BUTTON);
/**
* menu signal handler for activation on back item
*/
MENUHANDLER(back, BACK_BUTTON);
/**
* menu signal handler for activation on forward item
*/
MENUHANDLER(forward, FORWARD_BUTTON);
/**
* menu signal handler for activation on home item
*/
MENUHANDLER(home, HOME_BUTTON);
/**
* menu signal handler for activation on localhistory item
*/
MENUHANDLER(localhistory, LOCALHISTORY_BUTTON);
/**
* menu signal handler for activation on globalhistory item
*/
MENUHANDLER(globalhistory, GLOBALHISTORY_BUTTON);
/**
* menu signal handler for activation on addbookmarks item
*/
MENUHANDLER(addbookmarks, ADDBOOKMARKS_BUTTON);
/**
* menu signal handler for activation on showbookmarks item
*/
MENUHANDLER(showbookmarks, SHOWBOOKMARKS_BUTTON);
/**
* menu signal handler for activation on showcookies item
*/
MENUHANDLER(showcookies, SHOWCOOKIES_BUTTON);
/**
* menu signal handler for activation on showcookies item
*/
MENUHANDLER(openlocation, OPENLOCATION_BUTTON);
/**
* menu signal handler for activation on showcookies item
*/
MENUHANDLER(contents, CONTENTS_BUTTON);
/**
* menu signal handler for activation on showcookies item
*/
MENUHANDLER(guide, GUIDE_BUTTON);
/**
* menu signal handler for activation on showcookies item
*/
MENUHANDLER(info, INFO_BUTTON);
/**
* menu signal handler for activation on showcookies item
*/
MENUHANDLER(about, ABOUT_BUTTON);
#undef MENUHANDLER
#define TOOLBAR_ITEM_n(identifier, name)
#define TOOLBAR_ITEM(identifier, name, snstvty, clicked, activate) \
TOOLBAR_ITEM_ ## activate(identifier, name)
#include "gtk/toolbar_items.h"
#undef TOOLBAR_ITEM_y
#undef TOOLBAR_ITEM_n
#undef TOOLBAR_ITEM
static gboolean
@ -1081,7 +881,7 @@ create_scaffolding_link_menu(struct nsgtk_scaffolding *g, GtkAccelGroup *group)
*/
static nserror nsgtk_menu_initialise(struct nsgtk_scaffolding *g)
{
#define TOOLBAR_ITEM(identifier, name, snstvty, clicked) \
#define TOOLBAR_ITEM(identifier, name, snstvty, clicked, activate) \
g->menus[identifier].sensitivity = snstvty;
#include "gtk/toolbar_items.h"
#undef TOOLBAR_ITEM

View File

@ -202,7 +202,7 @@ int nsgtk_toolbar_get_id_from_widget(GtkWidget *widget, struct nsgtk_scaffolding
/* define data plus and data minus handlers */
#define TOOLBAR_ITEM(identifier, name, sensitivity, clicked) \
#define TOOLBAR_ITEM(identifier, name, sensitivity, clicked, activate) \
static gboolean \
nsgtk_toolbar_##name##_data_plus(GtkWidget *widget, \
GdkDragContext *cont, \
@ -3058,6 +3058,19 @@ localhistory_button_clicked_cb(GtkWidget *widget, gpointer data)
return TRUE;
}
/**
* handler for history tool bar item clicked signal
*
* \param widget The widget the signal is being delivered to.
* \param data The toolbar context passed when the signal was connected
* \return TRUE
*/
static gboolean
history_button_clicked_cb(GtkWidget *widget, gpointer data)
{
return localhistory_button_clicked_cb(widget, data);
}
/**
* handler for global history tool bar item clicked signal
@ -3283,14 +3296,20 @@ toolbar_item_create(nsgtk_toolbar_button id,
/* set item defaults from macro */
switch (id) {
#define TOOLBAR_ITEM(identifier, name, snstvty, clicked) \
#define TOOLBAR_ITEM_y(name) \
item->bhandler = name##_button_clicked_cb;
#define TOOLBAR_ITEM_n(name) \
item->bhandler = NULL;
#define TOOLBAR_ITEM(identifier, name, snstvty, clicked, activate) \
case identifier: \
item->sensitivity = snstvty; \
item->dataplus = nsgtk_toolbar_##name##_data_plus; \
item->dataminus = nsgtk_toolbar_##name##_data_minus; \
item->bhandler = clicked; \
TOOLBAR_ITEM_ ## clicked(name) \
break;
#include "gtk/toolbar_items.h"
#undef TOOLBAR_ITEM_y
#undef TOOLBAR_ITEM_n
#undef TOOLBAR_ITEM
case PLACEHOLDER_BUTTON:

View File

@ -79,68 +79,70 @@ typedef enum {
/*
* Item fields are:
* item identifier enum
* item name
* item initial visibility
* identifier enum
* name
* initial sensitivity
* if there is a toolbar click signal handler
* if the menu activate signal handler calls the toolbar click handler
*/
#ifndef TOOLBAR_ITEM
#define TOOLBAR_ITEM(a, b, c, d)
#define TOOLBAR_ITEM(a, b, c, d, e)
#define TOOLBAR_ITEM_SET
#endif
TOOLBAR_ITEM(BACK_BUTTON, back, false, back_button_clicked_cb)
TOOLBAR_ITEM(HISTORY_BUTTON, history, true, localhistory_button_clicked_cb)
TOOLBAR_ITEM(FORWARD_BUTTON, forward, false, forward_button_clicked_cb)
TOOLBAR_ITEM(STOP_BUTTON, stop, false, stop_button_clicked_cb)
TOOLBAR_ITEM(RELOAD_BUTTON, reload, true, reload_button_clicked_cb)
TOOLBAR_ITEM(HOME_BUTTON, home, true, home_button_clicked_cb)
TOOLBAR_ITEM(URL_BAR_ITEM, url_bar, true, NULL)
TOOLBAR_ITEM(WEBSEARCH_ITEM, websearch, true, NULL)
TOOLBAR_ITEM(THROBBER_ITEM, throbber, true, NULL)
TOOLBAR_ITEM(NEWWINDOW_BUTTON, newwindow, true, newwindow_button_clicked_cb)
TOOLBAR_ITEM(NEWTAB_BUTTON, newtab, true, newtab_button_clicked_cb)
TOOLBAR_ITEM(OPENFILE_BUTTON, openfile, true, openfile_button_clicked_cb)
TOOLBAR_ITEM(CLOSETAB_BUTTON, closetab, false, NULL)
TOOLBAR_ITEM(CLOSEWINDOW_BUTTON, closewindow, true, closewindow_button_clicked_cb)
TOOLBAR_ITEM(SAVEPAGE_BUTTON, savepage, true, savepage_button_clicked_cb)
TOOLBAR_ITEM(PDF_BUTTON, pdf, false, pdf_button_clicked_cb)
TOOLBAR_ITEM(PLAINTEXT_BUTTON, plaintext, true, plaintext_button_clicked_cb)
TOOLBAR_ITEM(DRAWFILE_BUTTON, drawfile, false, NULL)
TOOLBAR_ITEM(POSTSCRIPT_BUTTON, postscript, false, NULL)
TOOLBAR_ITEM(PRINTPREVIEW_BUTTON, printpreview, false, NULL)
TOOLBAR_ITEM(PRINT_BUTTON, print, true, print_button_clicked_cb)
TOOLBAR_ITEM(QUIT_BUTTON, quit, true, quit_button_clicked_cb)
TOOLBAR_ITEM(CUT_BUTTON, cut, true, cut_button_clicked_cb)
TOOLBAR_ITEM(COPY_BUTTON, copy, true, copy_button_clicked_cb)
TOOLBAR_ITEM(PASTE_BUTTON, paste, true, paste_button_clicked_cb)
TOOLBAR_ITEM(DELETE_BUTTON, delete, false, delete_button_clicked_cb)
TOOLBAR_ITEM(SELECTALL_BUTTON, selectall, true, selectall_button_clicked_cb)
TOOLBAR_ITEM(FIND_BUTTON, find, true, NULL)
TOOLBAR_ITEM(PREFERENCES_BUTTON, preferences, true, preferences_button_clicked_cb)
TOOLBAR_ITEM(ZOOMPLUS_BUTTON, zoomplus, true, zoomplus_button_clicked_cb)
TOOLBAR_ITEM(ZOOMMINUS_BUTTON, zoomminus, true, zoomminus_button_clicked_cb)
TOOLBAR_ITEM(ZOOMNORMAL_BUTTON, zoomnormal, true, zoomnormal_button_clicked_cb)
TOOLBAR_ITEM(FULLSCREEN_BUTTON, fullscreen, true, fullscreen_button_clicked_cb)
TOOLBAR_ITEM(VIEWSOURCE_BUTTON, viewsource, true, viewsource_button_clicked_cb)
TOOLBAR_ITEM(DOWNLOADS_BUTTON, downloads, true, downloads_button_clicked_cb)
TOOLBAR_ITEM(SAVEWINDOWSIZE_BUTTON, savewindowsize, true, savewindowsize_button_clicked_cb)
TOOLBAR_ITEM(TOGGLEDEBUGGING_BUTTON, toggledebugging, true, toggledebugging_button_clicked_cb)
TOOLBAR_ITEM(SAVEBOXTREE_BUTTON, debugboxtree, true, debugboxtree_button_clicked_cb)
TOOLBAR_ITEM(SAVEDOMTREE_BUTTON, debugdomtree, true, debugdomtree_button_clicked_cb)
TOOLBAR_ITEM(LOCALHISTORY_BUTTON, localhistory, true, localhistory_button_clicked_cb)
TOOLBAR_ITEM(GLOBALHISTORY_BUTTON, globalhistory, true, globalhistory_button_clicked_cb)
TOOLBAR_ITEM(ADDBOOKMARKS_BUTTON, addbookmarks, true, addbookmarks_button_clicked_cb)
TOOLBAR_ITEM(SHOWBOOKMARKS_BUTTON, showbookmarks, true, showbookmarks_button_clicked_cb)
TOOLBAR_ITEM(SHOWCOOKIES_BUTTON, showcookies, true, showcookies_button_clicked_cb)
TOOLBAR_ITEM(OPENLOCATION_BUTTON, openlocation, true, openlocation_button_clicked_cb)
TOOLBAR_ITEM(NEXTTAB_BUTTON, nexttab, false, NULL)
TOOLBAR_ITEM(PREVTAB_BUTTON, prevtab, false, NULL)
TOOLBAR_ITEM(CONTENTS_BUTTON, contents, true, contents_button_clicked_cb)
TOOLBAR_ITEM(GUIDE_BUTTON, guide, true, guide_button_clicked_cb)
TOOLBAR_ITEM(INFO_BUTTON, info, true, info_button_clicked_cb)
TOOLBAR_ITEM(ABOUT_BUTTON, about, true, about_button_clicked_cb)
TOOLBAR_ITEM(OPENMENU_BUTTON, openmenu, true, openmenu_button_clicked_cb)
TOOLBAR_ITEM(BACK_BUTTON, back, false, y, y)
TOOLBAR_ITEM(HISTORY_BUTTON, history, true, y, n)
TOOLBAR_ITEM(FORWARD_BUTTON, forward, false, y, y)
TOOLBAR_ITEM(STOP_BUTTON, stop, false, y, y)
TOOLBAR_ITEM(RELOAD_BUTTON, reload, true, y, y)
TOOLBAR_ITEM(HOME_BUTTON, home, true, y, y)
TOOLBAR_ITEM(URL_BAR_ITEM, url_bar, true, n, n)
TOOLBAR_ITEM(WEBSEARCH_ITEM, websearch, true, n, n)
TOOLBAR_ITEM(THROBBER_ITEM, throbber, true, n, n)
TOOLBAR_ITEM(NEWWINDOW_BUTTON, newwindow, true, y, y)
TOOLBAR_ITEM(NEWTAB_BUTTON, newtab, true, y, y)
TOOLBAR_ITEM(OPENFILE_BUTTON, openfile, true, y, y)
TOOLBAR_ITEM(CLOSETAB_BUTTON, closetab, false, n, n)
TOOLBAR_ITEM(CLOSEWINDOW_BUTTON, closewindow, true, y, y)
TOOLBAR_ITEM(SAVEPAGE_BUTTON, savepage, true, y, y)
TOOLBAR_ITEM(PDF_BUTTON, pdf, false, y, y)
TOOLBAR_ITEM(PLAINTEXT_BUTTON, plaintext, true, y, y)
TOOLBAR_ITEM(DRAWFILE_BUTTON, drawfile, false, n, n)
TOOLBAR_ITEM(POSTSCRIPT_BUTTON, postscript, false, n, n)
TOOLBAR_ITEM(PRINTPREVIEW_BUTTON, printpreview, false, n, y)
TOOLBAR_ITEM(PRINT_BUTTON, print, true, y, y)
TOOLBAR_ITEM(QUIT_BUTTON, quit, true, y, y)
TOOLBAR_ITEM(CUT_BUTTON, cut, true, y, y)
TOOLBAR_ITEM(COPY_BUTTON, copy, true, y, y)
TOOLBAR_ITEM(PASTE_BUTTON, paste, true, y, y)
TOOLBAR_ITEM(DELETE_BUTTON, delete, false, y, y)
TOOLBAR_ITEM(SELECTALL_BUTTON, selectall, true, y, y)
TOOLBAR_ITEM(FIND_BUTTON, find, true, n, n)
TOOLBAR_ITEM(PREFERENCES_BUTTON, preferences, true, y, y)
TOOLBAR_ITEM(ZOOMPLUS_BUTTON, zoomplus, true, y, y)
TOOLBAR_ITEM(ZOOMMINUS_BUTTON, zoomminus, true, y, y)
TOOLBAR_ITEM(ZOOMNORMAL_BUTTON, zoomnormal, true, y, y)
TOOLBAR_ITEM(FULLSCREEN_BUTTON, fullscreen, true, y, y)
TOOLBAR_ITEM(VIEWSOURCE_BUTTON, viewsource, true, y, y)
TOOLBAR_ITEM(DOWNLOADS_BUTTON, downloads, true, y, y)
TOOLBAR_ITEM(SAVEWINDOWSIZE_BUTTON, savewindowsize, true, y, y)
TOOLBAR_ITEM(TOGGLEDEBUGGING_BUTTON, toggledebugging, true, y, y)
TOOLBAR_ITEM(SAVEBOXTREE_BUTTON, debugboxtree, true, y, y)
TOOLBAR_ITEM(SAVEDOMTREE_BUTTON, debugdomtree, true, y, y)
TOOLBAR_ITEM(LOCALHISTORY_BUTTON, localhistory, true, y, y)
TOOLBAR_ITEM(GLOBALHISTORY_BUTTON, globalhistory, true, y, y)
TOOLBAR_ITEM(ADDBOOKMARKS_BUTTON, addbookmarks, true, y, y)
TOOLBAR_ITEM(SHOWBOOKMARKS_BUTTON, showbookmarks, true, y, y)
TOOLBAR_ITEM(SHOWCOOKIES_BUTTON, showcookies, true, y, y)
TOOLBAR_ITEM(OPENLOCATION_BUTTON, openlocation, true, y, y)
TOOLBAR_ITEM(NEXTTAB_BUTTON, nexttab, false, n, n)
TOOLBAR_ITEM(PREVTAB_BUTTON, prevtab, false, n, n)
TOOLBAR_ITEM(CONTENTS_BUTTON, contents, true, y, y)
TOOLBAR_ITEM(GUIDE_BUTTON, guide, true, y, y)
TOOLBAR_ITEM(INFO_BUTTON, info, true, y, y)
TOOLBAR_ITEM(ABOUT_BUTTON, about, true, y, y)
TOOLBAR_ITEM(OPENMENU_BUTTON, openmenu, true, y, n)
#ifdef TOOLBAR_ITEM_SET
#undef TOOLBAR_ITEM