]> git.saurik.com Git - wxWidgets.git/blame - src/common/stdpbase.cpp
No real changes, just refactor wxControlContainer code a little.
[wxWidgets.git] / src / common / stdpbase.cpp
CommitLineData
6cb5e50b 1///////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/common/stdpbase.cpp
6cb5e50b
VZ
3// Purpose: wxStandardPathsBase methods common to all ports
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 2004-10-19
7// RCS-ID: $Id$
8// Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
526954c5 9// Licence: wxWindows licence
6cb5e50b
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// for compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
ce336c6d
VZ
27#ifndef WX_PRECOMP
28 #include "wx/app.h"
29#endif //WX_PRECOMP
fc480dc1 30#include "wx/apptrait.h"
ce336c6d
VZ
31
32#include "wx/filename.h"
6cb5e50b
VZ
33#include "wx/stdpaths.h"
34
35// ----------------------------------------------------------------------------
36// module globals
37// ----------------------------------------------------------------------------
38
38aae140
VZ
39namespace
40{
41
42// Derive a class just to be able to create it: wxStandardPaths ctor is
43// protected to prevent its misuse, but it also means we can't create an object
44// of this class directly.
45class wxStandardPathsDefault : public wxStandardPaths
46{
47public:
48 wxStandardPathsDefault() { }
49};
50
51static wxStandardPathsDefault gs_stdPaths;
52
53} // anonymous namespace
6cb5e50b
VZ
54
55// ============================================================================
56// implementation
57// ============================================================================
58
59/* static */
25f49256 60wxStandardPaths& wxStandardPathsBase::Get()
fc480dc1 61{
81f9c575 62 wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
9a83f860 63 wxCHECK_MSG( traits, gs_stdPaths, wxT("create wxApp before calling this") );
81f9c575
VZ
64
65 return traits->GetStandardPaths();
fc480dc1
DE
66}
67
ac7ad70d
RR
68wxString wxStandardPathsBase::GetExecutablePath() const
69{
d154ab3d 70 if ( !wxTheApp || !wxTheApp->argv )
ac7ad70d
RR
71 return wxEmptyString;
72
73 wxString argv0 = wxTheApp->argv[0];
74 if (wxIsAbsolutePath(argv0))
75 return argv0;
76
77 // Search PATH.environment variable...
78 wxPathList pathlist;
79 pathlist.AddEnvList(wxT("PATH"));
80 wxString path = pathlist.FindAbsoluteValidPath(argv0);
81 if ( path.empty() )
82 return argv0; // better than nothing
83
84 wxFileName filename(path);
85 filename.Normalize();
86 return filename.GetFullPath();
87}
88
25f49256 89wxStandardPaths& wxAppTraitsBase::GetStandardPaths()
6cb5e50b
VZ
90{
91 return gs_stdPaths;
92}
93
2b147f2e
VZ
94wxStandardPathsBase::wxStandardPathsBase()
95{
96 // Set the default information that is used when
97 // forming some paths (by AppendAppInfo).
98 // Derived classes can call this in their constructors
99 // to set the platform-specific settings
100 UseAppInfo(AppInfo_AppName);
101}
102
6cb5e50b
VZ
103wxStandardPathsBase::~wxStandardPathsBase()
104{
105 // nothing to do here
106}
107
108wxString wxStandardPathsBase::GetLocalDataDir() const
109{
110 return GetDataDir();
111}
112
113wxString wxStandardPathsBase::GetUserLocalDataDir() const
114{
115 return GetUserDataDir();
116}
117
17af82fb
VZ
118wxString wxStandardPathsBase::GetDocumentsDir() const
119{
120 return wxFileName::GetHomeDir();
121}
122
d8efd219
VZ
123wxString wxStandardPathsBase::GetAppDocumentsDir() const
124{
125 const wxString docsDir = GetDocumentsDir();
126 wxString appDocsDir = AppendAppInfo(docsDir);
127
128 return wxDirExists(appDocsDir) ? appDocsDir : docsDir;
129}
130
ecf9559d
JS
131// return the temporary directory for the current user
132wxString wxStandardPathsBase::GetTempDir() const
133{
134 return wxFileName::GetTempDir();
135}
136
ce336c6d 137/* static */
d8efd219
VZ
138wxString
139wxStandardPathsBase::AppendPathComponent(const wxString& dir,
140 const wxString& component)
ce336c6d
VZ
141{
142 wxString subdir(dir);
143
3103e8a9 144 // empty string indicates that an error has occurred, don't touch it then
ce336c6d
VZ
145 if ( !subdir.empty() )
146 {
2b147f2e 147 if ( !component.empty() )
ce336c6d
VZ
148 {
149 const wxChar ch = *(subdir.end() - 1);
9a83f860 150 if ( !wxFileName::IsPathSeparator(ch) && ch != wxT('.') )
ce336c6d
VZ
151 subdir += wxFileName::GetPathSeparator();
152
2b147f2e 153 subdir += component;
ce336c6d
VZ
154 }
155 }
156
157 return subdir;
158}
2b147f2e
VZ
159
160
161wxString wxStandardPathsBase::AppendAppInfo(const wxString& dir) const
162{
163 wxString subdir(dir);
164
165 if ( UsesAppInfo(AppInfo_VendorName) )
166 {
167 subdir = AppendPathComponent(subdir, wxTheApp->GetVendorName());
168 }
169
170 if ( UsesAppInfo(AppInfo_AppName) )
171 {
172 subdir = AppendPathComponent(subdir, wxTheApp->GetAppName());
173 }
174
175 return subdir;
176}
177