From a85a25c7d87236d3bd43d045138b41001a88738b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 27 Mar 2006 20:23:33 +0000 Subject: [PATCH] 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 --- include/wx/generic/helpext.h | 15 ++---- src/generic/helpext.cpp | 101 +++++++++-------------------------- 2 files changed, 29 insertions(+), 87 deletions(-) diff --git a/include/wx/generic/helpext.h b/include/wx/generic/helpext.h index 1305f108ff..9925bedb34 100644 --- a/include/wx/generic/helpext.h +++ b/include/wx/generic/helpext.h @@ -14,13 +14,6 @@ #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. 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 isNetscape Set this to true if the browser is some variant of Netscape. */ - // Obsolete form - void SetBrowser(const wxString & browsername = WXEXTHELP_DEFAULTBROWSER, - bool isNetscape = WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE); + void SetBrowser(const wxString& browsername = wxEmptyString, + bool isNetscape = false); // 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 documentation. diff --git a/src/generic/helpext.cpp b/src/generic/helpext.cpp index 27da957978..452af67289 100644 --- a/src/generic/helpext.cpp +++ b/src/generic/helpext.cpp @@ -73,13 +73,12 @@ IMPLEMENT_CLASS(wxExtHelpController, wxHelpControllerBase) and a file mapping numerical Section numbers to relative URLS. */ -wxExtHelpController::wxExtHelpController(wxWindow* parentWindow): - wxHelpControllerBase(parentWindow) +wxExtHelpController::wxExtHelpController(wxWindow* parentWindow) + : wxHelpControllerBase(parentWindow) { - m_MapList = (wxList*) NULL; + m_MapList = NULL; m_NumOfEntries = 0; - m_BrowserName = WXEXTHELP_DEFAULTBROWSER; - m_BrowserIsNetscape = WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE; + m_BrowserIsNetscape = false; wxChar *browser = wxGetenv(WXEXTHELP_ENVVAR_BROWSER); if(browser) @@ -104,85 +103,35 @@ void wxExtHelpController::SetBrowser(const wxString& browsername, bool isNetscap // Set viewer: new, generic name for SetBrowser void wxExtHelpController::SetViewer(const wxString& viewer, long flags) { - SetBrowser(viewer, ((flags & wxHELP_NETSCAPE) == wxHELP_NETSCAPE)); + SetBrowser(viewer, (flags & wxHELP_NETSCAPE) != 0); } bool 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; -#if defined(__WXMSW__) - wxString url; - url << m_helpDir << '\\' << relativeURL.BeforeFirst('#'); - 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__) + // use the explicit browser program if specified + if ( !m_BrowserName.empty() ) + { + if ( m_BrowserIsNetscape ) + { + wxString command; + command << m_BrowserName + << wxT(" -remote openURL(") << url << wxT(')'); + if ( wxExecute(command, wxEXEC_SYNC) != -1 ) + return true; + } - 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; - command = m_BrowserName; - command << wxT(" file://") - << m_helpDir << wxFILE_SEP_PATH << relativeURL; - 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 + if ( wxExecute(m_BrowserName + _T(' ') + url, wxEXEC_SYNC) != -1 ) return true; - } - } -#endif - command = m_BrowserName; - command << wxT(" file://") - << m_helpDir << wxFILE_SEP_PATH << relativeURL; - return wxExecute(command) != 0; -#endif + } + //else: either no browser explicitly specified or we failed to open it + + // just use default browser + return wxLaunchDefaultBrowser(url); } class wxExtHelpMapEntry : public wxObject -- 2.45.2