]> git.saurik.com Git - wxWidgets.git/blame - src/generic/helpext.cpp
bug fix for m_parent == NULL
[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
22#ifndef WX_PRECOMP
23 #include "wx/setup.h"
24 #include "wx/string.h"
25 #include "wx/utils.h"
26 #include "wx/list.h"
27 #include "wx/intl.h"
28#endif
29
30#include "wx/helpbase.h"
31#include "wx/generic/helpext.h"
32
33#include <stdio.h>
34#include <ctype.h>
35#include <sys/stat.h>
36
37#ifndef __WINDOWS__
38 #include <unistd.h>
39#endif
e9aad10a 40
afcaf277 41IMPLEMENT_CLASS(wxExtHelpController, wxHTMLHelpControllerBase)
e9aad10a
KB
42
43/**
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.
47*/
48
49wxExtHelpController::wxExtHelpController(void)
50{
e9aad10a
KB
51 m_BrowserName = WXEXTHELP_DEFAULTBROWSER;
52 m_BrowserIsNetscape = WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE;
53
54 char *browser = getenv(WXEXTHELP_ENVVAR_BROWSER);
55 if(browser)
56 {
57 m_BrowserName = browser;
58 browser = getenv(WXEXTHELP_ENVVAR_BROWSERISNETSCAPE);
59 m_BrowserIsNetscape = browser && (atoi(browser) != 0);
60 }
61}
62
e9aad10a
KB
63
64void
65wxExtHelpController::SetBrowser(wxString const & browsername, bool isNetscape)
66{
67 m_BrowserName = browsername;
68 m_BrowserIsNetscape = isNetscape;
69}
70
33b64e6f
JS
71// Set viewer: new, generic name for SetBrowser
72void wxExtHelpController::SetViewer(const wxString& viewer, long flags)
73{
74 SetBrowser(viewer, ((flags & wxHELP_NETSCAPE) == wxHELP_NETSCAPE));
75}
76
e9aad10a 77bool
afcaf277 78wxExtHelpController::DisplayHelp(wxString const &relativeURL)
e9aad10a
KB
79{
80 wxBusyCursor b; // display a busy cursor
6e5fefdf
KB
81
82
83#ifdef __WXMSW__
f96b60aa
VZ
84 wxString url;
85 url << m_MapFile << '\\' << relativeURL.BeforeFirst('#');
86 bool bOk = (int)ShellExecute(NULL, "open", url,
87 NULL, NULL, SW_SHOWNORMAL ) > 32;
6e5fefdf
KB
88 if ( !bOk )
89 {
90 wxLogSysError(_("Cannot open URL '%s'"), relativeURL.c_str());
91 return false;
92 }
93 else
94 return true;
95#else
96 // assume UNIX
e9aad10a
KB
97 wxString command;
98
99 if(m_BrowserIsNetscape) // try re-loading first
100 {
101 wxString lockfile;
102 wxGetHomeDir(&lockfile);
87138c52 103 lockfile << WXEXTHELP_SEPARATOR << _T(".netscape/lock");
e9aad10a 104 struct stat statbuf;
87138c52 105 if(lstat(lockfile.fn_str(), &statbuf) == 0)
e9aad10a
KB
106 // cannot use wxFileExists, because it's a link pointing to a
107 // non-existing location if(wxFileExists(lockfile))
108 {
109 long success;
87138c52
OK
110 command << m_BrowserName << _T(" -remote openURL(")
111 << _T("file://") << m_MapFile
112 << WXEXTHELP_SEPARATOR << relativeURL << _T(")");
e9aad10a
KB
113 success = wxExecute(command);
114 if(success != 0 ) // returns PID on success
5dcf05ae 115 return TRUE;
e9aad10a
KB
116 }
117 }
118 command = m_BrowserName;
87138c52 119 command << _T(" file://")
e9aad10a
KB
120 << m_MapFile << WXEXTHELP_SEPARATOR << relativeURL;
121 return wxExecute(command) != 0;
6e5fefdf 122#endif
e9aad10a
KB
123}
124
e9aad10a 125