]> git.saurik.com Git - wxWidgets.git/commitdiff
Create temporary wxEventLoop in wxGenericProgressDialog if needed.
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 10 Sep 2010 11:44:46 +0000 (11:44 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 10 Sep 2010 11:44:46 +0000 (11:44 +0000)
wxGenericProgressDialog needs to have an active event loop in order to repaint
itself and process clicks on its buttons but it's more helpful to create a
temporary event loop if there is no currently active one instead of just
asserting. In particular, this allows to use wxProgressDialog from overridden
wxApp::OnInit().

Add temporary event loop creation and remove the now unnecessary asserts
verifying that there is an active event loop as there always will be one.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65499 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/progdlgg.h
src/generic/progdlgg.cpp

index c8585ed15c912c51557174a51950e6449a0da2c9..ba03308d49a0197bf5309ce44940e9925d5670cc 100644 (file)
@@ -15,6 +15,7 @@
 #include "wx/dialog.h"
 
 class WXDLLIMPEXP_FWD_CORE wxButton;
+class WXDLLIMPEXP_FWD_CORE wxEventLoop;
 class WXDLLIMPEXP_FWD_CORE wxGauge;
 class WXDLLIMPEXP_FWD_CORE wxStaticText;
 class WXDLLIMPEXP_FWD_CORE wxWindowDisabler;
@@ -197,6 +198,11 @@ private:
     // for wxPD_APP_MODAL case
     wxWindowDisabler *m_winDisabler;
 
+    // Temporary event loop created by the dialog itself if there is no
+    // currently active loop when it is created.
+    wxEventLoop *m_tempEventLoop;
+
+
     DECLARE_EVENT_TABLE()
     wxDECLARE_NO_COPY_CLASS(wxGenericProgressDialog);
 };
index fbfb8a8e329ee24fc86bce0a44f857ac6e5938e5..a3f0df2b4b93108e91cd9c4142f19e4ceadb1079 100644 (file)
@@ -127,6 +127,7 @@ void wxGenericProgressDialog::Init(wxWindow *parent, int maximum, int style)
     m_hasSkipButton = false;
 
     m_winDisabler = NULL;
+    m_tempEventLoop = NULL;
 }
 
 wxGenericProgressDialog::wxGenericProgressDialog(wxWindow *parent,
@@ -160,6 +161,17 @@ void wxGenericProgressDialog::Create( const wxString& title,
     SetParent( GetParentForModalDialog(parent, style) );
     SetTitle( title );
 
+    // We need a running event loop in order to update the dialog and be able
+    // to process clicks on its buttons, so ensure that there is one running
+    // even if this means we have to start it ourselves (this happens most
+    // commonly during the program initialization, e.g. for the progress
+    // dialogs shown from overridden wxApp::OnInit()).
+    if ( !wxEventLoopBase::GetActive() )
+    {
+        m_tempEventLoop = new wxEventLoop;
+        wxEventLoop::SetActive(m_tempEventLoop);
+    }
+
     m_hasAbortButton = (style & wxPD_CAN_ABORT) != 0;
     m_hasSkipButton = (style & wxPD_CAN_SKIP) != 0;
 
@@ -466,9 +478,6 @@ wxGenericProgressDialog::Update(int value, const wxString& newmsg, bool *skip)
                 m_msg->SetLabel(_("Done."));
             }
 
-            wxCHECK_MSG(wxEventLoopBase::GetActive(), false,
-                        "wxGenericProgressDialog::Update needs a running event loop");
-
             // allow the window to repaint:
             // NOTE: since we yield only for UI events with this call, there
             //       should be no side-effects
@@ -528,9 +537,6 @@ bool wxGenericProgressDialog::Pulse(const wxString& newmsg, bool *skip)
 
 bool wxGenericProgressDialog::DoBeforeUpdate(bool *skip)
 {
-    wxCHECK_MSG(wxEventLoopBase::GetActive(), false,
-                "wxGenericProgressDialog::DoBeforeUpdate needs a running event loop");
-
     // we have to yield because not only we want to update the display but
     // also to process the clicks on the cancel and skip buttons
     // NOTE: using YieldFor() this call shouldn't give re-entrancy problems
@@ -551,9 +557,6 @@ bool wxGenericProgressDialog::DoBeforeUpdate(bool *skip)
 
 void wxGenericProgressDialog::DoAfterUpdate()
 {
-    wxCHECK_RET(wxEventLoopBase::GetActive(),
-                "wxGenericProgressDialog::DoAfterUpdate needs a running event loop");
-
     // allow the window to repaint:
     // NOTE: since we yield only for UI events with this call, there
     //       should be no side-effects
@@ -715,6 +718,12 @@ wxGenericProgressDialog::~wxGenericProgressDialog()
 {
     // normally this should have been already done, but just in case
     ReenableOtherWindows();
+
+    if ( m_tempEventLoop )
+    {
+        wxEventLoopBase::SetActive(NULL);
+        delete m_tempEventLoop;
+    }
 }
 
 void wxGenericProgressDialog::DisableOtherWindows()
@@ -798,9 +807,6 @@ void wxGenericProgressDialog::EnableClose()
 
 void wxGenericProgressDialog::UpdateMessage(const wxString &newmsg)
 {
-    wxCHECK_RET(wxEventLoopBase::GetActive(),
-                "wxGenericProgressDialog::UpdateMessage needs a running event loop");
-
     if ( !newmsg.empty() && newmsg != m_msg->GetLabel() )
     {
         m_msg->SetLabel(newmsg);