]> git.saurik.com Git - wxWidgets.git/blob - src/generic/helpext.cpp
Don't prepend directory to filename for shortcuts
[wxWidgets.git] / src / generic / helpext.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: helpext.cpp
3 // Purpose: an external help controller for wxWindows
4 // Author: Karsten Ballueder
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Karsten Ballueder
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 # pragma implementation "wxexthlp.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #if wxUSE_HELP
23
24 #ifndef WX_PRECOMP
25 #include "wx/setup.h"
26 #include "wx/string.h"
27 #include "wx/utils.h"
28 #include "wx/list.h"
29 #include "wx/intl.h"
30 #endif
31
32 #include "wx/helpbase.h"
33 #include "wx/generic/helpext.h"
34
35 #include <stdio.h>
36 #include <ctype.h>
37 #include <sys/stat.h>
38
39 #if !defined(__WINDOWS__) && !defined(__OS2__)
40 #include <unistd.h>
41 #endif
42
43 #ifdef __WXMSW__
44 #include <windows.h>
45 #endif
46
47 IMPLEMENT_CLASS(wxExtHelpController, wxHTMLHelpControllerBase)
48
49 /// Name of environment variable to set help browser.
50 #define WXEXTHELP_ENVVAR_BROWSER wxT("WX_HELPBROWSER")
51 /// Is browser a netscape browser?
52 #define WXEXTHELP_ENVVAR_BROWSERISNETSCAPE wxT("WX_HELPBROWSER_NS")
53
54 /**
55 This class implements help via an external browser.
56 It requires the name of a directory containing the documentation
57 and a file mapping numerical Section numbers to relative URLS.
58 */
59
60 wxExtHelpController::wxExtHelpController(void)
61 {
62 m_BrowserName = WXEXTHELP_DEFAULTBROWSER;
63 m_BrowserIsNetscape = WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE;
64
65 wxChar *browser = wxGetenv(WXEXTHELP_ENVVAR_BROWSER);
66 if(browser)
67 {
68 m_BrowserName = browser;
69 browser = wxGetenv(WXEXTHELP_ENVVAR_BROWSERISNETSCAPE);
70 m_BrowserIsNetscape = browser && (wxAtoi(browser) != 0);
71 }
72 }
73
74
75 void wxExtHelpController::SetBrowser(wxString const & browsername, bool isNetscape)
76 {
77 m_BrowserName = browsername;
78 m_BrowserIsNetscape = isNetscape;
79 }
80
81 // Set viewer: new, generic name for SetBrowser
82 void wxExtHelpController::SetViewer(const wxString& viewer, long flags)
83 {
84 SetBrowser(viewer, ((flags & wxHELP_NETSCAPE) == wxHELP_NETSCAPE));
85 }
86
87 bool
88 wxExtHelpController::DisplayHelp(const wxString &relativeURL)
89 {
90 wxBusyCursor b; // display a busy cursor
91
92
93 #if defined(__WXMSW__)
94 wxString url;
95 url << m_MapFile << '\\' << relativeURL.BeforeFirst('#');
96 bool bOk = (int)ShellExecute(NULL, wxT("open"), url.c_str(),
97 NULL, NULL, SW_SHOWNORMAL ) > 32;
98 if ( !bOk )
99 {
100 wxLogSysError(_("Cannot open URL '%s'"), relativeURL.c_str());
101 return false;
102 }
103 else
104 return true;
105
106 #elif defined(__WXPM__)
107
108 wxString url;
109 url << m_MapFile << '\\' << relativeURL.BeforeFirst('#');
110 // will have to fix for OS/2, later.....DW
111 // bool bOk = (int)ShellExecute(NULL, "open", url,
112 // NULL, NULL, SW_SHOWNORMAL ) > 32;
113 // if ( !bOk )
114 // {
115 // wxLogSysError(_("Cannot open URL '%s'"), relativeURL.c_str());
116 // return false;
117 // }
118 // else
119 return TRUE;
120
121 #elif defined(__DOS__)
122
123 wxString command;
124 command = m_BrowserName;
125 command << wxT(" file://")
126 << m_MapFile << WXEXTHELP_SEPARATOR << relativeURL;
127 return wxExecute(command) != 0;
128
129 #else // UNIX
130 wxString command;
131
132 #ifndef __EMX__
133 if(m_BrowserIsNetscape) // try re-loading first
134 {
135 wxString lockfile;
136 wxGetHomeDir(&lockfile);
137 #ifdef __VMS__
138 lockfile << WXEXTHELP_SEPARATOR << wxT(".netscape]lock.");
139 struct stat statbuf;
140 if(stat(lockfile.fn_str(), &statbuf) == 0)
141 #else
142 lockfile << WXEXTHELP_SEPARATOR << wxT(".netscape/lock");
143 struct stat statbuf;
144 if(lstat(lockfile.fn_str(), &statbuf) == 0)
145 // cannot use wxFileExists, because it's a link pointing to a
146 // non-existing location if(wxFileExists(lockfile))
147 #endif
148 {
149 long success;
150 command << m_BrowserName << wxT(" -remote openURL(")
151 << wxT("file://") << m_MapFile
152 << WXEXTHELP_SEPARATOR << relativeURL << wxT(")");
153 success = wxExecute(command);
154 if(success != 0 ) // returns PID on success
155 return TRUE;
156 }
157 }
158 #endif
159 command = m_BrowserName;
160 command << wxT(" file://")
161 << m_MapFile << WXEXTHELP_SEPARATOR << relativeURL;
162 return wxExecute(command) != 0;
163 #endif
164 }
165
166 #endif // wxUSE_HELP
167