Refactor wxDocParentFrame and wxDocMDIParentFrame to share common base class.

Use the same approach as for the child frames: add a base template class which
allows wxDocParentFrame to inherit from wxFrame and wxDocMDIParentFrame from
wxMDIParentFrame while still allowing to reuse the common code.

This reduces code duplication and should make implementing parent AUI document
frame easier as well, see #8945.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64295 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-05-12 14:34:18 +00:00
parent 8329f1d1d6
commit c48bdb0c28
4 changed files with 176 additions and 199 deletions

View File

@@ -1,11 +1,11 @@
/////////////////////////////////////////////////////////////////////////////
// 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
/////////////////////////////////////////////////////////////////////////////
@@ -20,73 +20,7 @@
#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