use wxLaunchDefaultBrowser by default if no browser is specified

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38394 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-03-27 20:23:33 +00:00
parent 2364556be3
commit a85a25c7d8
2 changed files with 29 additions and 87 deletions

View File

@@ -14,13 +14,6 @@
#include "wx/helpbase.h" #include "wx/helpbase.h"
#ifndef WXEXTHELP_DEFAULTBROWSER
/// Default browser name.
# define WXEXTHELP_DEFAULTBROWSER _T("netscape")
/// Is default browse a variant of netscape?
# define WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE true
#endif
/** /**
This class implements help via an external browser. This class implements help via an external browser.
It requires the name of a directory containing the documentation It requires the name of a directory containing the documentation
@@ -54,12 +47,12 @@ public:
@param browsername The command to call a browser/html viewer. @param browsername The command to call a browser/html viewer.
@param isNetscape Set this to true if the browser is some variant of Netscape. @param isNetscape Set this to true if the browser is some variant of Netscape.
*/ */
// Obsolete form void SetBrowser(const wxString& browsername = wxEmptyString,
void SetBrowser(const wxString & browsername = WXEXTHELP_DEFAULTBROWSER, bool isNetscape = false);
bool isNetscape = WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE);
// Set viewer: new name for SetBrowser // Set viewer: new name for SetBrowser
virtual void SetViewer(const wxString& viewer = WXEXTHELP_DEFAULTBROWSER, long flags = wxHELP_NETSCAPE); virtual void SetViewer(const wxString& viewer = wxEmptyString,
long flags = wxHELP_NETSCAPE);
/** This must be called to tell the controller where to find the /** This must be called to tell the controller where to find the
documentation. documentation.

View File

@@ -73,13 +73,12 @@ IMPLEMENT_CLASS(wxExtHelpController, wxHelpControllerBase)
and a file mapping numerical Section numbers to relative URLS. and a file mapping numerical Section numbers to relative URLS.
*/ */
wxExtHelpController::wxExtHelpController(wxWindow* parentWindow): wxExtHelpController::wxExtHelpController(wxWindow* parentWindow)
wxHelpControllerBase(parentWindow) : wxHelpControllerBase(parentWindow)
{ {
m_MapList = (wxList*) NULL; m_MapList = NULL;
m_NumOfEntries = 0; m_NumOfEntries = 0;
m_BrowserName = WXEXTHELP_DEFAULTBROWSER; m_BrowserIsNetscape = false;
m_BrowserIsNetscape = WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE;
wxChar *browser = wxGetenv(WXEXTHELP_ENVVAR_BROWSER); wxChar *browser = wxGetenv(WXEXTHELP_ENVVAR_BROWSER);
if(browser) if(browser)
@@ -104,85 +103,35 @@ void wxExtHelpController::SetBrowser(const wxString& browsername, bool isNetscap
// Set viewer: new, generic name for SetBrowser // Set viewer: new, generic name for SetBrowser
void wxExtHelpController::SetViewer(const wxString& viewer, long flags) void wxExtHelpController::SetViewer(const wxString& viewer, long flags)
{ {
SetBrowser(viewer, ((flags & wxHELP_NETSCAPE) == wxHELP_NETSCAPE)); SetBrowser(viewer, (flags & wxHELP_NETSCAPE) != 0);
} }
bool bool
wxExtHelpController::DisplayHelp(const wxString &relativeURL) wxExtHelpController::DisplayHelp(const wxString &relativeURL)
{ {
wxBusyCursor b; // display a busy cursor // construct hte URL to open -- it's just a file
wxString url(_T("file://") + m_helpDir);
url << wxFILE_SEP_PATH << relativeURL;
// use the explicit browser program if specified
#if defined(__WXMSW__) if ( !m_BrowserName.empty() )
wxString url; {
url << m_helpDir << '\\' << relativeURL.BeforeFirst('#'); if ( m_BrowserIsNetscape )
bool bOk = (int)ShellExecute(NULL, wxT("open"), url.c_str(),
NULL, NULL, SW_SHOWNORMAL ) > 32;
if ( !bOk )
{ {
wxLogSysError(_("Cannot open URL '%s'"), relativeURL.c_str());
return false;
}
return true;
#elif defined(__OS2__)
wxString url;
url << m_helpDir << '\\' << relativeURL.BeforeFirst('#');
// will have to fix for OS/2, later.....DW
// bool bOk = (int)ShellExecute(NULL, "open", url,
// NULL, NULL, SW_SHOWNORMAL ) > 32;
// if ( !bOk )
// {
// wxLogSysError(_("Cannot open URL '%s'"), relativeURL.c_str());
// return false;
// }
// else
return true;
#elif defined(__DOS__)
wxString command; wxString command;
command = m_BrowserName; command << m_BrowserName
command << wxT(" file://") << wxT(" -remote openURL(") << url << wxT(')');
<< m_helpDir << wxFILE_SEP_PATH << relativeURL; if ( wxExecute(command, wxEXEC_SYNC) != -1 )
return wxExecute(command) != 0;
#else // UNIX
wxString command;
#ifndef __EMX__
if(m_BrowserIsNetscape) // try re-loading first
{
wxString lockfile;
wxGetHomeDir(&lockfile);
#ifdef __VMS__
lockfile << wxFILE_SEP_PATH << wxT(".netscape]lock.");
struct stat statbuf;
if(stat(lockfile.fn_str(), &statbuf) == 0)
#else
lockfile << wxFILE_SEP_PATH << wxT(".netscape/lock");
struct stat statbuf;
if(lstat(lockfile.fn_str(), &statbuf) == 0)
// cannot use wxFileExists, because it's a link pointing to a
// non-existing location if(wxFileExists(lockfile))
#endif
{
long success;
command << m_BrowserName << wxT(" -remote openURL(")
<< wxT("file://") << m_helpDir
<< wxFILE_SEP_PATH << relativeURL << wxT(")");
success = wxExecute(command);
if(success != 0 ) // returns PID on success
return true; return true;
} }
if ( wxExecute(m_BrowserName + _T(' ') + url, wxEXEC_SYNC) != -1 )
return true;
} }
#endif //else: either no browser explicitly specified or we failed to open it
command = m_BrowserName;
command << wxT(" file://") // just use default browser
<< m_helpDir << wxFILE_SEP_PATH << relativeURL; return wxLaunchDefaultBrowser(url);
return wxExecute(command) != 0;
#endif
} }
class wxExtHelpMapEntry : public wxObject class wxExtHelpMapEntry : public wxObject