Fix anchored popups with separators in them
authorJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
Tue, 16 Aug 2016 23:38:19 +0000 (01:38 +0200)
committerJulien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
Tue, 16 Aug 2016 23:45:47 +0000 (01:45 +0200)
The code computing the position of the popup menu used to compare the
given string to each MenuItem::get_label() result, but that method
actually replaces the content (child) of the MenuItem if that child is
not already a Gtk::Label. In particular, this breaks menu separators.

Avoid the issue by checking by hand if the only child of the MenuItem is
a Label, and directly compare the label text.

libs/gtkmm2ext/utils.cc

index 4ba85e2f25250ee3bde55bb13653abe3456f31ed..d4e9c57d58f663f9cb3e0a07dc61b029d5ac982f 100644 (file)
@@ -396,7 +396,8 @@ _position_menu_anchored (int& x, int& y, bool& push_in,
 
        MenuList::const_iterator i = items.begin();
        for ( ; i != items.end(); ++i) {
-               if (selected == ((std::string) i->get_label())) {
+               const Label* label_widget = dynamic_cast<const Label*>(i->get_child());
+               if (label_widget && selected == ((std::string) label_widget->get_label())) {
                        break;
                }
                offset += i->size_request().height;