]> git.saurik.com Git - wxWidgets.git/blob - src/html/helpctrl.cpp
applied SF patch #846732 file dialog long filename support
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "helpctrl.h"
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
23 #if wxUSE_WXHTML_HELP
24
25 #ifndef WX_PRECOMP
26 #include "wx/app.h"
27 #include "wx/intl.h"
28 #endif // WX_PRECOMP
29
30 #include "wx/html/helpctrl.h"
31 #include "wx/busyinfo.h"
32
33 #ifdef __WXGTK__
34 // for the hack in AddGrabIfNeeded()
35 #include "wx/dialog.h"
36 #endif // __WXGTK__
37
38 #if wxUSE_HELP
39 #include "wx/tipwin.h"
40 #endif
41
42
43 #if wxUSE_LIBMSPACK
44 #include "wx/html/forcelnk.h"
45 FORCE_LINK(wxhtml_chm_support)
46 #endif
47
48 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase)
49
50 wxHtmlHelpController::wxHtmlHelpController(int style)
51 {
52 m_helpFrame = NULL;
53 m_Config = NULL;
54 m_ConfigRoot = wxEmptyString;
55 m_titleFormat = _("Help: %s");
56 m_FrameStyle = style;
57 }
58
59 wxHtmlHelpController::~wxHtmlHelpController()
60 {
61 if (m_Config)
62 WriteCustomization(m_Config, m_ConfigRoot);
63 if (m_helpFrame)
64 DestroyHelpWindow();
65 }
66
67
68 void wxHtmlHelpController::DestroyHelpWindow()
69 {
70 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
71 if (m_helpFrame)
72 m_helpFrame->Destroy();
73 }
74
75 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
76 {
77 evt.Skip();
78
79 OnQuit();
80
81 m_helpFrame->SetController((wxHelpControllerBase*) NULL);
82 m_helpFrame = NULL;
83 }
84
85 void wxHtmlHelpController::SetTitleFormat(const wxString& title)
86 {
87 m_titleFormat = title;
88 if (m_helpFrame)
89 m_helpFrame->SetTitleFormat(title);
90 }
91
92
93 bool wxHtmlHelpController::AddBook(const wxFileName& book_file, bool show_wait_msg)
94 {
95 return AddBook(wxFileSystem::FileNameToURL(book_file), show_wait_msg);
96 }
97
98 bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
99 {
100 wxBusyCursor cur;
101 #if wxUSE_BUSYINFO
102 wxBusyInfo* busy = NULL;
103 wxString info;
104 if (show_wait_msg)
105 {
106 info.Printf(_("Adding book %s"), book.c_str());
107 busy = new wxBusyInfo(info);
108 }
109 #endif
110 bool retval = m_helpData.AddBook(book);
111 #if wxUSE_BUSYINFO
112 if (show_wait_msg)
113 delete busy;
114 #endif
115 if (m_helpFrame)
116 m_helpFrame->RefreshLists();
117 return retval;
118 }
119
120
121
122 wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
123 {
124 return new wxHtmlHelpFrame(data);
125 }
126
127
128 void wxHtmlHelpController::CreateHelpWindow()
129 {
130 if (m_helpFrame)
131 {
132 m_helpFrame->Raise();
133 return ;
134 }
135
136 if (m_Config == NULL)
137 {
138 m_Config = wxConfigBase::Get(FALSE);
139 if (m_Config != NULL)
140 m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
141 }
142
143 m_helpFrame = CreateHelpFrame(&m_helpData);
144 m_helpFrame->SetController(this);
145
146 if (m_Config)
147 m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
148
149 m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
150 m_helpFrame->SetTitleFormat(m_titleFormat);
151 m_helpFrame->Show(TRUE);
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 */
158 if (m_helpFrame && cfg)
159 m_helpFrame->ReadCustomization(cfg, path);
160 }
161
162 void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
163 {
164 /* typically called by the controllers OnCloseFrame handler */
165 if (m_helpFrame && cfg)
166 m_helpFrame->WriteCustomization(cfg, path);
167 }
168
169 void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
170 {
171 m_Config = config;
172 m_ConfigRoot = rootpath;
173 if (m_helpFrame) m_helpFrame->UseConfig(config, rootpath);
174 ReadCustomization(config, rootpath);
175 }
176
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
184 if (!dir.IsEmpty())
185 dir = dir + wxFILE_SEP_PATH;
186
187 // Try to find a suitable file
188 wxString actualFilename = dir + filename + wxString(wxT(".zip"));
189 if (!wxFileExists(actualFilename))
190 {
191 actualFilename = dir + filename + wxString(wxT(".htb"));
192 if (!wxFileExists(actualFilename))
193 {
194 actualFilename = dir + filename + wxString(wxT(".hhp"));
195 if (!wxFileExists(actualFilename))
196 {
197 #if wxUSE_LIBMSPACK
198 actualFilename = dir + filename + wxString(wxT(".chm"));
199 if (!wxFileExists(actualFilename))
200 #endif
201 return false;
202 }
203 }
204 }
205 return AddBook(wxFileName(actualFilename));
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.
211 return TRUE;
212 }
213
214 bool wxHtmlHelpController::DisplaySection(int sectionNo)
215 {
216 return Display(sectionNo);
217 }
218
219 bool wxHtmlHelpController::DisplayTextPopup(const wxString& text, const wxPoint& WXUNUSED(pos))
220 {
221 #if wxUSE_TIPWINDOW
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
237 return TRUE;
238 }
239 #endif // wxUSE_TIPWINDOW
240
241 return FALSE;
242 }
243
244 void wxHtmlHelpController::SetFrameParameters(const wxString& title,
245 const wxSize& size,
246 const wxPoint& pos,
247 bool WXUNUSED(newFrameEachTime))
248 {
249 SetTitleFormat(title);
250 if (m_helpFrame)
251 {
252 m_helpFrame->SetSize(pos.x, pos.y, size.x, size.y);
253 }
254 }
255
256 wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size,
257 wxPoint *pos,
258 bool *newFrameEachTime)
259 {
260 if (newFrameEachTime)
261 (* newFrameEachTime) = FALSE;
262 if (size && m_helpFrame)
263 (* size) = m_helpFrame->GetSize();
264 if (pos && m_helpFrame)
265 (* pos) = m_helpFrame->GetPosition();
266 return m_helpFrame;
267 }
268
269 bool wxHtmlHelpController::Quit()
270 {
271 DestroyHelpWindow();
272 return TRUE;
273 }
274
275 // Make the help controller's frame 'modal' if
276 // needed
277 void wxHtmlHelpController::AddGrabIfNeeded()
278 {
279 // So far, wxGTK only
280 #ifdef __WXGTK__
281 bool needGrab = FALSE;
282
283 // Check if there are any modal windows present,
284 // in which case we need to add a grab.
285 for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
286 node;
287 node = node->GetNext() )
288 {
289 wxWindow *win = node->GetData();
290 wxDialog *dialog = wxDynamicCast(win, wxDialog);
291
292 if (dialog && dialog->IsModal())
293 needGrab = TRUE;
294 }
295
296 if (needGrab && m_helpFrame)
297 m_helpFrame->AddGrab();
298 #endif // __WXGTK__
299 }
300
301 bool wxHtmlHelpController::Display(const wxString& x)
302 {
303 CreateHelpWindow();
304 bool success = m_helpFrame->Display(x);
305 AddGrabIfNeeded();
306 return success;
307 }
308
309 bool wxHtmlHelpController::Display(int id)
310 {
311 CreateHelpWindow();
312 bool success = m_helpFrame->Display(id);
313 AddGrabIfNeeded();
314 return success;
315 }
316
317 bool wxHtmlHelpController::DisplayContents()
318 {
319 CreateHelpWindow();
320 bool success = m_helpFrame->DisplayContents();
321 AddGrabIfNeeded();
322 return success;
323 }
324
325 bool wxHtmlHelpController::DisplayIndex()
326 {
327 CreateHelpWindow();
328 bool success = m_helpFrame->DisplayIndex();
329 AddGrabIfNeeded();
330 return success;
331 }
332
333 bool wxHtmlHelpController::KeywordSearch(const wxString& keyword,
334 wxHelpSearchMode mode)
335 {
336 CreateHelpWindow();
337 bool success = m_helpFrame->KeywordSearch(keyword, mode);
338 AddGrabIfNeeded();
339 return success;
340 }
341
342 #endif // wxUSE_WXHTML_HELP
343