X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/38bb138f09688c1575766aafdbf296dfeeee0d7d..5ce61d9fd2a225e5579c07a60a71bd481a282d99:/src/common/appcmn.cpp diff --git a/src/common/appcmn.cpp b/src/common/appcmn.cpp index 906f2c48d5..1255c30938 100644 --- a/src/common/appcmn.cpp +++ b/src/common/appcmn.cpp @@ -17,7 +17,7 @@ // headers // --------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "appbase.h" #endif @@ -41,9 +41,11 @@ #include "wx/apptrait.h" #include "wx/cmdline.h" +#include "wx/evtloop.h" #include "wx/msgout.h" #include "wx/thread.h" #include "wx/utils.h" +#include "wx/ptr_scpd.h" #if defined(__WXMSW__) #include "wx/msw/private.h" // includes windows.h for LOGFONT @@ -57,6 +59,14 @@ #include "wx/build.h" WX_CHECK_BUILD_OPTIONS("wxCore") + +// ---------------------------------------------------------------------------- +// wxEventLoopPtr +// ---------------------------------------------------------------------------- + +// this defines wxEventLoopPtr +wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoop); + // ============================================================================ // wxAppBase implementation // ============================================================================ @@ -71,6 +81,10 @@ wxAppBase::wxAppBase() m_useBestVisual = FALSE; m_isActive = TRUE; +#if wxUSE_EVTLOOP_IN_APP + m_mainLoop = NULL; +#endif // wxUSE_EVTLOOP_IN_APP + // 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 // to Yes initially as this dialog would be the last top level window. @@ -126,10 +140,10 @@ void wxAppBase::CleanUp() delete wxTheColourDatabase; wxTheColourDatabase = NULL; -#if wxUSE_THREADS delete wxPendingEvents; wxPendingEvents = NULL; +#if wxUSE_THREADS delete wxPendingEventsLocker; wxPendingEventsLocker = NULL; @@ -226,7 +240,7 @@ bool wxAppBase::OnCmdLineParsed(wxCmdLineParser& parser) return FALSE; } - if ( !SetDisplayMode(wxDisplayModeInfo(w, h, bpp)) ) + if ( !SetDisplayMode(wxVideoMode(w, h, bpp)) ) return FALSE; } #endif // __WXMGL__ @@ -236,6 +250,59 @@ bool wxAppBase::OnCmdLineParsed(wxCmdLineParser& parser) #endif // wxUSE_CMDLINE_PARSER +// ---------------------------------------------------------------------------- +// main event loop implementation +// ---------------------------------------------------------------------------- + +int wxAppBase::MainLoop() +{ +#if wxUSE_EVTLOOP_IN_APP + wxEventLoopTiedPtr mainLoop(&m_mainLoop, new wxEventLoop); + + return m_mainLoop->Run(); +#else // !wxUSE_EVTLOOP_IN_APP + return 0; +#endif // wxUSE_EVTLOOP_IN_APP/!wxUSE_EVTLOOP_IN_APP +} + +void wxAppBase::ExitMainLoop() +{ +#if wxUSE_EVTLOOP_IN_APP + // 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); + } +#endif // wxUSE_EVTLOOP_IN_APP +} + +bool wxAppBase::Pending() +{ +#if wxUSE_EVTLOOP_IN_APP + // 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(); +#else // wxUSE_EVTLOOP_IN_APP + return false; +#endif // wxUSE_EVTLOOP_IN_APP/!wxUSE_EVTLOOP_IN_APP +} + +bool wxAppBase::Dispatch() +{ +#if wxUSE_EVTLOOP_IN_APP + // see comment in Pending() + wxEventLoop * const loop = wxEventLoop::GetActive(); + + return loop && loop->Dispatch(); +#else // wxUSE_EVTLOOP_IN_APP + return true; +#endif // wxUSE_EVTLOOP_IN_APP/!wxUSE_EVTLOOP_IN_APP +} + // ---------------------------------------------------------------------------- // OnXXX() hooks // ---------------------------------------------------------------------------- @@ -323,7 +390,6 @@ bool wxAppBase::ProcessIdle() wxIdleEvent event; bool needMore = FALSE; wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst(); - node = wxTopLevelWindows.GetFirst(); while (node) { wxWindow* win = node->GetData(); @@ -399,7 +465,12 @@ void wxAppBase::OnIdle(wxIdleEvent& WXUNUSED(event)) wxLog *wxGUIAppTraitsBase::CreateLogTarget() { +#if wxUSE_LOGGUI return new wxLogGui; +#else + // wem ust have something! + return new wxLogStderr; +#endif } #endif // wxUSE_LOG @@ -503,14 +574,25 @@ void wxGUIAppTraitsBase::RemoveFromPendingDelete(wxObject *object) #include "wx/unix/gsockunx.h" #elif defined(__WINDOWS__) #include "wx/msw/gsockmsw.h" -#elif defined(__MAC__) - #include "wx/mac/gsockmac.h" +#elif defined(__WXMAC__) + #include + #define OTUNIXERRORS 1 + #include + #include + #include + + #include "wx/mac/gsockmac.h" #else #error "Must include correct GSocket header here" #endif GSocketGUIFunctionsTable* wxGUIAppTraitsBase::GetSocketGUIFunctionsTable() { +#if defined(__WXMAC__) && !defined(__DARWIN__) + // NB: wxMac CFM does not have any GUI-specific functions in gsocket.c and + // so it doesn't need this table at all + return NULL; +#else // !__WXMAC__ || __DARWIN__ static GSocketGUIFunctionsTable table = { _GSocket_GUI_Init, @@ -525,6 +607,7 @@ GSocketGUIFunctionsTable* wxGUIAppTraitsBase::GetSocketGUIFunctionsTable() _GSocket_Disable_Events }; return &table; +#endif // !__WXMAC__ || __DARWIN__ } #endif