tbx  0.7.3
Public Member Functions | Protected Member Functions | List of all members
tbx::doc::Document Class Referenceabstract

Base class for a document. More...

#include <document.h>

Public Member Functions

 Document ()
 Default constructor. More...
 
virtual ~Document ()
 Default destructor. More...
 
virtual void new_document ()
 Called after a new document has been created and before it is attached to a window. More...
 
void add_modified_changed_listener (DocModifiedChangedListener *listener)
 Add a listener to detect when a document goes to and from its modified state.
 
void remove_modified_changed_listener (DocModifiedChangedListener *listener)
 Remove a listener to detect when a document goes to and from its modified state.
 
bool modified () const
 Return true if document has been modifed since the last save.
 
const std::string & file_name () const
 Return the name of the document file.
 
virtual int file_type () const =0
 Return the file type for this document.
 
virtual int document_size () const =0
 Return the size of the document. More...
 
virtual bool has_selection () const
 Check if the document has a selection.
 
virtual bool save (std::string file_name)
 Called to save document to the given file. More...
 
virtual bool save (std::ostream &os)=0
 Save document to the given stream.
 
virtual void save_completed (std::string file_name, bool safe)
 This is called when a save is successfully completed. More...
 
virtual bool save_selection (std::string file_name)
 Save selection. More...
 
virtual bool save_selection (std::ostream &os)
 Save selection to the given output stream Default does nothing.
 
virtual void save_selection_completed (std::string file_name)
 Called when selection save has finished. More...
 
virtual bool load (std::string file_name, int estimated_size=-1)
 Load document from given file name. More...
 
virtual bool load (std::istream &is, int estimated_size)=0
 Load document from the given input stream. More...
 
virtual void load_completed (std::string file_name, bool from_filer)
 This is called after a document has successfully been loaded. More...
 

Protected Member Functions

void modified (bool changed)
 Set the document modified flag. More...
 

Detailed Description

Base class for a document.

Automatically adds and removes documents from the document manager and provides the interfaces required for the Document manager and other doc classes.

Constructor & Destructor Documentation

tbx::doc::Document::Document ( )

Default constructor.

Adds document to the document manager

tbx::doc::Document::~Document ( )
virtual

Default destructor.

Removes document from the document manager

Member Function Documentation

virtual int tbx::doc::Document::document_size ( ) const
pure virtual

Return the size of the document.

If the size can not be accurately calculated an estimate should be returned.

bool tbx::doc::Document::load ( std::string  file_name,
int  estimated_size = -1 
)
virtual

Load document from given file name.

This version opens a binary input stream on the file name and passes the loading onto load(std::istream*, int) If estimated_size == -1 it also calculates the length of the file before passing it on.

Parameters
file_namename of file to load
estimated_size- estimated size of file or -1 if not specified
virtual bool tbx::doc::Document::load ( std::istream &  is,
int  estimated_size 
)
pure virtual

Load document from the given input stream.

Parameters
isinput stream to load from
estimated_sizeestimated size of data or -1 if estimate not given
void tbx::doc::Document::load_completed ( std::string  file_name,
bool  from_filer 
)
virtual

This is called after a document has successfully been loaded.

It is called before the window is shown.

If you override this method you should call this base version to update the file name.

void tbx::doc::Document::modified ( bool  changed)
protected

Set the document modified flag.

If it has changed from it's old state the DocModifiedChangedListeners are fired.

void tbx::doc::Document::new_document ( )
virtual

Called after a new document has been created and before it is attached to a window.

The default sets the file_name to "Untitled" with a count

bool tbx::doc::Document::save ( std::string  file_name)
virtual

Called to save document to the given file.

This version opens a binary output stream on the file and calls save(std::ostream&).

void tbx::doc::Document::save_completed ( std::string  file_name,
bool  safe 
)
virtual

This is called when a save is successfully completed.

The default sets the file type, updates the file name and sends a modified event so listeners can update their titles.

Parameters
file_namefile name used for the save
safetrue if save was to a "safe" location (e.g. the filer)
bool tbx::doc::Document::save_selection ( std::string  file_name)
virtual

Save selection.

Parameters
file_namefile name to save to
Returns
true if save successful

This version opens a binary output stream and calls save_selection(std::ostream&)

Parameters
file_namefile_name to save to
Returns
true if save successful
virtual void tbx::doc::Document::save_selection_completed ( std::string  file_name)
inlinevirtual

Called when selection save has finished.

Base does nothing


The documentation for this class was generated from the following files: