tbx  0.7.6
scale.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  * scale.h
27  *
28  * Created on: 01-Jul-2010
29  * Author: alanb
30  */
31 
32 #ifndef TBX_SCALE_H_
33 #define TBX_SCALE_H_
34 
35 #include "showfullobject.h"
36 #include "listener.h"
37 #include "eventinfo.h"
38 #include "window.h"
39 
40 namespace tbx {
41 
42 // Listeners
43 class AboutToBeShownListener;
44 class HasBeenHiddenListener;
45 class ScaleApplyFactorListener;
46 
47 namespace res
48 {
49  class ResScale;
50 }
51 
58 class Scale : public tbx::ShowFullObject
59 {
60 public:
61  enum { TOOLBOX_CLASS = 0x82c00 };
62 
69  Scale() {};
78  Scale(const Scale &other) : ShowFullObject(other._handle) {}
89  Scale(const Object &other) : ShowFullObject(other) {check_toolbox_class(Scale::TOOLBOX_CLASS);}
97  Scale(const std::string &template_name) : ShowFullObject(template_name) {check_toolbox_class(Scale::TOOLBOX_CLASS);}
104  Scale(const res::ResScale &object_template);
105 
114  Scale &operator=(const Scale &other) {_handle = other.handle(); return *this;}
126  Scale &operator=(const Object &other) {_handle = other.handle(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
134  bool operator==(const Object &other) const {return (_handle == other.handle());}
142  bool operator!=(const Object &other) const {return (_handle != other.handle());}
143 
144  // Properties
148  Window window() const {return Window((ObjectId)int_property(0));}
149 
155  void value(int pc) {int_property(1, pc);}
156 
160  int value() const {return int_property(2);}
161 
162  // Bounds and step
163  void lower_bound(int value);
164  int lower_bound() const;
165  void upper_bound(int value);
166  int upper_bound() const;
167  void step_size(int value);
168  int step_size() const;
169 
173  void title(std::string msg) {string_property(5, msg);}
174 
178  std::string title() const {return string_property(6);}
179 
183  int title_length() const {return string_property_length(6);}
184 
185  // Listeners
192 };
193 
198 {
199 public:
207  EventInfo(id_block, data) {}
208 
212  int factor() const {return _data.word[4];}
213 };
214 
219 {
220 public:
222 
228  virtual void scale_apply_factor(const ScaleApplyFactorEvent &apply_event) = 0;
229 };
230 
231 }
232 
233 #endif /* TBX_SCALE_H_ */
tbx::Scale::Scale
Scale(const Scale &other)
Construct from another Scale object.
Definition: scale.h:78
tbx::Object::int_property
int int_property(int property_id) const
Return the value of a property that returns an integer.
Definition: object.cc:477
tbx::Scale::add_apply_factor_listener
void add_apply_factor_listener(ScaleApplyFactorListener *listener)
Add listener for save button on print dialogue.
Definition: scale.cc:185
tbx::Scale::Scale
Scale()
Uninitialised constructor.
Definition: scale.h:69
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::ScaleApplyFactorEvent::ScaleApplyFactorEvent
ScaleApplyFactorEvent(IdBlock &id_block, PollBlock &data)
Construct the event from Toolbox and WIMP event data.
Definition: scale.h:206
tbx::Scale::window
Window window() const
Return the underlying toolbox window used to implement the Scale object.
Definition: scale.h:148
tbx::Scale::add_about_to_be_shown_listener
void add_about_to_be_shown_listener(AboutToBeShownListener *listener)
This event is raised just before the Scale underlying window is about to be shown.
Definition: scale.cc:138
tbx::Object::handle
ObjectId handle() const
Return the underlying toolbox object id this object references.
Definition: object.h:93
tbx::Scale::operator=
Scale & operator=(const Object &other)
Assign this Scale from an Object that refers to a Scale.
Definition: scale.h:126
tbx::ScaleApplyFactorListener
Listener for scale factor events.
Definition: scale.h:219
tbx::Object::_handle
ObjectId _handle
Handle for toolbox object.
Definition: object.h:175
tbx::EventInfo::id_block
const IdBlock & id_block() const
IdBlock for the current event.
Definition: eventinfo.h:71
tbx::Object::string_property
std::string string_property(int property_id) const
Return the value of a property that returns text.
Definition: object.cc:519
tbx::Window
The Window object represents a toolbox window.
Definition: window.h:70
tbx::Scale::add_has_been_hidden_listener
void add_has_been_hidden_listener(HasBeenHiddenListener *listener)
This event is raised after the Scale dialog has been completed.
Definition: scale.cc:158
tbx::EventInfo::_data
PollBlock & _data
raw data from the event
Definition: eventinfo.h:53
tbx::Scale::operator=
Scale & operator=(const Scale &other)
Assign this Scale from another.
Definition: scale.h:114
tbx::Scale::upper_bound
int upper_bound() const
Get the upper bound for the scale.
Definition: scale.cc:92
tbx::PollBlock
Structure holding the raw data from a call to Wimp_Poll.
Definition: pollinfo.h:72
tbx::Scale::value
int value() const
Get the scale percentage.
Definition: scale.h:160
tbx::ScaleApplyFactorListener::scale_apply_factor
virtual void scale_apply_factor(const ScaleApplyFactorEvent &apply_event)=0
Method called when scale factors should be applied.
tbx::ScaleApplyFactorEvent::factor
int factor() const
Return the choses scale factor.
Definition: scale.h:212
tbx::HasBeenHiddenListener
Listener for an object has been hidden event.
Definition: hasbeenhiddenlistener.h:36
tbx::res::ResScale
Class for Scale object template.
Definition: resscale.h:37
tbx::Object::string_property_length
int string_property_length(int property_id) const
Gets the size of a string properties buffer.
Definition: object.cc:572
tbx::IdBlock
Information passed back by the Toolbox with each toolbox event providing information on where the eve...
Definition: pollinfo.h:42
tbx::Scale::remove_has_been_hidden_listener
void remove_has_been_hidden_listener(HasBeenHiddenListener *listener)
Remove has been hidden listener.
Definition: scale.cc:168
tbx::Scale::Scale
Scale(const std::string &template_name)
Create a Scale from the named template.
Definition: scale.h:97
tbx::Object::check_toolbox_class
void check_toolbox_class(int class_id) const
Check if this objects toolbox class is as specified.
Definition: object.cc:122
tbx::Scale::Scale
Scale(const Object &other)
Construct a Scale from an Object that refers to a Scale.
Definition: scale.h:89
tbx::Scale::lower_bound
int lower_bound() const
Get the lower bound for the scale.
Definition: scale.cc:63
tbx::AboutToBeShownListener
Listener for about to be shown event.
Definition: abouttobeshownlistener.h:77
tbx::Scale::value
void value(int pc)
Set the scale percentage.
Definition: scale.h:155
tbx::Scale::remove_apply_factor_listener
void remove_apply_factor_listener(ScaleApplyFactorListener *listener)
Remove listener for save button on print dialogue.
Definition: scale.cc:195
tbx::Object
Class to manipulate a toolbox object.
Definition: object.h:51
tbx::Listener
Base class for all toolbox event listeners.
Definition: listener.h:34
tbx::Scale::remove_about_to_be_shown_listener
void remove_about_to_be_shown_listener(AboutToBeShownListener *listener)
Remove about to be shown listener.
Definition: scale.cc:148
tbx::Scale::operator==
bool operator==(const Object &other) const
Check if this Scale refers to the same underlying toolbox object as another.
Definition: scale.h:134
tbx::ShowFullObject
Objects derived from this class can be shown with there full location and size specified as well as t...
Definition: showfullobject.h:41
tbx::ObjectId
unsigned int ObjectId
Type for underlying toolbox object id.
Definition: handles.h:31
tbx::Scale
Class to show a toolbox Scale object.
Definition: scale.h:59
tbx::PollBlock::word
int word[64]
Array containing information return from Wimp_Poll.
Definition: pollinfo.h:76
tbx::Scale::title_length
int title_length() const
Return the title length.
Definition: scale.h:183
tbx::Scale::title
std::string title() const
Return the title of the scale dialogue.
Definition: scale.h:178
tbx::Scale::title
void title(std::string msg)
Set the title for the scale dialogue.
Definition: scale.h:173
tbx::ScaleApplyFactorEvent
Class to provide apply factor event information for Scale object.
Definition: scale.h:198
tbx::EventInfo
Class to provide information on a toolbox event.
Definition: eventinfo.h:49
tbx::Scale::step_size
int step_size() const
Get the step size for the scale.
Definition: scale.cc:121
tbx::Scale::operator!=
bool operator!=(const Object &other) const
Check if this Scale does not refers to the same underlying toolbox object as another.
Definition: scale.h:142