general docview.cpp code cleanup; use wxVector<> instead of manually-allocated arrays; refactor wxDocManager::CreateDocument() and allow using wxDOC_SILENT with wxDOC_NEW; cleanup wxFileHistory code
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54965 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -40,14 +40,11 @@ class WXDLLIMPEXP_FWD_BASE wxConfigBase;
|
|||||||
#include "wx/stream.h"
|
#include "wx/stream.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Document manager flags
|
// Flags for wxDocManager (can be combined).
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
wxDOC_SDI = 1,
|
wxDOC_NEW = 1,
|
||||||
wxDOC_MDI,
|
wxDOC_SILENT = 2
|
||||||
wxDOC_NEW,
|
|
||||||
wxDOC_SILENT,
|
|
||||||
wxDEFAULT_DOCMAN_FLAGS = wxDOC_SDI
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Document template flags
|
// Document template flags
|
||||||
@@ -63,7 +60,7 @@ enum
|
|||||||
class WXDLLIMPEXP_CORE wxDocument : public wxEvtHandler
|
class WXDLLIMPEXP_CORE wxDocument : public wxEvtHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxDocument(wxDocument *parent = (wxDocument *) NULL);
|
wxDocument(wxDocument *parent = NULL);
|
||||||
virtual ~wxDocument();
|
virtual ~wxDocument();
|
||||||
|
|
||||||
// accessors
|
// accessors
|
||||||
@@ -129,7 +126,7 @@ public:
|
|||||||
const wxList& GetViews() const { return m_documentViews; }
|
const wxList& GetViews() const { return m_documentViews; }
|
||||||
wxView *GetFirstView() const;
|
wxView *GetFirstView() const;
|
||||||
|
|
||||||
virtual void UpdateAllViews(wxView *sender = (wxView *) NULL, wxObject *hint = (wxObject *) NULL);
|
virtual void UpdateAllViews(wxView *sender = NULL, wxObject *hint = NULL);
|
||||||
virtual void NotifyClosing();
|
virtual void NotifyClosing();
|
||||||
|
|
||||||
// Remove all views (because we're closing the document)
|
// Remove all views (because we're closing the document)
|
||||||
@@ -184,7 +181,6 @@ private:
|
|||||||
class WXDLLIMPEXP_CORE wxView: public wxEvtHandler
|
class WXDLLIMPEXP_CORE wxView: public wxEvtHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// wxView(wxDocument *doc = (wxDocument *) NULL);
|
|
||||||
wxView();
|
wxView();
|
||||||
virtual ~wxView();
|
virtual ~wxView();
|
||||||
|
|
||||||
@@ -200,13 +196,14 @@ public:
|
|||||||
virtual void OnActivateView(bool activate, wxView *activeView, wxView *deactiveView);
|
virtual void OnActivateView(bool activate, wxView *activeView, wxView *deactiveView);
|
||||||
virtual void OnDraw(wxDC *dc) = 0;
|
virtual void OnDraw(wxDC *dc) = 0;
|
||||||
virtual void OnPrint(wxDC *dc, wxObject *info);
|
virtual void OnPrint(wxDC *dc, wxObject *info);
|
||||||
virtual void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
|
virtual void OnUpdate(wxView *sender, wxObject *hint = NULL);
|
||||||
virtual void OnClosingDocument() {}
|
virtual void OnClosingDocument() {}
|
||||||
virtual void OnChangeFilename();
|
virtual void OnChangeFilename();
|
||||||
|
|
||||||
// Called by framework if created automatically by the default document
|
// Called by framework if created automatically by the default document
|
||||||
// manager class: gives view a chance to initialise
|
// manager class: gives view a chance to initialise
|
||||||
virtual bool OnCreate(wxDocument *WXUNUSED(doc), long WXUNUSED(flags)) { return true; }
|
virtual bool OnCreate(wxDocument *WXUNUSED(doc), long WXUNUSED(flags))
|
||||||
|
{ return true; }
|
||||||
|
|
||||||
// Checks if the view is the last one for the document; if so, asks user
|
// Checks if the view is the last one for the document; if so, asks user
|
||||||
// to confirm save data (if modified). If ok, deletes itself and returns
|
// to confirm save data (if modified). If ok, deletes itself and returns
|
||||||
@@ -256,8 +253,8 @@ public:
|
|||||||
const wxString& ext,
|
const wxString& ext,
|
||||||
const wxString& docTypeName,
|
const wxString& docTypeName,
|
||||||
const wxString& viewTypeName,
|
const wxString& viewTypeName,
|
||||||
wxClassInfo *docClassInfo = (wxClassInfo *) NULL,
|
wxClassInfo *docClassInfo = NULL,
|
||||||
wxClassInfo *viewClassInfo = (wxClassInfo *)NULL,
|
wxClassInfo *viewClassInfo = NULL,
|
||||||
long flags = wxDEFAULT_TEMPLATE_FLAGS);
|
long flags = wxDEFAULT_TEMPLATE_FLAGS);
|
||||||
|
|
||||||
virtual ~wxDocTemplate();
|
virtual ~wxDocTemplate();
|
||||||
@@ -325,7 +322,8 @@ private:
|
|||||||
class WXDLLIMPEXP_CORE wxDocManager: public wxEvtHandler
|
class WXDLLIMPEXP_CORE wxDocManager: public wxEvtHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxDocManager(long flags = wxDEFAULT_DOCMAN_FLAGS, bool initialize = true);
|
// NB: flags are unused, don't pass wxDOC_XXX to this ctor
|
||||||
|
wxDocManager(long flags = 0, bool initialize = true);
|
||||||
virtual ~wxDocManager();
|
virtual ~wxDocManager();
|
||||||
|
|
||||||
virtual bool Initialize();
|
virtual bool Initialize();
|
||||||
@@ -345,17 +343,12 @@ public:
|
|||||||
|
|
||||||
// Handlers for UI update commands
|
// Handlers for UI update commands
|
||||||
void OnUpdateFileOpen(wxUpdateUIEvent& event);
|
void OnUpdateFileOpen(wxUpdateUIEvent& event);
|
||||||
void OnUpdateFileClose(wxUpdateUIEvent& event);
|
void OnUpdateDisableIfNoDoc(wxUpdateUIEvent& event);
|
||||||
void OnUpdateFileRevert(wxUpdateUIEvent& event);
|
|
||||||
void OnUpdateFileNew(wxUpdateUIEvent& event);
|
void OnUpdateFileNew(wxUpdateUIEvent& event);
|
||||||
void OnUpdateFileSave(wxUpdateUIEvent& event);
|
void OnUpdateFileSave(wxUpdateUIEvent& event);
|
||||||
void OnUpdateFileSaveAs(wxUpdateUIEvent& event);
|
|
||||||
void OnUpdateUndo(wxUpdateUIEvent& event);
|
void OnUpdateUndo(wxUpdateUIEvent& event);
|
||||||
void OnUpdateRedo(wxUpdateUIEvent& event);
|
void OnUpdateRedo(wxUpdateUIEvent& event);
|
||||||
|
|
||||||
void OnUpdatePrint(wxUpdateUIEvent& event);
|
|
||||||
void OnUpdatePreview(wxUpdateUIEvent& event);
|
|
||||||
|
|
||||||
// Extend event processing to search the view's event table
|
// Extend event processing to search the view's event table
|
||||||
virtual bool ProcessEvent(wxEvent& event);
|
virtual bool ProcessEvent(wxEvent& event);
|
||||||
|
|
||||||
@@ -449,7 +442,6 @@ public:
|
|||||||
#endif // WXWIN_COMPATIBILITY_2_6
|
#endif // WXWIN_COMPATIBILITY_2_6
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
long m_flags;
|
|
||||||
int m_defaultDocumentNameCounter;
|
int m_defaultDocumentNameCounter;
|
||||||
int m_maxDocsOpen;
|
int m_maxDocsOpen;
|
||||||
wxList m_docs;
|
wxList m_docs;
|
||||||
@@ -499,7 +491,7 @@ public:
|
|||||||
wxView *GetView() const { return m_childView; }
|
wxView *GetView() const { return m_childView; }
|
||||||
void SetDocument(wxDocument *doc) { m_childDocument = doc; }
|
void SetDocument(wxDocument *doc) { m_childDocument = doc; }
|
||||||
void SetView(wxView *view) { m_childView = view; }
|
void SetView(wxView *view) { m_childView = view; }
|
||||||
bool Destroy() { m_childView = (wxView *)NULL; return wxFrame::Destroy(); }
|
bool Destroy() { m_childView = NULL; return wxFrame::Destroy(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wxDocument* m_childDocument;
|
wxDocument* m_childDocument;
|
||||||
@@ -564,7 +556,7 @@ private:
|
|||||||
class WXDLLIMPEXP_CORE wxDocPrintout : public wxPrintout
|
class WXDLLIMPEXP_CORE wxDocPrintout : public wxPrintout
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxDocPrintout(wxView *view = (wxView *) NULL, const wxString& title = wxT("Printout"));
|
wxDocPrintout(wxView *view = NULL, const wxString& title = wxT("Printout"));
|
||||||
bool OnPrintPage(int page);
|
bool OnPrintPage(int page);
|
||||||
bool HasPage(int page);
|
bool HasPage(int page);
|
||||||
bool OnBeginDocument(int startPage, int endPage);
|
bool OnBeginDocument(int startPage, int endPage);
|
||||||
@@ -589,7 +581,6 @@ class WXDLLIMPEXP_CORE wxFileHistory : public wxObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxFileHistory(size_t maxFiles = 9, wxWindowID idBase = wxID_FILE1);
|
wxFileHistory(size_t maxFiles = 9, wxWindowID idBase = wxID_FILE1);
|
||||||
virtual ~wxFileHistory();
|
|
||||||
|
|
||||||
// Operations
|
// Operations
|
||||||
virtual void AddFileToHistory(const wxString& file);
|
virtual void AddFileToHistory(const wxString& file);
|
||||||
@@ -660,6 +651,18 @@ bool WXDLLIMPEXP_CORE wxTransferFileToStream(const wxString& filename, wxOutputS
|
|||||||
bool WXDLLIMPEXP_CORE wxTransferStreamToFile(wxInputStream& stream, const wxString& filename);
|
bool WXDLLIMPEXP_CORE wxTransferStreamToFile(wxInputStream& stream, const wxString& filename);
|
||||||
#endif // wxUSE_STD_IOSTREAM
|
#endif // wxUSE_STD_IOSTREAM
|
||||||
|
|
||||||
|
|
||||||
|
// these flags are not used anywhere by wxWidgets and kept only for an unlikely
|
||||||
|
// case of existing user code using them for its own purposes
|
||||||
|
#ifdef WXWIN_COMPATIBILITY_2_8
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
wxDOC_SDI = 1,
|
||||||
|
wxDOC_MDI,
|
||||||
|
wxDEFAULT_DOCMAN_FLAGS = wxDOC_SDI
|
||||||
|
};
|
||||||
|
#endif // WXWIN_COMPATIBILITY_2_8
|
||||||
|
|
||||||
#endif // wxUSE_DOC_VIEW_ARCHITECTURE
|
#endif // wxUSE_DOC_VIEW_ARCHITECTURE
|
||||||
|
|
||||||
#endif // _WX_DOCH__
|
#endif // _WX_DOCH__
|
||||||
|
@@ -258,16 +258,18 @@ public:
|
|||||||
Constructor. Create a document manager instance dynamically near the
|
Constructor. Create a document manager instance dynamically near the
|
||||||
start of your application before doing any document or view operations.
|
start of your application before doing any document or view operations.
|
||||||
|
|
||||||
@a flags is currently unused.
|
|
||||||
|
|
||||||
If @a initialize is @true, the Initialize() function will be called to
|
If @a initialize is @true, the Initialize() function will be called to
|
||||||
create a default history list object. If you derive from wxDocManager,
|
create a default history list object. If you derive from wxDocManager,
|
||||||
you may wish to call the base constructor with @false, and then call
|
you may wish to call the base constructor with @false, and then call
|
||||||
Initialize() in your own constructor, to allow your own Initialize() or
|
Initialize() in your own constructor, to allow your own Initialize() or
|
||||||
OnCreateFileHistory functions to be called.
|
OnCreateFileHistory functions to be called.
|
||||||
|
|
||||||
|
@param flags
|
||||||
|
Currently unused.
|
||||||
|
@param initialize
|
||||||
|
Indicates whether Initialize() should be called by this ctor.
|
||||||
*/
|
*/
|
||||||
wxDocManager(long flags = wxDEFAULT_DOCMAN_FLAGS,
|
wxDocManager(long flags = 0, bool initialize = true);
|
||||||
bool initialize = true);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Destructor.
|
Destructor.
|
||||||
@@ -301,25 +303,42 @@ public:
|
|||||||
bool CloseDocuments(bool force = true);
|
bool CloseDocuments(bool force = true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates a new document in a manner determined by the @a flags
|
Creates a new document.
|
||||||
parameter, which can be:
|
|
||||||
|
|
||||||
- wxDOC_NEW - Creates a fresh document.
|
This function can either create a document corresponding to a new
|
||||||
- wxDOC_SILENT - Silently loads the given document file.
|
file or to an already existing one depending on whether @c wxDOC_NEW is
|
||||||
|
specified in the @a flags.
|
||||||
|
|
||||||
If wxDOC_NEW is present, a new document will be created and returned,
|
By default, this function asks the user for the type of document to
|
||||||
possibly after asking the user for a template to use if there is more
|
open and the path to its file if it's not specified, i.e. if @a path is
|
||||||
than one document template. If wxDOC_SILENT is present, a new document
|
empty. Specifying @c wxDOC_SILENT flag suppresses any prompts and means
|
||||||
will be created and the given file loaded into it. If neither of these
|
that the @a path must be non-empty and there must be a registered
|
||||||
flags is present, the user will be presented with a file selector for
|
document template handling the extension of this file, otherwise a
|
||||||
the file to load, and the template to use will be determined by the
|
warning message is logged and the function returns @NULL. Notice that
|
||||||
extension (Windows) or by popping up a template choice list (other
|
@c wxDOC_SILENT can be combined with @c wxDOC_NEW, however in this case
|
||||||
platforms).
|
the @a path must still be specified, even if the file with this path
|
||||||
|
typically won't exist.
|
||||||
|
|
||||||
If the maximum number of documents has been reached, this function will
|
Finally notice that if this document manager was configured to allow
|
||||||
delete the oldest currently loaded document before creating a new one.
|
only a limited number of simultaneously opened documents using
|
||||||
|
SetMaxDocsOpen(), this function will try to close the oldest existing
|
||||||
|
document if this number was reached before creating a new document.
|
||||||
|
And if closing the old document fails (e.g. because it was vetoed by
|
||||||
|
user), this function fails as well.
|
||||||
|
|
||||||
|
@param path
|
||||||
|
Path to a file or an empty string. If the path is empty, the user
|
||||||
|
will be asked to select it (thus, this is incompatible with the use
|
||||||
|
of @c wxDOC_SILENT). The file should exist unless @a flags includes
|
||||||
|
@c wxDOC_NEW.
|
||||||
|
@param flags
|
||||||
|
By default, none. May include @c wxDOC_NEW to indicate that the new
|
||||||
|
document corresponds to a new file and not an existing one and
|
||||||
|
@c wxDOC_SILENT to suppress any dialogs asking the user about the
|
||||||
|
file path and type.
|
||||||
|
@return a new document object or @NULL on failure.
|
||||||
*/
|
*/
|
||||||
wxDocument* CreateDocument(const wxString& path, long flags);
|
wxDocument *CreateDocument(const wxString& path, long flags = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates a new view for the given document. If more than one view is
|
Creates a new view for the given document. If more than one view is
|
||||||
@@ -559,11 +578,12 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Sets the maximum number of documents that can be open at a time. By
|
Sets the maximum number of documents that can be open at a time. By
|
||||||
default, this is 10,000. If you set it to 1, existing documents will be
|
default, this is @c INT_MAX, i.e. the number of documents is unlimited.
|
||||||
saved and deleted when the user tries to open or create a new one
|
If you set it to 1, existing documents will be saved and deleted when
|
||||||
(similar to the behaviour of Windows Write, for example). Allowing
|
the user tries to open or create a new one (similar to the behaviour of
|
||||||
multiple documents gives behaviour more akin to MS Word and other
|
Windows Write, for example). Allowing multiple documents gives
|
||||||
Multiple Document Interface applications.
|
behaviour more akin to MS Word and other Multiple Document Interface
|
||||||
|
applications.
|
||||||
*/
|
*/
|
||||||
void SetMaxDocsOpen(int n);
|
void SetMaxDocsOpen(int n);
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user