tbx  0.7.5
menu.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 #ifndef TBX_MENU_H_
26 #define TBX_MENU_H_
27 
28 #include "object.h"
29 #include "component.h"
30 
31 namespace tbx {
32 
33 class MenuItem;
34 class ResMenuItem;
35 class AboutToBeShownListener;
36 class HasBeenHiddenListener;
37 class SubMenuListener;
38 class MenuSelectionListener;
39 class Command;
40 
41 namespace res
42 {
43 class ResMenuItem;
44 }
45 
49 class Menu: public tbx::Object {
50 public:
51  enum { TOOLBOX_CLASS = 0x828c0 };
52 
59  Menu() {};
60 
66  Menu(const Menu &other) : Object(other._handle) {}
67 
74  Menu(const Object &other) : Object(other) {check_toolbox_class(Menu::TOOLBOX_CLASS);}
82  Menu(const char *template_name) : Object(template_name) {check_toolbox_class(Menu::TOOLBOX_CLASS);}
83 
89  Menu &operator=(const Menu &other) {_handle = other.handle(); return *this;}
90 
97  Menu &operator=(const Object &other) {_handle = other.handle(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
98 
104  bool operator==(const Object &other) const {return (_handle == other.handle());}
105 
111  bool operator!=(const Object &other) const {return (_handle != other.handle());}
112 
113  MenuItem item(ComponentId id);
114 
118  void help_message(const std::string &msg) {string_property(16,msg);}
122  std::string help_message() const {return string_property(17);}
126  int help_message_length() const {return string_property_length(17);}
127 
128  MenuItem add(const res::ResMenuItem &res_item, MenuItem *after = 0);
129  MenuItem insert(const res::ResMenuItem &res_item, MenuItem *before = 0);
130  void erase(ComponentId id);
131  void erase(MenuItem &item);
132 
136  int height() const {return int_property(22);}
137 
141  int width() const {return int_property(23);}
142 
146  void title(const std::string &title) {string_property(24, title);}
147 
151  std::string title() const {return string_property(25);}
155  int title_length() const {return string_property_length(25);}
156 
157  void add_about_to_be_shown_listener(AboutToBeShownListener *listener);
158  void remove_about_to_be_shown_listener(AboutToBeShownListener *listener);
159 
160  void add_has_been_hidden_listener(HasBeenHiddenListener *listener);
161  void remove_has_been_hidden_listener(HasBeenHiddenListener *listener);
162 
163  void add_submenu_listener(SubMenuListener *listener);
164  void remove_submenu_listener(SubMenuListener *listener);
165 
166  void add_selection_listener(MenuSelectionListener *listener);
167  void remove_selection_listener(MenuSelectionListener *listener);
168 };
169 
173 class MenuItem : public Component
174 {
175  MenuItem(ObjectId handle, ComponentId id) : Component(handle, id) {};
176  friend class Menu;
177 
178 public:
183 
189  MenuItem(const MenuItem &other) : Component(other.handle(), other.id()) {}
190 
196  MenuItem(const Component &other) : Component(other) {Menu check(_handle);}
197 
203  MenuItem &operator=(const MenuItem &other) {_handle = other._handle; _id = other._id; return *this;}
204 
210  MenuItem &operator=(const Component &other) {Menu check(other.handle()); _handle = other.handle(); _id = other.id(); return *this;}
211 
217  bool operator==(const MenuItem &other) {return (_handle == other._handle && _id == other._id);}
218 
224  bool operator!=(const MenuItem &other) {return (_handle != other._handle || _id != other._id);}
225 
229  Menu menu() {return Menu(_handle);}
230 
231  // Properties
232  void tick(bool set);
233  bool ticked() const;
234 
235  void fade(bool set);
236  bool faded() const;
237 
238  void text(const std::string &text);
239  std::string text() const;
240  int text_length() const;
241 
242  void sprite_name(const std::string &name);
243  std::string sprite_name() const;
244  int sprite_name_length() const;
245 
246  void submenu(const Object &object);
247  void clear_submenu();
248  bool has_submenu() const;
249  Object submenu();
250  void submenu_event(int id);
251  int submenu_event() const;
252 
253  void click_show(const Object &object, bool transient = true);
254  void clear_click_show();
255  bool has_click_show() const;
256  Object click_show(bool *transient = 0);
257  void click_event(int id);
258  int click_event() const;
259 
260  void help_message(const std::string &msg);
261  std::string help_message() const;
262  int help_message_length() const;
263 
264  void add_submenu_listener(SubMenuListener *listener);
265  void remove_submenu_listener(SubMenuListener *listener);
266 
267  void add_selection_listener(MenuSelectionListener *listener);
268  void remove_selection_listener(MenuSelectionListener *listener);
269 
270  void add_selection_command(Command *command);
271  void remove_selection_command(Command *command);
272 };
273 
274 }
275 
276 #endif /* TBX_MENU_H_ */
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
const ComponentId NULL_ComponentId
NULL component id.
Definition: handles.h:46
Class representing a toolbox menu.
Definition: menu.h:49
std::string title() const
Get the title of the menu.
Definition: menu.h:151
Listener for about to be shown event.
Definition: abouttobeshownlistener.h:76
Menu & operator=(const Menu &other)
Assign a menu to an existing menu.
Definition: menu.h:89
ObjectId handle() const
Return the object handle for his component.
Definition: component.h:95
int ComponentId
Type for underlying toolbox component id.
Definition: handles.h:33
Base class for commands in tbx.
Definition: command.h:36
Listener for event when mouse moves over the submenu arrow if no other toolbox event has been associa...
Definition: submenulistener.h:69
Classes to use/edit toolbox resources in memory.
MenuItem(const MenuItem &other)
Construct a menu item from an existing menu item.
Definition: menu.h:189
MenuItem()
Construct an uninitialised menu item.
Definition: menu.h:182
Listener for selection of menu items that do not have another event associated with them...
Definition: menuselectionlistener.h:42
void help_message(const std::string &msg)
Set the help message text for the menu.
Definition: menu.h:118
Base class for components in an object.
Definition: component.h:42
int title_length() const
Get the size of the buffer for the title.
Definition: menu.h:155
bool operator==(const Object &other) const
Checks if this menu refers to the same underlying toolbox object as the given object.
Definition: menu.h:104
unsigned int ObjectId
Type for underlying toolbox object id.
Definition: handles.h:31
Class representing a single menu item on a menu.
Definition: menu.h:173
Menu()
Construct an uninitiased menu.
Definition: menu.h:59
ComponentId id() const
Get the component ID of this component.
Definition: component.h:103
bool operator!=(const MenuItem &other)
Check if this menu item refers to the same underlying toolbox menu option.
Definition: menu.h:224
int width() const
Return the width of the work area of the menu in OS units.
Definition: menu.h:141
int height() const
Return the height of the work area of the menu in OS units.
Definition: menu.h:136
std::string help_message() const
Get the help message text.
Definition: menu.h:122
Menu item object.
Definition: resmenu.h:46
MenuItem & operator=(const MenuItem &other)
Assign to another menu item.
Definition: menu.h:203
bool operator!=(const Object &other) const
Checks if this menu refers to the same underlying toolbox object as the given object.
Definition: menu.h:111
MenuItem(const Component &other)
Construct a menu item from a Component.
Definition: menu.h:196
Listener for an object has been hidden event.
Definition: hasbeenhiddenlistener.h:36
Menu & operator=(const Object &other)
Assign a menu to an existing object.
Definition: menu.h:97
bool operator==(const MenuItem &other)
Check if this menu item refers to the same underlying toolbox menu option.
Definition: menu.h:217
int help_message_length() const
Get the length of buffer for the help message text.
Definition: menu.h:126
Menu(const Object &other)
Construct a menu from another toolbox object.
Definition: menu.h:74
void title(const std::string &title)
Set the title of the menu.
Definition: menu.h:146
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
Menu(const Menu &other)
Construct a menu from another menu.
Definition: menu.h:66
MenuItem & operator=(const Component &other)
Assign a menuitem field to refer to the same underlying toolbox component as an existing component...
Definition: menu.h:210
int _id
Underlying toolbox component id.
Definition: component.h:46
Class to manipulate a toolbox object.
Definition: object.h:50
Menu(const char *template_name)
Create the toolbox object with the given name from the Toolbox resources for the application and assi...
Definition: menu.h:82
ObjectId handle() const
Return the underlying toolbox object id this object references.
Definition: object.h:93
Menu menu()
Return the menu this menu item belongs to.
Definition: menu.h:229