Factor out wxGenericProgressDialog::EnsureActiveEventLoopExists()

Make this function reusable in order to allow it to be called from the
native MSW wxProgressDialog implementation in the upcoming commit.
This commit is contained in:
Vadim Zeitlin
2017-10-28 22:44:22 +02:00
parent 814a674531
commit 6818d0909e
2 changed files with 13 additions and 5 deletions

View File

@@ -105,6 +105,9 @@ protected:
// Converts seconds to HH:mm:ss format. // Converts seconds to HH:mm:ss format.
static wxString GetFormattedTime(unsigned long timeInSec); static wxString GetFormattedTime(unsigned long timeInSec);
// Create a new event loop if there is no currently running one.
void EnsureActiveEventLoopExists();
// callback for optional abort button // callback for optional abort button
void OnCancel(wxCommandEvent&); void OnCancel(wxCommandEvent&);

View File

@@ -160,11 +160,7 @@ bool wxGenericProgressDialog::Create( const wxString& title,
// even if this means we have to start it ourselves (this happens most // even if this means we have to start it ourselves (this happens most
// commonly during the program initialization, e.g. for the progress // commonly during the program initialization, e.g. for the progress
// dialogs shown from overridden wxApp::OnInit()). // dialogs shown from overridden wxApp::OnInit()).
if ( !wxEventLoopBase::GetActive() ) EnsureActiveEventLoopExists();
{
m_tempEventLoop = new wxEventLoop;
wxEventLoop::SetActive(m_tempEventLoop);
}
#if defined(__WXMSW__) && !defined(__WXUNIVERSAL__) #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
// we have to remove the "Close" button from the title bar then as it is // we have to remove the "Close" button from the title bar then as it is
@@ -363,6 +359,15 @@ wxString wxGenericProgressDialog::GetFormattedTime(unsigned long timeInSec)
return timeAsHMS; return timeAsHMS;
} }
void wxGenericProgressDialog::EnsureActiveEventLoopExists()
{
if ( !wxEventLoopBase::GetActive() )
{
m_tempEventLoop = new wxEventLoop;
wxEventLoop::SetActive(m_tempEventLoop);
}
}
wxStaticText * wxStaticText *
wxGenericProgressDialog::CreateLabel(const wxString& text, wxSizer *sizer) wxGenericProgressDialog::CreateLabel(const wxString& text, wxSizer *sizer)
{ {