X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/000eea7a2ef45e4053b66bdcc8fd57bfb2e907de..12b5f4b4d2d8a07962da7ba3b78c8c1ec2634a67:/src/common/appbase.cpp diff --git a/src/common/appbase.cpp b/src/common/appbase.cpp index e7eec2c75e..740deebb2b 100644 --- a/src/common/appbase.cpp +++ b/src/common/appbase.cpp @@ -51,29 +51,18 @@ #include #endif +#ifndef __WXPALMOS5__ #if !defined(__WXMSW__) || defined(__WXMICROWIN__) #include // for SIGTRAP used by wxTrap() #endif //Win/Unix #include +#endif // ! __WXPALMOS5__ #if wxUSE_FONTMAP #include "wx/fontmap.h" #endif // wxUSE_FONTMAP -#if defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS - // For MacTypes.h for Debugger function - #include -#endif - -#if defined(__WXMAC__) - #ifdef __DARWIN__ - #include - #else - #include "wx/mac/private.h" // includes mac headers - #endif -#endif // __WXMAC__ - #ifdef __WXDEBUG__ #if wxUSE_STACKWALKER #include "wx/stackwalk.h" @@ -122,6 +111,8 @@ wxAppConsole *wxAppConsoleBase::ms_appInstance = NULL; wxAppInitializerFunction wxAppConsoleBase::ms_appInitFn = NULL; +wxSocketManager *wxAppTraitsBase::ms_manager = NULL; + // ---------------------------------------------------------------------------- // wxEventLoopPtr // ---------------------------------------------------------------------------- @@ -142,7 +133,7 @@ wxAppConsoleBase::wxAppConsoleBase() m_traits = NULL; m_mainLoop = NULL; - ms_appInstance = wx_static_cast(wxAppConsole *, this); + ms_appInstance = static_cast(this); #ifdef __WXDEBUG__ SetTraceMasks(); @@ -165,22 +156,18 @@ wxAppConsoleBase::~wxAppConsoleBase() // initilization/cleanup // ---------------------------------------------------------------------------- -bool wxAppConsoleBase::Initialize(int& argcOrig, wxChar **argvOrig) +bool wxAppConsoleBase::Initialize(int& WXUNUSED(argc), wxChar **argv) { #if wxUSE_INTL GetTraits()->SetLocale(); #endif // wxUSE_INTL - // remember the command line arguments - argc = argcOrig; - argv = argvOrig; - #if wxUSE_THREADS - wxPendingEventsLocker = new wxCriticalSection; + wxHandlersWithPendingEventsLocker = new wxCriticalSection; #endif #ifndef __WXPALMOS__ - if ( m_appName.empty() && argv ) + if ( m_appName.empty() && argv && argv[0] ) { // the application name is, by default, the name of its executable file wxFileName::SplitPath(argv[0], NULL, &m_appName, NULL); @@ -203,12 +190,12 @@ void wxAppConsoleBase::CleanUp() m_mainLoop = NULL; } - delete wxPendingEvents; - wxPendingEvents = NULL; + delete wxHandlersWithPendingEvents; + wxHandlersWithPendingEvents = NULL; #if wxUSE_THREADS - delete wxPendingEventsLocker; - wxPendingEventsLocker = NULL; + delete wxHandlersWithPendingEventsLocker; + wxHandlersWithPendingEventsLocker = NULL; #endif // wxUSE_THREADS } @@ -256,7 +243,7 @@ int wxAppConsoleBase::OnExit() #if wxUSE_CONFIG // delete the config object if any (don't use Get() here, but Set() // because Get() could create a new config object) - delete wxConfigBase::Set((wxConfigBase *) NULL); + delete wxConfigBase::Set(NULL); #endif // wxUSE_CONFIG return 0; @@ -292,6 +279,13 @@ wxAppTraits *wxAppConsoleBase::GetTraits() return m_traits; } +/* static */ +wxAppTraits *wxAppConsoleBase::GetTraitsIfExists() +{ + wxAppConsole * const app = GetInstance(); + return app ? app->GetTraits() : NULL; +} + // ---------------------------------------------------------------------------- // event processing // ---------------------------------------------------------------------------- @@ -333,11 +327,11 @@ bool wxAppConsoleBase::Dispatch() bool wxAppConsoleBase::HasPendingEvents() const { - wxENTER_CRIT_SECT( *wxPendingEventsLocker ); + wxENTER_CRIT_SECT( *wxHandlersWithPendingEventsLocker ); - bool has = wxPendingEvents && !wxPendingEvents->IsEmpty(); + bool has = wxHandlersWithPendingEvents && !wxHandlersWithPendingEvents->IsEmpty(); - wxLEAVE_CRIT_SECT( *wxPendingEventsLocker ); + wxLEAVE_CRIT_SECT( *wxHandlersWithPendingEventsLocker ); return has; } @@ -353,34 +347,34 @@ bool wxAppConsoleBase::IsMainLoopRunning() void wxAppConsoleBase::ProcessPendingEvents() { #if wxUSE_THREADS - if ( !wxPendingEventsLocker ) + if ( !wxHandlersWithPendingEventsLocker ) return; #endif - wxENTER_CRIT_SECT( *wxPendingEventsLocker ); + wxENTER_CRIT_SECT( *wxHandlersWithPendingEventsLocker ); - if (wxPendingEvents) + if (wxHandlersWithPendingEvents) { // iterate until the list becomes empty: the handlers remove themselves // from it when they don't have any more pending events - wxList::compatibility_iterator node = wxPendingEvents->GetFirst(); + wxList::compatibility_iterator node = wxHandlersWithPendingEvents->GetFirst(); while (node) { // In ProcessPendingEvents(), new handlers might be add // and we can safely leave the critical section here. - wxLEAVE_CRIT_SECT( *wxPendingEventsLocker ); + wxLEAVE_CRIT_SECT( *wxHandlersWithPendingEventsLocker ); wxEvtHandler *handler = (wxEvtHandler *)node->GetData(); handler->ProcessPendingEvents(); - wxENTER_CRIT_SECT( *wxPendingEventsLocker ); + wxENTER_CRIT_SECT( *wxHandlersWithPendingEventsLocker ); // restart as the iterators could have been invalidated - node = wxPendingEvents->GetFirst(); + node = wxHandlersWithPendingEvents->GetFirst(); } } - wxLEAVE_CRIT_SECT( *wxPendingEventsLocker ); + wxLEAVE_CRIT_SECT( *wxHandlersWithPendingEventsLocker ); } void wxAppConsoleBase::WakeUpIdle() @@ -391,6 +385,9 @@ void wxAppConsoleBase::WakeUpIdle() bool wxAppConsoleBase::ProcessIdle() { + // process pending wx events before sending idle events + ProcessPendingEvents(); + wxIdleEvent event; event.SetEventObject(this); @@ -419,6 +416,20 @@ wxAppConsoleBase::HandleEvent(wxEvtHandler *handler, (handler->*func)(event); } +void wxAppConsoleBase::CallEventHandler(wxEvtHandler *handler, + wxEventFunctor& functor, + wxEvent& event) const +{ + // If the functor holds a method then, for backward compatibility, call + // HandleEvent(): + wxEventFunction eventFunction = functor.GetMethod(); + + if ( eventFunction ) + HandleEvent(handler, eventFunction, event); + else + functor(handler, event); +} + void wxAppConsoleBase::OnUnhandledException() { #ifdef __WXDEBUG__ @@ -675,12 +686,16 @@ void wxAppTraitsBase::MutexGuiLeave() void WXDLLIMPEXP_BASE wxMutexGuiEnter() { - wxAppConsoleBase::GetInstance()->GetTraits()->MutexGuiEnter(); + wxAppTraits * const traits = wxAppConsoleBase::GetTraitsIfExists(); + if ( traits ) + traits->MutexGuiEnter(); } void WXDLLIMPEXP_BASE wxMutexGuiLeave() { - wxAppConsoleBase::GetInstance()->GetTraits()->MutexGuiLeave(); + wxAppTraits * const traits = wxAppConsoleBase::GetTraitsIfExists(); + if ( traits ) + traits->MutexGuiLeave(); } #endif // wxUSE_THREADS