Fix for modal/modeless wizards
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35597 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -67,7 +67,6 @@ public:
|
|||||||
virtual bool OnInit();
|
virtual bool OnInit();
|
||||||
};
|
};
|
||||||
|
|
||||||
class MyWizard;
|
|
||||||
class MyFrame : public wxFrame
|
class MyFrame : public wxFrame
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -81,14 +80,9 @@ public:
|
|||||||
void OnWizardCancel(wxWizardEvent& event);
|
void OnWizardCancel(wxWizardEvent& event);
|
||||||
void OnWizardFinished(wxWizardEvent& event);
|
void OnWizardFinished(wxWizardEvent& event);
|
||||||
|
|
||||||
// Only required for modeless wizards, to implement destruction;
|
|
||||||
// if using modal wizards, you can rely on the default behaviour.
|
|
||||||
void OnCancel(wxCommandEvent& event);
|
|
||||||
private:
|
private:
|
||||||
// any class wishing to process wxWidgets events must use this macro
|
// any class wishing to process wxWidgets events must use this macro
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
|
|
||||||
MyWizard* m_wizard;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -99,15 +93,10 @@ class MyWizard : public wxWizard
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyWizard(wxFrame *frame);
|
MyWizard(wxFrame *frame);
|
||||||
|
|
||||||
void RunIt(bool modal);
|
void RunIt(bool modal);
|
||||||
|
|
||||||
// Is the wizard being invoked modally?
|
|
||||||
bool GetModalWizard() const { return m_isModal; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxWizardPageSimple *m_page1;
|
wxWizardPageSimple *m_page1;
|
||||||
bool m_isModal;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -329,8 +318,6 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
|
|
||||||
EVT_WIZARD_CANCEL(wxID_ANY, MyFrame::OnWizardCancel)
|
EVT_WIZARD_CANCEL(wxID_ANY, MyFrame::OnWizardCancel)
|
||||||
EVT_WIZARD_FINISHED(wxID_ANY, MyFrame::OnWizardFinished)
|
EVT_WIZARD_FINISHED(wxID_ANY, MyFrame::OnWizardFinished)
|
||||||
|
|
||||||
EVT_BUTTON(wxID_CANCEL, MyFrame::OnCancel)
|
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(wxRadioboxPage, wxWizardPageSimple)
|
BEGIN_EVENT_TABLE(wxRadioboxPage, wxWizardPageSimple)
|
||||||
@@ -360,14 +347,12 @@ bool MyApp::OnInit()
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// MyWizard
|
// MyWizard
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
MyWizard::MyWizard(wxFrame *frame)
|
MyWizard::MyWizard(wxFrame *frame)
|
||||||
:wxWizard(frame,wxID_ANY,_T("Absolutely Useless Wizard"),
|
:wxWizard(frame,wxID_ANY,_T("Absolutely Useless Wizard"),
|
||||||
wxBitmap(wiztest_xpm),wxDefaultPosition,
|
wxBitmap(wiztest_xpm),wxDefaultPosition,
|
||||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
||||||
{
|
{
|
||||||
m_isModal = false;
|
|
||||||
|
|
||||||
// a wizard page may be either an object of predefined class
|
// a wizard page may be either an object of predefined class
|
||||||
m_page1 = new wxWizardPageSimple(this);
|
m_page1 = new wxWizardPageSimple(this);
|
||||||
|
|
||||||
@@ -398,7 +383,6 @@ MyWizard::MyWizard(wxFrame *frame)
|
|||||||
|
|
||||||
void MyWizard::RunIt(bool modal)
|
void MyWizard::RunIt(bool modal)
|
||||||
{
|
{
|
||||||
m_isModal = modal;
|
|
||||||
if ( modal )
|
if ( modal )
|
||||||
{
|
{
|
||||||
if ( RunWizard(m_page1) )
|
if ( RunWizard(m_page1) )
|
||||||
@@ -424,8 +408,6 @@ MyFrame::MyFrame(const wxString& title)
|
|||||||
:wxFrame((wxFrame *)NULL, wxID_ANY, title,
|
:wxFrame((wxFrame *)NULL, wxID_ANY, title,
|
||||||
wxDefaultPosition, wxSize(250, 150)) // small frame
|
wxDefaultPosition, wxSize(250, 150)) // small frame
|
||||||
{
|
{
|
||||||
m_wizard = NULL;
|
|
||||||
|
|
||||||
wxMenu *menuFile = new wxMenu;
|
wxMenu *menuFile = new wxMenu;
|
||||||
menuFile->Append(Wizard_RunModal, _T("&Run wizard modal...\tCtrl-R"));
|
menuFile->Append(Wizard_RunModal, _T("&Run wizard modal...\tCtrl-R"));
|
||||||
menuFile->Append(Wizard_RunModeless, _T("&Run wizard modeless..."));
|
menuFile->Append(Wizard_RunModeless, _T("&Run wizard modeless..."));
|
||||||
@@ -464,17 +446,13 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|||||||
|
|
||||||
void MyFrame::OnRunWizard(wxCommandEvent& event)
|
void MyFrame::OnRunWizard(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
m_wizard = new MyWizard(this);
|
MyWizard *wizard = new MyWizard(this);
|
||||||
|
|
||||||
m_wizard->RunIt( event.GetId() == Wizard_RunModal );
|
wizard->RunIt( event.GetId() == Wizard_RunModal );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnWizardFinished(wxWizardEvent& WXUNUSED(event))
|
void MyFrame::OnWizardFinished(wxWizardEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
if (!m_wizard->GetModalWizard())
|
|
||||||
m_wizard->Destroy();
|
|
||||||
m_wizard = NULL;
|
|
||||||
|
|
||||||
wxMessageBox(wxT("The wizard finished successfully."), wxT("Wizard notification"));
|
wxMessageBox(wxT("The wizard finished successfully."), wxT("Wizard notification"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -482,16 +460,3 @@ void MyFrame::OnWizardCancel(wxWizardEvent& WXUNUSED(event))
|
|||||||
{
|
{
|
||||||
wxMessageBox(wxT("The wizard was cancelled."), wxT("Wizard notification"));
|
wxMessageBox(wxT("The wizard was cancelled."), wxT("Wizard notification"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnCancel(wxCommandEvent& WXUNUSED(event))
|
|
||||||
{
|
|
||||||
// Destroy a modeless wizard here - we can't destroy it in OnWizardCancel
|
|
||||||
// since the wxWizard object is still in use when that event is sent.
|
|
||||||
|
|
||||||
if (!m_wizard->GetModalWizard())
|
|
||||||
m_wizard->Destroy();
|
|
||||||
else
|
|
||||||
m_wizard->EndModal(wxID_CANCEL);
|
|
||||||
|
|
||||||
m_wizard = NULL;
|
|
||||||
}
|
|
||||||
|
@@ -267,6 +267,13 @@ wxSize wxWizardSizer::SiblingSize(wxSizerItem *child)
|
|||||||
// generic wxWizard implementation
|
// generic wxWizard implementation
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if wxCHECK_VERSION(2, 7, 0)
|
||||||
|
#error "Fix wxGTK vs. wxMSW difference other way"
|
||||||
|
#else
|
||||||
|
WX_DEFINE_ARRAY_PTR(wxWizard *, wxModelessWizards);
|
||||||
|
wxModelessWizards modelessWizards;
|
||||||
|
#endif
|
||||||
|
|
||||||
void wxWizard::Init()
|
void wxWizard::Init()
|
||||||
{
|
{
|
||||||
m_posWizard = wxDefaultPosition;
|
m_posWizard = wxDefaultPosition;
|
||||||
@@ -278,6 +285,7 @@ void wxWizard::Init()
|
|||||||
m_calledSetBorder = false;
|
m_calledSetBorder = false;
|
||||||
m_border = 0;
|
m_border = 0;
|
||||||
m_started = false;
|
m_started = false;
|
||||||
|
modelessWizards.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxWizard::Create(wxWindow *parent,
|
bool wxWizard::Create(wxWindow *parent,
|
||||||
@@ -660,6 +668,8 @@ bool wxWizard::RunWizard(wxWizardPage *firstPage)
|
|||||||
// can't return false here because there is no old page
|
// can't return false here because there is no old page
|
||||||
(void)ShowPage(firstPage, true /* forward */);
|
(void)ShowPage(firstPage, true /* forward */);
|
||||||
|
|
||||||
|
modelessWizards.Remove(this);
|
||||||
|
|
||||||
return ShowModal() == wxID_OK;
|
return ShowModal() == wxID_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -801,6 +811,18 @@ void wxWizard::OnWizEvent(wxWizardEvent& event)
|
|||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !IsModal() &&
|
||||||
|
( modelessWizards.Index(this) != wxNOT_FOUND ) &&
|
||||||
|
event.IsAllowed() &&
|
||||||
|
( event.GetEventType() == wxEVT_WIZARD_FINISHED ||
|
||||||
|
event.GetEventType() == wxEVT_WIZARD_CANCEL
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
modelessWizards.Remove(this);
|
||||||
|
Destroy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user