[GTK UI] Fix GTK submenus

This commit is contained in:
Prism Tutaj 2019-09-08 03:10:47 -05:00 committed by Rick Gibbed
parent 06ab8589b4
commit a86609e93a
1 changed files with 9 additions and 3 deletions

View File

@ -415,14 +415,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());
}
@ -431,7 +437,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);