]>
Commit | Line | Data |
---|---|---|
f96b60aa VZ |
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 | ||
e9aad10a KB |
12 | #ifdef __GNUG__ |
13 | # pragma implementation "wxexthlp.h" | |
14 | #endif | |
15 | ||
f96b60aa VZ |
16 | #include "wx/wxprec.h" |
17 | ||
18 | #ifdef __BORLANDC__ | |
19 | #pragma hdrstop | |
20 | #endif | |
21 | ||
31528cd3 VZ |
22 | #if wxUSE_HELP |
23 | ||
f96b60aa VZ |
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 | ||
004fd0c8 | 39 | #if !defined(__WINDOWS__) && !defined(__OS2__) |
f96b60aa VZ |
40 | #include <unistd.h> |
41 | #endif | |
e9aad10a | 42 | |
583f6c5c JS |
43 | #ifdef __WXMSW__ |
44 | #include <windows.h> | |
45 | #endif | |
46 | ||
afcaf277 | 47 | IMPLEMENT_CLASS(wxExtHelpController, wxHTMLHelpControllerBase) |
31528cd3 | 48 | |
aa0ffd1d VZ |
49 | /// Name of environment variable to set help browser. |
50 | #define WXEXTHELP_ENVVAR_BROWSER "WX_HELPBROWSER" | |
51 | /// Is browser a netscape browser? | |
52 | #define WXEXTHELP_ENVVAR_BROWSERISNETSCAPE "WX_HELPBROWSER_NS" | |
53 | ||
e9aad10a KB |
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 | { | |
e9aad10a KB |
62 | m_BrowserName = WXEXTHELP_DEFAULTBROWSER; |
63 | m_BrowserIsNetscape = WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE; | |
64 | ||
65 | char *browser = getenv(WXEXTHELP_ENVVAR_BROWSER); | |
66 | if(browser) | |
67 | { | |
68 | m_BrowserName = browser; | |
69 | browser = getenv(WXEXTHELP_ENVVAR_BROWSERISNETSCAPE); | |
70 | m_BrowserIsNetscape = browser && (atoi(browser) != 0); | |
71 | } | |
72 | } | |
73 | ||
e9aad10a KB |
74 | |
75 | void | |
76 | wxExtHelpController::SetBrowser(wxString const & browsername, bool isNetscape) | |
77 | { | |
78 | m_BrowserName = browsername; | |
79 | m_BrowserIsNetscape = isNetscape; | |
80 | } | |
81 | ||
33b64e6f JS |
82 | // Set viewer: new, generic name for SetBrowser |
83 | void wxExtHelpController::SetViewer(const wxString& viewer, long flags) | |
84 | { | |
85 | SetBrowser(viewer, ((flags & wxHELP_NETSCAPE) == wxHELP_NETSCAPE)); | |
86 | } | |
87 | ||
e9aad10a | 88 | bool |
f6bcfd97 | 89 | wxExtHelpController::DisplayHelp(const wxString &relativeURL) |
e9aad10a KB |
90 | { |
91 | wxBusyCursor b; // display a busy cursor | |
6e5fefdf KB |
92 | |
93 | ||
004fd0c8 | 94 | #if defined(__WXMSW__) |
f96b60aa VZ |
95 | wxString url; |
96 | url << m_MapFile << '\\' << relativeURL.BeforeFirst('#'); | |
f6bcfd97 | 97 | bool bOk = (int)ShellExecute(NULL, wxT("open"), url.c_str(), |
f96b60aa | 98 | NULL, NULL, SW_SHOWNORMAL ) > 32; |
6e5fefdf KB |
99 | if ( !bOk ) |
100 | { | |
101 | wxLogSysError(_("Cannot open URL '%s'"), relativeURL.c_str()); | |
102 | return false; | |
103 | } | |
104 | else | |
105 | return true; | |
b13f5fbf | 106 | |
004fd0c8 | 107 | #elif defined(__WXPM__) |
b13f5fbf | 108 | |
004fd0c8 DW |
109 | wxString url; |
110 | url << m_MapFile << '\\' << relativeURL.BeforeFirst('#'); | |
111 | // will have to fix for OS/2, later.....DW | |
112 | // bool bOk = (int)ShellExecute(NULL, "open", url, | |
113 | // NULL, NULL, SW_SHOWNORMAL ) > 32; | |
114 | // if ( !bOk ) | |
115 | // { | |
116 | // wxLogSysError(_("Cannot open URL '%s'"), relativeURL.c_str()); | |
117 | // return false; | |
118 | // } | |
119 | // else | |
120 | return TRUE; | |
b13f5fbf VS |
121 | |
122 | #elif defined(__DOS__) | |
123 | ||
124 | wxString command; | |
125 | command = m_BrowserName; | |
126 | command << wxT(" file://") | |
127 | << m_MapFile << WXEXTHELP_SEPARATOR << relativeURL; | |
128 | return wxExecute(command) != 0; | |
129 | ||
130 | #else // UNIX | |
e9aad10a KB |
131 | wxString command; |
132 | ||
de560321 | 133 | #ifndef __EMX__ |
e9aad10a KB |
134 | if(m_BrowserIsNetscape) // try re-loading first |
135 | { | |
136 | wxString lockfile; | |
137 | wxGetHomeDir(&lockfile); | |
e0b3e85b JJ |
138 | #ifdef __VMS__ |
139 | lockfile << WXEXTHELP_SEPARATOR << wxT(".netscape]lock."); | |
140 | struct stat statbuf; | |
141 | if(stat(lockfile.fn_str(), &statbuf) == 0) | |
142 | #else | |
223d09f6 | 143 | lockfile << WXEXTHELP_SEPARATOR << wxT(".netscape/lock"); |
e9aad10a | 144 | struct stat statbuf; |
87138c52 | 145 | if(lstat(lockfile.fn_str(), &statbuf) == 0) |
e9aad10a KB |
146 | // cannot use wxFileExists, because it's a link pointing to a |
147 | // non-existing location if(wxFileExists(lockfile)) | |
e0b3e85b | 148 | #endif |
aa0ffd1d | 149 | { |
e9aad10a | 150 | long success; |
223d09f6 KB |
151 | command << m_BrowserName << wxT(" -remote openURL(") |
152 | << wxT("file://") << m_MapFile | |
153 | << WXEXTHELP_SEPARATOR << relativeURL << wxT(")"); | |
e9aad10a KB |
154 | success = wxExecute(command); |
155 | if(success != 0 ) // returns PID on success | |
5dcf05ae | 156 | return TRUE; |
e9aad10a KB |
157 | } |
158 | } | |
de560321 | 159 | #endif |
e9aad10a | 160 | command = m_BrowserName; |
223d09f6 | 161 | command << wxT(" file://") |
31528cd3 VZ |
162 | << m_MapFile << WXEXTHELP_SEPARATOR << relativeURL; |
163 | return wxExecute(command) != 0; | |
6e5fefdf | 164 | #endif |
e9aad10a KB |
165 | } |
166 | ||
31528cd3 | 167 | #endif // wxUSE_HELP |
e9aad10a | 168 |