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__)
47 IMPLEMENT_CLASS(wxExtHelpController
, wxHTMLHelpControllerBase
)
50 This class implements help via an external browser.
51 It requires the name of a directory containing the documentation
52 and a file mapping numerical Section numbers to relative URLS.
55 wxExtHelpController::wxExtHelpController(void)
57 m_BrowserName
= WXEXTHELP_DEFAULTBROWSER
;
58 m_BrowserIsNetscape
= WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE
;
60 char *browser
= getenv(WXEXTHELP_ENVVAR_BROWSER
);
63 m_BrowserName
= browser
;
64 browser
= getenv(WXEXTHELP_ENVVAR_BROWSERISNETSCAPE
);
65 m_BrowserIsNetscape
= browser
&& (atoi(browser
) != 0);
71 wxExtHelpController::SetBrowser(wxString
const & browsername
, bool isNetscape
)
73 m_BrowserName
= browsername
;
74 m_BrowserIsNetscape
= isNetscape
;
77 // Set viewer: new, generic name for SetBrowser
78 void wxExtHelpController::SetViewer(const wxString
& viewer
, long flags
)
80 SetBrowser(viewer
, ((flags
& wxHELP_NETSCAPE
) == wxHELP_NETSCAPE
));
84 wxExtHelpController::DisplayHelp(const wxString
&relativeURL
)
86 wxBusyCursor b
; // display a busy cursor
89 #if defined(__WXMSW__)
91 url
<< m_MapFile
<< '\\' << relativeURL
.BeforeFirst('#');
92 bool bOk
= (int)ShellExecute(NULL
, wxT("open"), url
.c_str(),
93 NULL
, NULL
, SW_SHOWNORMAL
) > 32;
96 wxLogSysError(_("Cannot open URL '%s'"), relativeURL
.c_str());
102 #elif defined(__WXPM__)
105 url
<< m_MapFile
<< '\\' << relativeURL
.BeforeFirst('#');
106 // will have to fix for OS/2, later.....DW
107 // bool bOk = (int)ShellExecute(NULL, "open", url,
108 // NULL, NULL, SW_SHOWNORMAL ) > 32;
111 // wxLogSysError(_("Cannot open URL '%s'"), relativeURL.c_str());
117 #elif defined(__DOS__)
120 command
= m_BrowserName
;
121 command
<< wxT(" file://")
122 << m_MapFile
<< WXEXTHELP_SEPARATOR
<< relativeURL
;
123 return wxExecute(command
) != 0;
128 if(m_BrowserIsNetscape
) // try re-loading first
131 wxGetHomeDir(&lockfile
);
133 lockfile
<< WXEXTHELP_SEPARATOR
<< wxT(".netscape]lock.");
135 if(stat(lockfile
.fn_str(), &statbuf
) == 0)
137 lockfile
<< WXEXTHELP_SEPARATOR
<< wxT(".netscape/lock");
139 if(lstat(lockfile
.fn_str(), &statbuf
) == 0)
140 // cannot use wxFileExists, because it's a link pointing to a
141 // non-existing location if(wxFileExists(lockfile))
145 command
<< m_BrowserName
<< wxT(" -remote openURL(")
146 << wxT("file://") << m_MapFile
147 << WXEXTHELP_SEPARATOR
<< relativeURL
<< wxT(")");
148 success
= wxExecute(command
);
149 if(success
!= 0 ) // returns PID on success
153 command
= m_BrowserName
;
154 command
<< wxT(" file://")
155 << m_MapFile
<< WXEXTHELP_SEPARATOR
<< relativeURL
;
156 return wxExecute(command
) != 0;