]>
git.saurik.com Git - wxWidgets.git/blob - src/html/helpctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
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
8 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
26 #include "wx/busyinfo.h"
27 #include "wx/html/helpctrl.h"
28 #include "wx/html/helpwnd.h"
29 #include "wx/html/helpfrm.h"
30 #include "wx/html/helpdlg.h"
33 #include "wx/tipwin.h"
37 #include "wx/html/forcelnk.h"
38 FORCE_LINK(wxhtml_chm_support
)
41 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController
, wxHelpControllerBase
)
43 wxHtmlHelpController::wxHtmlHelpController(int style
, wxWindow
* parentWindow
):
44 wxHelpControllerBase(parentWindow
)
50 m_ConfigRoot
= wxEmptyString
;
51 m_titleFormat
= _("Help: %s");
55 wxHtmlHelpController::~wxHtmlHelpController()
58 WriteCustomization(m_Config
, m_ConfigRoot
);
64 void wxHtmlHelpController::DestroyHelpWindow()
66 if (m_FrameStyle
& wxHF_EMBEDDED
)
69 // Find top-most parent window
71 wxWindow
* parent
= FindTopLevelWindow();
74 wxDialog
* dialog
= wxDynamicCast(parent
, wxDialog
);
75 if (dialog
&& dialog
->IsModal())
77 dialog
->EndModal(wxID_OK
);
86 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent
& evt
)
89 WriteCustomization(m_Config
, m_ConfigRoot
);
96 m_helpWindow
->SetController(NULL
);
102 void wxHtmlHelpController::SetTitleFormat(const wxString
& title
)
104 m_titleFormat
= title
;
105 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
106 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
109 frame
->SetTitleFormat(title
);
112 dialog
->SetTitleFormat(title
);
115 // Find the top-most parent window
116 wxWindow
* wxHtmlHelpController::FindTopLevelWindow()
118 return wxGetTopLevelParent(m_helpWindow
);
121 bool wxHtmlHelpController::AddBook(const wxFileName
& book_file
, bool show_wait_msg
)
123 return AddBook(wxFileSystem::FileNameToURL(book_file
), show_wait_msg
);
126 bool wxHtmlHelpController::AddBook(const wxString
& book
, bool show_wait_msg
)
130 wxBusyInfo
* busy
= NULL
;
134 info
.Printf(_("Adding book %s"), book
.c_str());
135 busy
= new wxBusyInfo(info
);
138 bool retval
= m_helpData
.AddBook(book
);
143 wxUnusedVar(show_wait_msg
);
146 m_helpWindow
->RefreshLists();
150 wxHtmlHelpFrame
* wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
152 wxHtmlHelpFrame
* frame
= new wxHtmlHelpFrame(data
);
153 frame
->SetController(this);
154 frame
->Create(m_parentWindow
, -1, wxEmptyString
, m_FrameStyle
, m_Config
, m_ConfigRoot
);
155 frame
->SetTitleFormat(m_titleFormat
);
160 wxHtmlHelpDialog
* wxHtmlHelpController::CreateHelpDialog(wxHtmlHelpData
*data
)
162 wxHtmlHelpDialog
* dialog
= new wxHtmlHelpDialog(data
);
163 dialog
->SetController(this);
164 dialog
->SetTitleFormat(m_titleFormat
);
165 dialog
->Create(m_parentWindow
, -1, wxEmptyString
, m_FrameStyle
);
166 m_helpDialog
= dialog
;
170 wxWindow
* wxHtmlHelpController::CreateHelpWindow()
174 if (m_FrameStyle
& wxHF_EMBEDDED
)
177 wxWindow
* topLevelWindow
= FindTopLevelWindow();
179 topLevelWindow
->Raise();
183 if (m_Config
== NULL
)
185 m_Config
= wxConfigBase::Get(false);
186 if (m_Config
!= NULL
)
187 m_ConfigRoot
= _T("wxWindows/wxHtmlHelpController");
190 if (m_FrameStyle
& wxHF_DIALOG
)
192 wxHtmlHelpDialog
* dialog
= CreateHelpDialog(&m_helpData
);
193 m_helpWindow
= dialog
->GetHelpWindow();
195 else if ((m_FrameStyle
& wxHF_EMBEDDED
) && m_parentWindow
)
197 m_helpWindow
= new wxHtmlHelpWindow(m_parentWindow
, -1, wxDefaultPosition
, wxDefaultSize
,
198 wxTAB_TRAVERSAL
|wxNO_BORDER
, m_FrameStyle
, &m_helpData
);
202 wxHtmlHelpFrame
* frame
= CreateHelpFrame(&m_helpData
);
203 m_helpWindow
= frame
->GetHelpWindow();
210 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
212 /* should not be called by the user; call UseConfig, and the controller
213 * will do the rest */
214 if (m_helpWindow
&& cfg
)
215 m_helpWindow
->ReadCustomization(cfg
, path
);
218 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
220 /* typically called by the controllers OnCloseFrame handler */
221 if (m_helpWindow
&& cfg
)
222 m_helpWindow
->WriteCustomization(cfg
, path
);
225 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
228 m_ConfigRoot
= rootpath
;
229 if (m_helpWindow
) m_helpWindow
->UseConfig(config
, rootpath
);
230 ReadCustomization(config
, rootpath
);
233 //// Backward compatibility with wxHelpController API
235 bool wxHtmlHelpController::Initialize(const wxString
& file
)
237 wxString dir
, filename
, ext
;
238 wxFileName::SplitPath(file
, & dir
, & filename
, & ext
);
241 dir
= dir
+ wxFILE_SEP_PATH
;
243 // Try to find a suitable file
244 wxString actualFilename
= dir
+ filename
+ wxString(wxT(".zip"));
245 if (!wxFileExists(actualFilename
))
247 actualFilename
= dir
+ filename
+ wxString(wxT(".htb"));
248 if (!wxFileExists(actualFilename
))
250 actualFilename
= dir
+ filename
+ wxString(wxT(".hhp"));
251 if (!wxFileExists(actualFilename
))
254 actualFilename
= dir
+ filename
+ wxString(wxT(".chm"));
255 if (!wxFileExists(actualFilename
))
261 return AddBook(wxFileName(actualFilename
));
264 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
266 // Don't reload the file or we'll have it appear again, presumably.
270 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
272 return Display(sectionNo
);
275 bool wxHtmlHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& WXUNUSED(pos
))
278 static wxTipWindow
* s_tipWindow
= NULL
;
282 // Prevent s_tipWindow being nulled in OnIdle,
283 // thereby removing the chance for the window to be closed by ShowHelp
284 s_tipWindow
->SetTipWindowPtr(NULL
);
285 s_tipWindow
->Close();
291 s_tipWindow
= new wxTipWindow(wxTheApp
->GetTopWindow(), text
, 100, & s_tipWindow
);
297 #endif // wxUSE_TIPWINDOW
302 void wxHtmlHelpController::SetHelpWindow(wxHtmlHelpWindow
* helpWindow
)
304 m_helpWindow
= helpWindow
;
306 helpWindow
->SetController(this);
309 void wxHtmlHelpController::SetFrameParameters(const wxString
& title
,
312 bool WXUNUSED(newFrameEachTime
))
314 SetTitleFormat(title
);
315 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
316 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
318 frame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
320 dialog
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
323 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize
*size
,
325 bool *newFrameEachTime
)
327 if (newFrameEachTime
)
328 (* newFrameEachTime
) = false;
330 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
331 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
335 (* size
) = frame
->GetSize();
337 (* pos
) = frame
->GetPosition();
343 (* size
) = dialog
->GetSize();
345 (* pos
) = dialog
->GetPosition();
351 bool wxHtmlHelpController::Quit()
357 // Make the help controller's frame 'modal' if
359 void wxHtmlHelpController::MakeModalIfNeeded()
361 if ((m_FrameStyle
& wxHF_EMBEDDED
) == 0)
363 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
364 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
366 frame
->AddGrabIfNeeded();
367 else if (dialog
&& (m_FrameStyle
& wxHF_MODAL
))
374 bool wxHtmlHelpController::Display(const wxString
& x
)
377 bool success
= m_helpWindow
->Display(x
);
382 bool wxHtmlHelpController::Display(int id
)
385 bool success
= m_helpWindow
->Display(id
);
390 bool wxHtmlHelpController::DisplayContents()
393 bool success
= m_helpWindow
->DisplayContents();
398 bool wxHtmlHelpController::DisplayIndex()
401 bool success
= m_helpWindow
->DisplayIndex();
406 bool wxHtmlHelpController::KeywordSearch(const wxString
& keyword
,
407 wxHelpSearchMode mode
)
410 bool success
= m_helpWindow
->KeywordSearch(keyword
, mode
);
417 * A convenience class, to use like this:
419 * wxHtmlModalHelp help(parent, helpFile, topic);
422 wxHtmlModalHelp::wxHtmlModalHelp(wxWindow
* parent
, const wxString
& helpFile
, const wxString
& topic
, int style
)
424 // Force some mandatory styles
425 style
|= wxHF_DIALOG
| wxHF_MODAL
;
427 wxHtmlHelpController
controller(style
, parent
);
428 controller
.Initialize(helpFile
);
431 controller
.DisplayContents();
433 controller
.DisplaySection(topic
);
436 #endif // wxUSE_WXHTML_HELP