Adjustment Internals
OK, då säger du att det var väl fint, men om jag vill skapa mina egna hanterare för att svara när användaren justerar en Range-komponent eller en SpinButton då? För att komma åt värdet på en Gtk::Adjustment kan du använda metoderna get_value() och set_value():
As mentioned earlier, Gtk::Adjustment can emit signals. This is, of course, how updates happen automatically when you share an Adjustment object between a Scrollbar and another adjustable widget; all adjustable widgets connect signal handlers to their adjustment's value_changed signal, as can your program.
So, for example, if you have a Scale widget, and you want to change the rotation of a picture whenever its value changes, you would create a signal handler like this:
void cb_rotate_picture(MyPicture* picture)
{
picture->set_rotation(adj->get_value());
...
and connect it to the scale widget's adjustment like this:
adj->signal_value_changed().connect(sigc::bind<MyPicture*>(sigc::mem_fun(*this,
&cb_rotate_picture), picture));
What if a widget reconfigures the upper or lower fields of its Adjustment, such as when a user adds more text to a text widget? In this case, it emits the changed signal.
Range 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 lower and upper values of its Adjustment.
You probably won't ever need to attach a handler to this signal, unless you're writing a new type of range widget.
adjustment->signal_changed();