Re: [gtkmm] Problem replacing dynamically a Gtk::MenuElem by another MenuElem
- From: Ian Michell <ian michell hanzi co uk>
- To: cedric <cedric probesys com>
- Cc: gtkmm-list gnome org
- Subject: Re: [gtkmm] Problem replacing dynamically a Gtk::MenuElem by another MenuElem
- Date: Thu, 06 May 2004 15:11:27 +0100
cedric wrote:
Hello!
Here is my new daily problem... ;-)
preleminary: all of what follows in classes (mostly in the "testX"
class, which corresponds to ModuleX.
i handle a Gtk::Menubar that contains a "Modules" tab, in which each
of my plugins put one button: for exemple, the Deals module puts a
menuSelectionButton = new Gtk::Menu_Helpers::MenuElem ("Module
Customers",
Gtk::Menu::AccelKey ("<control>1"),
SigC::slot(*this, &test::module_selected) );
then, when i click on one one the modules button, i want to replace
the cliqued button by this one:
menuSelectedButton = new Gtk::Menu_Helpers::MenuElem("MODULE
CUSTOMERS", m_Menu_Customers_Functionnalities); //sub menu.
Gtk::Menu::MenuList& menulist =
m_Menu_Customers_Functionnalities.items();
menulist.push_back( Gtk::Menu_Helpers::MenuElem("Create a New
Customer",
SigC::slot(&test::add_customer)));
menulist.push_back( Gtk::Menu_Helpers::MenuElem("Delete a Customer",
SigC::slot(&test::del_customer)));
menulist.push_back( Gtk::Menu_Helpers::MenuElem("Cust others",
SigC::slot(&test::on_others)));
so when i click on the button (which is menuSelectionButton at the
beginning), i call a change_menu() method, which is also in the test
class. I manage to replace the button when i have only one module (so
my pointers are correct), but my problem is when i have many modules,
i don t know to find the cliqued one. here are some explanations:
menuButtonModulesDispayed_ptr is a ptr on the Modules.items(), so
menulist is a Gtk::MenuList of Gtk::MenuItemS which are the modules
buttons that i click to select a module. this ptr is accessible to all
modules and is never modified.
each module has his own menuButtonDisplayed ptr, which is a ptr on the
currently displayed button. so at the beginning, it points on
menuSelectionButton, but it points to menuSelectedButton once we ve
cliqued on the button. if later we click on another module's button,
this ptr will point again on menuSelectionButton (not implemented yet
but it won t be a major problem, i think i can success in it alone ;-) )
so in the While ( !end && XXXXX), i would like to replace XXXXX by
something like "*iter != *menuButtonDisplayed", but of course i can
compare neither the pointers nor the pointed objects since iter is a
Gtk::MenuItem* and menuButtonDisplayed is a Gtk::MenuElem*. i ve tried
to compare the "labels" by using Gtk::MenuItem get_submenu() then
Gtk::Menu get_label(), but it provoques seg faults... I don t see how
to compare a MenuElem to a MenuItem or a Menu! i ve read the api docs
and the tutos, but i ve found nothing that could help me :'(
void test::change_menu ()
{
// first we get the list of the Modules buttons
Gtk::Menu::MenuList& menulist =
menuButtonModulesDispayed_ptr->items();
// then, we get the button of this module
Gtk::Menu_Helpers::MenuList::iterator iter= menulist.begin();
while ( (iter != menulist.end()) ) //&& XXXXXXXXXXXXXXXXXXX )
{ iter++; }
//we switch to the other button
if(menuButtonDisplayed == menuSelectionButton)
{ menuButtonDisplayed = menuSelectedButton; }
else if (menuButtonDisplayed == menuSelectedButton)
{ menuButtonDisplayed = menuSelectionButton;}
else { std::cout << "cust: change ptr error" << std::endl; };
[snip]
// to replace the button,
iter = menulist.insert(iter, *menuButtonDisplayed);//we add the new
iter++;
iter = menulist.erase(iter); //then we delete the actual button
}
[snip]
Dude not to be funny or anything, one potential cause of a seg fault
is: the code above, why in gods name, are
you adding an element to the menulist, then removing it straight
afterwards? It seems pointless to me!
thanks to anyone that can help!!!
regards, cedric
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
I think you are trying to overcomplicate things.. coud you possibly be a
little clearer than you are being I found your post a little confusing...
[snip]
I don t see how to compare a MenuElem to a MenuItem or a Menu!
[/snip]
As an example: The first thought in my head was: HUH??????
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]