2015-04-20 17:34:51 -05:00
|
|
|
// 20 april 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
2015-04-20 17:56:42 -05:00
|
|
|
static void appendSeparator(GtkMenuShell *menu)
|
2015-04-20 17:34:51 -05:00
|
|
|
{
|
2015-04-20 17:56:42 -05:00
|
|
|
gtk_menu_shell_append(menu, gtk_separator_menu_item_new());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void appendMenuItem(GtkMenuShell *menu, const uiMenuItem *item)
|
|
|
|
{
|
|
|
|
GtkWidget *iw;
|
|
|
|
|
2015-04-20 22:38:23 -05:00
|
|
|
switch (item->Type) {
|
|
|
|
case uiMenuItemTypeCommand:
|
|
|
|
iw = gtk_menu_item_new_with_label(item->Name);
|
|
|
|
gtk_menu_shell_append(menu, iw);
|
|
|
|
return;
|
|
|
|
case uiMenuItemTypeCheckbox:
|
|
|
|
iw = gtk_check_menu_item_new_with_label(item->Name);
|
|
|
|
gtk_menu_shell_append(menu, iw);
|
|
|
|
return;
|
2015-04-20 17:56:42 -05:00
|
|
|
// TODO see if there are stock items for these three
|
2015-04-20 22:38:23 -05:00
|
|
|
case uiMenuItemTypeQuit:
|
|
|
|
// TODO verify name
|
2015-04-20 17:56:42 -05:00
|
|
|
appendSeparator(menu);
|
|
|
|
iw = gtk_menu_item_new_with_label("Quit");
|
|
|
|
gtk_menu_shell_append(menu, iw);
|
|
|
|
return;
|
2015-04-20 22:38:23 -05:00
|
|
|
case uiMenuItemTypePreferences:
|
|
|
|
// TODO verify name
|
2015-04-20 17:56:42 -05:00
|
|
|
appendSeparator(menu);
|
|
|
|
iw = gtk_menu_item_new_with_label("Preferences");
|
|
|
|
gtk_menu_shell_append(menu, iw);
|
|
|
|
return;
|
2015-04-20 22:38:23 -05:00
|
|
|
case uiMenuItemTypeAbout:
|
|
|
|
// TODO verify name
|
2015-04-20 17:56:42 -05:00
|
|
|
appendSeparator(menu);
|
|
|
|
iw = gtk_menu_item_new_with_label("About");
|
|
|
|
gtk_menu_shell_append(menu, iw);
|
|
|
|
return;
|
2015-04-20 22:38:23 -05:00
|
|
|
case uiMenuItemTypeSeparator:
|
|
|
|
// TODO verify name
|
2015-04-20 17:56:42 -05:00
|
|
|
appendSeparator(menu);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// TODO complain
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *makeMenu(const char *name, uiMenuItem *items)
|
|
|
|
{
|
|
|
|
GtkWidget *menu;
|
|
|
|
GtkWidget *submenu;
|
|
|
|
const uiMenuItem *i;
|
|
|
|
|
|
|
|
menu = gtk_menu_item_new_with_label(name);
|
|
|
|
submenu = gtk_menu_new();
|
2015-04-20 22:38:23 -05:00
|
|
|
for (i = items; i->Type != 0; i++)
|
2015-04-20 17:56:42 -05:00
|
|
|
appendMenuItem(GTK_MENU_SHELL(submenu), i);
|
|
|
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu), submenu);
|
|
|
|
return menu;
|
2015-04-20 17:34:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *makeMenubar(void)
|
|
|
|
{
|
|
|
|
GtkWidget *menubar;
|
|
|
|
const uiMenu *m;
|
|
|
|
|
|
|
|
if (options.Menu == NULL)
|
|
|
|
complain("asked to give uiWindow a menubar but didn't specify a menu in uiInitOptions");
|
|
|
|
|
|
|
|
menubar = gtk_menu_bar_new();
|
|
|
|
|
|
|
|
for (m = options.Menu; m->Name != NULL; m++)
|
2015-04-20 17:56:42 -05:00
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), makeMenu(m->Name, m->Items));
|
2015-04-20 17:34:51 -05:00
|
|
|
|
|
|
|
gtk_widget_set_hexpand(menubar, TRUE);
|
|
|
|
gtk_widget_set_halign(menubar, GTK_ALIGN_FILL);
|
|
|
|
gtk_widget_show_all(menubar);
|
|
|
|
return menubar;
|
|
|
|
}
|