tbx  0.7.6
numberrange.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010-2011 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef TBX_NUMBERRANGE_H_
26 #define TBX_NUMBERRANGE_H_
27 
28 #include "gadget.h"
29 #include "adjuster.h"
30 #include "slider.h"
31 
32 namespace tbx {
33 
34 class ValueChangedListener;
35 
42 class NumberRange: public tbx::Gadget {
43 public:
44  enum {TOOLBOX_CLASS = 832};
45 
47 
53 
59  NumberRange(const NumberRange &other) : Gadget(other) {}
60 
70  NumberRange(const Gadget &other) : Gadget(other) {check_toolbox_class(NumberRange::TOOLBOX_CLASS);}
71 
78  NumberRange(const Component &other) : Gadget(other) {Window check(other.handle()); check_toolbox_class(NumberRange::TOOLBOX_CLASS);}
79 
84  NumberRange &operator=(const NumberRange &other) {_handle = other._handle; _id = other._id; return *this;}
85 
92  NumberRange &operator=(const Gadget &other) {_handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
93 
101  NumberRange &operator=(const Component &other) {Window check(other.handle()); _handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
102 
108  bool operator==(const Gadget &other) const {return (_handle == other.handle() && _id == other.id());}
109 
115  bool operator!=(const Gadget &other) const {return (_handle != other.handle() || _id != other.id());}
116 
122  void value(int value) {int_property(832, value);}
123 
130  int value() const {return int_property(833);}
131 
132  void set_bounds(int lower, int upper, int step_size, int precision);
133  void get_bounds(int &lower, int &upper, int &step_size, int &precision) const;
134  void set_bounds(int lower, int upper, int step_size);
135  void get_bounds(int &lower, int &upper, int &step_size) const;
136  void set_bounds(int lower, int upper);
137  void get_bounds(int &lower, int &upper) const;
138  void lower_bound(int value);
139  int lower_bound() const;
140  void upper_bound(int value);
141  int upper_bound() const;
142  void step_size(int value);
143  int step_size() const;
144  void precision(int value);
145  int precision() const;
146 
147  Gadget numeric_gadget() const;
148  Adjuster left_adjuster() const;
149  Adjuster right_adjuster() const;
150  Slider slider() const;
151 
154 };
155 
156 }
157 
158 #endif /* NUMBERRANGE_H_ */
tbx::NumberRange::precision
int precision() const
Get the precision of the NumberRange.
Definition: numberrange.cc:297
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::Slider
A Slider is a gadget that shows bar in a well which may be draggable by the user.
Definition: slider.h:49
tbx::NumberRange::operator=
NumberRange & operator=(const Gadget &other)
Assign a number range to refer to the same underlying toolbox gadget as an existing Gadget.
Definition: numberrange.h:92
tbx::Component::handle
ObjectId handle() const
Return the object handle for his component.
Definition: component.h:95
tbx::NumberRange::slider
Slider slider() const
Get the slider.
Definition: numberrange.cc:366
tbx::NumberRange
NumberRange wrapper for an underlying toolbox NumberRange gadget.
Definition: numberrange.h:42
tbx::NumberRange::~NumberRange
~NumberRange()
Destroy a number range gadget.
Definition: numberrange.h:52
tbx::Window
The Window object represents a toolbox window.
Definition: window.h:70
tbx::Component::int_property
int int_property(int property_id) const
Get an integer property from the toolbox Component.
Definition: component.cc:165
tbx::Adjuster
An Adjuster is a gadget that shows two arrows facing in opposite directions either vertically or hori...
Definition: adjuster.h:49
tbx::NumberRange::operator==
bool operator==(const Gadget &other) const
Check if this number range refers to the same underlying toolbox gadget as another gadget.
Definition: numberrange.h:108
tbx::NumberRange::get_bounds
void get_bounds(int &lower, int &upper, int &step_size, int &precision) const
Get the bounds, step size and precision.
Definition: numberrange.cc:69
tbx::NumberRange::NumberRange
NumberRange(const Component &other)
Construct a number range from a gadget.
Definition: numberrange.h:78
tbx::Component
Base class for components in an object.
Definition: component.h:42
tbx::Component::_handle
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
tbx::Component::id
ComponentId id() const
Get the component ID of this component.
Definition: component.h:103
tbx::NumberRange::NumberRange
NumberRange(const Gadget &other)
Construct a number range from another gadget.
Definition: numberrange.h:70
tbx::NumberRange::value
void value(int value)
Set the value of the number range.
Definition: numberrange.h:122
tbx::NumberRange::set_bounds
void set_bounds(int lower, int upper, int step_size, int precision)
Set bounds, step size and precision.
Definition: numberrange.cc:46
tbx::NumberRange::right_adjuster
Adjuster right_adjuster() const
Get the right adjuster.
Definition: numberrange.cc:349
tbx::NumberRange::remove_value_changed_listener
void remove_value_changed_listener(ValueChangedListener *listener)
Remove listener for when the value of the number range changes.
Definition: numberrange.cc:403
tbx::NumberRange::left_adjuster
Adjuster left_adjuster() const
Get the left adjuster.
Definition: numberrange.cc:332
tbx::NumberRange::operator=
NumberRange & operator=(const NumberRange &other)
Assign a number range to refer to the same underlying toolbox gadget as another.
Definition: numberrange.h:84
tbx::NumberRange::add_value_changed_listener
void add_value_changed_listener(ValueChangedListener *listener)
Add listener for when the value of the number range changes.
Definition: numberrange.cc:395
tbx::ValueChangedListener
Listener for value changed events.
Definition: valuechangedlistener.h:62
tbx::NumberRange::operator=
NumberRange & operator=(const Component &other)
Assign a number range to refer to the same underlying toolbox component as an existing Gadget.
Definition: numberrange.h:101
tbx::NumberRange::step_size
int step_size() const
Get step size of NumberRange.
Definition: numberrange.cc:256
tbx::NumberRange::NumberRange
NumberRange()
Construct an uninitialised number range.
Definition: numberrange.h:46
tbx::NumberRange::numeric_gadget
Gadget numeric_gadget() const
Get the gadget that displays the value of the NumberRange.
Definition: numberrange.cc:315
tbx::Component::_id
int _id
Underlying toolbox component id.
Definition: component.h:46
tbx::NumberRange::operator!=
bool operator!=(const Gadget &other) const
Check if this number range refers to the same underlying toolbox gadget as another gadget.
Definition: numberrange.h:115
tbx::Gadget
This is the base class for all Gadgets.
Definition: gadget.h:49
tbx::NumberRange::lower_bound
int lower_bound() const
Get Lower bound of NumberRange.
Definition: numberrange.cc:190
tbx::Gadget::check_toolbox_class
void check_toolbox_class(int class_id) const
Check the underlying gadget class for this object has the given class id.
Definition: gadget.cc:47
tbx::NumberRange::value
int value() const
Get the value of the number range.
Definition: numberrange.h:130
tbx::NumberRange::NumberRange
NumberRange(const NumberRange &other)
Construct a number range from another number range.
Definition: numberrange.h:59
tbx::NumberRange::upper_bound
int upper_bound() const
Get Upper bound of NumberRange.
Definition: numberrange.cc:222