]> git.saurik.com Git - wxWidgets.git/blob - src/html/helpctrl.cpp
removed #errors in 2.7 compilation
[wxWidgets.git] / src / html / helpctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: helpctrl.cpp
3 // Purpose: wxHtmlHelpController
4 // Notes: Based on htmlhelp.cpp, implementing a monolithic
5 // HTML Help controller class, by Vaclav Slavik
6 // Author: Harm van der Heijden and Vaclav Slavik
7 // RCS-ID: $Id$
8 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_WXHTML_HELP
20
21 #ifndef WX_PRECOMP
22 #include "wx/app.h"
23 #include "wx/intl.h"
24 #endif // WX_PRECOMP
25
26 #include "wx/html/helpctrl.h"
27 #include "wx/busyinfo.h"
28
29 #ifdef __WXGTK__
30 // for the hack in AddGrabIfNeeded()
31 #include "wx/dialog.h"
32 #endif // __WXGTK__
33
34 #if wxUSE_HELP
35 #include "wx/tipwin.h"
36 #endif
37
38
39 #if wxUSE_LIBMSPACK
40 #include "wx/html/forcelnk.h"
41 FORCE_LINK(wxhtml_chm_support)
42 #endif
43
44 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase)
45
46 wxHtmlHelpController::wxHtmlHelpController(int style)
47 {
48 m_helpFrame = NULL;
49 m_Config = NULL;
50 m_ConfigRoot = wxEmptyString;
51 m_titleFormat = _("Help: %s");
52 m_FrameStyle = style;
53 }
54
55 wxHtmlHelpController::~wxHtmlHelpController()
56 {
57 if (m_Config)
58 WriteCustomization(m_Config, m_ConfigRoot);
59 if (m_helpFrame)
60 DestroyHelpWindow();
61 }
62
63
64 void wxHtmlHelpController::DestroyHelpWindow()
65 {
66 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
67 if (m_helpFrame)
68 m_helpFrame->Destroy();
69 }
70
71 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
72 {
73 evt.Skip();
74
75 OnQuit();
76
77 m_helpFrame->SetController((wxHelpControllerBase*) NULL);
78 m_helpFrame = NULL;
79 }
80
81 void wxHtmlHelpController::SetTitleFormat(const wxString& title)
82 {
83 m_titleFormat = title;
84 if (m_helpFrame)
85 m_helpFrame->SetTitleFormat(title);
86 }
87
88
89 bool wxHtmlHelpController::AddBook(const wxFileName& book_file, bool show_wait_msg)
90 {
91 return AddBook(wxFileSystem::FileNameToURL(book_file), show_wait_msg);
92 }
93
94 bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
95 {
96 wxBusyCursor cur;
97 #if wxUSE_BUSYINFO
98 wxBusyInfo* busy = NULL;
99 wxString info;
100 if (show_wait_msg)
101 {
102 info.Printf(_("Adding book %s"), book.c_str());
103 busy = new wxBusyInfo(info);
104 }
105 #endif
106 bool retval = m_helpData.AddBook(book);
107 #if wxUSE_BUSYINFO
108 if (show_wait_msg)
109 delete busy;
110 #else
111 wxUnusedVar(show_wait_msg);
112 #endif
113 if (m_helpFrame)
114 m_helpFrame->RefreshLists();
115 return retval;
116 }
117
118
119
120 wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
121 {
122 return new wxHtmlHelpFrame(data);
123 }
124
125
126 void wxHtmlHelpController::CreateHelpWindow()
127 {
128 if (m_helpFrame)
129 {
130 m_helpFrame->Raise();
131 return ;
132 }
133
134 if (m_Config == NULL)
135 {
136 m_Config = wxConfigBase::Get(false);
137 if (m_Config != NULL)
138 m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
139 }
140
141 m_helpFrame = CreateHelpFrame(&m_helpData);
142 m_helpFrame->SetController(this);
143
144 if (m_Config)
145 m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
146
147 m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
148 m_helpFrame->SetTitleFormat(m_titleFormat);
149
150 m_helpFrame->Show(true);
151 }
152
153 void 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 */
157 if (m_helpFrame && cfg)
158 m_helpFrame->ReadCustomization(cfg, path);
159 }
160
161 void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
162 {
163 /* typically called by the controllers OnCloseFrame handler */
164 if (m_helpFrame && cfg)
165 m_helpFrame->WriteCustomization(cfg, path);
166 }
167
168 void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
169 {
170 m_Config = config;
171 m_ConfigRoot = rootpath;
172 if (m_helpFrame) m_helpFrame->UseConfig(config, rootpath);
173 ReadCustomization(config, rootpath);
174 }
175
176 //// Backward compatibility with wxHelpController API
177
178 bool wxHtmlHelpController::Initialize(const wxString& file)
179 {
180 wxString dir, filename, ext;
181 wxSplitPath(file, & dir, & filename, & ext);
182
183 if (!dir.empty())
184 dir = dir + wxFILE_SEP_PATH;
185
186 // Try to find a suitable file
187 wxString actualFilename = dir + filename + wxString(wxT(".zip"));
188 if (!wxFileExists(actualFilename))
189 {
190 actualFilename = dir + filename + wxString(wxT(".htb"));
191 if (!wxFileExists(actualFilename))
192 {
193 actualFilename = dir + filename + wxString(wxT(".hhp"));
194 if (!wxFileExists(actualFilename))
195 {
196 #if wxUSE_LIBMSPACK
197 actualFilename = dir + filename + wxString(wxT(".chm"));
198 if (!wxFileExists(actualFilename))
199 #endif
200 return false;
201 }
202 }
203 }
204 return AddBook(wxFileName(actualFilename));
205 }
206
207 bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
208 {
209 // Don't reload the file or we'll have it appear again, presumably.
210 return true;
211 }
212
213 bool wxHtmlHelpController::DisplaySection(int sectionNo)
214 {
215 return Display(sectionNo);
216 }
217
218 bool wxHtmlHelpController::DisplayTextPopup(const wxString& text, const wxPoint& WXUNUSED(pos))
219 {
220 #if wxUSE_TIPWINDOW
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
236 return true;
237 }
238 #else
239 wxUnusedVar(text);
240 #endif // wxUSE_TIPWINDOW
241
242 return false;
243 }
244
245 void 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
257 wxFrame* 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
270 bool wxHtmlHelpController::Quit()
271 {
272 DestroyHelpWindow();
273 return true;
274 }
275
276 // Make the help controller's frame 'modal' if
277 // needed
278 void 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.
286 for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
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();
299 #endif // __WXGTK__
300 }
301
302 bool wxHtmlHelpController::Display(const wxString& x)
303 {
304 CreateHelpWindow();
305 bool success = m_helpFrame->Display(x);
306 AddGrabIfNeeded();
307 return success;
308 }
309
310 bool wxHtmlHelpController::Display(int id)
311 {
312 CreateHelpWindow();
313 bool success = m_helpFrame->Display(id);
314 AddGrabIfNeeded();
315 return success;
316 }
317
318 bool wxHtmlHelpController::DisplayContents()
319 {
320 CreateHelpWindow();
321 bool success = m_helpFrame->DisplayContents();
322 AddGrabIfNeeded();
323 return success;
324 }
325
326 bool wxHtmlHelpController::DisplayIndex()
327 {
328 CreateHelpWindow();
329 bool success = m_helpFrame->DisplayIndex();
330 AddGrabIfNeeded();
331 return success;
332 }
333
334 bool wxHtmlHelpController::KeywordSearch(const wxString& keyword,
335 wxHelpSearchMode mode)
336 {
337 CreateHelpWindow();
338 bool success = m_helpFrame->KeywordSearch(keyword, mode);
339 AddGrabIfNeeded();
340 return success;
341 }
342
343 #endif // wxUSE_WXHTML_HELP
344