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