[GTK UI] Fix GTK submenus
This commit is contained in:
parent
06ab8589b4
commit
a86609e93a
|
@ -415,14 +415,20 @@ GTKMenuItem::~GTKMenuItem() {
|
||||||
|
|
||||||
void GTKMenuItem::OnChildAdded(MenuItem* generic_child_item) {
|
void GTKMenuItem::OnChildAdded(MenuItem* generic_child_item) {
|
||||||
auto child_item = static_cast<GTKMenuItem*>(generic_child_item);
|
auto child_item = static_cast<GTKMenuItem*>(generic_child_item);
|
||||||
|
GtkWidget* submenu = nullptr;
|
||||||
switch (child_item->type()) {
|
switch (child_item->type()) {
|
||||||
case MenuItem::Type::kNormal:
|
case MenuItem::Type::kNormal:
|
||||||
// Nothing special.
|
// Nothing special.
|
||||||
break;
|
break;
|
||||||
case MenuItem::Type::kPopup:
|
case MenuItem::Type::kPopup:
|
||||||
if (GTK_IS_MENU_ITEM(menu_)) {
|
if (GTK_IS_MENU_ITEM(menu_)) {
|
||||||
assert(gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu_)) == nullptr);
|
submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(menu_));
|
||||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_), child_item->handle());
|
// 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 {
|
} else {
|
||||||
gtk_menu_shell_append(GTK_MENU_SHELL(menu_), child_item->handle());
|
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:
|
case MenuItem::Type::kString:
|
||||||
assert(GTK_IS_MENU_ITEM(menu_));
|
assert(GTK_IS_MENU_ITEM(menu_));
|
||||||
// Get sub menu and if it doesn't exist create it
|
// 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) {
|
if (submenu == nullptr) {
|
||||||
submenu = gtk_menu_new();
|
submenu = gtk_menu_new();
|
||||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_), submenu);
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_), submenu);
|
||||||
|
|
Loading…
Reference in New Issue