tbx  0.7.3
quit.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  * quit.h
27  *
28  * Created on: 09-Jun-2009
29  * Author: alanb
30  */
31 
32 #ifndef TBX_QUIT_H_
33 #define TBX_QUIT_H_
34 
35 #include "showfullobject.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 QuitQuitListener;
46 class QuitCancelListener;
47 
48 namespace res
49 {
50  class ResQuit;
51 }
52 
60 class Quit : public tbx::ShowFullObject
61 {
62 public:
63  enum { TOOLBOX_CLASS = 0x82a90 };
64 
70  Quit() {};
79  Quit(const Quit &other) : ShowFullObject(other._handle) {}
90  Quit(const Object &other) : ShowFullObject(other) {check_toolbox_class(Quit::TOOLBOX_CLASS);}
98  Quit(const std::string &template_name) : ShowFullObject(template_name) {check_toolbox_class(Quit::TOOLBOX_CLASS);}
105  Quit(const res::ResQuit &object_template);
106 
115  Quit &operator=(const Quit &other) {_handle = other.handle(); return *this;}
127  Quit &operator=(const Object &other) {_handle = other.handle(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
135  bool operator==(const Object &other) const {return (_handle == other.handle());}
143  bool operator!=(const Object &other) const {return (_handle != other.handle());}
144 
145 
146  // Properties
150  Window window() const {return Window((ObjectId)int_property(0));}
151 
155  void message(std::string msg) {string_property(1, msg);}
156 
160  std::string message() const {return string_property(2);}
164  int message_length() const {return string_property_length(2);}
165 
169  void title(std::string msg) {string_property(3, msg);}
170 
174  std::string title() const {return string_property(4);}
178  int title_length() const {return string_property_length(4);}
179 
180  // Listeners
185  void add_quit_listener(QuitQuitListener *listener);
186  void remove_quit_listener(QuitQuitListener *listener);
187  void add_cancel_listener(QuitCancelListener *listener);
189 };
190 
195 {
196 public:
200  virtual void quit_quit(const EventInfo &quit_event) = 0;
201 };
202 
207 {
208 public:
212  virtual void quit_cancel(const EventInfo &cancel_event) = 0;
213 };
214 
215 
216 }
217 
218 #endif /* TBX_QUIT_H_ */
Quit(const Quit &other)
Construct a Quit from another Quit.
Definition: quit.h:79
void message(std::string msg)
Set message to display in window.
Definition: quit.h:155
ObjectId _handle
Handle for toolbox object.
Definition: object.h:173
std::string message() const
Return message.
Definition: quit.h:160
Listener for when a Quit is selected from the Quit dialog.
Definition: quit.h:194
Quit()
Construct creates an unassigned Quit.
Definition: quit.h:70
int title_length() const
Return length of title.
Definition: quit.h:178
Listener for when a cancel is selected from the Quit dialog.
Definition: quit.h:206
Quit(const Object &other)
Construct a Quit from an Object that refers to a Quit.
Definition: quit.h:90
Listener for about to be shown event.
Definition: abouttobeshownlistener.h:76
void check_toolbox_class(int class_id) const
Check if this objects toolbox class is as specified.
Definition: object.cc:122
void add_quit_listener(QuitQuitListener *listener)
Add listener to be called when quit is selected from the dialogue.
Definition: quit.cc:93
int string_property_length(int property_id) const
Gets the size of a string properties buffer.
Definition: object.cc:530
bool operator==(const Object &other) const
Check if this Quit refers to the same underlying toolbox object as another.
Definition: quit.h:135
void remove_has_been_hidden_listener(HasBeenHiddenListener *listener)
Remove has been hidden listener.
Definition: quit.cc:77
Quit & operator=(const Object &other)
Assign this Quit from an Object that refers to a Quit.
Definition: quit.h:127
void title(std::string msg)
Set title of window.
Definition: quit.h:169
Quit(const std::string &template_name)
Create a Quit from the named template.
Definition: quit.h:98
int int_property(int property_id) const
Return the value of a property that returns an integer.
Definition: object.cc:435
std::string string_property(int property_id) const
Return the value of a property that returns text.
Definition: object.cc:477
virtual void quit_quit(const EventInfo &quit_event)=0
Called when quit is selected from a Quit dialog.
unsigned int ObjectId
Type for underlying toolbox object id.
Definition: handles.h:31
void add_about_to_be_shown_listener(AboutToBeShownListener *listener)
This event is raised just before the Quit underlying window is about to be shown. ...
Definition: quit.cc:47
bool operator!=(const Object &other) const
Check if this Quit does not refers to the same underlying toolbox object as another.
Definition: quit.h:143
void add_cancel_listener(QuitCancelListener *listener)
Add listener to be called when cancel is selected from the dialogue.
Definition: quit.cc:119
Class for Quit object template.
Definition: resquit.h:36
ObjectId handle() const
Return the underlying toolbox object id this object references.
Definition: object.h:93
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
void remove_cancel_listener(QuitCancelListener *listener)
Remove listener called when cancel is selected from the dialogue.
Definition: quit.cc:129
void remove_quit_listener(QuitQuitListener *listener)
Remove listener called when quit is selected from the dialogue.
Definition: quit.cc:103
Quit & operator=(const Quit &other)
Assign this Quit from another.
Definition: quit.h:115
void remove_about_to_be_shown_listener(AboutToBeShownListener *listener)
Remove about to be shown listener.
Definition: quit.cc:57
int message_length() const
Return length of message.
Definition: quit.h:164
Window window() const
Return the underlying toolbox window used to implement the Quit object.
Definition: quit.h:150
Class to show a toolbox Quit object that gives the user an option to Quit or Cancel the application...
Definition: quit.h:60
Listener for an object has been hidden event.
Definition: hasbeenhiddenlistener.h:36
Objects derived from this class can be shown with there full location and size specified as well as t...
Definition: showfullobject.h:40
Class to manipulate a toolbox object.
Definition: object.h:50
virtual void quit_cancel(const EventInfo &cancel_event)=0
Called when cancel is selected from a Quit dialog.
void add_has_been_hidden_listener(HasBeenHiddenListener *listener)
This event is raised after the Quit dialog has been completed.
Definition: quit.cc:67
std::string title() const
Return title.
Definition: quit.h:174