]> git.saurik.com Git - wxWidgets.git/blame - src/html/helpctrl.cpp
Corrected wxFileSystemHandler::GetRightLocation for the case
[wxWidgets.git] / src / html / helpctrl.cpp
CommitLineData
8ec2b484
HH
1/////////////////////////////////////////////////////////////////////////////
2// Name: helpctrl.cpp
3// Purpose: wxHtmlHelpController
f42b1601 4// Notes: Based on htmlhelp.cpp, implementing a monolithic
8ec2b484
HH
5// HTML Help controller class, by Vaclav Slavik
6// Author: Harm van der Heijden and Vaclav Slavik
69941f05 7// RCS-ID: $Id$
8ec2b484
HH
8// Copyright: (c) Harm van der Heijden and Vaclav Slavik
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
1aedb1dd 13#pragma implementation "helpctrl.h"
8ec2b484
HH
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
3379ed37 23#if wxUSE_WXHTML_HELP
8ec2b484 24
07b8d7ec
VZ
25#ifndef WX_PRECOMP
26 #include "wx/app.h"
27 #include "wx/intl.h"
28#endif // WX_PRECOMP
29
8ec2b484 30#include "wx/html/helpctrl.h"
8ec2b484
HH
31#include "wx/busyinfo.h"
32
c010d6a9
VZ
33#ifdef __WXGTK__
34 // for the hack in AddGrabIfNeeded()
35 #include "wx/dialog.h"
36#endif // __WXGTK__
37
673dfcfa 38#if wxUSE_HELP
c010d6a9 39 #include "wx/tipwin.h"
673dfcfa 40#endif
3527f29c
VS
41
42
43#if wxUSE_LIBMSPACK
44#include "wx/html/forcelnk.h"
45FORCE_LINK(wxhtml_chm_support)
46#endif
673dfcfa 47
b4414c1f 48IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase)
f42b1601 49
d5bb85a0 50wxHtmlHelpController::wxHtmlHelpController(int style)
8ec2b484
HH
51{
52 m_helpFrame = NULL;
53 m_Config = NULL;
54 m_ConfigRoot = wxEmptyString;
55 m_titleFormat = _("Help: %s");
d5bb85a0 56 m_FrameStyle = style;
8ec2b484
HH
57}
58
59wxHtmlHelpController::~wxHtmlHelpController()
60{
f6bcfd97
BP
61 if (m_Config)
62 WriteCustomization(m_Config, m_ConfigRoot);
8ec2b484 63 if (m_helpFrame)
b854b7b8 64 DestroyHelpWindow();
8ec2b484
HH
65}
66
b854b7b8
VS
67
68void wxHtmlHelpController::DestroyHelpWindow()
69{
70 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
71 if (m_helpFrame)
72 m_helpFrame->Destroy();
73}
74
b4414c1f 75void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
b854b7b8 76{
b4414c1f 77 evt.Skip();
b854b7b8 78
b4414c1f 79 OnQuit();
b854b7b8 80
b4414c1f
JS
81 m_helpFrame->SetController((wxHelpControllerBase*) NULL);
82 m_helpFrame = NULL;
83}
b854b7b8 84
8ec2b484
HH
85void wxHtmlHelpController::SetTitleFormat(const wxString& title)
86{
87 m_titleFormat = title;
88 if (m_helpFrame)
d5bb85a0 89 m_helpFrame->SetTitleFormat(title);
8ec2b484
HH
90}
91
d5bb85a0 92
fcf77487
VS
93bool wxHtmlHelpController::AddBook(const wxFileName& book_file, bool show_wait_msg)
94{
95 return AddBook(wxFileSystem::FileNameToURL(book_file), show_wait_msg);
96}
97
8ec2b484
HH
98bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
99{
100 wxBusyCursor cur;
101#if wxUSE_BUSYINFO
69941f05 102 wxBusyInfo* busy = NULL;
8ec2b484 103 wxString info;
33ac7e6f 104 if (show_wait_msg)
4f9297b0 105 {
d5bb85a0
VS
106 info.Printf(_("Adding book %s"), book.c_str());
107 busy = new wxBusyInfo(info);
8ec2b484
HH
108 }
109#endif
110 bool retval = m_helpData.AddBook(book);
111#if wxUSE_BUSYINFO
112 if (show_wait_msg)
d5bb85a0 113 delete busy;
33ac7e6f 114#endif
fc799548 115 if (m_helpFrame)
5ecdcaa7 116 m_helpFrame->RefreshLists();
8ec2b484
HH
117 return retval;
118}
119
b854b7b8
VS
120
121
122wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
123{
124 return new wxHtmlHelpFrame(data);
125}
126
127
052e12db 128void wxHtmlHelpController::CreateHelpWindow()
8ec2b484 129{
4f9297b0
VS
130 if (m_helpFrame)
131 {
d5bb85a0
VS
132 m_helpFrame->Raise();
133 return ;
8ec2b484 134 }
d5bb85a0 135
33ac7e6f 136 if (m_Config == NULL)
74accc50
VS
137 {
138 m_Config = wxConfigBase::Get(FALSE);
139 if (m_Config != NULL)
140 m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
141 }
142
b854b7b8 143 m_helpFrame = CreateHelpFrame(&m_helpData);
b4414c1f 144 m_helpFrame->SetController(this);
74accc50 145
8ec2b484 146 if (m_Config)
d5bb85a0 147 m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
74accc50 148
d5bb85a0 149 m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
8ec2b484 150 m_helpFrame->SetTitleFormat(m_titleFormat);
7e521b01 151
8ec2b484
HH
152 m_helpFrame->Show(TRUE);
153}
154
155void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path)
156{
157 /* should not be called by the user; call UseConfig, and the controller
158 * will do the rest */
f6bcfd97 159 if (m_helpFrame && cfg)
d5bb85a0 160 m_helpFrame->ReadCustomization(cfg, path);
8ec2b484
HH
161}
162
163void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
164{
165 /* typically called by the controllers OnCloseFrame handler */
f6bcfd97 166 if (m_helpFrame && cfg)
d5bb85a0 167 m_helpFrame->WriteCustomization(cfg, path);
8ec2b484
HH
168}
169
721ab905
VS
170void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
171{
172 m_Config = config;
173 m_ConfigRoot = rootpath;
4f9297b0 174 if (m_helpFrame) m_helpFrame->UseConfig(config, rootpath);
721ab905
VS
175 ReadCustomization(config, rootpath);
176}
177
b4414c1f
JS
178//// Backward compatibility with wxHelpController API
179
180bool wxHtmlHelpController::Initialize(const wxString& file)
181{
182 wxString dir, filename, ext;
183 wxSplitPath(file, & dir, & filename, & ext);
184
185 if (!dir.IsEmpty())
0222a60b 186 dir = dir + wxFILE_SEP_PATH;
b4414c1f
JS
187
188 // Try to find a suitable file
e81910e0 189 wxString actualFilename = dir + filename + wxString(wxT(".zip"));
b4414c1f
JS
190 if (!wxFileExists(actualFilename))
191 {
e81910e0 192 actualFilename = dir + filename + wxString(wxT(".htb"));
b4414c1f
JS
193 if (!wxFileExists(actualFilename))
194 {
e81910e0 195 actualFilename = dir + filename + wxString(wxT(".hhp"));
b4414c1f 196 if (!wxFileExists(actualFilename))
3527f29c
VS
197 {
198#if wxUSE_LIBMSPACK
199 actualFilename = dir + filename + wxString(wxT(".chm"));
200 if (!wxFileExists(actualFilename))
201#endif
202 return false;
203 }
b4414c1f
JS
204 }
205 }
fcf77487 206 return AddBook(wxFileName(actualFilename));
b4414c1f
JS
207}
208
209bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
210{
211 // Don't reload the file or we'll have it appear again, presumably.
212 return TRUE;
213}
214
215bool wxHtmlHelpController::DisplaySection(int sectionNo)
216{
217 return Display(sectionNo);
218}
219
673dfcfa
JS
220bool wxHtmlHelpController::DisplayTextPopup(const wxString& text, const wxPoint& WXUNUSED(pos))
221{
f38bcae5 222#if wxUSE_TIPWINDOW
673dfcfa
JS
223 static wxTipWindow* s_tipWindow = NULL;
224
225 if (s_tipWindow)
226 {
227 // Prevent s_tipWindow being nulled in OnIdle,
228 // thereby removing the chance for the window to be closed by ShowHelp
229 s_tipWindow->SetTipWindowPtr(NULL);
230 s_tipWindow->Close();
231 }
232 s_tipWindow = NULL;
233
234 if ( !text.empty() )
235 {
236 s_tipWindow = new wxTipWindow(wxTheApp->GetTopWindow(), text, 100, & s_tipWindow);
237
238 return TRUE;
239 }
f38bcae5
VZ
240#endif // wxUSE_TIPWINDOW
241
33ac7e6f 242 return FALSE;
673dfcfa
JS
243}
244
b4414c1f
JS
245void wxHtmlHelpController::SetFrameParameters(const wxString& title,
246 const wxSize& size,
247 const wxPoint& pos,
248 bool WXUNUSED(newFrameEachTime))
249{
250 SetTitleFormat(title);
251 if (m_helpFrame)
252 {
253 m_helpFrame->SetSize(pos.x, pos.y, size.x, size.y);
254 }
255}
256
257wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size,
258 wxPoint *pos,
259 bool *newFrameEachTime)
260{
261 if (newFrameEachTime)
262 (* newFrameEachTime) = FALSE;
263 if (size && m_helpFrame)
264 (* size) = m_helpFrame->GetSize();
265 if (pos && m_helpFrame)
266 (* pos) = m_helpFrame->GetPosition();
267 return m_helpFrame;
268}
269
270bool wxHtmlHelpController::Quit()
271{
272 DestroyHelpWindow();
273 return TRUE;
274}
275
5152b0e5
JS
276// Make the help controller's frame 'modal' if
277// needed
278void wxHtmlHelpController::AddGrabIfNeeded()
279{
280 // So far, wxGTK only
281#ifdef __WXGTK__
282 bool needGrab = FALSE;
283
284 // Check if there are any modal windows present,
285 // in which case we need to add a grab.
222ed1d6 286 for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
5152b0e5
JS
287 node;
288 node = node->GetNext() )
289 {
290 wxWindow *win = node->GetData();
291 wxDialog *dialog = wxDynamicCast(win, wxDialog);
292
293 if (dialog && dialog->IsModal())
294 needGrab = TRUE;
295 }
296
297 if (needGrab && m_helpFrame)
298 m_helpFrame->AddGrab();
c010d6a9 299#endif // __WXGTK__
5152b0e5
JS
300}
301
302bool wxHtmlHelpController::Display(const wxString& x)
303{
304 CreateHelpWindow();
305 bool success = m_helpFrame->Display(x);
306 AddGrabIfNeeded();
307 return success;
308}
309
310bool wxHtmlHelpController::Display(int id)
311{
312 CreateHelpWindow();
313 bool success = m_helpFrame->Display(id);
314 AddGrabIfNeeded();
315 return success;
316}
317
318bool wxHtmlHelpController::DisplayContents()
319{
320 CreateHelpWindow();
321 bool success = m_helpFrame->DisplayContents();
322 AddGrabIfNeeded();
323 return success;
324}
325
326bool wxHtmlHelpController::DisplayIndex()
327{
328 CreateHelpWindow();
329 bool success = m_helpFrame->DisplayIndex();
330 AddGrabIfNeeded();
331 return success;
332}
333
69b5cec2
VS
334bool wxHtmlHelpController::KeywordSearch(const wxString& keyword,
335 wxHelpSearchMode mode)
5152b0e5
JS
336{
337 CreateHelpWindow();
69b5cec2 338 bool success = m_helpFrame->KeywordSearch(keyword, mode);
5152b0e5
JS
339 AddGrabIfNeeded();
340 return success;
341}
342
3379ed37
VZ
343#endif // wxUSE_WXHTML_HELP
344