Xfce Foundation Classes
Main Page  | IndexNamespace List  |  Alphabetical List  |  Class List  |  File List


Public Member Functions | Static Protected Attributes
Xfc::Gtk::SpinButton Class Reference

A GtkSpinButton C++ wrapper class. More...

#include <xfc/gtk/spinbutton.hh>

Inheritance diagram for Xfc::Gtk::SpinButton:
Xfc::Gtk::Entry Xfc::Gtk::Widget Xfc::Gtk::Editable Xfc::Gtk::CellEditable Xfc::Gtk::Object Xfc::Atk::Implementor Xfc::G::TypeInterface Xfc::G::TypeInterface Xfc::G::Object Xfc::G::TypeInterface Xfc::G::TypeInstance Xfc::G::TypeInstance Xfc::G::TypeInstance Xfc::G::TypeInstance Xfc::Trackable Xfc::Trackable Xfc::Trackable Xfc::Trackable

List of all members.

Public Member Functions

Static Protected Attributes

Constructors


Detailed Description

A GtkSpinButton C++ wrapper class.

A SpinButton is an ideal way to allow the user to set the value of some attribute. Rather than having to directly type a number into a Entry, SpinButton allows the user to click on one of two arrows to increment or decrement the displayed value. A value can still be typed in, with the bonus that it can be checked to ensure it is in a given range. The main properties of a SpinButton are through an Adjustment. See the Adjustment section for more details about an adjustment's properties.

Example 1: Using a SpinButton to get an integer.

 #include <xfc/main.hh>
 #include <xfc/gtk/window.hh>
 #include <xfc/gtk/adjustment.hh>
 #include <xfc/gtk/spinbutton.hh>

 using namespace Xfc;

 class Window : public Gtk::Window
 {
        Gtk::SpinButton *spinner;
 public:
        Window();
        int grab_value() const;
 };

 Window::Window()
 {
        set_border_width(5);
        Gtk::Adjustment *spinner_adj = new Gtk::Adjustment(50.0, 0.0, 100.0, 1.0, 5.0, 5.0);

        // Creates the spinner, with no decimal places.
        spinner = new Gtk::SpinButton(spinner_adj, 1.0, 0);
        add(*spinner);
        show_all();
 }

 int
 Window::grab_value() const
 {
        return spinner->get_value_as_int();
 }

 int main (int argc, char *argv[])
 {
        using namespace Main;

        init(&argc, &argv);

        Window window;
        window.signal_destroy().connect(slot(&Xfc::Main::quit));

        run();
        return 0;
 }

Example 2: Using a SpinButton to get a floating point value.

 #include <xfc/main.hh>
 #include <xfc/gtk/window.hh>
 #include <xfc/gtk/adjustment.hh>
 #include <xfc/gtk/spinbutton.hh>

 using namespace Xfc;

 class Window : public Gtk::Window
 {
        Gtk::SpinButton *spinner;
 public:
        Window();
        double grab_value() const;
 };

 Window::Window()
 {
        set_border_width(5);
        Gtk::Adjustment *spinner_adj = new Gtk::Adjustment(2.500, 0.0, 5.0, 0.001, 0.1, 0.1);

        // Creates the spinner, with no decimal places.
        spinner = new Gtk::SpinButton(spinner_adj, 0.001, 3);
        add(*spinner);
        show_all();
 }

 double
 Window::grab_value() const
 {
        return spinner->get_value();
 }

 int main (int argc, char *argv[])
 {
        using namespace Main;

        init(&argc, &argv);

        Window window;
        window.signal_destroy().connect(slot(&Xfc::Main::quit));

        run();
        return 0;
 }

See also: the SpinButton HOWTO and example.


Constructor & Destructor Documentation

Xfc::Gtk::SpinButton::SpinButton ( GtkSpinButton *  spin_button,
bool  owns_reference = false 
) [explicit, protected]

Construct a new SpinButton from an existing GtkSpinButton.

Parameters:
spin_buttonA pointer to a GtkSpinButton.
owns_referenceSet false if the initial reference count is floating, set true if it's not.

The spin_button can be a newly created GtkSpinButton or an existing GtkSpinButton (see G::Object::Object).

Xfc::Gtk::SpinButton::SpinButton ( Adjustment adjustment,
double  climb_rate,
unsigned int  digits 
)

Construct a new spin button with the specified Adjustment, climb_rate and digits.

Parameters:
adjustmentThe Adjustment object that this spin button should use.
climb_rateSpecifies how much the spin button changes when an arrow is clicked on.
digitsThe number of decimal places to display.
Xfc::Gtk::SpinButton::SpinButton ( double  min,
double  max,
double  step = 1.0 
)

Construct a new spin button without specifying an Adjustment.

