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.
#define _WX_MAC_STDPATHS_H_
struct __CFBundle;
+struct __CFURL;
+
+typedef const __CFURL * wxCFURLRef;
+typedef __CFBundle * wxCFBundleRef;
// ----------------------------------------------------------------------------
// wxStandardPaths
~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;
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
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
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();
// 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();
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;
#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
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
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
#include "wx/wxprec.h"
#if wxUSE_STDPATHS
#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())
+ : m_bundle(CFBundleGetMainBundle())
{
CFRetain(m_bundle);
}
-wxStandardPathsCF::wxStandardPathsCF(struct __CFBundle *bundle)
-: m_bundle(bundle)
+wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle)
+ : m_bundle(bundle)
{
CFRetain(m_bundle);
}
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?
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
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
return wxFileName(wxGetFullModuleName()).GetPath();
}
-
// ============================================================================
// wxStandardPathsWin16 implementation
// ============================================================================
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
// ============================================================================
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