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