/////////////////////////////////////////////////////////////////////////////
-// Name: docmdi.h
+// Name: wx/docmdi.h
// Purpose: Frame classes for MDI document/view applications
// Author: Julian Smart
-// Modified by:
// Created: 01/02/97
// RCS-ID: $Id$
-// Copyright: (c) Julian Smart
+// Copyright: (c) 1997 Julian Smart
+// (c) 2010 Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/docview.h"
#include "wx/mdi.h"
-/*
- * Use this instead of wxMDIParentFrame
- */
-
-class WXDLLIMPEXP_CORE wxDocMDIParentFrame: public wxMDIParentFrame
-{
-public:
- wxDocMDIParentFrame();
- wxDocMDIParentFrame(wxDocManager *manager, wxFrame *parent, wxWindowID id,
- const wxString& title, const wxPoint& pos = wxDefaultPosition,
- const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE, const wxString& name = wxFrameNameStr);
-
- bool Create(wxDocManager *manager, wxFrame *parent, wxWindowID id,
- const wxString& title, const wxPoint& pos = wxDefaultPosition,
- const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE, const wxString& name = wxFrameNameStr);
-
- wxDocManager *GetDocumentManager(void) const { return m_docManager; }
+#ifdef __VISUALC6__
+ // "non dll-interface class 'wxDocXXXFrameAny<>' used as base interface for
+ // dll-interface class 'wxDocMDIXXXFrame'" -- 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
- void OnExit(wxCommandEvent& event);
- void OnMRUFile(wxCommandEvent& event);
- void OnCloseWindow(wxCloseEvent& event);
+// Define MDI versions of the doc-view frame classes. Note that we need to
+// define them as classes for wxRTTI, otherwise we could simply define them as
+// typedefs.
-protected:
- void Init();
+// ----------------------------------------------------------------------------
+// An MDI document parent frame
+// ----------------------------------------------------------------------------
- virtual bool TryBefore(wxEvent& event);
+typedef
+ wxDocParentFrameAny<wxMDIParentFrame> wxDocMDIParentFrameBase;
- wxDocManager *m_docManager;
+class WXDLLIMPEXP_CORE wxDocMDIParentFrame : public wxDocMDIParentFrameBase
+{
+public:
+ wxDocMDIParentFrame() : wxDocMDIParentFrameBase() { }
+
+ wxDocMDIParentFrame(wxDocManager *manager,
+ wxFrame *parent,
+ wxWindowID id,
+ const wxString& title,
+ const wxPoint& pos = wxDefaultPosition,
+ const wxSize& size = wxDefaultSize,
+ long style = wxDEFAULT_FRAME_STYLE,
+ const wxString& name = wxFrameNameStr)
+ : wxDocMDIParentFrameBase(manager,
+ parent, id, title, pos, size, style, name)
+ {
+ }
private:
DECLARE_CLASS(wxDocMDIParentFrame)
- DECLARE_EVENT_TABLE()
wxDECLARE_NO_COPY_CLASS(wxDocMDIParentFrame);
};
// ----------------------------------------------------------------------------
-// An MDI document child frame: we need to define it as a class just for wxRTTI,
-// otherwise we could simply typedef it
+// An MDI document child frame
// ----------------------------------------------------------------------------
-#ifdef __VISUALC6__
- // "non dll-interface class 'wxDocChildFrameAny<>' used as base interface
- // for dll-interface class 'wxDocMDIChildFrame'" -- 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<wxMDIChildFrame, wxMDIParentFrame> wxDocMDIChildFrameBase;
class WXDLLIMPEXP_CORE wxDocMDIChildFrame : public wxDocMDIChildFrameBase
{
public:
+ wxDocMDIChildFrame() { }
+
wxDocMDIChildFrame(wxDocument *doc,
wxView *view,
wxMDIParentFrame *parent,
wxDECLARE_NO_COPY_CLASS(wxDocChildFrame);
};
-#ifdef __VISUALC6__
- #pragma warning (pop)
-#endif
-
// ----------------------------------------------------------------------------
-// A default parent frame
+// wxDocParentFrame and related classes.
+//
+// As with wxDocChildFrame we define a template base class used by both normal
+// and MDI versions
// ----------------------------------------------------------------------------
-class WXDLLIMPEXP_CORE wxDocParentFrame : public wxFrame
+// Base class containing type-independent code of wxDocParentFrameAny
+//
+// Similarly to wxDocChildFrameAnyBase, this class is a mix-in and doesn't
+// derive from wxWindow.
+class WXDLLIMPEXP_CORE wxDocParentFrameAnyBase
{
public:
- wxDocParentFrame();
- wxDocParentFrame(wxDocManager *manager,
- wxFrame *frame,
- wxWindowID id,
- const wxString& title,
- const wxPoint& pos = wxDefaultPosition,
- const wxSize& size = wxDefaultSize,
- long style = wxDEFAULT_FRAME_STYLE,
- const wxString& name = wxFrameNameStr);
+ wxDocParentFrameAnyBase() { m_docManager = NULL; }
+
+ wxDocManager *GetDocumentManager() const { return m_docManager; }
+
+protected:
+ // Open the MRU file with the given index in our associated file history.
+ //
+ // This is called from the derived class event handler for the MRU menu
+ // items.
+ void DoOpenMRUFile(unsigned n);
+
+ wxDocManager *m_docManager;
+
+ wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAnyBase);
+};
+
+// This is similar to wxDocChildFrameAny and is used to provide common
+// implementation for both wxDocParentFrame and wxDocMDIParentFrame
+template <class BaseFrame>
+class WXDLLIMPEXP_CORE wxDocParentFrameAny : public BaseFrame,
+ public wxDocParentFrameAnyBase
+{
+public:
+ wxDocParentFrameAny() { }
+ wxDocParentFrameAny(wxDocManager *manager,
+ wxFrame *frame,
+ wxWindowID id,
+ const wxString& title,
+ const wxPoint& pos = wxDefaultPosition,
+ const wxSize& size = wxDefaultSize,
+ long style = wxDEFAULT_FRAME_STYLE,
+ const wxString& name = wxFrameNameStr)
+ {
+ Create(manager, frame, id, title, pos, size, style, name);
+ }
bool Create(wxDocManager *manager,
wxFrame *frame,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_FRAME_STYLE,
- const wxString& name = wxFrameNameStr);
+ const wxString& name = wxFrameNameStr)
+ {
+ m_docManager = manager;
- wxDocManager *GetDocumentManager() const { return m_docManager; }
+ if ( !BaseFrame::Create(frame, id, title, pos, size, style, name) )
+ return false;
+
+ this->Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED,
+ wxCommandEventHandler(wxDocParentFrameAny::OnExit));
+ this->Connect(wxID_FILE1, wxID_FILE9, wxEVT_COMMAND_MENU_SELECTED,
+ wxCommandEventHandler(wxDocParentFrameAny::OnMRUFile));
+ this->Connect(wxEVT_CLOSE_WINDOW,
+ wxCloseEventHandler(wxDocParentFrameAny::OnCloseWindow));
- void OnExit(wxCommandEvent& event);
- void OnMRUFile(wxCommandEvent& event);
- void OnCloseWindow(wxCloseEvent& event);
+ return true;
+ }
protected:
// hook the document manager into event handling chain here
- virtual bool TryBefore(wxEvent& event);
+ virtual bool TryBefore(wxEvent& event)
+ {
+ if ( m_docManager && m_docManager->ProcessEventLocally(event) )
+ return true;
- wxDocManager *m_docManager;
+ return BaseFrame::TryBefore(event);
+ }
+
+private:
+ void OnExit(wxCommandEvent& WXUNUSED(event))
+ {
+ this->Close();
+ }
+
+ void OnMRUFile(wxCommandEvent& event)
+ {
+ DoOpenMRUFile(event.GetId() - wxID_FILE1);
+ }
+
+ void OnCloseWindow(wxCloseEvent& event)
+ {
+ if ( m_docManager && !m_docManager->Clear(!event.CanVeto()) )
+ {
+ // The user decided not to close finally, abort.
+ event.Veto();
+ }
+ else
+ {
+ // Just skip the event, base class handler will destroy the window.
+ event.Skip();
+ }
+ }
+
+
+ wxDECLARE_NO_COPY_CLASS(wxDocParentFrameAny);
+};
+
+typedef wxDocParentFrameAny<wxFrame> wxDocParentFrameBase;
+
+class WXDLLIMPEXP_CORE wxDocParentFrame : public wxDocParentFrameBase
+{
+public:
+ wxDocParentFrame() : wxDocParentFrameBase() { }
+
+ wxDocParentFrame(wxDocManager *manager,
+ wxFrame *parent,
+ wxWindowID id,
+ const wxString& title,
+ const wxPoint& pos = wxDefaultPosition,
+ const wxSize& size = wxDefaultSize,
+ long style = wxDEFAULT_FRAME_STYLE,
+ const wxString& name = wxFrameNameStr)
+ : wxDocParentFrameBase(manager,
+ parent, id, title, pos, size, style, name)
+ {
+ }
+
+ bool Create(wxDocManager *manager,
+ 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 wxDocParentFrameBase::Create(manager,
+ parent, id, title,
+ pos, size, style, name);
+ }
private:
- typedef wxFrame base_type;
DECLARE_CLASS(wxDocParentFrame)
- DECLARE_EVENT_TABLE()
wxDECLARE_NO_COPY_CLASS(wxDocParentFrame);
};
+#ifdef __VISUALC6__
+ // reenable warning 4275
+ #pragma warning (pop)
+#endif
+
// ----------------------------------------------------------------------------
// Provide simple default printing facilities
// ----------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
-// Name: docmdi.cpp
+// Name: src/common/docmdi.cpp
// Purpose: Frame classes for MDI document/view applications
-// Author: Julian Smart
-// Modified by:
+// Author: Julian Smart, Vadim Zeitlin
// Created: 01/02/97
// RCS-ID: $Id$
-// Copyright: (c) Julian Smart
+// Copyright: (c) 1997 Julian Smart
+// (c) 2010 Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/docmdi.h"
-/*
- * Docview MDI parent frame
- */
-
IMPLEMENT_CLASS(wxDocMDIParentFrame, wxMDIParentFrame)
-
-BEGIN_EVENT_TABLE(wxDocMDIParentFrame, wxMDIParentFrame)
- EVT_MENU(wxID_EXIT, wxDocMDIParentFrame::OnExit)
- EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, wxDocMDIParentFrame::OnMRUFile)
- EVT_CLOSE(wxDocMDIParentFrame::OnCloseWindow)
-END_EVENT_TABLE()
-
-wxDocMDIParentFrame::wxDocMDIParentFrame()
-{
- Init();
-}
-
-wxDocMDIParentFrame::wxDocMDIParentFrame(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title,
- const wxPoint& pos, const wxSize& size, long style, const wxString& name)
-{
- Init();
- Create(manager, frame, id, title, pos, size, style, name);
-}
-
-bool wxDocMDIParentFrame::Create(wxDocManager *manager, wxFrame *frame, wxWindowID id, const wxString& title,
- const wxPoint& pos, const wxSize& size, long style, const wxString& name)
-{
- m_docManager = manager;
- return wxMDIParentFrame::Create(frame, id, title, pos, size, style, name);
-}
-
-void wxDocMDIParentFrame::OnExit(wxCommandEvent& WXUNUSED(event))
-{
- Close();
-}
-
-void wxDocMDIParentFrame::Init()
-{
- m_docManager = NULL;
-}
-
-void wxDocMDIParentFrame::OnMRUFile(wxCommandEvent& event)
-{
- wxString f(m_docManager->GetHistoryFile(event.GetId() - wxID_FILE1));
- if (!f.empty())
- (void)m_docManager->CreateDocument(f, wxDOC_SILENT);
-}
-
-bool wxDocMDIParentFrame::TryBefore(wxEvent& event)
-{
- if ( m_docManager && m_docManager->ProcessEventLocally(event) )
- return true;
-
- return wxMDIParentFrame::TryBefore(event);
-}
-
-void wxDocMDIParentFrame::OnCloseWindow(wxCloseEvent& event)
-{
- if (m_docManager->Clear(!event.CanVeto()))
- {
- this->Destroy();
- }
- else
- event.Veto();
-}
-
-
IMPLEMENT_CLASS(wxDocMDIChildFrame, wxMDIChildFrame)
#endif // wxUSE_DOC_VIEW_ARCHITECTURE
}
// ----------------------------------------------------------------------------
-// Default parent frame
+// wxDocParentFrameAnyBase
// ----------------------------------------------------------------------------
-BEGIN_EVENT_TABLE(wxDocParentFrame, wxFrame)
- EVT_MENU(wxID_EXIT, wxDocParentFrame::OnExit)
- EVT_MENU_RANGE(wxID_FILE1, wxID_FILE9, wxDocParentFrame::OnMRUFile)
- EVT_CLOSE(wxDocParentFrame::OnCloseWindow)
-END_EVENT_TABLE()
-
-wxDocParentFrame::wxDocParentFrame()
+void wxDocParentFrameAnyBase::DoOpenMRUFile(unsigned n)
{
- m_docManager = NULL;
-}
-
-wxDocParentFrame::wxDocParentFrame(wxDocManager *manager,
- wxFrame *frame,
- wxWindowID id,
- const wxString& title,
- const wxPoint& pos,
- const wxSize& size,
- long style,
- const wxString& name)
- : wxFrame(frame, id, title, pos, size, style, name)
-{
- m_docManager = manager;
-}
-
-bool wxDocParentFrame::Create(wxDocManager *manager,
- wxFrame *frame,
- wxWindowID id,
- const wxString& title,
- const wxPoint& pos,
- const wxSize& size,
- long style,
- const wxString& name)
-{
- m_docManager = manager;
- return base_type::Create(frame, id, title, pos, size, style, name);
-}
-
-void wxDocParentFrame::OnExit(wxCommandEvent& WXUNUSED(event))
-{
- Close();
-}
-
-void wxDocParentFrame::OnMRUFile(wxCommandEvent& event)
-{
- int n = event.GetId() - wxID_FILE1; // the index in MRU list
wxString filename(m_docManager->GetHistoryFile(n));
if ( filename.empty() )
return;
filename);
}
-// Extend event processing to search the view's event table
-bool wxDocParentFrame::TryBefore(wxEvent& event)
-{
- if ( m_docManager && m_docManager->ProcessEventLocally(event) )
- return true;
-
- return wxFrame::TryBefore(event);
-}
-
-// Define the behaviour for the frame closing
-// - must delete all frames except for the main one.
-void wxDocParentFrame::OnCloseWindow(wxCloseEvent& event)
-{
- if (m_docManager->Clear(!event.CanVeto()))
- {
- Destroy();
- }
- else
- event.Veto();
-}
-
#if wxUSE_PRINTING_ARCHITECTURE
wxDocPrintout::wxDocPrintout(wxView *view, const wxString& title)