]> git.saurik.com Git - wxWidgets.git/blob - src/generic/helpext.cpp
splitter doesn't change position when the window containing it is minimized and restored
[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 IMPLEMENT_CLASS(wxExtHelpController, wxHTMLHelpControllerBase)
24
25 /**
26 This class implements help via an external browser.
27 It requires the name of a directory containing the documentation
28 and a file mapping numerical Section numbers to relative URLS.
29 */
30
31 wxExtHelpController::wxExtHelpController(void)
32 {
33 m_BrowserName = WXEXTHELP_DEFAULTBROWSER;
34 m_BrowserIsNetscape = WXEXTHELP_DEFAULTBROWSER_IS_NETSCAPE;
35
36 char *browser = getenv(WXEXTHELP_ENVVAR_BROWSER);
37 if(browser)
38 {
39 m_BrowserName = browser;
40 browser = getenv(WXEXTHELP_ENVVAR_BROWSERISNETSCAPE);
41 m_BrowserIsNetscape = browser && (atoi(browser) != 0);
42 }
43 }
44
45
46 void
47 wxExtHelpController::SetBrowser(wxString const & browsername, bool isNetscape)
48 {
49 m_BrowserName = browsername;
50 m_BrowserIsNetscape = isNetscape;
51 }
52
53 // Set viewer: new, generic name for SetBrowser
54 void wxExtHelpController::SetViewer(const wxString& viewer, long flags)
55 {
56 SetBrowser(viewer, ((flags & wxHELP_NETSCAPE) == wxHELP_NETSCAPE));
57 }
58
59 bool
60 wxExtHelpController::DisplayHelp(wxString const &relativeURL)
61 {
62 wxBusyCursor b; // display a busy cursor
63
64
65 #ifdef __WXMSW__
66 bool bOk = (int)ShellExecute(NULL, "open", relativeURL.c_str(),
67 NULL, NULL, SW_SHOWNORMAL ) > 32;
68 if ( !bOk )
69 {
70 wxLogSysError(_("Cannot open URL '%s'"), relativeURL.c_str());
71 return false;
72 }
73 else
74 return true;
75 #else
76 // assume UNIX
77 wxString command;
78
79 if(m_BrowserIsNetscape) // try re-loading first
80 {
81 wxString lockfile;
82 wxGetHomeDir(&lockfile);
83 lockfile << WXEXTHELP_SEPARATOR << _T(".netscape/lock");
84 struct stat statbuf;
85 if(lstat(lockfile.fn_str(), &statbuf) == 0)
86 // cannot use wxFileExists, because it's a link pointing to a
87 // non-existing location if(wxFileExists(lockfile))
88 {
89 long success;
90 command << m_BrowserName << _T(" -remote openURL(")
91 << _T("file://") << m_MapFile
92 << WXEXTHELP_SEPARATOR << relativeURL << _T(")");
93 success = wxExecute(command);
94 if(success != 0 ) // returns PID on success
95 return TRUE;
96 }
97 }
98 command = m_BrowserName;
99 command << _T(" file://")
100 << m_MapFile << WXEXTHELP_SEPARATOR << relativeURL;
101 return wxExecute(command) != 0;
102 #endif
103 }
104
105