+ // 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);
+};
+
+// ----------------------------------------------------------------------------
+// Template implementing child frame concept using the given wxFrame-like class
+//
+// This is used to define wxDocChildFrame and wxDocMDIChildFrame: ChildFrame is
+// a wxFrame or wxMDIChildFrame (although in theory it could be any wxWindow-
+// derived class as long as it provided a ctor with the same signature as
+// wxFrame and OnActivate() method) and ParentFrame is either wxFrame or
+// wxMDIParentFrame.
+// ----------------------------------------------------------------------------
+
+template <class ChildFrame, class ParentFrame>
+class WXDLLIMPEXP_CORE wxDocChildFrameAny : public ChildFrame,
+ public wxDocChildFrameAnyBase
+{
+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,
+ ParentFrame *parent,
+ wxWindowID id,
+ const wxString& title,
+ const wxPoint& pos = wxDefaultPosition,
+ const wxSize& size = wxDefaultSize,
+ long style = wxDEFAULT_FRAME_STYLE,
+ const wxString& name = wxFrameNameStr)
+ {
+ 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()
+ {
+ // FIXME: why exactly do we do this? to avoid activation events during
+ // destructions maybe?
+ m_childView = NULL;
+ return BaseClass::Destroy();
+ }
+
+protected:
+ // hook the child view into event handlers chain here
+ virtual bool TryBefore(wxEvent& event)
+ {
+ return TryProcessEvent(event) || BaseClass::TryBefore(event);
+ }
+
+private:
+ void OnActivate(wxActivateEvent& event)
+ {
+ BaseClass::OnActivate(event);
+
+ if ( m_childView )
+ m_childView->Activate(event.GetActive());
+ }
+
+ void OnCloseWindow(wxCloseEvent& event)
+ {
+ if ( CloseView(event) )
+ Destroy();
+ //else: vetoed
+ }
+
+ wxDECLARE_NO_COPY_TEMPLATE_CLASS_2(wxDocChildFrameAny,
+ ChildFrame, ParentFrame);
+};
+
+// ----------------------------------------------------------------------------
+// A default child frame: we need to define it as a class just for wxRTTI,
+// otherwise we could simply typedef it
+// ----------------------------------------------------------------------------
+
+#ifdef __VISUALC6__
+ // "non dll-interface class 'wxDocChildFrameAny<>' used as base interface
+ // 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
+
+typedef wxDocChildFrameAny<wxFrame, wxFrame> wxDocChildFrameBase;
+
+class WXDLLIMPEXP_CORE wxDocChildFrame : public wxDocChildFrameBase
+{
+public:
+ wxDocChildFrame()
+ {
+ }
+
+ wxDocChildFrame(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)
+ : wxDocChildFrameBase(doc, view,
+ parent, id, title, pos, size, style, name)
+ {
+ }
+
+ 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
+ );
+ }
+