made wxApp::argv an object convertible to either char** or wchar_t** for better compatibility with the existing ANSI code

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49877 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-11-12 22:32:23 +00:00
parent d2263bbca3
commit 541ea80f0e
15 changed files with 865 additions and 546 deletions
+2
View File
@@ -306,6 +306,7 @@ ALL_BASE_HEADERS = \
wx/chartype.h \
wx/chkconf.h \
wx/clntdata.h \
wx/cmdargs.h \
wx/cmdline.h \
wx/confbase.h \
wx/config.h \
@@ -447,6 +448,7 @@ ALL_PORTS_BASE_HEADERS = \
wx/chartype.h \
wx/chkconf.h \
wx/clntdata.h \
wx/cmdargs.h \
wx/cmdline.h \
wx/confbase.h \
wx/config.h \
+1
View File
@@ -412,6 +412,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
wx/chartype.h
wx/chkconf.h
wx/clntdata.h
wx/cmdargs.h
wx/cmdline.h
wx/confbase.h
wx/config.h
+156 -136
View File
File diff suppressed because it is too large Load Diff
+160 -136
View File
File diff suppressed because it is too large Load Diff
+156 -136
View File
File diff suppressed because it is too large Load Diff
+160 -136
View File
File diff suppressed because it is too large Load Diff
+4
View File
@@ -1515,6 +1515,10 @@ SOURCE=..\..\include\wx\clntdata.h
# End Source File
# Begin Source File
SOURCE=..\..\include\wx\cmdargs.h
# End Source File
# Begin Source File
SOURCE=..\..\include\wx\cmdline.h
# End Source File
# Begin Source File
+63
View File
@@ -4144,6 +4144,69 @@ SOURCE=..\..\src\generic\accel.cpp
!ELSEIF "$(CFG)" == "core - Win32 Universal Debug"
!ELSEIF "$(CFG)" == "core - Win32 Unicode Release"
# PROP Exclude_From_Build 1
!ELSEIF "$(CFG)" == "core - Win32 Unicode Debug"
# PROP Exclude_From_Build 1
!ELSEIF "$(CFG)" == "core - Win32 Release"
# PROP Exclude_From_Build 1
!ELSEIF "$(CFG)" == "core - Win32 Debug"
# PROP Exclude_From_Build 1
!ENDIF
# End Source File
# Begin Source File
SOURCE=..\..\src\generic\animateg.cpp
!IF "$(CFG)" == "core - Win32 DLL Universal Unicode Release"
!ELSEIF "$(CFG)" == "core - Win32 DLL Universal Unicode Debug"
!ELSEIF "$(CFG)" == "core - Win32 DLL Universal Release"
!ELSEIF "$(CFG)" == "core - Win32 DLL Universal Debug"
!ELSEIF "$(CFG)" == "core - Win32 DLL Unicode Release"
# PROP Exclude_From_Build 1
!ELSEIF "$(CFG)" == "core - Win32 DLL Unicode Debug"
# PROP Exclude_From_Build 1
!ELSEIF "$(CFG)" == "core - Win32 DLL Release"
# PROP Exclude_From_Build 1
!ELSEIF "$(CFG)" == "core - Win32 DLL Debug"
# PROP Exclude_From_Build 1
!ELSEIF "$(CFG)" == "core - Win32 Universal Unicode Release"
!ELSEIF "$(CFG)" == "core - Win32 Universal Unicode Debug"
!ELSEIF "$(CFG)" == "core - Win32 Universal Release"
!ELSEIF "$(CFG)" == "core - Win32 Universal Debug"
!ELSEIF "$(CFG)" == "core - Win32 Unicode Release"
# PROP Exclude_From_Build 1
+12 -2
View File
@@ -19,6 +19,7 @@
#include "wx/event.h" // for the base class
#include "wx/build.h"
#include "wx/cmdargs.h" // for wxCmdLineArgsArray used by wxApp::argv
#include "wx/init.h" // we must declare wxEntry()
#include "wx/intl.h" // for wxLayoutDirection
@@ -316,8 +317,17 @@ public:
// command line arguments (public for backwards compatibility)
int argc;
wxChar **argv;
int argc;
// this object is implicitly convertible to either "char**" (traditional
// type of argv parameter of main()) or to "wchar_t **" (for compatibility
// with Unicode build in previous wx versions and because the command line
// can, in pr
#if wxUSE_UNICODE
wxCmdLineArgsArray argv;
#else
char **argv;
#endif
protected:
// the function which creates the traits object when GetTraits() needs it
+128
View File
@@ -0,0 +1,128 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/cmdargs.h
// Purpose: declaration of wxCmdLineArgsArray helper class
// Author: Vadim Zeitlin
// Created: 2007-11-12
// RCS-ID: $Id$
// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_CMDARGS_H_
#define _WX_CMDARGS_H_
#include "wx/arrstr.h"
// ----------------------------------------------------------------------------
// wxCmdLineArgsArray: helper class used by wxApp::argv
// ----------------------------------------------------------------------------
#if wxUSE_UNICODE
// this class is used instead of either "char **" or "wchar_t **" (neither of
// which would be backwards compatible with all the existing code) for argv
// field of wxApp
//
// as it's used for compatibility, it tries to look as much as traditional
// (char **) argv as possible, in particular it provides implicit conversions
// to "char **" and also array-like operator[]
class wxCmdLineArgsArray
{
public:
wxCmdLineArgsArray() { m_argsA = NULL; m_argsW = NULL; }
template <typename T>
wxCmdLineArgsArray& operator=(T **argv)
{
FreeArgs();
m_args.clear();
if ( argv )
{
while ( *argv )
m_args.push_back(*argv++);
}
return *this;
}
operator char**() const
{
if ( !m_argsA )
{
const size_t count = m_args.size();
m_argsA = new char *[count];
for ( size_t n = 0; n < count; n++ )
m_argsA[n] = wxStrdup(m_args[n].ToAscii());
}
return m_argsA;
}
operator wchar_t**() const
{
if ( !m_argsW )
{
const size_t count = m_args.size();
m_argsW = new wchar_t *[count];
for ( size_t n = 0; n < count; n++ )
m_argsW[n] = wxStrdup(m_args[n].wc_str());
}
return m_argsW;
}
// existing code does checks like "if ( argv )" and we want it to continue
// to compile, so provide this conversion even if it is pretty dangerous
operator bool() const
{
return !m_args.empty();
}
wxString operator[](size_t n) const
{
return m_args[n];
}
// this is the only method of this class which doesn't exist solely for
// compatibility purposes: it allows to access the arguments as a
// convenient array of wxStrings
const wxArrayString& GetArguments() const { return m_args; }
~wxCmdLineArgsArray()
{
FreeArgs();
}
private:
template <typename T>
void Free(T **args)
{
if ( !args )
return;
const size_t count = m_args.size();
for ( size_t n = 0; n < count; n++ )
free(args[n]);
delete [] args;
}
void FreeArgs()
{
Free(m_argsA);
Free(m_argsW);
}
wxArrayString m_args;
mutable char **m_argsA;
mutable wchar_t **m_argsW;
DECLARE_NO_COPY_CLASS(wxCmdLineArgsArray)
};
#endif // wxUSE_UNICODE
#endif // _WX_CMDARGS_H_
+8
View File
@@ -17,6 +17,7 @@
#include "wx/string.h"
#include "wx/arrstr.h"
#include "wx/cmdargs.h"
#if wxUSE_CMDLINE_PARSER
@@ -104,6 +105,8 @@ public:
wxCmdLineParser(int argc, char **argv) { Init(); SetCmdLine(argc, argv); }
#if wxUSE_UNICODE
wxCmdLineParser(int argc, wxChar **argv) { Init(); SetCmdLine(argc, argv); }
wxCmdLineParser(int argc, const wxCmdLineArgsArray& argv)
{ Init(); SetCmdLine(argc, argv); }
#endif // wxUSE_UNICODE
wxCmdLineParser(const wxString& cmdline) { Init(); SetCmdLine(cmdline); }
@@ -116,6 +119,10 @@ public:
#if wxUSE_UNICODE
wxCmdLineParser(const wxCmdLineEntryDesc *desc, int argc, wxChar **argv)
{ Init(); SetCmdLine(argc, argv); SetDesc(desc); }
wxCmdLineParser(const wxCmdLineEntryDesc *desc,
int argc,
const wxCmdLineArgsArray& argv)
{ Init(); SetCmdLine(argc, argv); SetDesc(desc); }
#endif // wxUSE_UNICODE
wxCmdLineParser(const wxCmdLineEntryDesc *desc, const wxString& cmdline)
{ Init(); SetCmdLine(cmdline); SetDesc(desc); }
@@ -124,6 +131,7 @@ public:
void SetCmdLine(int argc, char **argv);
#if wxUSE_UNICODE
void SetCmdLine(int argc, wxChar **argv);
void SetCmdLine(int argc, const wxCmdLineArgsArray& argv);
#endif // wxUSE_UNICODE
void SetCmdLine(const wxString& cmdline);
+12
View File
@@ -193,6 +193,7 @@ struct wxCmdLineParserData
void SetArguments(int argc, char **argv);
#if wxUSE_UNICODE
void SetArguments(int argc, wxChar **argv);
void SetArguments(int argc, const wxCmdLineArgsArray& argv);
#endif // wxUSE_UNICODE
void SetArguments(const wxString& cmdline);
@@ -240,6 +241,12 @@ void wxCmdLineParserData::SetArguments(int argc, wxChar **argv)
}
}
void wxCmdLineParserData::SetArguments(int WXUNUSED(argc),
const wxCmdLineArgsArray& argv)
{
m_arguments = argv.GetArguments();
}
#endif // wxUSE_UNICODE
void wxCmdLineParserData::SetArguments(const wxString& cmdLine)
@@ -310,6 +317,11 @@ void wxCmdLineParser::SetCmdLine(int argc, wxChar **argv)
m_data->SetArguments(argc, argv);
}
void wxCmdLineParser::SetCmdLine(int argc, const wxCmdLineArgsArray& argv)
{
m_data->SetArguments(argc, argv);
}
#endif // wxUSE_UNICODE
void wxCmdLineParser::SetCmdLine(const wxString& cmdline)
+1
View File
@@ -219,6 +219,7 @@ wx/build.h
wx/chartype.h
wx/chkconf.h
wx/clntdata.h
wx/cmdargs.h
wx/cmdline.h
wx/confbase.h
wx/config.h
+1
View File
@@ -124,6 +124,7 @@ wx/build.h
wx/chartype.h
wx/chkconf.h
wx/clntdata.h
wx/cmdargs.h
wx/cmdline.h
wx/confbase.h
wx/config.h
+1
View File
@@ -148,6 +148,7 @@ wx/build.h
wx/chartype.h
wx/chkconf.h
wx/clntdata.h
wx/cmdargs.h
wx/cmdline.h
wx/confbase.h
wx/config.h