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"
24 #include "wx/string.h"
30 #include "wx/helpbase.h"
31 #include "wx/generic/helpext.h"
41 IMPLEMENT_CLASS(wxExtHelpController
, wxHTMLHelpControllerBase
)
44 This class implements help via an external browser.
45 It requires the name of a directory containing the documentation
46 and a file mapping numerical Section numbers to relative URLS.
49 wxExtHelpController::wxExtHelpController(void)
51 m_BrowserName
= WXEXTHELP_DEFAULTBROWSER
;
52 m_BrowserIsNetscape
= WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE
;
54 char *browser
= getenv(WXEXTHELP_ENVVAR_BROWSER
);
57 m_BrowserName
= browser
;
58 browser
= getenv(WXEXTHELP_ENVVAR_BROWSERISNETSCAPE
);
59 m_BrowserIsNetscape
= browser
&& (atoi(browser
) != 0);
65 wxExtHelpController::SetBrowser(wxString
const & browsername
, bool isNetscape
)
67 m_BrowserName
= browsername
;
68 m_BrowserIsNetscape
= isNetscape
;
71 // Set viewer: new, generic name for SetBrowser
72 void wxExtHelpController::SetViewer(const wxString
& viewer
, long flags
)
74 SetBrowser(viewer
, ((flags
& wxHELP_NETSCAPE
) == wxHELP_NETSCAPE
));
78 wxExtHelpController::DisplayHelp(wxString
const &relativeURL
)
80 wxBusyCursor b
; // display a busy cursor
85 url
<< m_MapFile
<< '\\' << relativeURL
.BeforeFirst('#');
86 bool bOk
= (int)ShellExecute(NULL
, "open", url
,
87 NULL
, NULL
, SW_SHOWNORMAL
) > 32;
90 wxLogSysError(_("Cannot open URL '%s'"), relativeURL
.c_str());
99 if(m_BrowserIsNetscape
) // try re-loading first
102 wxGetHomeDir(&lockfile
);
103 lockfile
<< WXEXTHELP_SEPARATOR
<< _T(".netscape/lock");
105 if(lstat(lockfile
.fn_str(), &statbuf
) == 0)
106 // cannot use wxFileExists, because it's a link pointing to a
107 // non-existing location if(wxFileExists(lockfile))
110 command
<< m_BrowserName
<< _T(" -remote openURL(")
111 << _T("file://") << m_MapFile
112 << WXEXTHELP_SEPARATOR
<< relativeURL
<< _T(")");
113 success
= wxExecute(command
);
114 if(success
!= 0 ) // returns PID on success
118 command
= m_BrowserName
;
119 command
<< _T(" file://")
120 << m_MapFile
<< WXEXTHELP_SEPARATOR
<< relativeURL
;
121 return wxExecute(command
) != 0;