]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/corefoundation/stdpaths_cf.cpp
Each book control should say what its default orientation. Use this info
[wxWidgets.git] / src / mac / corefoundation / stdpaths_cf.cpp
... / ...
CommitLineData
1///////////////////////////////////////////////////////////////////////////////
2// Name: mac/corefoundation/stdpaths.cpp
3// Purpose: wxStandardPaths implementation for CoreFoundation systems
4// Author: David Elliott
5// Modified by:
6// Created: 2004-10-27
7// RCS-ID: $Id$
8// Copyright: (c) 2004 David Elliott <dfe@cox.net>
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#include "wx/wxprec.h"
21
22#if wxUSE_STDPATHS
23
24#ifndef WX_PRECOMP
25 #include "wx/intl.h"
26#endif //ndef WX_PRECOMP
27
28#include "wx/stdpaths.h"
29#include "wx/filename.h"
30#ifdef __WXMAC__
31#include "wx/mac/private.h"
32#endif
33#include "wx/mac/corefoundation/cfstring.h"
34#include "wx/mac/private.h"
35
36#if defined(__DARWIN__)
37#include <CoreFoundation/CFBundle.h>
38#include <CoreFoundation/CFURL.h>
39#else
40#include <CFBundle.h>
41#include <CFURL.h>
42#endif
43
44#if defined(__WXCOCOA__) || defined(__WXMAC_OSX__)
45#define kDefaultPathStyle kCFURLPOSIXPathStyle
46#else
47#define kDefaultPathStyle kCFURLHFSPathStyle
48#endif
49
50// ============================================================================
51// implementation
52// ============================================================================
53
54// ----------------------------------------------------------------------------
55// wxStandardPathsCF ctors/dtor
56// ----------------------------------------------------------------------------
57
58wxStandardPathsCF::wxStandardPathsCF()
59 : m_bundle(CFBundleGetMainBundle())
60{
61 CFRetain(m_bundle);
62}
63
64wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle)
65 : m_bundle(bundle)
66{
67 CFRetain(m_bundle);
68}
69
70wxStandardPathsCF::~wxStandardPathsCF()
71{
72 CFRelease(m_bundle);
73}
74
75// ----------------------------------------------------------------------------
76// wxStandardPathsCF Mac-specific methods
77// ----------------------------------------------------------------------------
78
79void wxStandardPathsCF::SetBundle(wxCFBundleRef bundle)
80{
81 CFRetain(bundle);
82 CFRelease(m_bundle);
83 m_bundle = bundle;
84}
85
86// ----------------------------------------------------------------------------
87// generic functions in terms of which the other ones are implemented
88// ----------------------------------------------------------------------------
89
90static wxString BundleRelativeURLToPath(CFURLRef relativeURL)
91{
92 CFURLRef absoluteURL = CFURLCopyAbsoluteURL(relativeURL);
93 wxCHECK_MSG(absoluteURL, wxEmptyString, wxT("Failed to resolve relative URL to absolute URL"));
94 CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kDefaultPathStyle);
95 CFRelease(absoluteURL);
96 return wxMacCFStringHolder(cfStrPath).AsString(wxLocale::GetSystemEncoding());
97}
98
99wxString wxStandardPathsCF::GetFromFunc(wxCFURLRef (*func)(wxCFBundleRef)) const
100{
101 wxCHECK_MSG(m_bundle, wxEmptyString,
102 wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
103 CFURLRef relativeURL = (*func)(m_bundle);
104 wxCHECK_MSG(relativeURL, wxEmptyString, wxT("Couldn't get URL"));
105 wxString ret(BundleRelativeURLToPath(relativeURL));
106 CFRelease(relativeURL);
107 return ret;
108}
109
110wxString wxStandardPathsCF::GetDocumentsDir() const
111{
112 return wxMacFindFolderNoSeparator
113 (
114#if TARGET_API_MAC_OSX
115 kUserDomain,
116#else
117 kOnSystemDisk,
118#endif
119 kDocumentsFolderType,
120 kCreateFolder
121 );
122}
123
124// ----------------------------------------------------------------------------
125// wxStandardPathsCF public API
126// ----------------------------------------------------------------------------
127
128wxString wxStandardPathsCF::GetConfigDir() const
129{
130#ifdef __WXMAC__
131 return wxMacFindFolder((short)kLocalDomain, kPreferencesFolderType, kCreateFolder);
132#else
133 return wxT("/Library/Preferences");
134#endif
135}
136
137wxString wxStandardPathsCF::GetUserConfigDir() const
138{
139#ifdef __WXMAC__
140 return wxMacFindFolder((short)kUserDomain, kPreferencesFolderType, kCreateFolder);
141#else
142 return wxFileName::GetHomeDir() + wxT("/Library/Preferences");
143#endif
144}
145
146wxString wxStandardPathsCF::GetDataDir() const
147{
148 return GetFromFunc(CFBundleCopySharedSupportURL);
149}
150
151wxString wxStandardPathsCF::GetLocalDataDir() const
152{
153#ifdef __WXMAC__
154 return AppendAppName(wxMacFindFolder((short)kLocalDomain, kApplicationSupportFolderType, kCreateFolder));
155#else
156 return AppendAppName(wxT("/Library/Application Support"));
157#endif
158}
159
160wxString wxStandardPathsCF::GetUserDataDir() const
161{
162#ifdef __WXMAC__
163 return AppendAppName(wxMacFindFolder((short)kUserDomain, kApplicationSupportFolderType, kCreateFolder));
164#else
165 return AppendAppName(wxFileName::GetHomeDir() + _T("/Library/Application Support"));
166#endif
167}
168
169wxString wxStandardPathsCF::GetPluginsDir() const
170{
171 return GetFromFunc(CFBundleCopyBuiltInPlugInsURL);
172}
173
174wxString wxStandardPathsCF::GetResourcesDir() const
175{
176 return GetFromFunc(CFBundleCopyResourcesDirectoryURL);
177}
178
179wxString
180wxStandardPathsCF::GetLocalizedResourcesDir(const wxChar *lang,
181 ResourceCat category) const
182{
183 return wxStandardPathsBase::
184 GetLocalizedResourcesDir(lang, category) + _T(".lproj");
185}
186
187#endif // wxUSE_STDPATHS