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