tbx  0.7.5
saveas.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  * saveas.h
27  *
28  * Created on: 08-Apr-2009
29  * Author: alanb
30  */
31 
32 #ifndef TBX_SAVEAS_H_
33 #define TBX_SAVEAS_H_
34 
35 #include "showfullobject.h"
36 #include "listener.h"
37 #include "eventinfo.h"
38 #include "window.h"
39 
40 namespace tbx {
41 
42 // Listener classes used by SaveAs
43 class AboutToBeShownListener;
44 class HasBeenHiddenListener;
45 class SaveAsDialogueCompletedListener;
46 class SaveAsSaveToFileHandler;
47 class SaveAsFillBufferHandler;
48 class SaveAsSaveCompletedListener;
49 
50 namespace res
51 {
52  class ResSaveAs;
53 }
54 
65 {
66 public:
67  enum { TOOLBOX_CLASS = 0x82bc0 };
68 
74  SaveAs() {};
83  SaveAs(const SaveAs &other) : ShowFullObject(other._handle) {}
94  SaveAs(const Object &other) : ShowFullObject(other) {check_toolbox_class(SaveAs::TOOLBOX_CLASS);}
102  SaveAs(const std::string &template_name) : ShowFullObject(template_name) {check_toolbox_class(SaveAs::TOOLBOX_CLASS);}
109  SaveAs(const res::ResSaveAs &object_template);
110 
119  SaveAs &operator=(const SaveAs &other) {_handle = other.handle(); return *this;}
131  SaveAs &operator=(const Object &other) {_handle = other.handle(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
139  bool operator==(const Object &other) const {return (_handle == other.handle());}
147  bool operator!=(const Object &other) const {return (_handle != other.handle());}
148 
149 
150  // Properties
154  Window window() const {return Window((ObjectId)int_property(0));}
155 
159  void title(std::string value) {string_property(1, value);}
160 
164  std::string title() const {return string_property(2);}
165 
169  void file_name(std::string value) {string_property(3, value);}
170 
174  std::string file_name() const {return string_property(4);}
175 
179  void file_type(int value) {int_property(5, value);}
180 
184  int file_type() const {return int_property(6);}
185 
189  void file_size(int value) {int_property(7, value);}
190 
194  int file_size() const {return int_property(8);}
195 
199  void selection_available(bool available) { bool_property(9, available);}
200 
201  void set_data_address(void *data, int size, void *selection = 0, int selection_size = 0);
202  void buffer_filled(void *buffer, int size);
203  void file_save_completed(bool successful, std::string file_name);
204 
205  void add_about_to_be_shown_listener(AboutToBeShownListener *listener);
206  void remove_about_to_be_shown_listener(AboutToBeShownListener *listener);
207  void add_has_been_hidden_listener(HasBeenHiddenListener *listener);
208  void remove_has_been_hidden_listener(HasBeenHiddenListener *listener);
209  void add_dialogue_completed_listener(SaveAsDialogueCompletedListener *listener);
210  void remove_dialogue_completed_listener(SaveAsDialogueCompletedListener *listener);
211  void add_save_completed_listener(SaveAsSaveCompletedListener *listener);
212  void remove_save_completed_listener(SaveAsSaveCompletedListener *listener);
213 
214  void set_save_to_file_handler(SaveAsSaveToFileHandler *handler);
215  void set_fill_buffer_handler(SaveAsFillBufferHandler *handler);
216 
217 };
218 
223 {
224 public:
232  EventInfo(id_block, data) {}
233 
241  bool save_done() const {return ((_data.word[3]&1) != 0);}
242 };
243 
248 {
249 public:
255  virtual void saveas_dialogue_completed(const SaveAsDialogueCompletedEvent &completed_event) = 0;
256 };
257 
263 {
264 public:
272  EventInfo(id_block, data)
273  {}
274 
278  bool selection_saved() const {return (_data.word[3] & 1) !=0;}
279 
283  bool safe() const {return (_data.word[3] & 2) != 0;}
284 
289  int message_id() const {return _data.word[4];}
290 
294  const std::string file_name() const {return reinterpret_cast<const char *>(&_data.word[5]);}
295 };
296 
301 {
302 public:
308  virtual void saveas_save_completed(SaveAsSaveCompletedEvent &event) = 0;
309 };
310 
317 {
318 public:
329  virtual void saveas_save_to_file(SaveAs saveas, bool selection, std::string file_name) = 0;
330 };
331 
338 {
339 public:
358  virtual void saveas_fill_buffer(SaveAs saveas, bool selection, int size, void *buffer, int already_transmitted) = 0;
359 };
360 
361 }
362 
363 #endif /* TBX_SAVEAS_H_ */
bool selection_saved() const
Check if save was of the selection.
Definition: saveas.h:278
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
SaveAs()
Construct creates an unassigned SaveAs.
Definition: saveas.h:74
std::string title() const
Get the title for the SaveAs object.
Definition: saveas.h:164
Event information for when saveas dialogue has been completed.
Definition: saveas.h:222
Listener for about to be shown event.
Definition: abouttobeshownlistener.h:76
SaveAsSaveCompletedEvent(IdBlock &id_block, PollBlock &data)
Construct the event from Toolbox and WIMP event data.
Definition: saveas.h:271
Structure holding the raw data from a call to Wimp_Poll.
Definition: pollinfo.h:71
SaveAsDialogueCompletedEvent(IdBlock &id_block, PollBlock &data)
Construct the event from Toolbox and WIMP event data.
Definition: saveas.h:231
SaveAs & operator=(const SaveAs &other)
Assign this SaveAs from another.
Definition: saveas.h:119
Classes to use/edit toolbox resources in memory.
const std::string file_name() const
Full file name of file location if save was safe.
Definition: saveas.h:294
Handler for SaveAsSaveToFile message.
Definition: saveas.h:316
bool save_done() const
Check if the dialogue was closed after a successful save.
Definition: saveas.h:241
SaveAs & operator=(const Object &other)
Assign this SaveAs from an Object that refers to a SaveAs.
Definition: saveas.h:131
std::string file_name() const
Get the file name for the SaveAs object.
Definition: saveas.h:174
void title(std::string value)
Set the title for the SaveAs object.
Definition: saveas.h:159
bool safe() const
Check if the save was to a safe location (e.g.
Definition: saveas.h:283
unsigned int ObjectId
Type for underlying toolbox object id.
Definition: handles.h:31
Event for SaveAsSaveCompletedListener.
Definition: saveas.h:262
int file_type() const
Get the file type from the SaveAs object.
Definition: saveas.h:184
Listener for when the save as dialogue box has been closed.
Definition: saveas.h:247
void file_size(int value)
Set the file size for the SaveAs object.
Definition: saveas.h:189
bool operator==(const Object &other) const
Check if this SaveAs refers to the same underlying toolbox object as another.
Definition: saveas.h:139
int file_size() const
Get the file size from the SaveAs object.
Definition: saveas.h:194
The Window object represents a toolbox window.
Definition: window.h:69
void selection_available(bool available)
Set if a selection is available.
Definition: saveas.h:199
Class to provide information on a toolbox event.
Definition: eventinfo.h:48
Base class for all toolbox event listeners.
Definition: listener.h:33
Class for SaveAs object template.
Definition: ressaveas.h:36
int message_id() const
Wimp message of original datasave message or 0 if save wasn&#39;t by a drag.
Definition: saveas.h:289
Listener for an object has been hidden event.
Definition: hasbeenhiddenlistener.h:36
SaveAs(const SaveAs &other)
Construct a SaveAs from another SaveAs.
Definition: saveas.h:83
void file_type(int value)
Set the file type for the SaveAs object.
Definition: saveas.h:179
Window window() const
Return the underlying toolbox window used to implement the SaveAs object.
Definition: saveas.h:154
Listener for when a save has been completed.
Definition: saveas.h:300
Objects derived from this class can be shown with there full location and size specified as well as t...
Definition: showfullobject.h:40
Information passed back by the Toolbox with each toolbox event providing information on where the eve...
Definition: pollinfo.h:41
SaveAs(const std::string &template_name)
Create a SaveAs from the named template.
Definition: saveas.h:102
Class to manipulate a toolbox object.
Definition: object.h:50
Handler for SaveAsFillBuffer message.
Definition: saveas.h:337
SaveAs(const Object &other)
Construct a SaveAs from an Object that refers to a SaveAs.
Definition: saveas.h:94
bool operator!=(const Object &other) const
Check if this SaveAs does not refers to the same underlying toolbox object as another.
Definition: saveas.h:147
Class to show the RISC OS SaveAs dialog box and generate events to allow the application to do the Sa...
Definition: saveas.h:64
ObjectId handle() const
Return the underlying toolbox object id this object references.
Definition: object.h:93
void file_name(std::string value)
Set the file name for the save as object.
Definition: saveas.h:169