]> git.saurik.com Git - wxWidgets.git/blame - src/mac/corefoundation/stdpaths_cf.cpp
added wxWindow::GetPrev/NextSibling()
[wxWidgets.git] / src / mac / corefoundation / stdpaths_cf.cpp
CommitLineData
726b98e9
DE
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
3af9f2de
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
726b98e9 20#include "wx/wxprec.h"
07158944
VZ
21
22#if wxUSE_STDPATHS
23
726b98e9
DE
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"
f5158fa6
SC
30#ifdef __WXMAC__
31#include "wx/mac/private.h"
32#endif
726b98e9
DE
33#include "wx/mac/corefoundation/cfstring.h"
34
35#include <CoreFoundation/CFBundle.h>
36#include <CoreFoundation/CFURL.h>
37
726b98e9 38#define kDefaultPathStyle kCFURLPOSIXPathStyle
726b98e9 39
3af9f2de
VZ
40// ============================================================================
41// implementation
42// ============================================================================
43
44// ----------------------------------------------------------------------------
45// wxStandardPathsCF ctors/dtor
46// ----------------------------------------------------------------------------
726b98e9 47
fc480dc1 48wxStandardPathsCF::wxStandardPathsCF()
3af9f2de 49 : m_bundle(CFBundleGetMainBundle())
726b98e9
DE
50{
51 CFRetain(m_bundle);
2b147f2e 52 UseAppInfo(AppInfo_AppName | AppInfo_VendorName);
726b98e9
DE
53}
54
3af9f2de
VZ
55wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle)
56 : m_bundle(bundle)
726b98e9
DE
57{
58 CFRetain(m_bundle);
2b147f2e 59 UseAppInfo(AppInfo_AppName | AppInfo_VendorName);
726b98e9
DE
60}
61
fc480dc1 62wxStandardPathsCF::~wxStandardPathsCF()
726b98e9
DE
63{
64 CFRelease(m_bundle);
65}
66
3af9f2de
VZ
67// ----------------------------------------------------------------------------
68// wxStandardPathsCF Mac-specific methods
69// ----------------------------------------------------------------------------
70
71void wxStandardPathsCF::SetBundle(wxCFBundleRef bundle)
726b98e9
DE
72{
73 CFRetain(bundle);
74 CFRelease(m_bundle);
75 m_bundle = bundle;
76}
77
3af9f2de
VZ
78// ----------------------------------------------------------------------------
79// generic functions in terms of which the other ones are implemented
80// ----------------------------------------------------------------------------
81
82static wxString BundleRelativeURLToPath(CFURLRef relativeURL)
83{
84 CFURLRef absoluteURL = CFURLCopyAbsoluteURL(relativeURL);
85 wxCHECK_MSG(absoluteURL, wxEmptyString, wxT("Failed to resolve relative URL to absolute URL"));
86 CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kDefaultPathStyle);
87 CFRelease(absoluteURL);
88 return wxMacCFStringHolder(cfStrPath).AsString(wxLocale::GetSystemEncoding());
89}
90
91wxString wxStandardPathsCF::GetFromFunc(wxCFURLRef (*func)(wxCFBundleRef)) const
92{
93 wxCHECK_MSG(m_bundle, wxEmptyString,
94 wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
95 CFURLRef relativeURL = (*func)(m_bundle);
96 wxCHECK_MSG(relativeURL, wxEmptyString, wxT("Couldn't get URL"));
97 wxString ret(BundleRelativeURLToPath(relativeURL));
98 CFRelease(relativeURL);
99 return ret;
100}
101
17af82fb
VZ
102wxString wxStandardPathsCF::GetDocumentsDir() const
103{
747592e7 104#ifdef __WXMAC__
17af82fb
VZ
105 return wxMacFindFolderNoSeparator
106 (
107#if TARGET_API_MAC_OSX
108 kUserDomain,
109#else
110 kOnSystemDisk,
111#endif
112 kDocumentsFolderType,
113 kCreateFolder
114 );
747592e7
SC
115#else
116 return wxFileName::GetHomeDir() + wxT("/Documents");
117#endif
17af82fb
VZ
118}
119
3af9f2de
VZ
120// ----------------------------------------------------------------------------
121// wxStandardPathsCF public API
122// ----------------------------------------------------------------------------
123
fc480dc1 124wxString wxStandardPathsCF::GetConfigDir() const
726b98e9 125{
f5158fa6
SC
126#ifdef __WXMAC__
127 return wxMacFindFolder((short)kLocalDomain, kPreferencesFolderType, kCreateFolder);
128#else
726b98e9 129 return wxT("/Library/Preferences");
f5158fa6 130#endif
726b98e9
DE
131}
132
fc480dc1 133wxString wxStandardPathsCF::GetUserConfigDir() const
726b98e9 134{
f5158fa6
SC
135#ifdef __WXMAC__
136 return wxMacFindFolder((short)kUserDomain, kPreferencesFolderType, kCreateFolder);
137#else
726b98e9 138 return wxFileName::GetHomeDir() + wxT("/Library/Preferences");
f5158fa6 139#endif
726b98e9
DE
140}
141
fc480dc1 142wxString wxStandardPathsCF::GetDataDir() const
726b98e9 143{
3af9f2de 144 return GetFromFunc(CFBundleCopySharedSupportURL);
726b98e9
DE
145}
146
ac371a87 147// TODO: implement this using real CoreFoundation API instead of Carbon API
ac7ad70d
RR
148wxString wxStandardPathsCF::GetExecutablePath() const
149{
ac371a87 150#ifdef __WXMAC__
ac7ad70d
RR
151 ProcessInfoRec processinfo;
152 ProcessSerialNumber procno ;
153 FSSpec fsSpec;
154
90412a12 155 procno.highLongOfPSN = 0 ;
ac7ad70d
RR
156 procno.lowLongOfPSN = kCurrentProcess ;
157 processinfo.processInfoLength = sizeof(ProcessInfoRec);
158 processinfo.processName = NULL;
159 processinfo.processAppSpec = &fsSpec;
160
161 GetProcessInformation( &procno , &processinfo ) ;
8b71ebad
SC
162#ifdef __LP64__
163 return wxMacFSRefToPath(&fsRef);
164#else
ac7ad70d 165 return wxMacFSSpec2MacFilename(&fsSpec);
8b71ebad 166#endif
ac371a87
VZ
167#else
168 return wxStandardPathsBase::GetExecutablePath();
169#endif
ac7ad70d
RR
170}
171
fc480dc1 172wxString wxStandardPathsCF::GetLocalDataDir() const
726b98e9 173{
f5158fa6 174#ifdef __WXMAC__
2b147f2e 175 return AppendAppInfo(wxMacFindFolder((short)kLocalDomain, kApplicationSupportFolderType, kCreateFolder));
f5158fa6 176#else
2b147f2e 177 return AppendAppInfo(wxT("/Library/Application Support"));
f5158fa6 178#endif
726b98e9
DE
179}
180
fc480dc1 181wxString wxStandardPathsCF::GetUserDataDir() const
726b98e9 182{
f5158fa6 183#ifdef __WXMAC__
2b147f2e 184 return AppendAppInfo(wxMacFindFolder((short)kUserDomain, kApplicationSupportFolderType, kCreateFolder));
f5158fa6 185#else
2b147f2e 186 return AppendAppInfo(wxFileName::GetHomeDir() + _T("/Library/Application Support"));
f5158fa6 187#endif
726b98e9
DE
188}
189
fc480dc1 190wxString wxStandardPathsCF::GetPluginsDir() const
726b98e9 191{
3af9f2de
VZ
192 return GetFromFunc(CFBundleCopyBuiltInPlugInsURL);
193}
194
195wxString wxStandardPathsCF::GetResourcesDir() const
196{
197 return GetFromFunc(CFBundleCopyResourcesDirectoryURL);
198}
199
200wxString
e0b3b9d0 201wxStandardPathsCF::GetLocalizedResourcesDir(const wxString& lang,
3af9f2de
VZ
202 ResourceCat category) const
203{
204 return wxStandardPathsBase::
205 GetLocalizedResourcesDir(lang, category) + _T(".lproj");
726b98e9
DE
206}
207
07158944 208#endif // wxUSE_STDPATHS