tbx  0.7.3
optionbutton.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  * optionbutton.h
27  *
28  * Created on: 20-Aug-2009
29  * Author: alanb
30  */
31 
32 #ifndef TBX_OPTIONBUTTON_H
33 #define TBX_OPTIONBUTTON_H
34 
35 #include "gadget.h"
36 
37 namespace tbx {
38 
39 class OptionButtonStateListener;
40 
46 class OptionButton : public Gadget
47 {
48 public:
49  enum { TOOLBOX_CLASS = 192 };
50 
52 
58  OptionButton(const OptionButton &other) : Gadget(other) {}
59 
69  OptionButton(const Gadget &other) : Gadget(other) {check_toolbox_class(OptionButton::TOOLBOX_CLASS);}
70 
77  OptionButton(const Component &other) : Gadget(other) {Window check(other.handle()); check_toolbox_class(OptionButton::TOOLBOX_CLASS);}
78 
83  OptionButton &operator=(const OptionButton &other) {_handle = other._handle; _id = other._id; return *this;}
84 
91  OptionButton &operator=(const Gadget &other) {_handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
92 
100  OptionButton &operator=(const Component &other) {Window check(other.handle()); _handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
101 
107  bool operator==(const Gadget &other) const {return (_handle == other.handle() && _id == other.id());}
108 
114  bool operator!=(const Gadget &other) const {return (_handle != other.handle() || _id != other.id());}
115 
121  void label(const std::string &value) {string_property(192, value);}
122 
128  std::string label() const {return string_property(193);}
129 
135  int label_length() const {return string_property_length(193);}
136 
142  void event(int code) {int_property(194, code);}
143 
149  int event() const {return int_property(195);}
150 
156  void on(bool value) {bool_property(196, value);}
157 
163  bool on() const {return bool_property(197); }
164 
167 };
168 
169 }
170 
171 
172 #endif /* TBX_OPTIONBUTTON_H_ */
bool bool_property(int property_id) const
Get a boolean property from the toolbox Component.
Definition: component.cc:214
Listener for changes to the state of an option button.
Definition: optionbuttonstatelistener.h:71
This is the base class for all Gadgets.
Definition: gadget.h:48
OptionButton & operator=(const OptionButton &other)
Assign a option button to refer to the same underlying toolbox gadget as another. ...
Definition: optionbutton.h:83
OptionButton & operator=(const Gadget &other)
Assign a option button to refer to the same underlying toolbox gadget as an existing Gadget...
Definition: optionbutton.h:91
OptionButton(const Gadget &other)
Construct a option button from another gadget.
Definition: optionbutton.h:69
bool operator==(const Gadget &other) const
Check if this option button refers to the same underlying toolbox gadget as another gadget...
Definition: optionbutton.h:107
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 int_property(int property_id) const
Get an integer property from the toolbox Component.
Definition: component.cc:165
int string_property_length(int property_id) const
Get a the length of a string property from the toolbox object.
Definition: component.cc:302
OptionButton(const OptionButton &other)
Construct a option button from another option button.
Definition: optionbutton.h:58
OptionButton wrapper for an underlying toolbox OptionButton gadget.
Definition: optionbutton.h:46
void label(const std::string &value)
Set the the label.
Definition: optionbutton.h:121
bool operator!=(const Gadget &other) const
Check if this option button refers to the same underlying toolbox gadget as another gadget...
Definition: optionbutton.h:114
ComponentId id() const
Get the component ID of this component.
Definition: component.h:103
OptionButton()
Construct an uninitialised option button.
Definition: optionbutton.h:51
Base class for components in an object.
Definition: component.h:42
void add_state_listener(OptionButtonStateListener *listener)
Add listener for option button state changed.
Definition: optionbutton.cc:51
std::string string_property(int property_id) const
Get a string property from the toolbox object.
Definition: component.cc:261
std::string label() const
Get the the label.
Definition: optionbutton.h:128
The Window object represents a toolbox window.
Definition: window.h:69
OptionButton(const Component &other)
Construct a option button from a gadget.
Definition: optionbutton.h:77
void remove_state_listener(OptionButtonStateListener *listener)
Remove listener for option button state changed.
Definition: optionbutton.cc:61
OptionButton & operator=(const Component &other)
Assign a option button to refer to the same underlying toolbox component as an existing Gadget...
Definition: optionbutton.h:100
int label_length() const
Get the length of the label.
Definition: optionbutton.h:135
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
void event(int code)
Set the event to be raised when this option button is clicked.
Definition: optionbutton.h:142
int _id
Underlying toolbox component id.
Definition: component.h:46
int event() const
Get the event that will be raised when this option button is clicked.
Definition: optionbutton.h:149
ObjectId handle() const
Return the object handle for his component.
Definition: component.h:95
bool on() const
Check if option button is on.
Definition: optionbutton.h:163
void on(bool value)
Turn option button on or off.
Definition: optionbutton.h:156