- DECLARE_ABSTRACT_CLASS(wxDocument)
- public:
- wxDocument(wxDocument *parent = (wxDocument *) NULL);
- ~wxDocument(void);
-
- void SetFilename(const wxString& filename, bool notifyViews = FALSE);
- inline wxString GetFilename(void) const { return m_documentFile; }
- inline void SetTitle(const wxString& title) { m_documentTitle = title; };
- inline wxString GetTitle(void) const { return m_documentTitle; }
- inline void SetDocumentName(const wxString& name) { m_documentTypeName = name; };
- inline wxString GetDocumentName(void) const { return m_documentTypeName; }
- // Has the document been saved yet?
- inline bool GetDocumentSaved(void) { return m_savedYet; }
- inline void SetDocumentSaved(bool saved = TRUE) { m_savedYet = saved; }
-
- virtual bool Close(void);
- virtual bool Save(void);
- virtual bool SaveAs(void);
- virtual bool Revert(void);
-
- virtual ostream& SaveObject(ostream& stream);
- virtual istream& LoadObject(istream& stream);
-
- // Called by wxWindows
- virtual bool OnSaveDocument(const wxString& filename);
- virtual bool OnOpenDocument(const wxString& filename);
- virtual bool OnNewDocument(void);
- virtual bool OnCloseDocument(void);
-
- // Prompts for saving if about to close a modified document.
- // Returns TRUE if ok to close the document (may have saved in the
- // meantime, or set modified to FALSE)
- virtual bool OnSaveModified(void);
-
- // Called by framework if created automatically by the
- // default document manager: gives document a chance to
- // initialise and (usually) create a view
- virtual bool OnCreate(const wxString& path, long flags);
-
- // By default, creates a base wxCommandProcessor.
- virtual wxCommandProcessor *OnCreateCommandProcessor(void);
- virtual inline wxCommandProcessor *GetCommandProcessor(void) const { return m_commandProcessor; }
- virtual inline void SetCommandProcessor(wxCommandProcessor *proc) { m_commandProcessor = proc; }
-
- // Called after a view is added or removed.
- // The default implementation deletes the document if this
- // is there are no more views.
- virtual void OnChangedViewList(void);
-
- virtual bool DeleteContents(void);
-
- virtual bool Draw(wxDC&);
- virtual inline bool IsModified(void) const { return m_documentModified; }
- virtual inline void Modify(bool mod) { m_documentModified = mod; }
-
- virtual bool AddView(wxView *view);
- virtual bool RemoveView(wxView *view);
- inline wxList& GetViews(void) const { return (wxList&) m_documentViews; }
- wxView *GetFirstView(void) const;
-
- virtual void UpdateAllViews(wxView *sender = (wxView *) NULL, wxObject *hint = (wxObject *) NULL);
-
- // Remove all views (because we're closing the document)
- virtual bool DeleteAllViews(void);
-
- // Other stuff
- virtual wxDocManager *GetDocumentManager(void) const;
- virtual inline wxDocTemplate *GetDocumentTemplate(void) const { return m_documentTemplate; }
- virtual inline void SetDocumentTemplate(wxDocTemplate *temp) { m_documentTemplate = temp; }
-
- // Get title, or filename if no title, else [unnamed]
- virtual bool GetPrintableName(wxString& buf) const;
-
- // Returns a window that can be used as a parent for document-related
- // dialogs. Override if necessary.
- virtual wxWindow *GetDocumentWindow(void) const;
- protected:
- wxList m_documentViews;
- wxString m_documentFile;
- wxString m_documentTitle;
- wxString m_documentTypeName;
- wxDocTemplate* m_documentTemplate;
- bool m_documentModified;
- wxDocument* m_documentParent;
- wxCommandProcessor* m_commandProcessor;
- bool m_savedYet;
+public:
+ wxDocument(wxDocument *parent = NULL);
+ virtual ~wxDocument();
+
+ // accessors
+ void SetFilename(const wxString& filename, bool notifyViews = false);
+ wxString GetFilename() const { return m_documentFile; }
+
+ void SetTitle(const wxString& title) { m_documentTitle = title; }
+ wxString GetTitle() const { return m_documentTitle; }
+
+ void SetDocumentName(const wxString& name) { m_documentTypeName = name; }
+ wxString GetDocumentName() const { return m_documentTypeName; }
+
+ // access the flag indicating whether this document had been already saved,
+ // SetDocumentSaved() is only used internally, don't call it
+ bool GetDocumentSaved() const { return m_savedYet; }
+ void SetDocumentSaved(bool saved = true) { m_savedYet = saved; }
+
+ // return true if the document hasn't been modified since the last time it
+ // was saved (implying that it returns false if it was never saved, even if
+ // the document is not modified)
+ bool AlreadySaved() const { return !IsModified() && GetDocumentSaved(); }
+
+ virtual bool Close();
+ virtual bool Save();
+ virtual bool SaveAs();
+ virtual bool Revert();
+
+#if wxUSE_STD_IOSTREAM
+ virtual wxSTD ostream& SaveObject(wxSTD ostream& stream);
+ virtual wxSTD istream& LoadObject(wxSTD istream& stream);
+#else
+ virtual wxOutputStream& SaveObject(wxOutputStream& stream);
+ virtual wxInputStream& LoadObject(wxInputStream& stream);
+#endif
+
+ // Called by wxWidgets
+ virtual bool OnSaveDocument(const wxString& filename);
+ virtual bool OnOpenDocument(const wxString& filename);
+ virtual bool OnNewDocument();
+ virtual bool OnCloseDocument();
+
+ // Prompts for saving if about to close a modified document. Returns true
+ // if ok to close the document (may have saved in the meantime, or set
+ // modified to false)
+ virtual bool OnSaveModified();
+
+ // if you override, remember to call the default
+ // implementation (wxDocument::OnChangeFilename)
+ virtual void OnChangeFilename(bool notifyViews);
+
+ // Called by framework if created automatically by the default document
+ // manager: gives document a chance to initialise and (usually) create a
+ // view
+ virtual bool OnCreate(const wxString& path, long flags);
+
+ // By default, creates a base wxCommandProcessor.
+ virtual wxCommandProcessor *OnCreateCommandProcessor();
+ virtual wxCommandProcessor *GetCommandProcessor() const
+ { return m_commandProcessor; }
+ virtual void SetCommandProcessor(wxCommandProcessor *proc)
+ { m_commandProcessor = proc; }
+
+ // Called after a view is added or removed. The default implementation
+ // deletes the document if this is there are no more views.
+ virtual void OnChangedViewList();
+
+ virtual bool DeleteContents();
+
+ virtual bool Draw(wxDC&);
+ virtual bool IsModified() const { return m_documentModified; }
+ virtual void Modify(bool mod);
+
+ virtual bool AddView(wxView *view);
+ virtual bool RemoveView(wxView *view);
+ wxList& GetViews() { return m_documentViews; }
+ const wxList& GetViews() const { return m_documentViews; }
+ wxView *GetFirstView() const;
+
+ virtual void UpdateAllViews(wxView *sender = NULL, wxObject *hint = NULL);
+ virtual void NotifyClosing();
+
+ // Remove all views (because we're closing the document)
+ virtual bool DeleteAllViews();
+
+ // Other stuff
+ virtual wxDocManager *GetDocumentManager() const;
+ virtual wxDocTemplate *GetDocumentTemplate() const
+ { return m_documentTemplate; }
+ virtual void SetDocumentTemplate(wxDocTemplate *temp)
+ { m_documentTemplate = temp; }
+
+ // Get the document name to be shown to the user: the title if there is
+ // any, otherwise the filename if the document was saved and, finally,
+ // "unnamed" otherwise
+ virtual wxString GetUserReadableName() const;
+
+#if WXWIN_COMPATIBILITY_2_8
+ // use GetUserReadableName() instead
+ wxDEPRECATED_BUT_USED_INTERNALLY(
+ virtual bool GetPrintableName(wxString& buf) const
+ );
+#endif // WXWIN_COMPATIBILITY_2_8
+
+ // Returns a window that can be used as a parent for document-related
+ // dialogs. Override if necessary.
+ virtual wxWindow *GetDocumentWindow() const;
+
+protected:
+ wxList m_documentViews;
+ wxString m_documentFile;
+ wxString m_documentTitle;
+ wxString m_documentTypeName;
+ wxDocTemplate* m_documentTemplate;
+ bool m_documentModified;
+ wxDocument* m_documentParent;
+ wxCommandProcessor* m_commandProcessor;
+ bool m_savedYet;
+
+ // Called by OnSaveDocument and OnOpenDocument to implement standard
+ // Save/Load behavior. Re-implement in derived class for custom
+ // behavior.
+ virtual bool DoSaveDocument(const wxString& file);
+ virtual bool DoOpenDocument(const wxString& file);
+
+ // the default implementation of GetUserReadableName()
+ wxString DoGetUserReadableName() const;
+
+private:
+ DECLARE_ABSTRACT_CLASS(wxDocument)
+ wxDECLARE_NO_COPY_CLASS(wxDocument);