state after EndModal is called. Future API might incorporate modal flag
so wxWizard can do the right thing.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35564
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
virtual bool OnInit();
};
virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
class MyFrame : public wxFrame
{
public:
void OnWizardCancel(wxWizardEvent& event);
void OnWizardFinished(wxWizardEvent& event);
void OnWizardCancel(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:
// any class wishing to process wxWidgets events must use this macro
DECLARE_EVENT_TABLE()
private:
// any class wishing to process wxWidgets events must use this macro
DECLARE_EVENT_TABLE()
};
// ----------------------------------------------------------------------------
};
// ----------------------------------------------------------------------------
{
public:
MyWizard(wxFrame *frame);
{
public:
MyWizard(wxFrame *frame);
+ // Is the wizard being invoked modally?
+ bool GetModalWizard() const { return m_isModal; }
+
private:
wxWizardPageSimple *m_page1;
private:
wxWizardPageSimple *m_page1;
};
// ----------------------------------------------------------------------------
};
// ----------------------------------------------------------------------------
EVT_WIZARD_CANCEL(wxID_ANY, MyFrame::OnWizardCancel)
EVT_WIZARD_FINISHED(wxID_ANY, MyFrame::OnWizardFinished)
EVT_WIZARD_CANCEL(wxID_ANY, MyFrame::OnWizardCancel)
EVT_WIZARD_FINISHED(wxID_ANY, MyFrame::OnWizardFinished)
+
+ EVT_BUTTON(wxID_CANCEL, MyFrame::OnCancel)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxRadioboxPage, wxWizardPageSimple)
END_EVENT_TABLE()
BEGIN_EVENT_TABLE(wxRadioboxPage, wxWizardPageSimple)
// ----------------------------------------------------------------------------
// MyWizard
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// MyWizard
// ----------------------------------------------------------------------------
MyWizard::MyWizard(wxFrame *frame)
:wxWizard(frame,wxID_ANY,_T("Absolutely Useless Wizard"),
wxBitmap(wiztest_xpm),wxDefaultPosition,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
MyWizard::MyWizard(wxFrame *frame)
:wxWizard(frame,wxID_ANY,_T("Absolutely Useless Wizard"),
wxBitmap(wiztest_xpm),wxDefaultPosition,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
{
// a wizard page may be either an object of predefined class
m_page1 = new wxWizardPageSimple(this);
// a wizard page may be either an object of predefined class
m_page1 = new wxWizardPageSimple(this);
void MyWizard::RunIt(bool modal)
{
void MyWizard::RunIt(bool modal)
{
if ( modal )
{
if ( RunWizard(m_page1) )
{
if ( modal )
{
if ( RunWizard(m_page1) )
{
- wxMessageBox(_T("The wizard successfully completed"), _T("That's all"),
- wxICON_INFORMATION | wxOK);
:wxFrame((wxFrame *)NULL, wxID_ANY, title,
wxDefaultPosition, wxSize(250, 150)) // small frame
{
:wxFrame((wxFrame *)NULL, wxID_ANY, title,
wxDefaultPosition, wxSize(250, 150)) // small frame
{
wxMenu *menuFile = new wxMenu;
menuFile->Append(Wizard_RunModal, _T("&Run wizard modal...\tCtrl-R"));
menuFile->Append(Wizard_RunModeless, _T("&Run wizard modeless..."));
wxMenu *menuFile = new wxMenu;
menuFile->Append(Wizard_RunModal, _T("&Run wizard modal...\tCtrl-R"));
menuFile->Append(Wizard_RunModeless, _T("&Run wizard modeless..."));
void MyFrame::OnRunWizard(wxCommandEvent& event)
{
void MyFrame::OnRunWizard(wxCommandEvent& event)
{
- MyWizard *wizard = new MyWizard(this);
+ m_wizard = new MyWizard(this);
- wizard->RunIt( event.GetId() == Wizard_RunModal );
+ m_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"));
}
{
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;
+}
-
- if ( !IsModal() &&
- event.IsAllowed() &&
- ( event.GetEventType() == wxEVT_WIZARD_FINISHED ||
- event.GetEventType() == wxEVT_WIZARD_CANCEL
- )
- )
- {
- Destroy();
- }
}
// ----------------------------------------------------------------------------
}
// ----------------------------------------------------------------------------