tbx  0.7.5
popup.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  * popup.h
27  *
28  * Created on: 6-Jul-2010
29  * Author: alanb
30  */
31 
32 #ifndef TBX_POPUP_H_
33 #define TBX_POPUP_H_
34 
35 #include "gadget.h"
36 #include "listener.h"
37 #include "eventinfo.h"
38 #include "menu.h"
39 
40 namespace tbx
41 {
42 
43 class PopUpAboutToBeShownListener;
44 
49 class PopUp: public tbx::Gadget
50 {
51 public:
52  enum {TOOLBOX_CLASS = 704};
53 
54  PopUp() {}
55 
60  ~PopUp() {}
61 
67  PopUp(const PopUp &other) : Gadget(other) {}
68 
78  PopUp(const Gadget &other) : Gadget(other) {check_toolbox_class(PopUp::TOOLBOX_CLASS);}
79 
86  PopUp(const Component &other) : Gadget(other) {Window check(other.handle()); check_toolbox_class(PopUp::TOOLBOX_CLASS);}
87 
92  PopUp &operator=(const PopUp &other) {_handle = other._handle; _id = other._id; return *this;}
93 
100  PopUp &operator=(const Gadget &other) {_handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
101 
109  PopUp &operator=(const Component &other) {Window check(other.handle()); _handle = other.handle(); _id = other.id(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
110 
116  bool operator==(const Gadget &other) const {return (_handle == other.handle() && _id == other.id());}
117 
123  bool operator!=(const Gadget &other) const {return (_handle != other.handle() || _id != other.id());}
124 
128  void menu(Menu menu) {int_property(704, (int)menu.handle());}
129 
133  Menu menu() const {return Menu((ObjectId)int_property(705));}
134 
137 };
138 
143 {
144 public:
149  EventInfo(id_block, data) {}
150 
154  Menu menu() const {return Menu((ObjectId)_data.word[4]);}
155 };
156 
161 {
162 public:
163  virtual ~PopUpAboutToBeShownListener() {}
169  virtual void popup_about_to_be_shown(const PopUpAboutToBeShownEvent &popup_event) = 0;
170 };
171 
172 }
173 
174 #endif /* TBX_POPUP_H_ */
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
A PopUp is a gadget that shows a menu arrow icon that shows an associated menu when clicked...
Definition: popup.h:49
int int_property(int property_id) const
Get an integer property from the toolbox Component.
Definition: component.cc:165
Class representing a toolbox menu.
Definition: menu.h:49
This is the base class for all Gadgets.
Definition: gadget.h:48
Menu menu() const
Get menu for popup.
Definition: popup.h:133
ObjectId handle() const
Return the object handle for his component.
Definition: component.h:95
void check_toolbox_class(int class_id) const
Check the underlying gadget class for this object has the given class id.
Definition: gadget.cc:47
PopUp & operator=(const PopUp &other)
Assign a popup to refer to the same underlying toolbox gadget as another.
Definition: popup.h:92
Structure holding the raw data from a call to Wimp_Poll.
Definition: pollinfo.h:71
void add_popup_about_to_be_shown_listener(PopUpAboutToBeShownListener *listener)
Add listener for popup menu is about to be shown.
Definition: popup.cc:46
bool operator==(const Gadget &other) const
Check if this popup refers to the same underlying toolbox gadget as another gadget.
Definition: popup.h:116
void remove_popup_about_to_be_shown_listener(PopUpAboutToBeShownListener *listener)
Remove listener for popup menu is about to be shown.
Definition: popup.cc:54
PopUp(const PopUp &other)
Construct a popup from another popup.
Definition: popup.h:67
PopUp & operator=(const Component &other)
Assign a popup to refer to the same underlying toolbox component as an existing Gadget.
Definition: popup.h:109
PopUp(const Gadget &other)
Construct a popup from another gadget.
Definition: popup.h:78
void menu(Menu menu)
Set menu for popup.
Definition: popup.h:128
Base class for components in an object.
Definition: component.h:42
unsigned int ObjectId
Type for underlying toolbox object id.
Definition: handles.h:31
ComponentId id() const
Get the component ID of this component.
Definition: component.h:103
Listener for PopUp AboutToBeShown events.
Definition: popup.h:160
PopUp(const Component &other)
Construct a popup from a component.
Definition: popup.h:86
The Window object represents a toolbox window.
Definition: window.h:69
Class to provide information on a toolbox event.
Definition: eventinfo.h:48
Base class for all toolbox event listeners.
Definition: listener.h:33
bool operator!=(const Gadget &other) const
Check if this popup refers to the same underlying toolbox gadget as another gadget.
Definition: popup.h:123
PopUp()
Construct an uninitialised popup.
Definition: popup.h:54
PopUpAboutToBeShownEvent(IdBlock &id_block, PollBlock &data)
Construct the event from information returned from the Toolbox/WIMP.
Definition: popup.h:148
PopUp & operator=(const Gadget &other)
Assign a popup to refer to the same underlying toolbox gadget as an existing Gadget.
Definition: popup.h:100
ObjectId _handle
Underlying toolbox handle.
Definition: component.h:45
Event information for PopUp AboutToBeShown event.
Definition: popup.h:142
Information passed back by the Toolbox with each toolbox event providing information on where the eve...
Definition: pollinfo.h:41
~PopUp()
Destroy a popup gadget.
Definition: popup.h:60
int _id
Underlying toolbox component id.
Definition: component.h:46
Menu menu() const
Menu that is about to be shown.
Definition: popup.h:154
ObjectId handle() const
Return the underlying toolbox object id this object references.
Definition: object.h:93