Fix GTK submenus

This commit is contained in:
Prism Tutaj 2019-09-08 03:10:47 -05:00
parent 2bf929f51e
commit b4fb2d9b3e
1 changed files with 9 additions and 3 deletions

View File

@ -481,14 +481,20 @@ GTKMenuItem::~GTKMenuItem() {
void GTKMenuItem::OnChildAdded(MenuItem* generic_child_item) {
auto child_item = static_cast<GTKMenuItem*>(generic_child_item);
GtkWidget* submenu = nullptr;
switch (child_item->type()) {
case MenuItem::Type::kNormal:
// Nothing special.
break;
case MenuItem::Type::kPopup:
if (GTK_IS_MENU_ITEM(menu_)) {
assert(gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu_)) == nullptr);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_), child_item->handle());
submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu_));
// Get sub menu and if it doesn't exist create it
if(submenu == nullptr) {
submenu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_), submenu);
}
gtk_menu_shell_append(GTK_MENU_SHELL(submenu), child_item->handle());
} else {
gtk_menu_shell_append(GTK_MENU_SHELL(menu_), child_item->handle());
}
@ -497,7 +503,7 @@ void GTKMenuItem::OnChildAdded(MenuItem* generic_child_item) {
case MenuItem::Type::kString:
assert(GTK_IS_MENU_ITEM(menu_));
// Get sub menu and if it doesn't exist create it
GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu_));
submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu_));
if (submenu == nullptr) {
submenu = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_), submenu);