tbx  0.7.3
wimpmessagelistener.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 #ifndef TBX_WIMPMESSAGELISTENER_H_
27 #define TBX_WIMPMESSAGELISTENER_H_
28 
29 #include "pollinfo.h"
30 
31 namespace tbx {
32 
37 {
38 public:
48  WimpMessage(PollBlock &poll_block);
49 
56  WimpMessage(int message_id, int size);
57 
67  WimpMessage(const WimpMessage &other, int size_override = 0);
68 
75  WimpMessage(const WimpMessage &other, bool copy);
76 
82  WimpMessage &operator=(const WimpMessage &other);
83 
88  virtual ~WimpMessage();
89 
90  // Common attributes for all messages
94  int block_size() const {return _message_block[0];}
98  int sender_task_handle() const {return _message_block[1];}
102  int my_ref() const {return _message_block[2];}
106  int your_ref() const {return _message_block[3];}
110  int message_id() const {return _message_block[4];}
111 
117  void my_ref(int ref) {_message_block[2] = ref;}
123  void your_ref(int ref) {_message_block[3] = ref;}
129  void message_id(int id) {_message_block[4] = id;}
130 
138  int word(int index) const {return _message_block[index];}
139 
147  int &word(int index) {return _message_block[index];}
148 
156  int operator[] (int index) const {return _message_block[index];}
157 
165  int &operator[] (int index) {return _message_block[index];}
166 
175  const char *str(int index) const {return reinterpret_cast<char *>(_message_block+index);}
176 
185  char *str(int index) {return reinterpret_cast<char *>(_message_block+index);}
186 
187  // Operations
191  enum SendType {User = 17, Recorded = 18, Acknowledge = 19};
195  enum SpecialDestination {Broadcast = 0, Iconbar = -2};
196  int send(SendType type, int destination, int icon_handle = 0);
197 
198 protected:
200  bool _owns_block;
201 };
202 
203 
210 {
211 private:
212  WimpMessage _message;
213  bool _claimed;
214 
215 public:
219  WimpMessageEvent(PollBlock &poll_block) : _message(poll_block), _claimed(false) {}
220 
224  const WimpMessage &message() const {return _message;}
225 
229  void claim() {_claimed = true;}
230 
234  bool claimed() const {return _claimed;}
235 };
236 
241 {
242 public:
246  virtual ~WimpMessageListener() {};
247 };
248 
253 {
254 public:
259 
263  virtual void user_message(WimpMessageEvent &event) {}
264 };
265 
270 {
271 public:
276 
277 
283  virtual void recorded_message(WimpMessageEvent &event, int reply_to) {}
284 };
285 
290 {
291 public:
299  virtual void acknowledge_message(WimpMessageEvent &event) {}
300 };
301 
302 }
303 
304 #endif /* TBX_WIMPMESSAGELISTENER_H_ */
virtual void recorded_message(WimpMessageEvent &event, int reply_to)
Override this to process recorded user messages.
Definition: wimpmessagelistener.h:283
int & word(int index)
Return reference to message word so it can be updated.
Definition: wimpmessagelistener.h:147
virtual void acknowledge_message(WimpMessageEvent &event)
Override this to process an acknowledgement.
Definition: wimpmessagelistener.h:299
WimpMessage & operator=(const WimpMessage &other)
Assignment creates a copy of an existing message.
Definition: wimpmessagelistener.cc:75
virtual ~WimpMessageListener()
Destructor.
Definition: wimpmessagelistener.h:246
virtual ~WimpUserMessageListener()
Destructor does nothing.
Definition: wimpmessagelistener.h:258
Structure holding the raw data from a call to Wimp_Poll.
Definition: pollinfo.h:71
void my_ref(int ref)
Set my reference for the message.
Definition: wimpmessagelistener.h:117
Listener to handle WimpRecordedMessages (event code 18)
Definition: wimpmessagelistener.h:269
Wimp message information.
Definition: wimpmessagelistener.h:36
int your_ref() const
Get your reference from the message.
Definition: wimpmessagelistener.h:106
int operator[](int index) const
Get message word (integer)
Definition: wimpmessagelistener.h:156
void your_ref(int ref)
Set your reference for the message.
Definition: wimpmessagelistener.h:123
int * _message_block
pointer to the message data
Definition: wimpmessagelistener.h:199
int send(SendType type, int destination, int icon_handle=0)
Send a message to another application.
Definition: wimpmessagelistener.cc:107
Wimp message received event.
Definition: wimpmessagelistener.h:209
bool claimed() const
Has the event been claimed.
Definition: wimpmessagelistener.h:234
Listener to handle WimpAcnowledgeMessages (event code 19)
Definition: wimpmessagelistener.h:289
int sender_task_handle() const
Get task handle of sender.
Definition: wimpmessagelistener.h:98
Listener to handle WimpUserMessages (event code 17)
Definition: wimpmessagelistener.h:252
const char * str(int index) const
Return char * for part of the message.
Definition: wimpmessagelistener.h:175
virtual ~WimpRecordedMessageListener()
Destructor does nothing.
Definition: wimpmessagelistener.h:275
WimpMessageEvent(PollBlock &poll_block)
Constructor.
Definition: wimpmessagelistener.h:219
Base for listener for wimp messages.
Definition: wimpmessagelistener.h:240
SendType
Enumeration specifying the type of message to send.
Definition: wimpmessagelistener.h:191
WimpMessage(PollBlock &poll_block)
Use to refer to a message in an existing wimp poll block.
Definition: wimpmessagelistener.cc:31
Class to represent toolbox iconbar icon.
Definition: iconbar.h:44
char * str(int index)
Return char * for part of the message.
Definition: wimpmessagelistener.h:185
int block_size() const
Get length of block, 20 - 256 bytes, a whole number of words.
Definition: wimpmessagelistener.h:94
void message_id(int id)
Set the message id for the message.
Definition: wimpmessagelistener.h:129
int my_ref() const
Get my reference from the message.
Definition: wimpmessagelistener.h:102
bool _owns_block
True if the message data will be deleted when this object is deleted.
Definition: wimpmessagelistener.h:200
virtual ~WimpMessage()
Destructor for WimpMessage.
Definition: wimpmessagelistener.cc:90
const WimpMessage & message() const
WimpMessage that was received.
Definition: wimpmessagelistener.h:224
SpecialDestination
Enumeration with special targets for sending messages to.
Definition: wimpmessagelistener.h:195
int word(int index) const
Get message word (integer)
Definition: wimpmessagelistener.h:138
int message_id() const
Get the message ID.
Definition: wimpmessagelistener.h:110
void claim()
Claim the event so no other listeners process it.
Definition: wimpmessagelistener.h:229
virtual ~WimpAcknowledgeMessageListener()
Destructor does nothing.
Definition: wimpmessagelistener.h:295
virtual void user_message(WimpMessageEvent &event)
Override this to process user messages.
Definition: wimpmessagelistener.h:263