Allow using AUI-based MDI classes in the docview sample

For testing, allow using wxAuiMDI{Parent,Child}Frame in the sample.

This change also shows that the AUI classes are now sufficiently
compatible with the standard ones for switching to them to be almost
trivial.
This commit is contained in:
Vadim Zeitlin
2018-05-13 00:11:41 +02:00
parent 6cdd564237
commit c756d18bc4
11 changed files with 143 additions and 66 deletions

View File

@@ -49,6 +49,10 @@
#include "wx/docview.h"
#include "wx/docmdi.h"
#if wxUSE_AUI
#include "wx/aui/tabmdi.h"
#endif // wxUSE_AUI
#include "docview.h"
#include "doc.h"
#include "view.h"
@@ -95,6 +99,9 @@ namespace CmdLineOption
#if wxUSE_MDI_ARCHITECTURE
const char * const MDI = "mdi";
#endif // wxUSE_MDI_ARCHITECTURE
#if wxUSE_AUI
const char * const AUI = "aui";
#endif // wxUSE_AUI
const char * const SDI = "sdi";
const char * const SINGLE = "single";
@@ -108,6 +115,10 @@ void MyApp::OnInitCmdLine(wxCmdLineParser& parser)
parser.AddSwitch("", CmdLineOption::MDI,
"run in MDI mode: multiple documents, single window");
#endif // wxUSE_MDI_ARCHITECTURE
#if wxUSE_AUI
parser.AddSwitch("", CmdLineOption::AUI,
"run in MDI mode using AUI: multiple documents, single window");
#endif // wxUSE_AUI
parser.AddSwitch("", CmdLineOption::SDI,
"run in SDI mode: multiple documents, multiple windows");
parser.AddSwitch("", CmdLineOption::SINGLE,
@@ -130,6 +141,14 @@ bool MyApp::OnCmdLineParsed(wxCmdLineParser& parser)
}
#endif // wxUSE_MDI_ARCHITECTURE
#if wxUSE_AUI
if ( parser.Found(CmdLineOption::AUI) )
{
m_mode = Mode_AUI;
numModeOptions++;
}
#endif // wxUSE_AUI
if ( parser.Found(CmdLineOption::SDI) )
{
m_mode = Mode_SDI;
@@ -202,22 +221,37 @@ bool MyApp::OnInit()
}
// create the main frame window
wxFrame *frame;
wxFrame *frame = NULL;
switch ( m_mode )
{
#if wxUSE_MDI_ARCHITECTURE
if ( m_mode == Mode_MDI )
{
frame = new wxDocMDIParentFrame(docManager, NULL, wxID_ANY,
GetAppDisplayName(),
wxDefaultPosition,
wxSize(500, 400));
}
else
case Mode_MDI:
frame = new wxDocMDIParentFrame(docManager, NULL, wxID_ANY,
GetAppDisplayName(),
wxDefaultPosition,
wxSize(500, 400));
break;
#endif // wxUSE_MDI_ARCHITECTURE
{
frame = new wxDocParentFrame(docManager, NULL, wxID_ANY,
GetAppDisplayName(),
wxDefaultPosition,
wxSize(500, 400));
#if wxUSE_AUI
case Mode_AUI:
frame = new wxDocParentFrameAny<wxAuiMDIParentFrame>
(
docManager, NULL, wxID_ANY,
GetAppDisplayName(),
wxDefaultPosition,
wxSize(500, 400)
);
break;
#endif // wxUSE_AUI
case Mode_SDI:
case Mode_Single:
frame = new wxDocParentFrame(docManager, NULL, wxID_ANY,
GetAppDisplayName(),
wxDefaultPosition,
wxSize(500, 400));
break;
}
// and its menu bar
@@ -321,37 +355,55 @@ void MyApp::CreateMenuBarForFrame(wxFrame *frame, wxMenu *file, wxMenu *edit)
wxFrame *MyApp::CreateChildFrame(wxView *view, bool isCanvas)
{
// create a child frame of appropriate class for the current mode
wxFrame *subframe;
wxFrame *subframe = NULL;
wxDocument *doc = view->GetDocument();
switch ( GetMode() )
#if wxUSE_MDI_ARCHITECTURE
if ( GetMode() == Mode_MDI )
{
subframe = new wxDocMDIChildFrame
(
doc,
view,
wxStaticCast(GetTopWindow(), wxDocMDIParentFrame),
wxID_ANY,
"Child Frame",
wxDefaultPosition,
wxSize(300, 300)
);
}
else
case Mode_MDI:
subframe = new wxDocMDIChildFrame
(
doc,
view,
wxStaticCast(GetTopWindow(), wxDocMDIParentFrame),
wxID_ANY,
"Child Frame",
wxDefaultPosition,
wxSize(300, 300)
);
break;
#endif // wxUSE_MDI_ARCHITECTURE
{
subframe = new wxDocChildFrame
(
doc,
view,
wxStaticCast(GetTopWindow(), wxDocParentFrame),
wxID_ANY,
"Child Frame",
wxDefaultPosition,
wxSize(300, 300)
);
subframe->Centre();
#if wxUSE_AUI
case Mode_AUI:
subframe = new wxDocChildFrameAny<wxAuiMDIChildFrame, wxAuiMDIParentFrame>
(
doc,
view,
wxStaticCast(GetTopWindow(), wxAuiMDIParentFrame),
wxID_ANY,
"Child Frame",
wxDefaultPosition,
wxSize(300, 300)
);
break;
#endif // wxUSE_AUI
case Mode_SDI:
case Mode_Single:
subframe = new wxDocChildFrame
(
doc,
view,
wxStaticCast(GetTopWindow(), wxDocParentFrame),
wxID_ANY,
"Child Frame",
wxDefaultPosition,
wxSize(300, 300)
);
subframe->Centre();
break;
}
wxMenu *menuFile = new wxMenu;
@@ -396,6 +448,12 @@ void MyApp::OnAbout(wxCommandEvent& WXUNUSED(event))
break;
#endif // wxUSE_MDI_ARCHITECTURE
#if wxUSE_AUI
case Mode_AUI:
modeName = "AUI";
break;
#endif // wxUSE_AUI
case Mode_SDI:
modeName = "SDI";
break;
@@ -419,7 +477,7 @@ void MyApp::OnAbout(wxCommandEvent& WXUNUSED(event))
"\n"
"Authors: Julian Smart, Vadim Zeitlin\n"
"\n"
"Usage: docview [--{mdi,sdi,single}]",
"Usage: docview [--{mdi,aui,sdi,single}]",
modeName,
docsCount
);