// Author: Vadim Zeitlin, Stefan Csomor
// Modified by:
// Created: 2006-01-12
-// RCS-ID: $Id: evtloop.cpp 54845 2008-07-30 14:52:41Z SC $
+// RCS-ID: $Id$
// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#include "wx/log.h"
+#if wxUSE_GUI
+ #include "wx/nonownedwnd.h"
+#endif
+
#include "wx/osx/private.h"
// ============================================================================
wxGUIEventLoop::wxGUIEventLoop()
{
- m_sleepTime = 0.0;
}
-void wxGUIEventLoop::WakeUp()
+void wxGUIEventLoop::DoRun()
{
- extern void wxMacWakeUp();
+ if ( IsMain() )
+ {
+ wxMacAutoreleasePool pool;
+ const char* appname = "app";
+ UIApplicationMain( 1, (char**) &appname, nil, @"wxAppDelegate" );
+ }
+ else
+ {
+ wxCFEventLoop::DoRun();
+ }
+}
- wxMacWakeUp();
+int wxGUIEventLoop::DoDispatchTimeout(unsigned long timeout)
+{
+ return wxCFEventLoop::DoDispatchTimeout(timeout);
}
-bool wxGUIEventLoop::Pending() const
+void wxGUIEventLoop::DoStop()
{
- wxMacAutoreleasePool autoreleasepool;
- // a pointer to the event is returned if there is one, or nil if not
- /*
- return [[UIApplication sharedApplication]
- nextEventMatchingMask: NSAnyEventMask
- untilDate: nil
- inMode: NSDefaultRunLoopMode
- dequeue: NO];
- */
- return false;
+ return wxCFEventLoop::DoStop();
}
-bool wxGUIEventLoop::Dispatch()
+CFRunLoopRef wxGUIEventLoop::CFGetCurrentRunLoop() const
{
- if ( !wxTheApp )
- return false;
+ return wxCFEventLoop::CFGetCurrentRunLoop();
+}
- wxMacAutoreleasePool autoreleasepool;
-/*
- if(UIEvent *event = [[UIApplication sharedApplication]
- nextEventMatchingMask:NSAnyEventMask
- untilDate:[NSDate dateWithTimeIntervalSinceNow: m_sleepTime]
- inMode:NSDefaultRunLoopMode
- dequeue: YES])
- {
- m_sleepTime = 0.0;
- [[UIApplication sharedApplication] sendEvent: event];
- }
- else
-*/
- {
- if ( wxTheApp->ProcessIdle() )
- m_sleepTime = 0.0 ;
- else
- {
- m_sleepTime = 1.0;
-#if wxUSE_THREADS
- wxMutexGuiLeave();
- wxMilliSleep(20);
- wxMutexGuiEnter();
-#endif
- }
- }
+// TODO move into a evtloop_osx.cpp
- return true;
+wxModalEventLoop::wxModalEventLoop(wxWindow *modalWindow)
+{
+ m_modalWindow = dynamic_cast<wxNonOwnedWindow*> (modalWindow);
+ wxASSERT_MSG( m_modalWindow != NULL, "must pass in a toplevel window for modal event loop" );
+ m_modalNativeWindow = m_modalWindow->GetWXWindow();
}
-bool wxGUIEventLoop::YieldFor(long eventsToProcess)
+wxModalEventLoop::wxModalEventLoop(WXWindow modalNativeWindow)
{
-#if wxUSE_THREADS
- // Yielding from a non-gui thread needs to bail out, otherwise we end up
- // possibly sending events in the thread too.
- if ( !wxThread::IsMain() )
- {
- return true;
- }
-#endif // wxUSE_THREADS
-
- m_isInsideYield = true;
- m_eventsToProcessInsideYield = eventsToProcess;
-
-#if wxUSE_LOG
- // disable log flushing from here because a call to wxYield() shouldn't
- // normally result in message boxes popping up &c
- wxLog::Suspend();
-#endif // wxUSE_LOG
-
- // process all pending events:
- while ( Pending() )
- Dispatch();
+ m_modalWindow = NULL;
+ wxASSERT_MSG( modalNativeWindow != NULL, "must pass in a toplevel window for modal event loop" );
+ m_modalNativeWindow = modalNativeWindow;
+}
- // 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() ) {}
+// END move into a evtloop_osx.cpp
-#if wxUSE_LOG
- wxLog::Resume();
-#endif // wxUSE_LOG
- m_isInsideYield = false;
- return true;
+void wxModalEventLoop::DoRun()
+{
+ // presentModalViewController:animated:
}
-int wxGUIEventLoop::DispatchTimeout(unsigned long timeout)
+void wxModalEventLoop::DoStop()
{
- wxMacAutoreleasePool autoreleasepool;
-/*
- UIEvent *event = [[UIApplication sharedApplication]
- nextEventMatchingMask:NSAnyEventMask
- untilDate:[NSDate dateWithTimeIntervalSinceNow: timeout/1000]
- inMode:NSDefaultRunLoopMode
- dequeue: YES];
- if ( !event )
- return -1;
-
- [NSApp sendEvent: event];
-*/
- return true;
+ // (void)dismissModalViewControllerAnimated:(BOOL)animated
}