tbx  0.7.3
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_ */
std::string title() const
Return the title of the scale dialogue.
Definition: scale.h:178
Window window() const
Return the underlying toolbox window used to implement the Scale object.
Definition: scale.h:148
ObjectId _handle
Handle for toolbox object.
Definition: object.h:173
int step_size() const
Get the step size for the scale.
Definition: scale.cc:121
void value(int pc)
Set the scale percentage.
Definition: scale.h:155
Listener for about to be shown event.
Definition: abouttobeshownlistener.h:76
void check_toolbox_class(int class_id) const
Check if this objects toolbox class is as specified.
Definition: object.cc:122
PollBlock & _data
raw data from the event
Definition: eventinfo.h:53
virtual void scale_apply_factor(const ScaleApplyFactorEvent &apply_event)=0
Method called when scale factors should be applied.
Structure holding the raw data from a call to Wimp_Poll.
Definition: pollinfo.h:71
int string_property_length(int property_id) const
Gets the size of a string properties buffer.
Definition: object.cc:530
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
void remove_has_been_hidden_listener(HasBeenHiddenListener *listener)
Remove has been hidden listener.
Definition: scale.cc:168
void remove_about_to_be_shown_listener(AboutToBeShownListener *listener)
Remove about to be shown listener.
Definition: scale.cc:148
void add_has_been_hidden_listener(HasBeenHiddenListener *listener)
This event is raised after the Scale dialog has been completed.
Definition: scale.cc:158
void remove_apply_factor_listener(ScaleApplyFactorListener *listener)
Remove listener for save button on print dialogue.
Definition: scale.cc:195
Class to provide apply factor event information for Scale object.
Definition: scale.h:197
int upper_bound() const
Get the upper bound for the scale.
Definition: scale.cc:92
bool operator==(const Object &other) const
Check if this Scale refers to the same underlying toolbox object as another.
Definition: scale.h:134
int int_property(int property_id) const
Return the value of a property that returns an integer.
Definition: object.cc:435
std::string string_property(int property_id) const
Return the value of a property that returns text.
Definition: object.cc:477
unsigned int ObjectId
Type for underlying toolbox object id.
Definition: handles.h:31
Scale()
Uninitialised constructor.
Definition: scale.h:69
ObjectId handle() const
Return the underlying toolbox object id this object references.
Definition: object.h:93
ScaleApplyFactorEvent(IdBlock &id_block, PollBlock &data)
Construct the event from Toolbox and WIMP event data.
Definition: scale.h:206
int value() const
Get the scale percentage.
Definition: scale.h:160
Scale & operator=(const Scale &other)
Assign this Scale from another.
Definition: scale.h:114
Listener for scale factor events.
Definition: scale.h:218
Scale(const Object &other)
Construct a Scale from an Object that refers to a Scale.
Definition: scale.h:89
The Window object represents a toolbox window.
Definition: window.h:69
void title(std::string msg)
Set the title for the scale dialogue.
Definition: scale.h:173
Class to provide information on a toolbox event.
Definition: eventinfo.h:48
Base class for all toolbox event listeners.
Definition: listener.h:33
Class to show a toolbox Scale object.
Definition: scale.h:58
int word[64]
Array containing information return from Wimp_Poll.
Definition: pollinfo.h:76
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
int factor() const
Return the choses scale factor.
Definition: scale.h:212
void add_apply_factor_listener(ScaleApplyFactorListener *listener)
Add listener for save button on print dialogue.
Definition: scale.cc:185
Listener for an object has been hidden event.
Definition: hasbeenhiddenlistener.h:36
const IdBlock & id_block() const
IdBlock for the current event.
Definition: eventinfo.h:71
Scale(const Scale &other)
Construct from another Scale object.
Definition: scale.h:78
Objects derived from this class can be shown with there full location and size specified as well as t...
Definition: showfullobject.h:40
Information passed back by the Toolbox with each toolbox event providing information on where the eve...
Definition: pollinfo.h:41
int lower_bound() const
Get the lower bound for the scale.
Definition: scale.cc:63
Class to manipulate a toolbox object.
Definition: object.h:50
Scale & operator=(const Object &other)
Assign this Scale from an Object that refers to a Scale.
Definition: scale.h:126
int title_length() const
Return the title length.
Definition: scale.h:183
Class for Scale object template.
Definition: resscale.h:36
Scale(const std::string &template_name)
Create a Scale from the named template.
Definition: scale.h:97