gtk context menu cleanups

svn path=/trunk/netsurf/; revision=11480
This commit is contained in:
Vincent Sanders 2011-01-25 09:19:47 +00:00
parent e21cab6a7f
commit 7ff51a93d5
3 changed files with 91 additions and 56 deletions

View File

@ -262,8 +262,7 @@ static struct nsgtk_debugging_submenu *nsgtk_menu_debugging_submenu(
* \param group The gtk 'global' accelerator reference * \param group The gtk 'global' accelerator reference
* \param parent The parent menu to attach to or NULL * \param parent The parent menu to attach to or NULL
*/ */
static struct nsgtk_file_menu *nsgtk_menu_file_menu(GtkAccelGroup *group, static struct nsgtk_file_menu *nsgtk_menu_file_menu(GtkAccelGroup *group)
GtkMenuShell *parent)
{ {
struct nsgtk_file_menu *fmenu; struct nsgtk_file_menu *fmenu;
@ -294,8 +293,6 @@ static struct nsgtk_file_menu *nsgtk_menu_file_menu(GtkAccelGroup *group,
IMAGE_ITEM(file, quit, gtkQuitMenu, fmenu, group); IMAGE_ITEM(file, quit, gtkQuitMenu, fmenu, group);
SET_SUBMENU(export, fmenu); SET_SUBMENU(export, fmenu);
ATTACH_PARENT(parent, gtkFile, fmenu->file, group);
return fmenu; return fmenu;
} }
@ -304,8 +301,7 @@ static struct nsgtk_file_menu *nsgtk_menu_file_menu(GtkAccelGroup *group,
* \param group the 'global' in a gtk sense accelerator reference * \param group the 'global' in a gtk sense accelerator reference
*/ */
static struct nsgtk_edit_menu *nsgtk_menu_edit_menu(GtkAccelGroup *group, static struct nsgtk_edit_menu *nsgtk_menu_edit_menu(GtkAccelGroup *group)
GtkMenuShell *parent)
{ {
struct nsgtk_edit_menu *ret = malloc(sizeof(struct nsgtk_edit_menu)); struct nsgtk_edit_menu *ret = malloc(sizeof(struct nsgtk_edit_menu));
if (ret == NULL) { if (ret == NULL) {
@ -329,8 +325,6 @@ static struct nsgtk_edit_menu *nsgtk_menu_edit_menu(GtkAccelGroup *group,
ADD_SEP(edit, ret); ADD_SEP(edit, ret);
IMAGE_ITEM(edit, preferences, gtkPreferences, ret, group); IMAGE_ITEM(edit, preferences, gtkPreferences, ret, group);
ATTACH_PARENT(parent, gtkEdit, ret->edit, group);
return ret; return ret;
} }
@ -339,8 +333,7 @@ static struct nsgtk_edit_menu *nsgtk_menu_edit_menu(GtkAccelGroup *group,
* \param group the 'global' in a gtk sense accelerator reference * \param group the 'global' in a gtk sense accelerator reference
*/ */
static struct nsgtk_view_menu *nsgtk_menu_view_menu(GtkAccelGroup *group, static struct nsgtk_view_menu *nsgtk_menu_view_menu(GtkAccelGroup *group)
GtkMenuShell *parent)
{ {
struct nsgtk_view_menu *ret = malloc(sizeof(struct nsgtk_view_menu)); struct nsgtk_view_menu *ret = malloc(sizeof(struct nsgtk_view_menu));
if (ret == NULL) { if (ret == NULL) {
@ -373,7 +366,6 @@ static struct nsgtk_view_menu *nsgtk_menu_view_menu(GtkAccelGroup *group,
SET_SUBMENU(tabs, ret); SET_SUBMENU(tabs, ret);
SET_SUBMENU(debugging, ret); SET_SUBMENU(debugging, ret);
ATTACH_PARENT(parent, gtkView, ret->view, group);
return ret; return ret;
} }
@ -383,8 +375,7 @@ static struct nsgtk_view_menu *nsgtk_menu_view_menu(GtkAccelGroup *group,
* \param group the 'global' in a gtk sense accelerator reference * \param group the 'global' in a gtk sense accelerator reference
*/ */
static struct nsgtk_nav_menu *nsgtk_menu_nav_menu(GtkAccelGroup *group, static struct nsgtk_nav_menu *nsgtk_menu_nav_menu(GtkAccelGroup *group)
GtkMenuShell *parent)
{ {
struct nsgtk_nav_menu *ret = malloc(sizeof(struct nsgtk_nav_menu)); struct nsgtk_nav_menu *ret = malloc(sizeof(struct nsgtk_nav_menu));
if (ret == NULL) { if (ret == NULL) {
@ -412,7 +403,6 @@ static struct nsgtk_nav_menu *nsgtk_menu_nav_menu(GtkAccelGroup *group,
ADD_SEP(nav, ret); ADD_SEP(nav, ret);
IMAGE_ITEM(nav, openlocation, gtkOpenLocation, ret, group); IMAGE_ITEM(nav, openlocation, gtkOpenLocation, ret, group);
ATTACH_PARENT(parent, gtkNavigate, ret->nav, group);
return ret; return ret;
} }
@ -422,8 +412,7 @@ static struct nsgtk_nav_menu *nsgtk_menu_nav_menu(GtkAccelGroup *group,
* \param group the 'global' in a gtk sense accelerator reference * \param group the 'global' in a gtk sense accelerator reference
*/ */
static struct nsgtk_help_menu *nsgtk_menu_help_menu(GtkAccelGroup *group, static struct nsgtk_help_menu *nsgtk_menu_help_menu(GtkAccelGroup *group)
GtkMenuShell *parent)
{ {
struct nsgtk_help_menu *ret = malloc(sizeof(struct nsgtk_help_menu)); struct nsgtk_help_menu *ret = malloc(sizeof(struct nsgtk_help_menu));
if (ret == NULL) { if (ret == NULL) {
@ -442,23 +431,59 @@ static struct nsgtk_help_menu *nsgtk_menu_help_menu(GtkAccelGroup *group,
ADD_SEP(help, ret); ADD_SEP(help, ret);
IMAGE_ITEM(help, about, gtkAbout, ret, group); IMAGE_ITEM(help, about, gtkAbout, ret, group);
ATTACH_PARENT(parent, gtkHelp, ret->help, group);
return ret; return ret;
} }
#define MENUBAR_MENU(p, q, r) \
p->q = nsgtk_menu_##q##_menu(group, GTK_MENU_SHELL(r)); \
p->rclick_##q = nsgtk_menu_##q##_menu(group, NULL)
/**
struct nsgtk_menu *nsgtk_menu_create(GladeXML *xml, GtkWindow *window) * Generate menubar menus.
*
* Generate the main menu structure and attach it to a menubar widget.
*/
struct nsgtk_menu_bar *nsgtk_menu_bar_create(GtkMenuShell *menubar, GtkWindow *window)
{ {
GtkAccelGroup *group; GtkAccelGroup *group;
struct nsgtk_menu *nmenu; struct nsgtk_menu_bar *nmenu;
GtkMenuBar *menubar;
nmenu = malloc(sizeof(struct nsgtk_menu)); nmenu = malloc(sizeof(struct nsgtk_menu_bar));
if (nmenu == NULL) {
warn_user(messages_get("NoMemory"), 0);
return NULL;
}
nmenu->menu_bar = GTK_MENU_BAR(menubar);
group = gtk_accel_group_new();
gtk_window_add_accel_group(window, group);
nmenu->file = nsgtk_menu_file_menu(group);
ATTACH_PARENT(menubar, gtkFile, nmenu->file->file, group);
nmenu->edit = nsgtk_menu_edit_menu(group);
ATTACH_PARENT(menubar, gtkEdit, nmenu->edit->edit, group);
nmenu->view = nsgtk_menu_view_menu(group);
ATTACH_PARENT(menubar, gtkView, nmenu->view->view, group);
nmenu->nav = nsgtk_menu_nav_menu(group);
ATTACH_PARENT(menubar, gtkNavigate, nmenu->nav->nav, group);
nmenu->help = nsgtk_menu_help_menu(group);
ATTACH_PARENT(menubar, gtkHelp, nmenu->help->help, group);
return nmenu;
}
/**
* Generate right click menu menu.
*
*/
struct nsgtk_menu_rclick *nsgtk_menu_rclick_create(GtkWindow *window)
{
GtkAccelGroup *group;
struct nsgtk_menu_rclick *nmenu;
nmenu = malloc(sizeof(struct nsgtk_menu_rclick));
if (nmenu == NULL) { if (nmenu == NULL) {
warn_user(messages_get("NoMemory"), 0); warn_user(messages_get("NoMemory"), 0);
return NULL; return NULL;
@ -466,13 +491,12 @@ struct nsgtk_menu *nsgtk_menu_create(GladeXML *xml, GtkWindow *window)
group = gtk_accel_group_new(); group = gtk_accel_group_new();
gtk_window_add_accel_group(window, group); gtk_window_add_accel_group(window, group);
menubar = GTK_MENU_BAR(glade_xml_get_widget(xml, "menubar"));
MENUBAR_MENU(nmenu, file, menubar); nmenu->file = nsgtk_menu_file_menu(group);
MENUBAR_MENU(nmenu, edit, menubar); nmenu->edit = nsgtk_menu_edit_menu(group);
MENUBAR_MENU(nmenu, view, menubar); nmenu->view = nsgtk_menu_view_menu(group);
MENUBAR_MENU(nmenu, nav, menubar); nmenu->nav = nsgtk_menu_nav_menu(group);
MENUBAR_MENU(nmenu, help, menubar); nmenu->help = nsgtk_menu_help_menu(group);
return nmenu; return nmenu;
} }

View File

@ -133,21 +133,26 @@ struct nsgtk_debugging_submenu {
}; };
struct nsgtk_menu { struct nsgtk_menu_bar {
GtkMenuBar *menu_bar;
struct nsgtk_file_menu *file; struct nsgtk_file_menu *file;
struct nsgtk_file_menu *rclick_file;
struct nsgtk_edit_menu *edit; struct nsgtk_edit_menu *edit;
struct nsgtk_edit_menu *rclick_edit;
struct nsgtk_view_menu *view; struct nsgtk_view_menu *view;
struct nsgtk_view_menu *rclick_view;
struct nsgtk_nav_menu *nav; struct nsgtk_nav_menu *nav;
struct nsgtk_nav_menu *rclick_nav;
struct nsgtk_tabs_menu *tabs; struct nsgtk_tabs_menu *tabs;
struct nsgtk_tabs_menu *rclick_tabs;
struct nsgtk_help_menu *help; struct nsgtk_help_menu *help;
struct nsgtk_help_menu *rclick_help;
}; };
struct nsgtk_menu *nsgtk_menu_create(GladeXML *xml, GtkWindow *window); struct nsgtk_menu_rclick {
struct nsgtk_file_menu *file;
struct nsgtk_edit_menu *edit;
struct nsgtk_view_menu *view;
struct nsgtk_nav_menu *nav;
struct nsgtk_tabs_menu *tabs;
struct nsgtk_help_menu *help;
};
struct nsgtk_menu_bar *nsgtk_menu_bar_create(GtkMenuShell *menubar, GtkWindow *window);
struct nsgtk_menu_rclick *nsgtk_menu_rclick_create(GtkWindow *window);
#endif #endif

View File

@ -91,10 +91,15 @@ struct gtk_scaffolding {
GtkNotebook *notebook; GtkNotebook *notebook;
GtkWidget *url_bar; GtkWidget *url_bar;
GtkEntryCompletion *url_bar_completion; GtkEntryCompletion *url_bar_completion;
struct nsgtk_menu *menus; /* menu hierarchy */
/** menu bar hierarchy */
struct nsgtk_menu_bar *menus;
/** right clcik menu hierarchy */
struct nsgtk_menu_rclick *menu_rclick;
GtkToolbar *tool_bar; GtkToolbar *tool_bar;
struct nsgtk_button_connect *buttons[PLACEHOLDER_BUTTON]; struct nsgtk_button_connect *buttons[PLACEHOLDER_BUTTON];
GtkMenuBar *menu_bar;
GtkImage *throbber; GtkImage *throbber;
GtkImage *icoFav; GtkImage *icoFav;
struct gtk_search *search; struct gtk_search *search;
@ -185,7 +190,7 @@ void nsgtk_attach_menu_handlers(struct gtk_scaffolding *g)
#define CONNECT_CHECK(q)\ #define CONNECT_CHECK(q)\
g_signal_connect(g->menus->view->toolbars_submenu->q##_menuitem,\ g_signal_connect(g->menus->view->toolbars_submenu->q##_menuitem,\
"toggled", G_CALLBACK(nsgtk_on_##q##_activate), g);\ "toggled", G_CALLBACK(nsgtk_on_##q##_activate), g);\
g_signal_connect(g->menus->rclick_view->toolbars_submenu->q##_menuitem,\ g_signal_connect(g->menu_rclick->view->toolbars_submenu->q##_menuitem,\
"toggled", G_CALLBACK(nsgtk_on_##q##_activate), g) "toggled", G_CALLBACK(nsgtk_on_##q##_activate), g)
CONNECT_CHECK(menubar); CONNECT_CHECK(menubar);
CONNECT_CHECK(toolbar); CONNECT_CHECK(toolbar);
@ -371,7 +376,7 @@ void nsgtk_window_tabs_num_changed(GtkNotebook *notebook, GtkWidget *page,
{ {
gboolean visible = gtk_notebook_get_show_tabs(g->notebook); gboolean visible = gtk_notebook_get_show_tabs(g->notebook);
g_object_set(g->menus->view->tabs_menuitem, "visible", visible, NULL); g_object_set(g->menus->view->tabs_menuitem, "visible", visible, NULL);
g_object_set(g->menus->rclick_view->tabs_menuitem, "visible", visible, NULL); g_object_set(g->menu_rclick->view->tabs_menuitem, "visible", visible, NULL);
g->buttons[NEXTTAB_BUTTON]->sensitivity = visible; g->buttons[NEXTTAB_BUTTON]->sensitivity = visible;
g->buttons[PREVTAB_BUTTON]->sensitivity = visible; g->buttons[PREVTAB_BUTTON]->sensitivity = visible;
g->buttons[CLOSETAB_BUTTON]->sensitivity = visible; g->buttons[CLOSETAB_BUTTON]->sensitivity = visible;
@ -951,7 +956,7 @@ MENUHANDLER(menubar)
if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) { if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) {
/* need to synchronise menus as gtk grumbles when one menu /* need to synchronise menus as gtk grumbles when one menu
* is attached to both headers */ * is attached to both headers */
w = GTK_WIDGET(g->menus->rclick_view-> w = GTK_WIDGET(g->menu_rclick->view->
toolbars_submenu->menubar_menuitem); toolbars_submenu->menubar_menuitem);
if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)) if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w))
== FALSE) == FALSE)
@ -964,7 +969,7 @@ MENUHANDLER(menubar)
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w),
TRUE); TRUE);
gtk_widget_show(GTK_WIDGET(g->menu_bar)); gtk_widget_show(GTK_WIDGET(g->menus->menu_bar));
gtk_widget_show_all(GTK_WIDGET(g->popup_menu)); gtk_widget_show_all(GTK_WIDGET(g->popup_menu));
@ -975,7 +980,7 @@ MENUHANDLER(menubar)
gtk_widget_hide(GTK_WIDGET(widgets->data)); gtk_widget_hide(GTK_WIDGET(widgets->data));
} else { } else {
w = GTK_WIDGET(g->menus->rclick_view-> w = GTK_WIDGET(g->menu_rclick->view->
toolbars_submenu->menubar_menuitem); toolbars_submenu->menubar_menuitem);
if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w))) if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)))
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w),
@ -985,7 +990,7 @@ MENUHANDLER(menubar)
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w),
FALSE); FALSE);
gtk_widget_hide(GTK_WIDGET(g->menu_bar)); gtk_widget_hide(GTK_WIDGET(g->menus->menu_bar));
GList *widgets = glade_xml_get_widget_prefix(g->popup_xml, GList *widgets = glade_xml_get_widget_prefix(g->popup_xml,
"menupopup"); "menupopup");
@ -1003,7 +1008,7 @@ MENUHANDLER(toolbar)
struct gtk_scaffolding *g = (struct gtk_scaffolding *)data; struct gtk_scaffolding *g = (struct gtk_scaffolding *)data;
if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) { if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) {
w = GTK_WIDGET(g->menus->rclick_view-> w = GTK_WIDGET(g->menu_rclick->view->
toolbars_submenu->toolbar_menuitem); toolbars_submenu->toolbar_menuitem);
if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)) if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w))
== FALSE) == FALSE)
@ -1017,7 +1022,7 @@ MENUHANDLER(toolbar)
TRUE); TRUE);
gtk_widget_show(GTK_WIDGET(g->tool_bar)); gtk_widget_show(GTK_WIDGET(g->tool_bar));
} else { } else {
w = GTK_WIDGET(g->menus->rclick_view-> w = GTK_WIDGET(g->menu_rclick->view->
toolbars_submenu->toolbar_menuitem); toolbars_submenu->toolbar_menuitem);
if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w))) if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(w)))
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w), gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(w),
@ -1456,7 +1461,6 @@ nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
glade_xml_signal_autoconnect(g->xml); glade_xml_signal_autoconnect(g->xml);
g->window = GTK_WINDOW(GET_WIDGET("wndBrowser")); g->window = GTK_WINDOW(GET_WIDGET("wndBrowser"));
g->notebook = GTK_NOTEBOOK(GET_WIDGET("notebook")); g->notebook = GTK_NOTEBOOK(GET_WIDGET("notebook"));
g->menu_bar = GTK_MENU_BAR(GET_WIDGET("menubar"));
g->tool_bar = GTK_TOOLBAR(GET_WIDGET("toolbar")); g->tool_bar = GTK_TOOLBAR(GET_WIDGET("toolbar"));
g->search = malloc(sizeof(struct gtk_search)); g->search = malloc(sizeof(struct gtk_search));
@ -1504,7 +1508,9 @@ nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
nsgtk_toolbar_customization_load(g); nsgtk_toolbar_customization_load(g);
nsgtk_toolbar_set_physical(g); nsgtk_toolbar_set_physical(g);
g->menus = nsgtk_menu_create(g->xml, g->window); g->menus = nsgtk_menu_bar_create(GTK_MENU_SHELL(glade_xml_get_widget(g->xml, "menubar")), g->window);
g->menu_rclick = nsgtk_menu_rclick_create(g->window);
g->preferences_dialog = NULL; g->preferences_dialog = NULL;
@ -1698,7 +1704,7 @@ nsgtk_scaffolding *nsgtk_new_scaffolding(struct gui_window *toplevel)
#define POPUP_ATTACH(q) gtk_menu_item_set_submenu( \ #define POPUP_ATTACH(q) gtk_menu_item_set_submenu( \
GTK_MENU_ITEM(glade_xml_get_widget(g->popup_xml,\ GTK_MENU_ITEM(glade_xml_get_widget(g->popup_xml,\
"menupopup_" #q)), GTK_WIDGET(g->menus->rclick_##q->q##_menu));\ "menupopup_" #q)), GTK_WIDGET(g->menu_rclick->q->q##_menu));\
POPUP_ATTACH(file); POPUP_ATTACH(file);
POPUP_ATTACH(edit); POPUP_ATTACH(edit);
@ -1971,7 +1977,7 @@ struct gtk_search *nsgtk_scaffolding_search(nsgtk_scaffolding *g)
GtkMenuBar *nsgtk_scaffolding_menu_bar(nsgtk_scaffolding *g) GtkMenuBar *nsgtk_scaffolding_menu_bar(nsgtk_scaffolding *g)
{ {
return g->menu_bar; return g->menus->menu_bar;
} }
struct gtk_history_window *nsgtk_scaffolding_history_window(nsgtk_scaffolding struct gtk_history_window *nsgtk_scaffolding_history_window(nsgtk_scaffolding
@ -2367,7 +2373,7 @@ void nsgtk_scaffolding_toolbar_init(struct gtk_scaffolding *g)
g->buttons[p##_BUTTON]->main =\ g->buttons[p##_BUTTON]->main =\
g->menus->q->r##_menuitem;\ g->menus->q->r##_menuitem;\
g->buttons[p##_BUTTON]->rclick =\ g->buttons[p##_BUTTON]->rclick =\
g->menus->rclick_##q->r##_menuitem;\ g->menu_rclick->q->r##_menuitem;\
g->buttons[p##_BUTTON]->mhandler =\ g->buttons[p##_BUTTON]->mhandler =\
nsgtk_on_##r##_activate_menu;\ nsgtk_on_##r##_activate_menu;\
g->buttons[p##_BUTTON]->bhandler =\ g->buttons[p##_BUTTON]->bhandler =\
@ -2380,7 +2386,7 @@ void nsgtk_scaffolding_toolbar_init(struct gtk_scaffolding *g)
g->buttons[p##_BUTTON]->main =\ g->buttons[p##_BUTTON]->main =\
g->menus->q->r##_submenu->s##_menuitem;\ g->menus->q->r##_submenu->s##_menuitem;\
g->buttons[p##_BUTTON]->rclick =\ g->buttons[p##_BUTTON]->rclick =\
g->menus->rclick_##q->r##_submenu->s##_menuitem;\ g->menu_rclick->q->r##_submenu->s##_menuitem;\
g->buttons[p##_BUTTON]->mhandler =\ g->buttons[p##_BUTTON]->mhandler =\
nsgtk_on_##s##_activate_menu;\ nsgtk_on_##s##_activate_menu;\
g->buttons[p##_BUTTON]->bhandler =\ g->buttons[p##_BUTTON]->bhandler =\