Xfce
Foundation Classes |
|||
« Main Page | Index | |||
Range WidgetsTable of ContentsThe category of range widgets
includes the
ubiquitous scrollbar widget and the less common scale widget. Though
these two types of widgets are generally used for different purposes,
they are quite similar in function and implementation. All range
widgets
share a set of common graphic elements, each of which has its own X
window and receives events. They all contain a "trough" and a "slider"
(what is sometimes called a "thumb wheel" in other GUI environments).
Dragging the slider with the pointer moves it back and forth within the
trough, while clicking in the trough advances the slider towards the
location of the click, either completely, or by a designated amount,
depending on which mouse button is used.
As mentioned in Adjustments, all range widgets are associated with an adjustment object, from which they calculate the length of the slider and its position within the trough. When the user manipulates the slider, the range widget will change the value of the adjustment. Scrollbar WidgetsThese are your standard, run-of-the-mill scrollbars. These should be used only for scrolling some other widget, such as a list, a text box, or a viewport (and it's generally easier to use the scrolled window widget in most cases). For other purposes, you should use scale widgets, as they are friendlier and more feature full.There are separate types for horizontal and vertical scrollbars. There really isn't much to say about these. You create horizontal scrollbars with these constructors: HScrollbar(); VScrollbar(); HScrollbar() and VScrollbar()
create
an anonymous Adjustment with all of its values set to 0.0.
You
can access this adjustment by calling the Gtk::Range's get_adjustment()
method:
Gtk::Adjustment*
get_adjustment() const; That's about it (if you don't believe me, look in the header files!). The 'adjustment' argument is a reference to an existing Adjustment. If you call the first constructor an Adjustment will be created for you. This might actually be useful if you wish to pass the newly-created adjustment to the constructor of some other widget which will configure it for you, such as a TextView widget. Scale WidgetsScale widgets are used to allow the user to visually select and manipulate a value within a specific range. You might want to use a scale widget, for example, to adjust the magnification level on a zoomed preview of a picture, or to control the brightness of a color, or to specify the number of minutes of inactivity before a screensaver takes over the screen.As with scrollbars, there are separate widget types for horizontal and vertical scale widgets. (Most programmers seem to favour horizontal scale widgets.) The following constructors create horizontal scale widgets: HScale(); and the following constructors create vertical scale widgets: VScale(); Scale widgets can display their current value as a number beside the trough. The default behaviour is to show the value, but you can change this with this method: void
set_draw_value(bool draw_value); As you might have guessed, 'draw_value' is either true or false, with predictable consequences for either one. The value displayed by a scale widget is rounded to one decimal point by default, as is the value field in its Adjustment. You can change this with method: void
set_digits(int digits); where 'digits' is the number of decimal
places you want. You can set digits to anything you like, but no more
than 13 decimal places will actually be drawn on screen.
Finally, the value can be drawn in different positions relative to the trough: void
set_value_pos(Gtk::PositionType pos); The 'pos' argument can be one of the following values from the Gtk::PositionType enum:
Common Range MethodsThe Gtk::Range widget class is fairly complicated internally, but, like all the "base class" widgets, most of its complexity is only interesting if you want to hack on it. Also, almost all of the methods and signals it defines are only really used in writing derived widgets. There are, however, a few useful methods that are defined in <xfc/gtk/range.hh> and will work on all range widgets.Setting the Update PolicyThe 'update policy' of a range widget defines at what points during user interaction it will change the value field of its Adjustment and emit the 'value_changed' signal on this Adjustment. The update policies are defined in the Gtk::UpdateType enum in <xfc/gtk/enums.hh>:
void
set_update_policy(Gtk::UpdateType policy); Getting and Setting AdjustmentsGetting and setting the adjustment for a range widget 'on the fly' is done, predictably, with these Gtk::Range methods:Gtk::Adjustment*
get_adjustment() const; which returns a pointer to the adjustment to which range is connected, and: void
set_adjustment(Gtk::Adjustment *adjustment); which does absolutely nothing if you pass it the adjustment that range is already using, regardless of whether you changed any of its fields or not. If you pass it a new Adjustment, it will unreference the old one if it exists (possibly destroying it), connect the appropriate signals to the new one, and call the private function gtk_range_adjustment_changed(), which will (or at least, is supposed to...) recalculate the size and/or position of the slider and redraw if necessary. As mentioned in the section on adjustments, if you wish to reuse the same Adjustment, when you modify its values directly, you should emit the 'changed' signal on it, like this: adjustment->emit_by_name
("changed"); Key and Mouse bindingsAll of the GTK range widgets react to mouse clicks in more or less the same way. Clicking button-1 in the trough will cause its adjustment's page_increment to be added or subtracted from its value, and the slider to be moved accordingly. Clicking mouse button-2 in the trough will jump the slider to the point at which the button was clicked. Clicking button-3 in the trough of a range or any button on a scrollbar's arrows will cause its adjustment's value to change by step_increment at a time.Scrollbars are not focusable, thus have no key bindings. The key bindings for the other range widgets (which are, of course, only active when the widget has focus) are do not differentiate between horizontal and vertical range widgets. All range widgets can be operated with the left, right, up and down arrow keys, as well as with the Page Up and Page Down keys. The arrows move the slider up and down by step_increment, while Page Up and Page Down move it by page_increment. The user can also move the slider all the way to one end or the other of the trough using the keyboard. This is done with the Home and End keys. Range Widget ExampleThis example displays a window with three range widgets all connected to the same adjustment, and a couple of controls for adjusting some of their parameters so you can see how they affect the way these widgets work for the user.The header file for the Range Widgets example is <rangewidgets.hh>: #include
<xfc/main.hh> and the source file is <rangewidgets.cc>: #include "rangewidgets.hh" Compiling Range Widget
If you compiled and installed XFC yourself, you will find the source
code for Range Widget in the
<examples/rangewidgets> source directory along with a Makefile.
If
XFC came pre-installed, or you installed it from an RPM package, you
will
find the source code in the
</usr/share/doc/xfcui-X.X/examples/rangewidgets> subdirectory. In
this case you will have to create the Makefile yourself (replace X.X
with the
version number of the libXFCui library you have installed). |
Copyright © 2004-2005 The XFC Development Team | Top |
XFC
4.4 |