]> git.saurik.com Git - wxWidgets.git/blob - src/generic/helpext.cpp
1. NOT_FOUND -> wxNOT_FOUND
[wxWidgets.git] / src / generic / helpext.cpp
1 /*-*- c++ -*-********************************************************
2 * helpext.cpp - an external help controller for wxWindows *
3 * *
4 * (C) 1999 by Karsten Ballüder (Ballueder@usa.net) *
5 * *
6 * $Id$
7 *******************************************************************/
8 #ifdef __GNUG__
9 # pragma implementation "wxexthlp.h"
10 #endif
11
12 #include "wx/setup.h"
13 #include "wx/helpbase.h"
14 #include "wx/generic/helpext.h"
15 #include "wx/string.h"
16 #include "wx/utils.h"
17 #include "wx/list.h"
18 #include <stdio.h>
19 #include <ctype.h>
20 #include <sys/stat.h>
21 #include <unistd.h>
22
23
24 struct wxBusyCursor
25 {
26 wxBusyCursor() { wxBeginBusyCursor(); }
27 ~wxBusyCursor() { wxEndBusyCursor(); }
28 };
29
30 IMPLEMENT_CLASS(wxExtHelpController, wxHTMLHelpControllerBase)
31
32 /**
33 This class implements help via an external browser.
34 It requires the name of a directory containing the documentation
35 and a file mapping numerical Section numbers to relative URLS.
36 */
37
38 wxExtHelpController::wxExtHelpController(void)
39 {
40 m_BrowserName = WXEXTHELP_DEFAULTBROWSER;
41 m_BrowserIsNetscape = WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE;
42
43 char *browser = getenv(WXEXTHELP_ENVVAR_BROWSER);
44 if(browser)
45 {
46 m_BrowserName = browser;
47 browser = getenv(WXEXTHELP_ENVVAR_BROWSERISNETSCAPE);
48 m_BrowserIsNetscape = browser && (atoi(browser) != 0);
49 }
50 }
51
52
53 void
54 wxExtHelpController::SetBrowser(wxString const & browsername, bool isNetscape)
55 {
56 m_BrowserName = browsername;
57 m_BrowserIsNetscape = isNetscape;
58 }
59
60 bool
61 wxExtHelpController::DisplayHelp(wxString const &relativeURL)
62 {
63 wxBusyCursor b; // display a busy cursor
64 wxString command;
65
66 if(m_BrowserIsNetscape) // try re-loading first
67 {
68 wxString lockfile;
69 wxGetHomeDir(&lockfile);
70 lockfile << WXEXTHELP_SEPARATOR << ".netscape/lock";
71 struct stat statbuf;
72 if(lstat(lockfile.c_str(), &statbuf) == 0)
73 // cannot use wxFileExists, because it's a link pointing to a
74 // non-existing location if(wxFileExists(lockfile))
75 {
76 long success;
77 command << m_BrowserName << " -remote openURL("
78 << "file://" << m_MapFile
79 << WXEXTHELP_SEPARATOR << relativeURL << ")";
80 success = wxExecute(command);
81 if(success != 0 ) // returns PID on success
82 return TRUE;
83 }
84 }
85 command = m_BrowserName;
86 command << " file://"
87 << m_MapFile << WXEXTHELP_SEPARATOR << relativeURL;
88 return wxExecute(command) != 0;
89 }
90
91