tbx  0.7.5
application.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010-2014 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_APPLICATION_H
26 #define TBX_APPLICATION_H
27 
28 #include "object.h"
29 #include "messagefile.h"
30 
34 namespace tbx
35 {
36  class AutoCreateListener;
37  class Command;
38  class WimpUserMessageListener;
39  class WimpRecordedMessageListener;
40  class WimpAcknowledgeMessageListener;
41  class PreQuitListener;
42  class QuitListener;
43  class ModeChangedListener;
44  class PaletteChangedListener;
45  class SpriteArea;
46  class Timer;
47  class Loader;
48  class PrePollListener;
49  class PostPollListener;
50  class PostEventListener;
51  class UncaughtHandler;
52 
53  namespace res
54  {
55  class ResObject;
56  }
57 
79  {
80  public:
81  static const int MIN_WIMP_VERSION;
82  static const int *NO_MESSAGES;
83  static const int *ALL_MESSAGES;
84  static const int *NO_EVENTS;
85  static const int *ALL_EVENTS;
86 
87  Application(const char *task_directory,
88  int wimp_version = MIN_WIMP_VERSION,
89  const int *deliver_messages = ALL_MESSAGES,
90  const int *deliver_events = ALL_EVENTS);
91 
96  static Application *instance() {return _instance;}
97 
103  SpriteArea *sprite_area() const {return _sprite_area;}
104 
105  void run();
106 
107  void set_autocreate_listener(std::string template_name, AutoCreateListener *listener);
108  void clear_autocreate_listener(std::string template_name);
109 
110  void add_command(int command_id, Command *command);
111  void remove_command(int command_id, Command *command);
112 
113  void add_idle_command(Command *command);
114  void remove_idle_command(Command *command);
115 
116  void add_user_message_listener(int message_id, WimpUserMessageListener *listener);
117  void remove_user_message_listener(int message_id, WimpUserMessageListener *listener);
118  void add_recorded_message_listener(int message_id, WimpRecordedMessageListener *listener);
119  void remove_recorded_message_listener(int message_id, WimpRecordedMessageListener *listener);
120  void add_acknowledge_message_listener(int message_id, WimpAcknowledgeMessageListener *listener);
121  void remove_acknowledge_message_listener(int message_id, WimpAcknowledgeMessageListener *listener);
122 
123  void add_prequit_listener(PreQuitListener *listener);
124  void remove_prequit_listener(PreQuitListener *listener);
125 
126  void add_quit_listener(QuitListener *listener);
127  void remove_quit_listener(QuitListener *listener);
128 
129  void add_mode_changed_listener(ModeChangedListener *listener);
130  void remove_mode_changed_listener(ModeChangedListener *listener);
131 
132  void add_palette_changed_listener(PaletteChangedListener *listener);
133  void remove_palette_changed_listener(PaletteChangedListener *listener);
134 
135  void add_timer(int elapsed, Timer *timer);
136  void remove_timer(Timer *timer);
137 
138  void add_opener(Loader *loader, int file_type);
139  void remove_opener(Loader *loader, int file_type);
140 
141 
142  res::ResObject resource(std::string template_name);
143 
147  TaskHandle task_handle() const {return _task_handle;}
148 
149  std::string directory() const;
150 
154  const MessageFile &messages() const {return _messages;}
155 
162  void quit() {_running = false;}
171  bool running() const {return _running;}
172 
173  bool yield();
174 
175  void unix_file_name_translation(bool on);
176  bool unix_file_name_translation() const;
177  void unix_file_name_control(int flags);
178  int unix_file_name_control() const;
179 
180  void catch_poll_exceptions(bool on);
181  void uncaught_handler(UncaughtHandler *handler);
182  void set_pre_poll_listener(PrePollListener *listener);
183  void set_post_poll_listener(PostPollListener *listener);
184  void set_post_event_listener(PostEventListener *listener);
185 
186  bool owns_window(WindowHandle window_handle, IconHandle icon_handle = 0);
187 
188  int start_wimp_task(std::string command);
189  void os_cli(std::string command);
190 
191  private:
192  bool _running;
193  TaskHandle _task_handle;
194  int _wimp_version;
195  SpriteArea *_sprite_area;
196  MessageFile _messages;
197 
198  static Application *_instance;
199  };
200 
206  inline Application *app() {return Application::instance();}
207 }
208 
209 #endif
210 
211 
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
TaskHandle task_handle() const
Get WIMP task handle for application.
Definition: application.h:147
static const int * ALL_EVENTS
Deliver all toolbox events.
Definition: application.h:85
SpriteArea * sprite_area() const
Get the sprite area.
Definition: application.h:103
Listener to handle WimpRecordedMessages (event code 18)
Definition: wimpmessagelistener.h:269
Base class for commands in tbx.
Definition: command.h:36
Listen for the pre quit message from the desktop.
Definition: prequitlistener.h:109
Class to provide a listener to allow processing before the call to wimp poll.
Definition: posteventlistener.h:47
Classes to use/edit toolbox resources in memory.
int WindowHandle
Type for WIMP windows handle.
Definition: handles.h:35
bool running() const
Check if application is running.
Definition: application.h:171
Class to simplify handling of Quit WIMP message.
Definition: quitlistener.h:45
The main application class.
Definition: application.h:78
Interface to process uncaught exceptions in an application.
Definition: uncaughthandler.h:43
Listener to handle WimpAcnowledgeMessages (event code 19)
Definition: wimpmessagelistener.h:289
Listener to handle WimpUserMessages (event code 17)
Definition: wimpmessagelistener.h:252
void quit()
Quit the application.
Definition: application.h:162
Class to provide a listener to allow processing before the call to wimp poll.
Definition: prepolllistener.h:47
static const int MIN_WIMP_VERSION
Minimum Wimp version TBX supports.
Definition: application.h:81
static const int * NO_MESSAGES
Don't deliver any wimp messages (except QUIT)
Definition: application.h:82
Class to handle file/data loading from the filer or an external application.
Definition: loader.h:179
const MessageFile & messages() const
Return the default message file for this application.
Definition: application.h:154
Class to simplify handling of Quit WIMP message.
Definition: palettechangedlistener.h:44
static const int * NO_EVENTS
Don't deliver any toolbox event.
Definition: application.h:84
Callback class for a timer.
Definition: timer.h:42
int IconHandle
Type for WIMP icon handle.
Definition: handles.h:37
static Application * instance()
Get the application instance.
Definition: application.h:96
static const int * ALL_MESSAGES
Deliver all messages.
Definition: application.h:83
Base Listener for auto create events.
Definition: autocreatelistener.h:41
int TaskHandle
Type for a Wimp Task.
Definition: handles.h:56
Base class for a resource object that can be edited.
Definition: resobject.h:52
Class to lookup token translations from a messages file.
Definition: messagefile.h:42
Class to simplify handling of Quit WIMP message.
Definition: modechangedlistener.h:44
Class to provide a listener to allow inspection of the values returned from the Wimp_Poll call...
Definition: postpolllistener.h:42
Application * app()
Get the current application instance.
Definition: application.h:206
A SpriteArea holds zero or more user sprites.
Definition: sprite.h:231