tbx  0.7.6
taskwindow.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2015 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 #ifndef TBX_TASKWINDOW_H
25 #define TBX_TASKWINDOW_H
26 
27 #include <string>
28 #include <vector>
29 #include "listener.h"
30 #include "wimpmessagelistener.h"
31 
32 namespace tbx
33 {
34 
35 class TaskWindowStartedListener;
36 class TaskWindowFinishedListener;
37 class TaskWindowOutputListener;
38 
43 {
44  std::string _command;
45  std::string _name;
46  int _wimp_slot;
47  unsigned int _options;
48  unsigned int _child_task;
49  unsigned int _txt_id;
50  bool _running;
51  static unsigned int _next_txt_id;
52  class Router :
55  {
56  TaskWindow *_me;
57  public:
58  Router(TaskWindow *me);
59  ~Router();
60  std::vector<TaskWindowStartedListener *> _started_listeners;
61  std::vector<TaskWindowFinishedListener *> _finished_listeners;
62  std::vector<TaskWindowOutputListener *> _output_listeners;
63 
64  virtual void user_message(tbx::WimpMessageEvent &event);
65  virtual void recorded_message(tbx::WimpMessageEvent &event, int reply_to);
66  } *_router;
67  friend Router;
68 public:
72  enum Options
73  {
81  DISPLAY=2,
85  QUIT=4
86  };
87 
88  TaskWindow();
89  TaskWindow(std::string command, std::string name, int wimp_slot = 0, unsigned int options = 0);
90  ~TaskWindow();
91 
97  const std::string &command() const { return _command; }
103  void command(const std::string &command) { _command = command; }
108  const std::string &name() const { return _name; }
114  void name(const std::string &name) { _name = name; }
118  int wimp_slot() const { return _wimp_slot; }
124  void wimp_slot(int slot) { _wimp_slot = slot; }
125 
130  unsigned int options() const { return _options; }
136  void options(unsigned int new_opts) { _options = new_opts; }
137 
144  bool running() const { return _running; }
150  unsigned int child_task() const { return _child_task; }
151 
158 
159  void run();
160 
161  void send_input(const char *text, int size = -1);
162  void send_input(const std::string &text);
163  void suspend();
164  void resume();
165  void kill();
166 };
167 
172 {
173 public:
175  virtual ~TaskWindowStartedListener() {}
176 
181  virtual void taskwindow_started(TaskWindow &task_window) = 0;
182 };
183 
188 {
189 public:
191  virtual ~TaskWindowFinishedListener() {}
192 
197  virtual void taskwindow_finished(TaskWindow &task_window) = 0;
198 };
199 
204 {
205 public:
207  virtual ~TaskWindowOutputListener() {}
208 
215  virtual void taskwindow_output(TaskWindow &task_window, int size, const char *text) = 0;
216 };
217 
218 }; /* end of namespace tbx */
219 
220 #endif
tbx::TaskWindow::remove_finished_listener
void remove_finished_listener(TaskWindowFinishedListener *listener)
Remove listener to detect when the child task has finished.
Definition: taskwindow.cc:134
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::TaskWindow
Class to start a child task in a RISC OS task window.
Definition: taskwindow.h:43
tbx::TaskWindow::DISPLAY
@ DISPLAY
Show the taskwindow output window before any output comes from the task.
Definition: taskwindow.h:81
tbx::TaskWindowStartedListener
Listener for when a task window has started.
Definition: taskwindow.h:172
tbx::TaskWindow::wimp_slot
int wimp_slot() const
Get the wimp slot size in KB for the task window.
Definition: taskwindow.h:118
tbx::TaskWindow::remove_output_listener
void remove_output_listener(TaskWindowOutputListener *listener)
Remove listener to detect output from the child task.
Definition: taskwindow.cc:171
tbx::TaskWindowFinishedListener::taskwindow_finished
virtual void taskwindow_finished(TaskWindow &task_window)=0
Called when the task window has finished.
tbx::TaskWindow::command
void command(const std::string &command)
Set the command run by this task window.
Definition: taskwindow.h:103
tbx::TaskWindow::command
const std::string & command() const
Get the command run by this task window.
Definition: taskwindow.h:97
tbx::TaskWindow::add_finished_listener
void add_finished_listener(TaskWindowFinishedListener *listener)
Add listener to detect when the child task has finished.
Definition: taskwindow.cc:124
tbx::TaskWindow::name
const std::string & name() const
Get the task name for the task window.
Definition: taskwindow.h:108
tbx::TaskWindow::TaskWindow
TaskWindow()
Uninitialised task window.
Definition: taskwindow.cc:50
tbx::TaskWindow::resume
void resume()
Resume the current child task after it has been suspended with a call to suspend.
Definition: taskwindow.cc:296
tbx::TaskWindow::add_started_listener
void add_started_listener(TaskWindowStartedListener *listener)
Add listener to detect when the child task is started.
Definition: taskwindow.cc:95
tbx::WimpRecordedMessageListener
Listener to handle WimpRecordedMessages (event code 18)
Definition: wimpmessagelistener.h:270
tbx::TaskWindowOutputListener::taskwindow_output
virtual void taskwindow_output(TaskWindow &task_window, int size, const char *text)=0
Called when there is output from the task window has.
tbx::TaskWindow::options
void options(unsigned int new_opts)
Set the options when the task window is executed Changing this will have no effect on a currently run...
Definition: taskwindow.h:136
tbx::TaskWindowFinishedListener
Listener for when a task window has finished.
Definition: taskwindow.h:188
tbx::TaskWindow::child_task
unsigned int child_task() const
task id of the child task.
Definition: taskwindow.h:150
tbx::TaskWindow::Options
Options
Task window run options.
Definition: taskwindow.h:73
tbx::TaskWindowOutputListener
Listener for output from a task window.
Definition: taskwindow.h:204
tbx::TaskWindow::options
unsigned int options() const
The options applied when the task window is executed.
Definition: taskwindow.h:130
tbx::TaskWindowStartedListener::taskwindow_started
virtual void taskwindow_started(TaskWindow &task_window)=0
Called when the task window has started.
tbx::TaskWindow::run
void run()
Run the child task.
Definition: taskwindow.cc:209
tbx::TaskWindow::name
void name(const std::string &name)
Set the name of the task window Changing this will have no effect on a currently running task window.
Definition: taskwindow.h:114
tbx::TaskWindow::suspend
void suspend()
Suspend the current child task.
Definition: taskwindow.cc:283
tbx::TaskWindow::kill
void kill()
Kill the current child task.
Definition: taskwindow.cc:307
tbx::TaskWindow::ALLOW_CONTROL
@ ALLOW_CONTROL
Allow control characters to be sent to the output.
Definition: taskwindow.h:77
tbx::WimpUserMessageListener
Listener to handle WimpUserMessages (event code 17)
Definition: wimpmessagelistener.h:253
tbx::TaskWindow::running
bool running() const
Check if task window is running.
Definition: taskwindow.h:144
tbx::TaskWindow::remove_started_listener
void remove_started_listener(TaskWindowStartedListener *listener)
Remove listener to detect when the child task is started.
Definition: taskwindow.cc:105
tbx::TaskWindow::send_input
void send_input(const char *text, int size=-1)
Send input to the task window.
Definition: taskwindow.cc:250
tbx::Listener
Base class for all toolbox event listeners.
Definition: listener.h:34
tbx::WimpMessageEvent
Wimp message received event.
Definition: wimpmessagelistener.h:210
tbx::TaskWindow::~TaskWindow
~TaskWindow()
Destructor, remove interest in the task window.
Definition: taskwindow.cc:86
tbx::TaskWindow::QUIT
@ QUIT
Quit the task windo wht the child task finishes.
Definition: taskwindow.h:85
tbx::TaskWindow::add_output_listener
void add_output_listener(TaskWindowOutputListener *listener)
Add listener to capture output from the child task.
Definition: taskwindow.cc:156
tbx::TaskWindow::wimp_slot
void wimp_slot(int slot)
Set the wimp slot for the task window Changing this will have no effect on a currently running task w...
Definition: taskwindow.h:124