Search code examples
gtkgtkmmlibsigc++

GTK activate_link doesn't work with label uri? gtkmm Gtk::Label and signal_activate_link()?


I have a handler function:

bool test( const Glib::ustring& uri )
{
    MessageBoxA( NULL, "hello", NULL, 0 );
    return true;
}

and I connect

label2.set_markup( "<a href=\"http://www.google.com\">Google</a>" );
sigc::connection conn = label2.signal_activate_link().connect( sigc::ptr_fun( test ) );

I don't understand why that doesn't work. When I click on Google I can see it's using the default URI handler not mine.


Solution

  • I had to make sure my function was called before the default. I'm guessing what happens is the default signal handler returns true and therefore the signal is not propagated?

      /** Connects a signal to a signal handler.
       * For instance, connect( sigc::mem_fun(*this, &TheClass::on_something) );
       *
       * @param slot The signal handler, usually created with sigc::mem_fun(), or sigc::ptr_fun().
       * @param after Whether this signal handler should be called before or after the default signal handler.
       */
      sigc::connection connect(const SlotType& slot, bool after = true)
        { return sigc::connection(connect_(slot, after)); }
    

    Here is the correct code:

    label2.signal_activate_link().connect( sigc::ptr_fun( test ), false );