]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/generic/helpext.cpp
wxGTK now chooses the best visual X offers,
[wxWidgets.git] / src / generic / helpext.cpp
... / ...
CommitLineData
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
12#ifdef __GNUG__
13# pragma implementation "wxexthlp.h"
14#endif
15
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
40
41IMPLEMENT_CLASS(wxExtHelpController, wxHTMLHelpControllerBase)
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{
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
63
64void
65wxExtHelpController::SetBrowser(wxString const & browsername, bool isNetscape)
66{
67 m_BrowserName = browsername;
68 m_BrowserIsNetscape = isNetscape;
69}
70
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
77bool
78wxExtHelpController::DisplayHelp(wxString const &relativeURL)
79{
80 wxBusyCursor b; // display a busy cursor
81
82
83#ifdef __WXMSW__
84 wxString url;
85 url << m_MapFile << '\\' << relativeURL.BeforeFirst('#');
86 bool bOk = (int)ShellExecute(NULL, "open", url,
87 NULL, NULL, SW_SHOWNORMAL ) > 32;
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
97 wxString command;
98
99 if(m_BrowserIsNetscape) // try re-loading first
100 {
101 wxString lockfile;
102 wxGetHomeDir(&lockfile);
103 lockfile << WXEXTHELP_SEPARATOR << _T(".netscape/lock");
104 struct stat statbuf;
105 if(lstat(lockfile.fn_str(), &statbuf) == 0)
106 // cannot use wxFileExists, because it's a link pointing to a
107 // non-existing location if(wxFileExists(lockfile))
108 {
109 long success;
110 command << m_BrowserName << _T(" -remote openURL(")
111 << _T("file://") << m_MapFile
112 << WXEXTHELP_SEPARATOR << relativeURL << _T(")");
113 success = wxExecute(command);
114 if(success != 0 ) // returns PID on success
115 return TRUE;
116 }
117 }
118 command = m_BrowserName;
119 command << _T(" file://")
120 << m_MapFile << WXEXTHELP_SEPARATOR << relativeURL;
121 return wxExecute(command) != 0;
122#endif
123}
124
125