Why signal handler in canvas items can't be overriden?



I want to override a signal handler in a canvas item. Also the keyword "override" seams to "find" a function 
to override, because no compile error is raised. But the handler is simply never called.

Example:

class MyRect : public Goocanvas::Rect
{
    public:
        MyRect( double x, double y, double w, double h): 
            Glib::ObjectBase("ii"),
             Goocanvas::Rect( x,y,w,h)
    {
        /*
        property_x()=x;
        property_y()=y;
        property_width()=w;
        property_height()=h;
        */
    }

    public:
        virtual void nonsens() {}

        bool on_button_press_event(const Glib::RefPtr<Item>& target, GdkEventButton* event) override
        {
            cout << "override handler" << endl;
            return false;
        }

        bool Handler( const Glib::RefPtr<Goocanvas::Item>& item, GdkEventButton* ev )
        {
            cout << "via mem_fun" << endl;
            return false;
        }

        bool on_enter_notify_event(const Glib::RefPtr<Item>& target, GdkEventCrossing* event) override
        {
            cout << "override enter notify" << endl;
            return false;
        }
};


int main(int argc, char* argv[])
{
    Gtk::Main app(&argc, &argv);
    Goocanvas::init("example", "0.1", argc, argv);
    Gtk::Window win;
    Goocanvas::Canvas m_canvas;
    m_canvas.set_size_request(640, 480);
    m_canvas.set_bounds(0, 0, 1000, 1000);


    MyRect* ptr;
    Glib::RefPtr<MyRect> m_rect_own(ptr=new MyRect(225, 225, 150, 150));
    m_rect_own->property_line_width() = 1.0;
    m_rect_own->property_stroke_color() = "black";
    m_rect_own->property_fill_color_rgba() = 0x555555ff;     

    Glib::RefPtr<Goocanvas::Item> root = m_canvas.get_root_item();
    root->add_child( m_rect_own);

    
((Glib::RefPtr<Goocanvas::Item>&)m_rect_own)->signal_button_press_event().connect(sigc::ptr_fun(&MyExternalHandler));
    ((Glib::RefPtr<Goocanvas::Item>&)m_rect_own)->signal_button_press_event().connect(sigc::mem_fun(*ptr, 
&MyRect::Handler));

    win.add(m_canvas);

    win.show_all_children();

    Gtk::Main::run(win);

    return 0;
}


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