Allow expanding environment variables in XRC file paths

Add a new flag wxXRC_USE_ENVVARS for wxXmlResourceFlags that triggers a
call to wxExpandEnvVars() for bitmap, icon and animation paths.

This flag is not set by default to avoid silently changing the behaviour
of existing applications.

Closes https://github.com/wxWidgets/wxWidgets/pull/1445
This commit is contained in:
ousnius
2019-07-28 13:36:19 +02:00
committed by Vadim Zeitlin
parent cd2e3dd2cf
commit 2a2fa8c5af
6 changed files with 55 additions and 6 deletions

View File

@@ -44,6 +44,7 @@
#include "wx/xml/xml.h"
#include "wx/hashset.h"
#include "wx/scopedptr.h"
#include "wx/config.h"
#include <limits.h>
#include <locale.h>
@@ -1825,7 +1826,7 @@ wxBitmap wxXmlResourceHandlerImpl::GetBitmap(const wxXmlNode* node,
}
/* ...or load the bitmap from file: */
wxString name = GetParamValue(node);
wxString name = GetFilePath(node);
if (name.empty()) return wxNullBitmap;
#if wxUSE_FILESYSTEM
wxFSFile *fsfile = GetCurFileSystem().OpenFile(name, wxFS_READ | wxFS_SEEKABLE);
@@ -1898,7 +1899,7 @@ wxIconBundle wxXmlResourceHandlerImpl::GetIconBundle(const wxString& param,
return stockArt;
}
const wxString name = GetParamValue(param);
const wxString name = GetFilePath(GetParamNode(param));
if ( name.empty() )
return wxNullIconBundle;
@@ -1982,6 +1983,16 @@ wxImageList *wxXmlResourceHandlerImpl::GetImageList(const wxString& param)
return imagelist;
}
wxString wxXmlResourceHandlerImpl::GetFilePath(const wxXmlNode* node)
{
wxString path = GetParamValue(node);
if ( m_handler->m_resource->GetFlags() & wxXRC_USE_ENVVARS )
path = wxExpandEnvVars(path);
return path;
}
wxXmlNode *wxXmlResourceHandlerImpl::GetParamNode(const wxString& param)
{
wxCHECK_MSG(m_handler->m_node, NULL, wxT("You can't access handler data before it was initialized!"));