]> git.saurik.com Git - wxWidgets.git/blame - src/html/helpctrl.cpp
WinCE build fixes.
[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
8ec2b484
HH
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
3379ed37 19#if wxUSE_WXHTML_HELP
8ec2b484 20
07b8d7ec
VZ
21#ifndef WX_PRECOMP
22 #include "wx/app.h"
23 #include "wx/intl.h"
24#endif // WX_PRECOMP
25
8ec2b484 26#include "wx/html/helpctrl.h"
8ec2b484
HH
27#include "wx/busyinfo.h"
28
c010d6a9
VZ
29#ifdef __WXGTK__
30 // for the hack in AddGrabIfNeeded()
31 #include "wx/dialog.h"
32#endif // __WXGTK__
33
673dfcfa 34#if wxUSE_HELP
c010d6a9 35 #include "wx/tipwin.h"
673dfcfa 36#endif
d1da8872 37
3527f29c
VS
38
39#if wxUSE_LIBMSPACK
40#include "wx/html/forcelnk.h"
41FORCE_LINK(wxhtml_chm_support)
42#endif
673dfcfa 43
b4414c1f 44IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase)
f42b1601 45
d5bb85a0 46wxHtmlHelpController::wxHtmlHelpController(int style)
8ec2b484
HH
47{
48 m_helpFrame = NULL;
49 m_Config = NULL;
50 m_ConfigRoot = wxEmptyString;
51 m_titleFormat = _("Help: %s");
d5bb85a0 52 m_FrameStyle = style;
8ec2b484
HH
53}
54
55wxHtmlHelpController::~wxHtmlHelpController()
56{
f6bcfd97
BP
57 if (m_Config)
58 WriteCustomization(m_Config, m_ConfigRoot);
8ec2b484 59 if (m_helpFrame)
b854b7b8 60 DestroyHelpWindow();
8ec2b484
HH
61}
62
b854b7b8
VS
63
64void wxHtmlHelpController::DestroyHelpWindow()
65{
66 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
67 if (m_helpFrame)
68 m_helpFrame->Destroy();
69}
70
b4414c1f 71void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
b854b7b8 72{
b4414c1f 73 evt.Skip();
b854b7b8 74
b4414c1f 75 OnQuit();
b854b7b8 76
b4414c1f
JS
77 m_helpFrame->SetController((wxHelpControllerBase*) NULL);
78 m_helpFrame = NULL;
79}
b854b7b8 80
8ec2b484
HH
81void wxHtmlHelpController::SetTitleFormat(const wxString& title)
82{
83 m_titleFormat = title;
84 if (m_helpFrame)
d5bb85a0 85 m_helpFrame->SetTitleFormat(title);
8ec2b484
HH
86}
87
d5bb85a0 88
fcf77487
VS
89bool wxHtmlHelpController::AddBook(const wxFileName& book_file, bool show_wait_msg)
90{
91 return AddBook(wxFileSystem::FileNameToURL(book_file), show_wait_msg);
92}
93
8ec2b484
HH
94bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
95{
96 wxBusyCursor cur;
97#if wxUSE_BUSYINFO
69941f05 98 wxBusyInfo* busy = NULL;
8ec2b484 99 wxString info;
33ac7e6f 100 if (show_wait_msg)
4f9297b0 101 {
d5bb85a0
VS
102 info.Printf(_("Adding book %s"), book.c_str());
103 busy = new wxBusyInfo(info);
8ec2b484
HH
104 }
105#endif
106 bool retval = m_helpData.AddBook(book);
107#if wxUSE_BUSYINFO
108 if (show_wait_msg)
d5bb85a0 109 delete busy;
132a5928
WS
110#else
111 wxUnusedVar(show_wait_msg);
33ac7e6f 112#endif
d1da8872 113 if (m_helpFrame)
5ecdcaa7 114 m_helpFrame->RefreshLists();
8ec2b484
HH
115 return retval;
116}
117
b854b7b8
VS
118
119
120wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
121{
122 return new wxHtmlHelpFrame(data);
123}
124
125
052e12db 126void wxHtmlHelpController::CreateHelpWindow()
8ec2b484 127{
4f9297b0
VS
128 if (m_helpFrame)
129 {
d5bb85a0
VS
130 m_helpFrame->Raise();
131 return ;
8ec2b484 132 }
d5bb85a0 133
33ac7e6f 134 if (m_Config == NULL)
74accc50 135 {
d1da8872 136 m_Config = wxConfigBase::Get(false);
74accc50 137 if (m_Config != NULL)
e7d9c398 138 m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
74accc50
VS
139 }
140
b854b7b8 141 m_helpFrame = CreateHelpFrame(&m_helpData);
b4414c1f 142 m_helpFrame->SetController(this);
74accc50 143
8ec2b484 144 if (m_Config)
d5bb85a0 145 m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
74accc50 146
d5bb85a0 147 m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
8ec2b484 148 m_helpFrame->SetTitleFormat(m_titleFormat);
7e521b01 149
d1da8872 150 m_helpFrame->Show(true);
8ec2b484
HH
151}
152
153void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path)
154{
155 /* should not be called by the user; call UseConfig, and the controller
156 * will do the rest */
f6bcfd97 157 if (m_helpFrame && cfg)
d5bb85a0 158 m_helpFrame->ReadCustomization(cfg, path);
8ec2b484
HH
159}
160
161void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
162{
163 /* typically called by the controllers OnCloseFrame handler */
f6bcfd97 164 if (m_helpFrame && cfg)
d5bb85a0 165 m_helpFrame->WriteCustomization(cfg, path);
8ec2b484
HH
166}
167
721ab905
VS
168void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
169{
170 m_Config = config;
171 m_ConfigRoot = rootpath;
4f9297b0 172 if (m_helpFrame) m_helpFrame->UseConfig(config, rootpath);
721ab905
VS
173 ReadCustomization(config, rootpath);
174}
175
b4414c1f
JS
176//// Backward compatibility with wxHelpController API
177
178bool wxHtmlHelpController::Initialize(const wxString& file)
179{
180 wxString dir, filename, ext;
181 wxSplitPath(file, & dir, & filename, & ext);
182
ddc80eb4 183 if (!dir.empty())
0222a60b 184 dir = dir + wxFILE_SEP_PATH;
b4414c1f
JS
185
186 // Try to find a suitable file
e81910e0 187 wxString actualFilename = dir + filename + wxString(wxT(".zip"));
b4414c1f
JS
188 if (!wxFileExists(actualFilename))
189 {
e81910e0 190 actualFilename = dir + filename + wxString(wxT(".htb"));
b4414c1f
JS
191 if (!wxFileExists(actualFilename))
192 {
e81910e0 193 actualFilename = dir + filename + wxString(wxT(".hhp"));
b4414c1f 194 if (!wxFileExists(actualFilename))
3527f29c
VS
195 {
196#if wxUSE_LIBMSPACK
197 actualFilename = dir + filename + wxString(wxT(".chm"));
198 if (!wxFileExists(actualFilename))
199#endif
200 return false;
201 }
b4414c1f
JS
202 }
203 }
fcf77487 204 return AddBook(wxFileName(actualFilename));
b4414c1f
JS
205}
206
207bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
208{
209 // Don't reload the file or we'll have it appear again, presumably.
d1da8872 210 return true;
b4414c1f
JS
211}
212
213bool wxHtmlHelpController::DisplaySection(int sectionNo)
214{
215 return Display(sectionNo);
216}
217
673dfcfa
JS
218bool wxHtmlHelpController::DisplayTextPopup(const wxString& text, const wxPoint& WXUNUSED(pos))
219{
f38bcae5 220#if wxUSE_TIPWINDOW
673dfcfa
JS
221 static wxTipWindow* s_tipWindow = NULL;
222
223 if (s_tipWindow)
224 {
225 // Prevent s_tipWindow being nulled in OnIdle,
226 // thereby removing the chance for the window to be closed by ShowHelp
227 s_tipWindow->SetTipWindowPtr(NULL);
228 s_tipWindow->Close();
229 }
230 s_tipWindow = NULL;
231
232 if ( !text.empty() )
233 {
234 s_tipWindow = new wxTipWindow(wxTheApp->GetTopWindow(), text, 100, & s_tipWindow);
235
d1da8872 236 return true;
673dfcfa 237 }
ddc80eb4
WS
238#else
239 wxUnusedVar(text);
f38bcae5
VZ
240#endif // wxUSE_TIPWINDOW
241
d1da8872 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)
d1da8872 262 (* newFrameEachTime) = false;
b4414c1f
JS
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();
d1da8872 273 return true;
b4414c1f
JS
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__
d1da8872
WS
282 bool needGrab = false;
283
5152b0e5
JS
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())
d1da8872 294 needGrab = true;
5152b0e5
JS
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();
d1da8872 307 return success;
5152b0e5
JS
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