]>
git.saurik.com Git - wxWidgets.git/blob - src/html/helpctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/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 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
25 #include "wx/busyinfo.h"
26 #include "wx/html/helpctrl.h"
27 #include "wx/html/helpwnd.h"
28 #include "wx/html/helpfrm.h"
29 #include "wx/html/helpdlg.h"
32 #include "wx/tipwin.h"
36 #include "wx/html/forcelnk.h"
37 FORCE_LINK(wxhtml_chm_support
)
40 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController
, wxHelpControllerBase
)
42 wxHtmlHelpController::wxHtmlHelpController(int style
, wxWindow
* parentWindow
):
43 wxHelpControllerBase(parentWindow
)
48 wxHtmlHelpController::wxHtmlHelpController(wxWindow
* parentWindow
, int style
):
49 wxHelpControllerBase(parentWindow
)
54 void wxHtmlHelpController::Init(int style
)
61 m_ConfigRoot
= wxEmptyString
;
62 #endif // wxUSE_CONFIG
63 m_titleFormat
= _("Help: %s");
65 m_shouldPreventAppExit
= false;
69 wxHtmlHelpController::~wxHtmlHelpController()
73 WriteCustomization(m_Config
, m_ConfigRoot
);
74 #endif // wxUSE_CONFIG
80 void wxHtmlHelpController::DestroyHelpWindow()
82 if (m_FrameStyle
& wxHF_EMBEDDED
)
85 // Find top-most parent window
87 wxWindow
* parent
= FindTopLevelWindow();
90 wxDialog
* dialog
= wxDynamicCast(parent
, wxDialog
);
91 if (dialog
&& dialog
->IsModal())
93 dialog
->EndModal(wxID_OK
);
102 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent
& evt
)
106 WriteCustomization(m_Config
, m_ConfigRoot
);
107 #endif // wxUSE_CONFIG
114 m_helpWindow
->SetController(NULL
);
120 void wxHtmlHelpController::SetShouldPreventAppExit(bool enable
)
122 m_shouldPreventAppExit
= enable
;
124 m_helpFrame
->SetShouldPreventAppExit(enable
);
127 void wxHtmlHelpController::SetTitleFormat(const wxString
& title
)
129 m_titleFormat
= title
;
130 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
131 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
134 frame
->SetTitleFormat(title
);
137 dialog
->SetTitleFormat(title
);
140 // Find the top-most parent window
141 wxWindow
* wxHtmlHelpController::FindTopLevelWindow()
143 return wxGetTopLevelParent(m_helpWindow
);
146 bool wxHtmlHelpController::AddBook(const wxFileName
& book_file
, bool show_wait_msg
)
148 return AddBook(wxFileSystem::FileNameToURL(book_file
), show_wait_msg
);
151 bool wxHtmlHelpController::AddBook(const wxString
& book
, bool show_wait_msg
)
155 wxBusyInfo
* busy
= NULL
;
159 info
.Printf(_("Adding book %s"), book
.c_str());
160 busy
= new wxBusyInfo(info
);
163 bool retval
= m_helpData
.AddBook(book
);
168 wxUnusedVar(show_wait_msg
);
171 m_helpWindow
->RefreshLists();
175 wxHtmlHelpFrame
* wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
177 wxHtmlHelpFrame
* frame
= new wxHtmlHelpFrame(data
);
178 frame
->SetController(this);
179 frame
->Create(m_parentWindow
, -1, wxEmptyString
, m_FrameStyle
181 , m_Config
, m_ConfigRoot
182 #endif // wxUSE_CONFIG
184 frame
->SetTitleFormat(m_titleFormat
);
185 frame
->SetShouldPreventAppExit(m_shouldPreventAppExit
);
190 wxHtmlHelpDialog
* wxHtmlHelpController::CreateHelpDialog(wxHtmlHelpData
*data
)
192 wxHtmlHelpDialog
* dialog
= new wxHtmlHelpDialog(data
);
193 dialog
->SetController(this);
194 dialog
->SetTitleFormat(m_titleFormat
);
195 dialog
->Create(m_parentWindow
, -1, wxEmptyString
, m_FrameStyle
);
196 m_helpDialog
= dialog
;
200 wxWindow
* wxHtmlHelpController::CreateHelpWindow()
204 if (m_FrameStyle
& wxHF_EMBEDDED
)
207 wxWindow
* topLevelWindow
= FindTopLevelWindow();
209 topLevelWindow
->Raise();
214 if (m_Config
== NULL
)
216 m_Config
= wxConfigBase::Get(false);
217 if (m_Config
!= NULL
)
218 m_ConfigRoot
= wxT("wxWindows/wxHtmlHelpController");
220 #endif // wxUSE_CONFIG
222 if (m_FrameStyle
& wxHF_DIALOG
)
224 wxHtmlHelpDialog
* dialog
= CreateHelpDialog(&m_helpData
);
225 m_helpWindow
= dialog
->GetHelpWindow();
227 else if ((m_FrameStyle
& wxHF_EMBEDDED
) && m_parentWindow
)
229 m_helpWindow
= new wxHtmlHelpWindow(m_parentWindow
, -1, wxDefaultPosition
, wxDefaultSize
,
230 wxTAB_TRAVERSAL
|wxNO_BORDER
, m_FrameStyle
, &m_helpData
);
234 wxHtmlHelpFrame
* frame
= CreateHelpFrame(&m_helpData
);
235 m_helpWindow
= frame
->GetHelpWindow();
243 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
245 /* should not be called by the user; call UseConfig, and the controller
246 * will do the rest */
247 if (m_helpWindow
&& cfg
)
248 m_helpWindow
->ReadCustomization(cfg
, path
);
251 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
253 /* typically called by the controllers OnCloseFrame handler */
254 if (m_helpWindow
&& cfg
)
255 m_helpWindow
->WriteCustomization(cfg
, path
);
258 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
261 m_ConfigRoot
= rootpath
;
262 if (m_helpWindow
) m_helpWindow
->UseConfig(config
, rootpath
);
263 ReadCustomization(config
, rootpath
);
265 #endif // wxUSE_CONFIG
267 //// Backward compatibility with wxHelpController API
269 bool wxHtmlHelpController::Initialize(const wxString
& file
)
271 wxString dir
, filename
, ext
;
272 wxFileName::SplitPath(file
, & dir
, & filename
, & ext
);
275 dir
= dir
+ wxFILE_SEP_PATH
;
277 // Try to find a suitable file
278 wxString actualFilename
= dir
+ filename
+ wxString(wxT(".zip"));
279 if (!wxFileExists(actualFilename
))
281 actualFilename
= dir
+ filename
+ wxString(wxT(".htb"));
282 if (!wxFileExists(actualFilename
))
284 actualFilename
= dir
+ filename
+ wxString(wxT(".hhp"));
285 if (!wxFileExists(actualFilename
))
288 actualFilename
= dir
+ filename
+ wxString(wxT(".chm"));
289 if (!wxFileExists(actualFilename
))
295 return AddBook(wxFileName(actualFilename
));
298 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
300 // Don't reload the file or we'll have it appear again, presumably.
304 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
306 return Display(sectionNo
);
309 bool wxHtmlHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& WXUNUSED(pos
))
312 static wxTipWindow
* s_tipWindow
= NULL
;
316 // Prevent s_tipWindow being nulled in OnIdle,
317 // thereby removing the chance for the window to be closed by ShowHelp
318 s_tipWindow
->SetTipWindowPtr(NULL
);
319 s_tipWindow
->Close();
325 s_tipWindow
= new wxTipWindow(wxTheApp
->GetTopWindow(), text
, 100, & s_tipWindow
);
331 #endif // wxUSE_TIPWINDOW
336 void wxHtmlHelpController::SetHelpWindow(wxHtmlHelpWindow
* helpWindow
)
338 m_helpWindow
= helpWindow
;
340 helpWindow
->SetController(this);
343 void wxHtmlHelpController::SetFrameParameters(const wxString
& titleFormat
,
346 bool WXUNUSED(newFrameEachTime
))
348 SetTitleFormat(titleFormat
);
349 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
350 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
352 frame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
354 dialog
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
357 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize
*size
,
359 bool *newFrameEachTime
)
361 if (newFrameEachTime
)
362 (* newFrameEachTime
) = false;
364 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
365 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
369 (* size
) = frame
->GetSize();
371 (* pos
) = frame
->GetPosition();
377 (* size
) = dialog
->GetSize();
379 (* pos
) = dialog
->GetPosition();
385 bool wxHtmlHelpController::Quit()
391 // Make the help controller's frame 'modal' if
393 void wxHtmlHelpController::MakeModalIfNeeded()
395 if ((m_FrameStyle
& wxHF_EMBEDDED
) == 0)
397 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
398 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
400 frame
->AddGrabIfNeeded();
401 else if (dialog
&& (m_FrameStyle
& wxHF_MODAL
))
408 bool wxHtmlHelpController::Display(const wxString
& x
)
411 bool success
= m_helpWindow
->Display(x
);
416 bool wxHtmlHelpController::Display(int id
)
419 bool success
= m_helpWindow
->Display(id
);
424 bool wxHtmlHelpController::DisplayContents()
427 bool success
= m_helpWindow
->DisplayContents();
432 bool wxHtmlHelpController::DisplayIndex()
435 bool success
= m_helpWindow
->DisplayIndex();
440 bool wxHtmlHelpController::KeywordSearch(const wxString
& keyword
,
441 wxHelpSearchMode mode
)
444 bool success
= m_helpWindow
->KeywordSearch(keyword
, mode
);
451 * A convenience class, to use like this:
453 * wxHtmlModalHelp help(parent, helpFile, topic);
456 wxHtmlModalHelp::wxHtmlModalHelp(wxWindow
* parent
, const wxString
& helpFile
, const wxString
& topic
, int style
)
458 // Force some mandatory styles
459 style
|= wxHF_DIALOG
| wxHF_MODAL
;
461 wxHtmlHelpController
controller(style
, parent
);
462 controller
.Initialize(helpFile
);
465 controller
.DisplayContents();
467 controller
.DisplaySection(topic
);
470 #endif // wxUSE_WXHTML_HELP