implement event loop for console applications (heavily modified patch 1715735)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46029 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-05-14 23:43:39 +00:00
parent 9e9f08b5ed
commit b46b1d59d6
72 changed files with 3181 additions and 1128 deletions

View File

@@ -37,11 +37,9 @@
#include "wx/apptrait.h"
#include "wx/cmdline.h"
#include "wx/evtloop.h"
#include "wx/msgout.h"
#include "wx/thread.h"
#include "wx/vidmode.h"
#include "wx/ptr_scpd.h"
#ifdef __WXDEBUG__
#if wxUSE_STACKWALKER
@@ -63,13 +61,6 @@ WX_CHECK_BUILD_OPTIONS("wxCore")
WXDLLIMPEXP_DATA_CORE(wxList) wxPendingDelete;
// ----------------------------------------------------------------------------
// wxEventLoopPtr
// ----------------------------------------------------------------------------
// this defines wxEventLoopPtr
wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoop)
// ============================================================================
// wxAppBase implementation
// ============================================================================
@@ -81,13 +72,11 @@ wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoop)
wxAppBase::wxAppBase()
{
m_topWindow = (wxWindow *)NULL;
m_useBestVisual = false;
m_forceTrueColour = false;
m_isActive = true;
m_mainLoop = NULL;
m_isActive = true;
// We don't want to exit the app if the user code shows a dialog from its
// OnInit() -- but this is what would happen if we set m_exitOnFrameDelete
@@ -109,10 +98,6 @@ bool wxAppBase::Initialize(int& argcOrig, wxChar **argvOrig)
if ( !wxAppConsole::Initialize(argcOrig, argvOrig) )
return false;
#if wxUSE_THREADS
wxPendingEventsLocker = new wxCriticalSection;
#endif
wxInitializeStockLists();
wxBitmap::InitStandardHandlers();
@@ -157,9 +142,6 @@ void wxAppBase::CleanUp()
wxPendingEvents = NULL;
#if wxUSE_THREADS
delete wxPendingEventsLocker;
wxPendingEventsLocker = NULL;
#if wxUSE_VALIDATORS
// If we don't do the following, we get an apparent memory leak.
((wxEvtHandler&) wxDefaultValidator).ClearEventLocker();
@@ -298,45 +280,6 @@ bool wxAppBase::OnCmdLineParsed(wxCmdLineParser& parser)
#endif // wxUSE_CMDLINE_PARSER
// ----------------------------------------------------------------------------
// main event loop implementation
// ----------------------------------------------------------------------------
int wxAppBase::MainLoop()
{
wxEventLoopTiedPtr mainLoop(&m_mainLoop, new wxEventLoop);
return m_mainLoop->Run();
}
void wxAppBase::ExitMainLoop()
{
// we should exit from the main event loop, not just any currently active
// (e.g. modal dialog) event loop
if ( m_mainLoop && m_mainLoop->IsRunning() )
{
m_mainLoop->Exit(0);
}
}
bool wxAppBase::Pending()
{
// use the currently active message loop here, not m_mainLoop, because if
// we're showing a modal dialog (with its own event loop) currently the
// main event loop is not running anyhow
wxEventLoop * const loop = wxEventLoop::GetActive();
return loop && loop->Pending();
}
bool wxAppBase::Dispatch()
{
// see comment in Pending()
wxEventLoop * const loop = wxEventLoop::GetActive();
return loop && loop->Dispatch();
}
// ----------------------------------------------------------------------------
// OnXXX() hooks
// ----------------------------------------------------------------------------
@@ -361,7 +304,7 @@ int wxAppBase::OnRun()
}
//else: it has been changed, assume the user knows what he is doing
return MainLoop();
return wxAppConsole::OnRun();
}
int wxAppBase::OnExit()
@@ -373,11 +316,6 @@ int wxAppBase::OnExit()
return wxAppConsole::OnExit();
}
void wxAppBase::Exit()
{
ExitMainLoop();
}
wxAppTraits *wxAppBase::CreateTraits()
{
return new wxGUIAppTraits;
@@ -439,10 +377,7 @@ bool wxAppBase::ProcessIdle()
node = node->GetNext();
}
event.SetEventObject(this);
(void) ProcessEvent(event);
if (event.MoreRequested())
needMore = true;
needMore = wxAppConsole::ProcessIdle();
wxUpdateUIEvent::ResetUpdateTime();
@@ -456,7 +391,9 @@ bool wxAppBase::SendIdleEvents(wxWindow* win, wxIdleEvent& event)
win->OnInternalIdle();
if (wxIdleEvent::CanSend(win))
// should we send idle event to this window?
if ( wxIdleEvent::GetMode() == wxIDLE_PROCESS_ALL ||
win->HasExtraStyle(wxWS_EX_PROCESS_IDLE) )
{
event.SetEventObject(win);
win->GetEventHandler()->ProcessEvent(event);
@@ -498,24 +435,6 @@ void wxAppBase::OnIdle(wxIdleEvent& WXUNUSED(event))
}
// ----------------------------------------------------------------------------
// exceptions support
// ----------------------------------------------------------------------------
#if wxUSE_EXCEPTIONS
bool wxAppBase::OnExceptionInMainLoop()
{
throw;
// some compilers are too stupid to know that we never return after throw
#if defined(__DMC__) || (defined(_MSC_VER) && _MSC_VER < 1200)
return false;
#endif
}
#endif // wxUSE_EXCEPTIONS
// ----------------------------------------------------------------------------
// wxGUIAppTraitsBase
// ----------------------------------------------------------------------------