Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > e40b0b2b839eccdb3c85993a7b738115 > files > 148

gtkmm-documentation-3.24.0-1.mga7.noarch.rpm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Binding extra arguments</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="index.html" title="Programming with gtkmm 3">
<link rel="up" href="chapter-signals.html" title="Appendix B. Signals">
<link rel="prev" href="sec-overriding-default-signal-handlers.html" title="Overriding default signal handlers">
<link rel="next" href="sec-xeventsignals.html" title="X Event signals">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Binding extra arguments</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="sec-overriding-default-signal-handlers.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<th width="60%" align="center">Appendix B. Signals</th>
<td width="20%" align="right"> <a accesskey="n" href="sec-xeventsignals.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-binding-extra-arguments"></a>Binding extra arguments</h2></div></div></div>
<p>
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
<code class="function">sigc::bind()</code>. Here's some code from the <a class="link" href="sec-multi-item-containers.html#sec-helloworld2" title="An improved Hello World">helloworld2</a> example.
</p>
<pre class="programlisting">
m_button1.signal_clicked().connect( sigc::bind&lt;Glib::ustring&gt;( sigc::mem_fun(*this, &amp;HelloWorld::on_button_clicked), "button 1") );
</pre>
<p>
This says that we want the signal to send an extra
<code class="classname">Glib::ustring</code> 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:
</p>
<pre class="programlisting">
virtual void on_button_clicked(Glib::ustring data);
</pre>
<p>
Of course, a normal "clicked" signal handler would have no arguments.
</p>
<p>
<code class="function">sigc::bind()</code> is not commonly used, but you might find it
helpful sometimes. If you are familiar with <span class="application">GTK+</span>
programming then you have probably noticed that this is similar to the extra
<code class="literal">gpointer data</code> arguments which all GTK+ callbacks have. This
is generally overused in <span class="application">GTK+</span> 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 <span class="application">gtkmm</span>.
</p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="sec-overriding-default-signal-handlers.html"><img src="icons/prev.png" alt="Prev"></a> </td>
<td width="20%" align="center"><a accesskey="u" href="chapter-signals.html"><img src="icons/up.png" alt="Up"></a></td>
<td width="40%" align="right"> <a accesskey="n" href="sec-xeventsignals.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Overriding default signal handlers </td>
<td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td>
<td width="40%" align="right" valign="top"> X Event signals</td>
</tr>
</table>
</div>
</body>
</html>