]> git.saurik.com Git - wxWidgets.git/blame - src/osx/core/stdpaths_cf.cpp
adding support for extraControl on osx_carbon
[wxWidgets.git] / src / osx / core / stdpaths_cf.cpp
CommitLineData
489468fe
SC
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__
c8ef3d55 31#include "wx/osx/private.h"
489468fe 32#endif
c8ef3d55 33#include "wx/osx/core/cfstring.h"
489468fe
SC
34
35#include <CoreFoundation/CFBundle.h>
36#include <CoreFoundation/CFURL.h>
37
38#define kDefaultPathStyle kCFURLPOSIXPathStyle
39
40// ============================================================================
41// implementation
42// ============================================================================
43
44// ----------------------------------------------------------------------------
45// wxStandardPathsCF ctors/dtor
46// ----------------------------------------------------------------------------
47
48wxStandardPathsCF::wxStandardPathsCF()
49 : m_bundle(CFBundleGetMainBundle())
50{
51 CFRetain(m_bundle);
489468fe
SC
52}
53
54wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle)
55 : m_bundle(bundle)
56{
57 CFRetain(m_bundle);
489468fe
SC
58}
59
60wxStandardPathsCF::~wxStandardPathsCF()
61{
62 CFRelease(m_bundle);
63}
64
65// ----------------------------------------------------------------------------
66// wxStandardPathsCF Mac-specific methods
67// ----------------------------------------------------------------------------
68
69void wxStandardPathsCF::SetBundle(wxCFBundleRef bundle)
70{
71 CFRetain(bundle);
72 CFRelease(m_bundle);
73 m_bundle = bundle;
74}
75
76// ----------------------------------------------------------------------------
77// generic functions in terms of which the other ones are implemented
78// ----------------------------------------------------------------------------
79
80static wxString BundleRelativeURLToPath(CFURLRef relativeURL)
81{
82 CFURLRef absoluteURL = CFURLCopyAbsoluteURL(relativeURL);
83 wxCHECK_MSG(absoluteURL, wxEmptyString, wxT("Failed to resolve relative URL to absolute URL"));
84 CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kDefaultPathStyle);
85 CFRelease(absoluteURL);
86 return wxCFStringRef(cfStrPath).AsString(wxLocale::GetSystemEncoding());
87}
88
89wxString wxStandardPathsCF::GetFromFunc(wxCFURLRef (*func)(wxCFBundleRef)) const
90{
91 wxCHECK_MSG(m_bundle, wxEmptyString,
92 wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
93 CFURLRef relativeURL = (*func)(m_bundle);
94 wxCHECK_MSG(relativeURL, wxEmptyString, wxT("Couldn't get URL"));
95 wxString ret(BundleRelativeURLToPath(relativeURL));
96 CFRelease(relativeURL);
97 return ret;
98}
99
100wxString wxStandardPathsCF::GetDocumentsDir() const
101{
56869c54 102#if defined( __WXMAC__ ) && wxOSX_USE_CARBON
489468fe
SC
103 return wxMacFindFolderNoSeparator
104 (
105 kUserDomain,
106 kDocumentsFolderType,
107 kCreateFolder
108 );
109#else
110 return wxFileName::GetHomeDir() + wxT("/Documents");
111#endif
112}
113
114// ----------------------------------------------------------------------------
115// wxStandardPathsCF public API
116// ----------------------------------------------------------------------------
117
118wxString wxStandardPathsCF::GetConfigDir() const
119{
56869c54 120#if defined( __WXMAC__ ) && wxOSX_USE_CARBON
489468fe
SC
121 return wxMacFindFolder((short)kLocalDomain, kPreferencesFolderType, kCreateFolder);
122#else
123 return wxT("/Library/Preferences");
124#endif
125}
126
127wxString wxStandardPathsCF::GetUserConfigDir() const
128{
56869c54 129#if defined( __WXMAC__ ) && wxOSX_USE_CARBON
489468fe
SC
130 return wxMacFindFolder((short)kUserDomain, kPreferencesFolderType, kCreateFolder);
131#else
132 return wxFileName::GetHomeDir() + wxT("/Library/Preferences");
133#endif
134}
135
136wxString wxStandardPathsCF::GetDataDir() const
137{
138 return GetFromFunc(CFBundleCopySharedSupportURL);
139}
140
141wxString wxStandardPathsCF::GetExecutablePath() const
142{
143#ifdef __WXMAC__
144#if 1
145 return GetFromFunc(CFBundleCopyBundleURL);
146#else
147 // TODO remove if cf implementation ok
148 ProcessInfoRec processinfo;
149 ProcessSerialNumber procno ;
150#ifdef __LP64__
151 FSRef fsRef;
152#else
153 FSSpec fsSpec;
154#endif
03647350 155
489468fe
SC
156 procno.highLongOfPSN = 0 ;
157 procno.lowLongOfPSN = kCurrentProcess ;
158 processinfo.processInfoLength = sizeof(ProcessInfoRec);
159 processinfo.processName = NULL;
160#ifdef __LP64__
161 processinfo.processAppRef = &fsRef;
162#else
163 processinfo.processAppSpec = &fsSpec;
164#endif
03647350 165
489468fe
SC
166 GetProcessInformation( &procno , &processinfo ) ;
167#ifdef __LP64__
168 return wxMacFSRefToPath(&fsRef);
169#else
170 return wxMacFSSpec2MacFilename(&fsSpec);
171#endif
172#endif
03647350 173
489468fe
SC
174#else
175 return wxStandardPathsBase::GetExecutablePath();
176#endif
177}
178
179wxString wxStandardPathsCF::GetLocalDataDir() const
180{
56869c54 181#if defined( __WXMAC__ ) && wxOSX_USE_CARBON
489468fe
SC
182 return AppendAppInfo(wxMacFindFolder((short)kLocalDomain, kApplicationSupportFolderType, kCreateFolder));
183#else
184 return AppendAppInfo(wxT("/Library/Application Support"));
185#endif
186}
187
188wxString wxStandardPathsCF::GetUserDataDir() const
189{
56869c54 190#if defined( __WXMAC__ ) && wxOSX_USE_CARBON
489468fe
SC
191 return AppendAppInfo(wxMacFindFolder((short)kUserDomain, kApplicationSupportFolderType, kCreateFolder));
192#else
9a83f860 193 return AppendAppInfo(wxFileName::GetHomeDir() + wxT("/Library/Application Support"));
489468fe
SC
194#endif
195}
196
197wxString wxStandardPathsCF::GetPluginsDir() const
198{
199 return GetFromFunc(CFBundleCopyBuiltInPlugInsURL);
200}
201
202wxString wxStandardPathsCF::GetResourcesDir() const
203{
204 return GetFromFunc(CFBundleCopyResourcesDirectoryURL);
205}
206
207wxString
208wxStandardPathsCF::GetLocalizedResourcesDir(const wxString& lang,
209 ResourceCat category) const
210{
211 return wxStandardPathsBase::
9a83f860 212 GetLocalizedResourcesDir(lang, category) + wxT(".lproj");
489468fe
SC
213}
214
215#endif // wxUSE_STDPATHS