]> git.saurik.com Git - wxWidgets.git/blame - src/html/helpctrl.cpp
adding protected inquiry function whether a child window belongs to the 'client'...
[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 8// Copyright: (c) Harm van der Heijden and Vaclav Slavik
65571936 9// Licence: wxWindows licence
8ec2b484
HH
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
d1da8872 41
3527f29c
VS
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;
132a5928
WS
114#else
115 wxUnusedVar(show_wait_msg);
33ac7e6f 116#endif
d1da8872 117 if (m_helpFrame)
5ecdcaa7 118 m_helpFrame->RefreshLists();
8ec2b484
HH
119 return retval;
120}
121
b854b7b8
VS
122
123
124wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
125{
126 return new wxHtmlHelpFrame(data);
127}
128
129
052e12db 130void wxHtmlHelpController::CreateHelpWindow()
8ec2b484 131{
4f9297b0
VS
132 if (m_helpFrame)
133 {
d5bb85a0
VS
134 m_helpFrame->Raise();
135 return ;
8ec2b484 136 }
d5bb85a0 137
33ac7e6f 138 if (m_Config == NULL)
74accc50 139 {
d1da8872 140 m_Config = wxConfigBase::Get(false);
74accc50 141 if (m_Config != NULL)
e7d9c398 142 m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
74accc50
VS
143 }
144
b854b7b8 145 m_helpFrame = CreateHelpFrame(&m_helpData);
b4414c1f 146 m_helpFrame->SetController(this);
74accc50 147
8ec2b484 148 if (m_Config)
d5bb85a0 149 m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
74accc50 150
d5bb85a0 151 m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
8ec2b484 152 m_helpFrame->SetTitleFormat(m_titleFormat);
7e521b01 153
d1da8872 154 m_helpFrame->Show(true);
8ec2b484
HH
155}
156
157void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path)
158{
159 /* should not be called by the user; call UseConfig, and the controller
160 * will do the rest */
f6bcfd97 161 if (m_helpFrame && cfg)
d5bb85a0 162 m_helpFrame->ReadCustomization(cfg, path);
8ec2b484
HH
163}
164
165void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
166{
167 /* typically called by the controllers OnCloseFrame handler */
f6bcfd97 168 if (m_helpFrame && cfg)
d5bb85a0 169 m_helpFrame->WriteCustomization(cfg, path);
8ec2b484
HH
170}
171
721ab905
VS
172void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
173{
174 m_Config = config;
175 m_ConfigRoot = rootpath;
4f9297b0 176 if (m_helpFrame) m_helpFrame->UseConfig(config, rootpath);
721ab905
VS
177 ReadCustomization(config, rootpath);
178}
179
b4414c1f
JS
180//// Backward compatibility with wxHelpController API
181
182bool wxHtmlHelpController::Initialize(const wxString& file)
183{
184 wxString dir, filename, ext;
185 wxSplitPath(file, & dir, & filename, & ext);
186
ddc80eb4 187 if (!dir.empty())
0222a60b 188 dir = dir + wxFILE_SEP_PATH;
b4414c1f
JS
189
190 // Try to find a suitable file
e81910e0 191 wxString actualFilename = dir + filename + wxString(wxT(".zip"));
b4414c1f
JS
192 if (!wxFileExists(actualFilename))
193 {
e81910e0 194 actualFilename = dir + filename + wxString(wxT(".htb"));
b4414c1f
JS
195 if (!wxFileExists(actualFilename))
196 {
e81910e0 197 actualFilename = dir + filename + wxString(wxT(".hhp"));
b4414c1f 198 if (!wxFileExists(actualFilename))
3527f29c
VS
199 {
200#if wxUSE_LIBMSPACK
201 actualFilename = dir + filename + wxString(wxT(".chm"));
202 if (!wxFileExists(actualFilename))
203#endif
204 return false;
205 }
b4414c1f
JS
206 }
207 }
fcf77487 208 return AddBook(wxFileName(actualFilename));
b4414c1f
JS
209}
210
211bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
212{
213 // Don't reload the file or we'll have it appear again, presumably.
d1da8872 214 return true;
b4414c1f
JS
215}
216
217bool wxHtmlHelpController::DisplaySection(int sectionNo)
218{
219 return Display(sectionNo);
220}
221
673dfcfa
JS
222bool wxHtmlHelpController::DisplayTextPopup(const wxString& text, const wxPoint& WXUNUSED(pos))
223{
f38bcae5 224#if wxUSE_TIPWINDOW
673dfcfa
JS
225 static wxTipWindow* s_tipWindow = NULL;
226
227 if (s_tipWindow)
228 {
229 // Prevent s_tipWindow being nulled in OnIdle,
230 // thereby removing the chance for the window to be closed by ShowHelp
231 s_tipWindow->SetTipWindowPtr(NULL);
232 s_tipWindow->Close();
233 }
234 s_tipWindow = NULL;
235
236 if ( !text.empty() )
237 {
238 s_tipWindow = new wxTipWindow(wxTheApp->GetTopWindow(), text, 100, & s_tipWindow);
239
d1da8872 240 return true;
673dfcfa 241 }
ddc80eb4
WS
242#else
243 wxUnusedVar(text);
f38bcae5
VZ
244#endif // wxUSE_TIPWINDOW
245
d1da8872 246 return false;
673dfcfa
JS
247}
248
b4414c1f
JS
249void wxHtmlHelpController::SetFrameParameters(const wxString& title,
250 const wxSize& size,
251 const wxPoint& pos,
252 bool WXUNUSED(newFrameEachTime))
253{
254 SetTitleFormat(title);
255 if (m_helpFrame)
256 {
257 m_helpFrame->SetSize(pos.x, pos.y, size.x, size.y);
258 }
259}
260
261wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size,
262 wxPoint *pos,
263 bool *newFrameEachTime)
264{
265 if (newFrameEachTime)
d1da8872 266 (* newFrameEachTime) = false;
b4414c1f
JS
267 if (size && m_helpFrame)
268 (* size) = m_helpFrame->GetSize();
269 if (pos && m_helpFrame)
270 (* pos) = m_helpFrame->GetPosition();
271 return m_helpFrame;
272}
273
274bool wxHtmlHelpController::Quit()
275{
276 DestroyHelpWindow();
d1da8872 277 return true;
b4414c1f
JS
278}
279
5152b0e5
JS
280// Make the help controller's frame 'modal' if
281// needed
282void wxHtmlHelpController::AddGrabIfNeeded()
283{
284 // So far, wxGTK only
285#ifdef __WXGTK__
d1da8872
WS
286 bool needGrab = false;
287
5152b0e5
JS
288 // Check if there are any modal windows present,
289 // in which case we need to add a grab.
222ed1d6 290 for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
5152b0e5
JS
291 node;
292 node = node->GetNext() )
293 {
294 wxWindow *win = node->GetData();
295 wxDialog *dialog = wxDynamicCast(win, wxDialog);
296
297 if (dialog && dialog->IsModal())
d1da8872 298 needGrab = true;
5152b0e5
JS
299 }
300
301 if (needGrab && m_helpFrame)
302 m_helpFrame->AddGrab();
c010d6a9 303#endif // __WXGTK__
5152b0e5
JS
304}
305
306bool wxHtmlHelpController::Display(const wxString& x)
307{
308 CreateHelpWindow();
309 bool success = m_helpFrame->Display(x);
310 AddGrabIfNeeded();
d1da8872 311 return success;
5152b0e5
JS
312}
313
314bool wxHtmlHelpController::Display(int id)
315{
316 CreateHelpWindow();
317 bool success = m_helpFrame->Display(id);
318 AddGrabIfNeeded();
319 return success;
320}
321
322bool wxHtmlHelpController::DisplayContents()
323{
324 CreateHelpWindow();
325 bool success = m_helpFrame->DisplayContents();
326 AddGrabIfNeeded();
327 return success;
328}
329
330bool wxHtmlHelpController::DisplayIndex()
331{
332 CreateHelpWindow();
333 bool success = m_helpFrame->DisplayIndex();
334 AddGrabIfNeeded();
335 return success;
336}
337
69b5cec2
VS
338bool wxHtmlHelpController::KeywordSearch(const wxString& keyword,
339 wxHelpSearchMode mode)
5152b0e5
JS
340{
341 CreateHelpWindow();
69b5cec2 342 bool success = m_helpFrame->KeywordSearch(keyword, mode);
5152b0e5
JS
343 AddGrabIfNeeded();
344 return success;
345}
346
3379ed37
VZ
347#endif // wxUSE_WXHTML_HELP
348