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


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.

Signal Prototypes

Public Member Functions

Accessors
Methods
Signal Proxies

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_button A pointer to a GtkSpinButton.
owns_reference Set 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:
adjustment The Adjustment object that this spin button should use.
climb_rate Specifies how much the spin button changes when an arrow is clicked on.
digits The 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:
min The minimum allowable value.
max The maximum allowable value.
step The 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.

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

Construct a new SpinButton from an existing GtkSpinButton.

Parameters:
spin_button A pointer to a GtkSpinButton.
owns_reference Set 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:
adjustment The Adjustment object that this spin button should use.
climb_rate Specifies how much the spin button changes when an arrow is clicked on.
digits The 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:
min The minimum allowable value.
max The maximum allowable value.
step The 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

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:
step The location to store step increment, or null.
page The location to store page increment, or null.

void Xfc::Gtk::SpinButton::get_range ( double *  min,
double *  max 
) const

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

Parameters:
min The location to store minimum allowed value, or null.
max The location to store maximum allowed value, or null.

int Xfc::Gtk::SpinButton::get_value_as_int (  )  const

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

Returns:
The value of the spin button.

SpinButtonUpdatePolicy Xfc::Gtk::SpinButton::get_update_policy (  )  const

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

Returns:
The current update policy.

bool Xfc::Gtk::SpinButton::get_numeric (  )  const

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

Returns:
true if only numeric text can be entered.

bool Xfc::Gtk::SpinButton::get_wrap (  )  const

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.

bool Xfc::Gtk::SpinButton::get_snap_to_ticks (  )  const

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.

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

Changes the properties of an existing spin button.

Parameters:
adjustment The new Adjustment object this spin button should use.
climb_rate How much the spin button changes when an arrow is clicked on.
digits The 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.

void Xfc::Gtk::SpinButton::set_adjustment ( Adjustment adjustment  ) 

Replaces the Adjustment associated with the spin button.

Parameters:
adjustment An 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:
digits The 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:
step The increment applied for a button 1 press.
page The 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_range ( double  min,
double  max 
)

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

Parameters:
min The minimum allowable value.
max The maximum allowable value.

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

Set the value of the spin button.

Parameters:
value The new value.

void Xfc::Gtk::SpinButton::set_update_policy ( SpinButtonUpdatePolicy  policy  ) 

Sets the update behavior of the spin button.

Parameters:
policy A SpinButtonUpdatePolicy value.
This determines whether the spin button is always updated or only when a valid value is set.

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:
numeric true if only numeric entry is allowed.

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:
direction A SpinType indicating the direction to spin.
increment The step increment to apply in the specified direction.

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:
wrap true if wrapping behavior is performed.

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_ticks A flag indicating if invalid values should be corrected.


Member Data Documentation

const InputSignalType Xfc::Gtk::SpinButton::input_signal [static, protected]

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.
<

const OutputSignalType Xfc::Gtk::SpinButton::output_signal [static, protected]

Output signal (see signal_output()).

Calls a slot with the signature:

< int function();
<

const ValueChangedSignalType Xfc::Gtk::SpinButton::value_changed_signal [static, protected]

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 4.3