Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 345aa895e80053137c21f8693106c3a0 > files > 208

gtkmm2.4-documentation-2.17.4-1mdv2010.0.noarch.rpm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Writing signal handlers</title>
<link rel="stylesheet" href="style.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.75.1">
<link rel="home" href="index.html" title="Programming with gtkmm">
<link rel="up" href="chapter-signals.html" title="Appendix B. Signals">
<link rel="prev" href="chapter-signals.html" title="Appendix B. Signals">
<link rel="next" href="sec-disconnecting-signal-handlers.html" title="Disconnecting signal handlers">
</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">Writing signal handlers</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="chapter-signals.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-disconnecting-signal-handlers.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="sect1" title="Writing signal handlers">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="sec-writing-signal-handlers"></a>Writing signal handlers</h2></div></div></div>
<p>
To find out what type of signal handler you can connect to a signal, you can
look it up in the reference documentation or the header file. Here's an example of a signal declaration you
might see in the <span class="application">gtkmm</span> headers:
</p>
<p>
</p>
<pre class="programlisting">
Glib::SignalProxy1&lt;bool, Gtk::DirectionType&gt; signal_focus()
</pre>
<p>
</p>
<p>
Other than the signal's name (<code class="literal">focus</code>), two things are
important to note here: the number following the word
<code class="classname">SignalProxy</code> at the beginning (1, in this case), and the
types in the list (<span class="type">bool</span> and <span class="type">Gtk::DirectionType</span>).  The
number indicates how many arguments the signal handler should have; the first
type, <span class="type">bool</span>, is the type that the signal handler should return; and
the next type, <span class="type">Gtk::DirectionType</span>, is the type of this signal's
first, and only, argument. By looking at the reference documentation, you can
see the names of the arguments too.
</p>
<p>
The same principles apply for signals which have more arguments.  Here's one
with three (taken from <code class="filename">&lt;gtkmm/editable.h&gt;</code>):
</p>
<p>
</p>
<pre class="programlisting">
Glib::SignalProxy3&lt;void, const Glib::ustring&amp;, int, int*&gt; signal_insert_text()

</pre>
<p>
</p>
<p>
It follows the same form.  The number 3 at the end of the type's name indicates
that our signal handler will need three arguments.  The first type in the type
list is <span class="type">void</span>, so that should be our signal handler's return type.
The following three types are the argument types, in order. Our signal
handler's prototype could look like this:
</p>
<p>
</p>
<pre class="programlisting">
void on_insert_text(const Glib::ustring&amp; text, int length, int* position);
</pre>
<p>
</p>
</div>
<div class="navfooter">
<hr>
<table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="chapter-signals.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-disconnecting-signal-handlers.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">Appendix B. Signals </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"> Disconnecting signal handlers</td>
</tr>
</table>
</div>
</body>
</html>