From b913d3ed6e9683c477fac4c12021f5e53bdf5675 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 3 Aug 2003 21:00:52 +0000 Subject: [PATCH] moved wxUniv-specific GUI stuff from wxBase to wxCore; this fixes wxUniv DLL build git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22542 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/app.h | 16 +++++- src/common/appbase.cpp | 64 ------------------------ src/common/appcmn.cpp | 111 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 121 insertions(+), 70 deletions(-) diff --git a/include/wx/app.h b/include/wx/app.h index c95c47751c..a7459b0269 100644 --- a/include/wx/app.h +++ b/include/wx/app.h @@ -170,11 +170,13 @@ public: #if wxUSE_CMDLINE_PARSER // this one is called from OnInit() to add all supported options - // to the given parser + // to the given parser (don't forget to call the base class version if you + // override it!) virtual void OnInitCmdLine(wxCmdLineParser& parser); // called after successfully parsing the command line, return TRUE - // to continue and FALSE to exit + // to continue and FALSE to exit (don't forget to call the base class + // version if you override it!) virtual bool OnCmdLineParsed(wxCmdLineParser& parser); // called if "--help" option was specified, return TRUE to continue @@ -346,6 +348,9 @@ public: // Override: rarely in GUI applications, always in console ones. virtual int OnRun(); + // a matching function for OnInit() + virtual int OnExit(); + // very last clean up function // // Override: very rarely @@ -457,6 +462,13 @@ public: int GetPrintMode() const { return wxPRINT_POSTSCRIPT; } + // command line parsing (GUI-specific) + // ------------------------------------------------------------------------ + + virtual bool OnCmdLineParsed(wxCmdLineParser& parser); + virtual void OnInitCmdLine(wxCmdLineParser& parser); + + // miscellaneous other stuff // ------------------------------------------------------------------------ diff --git a/src/common/appbase.cpp b/src/common/appbase.cpp index 5971f3962b..40747cb053 100644 --- a/src/common/appbase.cpp +++ b/src/common/appbase.cpp @@ -182,10 +182,6 @@ int wxAppConsole::OnExit() delete wxConfigBase::Set((wxConfigBase *) NULL); #endif // wxUSE_CONFIG -#ifdef __WXUNIVERSAL__ - delete wxTheme::Set(NULL); -#endif // __WXUNIVERSAL__ - // use Set(NULL) and not Get() to avoid creating a message output object on // demand when we just want to delete it delete wxMessageOutput::Set(NULL); @@ -288,8 +284,6 @@ int wxAppConsole::FilterEvent(wxEvent& WXUNUSED(event)) #if wxUSE_CMDLINE_PARSER #define OPTION_VERBOSE _T("verbose") -#define OPTION_THEME _T("theme") -#define OPTION_MODE _T("mode") void wxAppConsole::OnInitCmdLine(wxCmdLineParser& parser) { @@ -316,31 +310,6 @@ void wxAppConsole::OnInitCmdLine(wxCmdLineParser& parser) }, #endif // wxUSE_LOG -#ifdef __WXUNIVERSAL__ - { - wxCMD_LINE_OPTION, - _T(""), - OPTION_THEME, - gettext_noop("specify the theme to use"), - wxCMD_LINE_VAL_STRING, - 0x0 - }, -#endif // __WXUNIVERSAL__ - -#if defined(__WXMGL__) - // VS: this is not specific to wxMGL, all fullscreen (framebuffer) ports - // should provide this option. That's why it is in common/appcmn.cpp - // and not mgl/app.cpp - { - wxCMD_LINE_OPTION, - _T(""), - OPTION_MODE, - gettext_noop("specify display mode to use (e.g. 640x480-16)"), - wxCMD_LINE_VAL_STRING, - 0x0 - }, -#endif // __WXMGL__ - // terminator { wxCMD_LINE_NONE, @@ -364,39 +333,6 @@ bool wxAppConsole::OnCmdLineParsed(wxCmdLineParser& parser) } #endif // wxUSE_LOG -#ifdef __WXUNIVERSAL__ - wxString themeName; - if ( parser.Found(OPTION_THEME, &themeName) ) - { - wxTheme *theme = wxTheme::Create(themeName); - if ( !theme ) - { - wxLogError(_("Unsupported theme '%s'."), themeName.c_str()); - return FALSE; - } - - // Delete the defaultly created theme and set the new theme. - delete wxTheme::Get(); - wxTheme::Set(theme); - } -#endif // __WXUNIVERSAL__ - -#if defined(__WXMGL__) - wxString modeDesc; - if ( parser.Found(OPTION_MODE, &modeDesc) ) - { - unsigned w, h, bpp; - if ( wxSscanf(modeDesc.c_str(), _T("%ux%u-%u"), &w, &h, &bpp) != 3 ) - { - wxLogError(_("Invalid display mode specification '%s'."), modeDesc.c_str()); - return FALSE; - } - - if ( !SetDisplayMode(wxDisplayModeInfo(w, h, bpp)) ) - return FALSE; - } -#endif // __WXMGL__ - return TRUE; } diff --git a/src/common/appcmn.cpp b/src/common/appcmn.cpp index 3d7af86d6c..d70ff7bc23 100644 --- a/src/common/appcmn.cpp +++ b/src/common/appcmn.cpp @@ -40,6 +40,7 @@ #endif #include "wx/apptrait.h" +#include "wx/cmdline.h" #include "wx/msgout.h" #include "wx/thread.h" #include "wx/utils.h" @@ -128,13 +129,106 @@ void wxAppBase::CleanUp() delete wxPendingEventsLocker; wxPendingEventsLocker = NULL; -#if wxUSE_VALIDATORS - // If we don't do the following, we get an apparent memory leak. - ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker(); -#endif // wxUSE_VALIDATORS + #if wxUSE_VALIDATORS + // If we don't do the following, we get an apparent memory leak. + ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker(); + #endif // wxUSE_VALIDATORS #endif // wxUSE_THREADS } +#if wxUSE_CMDLINE_PARSER + +// ---------------------------------------------------------------------------- +// GUI-specific command line options handling +// ---------------------------------------------------------------------------- + +#define OPTION_THEME _T("theme") +#define OPTION_MODE _T("mode") + +void wxAppBase::OnInitCmdLine(wxCmdLineParser& parser) +{ + // the standard command line options + static const wxCmdLineEntryDesc cmdLineGUIDesc[] = + { +#ifdef __WXUNIVERSAL__ + { + wxCMD_LINE_OPTION, + _T(""), + OPTION_THEME, + gettext_noop("specify the theme to use"), + wxCMD_LINE_VAL_STRING, + 0x0 + }, +#endif // __WXUNIVERSAL__ + +#if defined(__WXMGL__) + // VS: this is not specific to wxMGL, all fullscreen (framebuffer) ports + // should provide this option. That's why it is in common/appcmn.cpp + // and not mgl/app.cpp + { + wxCMD_LINE_OPTION, + _T(""), + OPTION_MODE, + gettext_noop("specify display mode to use (e.g. 640x480-16)"), + wxCMD_LINE_VAL_STRING, + 0x0 + }, +#endif // __WXMGL__ + + // terminator + { + wxCMD_LINE_NONE, + _T(""), + _T(""), + _T(""), + wxCMD_LINE_VAL_NONE, + 0x0 + } + }; + + parser.SetDesc(cmdLineGUIDesc); +} + +bool wxAppBase::OnCmdLineParsed(wxCmdLineParser& parser) +{ +#ifdef __WXUNIVERSAL__ + wxString themeName; + if ( parser.Found(OPTION_THEME, &themeName) ) + { + wxTheme *theme = wxTheme::Create(themeName); + if ( !theme ) + { + wxLogError(_("Unsupported theme '%s'."), themeName.c_str()); + return FALSE; + } + + // Delete the defaultly created theme and set the new theme. + delete wxTheme::Get(); + wxTheme::Set(theme); + } +#endif // __WXUNIVERSAL__ + +#if defined(__WXMGL__) + wxString modeDesc; + if ( parser.Found(OPTION_MODE, &modeDesc) ) + { + unsigned w, h, bpp; + if ( wxSscanf(modeDesc.c_str(), _T("%ux%u-%u"), &w, &h, &bpp) != 3 ) + { + wxLogError(_("Invalid display mode specification '%s'."), modeDesc.c_str()); + return FALSE; + } + + if ( !SetDisplayMode(wxDisplayModeInfo(w, h, bpp)) ) + return FALSE; + } +#endif // __WXMGL__ + + return wxAppConsole::OnCmdLineParsed(parser); +} + +#endif // wxUSE_CMDLINE_PARSER + // ---------------------------------------------------------------------------- // OnXXX() hooks // ---------------------------------------------------------------------------- @@ -162,6 +256,15 @@ int wxAppBase::OnRun() return MainLoop(); } +int wxAppBase::OnExit() +{ +#ifdef __WXUNIVERSAL__ + delete wxTheme::Set(NULL); +#endif // __WXUNIVERSAL__ + + return wxAppConsole::OnExit(); +} + void wxAppBase::Exit() { ExitMainLoop(); -- 2.45.2