]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/stdpbase.cpp
Suppress harmless clang 3.3 warning about unused wxMessageOutputBest field.
[wxWidgets.git] / src / common / stdpbase.cpp
... / ...
CommitLineData
1///////////////////////////////////////////////////////////////////////////////
2// Name: src/common/stdpbase.cpp
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>
9// Licence: wxWindows licence
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
27#ifndef WX_PRECOMP
28 #include "wx/app.h"
29#endif //WX_PRECOMP
30#include "wx/apptrait.h"
31
32#include "wx/filename.h"
33#include "wx/stdpaths.h"
34
35// ----------------------------------------------------------------------------
36// module globals
37// ----------------------------------------------------------------------------
38
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
54
55// ============================================================================
56// implementation
57// ============================================================================
58
59/* static */
60wxStandardPaths& wxStandardPathsBase::Get()
61{
62 wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
63 wxCHECK_MSG( traits, gs_stdPaths, wxT("create wxApp before calling this") );
64
65 return traits->GetStandardPaths();
66}
67
68wxString wxStandardPathsBase::GetExecutablePath() const
69{
70 if ( !wxTheApp || !wxTheApp->argv )
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
89wxStandardPaths& wxAppTraitsBase::GetStandardPaths()
90{
91 return gs_stdPaths;
92}
93
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
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
118wxString wxStandardPathsBase::GetDocumentsDir() const
119{
120 return wxFileName::GetHomeDir();
121}
122
123wxString wxStandardPathsBase::GetAppDocumentsDir() const
124{
125 const wxString docsDir = GetDocumentsDir();
126 wxString appDocsDir = AppendAppInfo(docsDir);
127
128 return wxDirExists(appDocsDir) ? appDocsDir : docsDir;
129}
130
131// return the temporary directory for the current user
132wxString wxStandardPathsBase::GetTempDir() const
133{
134 return wxFileName::GetTempDir();
135}
136
137/* static */
138wxString
139wxStandardPathsBase::AppendPathComponent(const wxString& dir,
140 const wxString& component)
141{
142 wxString subdir(dir);
143
144 // empty string indicates that an error has occurred, don't touch it then
145 if ( !subdir.empty() )
146 {
147 if ( !component.empty() )
148 {
149 const wxChar ch = *(subdir.end() - 1);
150 if ( !wxFileName::IsPathSeparator(ch) && ch != wxT('.') )
151 subdir += wxFileName::GetPathSeparator();
152
153 subdir += component;
154 }
155 }
156
157 return subdir;
158}
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