X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/73bde1ef2536d63b2e42223a27cc0922b59e2dbb..da00cef2d8497aff5bd5d84bed7983575fce71f0:/include/wx/docview.h?ds=sidebyside diff --git a/include/wx/docview.h b/include/wx/docview.h index 0ff527c403..c9109ce65b 100644 --- a/include/wx/docview.h +++ b/include/wx/docview.h @@ -133,7 +133,7 @@ public: virtual bool Draw(wxDC&); virtual bool IsModified() const { return m_documentModified; } - virtual void Modify(bool mod) { m_documentModified = mod; } + virtual void Modify(bool mod); virtual bool AddView(wxView *view); virtual bool RemoveView(wxView *view); @@ -248,10 +248,7 @@ public: // set the associated frame, it is used to reset its view when we're // destroyed - void SetDocChildFrame(wxDocChildFrameAnyBase *docChildFrame) - { - m_docChildFrame = docChildFrame; - } + void SetDocChildFrame(wxDocChildFrameAnyBase *docChildFrame); protected: // hook the document into event handlers chain here @@ -523,13 +520,44 @@ inline size_t wxDocManager::GetNoHistoryFiles() const class WXDLLIMPEXP_CORE wxDocChildFrameAnyBase { public: - wxDocChildFrameAnyBase(wxDocument *doc, wxView *view) + // default ctor, use Create() after it + wxDocChildFrameAnyBase() + { + m_childDocument = NULL; + m_childView = NULL; + m_win = NULL; + } + + // full ctor equivalent to using the default one and Create(0 + wxDocChildFrameAnyBase(wxDocument *doc, wxView *view, wxWindow *win) + { + Create(doc, view, win); + } + + // method which must be called for an object created using the default ctor + // + // note that it returns bool just for consistency with Create() methods in + // other classes, we never return false from here + bool Create(wxDocument *doc, wxView *view, wxWindow *win) { m_childDocument = doc; m_childView = view; + m_win = win; if ( view ) view->SetDocChildFrame(this); + + return true; + } + + // dtor doesn't need to be virtual, an object should never be destroyed via + // a pointer to this class + ~wxDocChildFrameAnyBase() + { + // prevent the view from deleting us if we're being deleted directly + // (and not via Close() + Destroy()) + if ( m_childView ) + m_childView->SetDocChildFrame(NULL); } wxDocument *GetDocument() const { return m_childDocument; } @@ -537,6 +565,8 @@ public: void SetDocument(wxDocument *doc) { m_childDocument = doc; } void SetView(wxView *view) { m_childView = view; } + wxWindow *GetWindow() const { return m_win; } + protected: // we're not a wxEvtHandler but we provide this wxEvtHandler-like function // which is called from TryBefore() of the derived classes to give our view @@ -554,6 +584,11 @@ protected: wxDocument* m_childDocument; wxView* m_childView; + // the associated window: having it here is not terribly elegant but it + // allows us to avoid having any virtual functions in this class + wxWindow* m_win; + + wxDECLARE_NO_COPY_CLASS(wxDocChildFrameAnyBase); }; @@ -574,6 +609,9 @@ class WXDLLIMPEXP_CORE wxDocChildFrameAny : public ChildFrame, public: typedef ChildFrame BaseClass; + // default ctor, use Create after it + wxDocChildFrameAny() { } + // ctor for a frame showing the given view of the specified document wxDocChildFrameAny(wxDocument *doc, wxView *view, @@ -584,16 +622,32 @@ public: const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE, const wxString& name = wxFrameNameStr) - : BaseClass(parent, id, title, pos, size, style, name), - wxDocChildFrameAnyBase(doc, view) { - if ( view ) - view->SetFrame(this); + Create(doc, view, parent, id, title, pos, size, style, name); + } + + bool Create(wxDocument *doc, + wxView *view, + ParentFrame *parent, + wxWindowID id, + const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE, + const wxString& name = wxFrameNameStr) + { + if ( !wxDocChildFrameAnyBase::Create(doc, view, this) ) + return false; + + if ( !BaseClass::Create(parent, id, title, pos, size, style, name) ) + return false; this->Connect(wxEVT_ACTIVATE, wxActivateEventHandler(wxDocChildFrameAny::OnActivate)); this->Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(wxDocChildFrameAny::OnCloseWindow)); + + return true; } virtual bool Destroy() @@ -641,6 +695,7 @@ private: // for dll-interface class 'wxDocChildFrame'" -- this is bogus as the // template will be DLL-exported but only once it is used as base class // here! + #pragma warning (push) #pragma warning (disable:4275) #endif @@ -649,6 +704,10 @@ typedef wxDocChildFrameAny wxDocChildFrameBase; class WXDLLIMPEXP_CORE wxDocChildFrame : public wxDocChildFrameBase { public: + wxDocChildFrame() + { + } + wxDocChildFrame(wxDocument *doc, wxView *view, wxFrame *parent, @@ -663,13 +722,30 @@ public: { } + bool Create(wxDocument *doc, + wxView *view, + wxFrame *parent, + wxWindowID id, + const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE, + const wxString& name = wxFrameNameStr) + { + return wxDocChildFrameBase::Create + ( + doc, view, + parent, id, title, pos, size, style, name + ); + } + private: DECLARE_CLASS(wxDocChildFrame) wxDECLARE_NO_COPY_CLASS(wxDocChildFrame); }; #ifdef __VISUALC6__ - #pragma warning (default:4275) + #pragma warning (pop) #endif // ----------------------------------------------------------------------------