tbx  0.7.5
radiobutton.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  * radiobutton.h
27  *
28  * Created on: 6-Jul-2010
29  * Author: alanb
30  */
31 
32 #ifndef TBX_RADIOBUTTON_H_
33 #define TBX_RADIOBUTTON_H_
34 
35 #include "gadget.h"
36 #include "listener.h"
37 #include "eventinfo.h"
38 
39 namespace tbx
40 {
41 
42 class RadioButtonStateChangedListener;
43 
48 class RadioButton: public tbx::Gadget
49 {
50 public:
51  enum {TOOLBOX_CLASS = 384};
52 
54 
60 
66  RadioButton(const RadioButton &other) : Gadget(other) {}
67 
77  RadioButton(const Gadget &other) : Gadget(other) {check_toolbox_class(RadioButton::TOOLBOX_CLASS);}
78 
85  RadioButton(const Component &other) : Gadget(other) {Window check(other.handle()); check_toolbox_class(RadioButton::TOOLBOX_CLASS);}
86 
91  RadioButton &operator=(const RadioButton &other) {_handle = other._handle; _id = other._id; return *this;}
92 
99  RadioButton &operator=(const Gadget &other) {_handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
100 
108  RadioButton &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 
127  void label(std::string value) {string_property(384, value);}
128 
132  std::string label() const {return string_property(385);}
133 
137  int label_length() const {return string_property_length(385);}
138 
142  void event(int id) {int_property(386, id);}
143 
147  int event() const {return int_property(387);}
148 
160  void on(bool turn_on) {bool_property(388, turn_on);}
161 
165  bool on() const {return bool_property(389);}
166 
169 };
170 
176 {
177 public:
185  EventInfo(id_block, data) {}
186 
190  bool adjust() const {return (_data.word[3] & 1) !=0;}
191 
195  bool select() const {return (_data.word[3] & 4) !=0;}
196 
200  bool on() const {return (_data.word[4] !=0);}
201 
205  RadioButton old_on() const {return Component(id_block().self_object().handle(), (ComponentId)_data.word[5]);}
206 };
207 
212 {
213 public:
214  virtual ~RadioButtonStateChangedListener() {}
220  virtual void radiobutton_state_changed(const RadioButtonStateChangedEvent &state_changed_event) = 0;
221 };
222 
223 }
224 
225 #endif /* TBX_RADIOBUTTON_H_ */
bool on() const
return true if state changed to on, otherwise false
Definition: radiobutton.h:200
RadioButton(const Component &other)
Construct a radiobutton from a component.
Definition: radiobutton.h:85
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
int int_property(int property_id) const
Get an integer property from the toolbox Component.
Definition: component.cc:165
bool select() const
return true if state was changed by select
Definition: radiobutton.h:195
This is the base class for all Gadgets.
Definition: gadget.h:48
ObjectId handle() const
Return the object handle for his component.
Definition: component.h:95
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
Structure holding the raw data from a call to Wimp_Poll.
Definition: pollinfo.h:71
int ComponentId
Type for underlying toolbox component id.
Definition: handles.h:33
RadioButton()
Construct an uninitialised radiobutton.
Definition: radiobutton.h:53
RadioButton & operator=(const RadioButton &other)
Assign a radiobutton to refer to the same underlying toolbox gadget as another.
Definition: radiobutton.h:91
RadioButton(const RadioButton &other)
Construct a radiobutton from another radiobutton.
Definition: radiobutton.h:66
void remove_state_changed_listener(RadioButtonStateChangedListener *listener)
Remove listener for when the radio buttons state changes.
Definition: radiobutton.cc:54
RadioButton old_on() const
Return the previous radio button that was on.
Definition: radiobutton.h:205
Listener for RadioButton state changed event.
Definition: radiobutton.h:211
bool operator!=(const Gadget &other) const
Check if this radiobutton refers to the same underlying toolbox gadget as another gadget...
Definition: radiobutton.h:122
std::string string_property(int property_id) const
Get a string property from the toolbox object.
Definition: component.cc:261
bool on() const
Return true if radio button is on.
Definition: radiobutton.h:165
Base class for components in an object.
Definition: component.h:42
A RadioButton is a gadget that is shown with other RadioButtons to allow the choice of one item of a ...
Definition: radiobutton.h:48
std::string label() const
Get the label of the radio button.
Definition: radiobutton.h:132
bool bool_property(int property_id) const
Get a boolean property from the toolbox Component.
Definition: component.cc:214
ComponentId id() const
Get the component ID of this component.
Definition: component.h:103
RadioButton(const Gadget &other)
Construct a radiobutton from another gadget.
Definition: radiobutton.h:77
Event information for RadioStateButton event that is generated when a radio buttons state changes...
Definition: radiobutton.h:175
void label(std::string value)
Set the label for the radio button.
Definition: radiobutton.h:127
bool adjust() const
return true if state was changed by adjust
Definition: radiobutton.h:190
~RadioButton()
Destroy a radiobutton gadget.
Definition: radiobutton.h:59
The Window object represents a toolbox window.
Definition: window.h:69
int label_length() const
Get the length of the label.
Definition: radiobutton.h:137
Class to provide information on a toolbox event.
Definition: eventinfo.h:48
void event(int id)
Set the event that will be raised when the radio buttons state changes.
Definition: radiobutton.h:142
void on(bool turn_on)
Turn radio button on or off.
Definition: radiobutton.h:160
Base class for all toolbox event listeners.
Definition: listener.h:33
void add_state_changed_listener(RadioButtonStateChangedListener *listener)
Add listener for when the radio buttons state changes.
Definition: radiobutton.cc:46
RadioButton & operator=(const Gadget &other)
Assign a radiobutton to refer to the same underlying toolbox gadget as an existing Gadget...
Definition: radiobutton.h:99
Component()
Construct an uninitialised component.
Definition: component.h:55
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
RadioButton & operator=(const Component &other)
Assign a radiobutton to refer to the same underlying toolbox component as an existing Gadget...
Definition: radiobutton.h:108
Information passed back by the Toolbox with each toolbox event providing information on where the eve...
Definition: pollinfo.h:41
int _id
Underlying toolbox component id.
Definition: component.h:46
RadioButtonStateChangedEvent(IdBlock &id_block, PollBlock &data)
Construct the event from Toolbox and WIMP event data.
Definition: radiobutton.h:184
int string_property_length(int property_id) const
Get a the length of a string property from the toolbox object.
Definition: component.cc:302
bool operator==(const Gadget &other) const
Check if this radiobutton refers to the same underlying toolbox gadget as another gadget...
Definition: radiobutton.h:115
int event() const
Get the event that is raised when the radio buttons state changes.
Definition: radiobutton.h:147