1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: an external help controller for wxWindows
4 // Author: Karsten Ballueder
8 // Copyright: (c) Karsten Ballueder
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 # pragma implementation "wxexthlp.h"
16 #include "wx/wxprec.h"
26 #include "wx/string.h"
32 #include "wx/helpbase.h"
33 #include "wx/generic/helpext.h"
39 #if !defined(__WINDOWS__) && !defined(__OS2__)
43 IMPLEMENT_CLASS(wxExtHelpController
, wxHTMLHelpControllerBase
)
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.
51 wxExtHelpController::wxExtHelpController(void)
53 m_BrowserName
= WXEXTHELP_DEFAULTBROWSER
;
54 m_BrowserIsNetscape
= WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE
;
56 char *browser
= getenv(WXEXTHELP_ENVVAR_BROWSER
);
59 m_BrowserName
= browser
;
60 browser
= getenv(WXEXTHELP_ENVVAR_BROWSERISNETSCAPE
);
61 m_BrowserIsNetscape
= browser
&& (atoi(browser
) != 0);
67 wxExtHelpController::SetBrowser(wxString
const & browsername
, bool isNetscape
)
69 m_BrowserName
= browsername
;
70 m_BrowserIsNetscape
= isNetscape
;
73 // Set viewer: new, generic name for SetBrowser
74 void wxExtHelpController::SetViewer(const wxString
& viewer
, long flags
)
76 SetBrowser(viewer
, ((flags
& wxHELP_NETSCAPE
) == wxHELP_NETSCAPE
));
80 wxExtHelpController::DisplayHelp(wxString
const &relativeURL
)
82 wxBusyCursor b
; // display a busy cursor
85 #if defined(__WXMSW__)
87 url
<< m_MapFile
<< '\\' << relativeURL
.BeforeFirst('#');
88 bool bOk
= (int)ShellExecute(NULL
, "open", url
,
89 NULL
, NULL
, SW_SHOWNORMAL
) > 32;
92 wxLogSysError(_("Cannot open URL '%s'"), relativeURL
.c_str());
97 #elif defined(__WXPM__)
99 url
<< m_MapFile
<< '\\' << relativeURL
.BeforeFirst('#');
100 // will have to fix for OS/2, later.....DW
101 // bool bOk = (int)ShellExecute(NULL, "open", url,
102 // NULL, NULL, SW_SHOWNORMAL ) > 32;
105 // wxLogSysError(_("Cannot open URL '%s'"), relativeURL.c_str());
114 if(m_BrowserIsNetscape
) // try re-loading first
117 wxGetHomeDir(&lockfile
);
118 lockfile
<< WXEXTHELP_SEPARATOR
<< wxT(".netscape/lock");
120 if(lstat(lockfile
.fn_str(), &statbuf
) == 0)
121 // cannot use wxFileExists, because it's a link pointing to a
122 // non-existing location if(wxFileExists(lockfile))
125 command
<< m_BrowserName
<< wxT(" -remote openURL(")
126 << wxT("file://") << m_MapFile
127 << WXEXTHELP_SEPARATOR
<< relativeURL
<< wxT(")");
128 success
= wxExecute(command
);
129 if(success
!= 0 ) // returns PID on success
133 command
= m_BrowserName
;
134 command
<< wxT(" file://")
135 << m_MapFile
<< WXEXTHELP_SEPARATOR
<< relativeURL
;
136 return wxExecute(command
) != 0;