forward compatibility with wx3: accept empty string as well as NULL in places where wx3 uses empty strings only

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@47482 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2007-07-15 14:12:08 +00:00
parent 901abc184c
commit 23536a41a8
2 changed files with 29 additions and 21 deletions

View File

@@ -186,17 +186,17 @@ wxString wxFileSelector(const wxChar *title,
// suitable filter. // suitable filter.
wxString filter2; wxString filter2;
if ( defaultExtension && !filter ) if ( !wxIsEmpty(defaultExtension) && wxIsEmpty(filter) )
filter2 = wxString(wxT("*.")) + defaultExtension; filter2 = wxString(wxT("*.")) + defaultExtension;
else if ( filter ) else if ( !wxIsEmpty(filter) )
filter2 = filter; filter2 = filter;
wxString defaultDirString; wxString defaultDirString;
if (defaultDir) if (!wxIsEmpty(defaultDir))
defaultDirString = defaultDir; defaultDirString = defaultDir;
wxString defaultFilenameString; wxString defaultFilenameString;
if (defaultFileName) if (!wxIsEmpty(defaultFileName))
defaultFilenameString = defaultFileName; defaultFilenameString = defaultFileName;
wxFileDialog fileDialog(parent, title, defaultDirString, wxFileDialog fileDialog(parent, title, defaultDirString,
@@ -249,10 +249,10 @@ wxString wxFileSelectorEx(const wxChar *title,
{ {
wxFileDialog fileDialog(parent, wxFileDialog fileDialog(parent,
title ? title : wxEmptyString, !wxIsEmpty(title) ? title : wxEmptyString,
defaultDir ? defaultDir : wxEmptyString, !wxIsEmpty(defaultDir) ? defaultDir : wxEmptyString,
defaultFileName ? defaultFileName : wxEmptyString, !wxIsEmpty(defaultFileName) ? defaultFileName : wxEmptyString,
filter ? filter : wxEmptyString, !wxIsEmpty(filter) ? filter : wxEmptyString,
flags, wxPoint(x, y)); flags, wxPoint(x, y));
wxString filename; wxString filename;
@@ -287,7 +287,7 @@ static wxString wxDefaultFileSelector(bool load,
wxString wild; wxString wild;
const wxChar *ext = extension; const wxChar *ext = extension;
if ( ext ) if ( !wxIsEmpty(ext) )
{ {
if ( *ext == wxT('.') ) if ( *ext == wxT('.') )
ext++; ext++;

View File

@@ -117,6 +117,11 @@ static bool KeyExists(WXHKEY hRootKey, const wxChar *szKey);
static const wxChar *GetFullName(const wxRegKey *pKey, static const wxChar *GetFullName(const wxRegKey *pKey,
const wxChar *szValue = NULL); const wxChar *szValue = NULL);
static inline const wxChar *RegValueStr(const wxChar *szValue)
{
return wxIsEmpty(szValue) ? NULL : szValue;
}
// ============================================================================ // ============================================================================
// implementation of wxRegKey class // implementation of wxRegKey class
// ============================================================================ // ============================================================================
@@ -475,7 +480,7 @@ bool wxRegKey::CopyValue(const wxChar *szValue,
wxRegKey& keyDst, wxRegKey& keyDst,
const wxChar *szValueNew) const wxChar *szValueNew)
{ {
if ( !szValueNew ) { if ( wxIsEmpty(szValueNew) ) {
// by default, use the same name // by default, use the same name
szValueNew = szValue; szValueNew = szValue;
} }
@@ -714,7 +719,7 @@ bool wxRegKey::DeleteValue(const wxChar *szValue)
if ( !Open() ) if ( !Open() )
return false; return false;
m_dwLastError = RegDeleteValue((HKEY) m_hKey, WXSTRINGCAST szValue); m_dwLastError = RegDeleteValue((HKEY) m_hKey, RegValueStr(szValue));
// deleting a value which doesn't exist is not considered an error // deleting a value which doesn't exist is not considered an error
if ( (m_dwLastError != ERROR_SUCCESS) && if ( (m_dwLastError != ERROR_SUCCESS) &&
@@ -742,7 +747,7 @@ bool wxRegKey::HasValue(const wxChar *szValue) const
return false; return false;
LONG dwRet = ::RegQueryValueEx((HKEY) m_hKey, LONG dwRet = ::RegQueryValueEx((HKEY) m_hKey,
WXSTRINGCAST szValue, RegValueStr(szValue),
RESERVED, RESERVED,
NULL, NULL, NULL); NULL, NULL, NULL);
return dwRet == ERROR_SUCCESS; return dwRet == ERROR_SUCCESS;
@@ -790,7 +795,7 @@ wxRegKey::ValueType wxRegKey::GetValueType(const wxChar *szValue) const
return Type_None; return Type_None;
DWORD dwType; DWORD dwType;
m_dwLastError = RegQueryValueEx((HKEY) m_hKey, WXSTRINGCAST szValue, RESERVED, m_dwLastError = RegQueryValueEx((HKEY) m_hKey, RegValueStr(szValue), RESERVED,
&dwType, NULL, NULL); &dwType, NULL, NULL);
if ( m_dwLastError != ERROR_SUCCESS ) { if ( m_dwLastError != ERROR_SUCCESS ) {
wxLogSysError(m_dwLastError, _("Can't read value of key '%s'"), wxLogSysError(m_dwLastError, _("Can't read value of key '%s'"),
@@ -804,7 +809,7 @@ wxRegKey::ValueType wxRegKey::GetValueType(const wxChar *szValue) const
bool wxRegKey::SetValue(const wxChar *szValue, long lValue) bool wxRegKey::SetValue(const wxChar *szValue, long lValue)
{ {
if ( CONST_CAST Open() ) { if ( CONST_CAST Open() ) {
m_dwLastError = RegSetValueEx((HKEY) m_hKey, szValue, (DWORD) RESERVED, REG_DWORD, m_dwLastError = RegSetValueEx((HKEY) m_hKey, RegValueStr(szValue), (DWORD) RESERVED, REG_DWORD,
(RegString)&lValue, sizeof(lValue)); (RegString)&lValue, sizeof(lValue));
if ( m_dwLastError == ERROR_SUCCESS ) if ( m_dwLastError == ERROR_SUCCESS )
return true; return true;
@@ -820,7 +825,7 @@ bool wxRegKey::QueryValue(const wxChar *szValue, long *plValue) const
if ( CONST_CAST Open(Read) ) { if ( CONST_CAST Open(Read) ) {
DWORD dwType, dwSize = sizeof(DWORD); DWORD dwType, dwSize = sizeof(DWORD);
RegString pBuf = (RegString)plValue; RegString pBuf = (RegString)plValue;
m_dwLastError = RegQueryValueEx((HKEY) m_hKey, WXSTRINGCAST szValue, RESERVED, m_dwLastError = RegQueryValueEx((HKEY) m_hKey, RegValueStr(szValue), RESERVED,
&dwType, pBuf, &dwSize); &dwType, pBuf, &dwSize);
if ( m_dwLastError != ERROR_SUCCESS ) { if ( m_dwLastError != ERROR_SUCCESS ) {
wxLogSysError(m_dwLastError, _("Can't read value of key '%s'"), wxLogSysError(m_dwLastError, _("Can't read value of key '%s'"),
@@ -846,7 +851,7 @@ bool wxRegKey::SetValue(const wxChar *szValue,const wxMemoryBuffer& buffer)
return false; return false;
#else #else
if ( CONST_CAST Open() ) { if ( CONST_CAST Open() ) {
m_dwLastError = RegSetValueEx((HKEY) m_hKey, szValue, (DWORD) RESERVED, REG_BINARY, m_dwLastError = RegSetValueEx((HKEY) m_hKey, RegValueStr(szValue), (DWORD) RESERVED, REG_BINARY,
(RegBinary)buffer.GetData(),buffer.GetDataLen()); (RegBinary)buffer.GetData(),buffer.GetDataLen());
if ( m_dwLastError == ERROR_SUCCESS ) if ( m_dwLastError == ERROR_SUCCESS )
return true; return true;
@@ -863,14 +868,14 @@ bool wxRegKey::QueryValue(const wxChar *szValue, wxMemoryBuffer& buffer) const
if ( CONST_CAST Open(Read) ) { if ( CONST_CAST Open(Read) ) {
// first get the type and size of the data // first get the type and size of the data
DWORD dwType, dwSize; DWORD dwType, dwSize;
m_dwLastError = RegQueryValueEx((HKEY) m_hKey, WXSTRINGCAST szValue, RESERVED, m_dwLastError = RegQueryValueEx((HKEY) m_hKey, RegValueStr(szValue), RESERVED,
&dwType, NULL, &dwSize); &dwType, NULL, &dwSize);
if ( m_dwLastError == ERROR_SUCCESS ) { if ( m_dwLastError == ERROR_SUCCESS ) {
if ( dwSize ) { if ( dwSize ) {
const RegBinary pBuf = (RegBinary)buffer.GetWriteBuf(dwSize); const RegBinary pBuf = (RegBinary)buffer.GetWriteBuf(dwSize);
m_dwLastError = RegQueryValueEx((HKEY) m_hKey, m_dwLastError = RegQueryValueEx((HKEY) m_hKey,
WXSTRINGCAST szValue, RegValueStr(szValue),
RESERVED, RESERVED,
&dwType, &dwType,
pBuf, pBuf,
@@ -903,7 +908,9 @@ bool wxRegKey::QueryValue(const wxChar *szValue,
// first get the type and size of the data // first get the type and size of the data
DWORD dwType=REG_NONE, dwSize=0; DWORD dwType=REG_NONE, dwSize=0;
m_dwLastError = RegQueryValueEx((HKEY) m_hKey, WXSTRINGCAST szValue, RESERVED, m_dwLastError = RegQueryValueEx((HKEY) m_hKey,
RegValueStr(szValue),
RESERVED,
&dwType, NULL, &dwSize); &dwType, NULL, &dwSize);
if ( m_dwLastError == ERROR_SUCCESS ) if ( m_dwLastError == ERROR_SUCCESS )
{ {
@@ -916,7 +923,7 @@ bool wxRegKey::QueryValue(const wxChar *szValue,
else else
{ {
m_dwLastError = RegQueryValueEx((HKEY) m_hKey, m_dwLastError = RegQueryValueEx((HKEY) m_hKey,
WXSTRINGCAST szValue, RegValueStr(szValue),
RESERVED, RESERVED,
&dwType, &dwType,
(RegString)(wxChar*)wxStringBuffer(strValue, dwSize), (RegString)(wxChar*)wxStringBuffer(strValue, dwSize),
@@ -966,7 +973,8 @@ bool wxRegKey::QueryValue(const wxChar *szValue,
bool wxRegKey::SetValue(const wxChar *szValue, const wxString& strValue) bool wxRegKey::SetValue(const wxChar *szValue, const wxString& strValue)
{ {
if ( CONST_CAST Open() ) { if ( CONST_CAST Open() ) {
m_dwLastError = RegSetValueEx((HKEY) m_hKey, szValue, (DWORD) RESERVED, REG_SZ, m_dwLastError = RegSetValueEx((HKEY) m_hKey, RegValueStr(szValue),
(DWORD) RESERVED, REG_SZ,
(RegString)strValue.c_str(), (RegString)strValue.c_str(),
(strValue.Len() + 1)*sizeof(wxChar)); (strValue.Len() + 1)*sizeof(wxChar));
if ( m_dwLastError == ERROR_SUCCESS ) if ( m_dwLastError == ERROR_SUCCESS )