[gtkmm] Problem replacing dynamically a Gtk::MenuElem by another MenuElem
- From: cedric <cedric probesys com>
- To: gtkmm-list gnome org
- Subject: [gtkmm] Problem replacing dynamically a Gtk::MenuElem by another MenuElem
- Date: Thu, 06 May 2004 15:59:06 +0200
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; };
// to replace the button,
iter = menulist.insert(iter, *menuButtonDisplayed);//we add the new
iter++;
iter = menulist.erase(iter); //then we delete the actual button
}
thanks to anyone that can help!!!
regards, cedric
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]