]>
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 | ||
39 | #ifndef __WINDOWS__ | |
40 | #include <unistd.h> | |
41 | #endif | |
e9aad10a | 42 | |
afcaf277 | 43 | IMPLEMENT_CLASS(wxExtHelpController, wxHTMLHelpControllerBase) |
31528cd3 | 44 | |
e9aad10a KB |
45 | /** |
46 | This class implements help via an external browser. | |
47 | It requires the name of a directory containing the documentation | |
48 | and a file mapping numerical Section numbers to relative URLS. | |
49 | */ | |
50 | ||
51 | wxExtHelpController::wxExtHelpController(void) | |
52 | { | |
e9aad10a KB |
53 | m_BrowserName = WXEXTHELP_DEFAULTBROWSER; |
54 | m_BrowserIsNetscape = WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE; | |
55 | ||
56 | char *browser = getenv(WXEXTHELP_ENVVAR_BROWSER); | |
57 | if(browser) | |
58 | { | |
59 | m_BrowserName = browser; | |
60 | browser = getenv(WXEXTHELP_ENVVAR_BROWSERISNETSCAPE); | |
61 | m_BrowserIsNetscape = browser && (atoi(browser) != 0); | |
62 | } | |
63 | } | |
64 | ||
e9aad10a KB |
65 | |
66 | void | |
67 | wxExtHelpController::SetBrowser(wxString const & browsername, bool isNetscape) | |
68 | { | |
69 | m_BrowserName = browsername; | |
70 | m_BrowserIsNetscape = isNetscape; | |
71 | } | |
72 | ||
33b64e6f JS |
73 | // Set viewer: new, generic name for SetBrowser |
74 | void wxExtHelpController::SetViewer(const wxString& viewer, long flags) | |
75 | { | |
76 | SetBrowser(viewer, ((flags & wxHELP_NETSCAPE) == wxHELP_NETSCAPE)); | |
77 | } | |
78 | ||
e9aad10a | 79 | bool |
afcaf277 | 80 | wxExtHelpController::DisplayHelp(wxString const &relativeURL) |
e9aad10a KB |
81 | { |
82 | wxBusyCursor b; // display a busy cursor | |
6e5fefdf KB |
83 | |
84 | ||
85 | #ifdef __WXMSW__ | |
f96b60aa VZ |
86 | wxString url; |
87 | url << m_MapFile << '\\' << relativeURL.BeforeFirst('#'); | |
88 | bool bOk = (int)ShellExecute(NULL, "open", url, | |
89 | NULL, NULL, SW_SHOWNORMAL ) > 32; | |
6e5fefdf KB |
90 | if ( !bOk ) |
91 | { | |
92 | wxLogSysError(_("Cannot open URL '%s'"), relativeURL.c_str()); | |
93 | return false; | |
94 | } | |
95 | else | |
96 | return true; | |
97 | #else | |
98 | // assume UNIX | |
e9aad10a KB |
99 | wxString command; |
100 | ||
101 | if(m_BrowserIsNetscape) // try re-loading first | |
102 | { | |
103 | wxString lockfile; | |
104 | wxGetHomeDir(&lockfile); | |
e90c1d2a | 105 | lockfile << WXEXTHELP_SEPARATOR << T(".netscape/lock"); |
e9aad10a | 106 | struct stat statbuf; |
87138c52 | 107 | if(lstat(lockfile.fn_str(), &statbuf) == 0) |
e9aad10a KB |
108 | // cannot use wxFileExists, because it's a link pointing to a |
109 | // non-existing location if(wxFileExists(lockfile)) | |
110 | { | |
111 | long success; | |
e90c1d2a VZ |
112 | command << m_BrowserName << T(" -remote openURL(") |
113 | << T("file://") << m_MapFile | |
114 | << WXEXTHELP_SEPARATOR << relativeURL << T(")"); | |
e9aad10a KB |
115 | success = wxExecute(command); |
116 | if(success != 0 ) // returns PID on success | |
5dcf05ae | 117 | return TRUE; |
e9aad10a KB |
118 | } |
119 | } | |
120 | command = m_BrowserName; | |
e90c1d2a | 121 | command << T(" file://") |
31528cd3 VZ |
122 | << m_MapFile << WXEXTHELP_SEPARATOR << relativeURL; |
123 | return wxExecute(command) != 0; | |
6e5fefdf | 124 | #endif |
e9aad10a KB |
125 | } |
126 | ||
31528cd3 | 127 | #endif // wxUSE_HELP |
e9aad10a | 128 |