tbx  0.7.6
fontdbox.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  * fontdbox.h
27  *
28  * Created on: 01-Jul-2010
29  * Author: alanb
30  */
31 
32 #ifndef TBX_FONTDBOX_H_
33 #define TBX_FONTDBOX_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 FontDboxApplyListener;
46 
47 namespace res
48 {
49  class ResFontDbox;
50 }
51 
58 {
59 public:
60  enum { TOOLBOX_CLASS = 0x82a00 };
61 
67  FontDbox() {};
76  FontDbox(const FontDbox &other) : ShowFullObject(other._handle) {}
87  FontDbox(const Object &other) : ShowFullObject(other) {check_toolbox_class(FontDbox::TOOLBOX_CLASS);}
95  FontDbox(const std::string &template_name) : ShowFullObject(template_name) {check_toolbox_class(FontDbox::TOOLBOX_CLASS);}
102  FontDbox(const res::ResFontDbox &object_template);
103 
112  FontDbox &operator=(const FontDbox &other) {_handle = other.handle(); return *this;}
124  FontDbox &operator=(const Object &other) {_handle = other.handle(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
132  bool operator==(const Object &other) const {return (_handle == other.handle());}
140  bool operator!=(const Object &other) const {return (_handle != other.handle());}
141 
142 
143  // Properties
147  Window window() const {return Window((ObjectId)int_property(0));}
148 
154  void font(std::string value) {string_property(1, value);}
155 
159  void no_font() {int_property(1, 0);}
160 
164  std::string font() const {return string_property(2);}
165 
169  int font_length() const {return string_property_length(2);}
170 
174  void height(int size);
175 
179  int height() const;
180 
184  void aspect_ratio(int value);
185 
189  int aspect_ratio() const;
190 
194  void try_string(std::string value) {string_property(5, value);}
195 
199  std::string try_string() const {return string_property(6);}
200 
204  int try_string_length() const {return string_property_length(6);}
205 
209  void title(std::string value) {string_property(7, value);}
210 
214  std::string title() const {return string_property(8);}
215 
219  int title_length() const {return string_property_length(8);}
220 
221 
222  // Listeners
229 };
230 
235 {
236 public:
244  EventInfo(id_block, data) {}
245 
249  int height() const {return _data.word[4];}
250 
254  int aspect_ratio() const {return _data.word[5];}
255 
260  const std::string name() const {return reinterpret_cast<const char *>(&_data.word[6]);}
261 };
262 
267 {
268 public:
269  ~FontDboxApplyListener() {};
270 
276  virtual void fontdbox_apply(const FontDboxApplyEvent &apply_event) = 0;
277 };
278 
279 }
280 
281 #endif /* TBX_FONTDBOX_H_ */
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::FontDbox::aspect_ratio
int aspect_ratio() const
Get aspect ration of font.
Definition: fontdbox.cc:86
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::FontDbox::remove_apply_listener
void remove_apply_listener(FontDboxApplyListener *listener)
Remove listener for when a font is chosen.
Definition: fontdbox.cc:148
tbx::FontDboxApplyListener::fontdbox_apply
virtual void fontdbox_apply(const FontDboxApplyEvent &apply_event)=0
Method called when apply button is clicked on the FontDbox.
tbx::Object::handle
ObjectId handle() const
Return the underlying toolbox object id this object references.
Definition: object.h:93
tbx::FontDbox::title_length
int title_length() const
Get length of title.
Definition: fontdbox.h:219
tbx::FontDboxApplyListener
Listener for FontDbox Apply events.
Definition: fontdbox.h:267
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::FontDbox::try_string
std::string try_string() const
Get string to shown in try box.
Definition: fontdbox.h:199
tbx::FontDbox::operator!=
bool operator!=(const Object &other) const
Check if this FontDbox does not refers to the same underlying toolbox object as another.
Definition: fontdbox.h:140
tbx::EventInfo::_data
PollBlock & _data
raw data from the event
Definition: eventinfo.h:53
tbx::FontDbox::FontDbox
FontDbox(const FontDbox &other)
Construct a FontDbox from another FontDbox.
Definition: fontdbox.h:76
tbx::FontDbox::font
std::string font() const
Return selected font.
Definition: fontdbox.h:164
tbx::FontDbox::remove_about_to_be_shown_listener
void remove_about_to_be_shown_listener(AboutToBeShownListener *listener)
Remove about to be shown listener.
Definition: fontdbox.cc:110
tbx::FontDbox::try_string_length
int try_string_length() const
Get length of string shown in try box.
Definition: fontdbox.h:204
tbx::PollBlock
Structure holding the raw data from a call to Wimp_Poll.
Definition: pollinfo.h:72
tbx::FontDboxApplyEvent::aspect_ratio
int aspect_ratio() const
Aspect ratio selected.
Definition: fontdbox.h:254
tbx::FontDboxApplyEvent
Event information for FontDboxApplyListener.
Definition: fontdbox.h:235
tbx::FontDbox::window
Window window() const
Return the underlying toolbox window used to implement the FontDbox object.
Definition: fontdbox.h:147
tbx::HasBeenHiddenListener
Listener for an object has been hidden event.
Definition: hasbeenhiddenlistener.h:36
tbx::FontDbox::font_length
int font_length() const
Return selected font name length.
Definition: fontdbox.h:169
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::FontDbox::operator=
FontDbox & operator=(const FontDbox &other)
Assign this FontDbox from another.
Definition: fontdbox.h:112
tbx::IdBlock
Information passed back by the Toolbox with each toolbox event providing information on where the eve...
Definition: pollinfo.h:42
tbx::FontDbox::add_apply_listener
void add_apply_listener(FontDboxApplyListener *listener)
Add listener for when a font is chosen.
Definition: fontdbox.cc:140
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::FontDboxApplyEvent::name
const std::string name() const
Name of font selected.
Definition: fontdbox.h:260
tbx::AboutToBeShownListener
Listener for about to be shown event.
Definition: abouttobeshownlistener.h:77
tbx::FontDboxApplyEvent::FontDboxApplyEvent
FontDboxApplyEvent(const IdBlock &id_block, PollBlock &data)
Construct the event from the details return by the toolbox.
Definition: fontdbox.h:243
tbx::FontDbox::title
void title(std::string value)
Set title.
Definition: fontdbox.h:209
tbx::FontDbox::no_font
void no_font()
Set dialog to no font selected.
Definition: fontdbox.h:159
tbx::FontDbox
Class to show a toolbox FontDbox object.
Definition: fontdbox.h:58
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::FontDbox::add_about_to_be_shown_listener
void add_about_to_be_shown_listener(AboutToBeShownListener *listener)
This event is raised just before the FontDbox underlying window is about to be shown.
Definition: fontdbox.cc:102
tbx::FontDbox::height
int height() const
Get height of font.
Definition: fontdbox.cc:60
tbx::FontDbox::title
std::string title() const
Get title.
Definition: fontdbox.h:214
tbx::FontDbox::FontDbox
FontDbox(const Object &other)
Construct a FontDbox from an Object that refers to a FontDbox.
Definition: fontdbox.h:87
tbx::FontDbox::font
void font(std::string value)
Set font to select.
Definition: fontdbox.h:154
tbx::FontDbox::operator=
FontDbox & operator=(const Object &other)
Assign this FontDbox from an Object that refers to a FontDbox.
Definition: fontdbox.h:124
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::FontDbox::FontDbox
FontDbox(const std::string &template_name)
Create a FontDbox from the named template.
Definition: fontdbox.h:95
tbx::FontDbox::add_has_been_hidden_listener
void add_has_been_hidden_listener(HasBeenHiddenListener *listener)
This event is raised after the FontDbox dialog has been completed.
Definition: fontdbox.cc:118
tbx::FontDbox::try_string
void try_string(std::string value)
Set string to show in try box.
Definition: fontdbox.h:194
tbx::PollBlock::word
int word[64]
Array containing information return from Wimp_Poll.
Definition: pollinfo.h:76
tbx::FontDbox::FontDbox
FontDbox()
Construct creates an unassigned FontDbox.
Definition: fontdbox.h:67
tbx::FontDbox::remove_has_been_hidden_listener
void remove_has_been_hidden_listener(HasBeenHiddenListener *listener)
Remove has been hidden listener.
Definition: fontdbox.cc:126
tbx::res::ResFontDbox
Class for FontDbox object template.
Definition: resfontdbox.h:37
tbx::FontDbox::operator==
bool operator==(const Object &other) const
Check if this FontDbox refers to the same underlying toolbox object as another.
Definition: fontdbox.h:132
tbx::FontDboxApplyEvent::height
int height() const
Height selected.
Definition: fontdbox.h:249
tbx::EventInfo
Class to provide information on a toolbox event.
Definition: eventinfo.h:49