};
// ----------------------------------------------------------------------------
-// wxAppConsole: wxApp for non-GUI applications
+// wxAppConsoleBase: wxApp for non-GUI applications
// ----------------------------------------------------------------------------
-class WXDLLIMPEXP_BASE wxAppConsole : public wxEvtHandler
+class WXDLLIMPEXP_BASE wxAppConsoleBase : public wxEvtHandler
{
public:
// ctor and dtor
- wxAppConsole();
- virtual ~wxAppConsole();
+ wxAppConsoleBase();
+ virtual ~wxAppConsoleBase();
// the virtual functions which may/must be overridden in the derived class
// return true if we're running event loop, i.e. if the events can
// (already) be dispatched
- static bool IsMainLoopRunning()
- {
- const wxAppConsole * const app = GetInstance();
- return app && app->m_mainLoop != NULL;
- }
+ static bool IsMainLoopRunning();
// process all events in the wxPendingEvents list -- it is necessary to
// call this function to process posted events. This happens during each
// the application object is a singleton anyhow, there is no sense in
// copying it
- DECLARE_NO_COPY_CLASS(wxAppConsole)
+ DECLARE_NO_COPY_CLASS(wxAppConsoleBase)
};
+#if defined(__UNIX__)
+ #include "wx/unix/app.h"
+#else
+ typedef wxAppConsoleBase wxAppConsole;
+#endif
+
// ----------------------------------------------------------------------------
// wxAppBase: the common part of wxApp implementations for all platforms
// ----------------------------------------------------------------------------
inline bool wxAppBase::Initialized() { return true; }
#endif // WXWIN_COMPATIBILITY_2_6
-#endif // wxUSE_GUI
-
// ----------------------------------------------------------------------------
// now include the declaration of the real class
// ----------------------------------------------------------------------------
-#if wxUSE_GUI
- #if defined(__WXPALMOS__)
- #include "wx/palmos/app.h"
- #elif defined(__WXMSW__)
- #include "wx/msw/app.h"
- #elif defined(__WXMOTIF__)
- #include "wx/motif/app.h"
- #elif defined(__WXMGL__)
- #include "wx/mgl/app.h"
- #elif defined(__WXDFB__)
- #include "wx/dfb/app.h"
- #elif defined(__WXGTK20__)
- #include "wx/gtk/app.h"
- #elif defined(__WXGTK__)
- #include "wx/gtk1/app.h"
- #elif defined(__WXX11__)
- #include "wx/x11/app.h"
- #elif defined(__WXMAC__)
- #include "wx/mac/app.h"
- #elif defined(__WXCOCOA__)
- #include "wx/cocoa/app.h"
- #elif defined(__WXPM__)
- #include "wx/os2/app.h"
- #endif
+#if defined(__WXPALMOS__)
+ #include "wx/palmos/app.h"
+#elif defined(__WXMSW__)
+ #include "wx/msw/app.h"
+#elif defined(__WXMOTIF__)
+ #include "wx/motif/app.h"
+#elif defined(__WXMGL__)
+ #include "wx/mgl/app.h"
+#elif defined(__WXDFB__)
+ #include "wx/dfb/app.h"
+#elif defined(__WXGTK20__)
+ #include "wx/gtk/app.h"
+#elif defined(__WXGTK__)
+ #include "wx/gtk1/app.h"
+#elif defined(__WXX11__)
+ #include "wx/x11/app.h"
+#elif defined(__WXMAC__)
+ #include "wx/mac/app.h"
+#elif defined(__WXCOCOA__)
+ #include "wx/cocoa/app.h"
+#elif defined(__WXPM__)
+ #include "wx/os2/app.h"
+#endif
+
#else // !GUI
- // wxApp is defined in core and we cannot define another one in wxBase,
- // so we create a different class and typedef it to wxApp instead
- #if defined(__UNIX__)
- #include "wx/unix/app.h"
- class wxApp : public wxAppConsoleUnix { };
- #else
- // allow using just wxApp (instead of wxAppConsole) in console programs
- class wxApp : public wxAppConsole { };
- #endif
+
+// wxApp is defined in core and we cannot define another one in wxBase,
+// so use the preprocessor to allow using wxApp in console programs too
+#define wxApp wxAppConsole
+
#endif // GUI/!GUI
// ----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
// Name: src/common/appbase.cpp
-// Purpose: implements wxAppConsole class
+// Purpose: implements wxAppConsoleBase class
// Author: Vadim Zeitlin
// Modified by:
// Created: 19.06.2003 (extracted from common/appcmn.cpp)
// global vars
// ----------------------------------------------------------------------------
-wxAppConsole *wxAppConsole::ms_appInstance = NULL;
+wxAppConsole *wxAppConsoleBase::ms_appInstance = NULL;
-wxAppInitializerFunction wxAppConsole::ms_appInitFn = NULL;
+wxAppInitializerFunction wxAppConsoleBase::ms_appInitFn = NULL;
// ----------------------------------------------------------------------------
// wxEventLoopPtr
wxDEFINE_TIED_SCOPED_PTR_TYPE(wxEventLoopBase)
// ============================================================================
-// wxAppConsole implementation
+// wxAppConsoleBase implementation
// ============================================================================
// ----------------------------------------------------------------------------
// ctor/dtor
// ----------------------------------------------------------------------------
-wxAppConsole::wxAppConsole()
+wxAppConsoleBase::wxAppConsoleBase()
{
m_traits = NULL;
m_mainLoop = NULL;
- ms_appInstance = this;
+ ms_appInstance = wx_static_cast(wxAppConsole *, this);
#ifdef __WXDEBUG__
SetTraceMasks();
#endif
}
-wxAppConsole::~wxAppConsole()
+wxAppConsoleBase::~wxAppConsoleBase()
{
delete m_traits;
}
// initilization/cleanup
// ----------------------------------------------------------------------------
-bool wxAppConsole::Initialize(int& argcOrig, wxChar **argvOrig)
+bool wxAppConsoleBase::Initialize(int& argcOrig, wxChar **argvOrig)
{
#if wxUSE_INTL
GetTraits()->SetLocale();
return true;
}
-wxEventLoopBase *wxAppConsole::CreateMainLoop()
+wxEventLoopBase *wxAppConsoleBase::CreateMainLoop()
{
return GetTraits()->CreateEventLoop();
}
-void wxAppConsole::CleanUp()
+void wxAppConsoleBase::CleanUp()
{
if ( m_mainLoop )
{
// OnXXX() callbacks
// ----------------------------------------------------------------------------
-bool wxAppConsole::OnInit()
+bool wxAppConsoleBase::OnInit()
{
#if wxUSE_CMDLINE_PARSER
wxCmdLineParser parser(argc, argv);
return true;
}
-int wxAppConsole::OnRun()
+int wxAppConsoleBase::OnRun()
{
return MainLoop();
}
-int wxAppConsole::OnExit()
+int wxAppConsoleBase::OnExit()
{
#if wxUSE_CONFIG
// delete the config object if any (don't use Get() here, but Set()
return 0;
}
-void wxAppConsole::Exit()
+void wxAppConsoleBase::Exit()
{
if (m_mainLoop != NULL)
ExitMainLoop();
// traits stuff
// ----------------------------------------------------------------------------
-wxAppTraits *wxAppConsole::CreateTraits()
+wxAppTraits *wxAppConsoleBase::CreateTraits()
{
return new wxConsoleAppTraits;
}
-wxAppTraits *wxAppConsole::GetTraits()
+wxAppTraits *wxAppConsoleBase::GetTraits()
{
// FIXME-MT: protect this with a CS?
if ( !m_traits )
// event processing
// ----------------------------------------------------------------------------
-int wxAppConsole::MainLoop()
+int wxAppConsoleBase::MainLoop()
{
wxEventLoopBaseTiedPtr mainLoop(&m_mainLoop, CreateMainLoop());
return m_mainLoop ? m_mainLoop->Run() : -1;
}
-void wxAppConsole::ExitMainLoop()
+void wxAppConsoleBase::ExitMainLoop()
{
// we should exit from the main event loop, not just any currently active
// (e.g. modal dialog) event loop
}
}
-bool wxAppConsole::Pending()
+bool wxAppConsoleBase::Pending()
{
// 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
return loop && loop->Pending();
}
-bool wxAppConsole::Dispatch()
+bool wxAppConsoleBase::Dispatch()
{
// see comment in Pending()
wxEventLoopBase * const loop = wxEventLoopBase::GetActive();
return loop && loop->Dispatch();
}
-bool wxAppConsole::HasPendingEvents() const
+bool wxAppConsoleBase::HasPendingEvents() const
{
// ensure that we're the only thread to modify the pending events list
wxENTER_CRIT_SECT( *wxPendingEventsLocker );
return true;
}
-void wxAppConsole::ProcessPendingEvents()
+/* static */
+bool wxAppConsoleBase::IsMainLoopRunning()
+{
+ const wxAppConsole * const app = GetInstance();
+
+ return app && app->m_mainLoop != NULL;
+}
+
+void wxAppConsoleBase::ProcessPendingEvents()
{
#if wxUSE_THREADS
if ( !wxPendingEventsLocker )
wxLEAVE_CRIT_SECT( *wxPendingEventsLocker );
}
-void wxAppConsole::WakeUpIdle()
+void wxAppConsoleBase::WakeUpIdle()
{
if ( m_mainLoop )
m_mainLoop->WakeUp();
}
-bool wxAppConsole::ProcessIdle()
+bool wxAppConsoleBase::ProcessIdle()
{
wxIdleEvent event;
return event.MoreRequested();
}
-int wxAppConsole::FilterEvent(wxEvent& WXUNUSED(event))
+int wxAppConsoleBase::FilterEvent(wxEvent& WXUNUSED(event))
{
// process the events normally by default
return -1;
#if wxUSE_EXCEPTIONS
void
-wxAppConsole::HandleEvent(wxEvtHandler *handler,
- wxEventFunction func,
- wxEvent& event) const
+wxAppConsoleBase::HandleEvent(wxEvtHandler *handler,
+ wxEventFunction func,
+ wxEvent& event) const
{
// by default, simply call the handler
(handler->*func)(event);
#if wxUSE_EXCEPTIONS
-bool wxAppConsole::OnExceptionInMainLoop()
+bool wxAppConsoleBase::OnExceptionInMainLoop()
{
throw;
#define OPTION_VERBOSE _T("verbose")
-void wxAppConsole::OnInitCmdLine(wxCmdLineParser& parser)
+void wxAppConsoleBase::OnInitCmdLine(wxCmdLineParser& parser)
{
// the standard command line options
static const wxCmdLineEntryDesc cmdLineDesc[] =
parser.SetDesc(cmdLineDesc);
}
-bool wxAppConsole::OnCmdLineParsed(wxCmdLineParser& parser)
+bool wxAppConsoleBase::OnCmdLineParsed(wxCmdLineParser& parser)
{
#if wxUSE_LOG
if ( parser.Found(OPTION_VERBOSE) )
return true;
}
-bool wxAppConsole::OnCmdLineHelp(wxCmdLineParser& parser)
+bool wxAppConsoleBase::OnCmdLineHelp(wxCmdLineParser& parser)
{
parser.Usage();
return false;
}
-bool wxAppConsole::OnCmdLineError(wxCmdLineParser& parser)
+bool wxAppConsoleBase::OnCmdLineError(wxCmdLineParser& parser)
{
parser.Usage();
// ----------------------------------------------------------------------------
/* static */
-bool wxAppConsole::CheckBuildOptions(const char *optionsSignature,
- const char *componentName)
+bool wxAppConsoleBase::CheckBuildOptions(const char *optionsSignature,
+ const char *componentName)
{
#if 0 // can't use wxLogTrace, not up and running yet
printf("checking build options object '%s' (ptr %p) in '%s'\n",
#ifdef __WXDEBUG__
-void wxAppConsole::OnAssertFailure(const wxChar *file,
- int line,
- const wxChar *func,
- const wxChar *cond,
- const wxChar *msg)
+void wxAppConsoleBase::OnAssertFailure(const wxChar *file,
+ int line,
+ const wxChar *func,
+ const wxChar *cond,
+ const wxChar *msg)
{
ShowAssertDialog(file, line, func, cond, msg, GetTraits());
}
-void wxAppConsole::OnAssert(const wxChar *file,
- int line,
- const wxChar *cond,
- const wxChar *msg)
+void wxAppConsoleBase::OnAssert(const wxChar *file,
+ int line,
+ const wxChar *cond,
+ const wxChar *msg)
{
OnAssertFailure(file, line, NULL, cond, msg);
}
#include "wx/log.h"
#include "wx/evtloop.h"
-//this code should not be compiled when GUI is defined
-//(monolithic build issue)
-#if !wxUSE_GUI
-
#include <signal.h>
#include <unistd.h>
-bool wxAppConsoleUnix::Initialize(int& argc, wxChar** argv)
+bool wxAppConsole::Initialize(int& argc, wxChar** argv)
{
- if ( !wxAppConsole::Initialize(argc,argv) )
- return false;
-
- if ( !m_mainLoop->IsOk() )
+ if ( !wxAppConsoleBase::Initialize(argc,argv) )
return false;
sigemptyset(&m_signalsCaught);
return true;
}
-void wxAppConsoleUnix::HandleSignal(int signal)
+void wxAppConsole::HandleSignal(int signal)
{
- wxAppConsoleUnix * const app = wxTheApp;
+ wxAppConsole * const app = wxTheApp;
if ( !app )
return;
app->WakeUpIdle();
}
-void wxAppConsoleUnix::CheckSignal()
+void wxAppConsole::CheckSignal()
{
for ( SignalHandlerHash::iterator it = m_signalHandlerHash.begin();
it != m_signalHandlerHash.end();
}
}
-bool wxAppConsoleUnix::SetSignalHandler(int signal, SignalHandler handler)
+bool wxAppConsole::SetSignalHandler(int signal, SignalHandler handler)
{
const bool install = handler != SIG_DFL && handler != SIG_IGN;
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
- sa.sa_handler = &wxAppConsoleUnix::HandleSignal;
+ sa.sa_handler = &wxAppConsole::HandleSignal;
sa.sa_flags = SA_RESTART;
int res = sigaction(signal, &sa, 0);
if ( res != 0 )
return true;
}
-#endif // !wxUSE_GUI