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