tbx  0.7.6
document.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  * Document.h
26  *
27  * Created on: 8 Oct 2010
28  * Author: alanb
29  */
30 
31 #ifndef TBX_DOCUMENT_H_
32 #define TBX_DOCUMENT_H_
33 
34 #include "../safelist.h"
35 #include "../listener.h"
36 #include <string>
37 #include <iostream>
38 
39 namespace tbx
40 {
41 namespace doc
42 {
43 class DocModifiedChangedListener;
44 
52 class Document
53 {
54 private:
55  std::string _file_name;
56  bool _modified;
58  static unsigned int _untitled;
59 
60 public:
61  Document();
62  virtual ~Document();
63 
64  virtual void new_document();
65 
68 
72  bool modified() const {return _modified;}
73 
77  const std::string &file_name() const {return _file_name;}
78 
82  virtual int file_type() const = 0;
83 
90  virtual int document_size() const = 0;
91 
95  virtual bool has_selection() const {return false;}
96 
97  virtual bool save(std::string file_name);
98 
102  virtual bool save(std::ostream &os) = 0;
103  virtual void save_completed(std::string file_name, bool safe);
104 
110  virtual bool save_selection(std::string file_name);
115  virtual bool save_selection(std::ostream &os) {return false;}
116 
122  virtual void save_selection_completed(std::string file_name) {}
123 
124  virtual bool load(std::string file_name, int estimated_size = -1);
131  virtual bool load(std::istream &is, int estimated_size) = 0;
132  virtual void load_completed(std::string file_name, bool from_filer);
133 
134 
135 protected:
136  void modified(bool changed);
137 };
138 
139 
144 {
145 public:
146  virtual ~DocModifiedChangedListener() {};
147 
152  virtual void document_modified_changed(Document *doc) = 0;
153 };
154 
155 
156 }
157 }
158 
159 #endif /* TBX_DOCUMENT_H_ */
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::doc::Document::save
virtual bool save(std::string file_name)
Called to save document to the given file.
Definition: document.cc:120
tbx::doc::Document::add_modified_changed_listener
void add_modified_changed_listener(DocModifiedChangedListener *listener)
Add a listener to detect when a document goes to and from its modified state.
Definition: document.cc:80
tbx::doc::Document::load
virtual bool load(std::string file_name, int estimated_size=-1)
Load document from given file name.
Definition: document.cc:172
tbx::doc::Document
Base class for a document.
Definition: document.h:53
tbx::doc::Document::has_selection
virtual bool has_selection() const
Check if the document has a selection.
Definition: document.h:95
tbx::doc::Document::file_type
virtual int file_type() const =0
Return the file type for this document.
tbx::doc::Document::save_selection
virtual bool save_selection(std::ostream &os)
Save selection to the given output stream Default does nothing.
Definition: document.h:115
tbx::doc::Document::save_selection_completed
virtual void save_selection_completed(std::string file_name)
Called when selection save has finished.
Definition: document.h:122
tbx::doc::Document::~Document
virtual ~Document()
Default destructor.
Definition: document.cc:60
tbx::SafeList
Simple one way linked list of pointers that provides a single iterator that can be used safely if ite...
Definition: safelist.h:45
tbx::doc::Document::document_size
virtual int document_size() const =0
Return the size of the document.
tbx::doc::Document::modified
bool modified() const
Return true if document has been modifed since the last save.
Definition: document.h:72
tbx::doc::Document::save_selection
virtual bool save_selection(std::string file_name)
Save selection.
Definition: document.cc:208
tbx::doc::Document::save_completed
virtual void save_completed(std::string file_name, bool safe)
This is called when a save is successfully completed.
Definition: document.cc:136
tbx::Listener
Base class for all toolbox event listeners.
Definition: listener.h:34
tbx::doc::Document::file_name
const std::string & file_name() const
Return the name of the document file.
Definition: document.h:77
tbx::doc::Document::load_completed
virtual void load_completed(std::string file_name, bool from_filer)
This is called after a document has successfully been loaded.
Definition: document.cc:194
tbx::doc::Document::new_document
virtual void new_document()
Called after a new document has been created and before it is attached to a window.
Definition: document.cc:71
tbx::doc::DocModifiedChangedListener::document_modified_changed
virtual void document_modified_changed(Document *doc)=0
This routine is called when the documents modified flag changes.
tbx::doc::Document::save
virtual bool save(std::ostream &os)=0
Save document to the given stream.
tbx::doc::Document::remove_modified_changed_listener
void remove_modified_changed_listener(DocModifiedChangedListener *listener)
Remove a listener to detect when a document goes to and from its modified state.
Definition: document.cc:89
tbx::doc::Document::Document
Document()
Default constructor.
Definition: document.cc:50
tbx::doc::DocModifiedChangedListener
Listener for document modified state changed.
Definition: document.h:144
tbx::doc::Document::load
virtual bool load(std::istream &is, int estimated_size)=0
Load document from the given input stream.