Return true from wxDialog::IsModal() in wxEVT_INIT_DIALOG handler
Ensure that checking for dialog modality in wxEVT_INIT_DIALOG handler returns true when the dialog is being shown modally in MSW and GTK. Add a unit test checking that this is the case. Closes #10385.
This commit is contained in:
committed by
Vadim Zeitlin
parent
d2c2274baa
commit
b6f2973c41
@@ -161,10 +161,10 @@ int wxDialog::ShowModal()
|
||||
// NOTE: this will cause a gtk_grab_add() during Show()
|
||||
gtk_window_set_modal(GTK_WINDOW(m_widget), true);
|
||||
|
||||
Show( true );
|
||||
|
||||
m_modalShowing = true;
|
||||
|
||||
Show( true );
|
||||
|
||||
wxOpenModalDialogLocker modalLock;
|
||||
|
||||
// Prevent the widget from being destroyed if the user closes the window.
|
||||
|
@@ -181,17 +181,17 @@ int wxDialog::ShowModal()
|
||||
|
||||
wxASSERT_MSG( !IsModal(), wxT("ShowModal() can't be called twice") );
|
||||
|
||||
wxDialogModalDataTiedPtr modalData(&m_modalData,
|
||||
new wxDialogModalData(this));
|
||||
|
||||
Show();
|
||||
|
||||
// EndModal may have been called from InitDialog handler (called from
|
||||
// inside Show()) and hidden the dialog back again
|
||||
if ( IsShown() )
|
||||
{
|
||||
// enter and run the modal loop
|
||||
wxDialogModalDataTiedPtr modalData(&m_modalData,
|
||||
new wxDialogModalData(this));
|
||||
modalData->RunLoop();
|
||||
}
|
||||
else
|
||||
m_modalData->ExitLoop();
|
||||
|
||||
return GetReturnCode();
|
||||
}
|
||||
|
@@ -36,11 +36,13 @@ private:
|
||||
#endif
|
||||
CPPUNIT_TEST( FileDialog );
|
||||
CPPUNIT_TEST( CustomDialog );
|
||||
CPPUNIT_TEST( InitDialog );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void MessageDialog();
|
||||
void FileDialog();
|
||||
void CustomDialog();
|
||||
void InitDialog();
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(ModalDialogsTestCase);
|
||||
};
|
||||
@@ -132,4 +134,36 @@ void ModalDialogsTestCase::CustomDialog()
|
||||
CPPUNIT_ASSERT_EQUAL( 42, dlg.m_value );
|
||||
}
|
||||
|
||||
|
||||
class MyModalDialog : public wxDialog
|
||||
{
|
||||
public:
|
||||
MyModalDialog() : wxDialog (NULL, wxID_ANY, "Modal Dialog")
|
||||
{
|
||||
m_wasModal = false;
|
||||
Bind( wxEVT_INIT_DIALOG, &MyModalDialog::OnInit, this );
|
||||
}
|
||||
|
||||
void OnInit(wxInitDialogEvent& WXUNUSED(event))
|
||||
{
|
||||
m_wasModal = IsModal();
|
||||
CallAfter( &MyModalDialog::EndModal, wxID_OK );
|
||||
}
|
||||
|
||||
bool WasModal() const
|
||||
{
|
||||
return m_wasModal;
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_wasModal;
|
||||
};
|
||||
|
||||
void ModalDialogsTestCase::InitDialog()
|
||||
{
|
||||
MyModalDialog dlg;
|
||||
dlg.ShowModal();
|
||||
CPPUNIT_ASSERT( dlg.WasModal() );
|
||||
}
|
||||
|
||||
#endif // HAVE_VARIADIC_MACROS
|
||||
|
Reference in New Issue
Block a user