added wxStandardPaths::GetResourcesDir() and GetLocalizedResourcesDir()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38370 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -25,6 +25,7 @@ Deprecated methods since 2.6.x and their replacements
|
||||
All:
|
||||
|
||||
- wxLaunchDefaultBrowser() now supports wxBROWSER_NEW_WINDOW flag.
|
||||
- Added wxStandardPaths::GetResourcesDir() and GetLocalizedResourcesDir()
|
||||
- Added wxStringTokenizer::GetLastDelimiter(); improved documentation.
|
||||
- Speed improvements to wxRegEx when matching is done in a loop such as
|
||||
during a search and replace.
|
||||
|
@@ -13,6 +13,10 @@
|
||||
#define _WX_MAC_STDPATHS_H_
|
||||
|
||||
struct __CFBundle;
|
||||
struct __CFURL;
|
||||
|
||||
typedef const __CFURL * wxCFURLRef;
|
||||
typedef __CFBundle * wxCFBundleRef;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxStandardPaths
|
||||
@@ -25,8 +29,8 @@ public:
|
||||
~wxStandardPathsCF();
|
||||
|
||||
// wxMac specific: allow user to specify a different bundle
|
||||
wxStandardPathsCF(struct __CFBundle *bundle);
|
||||
void SetBundle(struct __CFBundle *bundle);
|
||||
wxStandardPathsCF(wxCFBundleRef bundle);
|
||||
void SetBundle(wxCFBundleRef bundle);
|
||||
|
||||
// implement base class pure virtuals
|
||||
virtual wxString GetConfigDir() const;
|
||||
@@ -35,8 +39,16 @@ public:
|
||||
virtual wxString GetLocalDataDir() const;
|
||||
virtual wxString GetUserDataDir() const;
|
||||
virtual wxString GetPluginsDir() const;
|
||||
virtual wxString GetResourcesDir() const;
|
||||
virtual wxString GetLocalizedResourcesDir(const wxChar *lang,
|
||||
ResourceCat category) const;
|
||||
|
||||
protected:
|
||||
struct __CFBundle *m_bundle;
|
||||
// this function can be called with any of CFBundleCopyXXXURL function
|
||||
// pointer as parameter
|
||||
wxString GetFromFunc(wxCFURLRef (*func)(wxCFBundleRef)) const;
|
||||
|
||||
wxCFBundleRef m_bundle;
|
||||
};
|
||||
|
||||
// If using UNIX (i.e. darwin) then use UNIX standard paths
|
||||
|
@@ -26,6 +26,8 @@ public:
|
||||
virtual wxString GetUserDataDir() const;
|
||||
virtual wxString GetUserLocalDataDir() const;
|
||||
virtual wxString GetPluginsDir() const;
|
||||
virtual wxString GetLocalizedResourcesDir(const wxChar *lang,
|
||||
ResourceCat category) const;
|
||||
|
||||
protected:
|
||||
// get the path corresponding to the given standard CSIDL_XXX constant
|
||||
|
@@ -25,6 +25,20 @@
|
||||
class WXDLLIMPEXP_BASE wxStandardPathsBase
|
||||
{
|
||||
public:
|
||||
// possible resources categorires
|
||||
enum ResourceCat
|
||||
{
|
||||
// no special category
|
||||
ResourceCat_None,
|
||||
|
||||
// message catalog resources
|
||||
ResourceCat_Messages,
|
||||
|
||||
// end of enum marker
|
||||
ResourceCat_Max
|
||||
};
|
||||
|
||||
|
||||
// return the global standard paths object
|
||||
static wxStandardPathsBase& Get();
|
||||
|
||||
@@ -74,6 +88,27 @@ public:
|
||||
// Contents/Plugins app bundle subdirectory under Mac
|
||||
virtual wxString GetPluginsDir() const = 0;
|
||||
|
||||
// get resources directory: resources are auxiliary files used by the
|
||||
// application and include things like image and sound files
|
||||
//
|
||||
// same as GetDataDir() for all platforms except Mac where it returns
|
||||
// Contents/Resources subdirectory of the app bundle
|
||||
virtual wxString GetResourcesDir() const { return GetDataDir(); }
|
||||
|
||||
// get localized resources directory containing the resource files of the
|
||||
// specified category for the given language
|
||||
//
|
||||
// in general this is just GetResourcesDir()/lang under Windows and Unix
|
||||
// and GetResourcesDir()/lang.lproj under Mac but is something quite
|
||||
// different under Unix for message catalog category (namely the standard
|
||||
// prefix/share/locale/lang/LC_MESSAGES)
|
||||
virtual wxString
|
||||
GetLocalizedResourcesDir(const wxChar *lang,
|
||||
ResourceCat category = ResourceCat_None) const
|
||||
{
|
||||
return GetResourcesDir() + wxFILE_SEP_PATH + lang;
|
||||
}
|
||||
|
||||
|
||||
// virtual dtor for the base class
|
||||
virtual ~wxStandardPathsBase();
|
||||
|
@@ -41,6 +41,8 @@ public:
|
||||
virtual wxString GetLocalDataDir() const;
|
||||
virtual wxString GetUserDataDir() const;
|
||||
virtual wxString GetPluginsDir() const;
|
||||
virtual wxString GetLocalizedResourcesDir(const wxChar *lang,
|
||||
ResourceCat category) const;
|
||||
|
||||
private:
|
||||
wxString m_prefix;
|
||||
|
@@ -85,7 +85,7 @@
|
||||
#define TEST_WCHAR
|
||||
#define TEST_ZIP
|
||||
#else // #if TEST_ALL
|
||||
#define TEST_DIR
|
||||
#define TEST_STDPATHS
|
||||
#endif
|
||||
|
||||
// some tests are interactive, define this to run them
|
||||
@@ -2685,6 +2685,15 @@ static void TestStandardPaths()
|
||||
wxPrintf(_T("Data dir (user):\t%s\n"), stdp.GetUserDataDir().c_str());
|
||||
wxPrintf(_T("Data dir (user local):\t%s\n"), stdp.GetUserLocalDataDir().c_str());
|
||||
wxPrintf(_T("Plugins dir:\t\t%s\n"), stdp.GetPluginsDir().c_str());
|
||||
wxPrintf(_T("Resources dir:\t\t%s\n"), stdp.GetResourcesDir().c_str());
|
||||
wxPrintf(_T("Localized res. dir:\t%s\n"),
|
||||
stdp.GetLocalizedResourcesDir(_T("fr")).c_str());
|
||||
wxPrintf(_T("Message catalogs dir:\t%s\n"),
|
||||
stdp.GetLocalizedResourcesDir
|
||||
(
|
||||
_T("fr"),
|
||||
wxStandardPaths::ResourceCat_Messages
|
||||
).c_str());
|
||||
}
|
||||
|
||||
#endif // TEST_STDPATHS
|
||||
|
@@ -9,6 +9,14 @@
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#if wxUSE_STDPATHS
|
||||
@@ -35,14 +43,13 @@
|
||||
#define kDefaultPathStyle kCFURLHFSPathStyle
|
||||
#endif
|
||||
|
||||
static wxString BundleRelativeURLToPath(CFURLRef relativeURL)
|
||||
{
|
||||
CFURLRef absoluteURL = CFURLCopyAbsoluteURL(relativeURL);
|
||||
wxCHECK_MSG(absoluteURL, wxEmptyString, wxT("Failed to resolve relative URL to absolute URL"));
|
||||
CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kDefaultPathStyle);
|
||||
CFRelease(absoluteURL);
|
||||
return wxMacCFStringHolder(cfStrPath).AsString(wxLocale::GetSystemEncoding());
|
||||
}
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxStandardPathsCF ctors/dtor
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxStandardPathsCF::wxStandardPathsCF()
|
||||
: m_bundle(CFBundleGetMainBundle())
|
||||
@@ -50,7 +57,7 @@ wxStandardPathsCF::wxStandardPathsCF()
|
||||
CFRetain(m_bundle);
|
||||
}
|
||||
|
||||
wxStandardPathsCF::wxStandardPathsCF(struct __CFBundle *bundle)
|
||||
wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle)
|
||||
: m_bundle(bundle)
|
||||
{
|
||||
CFRetain(m_bundle);
|
||||
@@ -61,13 +68,45 @@ wxStandardPathsCF::~wxStandardPathsCF()
|
||||
CFRelease(m_bundle);
|
||||
}
|
||||
|
||||
void wxStandardPathsCF::SetBundle(struct __CFBundle *bundle)
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxStandardPathsCF Mac-specific methods
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxStandardPathsCF::SetBundle(wxCFBundleRef bundle)
|
||||
{
|
||||
CFRetain(bundle);
|
||||
CFRelease(m_bundle);
|
||||
m_bundle = bundle;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// generic functions in terms of which the other ones are implemented
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static wxString BundleRelativeURLToPath(CFURLRef relativeURL)
|
||||
{
|
||||
CFURLRef absoluteURL = CFURLCopyAbsoluteURL(relativeURL);
|
||||
wxCHECK_MSG(absoluteURL, wxEmptyString, wxT("Failed to resolve relative URL to absolute URL"));
|
||||
CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kDefaultPathStyle);
|
||||
CFRelease(absoluteURL);
|
||||
return wxMacCFStringHolder(cfStrPath).AsString(wxLocale::GetSystemEncoding());
|
||||
}
|
||||
|
||||
wxString wxStandardPathsCF::GetFromFunc(wxCFURLRef (*func)(wxCFBundleRef)) const
|
||||
{
|
||||
wxCHECK_MSG(m_bundle, wxEmptyString,
|
||||
wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
|
||||
CFURLRef relativeURL = (*func)(m_bundle);
|
||||
wxCHECK_MSG(relativeURL, wxEmptyString, wxT("Couldn't get URL"));
|
||||
wxString ret(BundleRelativeURLToPath(relativeURL));
|
||||
CFRelease(relativeURL);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxStandardPathsCF public API
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxString wxStandardPathsCF::GetConfigDir() const
|
||||
{
|
||||
// TODO: What do we do for pure Carbon?
|
||||
@@ -82,12 +121,7 @@ wxString wxStandardPathsCF::GetUserConfigDir() const
|
||||
|
||||
wxString wxStandardPathsCF::GetDataDir() const
|
||||
{
|
||||
wxCHECK_MSG(m_bundle, wxEmptyString, wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
|
||||
CFURLRef relativeURL = CFBundleCopySharedSupportURL(m_bundle);
|
||||
wxCHECK_MSG(relativeURL, wxEmptyString, wxT("Couldn't get SharedSupport URL"));
|
||||
wxString ret(BundleRelativeURLToPath(relativeURL));
|
||||
CFRelease(relativeURL);
|
||||
return ret;
|
||||
return GetFromFunc(CFBundleCopySharedSupportURL);
|
||||
}
|
||||
|
||||
wxString wxStandardPathsCF::GetLocalDataDir() const
|
||||
@@ -102,12 +136,20 @@ wxString wxStandardPathsCF::GetUserDataDir() const
|
||||
|
||||
wxString wxStandardPathsCF::GetPluginsDir() const
|
||||
{
|
||||
wxCHECK_MSG(m_bundle, wxEmptyString, wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
|
||||
CFURLRef relativeURL = CFBundleCopyBuiltInPlugInsURL(m_bundle);
|
||||
wxCHECK_MSG(relativeURL, wxEmptyString, wxT("Couldn't get BuiltInPlugIns URL"));
|
||||
wxString ret(BundleRelativeURLToPath(relativeURL));
|
||||
CFRelease(relativeURL);
|
||||
return ret;
|
||||
return GetFromFunc(CFBundleCopyBuiltInPlugInsURL);
|
||||
}
|
||||
|
||||
wxString wxStandardPathsCF::GetResourcesDir() const
|
||||
{
|
||||
return GetFromFunc(CFBundleCopyResourcesDirectoryURL);
|
||||
}
|
||||
|
||||
wxString
|
||||
wxStandardPathsCF::GetLocalizedResourcesDir(const wxChar *lang,
|
||||
ResourceCat category) const
|
||||
{
|
||||
return wxStandardPathsBase::
|
||||
GetLocalizedResourcesDir(lang, category) + _T(".lproj");
|
||||
}
|
||||
|
||||
#endif // wxUSE_STDPATHS
|
||||
|
@@ -278,7 +278,6 @@ wxString wxStandardPaths::GetPluginsDir() const
|
||||
return wxFileName(wxGetFullModuleName()).GetPath();
|
||||
}
|
||||
|
||||
|
||||
// ============================================================================
|
||||
// wxStandardPathsWin16 implementation
|
||||
// ============================================================================
|
||||
|
@@ -93,6 +93,13 @@ wxString wxStandardPaths::GetPluginsDir() const
|
||||
return wxString(); // TODO: this is wrong, it should return something
|
||||
}
|
||||
|
||||
wxString
|
||||
wxStandardPaths::GetLocalizedResourcesDir(const wxChar *lang,
|
||||
ResourceCat category) const
|
||||
{
|
||||
return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
|
||||
}
|
||||
|
||||
#else // !__VMS
|
||||
|
||||
// ============================================================================
|
||||
@@ -161,6 +168,16 @@ wxString wxStandardPaths::GetPluginsDir() const
|
||||
return AppendAppName(GetInstallPrefix() + _T("/lib"));
|
||||
}
|
||||
|
||||
wxString
|
||||
wxStandardPaths::GetLocalizedResourcesDir(const wxChar *lang,
|
||||
ResourceCat category) const
|
||||
{
|
||||
if ( category != ResourceCat_Messages )
|
||||
return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
|
||||
|
||||
return GetInstallPrefix() + _T("/share/locale/") + lang + _T("/LC_MESSAGES");
|
||||
}
|
||||
|
||||
#endif // __VMS/!__VMS
|
||||
|
||||
#endif // wxUSE_STDPATHS
|
||||
|
Reference in New Issue
Block a user