added cmd line parsing support to wxApp and --theme option to wxUniv

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10952 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2001-07-10 17:28:19 +00:00
parent a5bb60ce35
commit bf188f1add
5 changed files with 307 additions and 77 deletions

View File

@@ -30,20 +30,22 @@
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/intl.h"
#include "wx/list.h"
#endif
#include "wx/cmdline.h"
#include "wx/thread.h"
#include "wx/confbase.h"
#ifdef __WXUNIVERSAL__
#include "wx/univ/theme.h"
#endif // __WXUNIVERSAL__
// ===========================================================================
// implementation
// ===========================================================================
// ----------------------------------------------------------------------------
// initialization and termination
// ----------------------------------------------------------------------------
wxAppBase::wxAppBase()
{
wxTheApp = (wxApp *)this;
@@ -59,15 +61,11 @@ wxAppBase::wxAppBase()
#endif // wxUSE_GUI
}
// ----------------------------------------------------------------------------
// initialization and termination
// ----------------------------------------------------------------------------
#if wxUSE_GUI
bool wxAppBase::OnInitGui()
{
#ifdef __WXUNIVERSAL__
if ( !wxTheme::CreateDefault() )
if ( !wxTheme::Get() && !wxTheme::CreateDefault() )
return FALSE;
#endif // __WXUNIVERSAL__
@@ -136,3 +134,127 @@ void wxAppBase::SetActive(bool active, wxWindow * WXUNUSED(lastFocus))
}
#endif // wxUSE_GUI
// ----------------------------------------------------------------------------
// cmd line parsing
// ----------------------------------------------------------------------------
bool wxAppBase::OnInit()
{
#if wxUSE_CMDLINE_PARSER
wxCmdLineParser parser(argc, argv);
OnInitCmdLine(parser);
bool cont;
switch ( parser.Parse() )
{
case -1:
cont = OnCmdLineHelp(parser);
break;
case 0:
cont = OnCmdLineParsed(parser);
break;
default:
cont = OnCmdLineError(parser);
break;
}
if ( !cont )
return FALSE;
#endif // wxUSE_CMDLINE_PARSER
return TRUE;
}
#if wxUSE_CMDLINE_PARSER
#define OPTION_VERBOSE _T("verbose")
#define OPTION_THEME _T("theme")
void wxAppBase::OnInitCmdLine(wxCmdLineParser& parser)
{
// the standard command line options
static const wxCmdLineEntryDesc cmdLineDesc[] =
{
{
wxCMD_LINE_SWITCH,
_T("h"),
_T("help"),
gettext_noop("show this help message"),
wxCMD_LINE_VAL_NONE,
wxCMD_LINE_OPTION_HELP
},
#if wxUSE_LOG
{
wxCMD_LINE_SWITCH,
_T(""),
OPTION_VERBOSE,
gettext_noop("generate verbose log messages")
},
#endif wxUSE_LOG
#ifdef __WXUNIVERSAL__
{
wxCMD_LINE_OPTION,
_T(""),
OPTION_THEME,
gettext_noop("specify the theme to use"),
wxCMD_LINE_VAL_STRING
},
#endif // __WXUNIVERSAL__
// terminator
{ wxCMD_LINE_NONE }
};
parser.SetDesc(cmdLineDesc);
}
bool wxAppBase::OnCmdLineParsed(wxCmdLineParser& parser)
{
#if wxUSE_LOG
if ( parser.Found(OPTION_VERBOSE) )
{
wxLog::SetVerbose(TRUE);
}
#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;
}
wxTheme::Set(theme);
}
#endif // __WXUNIVERSAL__
return TRUE;
}
bool wxAppBase::OnCmdLineHelp(wxCmdLineParser& parser)
{
parser.Usage();
return FALSE;
}
bool wxAppBase::OnCmdLineError(wxCmdLineParser& parser)
{
parser.Usage();
return FALSE;
}
#endif // wxUSE_CMDLINE_PARSER