Parameters:
minThe minimum allowable value.
maxThe maximum allowable value.
stepThe increment added or subtracted by spinning the widget.

This is a convenience constructor that allows creation of a numeric SpinButton without manually creating an adjustment. The value is initially set to the minimum value and a page increment of 10 * step is the default. The precision of the spinbutton is equivalent to the precision of step.


Member Function Documentation

void Xfc::Gtk::SpinButton::configure ( Adjustment adjustment,
double  climb_rate,
unsigned int  digits 
)

Changes the properties of an existing spin button.

Parameters:
adjustmentThe new Adjustment object this spin button should use.
climb_rateHow much the spin button changes when an arrow is clicked on.
digitsThe number of decimal places to display in the spin button.

The adjustment, climb rate, and number of decimal places are all changed accordingly, after this function call.

unsigned int Xfc::Gtk::SpinButton::get_digits ( ) const

Fetches the precision of the spin button (see set_digits()).

Returns:
The current precision.
void Xfc::Gtk::SpinButton::get_increments ( double *  step,
double *  page 
) const

Gets the current step and page the increments used by the spin button (see set_increments()).

Parameters:
stepThe location to store step increment, or null.
pageThe location to store page increment, or null.

Returns whether non-numeric text can be typed into the spin button (see set_numeric()).

Returns:
true if only numeric text can be entered.
void Xfc::Gtk::SpinButton::get_range ( double *  min,
double *  max 
) const

Gets the range allowed for the spin button (see set_range()).

Parameters:
minThe location to store minimum allowed value, or null.
maxThe location to store maximum allowed value, or null.

Returns whether the values are corrected to the nearest step (see set_snap_to_ticks()).

Returns:
true if values are snapped to the nearest step.

Gets the update behavior of the spin button (see set_update_policy()).

Returns:
The current update policy.

Get the value of the spin button represented as an integer.

Returns:
The value of the spin button.

Returns whether the spin button's value wraps around to the opposite limit when the upper or lower limit of the range is exceeded (see set_wrap()).

Returns:
true if the spin button wraps around.

Replaces the Adjustment associated with the spin button.

Parameters:
adjustmentAn Adjustment to replace the existing adjustment.
void Xfc::Gtk::SpinButton::set_digits ( unsigned int  digits)

Set the precision to be displayed by the spin button.

Parameters:
digitsThe number of digits to be displayed for the spin button's value.

Up to 20 digit precision is allowed.

void Xfc::Gtk::SpinButton::set_increments ( double  step,
double  page 
)

Sets the step and page increments for the spin button.

Parameters:
stepThe increment applied for a button 1 press.
pageThe increment applied for a button 2 press.

This affects how quickly the value changes when the spin button's arrows are activated.

void Xfc::Gtk::SpinButton::set_numeric ( bool  numeric)

Sets the flag that determines if non-numeric text can be typed into the spin button.

Parameters:
numerictrue if only numeric entry is allowed.
void Xfc::Gtk::SpinButton::set_range ( double  min,
double  max 
)

Sets the minimum and maximum allowable values for the spin button.

Parameters:
minThe minimum allowable value.
maxThe maximum allowable value.
void Xfc::Gtk::SpinButton::set_snap_to_ticks ( bool  snap_to_ticks)

Sets the policy as to whether values are corrected to the nearest step increment when a spin button is activated after providing an invalid value.

Parameters:
snap_to_ticksA flag indicating if invalid values should be corrected.

Sets the update behavior of the spin button.

Parameters:
policyA SpinButtonUpdatePolicy value.

This determines whether the spin button is always updated or only when a valid value is set.

void Xfc::Gtk::SpinButton::set_value ( double  value)

Set the value of the spin button.

Parameters:
valueThe new value.
void Xfc::Gtk::SpinButton::set_wrap ( bool  wrap)

Sets the flag that determines if a spin button value wraps around to the opposite limit when the upper or lower limit of the range is exceeded.

Parameters:
wraptrue if wrapping behavior is performed.
void Xfc::Gtk::SpinButton::spin ( SpinType  direction,
double  increment 
)

Increment or decrement a spin button's value in a specified direction by a specified amount.

Parameters:
directionA SpinType indicating the direction to spin.
incrementThe step increment to apply in the specified direction.

Member Data Documentation

Input signal (see signal_input()).

Calls a slot with the signature:

< int function(double *new_value);
< // new_value: The new value of the spin button.
< // return: -1 if an error occurs, otherwise 0.
<

Output signal (see signal_output()).

Calls a slot with the signature:

< int function();
<

Value changed signal (see signal_value_changed()).

Calls a slot with the signature:

< void function();
<

The documentation for this class was generated from the following file:
Xfce Foundation Classes
Copyright © 2004-2005 The XFC Development Team XFC