how to connect Gio::SimpleAction signal



Hi all,
I've been trying to create a dynamic menu in gtkmm3, using the
Gio::MenuModel classes. I can get the Gtk::MenuButton to popup the
Gio::MenuItem, and the Item responds to the click. Unfortunately, I
can't figure out how to connect the Gio::SimpleAction to my signal
handler. The only example I can find is a Gtk+ one, and it uses
different functions.

The problem is thet the prototype for the signal connection is:
 void on_my_activate(const Glib::VariantBase& parameter)

I've tried various combinations, but I can't get the connection to
work. I don't know how to handle the VariantBase.

I'd appreciate a nudge in the right direction.
Thanks,
Marty

Here's my code:

xwin.h:
 
#include <iostream>
#include <gtkmm.h>
#include <giomm/menu.h>
#include <giomm/simpleaction.h>


using std::cout;
using std::endl;

namespace geode
{


    class Gui : public Gtk::Window
    {
    public:
      Gui();
      virtual ~Gui();

      void create_cv_menu ();

    protected:
//    void on_cv_menu_clicked( guint& index);
//            void on_cv_menu_clicked();
//    void on_cv_menu_clicked(guint& index);
      void on_cv_menu_clicked( guint& index)
//        const Glib::Variant<guint32>& parameter)
          { cout << "on_cv_clicked 0:" << endl; }     

      //Child widgets:
      Gtk::Box m_Box;
      Glib::RefPtr<Gio::MenuModel> menumodel;
      Glib::RefPtr<Gio::Menu> giomenu;
      Gtk::MenuButton mbut1;
      Glib::RefPtr<Gio::SimpleAction> ref_action;
    }; // end class Gui
    
} // end namespace geode
#endif //GTKMM_EXAMPLEWINDOW_H

xwin.cpp:

#include "xwin.h"
#include <iostream>

namespace geode
{
    
//CCCCCC GUI CCCCCCCCCCCCCCCC
    Gui::Gui()
        : m_Box(Gtk::ORIENTATION_VERTICAL),
          mbut1()
    {
        set_title("menu test");
        set_default_size(200, 200);
        mbut1.set_label("button 1");
        add(m_Box);
        create_cv_menu();
        m_Box.pack_start(mbut1, Gtk::PACK_SHRINK, 5);
        mbut1.set_menu_model(menumodel);
        show_all_children();
    }

    Gui::~Gui()
    {
    }

    //FFFFFF GUI FFFFFFFFFFFFFFFF
    void Gui::create_cv_menu()
    {
        cout << "Gui create_cv_menu 0:" << endl;
        guint32 index = 1;
        giomenu = Gio::Menu::create();
        menumodel = giomenu;
        giomenu->append("FRONT");
        ref_action = Gio::SimpleAction::create("FRONT");
        ref_action->signal_activate().connect(
            sigc::bind<guint32>(
        sigc::mem_fun(*this, &Gui::on_cv_menu_clicked), index));

// this is Gio::SimpleAction signal_activate handler prototype
//    void on_my_activate(const Glib::VariantBase& parameter)

        cout << "Gui create_cv_menu 99:" << endl;
    }
/*
//FFFFFF GUI FFFFFFFFFFFFFFFF
    void Gui::on_cv_menu_clicked(const Glib::Variant<guint32>& index)
    {
        cout << "Gui on_cv_menu_clicked 0: index = " << index << endl;

//      return true;
    }
*/
} // end namespace geode



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]