1 2 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="highlight.min.css">
<script src="highlight.min.js"></script><script>
hljs.configure({languages: ['cpp']});
hljs.highlightAll();
</script><title>Adjustment Internals</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="Programming with gtkmm 4">
<link rel="up" href="chapter-adjustment.html" title="Chapter 16. Adjustments">
<link rel="prev" href="sec-adjustments-easy.html" title="Using Adjustments the Easy Way">
<link rel="next" href="chapter-dialogs.html" title="Chapter 17. Dialogs">
</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 16. Adjustments</th>
<td width="20%" align="right"> <a accesskey="n" href="chapter-dialogs.html"><img src="icons/next.png" alt="Next"></a>
</td>
</tr>
</table>
<hr>
</div>
<div class="section">
<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"><code class="code">void cb_rotate_picture(MyPicture* picture)
{
picture->set_rotation(adj->get_value());
...</code></pre>
<p>
and connect it to the scale widget's adjustment like this:
</p>
<pre class="programlisting"><code class="code">adj->signal_value_changed().connect(sigc::bind<MyPicture*>(sigc::mem_fun(*this,
&cb_rotate_picture), picture));</code></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"><code class="code">adjustment->signal_changed();</code></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-dialogs.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 17. Dialogs</td>
</tr>
</table>
</div>
</body>
</html>
|