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
This commit is contained in:
Vadim Zeitlin
2000-02-22 10:00:29 +00:00
parent 6daa30a07e
commit 2ed3265e18
5 changed files with 45 additions and 15 deletions

View File

@@ -135,9 +135,12 @@ public:
// flush the active target if any // flush the active target if any
static void FlushActive() static void FlushActive()
{ {
wxLog *log = GetActiveTarget(); if ( !ms_suspendCount )
if ( log ) {
log->Flush(); wxLog *log = GetActiveTarget();
if ( log && log->HasPendingMessages() )
log->Flush();
}
} }
// get current log target, will call wxApp::CreateLogTarget() to // get current log target, will call wxApp::CreateLogTarget() to
// create one if none exists // create one if none exists
@@ -145,6 +148,13 @@ public:
// change log target, pLogger may be NULL // change log target, pLogger may be NULL
static wxLog *SetActiveTarget(wxLog *pLogger); 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 // functions controlling the default wxLog behaviour
// verbose mode is activated by standard command-line '-verbose' // verbose mode is activated by standard command-line '-verbose'
// option // option
@@ -205,6 +215,8 @@ private:
static bool ms_doLog; // FALSE => all logging disabled static bool ms_doLog; // FALSE => all logging disabled
static bool ms_bAutoCreate; // create new log targets on demand? 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 // format string for strftime(), if NULL, time stamping log messages is
// disabled // disabled
static const wxChar *ms_timestamp; static const wxChar *ms_timestamp;

View File

@@ -448,6 +448,8 @@ wxLog *wxLog::ms_pLogger = (wxLog *)NULL;
bool wxLog::ms_doLog = TRUE; bool wxLog::ms_doLog = TRUE;
bool wxLog::ms_bAutoCreate = TRUE; bool wxLog::ms_bAutoCreate = TRUE;
size_t wxLog::ms_suspendCount = 0;
#if wxUSE_GUI #if wxUSE_GUI
const wxChar *wxLog::ms_timestamp = wxT("%X"); // time only, no date const wxChar *wxLog::ms_timestamp = wxT("%X"); // time only, no date
#else #else

View File

@@ -99,10 +99,18 @@ bool wxYield()
wxTheApp->m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL ); 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 /* it's necessary to call ProcessIdle() to update the frames sizes which
might have been changed (it also will update other things set from might have been changed (it also will update other things set from
OnUpdateUI() which is a nice (and desired) side effect) */ 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; return TRUE;
} }
@@ -380,9 +388,7 @@ void wxApp::OnIdle( wxIdleEvent &event )
/* flush the logged messages if any */ /* flush the logged messages if any */
#if wxUSE_LOG #if wxUSE_LOG
wxLog *log = wxLog::GetActiveTarget(); wxLog::FlushActive();
if (log != NULL && log->HasPendingMessages())
log->Flush();
#endif // wxUSE_LOG #endif // wxUSE_LOG
} }

View File

@@ -99,10 +99,18 @@ bool wxYield()
wxTheApp->m_idleTag = gtk_idle_add( wxapp_idle_callback, (gpointer) NULL ); 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 /* it's necessary to call ProcessIdle() to update the frames sizes which
might have been changed (it also will update other things set from might have been changed (it also will update other things set from
OnUpdateUI() which is a nice (and desired) side effect) */ 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; return TRUE;
} }
@@ -380,9 +388,7 @@ void wxApp::OnIdle( wxIdleEvent &event )
/* flush the logged messages if any */ /* flush the logged messages if any */
#if wxUSE_LOG #if wxUSE_LOG
wxLog *log = wxLog::GetActiveTarget(); wxLog::FlushActive();
if (log != NULL && log->HasPendingMessages())
log->Flush();
#endif // wxUSE_LOG #endif // wxUSE_LOG
} }

View File

@@ -1019,9 +1019,7 @@ void wxApp::OnIdle(wxIdleEvent& event)
#if wxUSE_LOG #if wxUSE_LOG
// flush the logged messages if any // flush the logged messages if any
wxLog *pLog = wxLog::GetActiveTarget(); wxLog::FlushActive();
if ( pLog != NULL && pLog->HasPendingMessages() )
pLog->Flush();
#endif // wxUSE_LOG #endif // wxUSE_LOG
// Send OnIdle events to all windows // Send OnIdle events to all windows
@@ -1216,9 +1214,12 @@ void wxExit()
// Yield to incoming messages // Yield to incoming messages
bool wxYield() 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 // we don't want to process WM_QUIT from here - it should be processed in
// the main event loop in order to stop it // the main event loop in order to stop it
MSG msg; MSG msg;
while ( PeekMessage(&msg, (HWND)0, 0, 0, PM_NOREMOVE) && while ( PeekMessage(&msg, (HWND)0, 0, 0, PM_NOREMOVE) &&
msg.message != WM_QUIT ) msg.message != WM_QUIT )
@@ -1234,6 +1235,9 @@ bool wxYield()
// If they are pending events, we must process them. // If they are pending events, we must process them.
wxTheApp->ProcessPendingEvents(); wxTheApp->ProcessPendingEvents();
// let the logs be flashed again
wxLog::Resume();
return TRUE; return TRUE;
} }