]> git.saurik.com Git - wxWidgets.git/blame - src/common/stdpbase.cpp
Applied #13738: Make a wxRichTextImage's box display around the image (dghart)
[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
39static wxStandardPaths gs_stdPaths;
40
41// ============================================================================
42// implementation
43// ============================================================================
44
45/* static */
25f49256 46wxStandardPaths& wxStandardPathsBase::Get()
fc480dc1 47{
81f9c575 48 wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
9a83f860 49 wxCHECK_MSG( traits, gs_stdPaths, wxT("create wxApp before calling this") );
81f9c575
VZ
50
51 return traits->GetStandardPaths();
fc480dc1
DE
52}
53
ac7ad70d
RR
54wxString wxStandardPathsBase::GetExecutablePath() const
55{
d154ab3d 56 if ( !wxTheApp || !wxTheApp->argv )
ac7ad70d
RR
57 return wxEmptyString;
58
59 wxString argv0 = wxTheApp->argv[0];
60 if (wxIsAbsolutePath(argv0))
61 return argv0;
62
63 // Search PATH.environment variable...
64 wxPathList pathlist;
65 pathlist.AddEnvList(wxT("PATH"));
66 wxString path = pathlist.FindAbsoluteValidPath(argv0);
67 if ( path.empty() )
68 return argv0; // better than nothing
69
70 wxFileName filename(path);
71 filename.Normalize();
72 return filename.GetFullPath();
73}
74
25f49256 75wxStandardPaths& wxAppTraitsBase::GetStandardPaths()
6cb5e50b
VZ
76{
77 return gs_stdPaths;
78}
79
2b147f2e
VZ
80wxStandardPathsBase::wxStandardPathsBase()
81{
82 // Set the default information that is used when
83 // forming some paths (by AppendAppInfo).
84 // Derived classes can call this in their constructors
85 // to set the platform-specific settings
86 UseAppInfo(AppInfo_AppName);
87}
88
6cb5e50b
VZ
89wxStandardPathsBase::~wxStandardPathsBase()
90{
91 // nothing to do here
92}
93
94wxString wxStandardPathsBase::GetLocalDataDir() const
95{
96 return GetDataDir();
97}
98
99wxString wxStandardPathsBase::GetUserLocalDataDir() const
100{
101 return GetUserDataDir();
102}
103
17af82fb
VZ
104wxString wxStandardPathsBase::GetDocumentsDir() const
105{
106 return wxFileName::GetHomeDir();
107}
108
d8efd219
VZ
109wxString wxStandardPathsBase::GetAppDocumentsDir() const
110{
111 const wxString docsDir = GetDocumentsDir();
112 wxString appDocsDir = AppendAppInfo(docsDir);
113
114 return wxDirExists(appDocsDir) ? appDocsDir : docsDir;
115}
116
ecf9559d
JS
117// return the temporary directory for the current user
118wxString wxStandardPathsBase::GetTempDir() const
119{
120 return wxFileName::GetTempDir();
121}
122
ce336c6d 123/* static */
d8efd219
VZ
124wxString
125wxStandardPathsBase::AppendPathComponent(const wxString& dir,
126 const wxString& component)
ce336c6d
VZ
127{
128 wxString subdir(dir);
129
3103e8a9 130 // empty string indicates that an error has occurred, don't touch it then
ce336c6d
VZ
131 if ( !subdir.empty() )
132 {
2b147f2e 133 if ( !component.empty() )
ce336c6d
VZ
134 {
135 const wxChar ch = *(subdir.end() - 1);
9a83f860 136 if ( !wxFileName::IsPathSeparator(ch) && ch != wxT('.') )
ce336c6d
VZ
137 subdir += wxFileName::GetPathSeparator();
138
2b147f2e 139 subdir += component;
ce336c6d
VZ
140 }
141 }
142
143 return subdir;
144}
2b147f2e
VZ
145
146
147wxString wxStandardPathsBase::AppendAppInfo(const wxString& dir) const
148{
149 wxString subdir(dir);
150
151 if ( UsesAppInfo(AppInfo_VendorName) )
152 {
153 subdir = AppendPathComponent(subdir, wxTheApp->GetVendorName());
154 }
155
156 if ( UsesAppInfo(AppInfo_AppName) )
157 {
158 subdir = AppendPathComponent(subdir, wxTheApp->GetAppName());
159 }
160
161 return subdir;
162}
163