X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7e1bcfa80e19ac853b8bc7084075fe3b01e63f03..8a82c9ecc9a2cba9727b538c818ebdba243eacbc:/src/motif/evtloop.cpp diff --git a/src/motif/evtloop.cpp b/src/motif/evtloop.cpp index 57a3283542..f0f1d779dc 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 @@ -168,7 +169,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 +234,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 +260,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 +294,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 +308,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 +320,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 +334,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 +346,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 +402,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 +446,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 +465,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],