tbx  0.7.3
prequitlistener.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  * prequitlistener.h
27  *
28  * Created on: 09-Jun-2009
29  * Author: alanb
30  */
31 
32 #ifndef TBX_PREQUITLISTENER_H_
33 #define TBX_PREQUITLISTENER_H_
34 
35 #include "wimpmessagelistener.h"
36 #include "listener.h"
37 #include <vector>
38 
39 namespace tbx
40 {
46  {
47  int _prequit_sender;
48  bool _close_only;
49 
50  public:
51  QuitRestarter();
52  QuitRestarter(int sender, bool close_only);
53  QuitRestarter(const QuitRestarter &other);
54 
55  QuitRestarter &operator=(const QuitRestarter &other);
56 
65  void close_application_only(bool close_only) {_close_only = close_only;}
66 
73  bool close_application_only() const {return _close_only;}
74 
75  void restart_quit();
76 
77  };
78 
83  {
84  private:
85  WimpMessage _message;
86  int _reply_to;
87  bool _cancelled;
88  QuitRestarter _restarter;
89 
90  public:
91  PreQuitEvent(const WimpMessage &m, int reply_to);
92  void cancel_quit();
93 
98  bool cancelled() const { return _cancelled;}
99 
103  QuitRestarter quit_restarter() const {return _restarter;}
104  };
105 
109  class PreQuitListener : public Listener
110  {
111  public:
123  virtual void pre_quit(PreQuitEvent &event) = 0;
124  };
125 
127 
130  class PreQuitManager : public WimpRecordedMessageListener
131  {
132  static PreQuitManager *_instance;
133  std::vector<PreQuitListener *> _listeners;
134 
135  public:
136  PreQuitManager();
137  static PreQuitManager *instance() {return _instance;}
138 
139  void add_listener(PreQuitListener *listener);
140  void remove_listener(PreQuitListener *listener);
141 
142  virtual void recorded_message(WimpMessageEvent &event, int reply_to);
143  };
145 
146 }
147 
148 #endif /* TBX_PREQUITLISTENER_H_ */
bool close_application_only() const
Check if this QuitRestarter will close the current application only.
Definition: prequitlistener.h:73
Event passed to pre quit listeners.
Definition: prequitlistener.h:82
virtual void pre_quit(PreQuitEvent &event)=0
Called when the prequit message has been received from the desktop.
PreQuitEvent(const WimpMessage &m, int reply_to)
Construct PreQuitEvent from prequit message received from the WIMP.
Definition: prequitlistener.cc:109
Class to allow a quit cancelled during the prequit message to be restarted.
Definition: prequitlistener.h:45
Listener to handle WimpRecordedMessages (event code 18)
Definition: wimpmessagelistener.h:269
Listen for the pre quit message from the desktop.
Definition: prequitlistener.h:109
void cancel_quit()
Cancel the quit preceeded by this pre-quit message.
Definition: prequitlistener.cc:120
Wimp message information.
Definition: wimpmessagelistener.h:36
void close_application_only(bool close_only)
Set the QuitRestarter to close this application and not continue a desktop shutdown.
Definition: prequitlistener.h:65
bool cancelled() const
Quit has already been cancelled by a previous pre-quit handler.
Definition: prequitlistener.h:98
QuitRestarter & operator=(const QuitRestarter &other)
Assignment operator.
Definition: prequitlistener.cc:66
Base class for all toolbox event listeners.
Definition: listener.h:33
QuitRestarter()
Construct a quit restarter that will just close the current application when restart_quit is called...
Definition: prequitlistener.cc:49
void restart_quit()
Restart a quit application cancelled during a PreQuit message.
Definition: prequitlistener.cc:91
QuitRestarter quit_restarter() const
Return a class that can be used to restart the quit.
Definition: prequitlistener.h:103