X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7e1bcfa80e19ac853b8bc7084075fe3b01e63f03..3dd4386160b8f6d28ecc4ad2ca308c437721a41f:/src/motif/evtloop.cpp?ds=sidebyside diff --git a/src/motif/evtloop.cpp b/src/motif/evtloop.cpp index 57a3283542..431f2a11b3 100644 --- a/src/motif/evtloop.cpp +++ b/src/motif/evtloop.cpp @@ -6,7 +6,7 @@ // Created: 01.11.02 // RCS-ID: $Id$ // Copyright: (c) 2002 Mattia Barbon -// License: wxWindows license +// License: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -17,7 +17,7 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "evtloop.h" #endif @@ -35,6 +35,7 @@ #include "wx/evtloop.h" #include "wx/event.h" #include "wx/app.h" +#include "wx/window.h" #ifdef __VMS__ #pragma message disable nosimpint @@ -82,9 +83,7 @@ private: static bool SendIdleMessage() { - wxIdleEvent event; - - return wxTheApp->ProcessEvent(event) && event.MoreRequested(); + return wxTheApp->ProcessIdle(); } bool wxEventLoopImpl::SendIdleMessage() @@ -100,18 +99,13 @@ bool wxEventLoopImpl::SendIdleMessage() // wxEventLoop running and exiting // ---------------------------------------------------------------------------- -wxEventLoop *wxEventLoop::ms_activeLoop = NULL; +wxEventLoop *wxEventLoopBase::ms_activeLoop = NULL; wxEventLoop::~wxEventLoop() { wxASSERT_MSG( !m_impl, _T("should have been deleted in Run()") ); } -bool wxEventLoop::IsRunning() const -{ - return m_impl != NULL; -} - int wxEventLoop::Run() { // event loops are not recursive, you need to create another loop! @@ -168,7 +162,11 @@ bool wxEventLoop::Dispatch() ProcessXEvent( &event ); } else - XtAppProcessEvent( context, XtIMTimer|XtIMAlternateInput|XtIMSignal ); +#ifdef __VMS + XtAppProcessEvent( context, XtIMTimer|XtIMAlternateInput ); +#else + XtAppProcessEvent( context, XtIMTimer|XtIMAlternateInput|XtIMSignal ); +#endif return m_impl ? m_impl->GetKeepGoing() : true; } @@ -229,7 +227,7 @@ void ProcessXEvent(XEvent* event) * window is recieved. Prevents flicker as windows are resized. */ - Display *disp = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()); + Display *disp = event->xany.display; Window win = event->xany.window; XEvent report; @@ -255,7 +253,7 @@ bool CheckForAccelerator(XEvent* event) { // Find a wxWindow for this window // TODO: should get display for the window, not the current display - Widget widget = XtWindowToWidget((Display*) wxGetDisplay(), + Widget widget = XtWindowToWidget(event->xany.display, event->xany.window); wxWindow* win = NULL; @@ -289,8 +287,8 @@ bool CheckForKeyDown(XEvent* event) { if (event->xany.type == KeyPress) { - Widget widget = XtWindowToWidget((Display*) wxGetDisplay(), - event->xany.window); + Widget widget = XtWindowToWidget(event->xany.display, + event->xany.window); wxWindow* win = NULL; // Find the first wxWindow that corresponds to this event window @@ -303,7 +301,7 @@ bool CheckForKeyDown(XEvent* event) wxKeyEvent keyEvent(wxEVT_KEY_DOWN); wxTranslateKeyEvent(keyEvent, win, (Widget) 0, event); - return win->ProcessEvent( keyEvent ); + return win->GetEventHandler()->ProcessEvent( keyEvent ); } return false; @@ -315,8 +313,8 @@ bool CheckForKeyUp(XEvent* event) { if (event->xany.type == KeyRelease) { - Widget widget = XtWindowToWidget((Display*) wxGetDisplay(), - event->xany.window); + Widget widget = XtWindowToWidget(event->xany.display, + event->xany.window); wxWindow* win = NULL; // Find the first wxWindow that corresponds to this event window @@ -329,7 +327,7 @@ bool CheckForKeyUp(XEvent* event) wxKeyEvent keyEvent(wxEVT_KEY_UP); wxTranslateKeyEvent(keyEvent, win, (Widget) 0, event); - return win->ProcessEvent( keyEvent ); + return win->GetEventHandler()->ProcessEvent( keyEvent ); } return false; @@ -341,17 +339,27 @@ bool CheckForKeyUp(XEvent* event) bool wxDoEventLoopIteration( wxEventLoop& evtLoop ) { + bool moreRequested, pendingEvents; + + for(;;) + { + pendingEvents = evtLoop.Pending(); + if( pendingEvents ) break; + moreRequested = ::SendIdleMessage(); + if( !moreRequested ) break; + } + #if wxUSE_THREADS - // leave the main loop to give other threads a chance to - // perform their GUI work - wxMutexGuiLeave(); - wxUsleep(20); - wxMutexGuiEnter(); + if( !pendingEvents && !moreRequested ) + { + // leave the main loop to give other threads a chance to + // perform their GUI work + wxMutexGuiLeave(); + wxUsleep(20); + wxMutexGuiEnter(); + } #endif - while ( !evtLoop.Pending() && ::SendIdleMessage() ) - ; - if( !evtLoop.Dispatch() ) return false; @@ -387,9 +395,11 @@ public: virtual bool OnInit() { + // Must be done before modules are initialized +#if 0 if( pipe(idleFds) != 0 ) return false; - +#endif return true; } @@ -429,7 +439,7 @@ static void wxInputCallback( XtPointer, int* fd, XtInputId* ) static void wxBreakDispatch() { - char dummy; + char dummy = 0; // for valgrind // check if wxWakeUpIdle has already been called fd_set in; @@ -448,13 +458,23 @@ static void wxBreakDispatch() write( idleFds[1], &dummy, 1 ); } -void wxWakeUpIdle() +void wxApp::WakeUpIdle() { ::wxBreakDispatch(); } +bool wxInitIdleFds() +{ + if( pipe(idleFds) != 0 ) + return false; + return true; +} + bool wxAddIdleCallback() { + if (!wxInitIdleFds()) + return false; + // install input handler for wxWakeUpIdle inputId = XtAppAddInput( (XtAppContext) wxTheApp->GetAppContext(), idleFds[0],