From: Vadim Zeitlin Date: Tue, 22 Feb 2000 10:00:29 +0000 (+0000) Subject: added wxLog::Suspend/Resume and wxYield() uses them now so that it won't flush X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/2ed3265e18ed0470d7b56bc2a8a6796c697b90af?ds=inline added wxLog::Suspend/Resume and wxYield() uses them now so that it won't flush the messages any more git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6204 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/log.h b/include/wx/log.h index 94d0beb5b6..f5138cf988 100644 --- a/include/wx/log.h +++ b/include/wx/log.h @@ -135,9 +135,12 @@ public: // flush the active target if any static void FlushActive() { - wxLog *log = GetActiveTarget(); - if ( log ) - log->Flush(); + if ( !ms_suspendCount ) + { + wxLog *log = GetActiveTarget(); + if ( log && log->HasPendingMessages() ) + log->Flush(); + } } // get current log target, will call wxApp::CreateLogTarget() to // create one if none exists @@ -145,6 +148,13 @@ public: // change log target, pLogger may be NULL static wxLog *SetActiveTarget(wxLog *pLogger); + // suspend the message flushing of the main target until the next call + // to Resume() - this is mainly for internal use (to prevent wxYield() + // from flashing the messages) + static void Suspend() { ms_suspendCount++; } + // must be called for each Suspend()! + static void Resume() { ms_suspendCount--; } + // functions controlling the default wxLog behaviour // verbose mode is activated by standard command-line '-verbose' // option @@ -205,6 +215,8 @@ private: static bool ms_doLog; // FALSE => all logging disabled static bool ms_bAutoCreate; // create new log targets on demand? + static size_t ms_suspendCount; // if positive, logs are not flushed + // format string for strftime(), if NULL, time stamping log messages is // disabled static const wxChar *ms_timestamp; diff --git a/src/common/log.cpp b/src/common/log.cpp index 2179500499..3f062d0dfc 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -448,6 +448,8 @@ wxLog *wxLog::ms_pLogger = (wxLog *)NULL; bool wxLog::ms_doLog = TRUE; bool wxLog::ms_bAutoCreate = TRUE; +size_t wxLog::ms_suspendCount = 0; + #if wxUSE_GUI const wxChar *wxLog::ms_timestamp = wxT("%X"); // time only, no date #else diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index bd85f4f6a2..b89d77cd5c 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -99,10 +99,18 @@ bool wxYield() wxTheApp->m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL ); } + // disable log flushing from here because a call to wxYield() shouldn't + // normally result in message boxes popping up &c + wxLog::Suspend(); + /* it's necessary to call ProcessIdle() to update the frames sizes which might have been changed (it also will update other things set from OnUpdateUI() which is a nice (and desired) side effect) */ - while (wxTheApp->ProcessIdle()) { } + while (wxTheApp->ProcessIdle()) + ; + + // let the logs be flashed again + wxLog::Resume(); return TRUE; } @@ -380,9 +388,7 @@ void wxApp::OnIdle( wxIdleEvent &event ) /* flush the logged messages if any */ #if wxUSE_LOG - wxLog *log = wxLog::GetActiveTarget(); - if (log != NULL && log->HasPendingMessages()) - log->Flush(); + wxLog::FlushActive(); #endif // wxUSE_LOG } diff --git a/src/gtk1/app.cpp b/src/gtk1/app.cpp index bd85f4f6a2..b89d77cd5c 100644 --- a/src/gtk1/app.cpp +++ b/src/gtk1/app.cpp @@ -99,10 +99,18 @@ bool wxYield() wxTheApp->m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL ); } + // disable log flushing from here because a call to wxYield() shouldn't + // normally result in message boxes popping up &c + wxLog::Suspend(); + /* it's necessary to call ProcessIdle() to update the frames sizes which might have been changed (it also will update other things set from OnUpdateUI() which is a nice (and desired) side effect) */ - while (wxTheApp->ProcessIdle()) { } + while (wxTheApp->ProcessIdle()) + ; + + // let the logs be flashed again + wxLog::Resume(); return TRUE; } @@ -380,9 +388,7 @@ void wxApp::OnIdle( wxIdleEvent &event ) /* flush the logged messages if any */ #if wxUSE_LOG - wxLog *log = wxLog::GetActiveTarget(); - if (log != NULL && log->HasPendingMessages()) - log->Flush(); + wxLog::FlushActive(); #endif // wxUSE_LOG } diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 25181c2d11..94c9239a6d 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -1019,9 +1019,7 @@ void wxApp::OnIdle(wxIdleEvent& event) #if wxUSE_LOG // flush the logged messages if any - wxLog *pLog = wxLog::GetActiveTarget(); - if ( pLog != NULL && pLog->HasPendingMessages() ) - pLog->Flush(); + wxLog::FlushActive(); #endif // wxUSE_LOG // Send OnIdle events to all windows @@ -1216,9 +1214,12 @@ void wxExit() // Yield to incoming messages bool wxYield() { + // disable log flushing from here because a call to wxYield() shouldn't + // normally result in message boxes popping up &c + wxLog::Suspend(); + // we don't want to process WM_QUIT from here - it should be processed in // the main event loop in order to stop it - MSG msg; while ( PeekMessage(&msg, (HWND)0, 0, 0, PM_NOREMOVE) && msg.message != WM_QUIT ) @@ -1234,6 +1235,9 @@ bool wxYield() // If they are pending events, we must process them. wxTheApp->ProcessPendingEvents(); + // let the logs be flashed again + wxLog::Resume(); + return TRUE; }