| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 
 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Writing signal handlers</title><meta name="generator" content="DocBook XSL Stylesheets V1.64.1"><link rel="home" href="index.html" title="Programming with gtkmm2"><link rel="up" href="apb.html" title="AppendixB.Signals"><link rel="previous" href="apb.html" title="AppendixB.Signals"><link rel="next" href="apbs03.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="apb.html">Prev</a></td><th width="60%" align="center">AppendixB.Signals</th><td width="20%" align="right"><a accesskey="n" href="apbs03.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2520976"></a>Writing signal handlers</h2></div></div><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 gtkmm headers:
</p><p>
</p><pre class="programlisting">
Glib::SignalProxy1<bool, GtkDirectionType> signal_focus() 
</pre><p>
</p><p>
Other than the signal's name (<tt class="literal">focus</tt>), two things are
important to note here: the number following the word <tt class="literal">SignalProxy</tt> at
the beginning (1, in this case), and the types in the list
(<tt class="literal">bool</tt> and <tt class="literal">GtkDirectionType</tt>).  The number indicates how many
arguments the signal handler should have; the first type, <tt class="literal">bool</tt>,
is the type that the signal handler should return; and the next type,
<tt class="literal">GtkDirectionType</tt>, 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
<tt class="literal"><gtkmm/editable.h></tt>):
</p><p>
</p><pre class="programlisting">
Glib::SignalProxy3<void, const Glib::ustring&, int, int*> 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
<tt class="literal">void</tt>, 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& 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="apb.html">Prev</a></td><td width="20%" align="center"><a accesskey="u" href="apb.html">Up</a></td><td width="40%" align="right"><a accesskey="n" href="apbs03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">AppendixB.Signals</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">Disconnecting signal handlers</td></tr></table></div></body></html>
 |