Exemplo n.º 1
0
void wxGUIEventLoop::DoYieldFor(long eventsToProcess)
{
    // TODO: implement event filtering using the eventsToProcess mask

    // process all pending events:
    while ( Pending() )
        Dispatch();

    // handle timers, sockets etc.
    OnNextIteration();

    // 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 ( ProcessIdle() ) {}

    wxEventLoopBase::DoYieldFor(eventsToProcess);
}
Exemplo n.º 2
0
void wxCFEventLoop::OSXDoRun()
{
    for ( ;; )
    {
        OnNextIteration();

        // generate and process idle events for as long as we don't
        // have anything else to do
        DoProcessEvents();

        // if the "should exit" flag is set, the loop should terminate
        // but not before processing any remaining messages so while
        // Pending() returns true, do process them
        if ( m_shouldExit )
        {
            while ( DoProcessEvents() == 1 )
                ;

            break;
        }

        // Process the remaining queued messages, both at the level of the
        // underlying toolkit level (Pending/Dispatch()) and wx level
        // (Has/ProcessPendingEvents()).
        //
        // We do run the risk of never exiting this loop if pending event
        // handlers endlessly generate new events but they shouldn't do
        // this in a well-behaved program and we shouldn't just discard the
        // events we already have, they might be important.
        for ( ;; )
        {
            bool hasMoreEvents = false;
            if ( wxTheApp && wxTheApp->HasPendingEvents() )
            {
                wxTheApp->ProcessPendingEvents();
                hasMoreEvents = true;
            }

            if ( !hasMoreEvents )
                break;
        }
    }
}
Exemplo n.º 3
0
void wxCFEventLoop::OSXDoRun()
{
    for ( ;; )
    {
        OnNextIteration();

        // generate and process idle events for as long as we don't
        // have anything else to do
        DoProcessEvents();

        // if the "should exit" flag is set, the loop should terminate
        // but not before processing any remaining messages so while
        // Pending() returns true, do process them
        if ( m_shouldExit )
        {
            while ( DoProcessEvents() == 1 )
                ;

            break;
        }
    }
}
Exemplo n.º 4
0
bool wxGUIEventLoop::YieldFor(long eventsToProcess)
{
#if wxUSE_THREADS
    if ( !wxThread::IsMain() )
        return true; // can't process events from other threads
#endif // wxUSE_THREADS

    m_isInsideYield = true;
    m_eventsToProcessInsideYield = eventsToProcess;

#if wxUSE_LOG
    wxLog::Suspend();
#endif // wxUSE_LOG

    // TODO: implement event filtering using the eventsToProcess mask

    // process all pending events:
    while ( Pending() )
        Dispatch();

    // handle timers, sockets etc.
    OnNextIteration();

    // 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 ( ProcessIdle() ) {}

#if wxUSE_LOG
    wxLog::Resume();
#endif // wxUSE_LOG

    m_isInsideYield = false;

    return true;
}
Exemplo n.º 5
0
int wxEventLoopManual::DoRun()
{
    // we must ensure that OnExit() is called even if an exception is thrown
    // from inside ProcessEvents() but we must call it from Exit() in normal
    // situations because it is supposed to be called synchronously,
    // wxModalEventLoop depends on this (so we can't just use ON_BLOCK_EXIT or
    // something similar here)
#if wxUSE_EXCEPTIONS
    for ( ;; )
    {
        try
        {
#endif // wxUSE_EXCEPTIONS

            // this is the event loop itself
            for ( ;; )
            {
                // give them the possibility to do whatever they want
                OnNextIteration();

                // generate and process idle events for as long as we don't
                // have anything else to do
                while ( !m_shouldExit && !Pending() && ProcessIdle() )
                    ;

                if ( m_shouldExit )
                    break;

                // a message came or no more idle processing to do, dispatch
                // all the pending events and call Dispatch() to wait for the
                // next message
                if ( !ProcessEvents() )
                {
                    // we got WM_QUIT
                    break;
                }
            }

            // Process the remaining queued messages, both at the level of the
            // underlying toolkit level (Pending/Dispatch()) and wx level
            // (Has/ProcessPendingEvents()).
            //
            // We do run the risk of never exiting this loop if pending event
            // handlers endlessly generate new events but they shouldn't do
            // this in a well-behaved program and we shouldn't just discard the
            // events we already have, they might be important.
            for ( ;; )
            {
                bool hasMoreEvents = false;
                if ( wxTheApp && wxTheApp->HasPendingEvents() )
                {
                    wxTheApp->ProcessPendingEvents();
                    hasMoreEvents = true;
                }

                if ( Pending() )
                {
                    Dispatch();
                    hasMoreEvents = true;
                }

                if ( !hasMoreEvents )
                    break;
            }

#if wxUSE_EXCEPTIONS
            // exit the outer loop as well
            break;
        }
        catch ( ... )
        {
            try
            {
                if ( !wxTheApp || !wxTheApp->OnExceptionInMainLoop() )
                {
                    OnExit();
                    break;
                }
                //else: continue running the event loop
            }
            catch ( ... )
            {
                // OnException() throwed, possibly rethrowing the same
                // exception again: very good, but we still need OnExit() to
                // be called
                OnExit();
                throw;
            }
        }
    }
#endif // wxUSE_EXCEPTIONS

    return m_exitcode;
}
Exemplo n.º 6
0
int wxEventLoopManual::Run()
{
    // event loops are not recursive, you need to create another loop!
    wxCHECK_MSG( !IsRunning(), -1, _T("can't reenter a message loop") );

    // ProcessIdle() and Dispatch() below may throw so the code here should
    // be exception-safe, hence we must use local objects for all actions we
    // should undo
    wxEventLoopActivator activate(wx_static_cast(wxEventLoop *, this));

#if defined(__WXMSW__) && wxUSE_THREADS
    wxRunningEventLoopCounter evtLoopCounter;
#endif // __WXMSW__

    // we must ensure that OnExit() is called even if an exception is thrown
    // from inside Dispatch() but we must call it from Exit() in normal
    // situations because it is supposed to be called synchronously,
    // wxModalEventLoop depends on this (so we can't just use ON_BLOCK_EXIT or
    // something similar here)
#if wxUSE_EXCEPTIONS
    for ( ;; )
    {
        try
        {
#endif // wxUSE_EXCEPTIONS

            // this is the event loop itself
            for ( ;; )
            {
                // give them the possibility to do whatever they want
                OnNextIteration();

                // generate and process idle events for as long as we don't
                // have anything else to do
                while ( !Pending() && (wxTheApp && wxTheApp->ProcessIdle()) )
                    ;

                // if the "should exit" flag is set, the loop should terminate
                // but not before processing any remaining messages so while
                // Pending() returns true, do process them
                if ( m_shouldExit )
                {
                    while ( Pending() )
                        Dispatch();

                    break;
                }

                // a message came or no more idle processing to do, sit in
                // Dispatch() waiting for the next message
                if ( !Dispatch() )
                {
                    // we got WM_QUIT
                    break;
                }
            }

#if wxUSE_EXCEPTIONS
            // exit the outer loop as well
            break;
        }
        catch ( ... )
        {
            try
            {
                if ( !wxTheApp || !wxTheApp->OnExceptionInMainLoop() )
                {
                    OnExit();
                    break;
                }
                //else: continue running the event loop
            }
            catch ( ... )
            {
                // OnException() throwed, possibly rethrowing the same
                // exception again: very good, but we still need OnExit() to
                // be called
                OnExit();
                throw;
            }
        }
    }
#endif // wxUSE_EXCEPTIONS

    return m_exitcode;
}