]> git.saurik.com Git - wxWidgets.git/blame - src/mac/corefoundation/stdpaths_cf.cpp
Initial commit of native OS X list ctrl support. Compile tested on Win, Mac, FC4...
[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 33#include "wx/mac/corefoundation/cfstring.h"
17af82fb 34#include "wx/mac/private.h"
726b98e9 35
072a99f4 36#if defined(__DARWIN__)
726b98e9
DE
37#include <CoreFoundation/CFBundle.h>
38#include <CoreFoundation/CFURL.h>
072a99f4
DE
39#else
40#include <CFBundle.h>
41#include <CFURL.h>
42#endif
726b98e9 43
726b98e9
DE
44#if defined(__WXCOCOA__) || defined(__WXMAC_OSX__)
45#define kDefaultPathStyle kCFURLPOSIXPathStyle
46#else
47#define kDefaultPathStyle kCFURLHFSPathStyle
48#endif
49
3af9f2de
VZ
50// ============================================================================
51// implementation
52// ============================================================================
53
54// ----------------------------------------------------------------------------
55// wxStandardPathsCF ctors/dtor
56// ----------------------------------------------------------------------------
726b98e9 57
fc480dc1 58wxStandardPathsCF::wxStandardPathsCF()
3af9f2de 59 : m_bundle(CFBundleGetMainBundle())
726b98e9
DE
60{
61 CFRetain(m_bundle);
62}
63
3af9f2de
VZ
64wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle)
65 : m_bundle(bundle)
726b98e9
DE
66{
67 CFRetain(m_bundle);
68}
69
fc480dc1 70wxStandardPathsCF::~wxStandardPathsCF()
726b98e9
DE
71{
72 CFRelease(m_bundle);
73}
74
3af9f2de
VZ
75// ----------------------------------------------------------------------------
76// wxStandardPathsCF Mac-specific methods
77// ----------------------------------------------------------------------------
78
79void wxStandardPathsCF::SetBundle(wxCFBundleRef bundle)
726b98e9
DE
80{
81 CFRetain(bundle);
82 CFRelease(m_bundle);
83 m_bundle = bundle;
84}
85
3af9f2de
VZ
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
17af82fb
VZ
110wxString wxStandardPathsCF::GetDocumentsDir() const
111{
747592e7 112#ifdef __WXMAC__
17af82fb
VZ
113 return wxMacFindFolderNoSeparator
114 (
115#if TARGET_API_MAC_OSX
116 kUserDomain,
117#else
118 kOnSystemDisk,
119#endif
120 kDocumentsFolderType,
121 kCreateFolder
122 );
747592e7
SC
123#else
124 return wxFileName::GetHomeDir() + wxT("/Documents");
125#endif
17af82fb
VZ
126}
127
3af9f2de
VZ
128// ----------------------------------------------------------------------------
129// wxStandardPathsCF public API
130// ----------------------------------------------------------------------------
131
fc480dc1 132wxString wxStandardPathsCF::GetConfigDir() const
726b98e9 133{
f5158fa6
SC
134#ifdef __WXMAC__
135 return wxMacFindFolder((short)kLocalDomain, kPreferencesFolderType, kCreateFolder);
136#else
726b98e9 137 return wxT("/Library/Preferences");
f5158fa6 138#endif
726b98e9
DE
139}
140
fc480dc1 141wxString wxStandardPathsCF::GetUserConfigDir() const
726b98e9 142{
f5158fa6
SC
143#ifdef __WXMAC__
144 return wxMacFindFolder((short)kUserDomain, kPreferencesFolderType, kCreateFolder);
145#else
726b98e9 146 return wxFileName::GetHomeDir() + wxT("/Library/Preferences");
f5158fa6 147#endif
726b98e9
DE
148}
149
fc480dc1 150wxString wxStandardPathsCF::GetDataDir() const
726b98e9 151{
3af9f2de 152 return GetFromFunc(CFBundleCopySharedSupportURL);
726b98e9
DE
153}
154
fc480dc1 155wxString wxStandardPathsCF::GetLocalDataDir() const
726b98e9 156{
f5158fa6
SC
157#ifdef __WXMAC__
158 return AppendAppName(wxMacFindFolder((short)kLocalDomain, kApplicationSupportFolderType, kCreateFolder));
159#else
726b98e9 160 return AppendAppName(wxT("/Library/Application Support"));
f5158fa6 161#endif
726b98e9
DE
162}
163
fc480dc1 164wxString wxStandardPathsCF::GetUserDataDir() const
726b98e9 165{
f5158fa6
SC
166#ifdef __WXMAC__
167 return AppendAppName(wxMacFindFolder((short)kUserDomain, kApplicationSupportFolderType, kCreateFolder));
168#else
726b98e9 169 return AppendAppName(wxFileName::GetHomeDir() + _T("/Library/Application Support"));
f5158fa6 170#endif
726b98e9
DE
171}
172
fc480dc1 173wxString wxStandardPathsCF::GetPluginsDir() const
726b98e9 174{
3af9f2de
VZ
175 return GetFromFunc(CFBundleCopyBuiltInPlugInsURL);
176}
177
178wxString wxStandardPathsCF::GetResourcesDir() const
179{
180 return GetFromFunc(CFBundleCopyResourcesDirectoryURL);
181}
182
183wxString
184wxStandardPathsCF::GetLocalizedResourcesDir(const wxChar *lang,
185 ResourceCat category) const
186{
187 return wxStandardPathsBase::
188 GetLocalizedResourcesDir(lang, category) + _T(".lproj");
726b98e9
DE
189}
190
07158944 191#endif // wxUSE_STDPATHS