tbx  0.7.6
fontmenu.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  * fontmenu.h
27  *
28  * Created on: 01-Jul-2010
29  * Author: alanb
30  */
31 
32 #ifndef TBX_FONTMENU_H_
33 #define TBX_FONTMENU_H_
34 
35 #include "showpointobject.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 FontMenuSelectionListener;
46 
47 namespace res
48 {
49  class ResFontMenu;
50 }
51 
57 {
58 public:
59  enum { TOOLBOX_CLASS = 0x82a40 };
60 
66  FontMenu() {};
75  FontMenu(const FontMenu &other) : ShowPointObject(other._handle) {}
86  FontMenu(const Object &other) : ShowPointObject(other) {check_toolbox_class(FontMenu::TOOLBOX_CLASS);}
94  FontMenu(const std::string &template_name) : ShowPointObject(template_name) {check_toolbox_class(FontMenu::TOOLBOX_CLASS);}
101  FontMenu(const res::ResFontMenu &object_template);
102 
111  FontMenu &operator=(const FontMenu &other) {_handle = other.handle(); return *this;}
123  FontMenu &operator=(const Object &other) {_handle = other.handle(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
131  bool operator==(const Object &other) const {return (_handle == other.handle());}
139  bool operator!=(const Object &other) const {return (_handle != other.handle());}
140 
141 
142  // Properties
148  void font(std::string value) {string_property(0, value);}
149 
153  void no_font() {int_property(0, 0);}
154 
158  std::string font() const {return string_property(1);}
159 
163  int font_length() const {return string_property_length(1);}
164 
165  // Listeners
172 };
173 
174 
179 {
180 public:
188  EventInfo(id_block, data) {}
189 
193  std::string font() const {return reinterpret_cast<const char *>(_data.word[4]);}
194 };
195 
200 {
201 public:
203 
209  virtual void fontmenu_selection(const FontMenuSelectionEvent &font_selected) = 0;
210 };
211 
212 }
213 
214 #endif /* TBX_FONTMENU_H_ */
tbx::FontMenu::font_length
int font_length() const
Return selected font name length.
Definition: fontmenu.h:163
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
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::FontMenu::FontMenu
FontMenu(const FontMenu &other)
Construct a FontMenu from another FontMenu.
Definition: fontmenu.h:75
tbx::Object::handle
ObjectId handle() const
Return the underlying toolbox object id this object references.
Definition: object.h:93
tbx::FontMenu
Class to show a toolbox FontMenu object.
Definition: fontmenu.h:57
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::FontMenu::operator=
FontMenu & operator=(const FontMenu &other)
Assign this FontMenu from another.
Definition: fontmenu.h:111
tbx::EventInfo::_data
PollBlock & _data
raw data from the event
Definition: eventinfo.h:53
tbx::FontMenu::remove_about_to_be_shown_listener
void remove_about_to_be_shown_listener(AboutToBeShownListener *listener)
Remove about to be shown listener.
Definition: fontmenu.cc:53
tbx::ShowPointObject
Object that can be shown at a specific position as well as its default place.
Definition: showpointobject.h:43
tbx::FontMenuSelectionEvent::FontMenuSelectionEvent
FontMenuSelectionEvent(IdBlock &id_block, PollBlock &data)
Constructor from event data returned from the toolbox.
Definition: fontmenu.h:187
tbx::PollBlock
Structure holding the raw data from a call to Wimp_Poll.
Definition: pollinfo.h:72
tbx::FontMenuSelectionEvent
Class to return information on font menu selection event.
Definition: fontmenu.h:179
tbx::FontMenu::FontMenu
FontMenu(const std::string &template_name)
Create a FontMenu from the named template.
Definition: fontmenu.h:94
tbx::FontMenu::font
std::string font() const
Return selected font.
Definition: fontmenu.h:158
tbx::HasBeenHiddenListener
Listener for an object has been hidden event.
Definition: hasbeenhiddenlistener.h:36
tbx::FontMenu::remove_selection_listener
void remove_selection_listener(FontMenuSelectionListener *listener)
Remove listener to be called when a font is selected in the menu.
Definition: fontmenu.cc:91
tbx::FontMenu::add_about_to_be_shown_listener
void add_about_to_be_shown_listener(AboutToBeShownListener *listener)
This event is raised just before the FontMenu underlying window is about to be shown.
Definition: fontmenu.cc:45
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::FontMenuSelectionEvent::font
std::string font() const
Returns id of the font selected or "SystemFont" for the system entry.
Definition: fontmenu.h:193
tbx::FontMenu::operator=
FontMenu & operator=(const Object &other)
Assign this FontMenu from an Object that refers to a FontMenu.
Definition: fontmenu.h:123
tbx::IdBlock
Information passed back by the Toolbox with each toolbox event providing information on where the eve...
Definition: pollinfo.h:42
tbx::FontMenu::FontMenu
FontMenu()
Construct creates an unassigned FontMenu.
Definition: fontmenu.h:66
tbx::FontMenu::operator!=
bool operator!=(const Object &other) const
Check if this FontMenu does not refers to the same underlying toolbox object as another.
Definition: fontmenu.h:139
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::FontMenuSelectionListener::fontmenu_selection
virtual void fontmenu_selection(const FontMenuSelectionEvent &font_selected)=0
Called when a menu option has been selected.
tbx::FontMenu::add_has_been_hidden_listener
void add_has_been_hidden_listener(HasBeenHiddenListener *listener)
This event is raised after the FontMenu dialog has been completed.
Definition: fontmenu.cc:61
tbx::AboutToBeShownListener
Listener for about to be shown event.
Definition: abouttobeshownlistener.h:77
tbx::FontMenu::remove_has_been_hidden_listener
void remove_has_been_hidden_listener(HasBeenHiddenListener *listener)
Remove has been hidden listener.
Definition: fontmenu.cc:69
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::FontMenu::no_font
void no_font()
Set dialog to no font selected.
Definition: fontmenu.h:153
tbx::FontMenu::add_selection_listener
void add_selection_listener(FontMenuSelectionListener *listener)
Add listener to be called when a font is selected in the menu.
Definition: fontmenu.cc:83
tbx::PollBlock::word
int word[64]
Array containing information return from Wimp_Poll.
Definition: pollinfo.h:76
tbx::FontMenu::font
void font(std::string value)
Set font to select.
Definition: fontmenu.h:148
tbx::FontMenuSelectionListener
Listener for font menu selection events.
Definition: fontmenu.h:200
tbx::FontMenu::FontMenu
FontMenu(const Object &other)
Construct a FontMenu from an Object that refers to a FontMenu.
Definition: fontmenu.h:86
tbx::FontMenu::operator==
bool operator==(const Object &other) const
Check if this FontMenu refers to the same underlying toolbox object as another.
Definition: fontmenu.h:131
tbx::EventInfo
Class to provide information on a toolbox event.
Definition: eventinfo.h:49
tbx::res::ResFontMenu
Class for FontMenu object template.
Definition: resfontmenu.h:37