After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 111084 - Deleted menu item's signal handler still called.
Deleted menu item's signal handler still called.
Status: RESOLVED FIXED
Product: gtkmm
Classification: Bindings
Component: general
2.2
Other Windows
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2003-04-18 13:13 UTC by Pierre Mazoyer
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
old_accel.cc simplified test case (970 bytes, text/plain)
2003-05-08 17:47 UTC, Murray Cumming
  Details
old_accel_gtk.c (2.65 KB, patch)
2003-05-11 19:30 UTC, Murray Cumming
none Details | Review

Description Pierre Mazoyer 2003-04-18 13:13:09 UTC
Deleting an item using Gtk::Menu_Helpers::MenuList::insert() or 
Gtk::Menu_Helpers::MenuList::remove() does not completely remove it.
The item is still available through its keyboard shortcut.

Example code:

#include <gtkmm.h>
#include <iostream>

class TestWindow : public Gtk::Window
{
public:
    TestWindow();

private:
    Gtk::VBox windowVBox;
    Gtk::MenuBar menuBar;
    Gtk::Menu menu_Test1;
    Gtk::Menu menu_Test2;
    
    void delete_with_erase_test();
    void delete_with_remove_test();
};

TestWindow::TestWindow()
{
    set_title("MenuList erase() and remove() bug");
    set_resizable(false);
    set_border_width(5);

  	menu_Test1.items().push_back(Gtk::Menu_Helpers::MenuElem("Delete 
this using erase()",  Gtk::Menu::AccelKey("<control>e"), SigC::slot(*this, 
&TestWindow::delete_with_erase_test)));
    menu_Test1.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
    menu_Test1.items().push_back(Gtk::Menu_Helpers::MenuElem("Quit",  
SigC::slot(*this, &Gtk::Widget::hide)));

  	menu_Test2.items().push_back(Gtk::Menu_Helpers::MenuElem("Delete 
this using remove()",  Gtk::Menu::AccelKey("<control>r"), SigC::slot
(*this, &TestWindow::delete_with_remove_test)));
    menu_Test2.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
    menu_Test2.items().push_back(Gtk::Menu_Helpers::MenuElem("Quit",  
SigC::slot(*this, &Gtk::Widget::hide)));

    menuBar.items().push_back(Gtk::Menu_Helpers::MenuElem("Test 1", 
menu_Test1));
    menuBar.items().push_back(Gtk::Menu_Helpers::MenuElem("Test 2", 
menu_Test2));

    windowVBox.pack_start(menuBar);
    add(windowVBox);
    show_all();
}

void TestWindow::delete_with_erase_test()
{
    Gtk::Menu_Helpers::MenuList::iterator i = menu_Test1.items().begin();
    menu_Test1.items().erase(i);
    std::cout << "Test 1 > 'Delete this using erase()' deleted." << 
std::endl;
    std::cout << "Bug: try to press Ctrl+e" << std::endl;
}

void TestWindow::delete_with_remove_test()
{
    menu_Test2.items().remove(menu_Test2.items()[0]);
    std::cout << "Test 2 > 'Delete this using remove()' deleted." << 
std::endl;
    std::cout << "Bug: try to press Ctrl+r" << std::endl;
}

int main(int argc, char* argv[])
{
    Gtk::Main kit(argc, argv);

    TestWindow testWindow;
    
    Gtk::Main::run(testWindow);
    
    return 0;
}
Comment 1 Murray Cumming 2003-04-18 13:26:04 UTC
Please _attach_ test code in future. Please simplify this test case as
much as possible. Please show us one bug, not two.
Comment 2 Murray Cumming 2003-05-08 17:47:45 UTC
Created attachment 16372 [details]
old_accel.cc simplified test case
Comment 3 Murray Cumming 2003-05-08 17:49:35 UTC
You were right - The MenuItem is not really being deleted. It's
probably because something is referencing it but not unreferencing - a
GTK+ bug, I suspect. We've seen and fixed similar bugs before. The
next step is to to the same thing in GTK+ C code, and then, if the
problem is still there, find out exactly what is refing/unrefing it.
Comment 4 Murray Cumming 2003-05-11 19:29:42 UTC
This should be fixed in cvs now:

2003-05-09  Murray Cumming  <murrayc@usa.net>

	* gtk/src/menushell.[hg|ccg] replace GP_LIST_CONTAINER_REMOVE() with
	custom-written remove() and erase() MenuList methods, to ensure that
	we unset the accel widget that we might have set in the MenuItem() 
	constructor. This avoids a memory leak due to the extra reference.

The attached old_accel_gtk.c shows what the problem was.
Comment 5 Murray Cumming 2003-05-11 19:30:21 UTC
Created attachment 16433 [details] [review]
old_accel_gtk.c