]> git.saurik.com Git - wxWidgets.git/blame - src/generic/helpext.cpp
added constructor for compliance with wxPython
[wxWidgets.git] / src / generic / helpext.cpp
CommitLineData
f96b60aa
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: helpext.cpp
3// Purpose: an external help controller for wxWindows
4// Author: Karsten Ballueder
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Karsten Ballueder
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
e9aad10a
KB
12#ifdef __GNUG__
13# pragma implementation "wxexthlp.h"
14#endif
15
f96b60aa
VZ
16#include "wx/wxprec.h"
17
18#ifdef __BORLANDC__
19 #pragma hdrstop
20#endif
21
31528cd3
VZ
22#if wxUSE_HELP
23
f96b60aa
VZ
24#ifndef WX_PRECOMP
25 #include "wx/setup.h"
26 #include "wx/string.h"
27 #include "wx/utils.h"
28 #include "wx/list.h"
29 #include "wx/intl.h"
30#endif
31
32#include "wx/helpbase.h"
33#include "wx/generic/helpext.h"
34
35#include <stdio.h>
36#include <ctype.h>
37#include <sys/stat.h>
38
004fd0c8 39#if !defined(__WINDOWS__) && !defined(__OS2__)
f96b60aa
VZ
40 #include <unistd.h>
41#endif
e9aad10a 42
583f6c5c
JS
43#ifdef __WXMSW__
44#include <windows.h>
45#endif
46
afcaf277 47IMPLEMENT_CLASS(wxExtHelpController, wxHTMLHelpControllerBase)
31528cd3 48
e9aad10a
KB
49/**
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.
53*/
54
55wxExtHelpController::wxExtHelpController(void)
56{
e9aad10a
KB
57 m_BrowserName = WXEXTHELP_DEFAULTBROWSER;
58 m_BrowserIsNetscape = WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE;
59
60 char *browser = getenv(WXEXTHELP_ENVVAR_BROWSER);
61 if(browser)
62 {
63 m_BrowserName = browser;
64 browser = getenv(WXEXTHELP_ENVVAR_BROWSERISNETSCAPE);
65 m_BrowserIsNetscape = browser && (atoi(browser) != 0);
66 }
67}
68
e9aad10a
KB
69
70void
71wxExtHelpController::SetBrowser(wxString const & browsername, bool isNetscape)
72{
73 m_BrowserName = browsername;
74 m_BrowserIsNetscape = isNetscape;
75}
76
33b64e6f
JS
77// Set viewer: new, generic name for SetBrowser
78void wxExtHelpController::SetViewer(const wxString& viewer, long flags)
79{
80 SetBrowser(viewer, ((flags & wxHELP_NETSCAPE) == wxHELP_NETSCAPE));
81}
82
e9aad10a 83bool
f6bcfd97 84wxExtHelpController::DisplayHelp(const wxString &relativeURL)
e9aad10a
KB
85{
86 wxBusyCursor b; // display a busy cursor
6e5fefdf
KB
87
88
004fd0c8 89#if defined(__WXMSW__)
f96b60aa
VZ
90 wxString url;
91 url << m_MapFile << '\\' << relativeURL.BeforeFirst('#');
f6bcfd97 92 bool bOk = (int)ShellExecute(NULL, wxT("open"), url.c_str(),
f96b60aa 93 NULL, NULL, SW_SHOWNORMAL ) > 32;
6e5fefdf
KB
94 if ( !bOk )
95 {
96 wxLogSysError(_("Cannot open URL '%s'"), relativeURL.c_str());
97 return false;
98 }
99 else
100 return true;
b13f5fbf 101
004fd0c8 102#elif defined(__WXPM__)
b13f5fbf 103
004fd0c8
DW
104 wxString url;
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;
109// if ( !bOk )
110// {
111// wxLogSysError(_("Cannot open URL '%s'"), relativeURL.c_str());
112// return false;
113// }
114// else
115 return TRUE;
b13f5fbf
VS
116
117#elif defined(__DOS__)
118
119 wxString command;
120 command = m_BrowserName;
121 command << wxT(" file://")
122 << m_MapFile << WXEXTHELP_SEPARATOR << relativeURL;
123 return wxExecute(command) != 0;
124
125#else // UNIX
e9aad10a
KB
126 wxString command;
127
128 if(m_BrowserIsNetscape) // try re-loading first
129 {
130 wxString lockfile;
131 wxGetHomeDir(&lockfile);
e0b3e85b
JJ
132#ifdef __VMS__
133 lockfile << WXEXTHELP_SEPARATOR << wxT(".netscape]lock.");
134 struct stat statbuf;
135 if(stat(lockfile.fn_str(), &statbuf) == 0)
136#else
223d09f6 137 lockfile << WXEXTHELP_SEPARATOR << wxT(".netscape/lock");
e9aad10a 138 struct stat statbuf;
87138c52 139 if(lstat(lockfile.fn_str(), &statbuf) == 0)
e9aad10a
KB
140 // cannot use wxFileExists, because it's a link pointing to a
141 // non-existing location if(wxFileExists(lockfile))
e0b3e85b
JJ
142#endif
143 {
e9aad10a 144 long success;
223d09f6
KB
145 command << m_BrowserName << wxT(" -remote openURL(")
146 << wxT("file://") << m_MapFile
147 << WXEXTHELP_SEPARATOR << relativeURL << wxT(")");
e9aad10a
KB
148 success = wxExecute(command);
149 if(success != 0 ) // returns PID on success
5dcf05ae 150 return TRUE;
e9aad10a
KB
151 }
152 }
153 command = m_BrowserName;
223d09f6 154 command << wxT(" file://")
31528cd3
VZ
155 << m_MapFile << WXEXTHELP_SEPARATOR << relativeURL;
156 return wxExecute(command) != 0;
6e5fefdf 157#endif
e9aad10a
KB
158}
159
31528cd3 160#endif // wxUSE_HELP
e9aad10a 161