<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Adjustment Internals</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-adjustment.html" title="Chapter 12. Adjustments"> <link rel="prev" href="sec-adjustments-easy.html" title="Using Adjustments the Easy Way"> <link rel="next" href="chapter-widgets-without-xwindows.html" title="Chapter 13. Widgets Without X-Windows"> </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">Adjustment Internals</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="sec-adjustments-easy.html"><img src="icons/prev.png" alt="Prev"></a> </td> <th width="60%" align="center">Chapter 12. Adjustments </th> <td width="20%" align="right"> <a accesskey="n" href="chapter-widgets-without-xwindows.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> </table> <hr> </div> <div class="sect1" title="Adjustment Internals"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="sec-adjustment-internals"></a>Adjustment Internals</h2></div></div></div> <p> OK, you say, that's nice, but what if I want to create my own handlers to respond when the user adjusts a <code class="classname">Range</code> widget or a <code class="classname">SpinButton</code>. To access the value of a <code class="classname">Gtk::Adjustment</code>, you can use the <code class="methodname">get_value()</code> and <code class="methodname">set_value()</code> methods: </p> <p> As mentioned earlier, <code class="classname">Gtk::Adjustment</code> can emit signals. This is, of course, how updates happen automatically when you share an <code class="classname">Adjustment</code> object between a <code class="classname">Scrollbar</code> and another adjustable widget; all adjustable widgets connect signal handlers to their adjustment's <code class="literal">value_changed</code> signal, as can your program. </p> <p> So, for example, if you have a <code class="classname">Scale</code> widget, and you want to change the rotation of a picture whenever its value changes, you would create a signal handler like this: </p> <pre class="programlisting">void cb_rotate_picture (Gtk::Widget *picture) { picture->set_rotation (adj->value); ...</pre> <p> and connect it to the scale widget's adjustment like this: </p> <pre class="programlisting">adj.value_changed.connect(sigc::bind<Widget*>(sigc::mem_fun(*this, &cb_rotate_picture), picture));</pre> <p> What if a widget reconfigures the <em class="parameter"><code>upper</code></em> or <em class="parameter"><code>lower</code></em> fields of its <code class="classname">Adjustment</code>, such as when a user adds more text to a text widget? In this case, it emits the <code class="literal">changed</code> signal. </p> <p> <code class="classname">Range</code> widgets typically connect a handler to this signal, which changes their appearance to reflect the change - for example, the size of the slider in a scrollbar will grow or shrink in inverse proportion to the difference between the <em class="parameter"><code>lower</code></em> and <em class="parameter"><code>upper</code></em> values of its <code class="classname">Adjustment</code>. </p> <p> You probably won't ever need to attach a handler to this signal, unless you're writing a new type of range widget. </p> <pre class="programlisting">adjustment->changed();</pre> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="sec-adjustments-easy.html"><img src="icons/prev.png" alt="Prev"></a> </td> <td width="20%" align="center"><a accesskey="u" href="chapter-adjustment.html"><img src="icons/up.png" alt="Up"></a></td> <td width="40%" align="right"> <a accesskey="n" href="chapter-widgets-without-xwindows.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> <tr> <td width="40%" align="left" valign="top">Using Adjustments the Easy Way </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"> Chapter 13. Widgets Without X-Windows</td> </tr> </table> </div> </body> </html>