Binding extra arguments

If you use one signal handler to catch the same signal from several widgets, you might like that signal handler to receive some extra information. For instance, you might want to know which button was clicked. You can do this with sigc::bind(). Here's some code from the helloworld2 example.

m_button1.signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &HelloWorld::on_button_clicked), "button 1"));

This says that we want the signal to send an extra Glib::ustring argument to the signal handler, and that the value of that argument should be "button 1". Of course we will need to add that extra argument to the declaration of our signal handler:

void on_button_clicked(const Glib::ustring& data);

Of course, a normal "clicked" signal handler would have no arguments.

sigc::bind() is not commonly used, but you might find it helpful sometimes. If you are familiar with GTK programming then you have probably noticed that this is similar to the extra gpointer data arguments which all GTK callbacks have. This is generally overused in GTK to pass information that should be stored as member data in a derived widget, but widget derivation is very difficult in C. We have far less need of this hack in gtkmm.