tbx  0.7.3
slider.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 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 /*
26  * slider.h
27  *
28  * Created on: 27-Mar-2009
29  * Author: alanb
30  */
31 
32 #ifndef TBX_SLIDER_H_
33 #define TBX_SLIDER_H_
34 
35 #include "gadget.h"
36 #include "valuechangedlistener.h"
37 #include "colour.h"
38 
39 namespace tbx
40 {
41 
42 class SliderValueChangedListener;
43 
48 class Slider: public tbx::Gadget
49 {
50 public:
51  enum {TOOLBOX_CLASS = 576};
52 
53  Slider() {}
54 
59  ~Slider() {}
60 
66  Slider(const Slider &other) : Gadget(other) {}
67 
77  Slider(const Gadget &other) : Gadget(other) {check_toolbox_class(Slider::TOOLBOX_CLASS);}
78 
85  Slider(const Component &other) : Gadget(other) {Window check(other.handle()); check_toolbox_class(Slider::TOOLBOX_CLASS);}
86 
91  Slider &operator=(const Slider &other) {_handle = other._handle; _id = other._id; return *this;}
92 
99  Slider &operator=(const Gadget &other) {_handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
100 
108  Slider &operator=(const Component &other) {Window check(other.handle()); _handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
109 
115  bool operator==(const Gadget &other) const {return (_handle == other.handle() && _id == other.id());}
116 
122  bool operator!=(const Gadget &other) const {return (_handle != other.handle() || _id != other.id());}
123 
128  void value(int value) {int_property(576, value);}
129 
134  int value() const {return int_property(577);}
135 
136  void set_bounds(int lower, int upper, int step_size);
137  void get_bounds(int &lower, int &upper, int &step_size) const;
138  void set_bounds(int lower, int upper);
139  void get_bounds(int &lower, int &upper) const;
140  void lower_bound(int value);
141  int lower_bound() const;
142  void upper_bound(int value);
143  int upper_bound() const;
144  void step_size(int value);
145  int step_size() const;
146 
147  void set_colour(WimpColour bar, WimpColour background);
148  void get_colour(WimpColour &bar, WimpColour &background);
149 
151  WimpColour bar_colour() const;
154 
157 
160 
161 };
162 
168 {
169 public:
177  ValueChangedEvent(id_block, data) {};
178 
186  bool drag_start_or_click() const {return (_data.word[3] & 1)!=0;}
192  bool drag_in_progress() const {return (_data.word[3] & 2)!=0;}
198  bool drag_ended() const {return (_data.word[3] & 4)!=0;}
199 };
200 
205 {
206 public:
208  virtual ~SliderValueChangedListener() {}
209 
215  virtual void slider_value_changed(const SliderValueChangedEvent &event) = 0;
216 };
217 
218 }
219 
220 #endif /* TBX_SLIDER_H_ */
void value(int value)
Set the value of the slider.
Definition: slider.h:128
Slider & operator=(const Slider &other)
Assign a slider to refer to the same underlying toolbox gadget as another.
Definition: slider.h:91
Slider(const Component &other)
Construct a slider from a gadget.
Definition: slider.h:85
bool drag_start_or_click() const
Check if value was changed by a click or start of dragging of the bar.
Definition: slider.h:186
This is the base class for all Gadgets.
Definition: gadget.h:48
bool drag_ended() const
Check if this is the end of a drag.
Definition: slider.h:198
WimpColour background_colour() const
Get the background colour of the slider.
Definition: slider.cc:295
~Slider()
Destroy a slider gadget.
Definition: slider.h:59
void get_bounds(int &lower, int &upper, int &step_size) const
Get all three bounds at once.
Definition: slider.cc:58
PollBlock & _data
raw data from the event
Definition: eventinfo.h:53
bool operator==(const Gadget &other) const
Check if this slider refers to the same underlying toolbox gadget as another gadget.
Definition: slider.h:115
void add_value_changed_listener(SliderValueChangedListener *listener)
Add Listener for changes in the slider.
Definition: slider.cc:332
Structure holding the raw data from a call to Wimp_Poll.
Definition: pollinfo.h:71
bool drag_in_progress() const
Check if the drag is in progress.
Definition: slider.h:192
int upper_bound() const
Get Upper bound of slider.
Definition: slider.cc:148
Listener for changes in the slider value.
Definition: slider.h:204
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
int step_size() const
Get step size of slider.
Definition: slider.cc:178
Event details for a change of an integer value in a gadget.
Definition: valuechangedlistener.h:38
int int_property(int property_id) const
Get an integer property from the toolbox Component.
Definition: component.cc:165
WimpColour bar_colour() const
Get the bar colour of the slider.
Definition: slider.cc:255
Class to represent a standard desktop WIMP colour.
Definition: colour.h:146
Slider & operator=(const Gadget &other)
Assign a slider to refer to the same underlying toolbox gadget as an existing Gadget.
Definition: slider.h:99
Slider(const Slider &other)
Construct a slider from another slider.
Definition: slider.h:66
ComponentId id() const
Get the component ID of this component.
Definition: component.h:103
Base class for components in an object.
Definition: component.h:42
void set_bounds(int lower, int upper, int step_size)
Set all three bounds at once.
Definition: slider.cc:42
virtual void slider_value_changed(const SliderValueChangedEvent &event)=0
Method called when the slider value has changed.
The Window object represents a toolbox window.
Definition: window.h:69
Base class for all toolbox event listeners.
Definition: listener.h:33
void set_colour(WimpColour bar, WimpColour background)
Set colours for the bar and background of the slider.
Definition: slider.cc:196
int word[64]
Array containing information return from Wimp_Poll.
Definition: pollinfo.h:76
int value() const
Get the value of the slider.
Definition: slider.h:134
SliderValueChangedEvent(IdBlock &id_block, PollBlock &data)
Construct the event from Toolbox and WIMP event data.
Definition: slider.h:176
Slider & operator=(const Component &other)
Assign a slider to refer to the same underlying toolbox component as an existing Gadget.
Definition: slider.h:108
Listener for value changed events.
Definition: valuechangedlistener.h:61
int lower_bound() const
Get Lower bound of slider.
Definition: slider.cc:119
void remove_value_changed_listener(SliderValueChangedListener *listener)
Remove Listener for changes in the slider.
Definition: slider.cc:341
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
const IdBlock & id_block() const
IdBlock for the current event.
Definition: eventinfo.h:71
Slider(const Gadget &other)
Construct a slider from another gadget.
Definition: slider.h:77
Information passed back by the Toolbox with each toolbox event providing information on where the eve...
Definition: pollinfo.h:41
void get_colour(WimpColour &bar, WimpColour &background)
Get colours for the bar and background of the slider.
Definition: slider.cc:214
int _id
Underlying toolbox component id.
Definition: component.h:46
bool operator!=(const Gadget &other) const
Check if this slider refers to the same underlying toolbox gadget as another gadget.
Definition: slider.h:122
ObjectId handle() const
Return the object handle for his component.
Definition: component.h:95
A Slider is a gadget that shows bar in a well which may be draggable by the user. ...
Definition: slider.h:48
Information on event generated when the value of the slider has been changed.
Definition: slider.h:167
Slider()
Construct an uninitialised slider.
Definition: slider.h:53