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