]>
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 wxWindow
* parent
= m_helpWindow
;
119 while (parent
&& !parent
->IsTopLevel())
121 parent
= parent
->GetParent();
126 bool wxHtmlHelpController::AddBook(const wxFileName
& book_file
, bool show_wait_msg
)
128 return AddBook(wxFileSystem::FileNameToURL(book_file
), show_wait_msg
);
131 bool wxHtmlHelpController::AddBook(const wxString
& book
, bool show_wait_msg
)
135 wxBusyInfo
* busy
= NULL
;
139 info
.Printf(_("Adding book %s"), book
.c_str());
140 busy
= new wxBusyInfo(info
);
143 bool retval
= m_helpData
.AddBook(book
);
148 wxUnusedVar(show_wait_msg
);
151 m_helpWindow
->RefreshLists();
155 wxHtmlHelpFrame
* wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
157 wxHtmlHelpFrame
* frame
= new wxHtmlHelpFrame(data
);
158 frame
->SetController(this);
159 frame
->Create(m_parentWindow
, -1, wxEmptyString
, m_FrameStyle
, m_Config
, m_ConfigRoot
);
160 frame
->SetTitleFormat(m_titleFormat
);
165 wxHtmlHelpDialog
* wxHtmlHelpController::CreateHelpDialog(wxHtmlHelpData
*data
)
167 wxHtmlHelpDialog
* dialog
= new wxHtmlHelpDialog(data
);
168 dialog
->SetController(this);
169 dialog
->SetTitleFormat(m_titleFormat
);
170 dialog
->Create(m_parentWindow
, -1, wxEmptyString
, m_FrameStyle
);
171 m_helpDialog
= dialog
;
175 wxWindow
* wxHtmlHelpController::CreateHelpWindow()
179 if (m_FrameStyle
& wxHF_EMBEDDED
)
182 wxWindow
* topLevelWindow
= FindTopLevelWindow();
184 topLevelWindow
->Raise();
188 if (m_Config
== NULL
)
190 m_Config
= wxConfigBase::Get(false);
191 if (m_Config
!= NULL
)
192 m_ConfigRoot
= _T("wxWindows/wxHtmlHelpController");
195 if (m_FrameStyle
& wxHF_DIALOG
)
197 wxHtmlHelpDialog
* dialog
= CreateHelpDialog(&m_helpData
);
198 m_helpWindow
= dialog
->GetHelpWindow();
200 else if ((m_FrameStyle
& wxHF_EMBEDDED
) && m_parentWindow
)
202 m_helpWindow
= new wxHtmlHelpWindow(m_parentWindow
, -1, wxDefaultPosition
, wxDefaultSize
,
203 wxTAB_TRAVERSAL
|wxNO_BORDER
, m_FrameStyle
, &m_helpData
);
207 wxHtmlHelpFrame
* frame
= CreateHelpFrame(&m_helpData
);
208 m_helpWindow
= frame
->GetHelpWindow();
215 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
217 /* should not be called by the user; call UseConfig, and the controller
218 * will do the rest */
219 if (m_helpWindow
&& cfg
)
220 m_helpWindow
->ReadCustomization(cfg
, path
);
223 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
225 /* typically called by the controllers OnCloseFrame handler */
226 if (m_helpWindow
&& cfg
)
227 m_helpWindow
->WriteCustomization(cfg
, path
);
230 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
233 m_ConfigRoot
= rootpath
;
234 if (m_helpWindow
) m_helpWindow
->UseConfig(config
, rootpath
);
235 ReadCustomization(config
, rootpath
);
238 //// Backward compatibility with wxHelpController API
240 bool wxHtmlHelpController::Initialize(const wxString
& file
)
242 wxString dir
, filename
, ext
;
243 wxSplitPath(file
, & dir
, & filename
, & ext
);
246 dir
= dir
+ wxFILE_SEP_PATH
;
248 // Try to find a suitable file
249 wxString actualFilename
= dir
+ filename
+ wxString(wxT(".zip"));
250 if (!wxFileExists(actualFilename
))
252 actualFilename
= dir
+ filename
+ wxString(wxT(".htb"));
253 if (!wxFileExists(actualFilename
))
255 actualFilename
= dir
+ filename
+ wxString(wxT(".hhp"));
256 if (!wxFileExists(actualFilename
))
259 actualFilename
= dir
+ filename
+ wxString(wxT(".chm"));
260 if (!wxFileExists(actualFilename
))
266 return AddBook(wxFileName(actualFilename
));
269 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
271 // Don't reload the file or we'll have it appear again, presumably.
275 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
277 return Display(sectionNo
);
280 bool wxHtmlHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& WXUNUSED(pos
))
283 static wxTipWindow
* s_tipWindow
= NULL
;
287 // Prevent s_tipWindow being nulled in OnIdle,
288 // thereby removing the chance for the window to be closed by ShowHelp
289 s_tipWindow
->SetTipWindowPtr(NULL
);
290 s_tipWindow
->Close();
296 s_tipWindow
= new wxTipWindow(wxTheApp
->GetTopWindow(), text
, 100, & s_tipWindow
);
302 #endif // wxUSE_TIPWINDOW
307 void wxHtmlHelpController::SetHelpWindow(wxHtmlHelpWindow
* helpWindow
)
309 m_helpWindow
= helpWindow
;
311 helpWindow
->SetController(this);
314 void wxHtmlHelpController::SetFrameParameters(const wxString
& title
,
317 bool WXUNUSED(newFrameEachTime
))
319 SetTitleFormat(title
);
320 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
321 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
323 frame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
325 dialog
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
328 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize
*size
,
330 bool *newFrameEachTime
)
332 if (newFrameEachTime
)
333 (* newFrameEachTime
) = false;
335 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
336 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
340 (* size
) = frame
->GetSize();
342 (* pos
) = frame
->GetPosition();
348 (* size
) = dialog
->GetSize();
350 (* pos
) = dialog
->GetPosition();
356 bool wxHtmlHelpController::Quit()
362 // Make the help controller's frame 'modal' if
364 void wxHtmlHelpController::MakeModalIfNeeded()
366 if ((m_FrameStyle
& wxHF_EMBEDDED
) == 0)
368 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
369 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
371 frame
->AddGrabIfNeeded();
372 else if (dialog
&& (m_FrameStyle
& wxHF_MODAL
))
379 bool wxHtmlHelpController::Display(const wxString
& x
)
382 bool success
= m_helpWindow
->Display(x
);
387 bool wxHtmlHelpController::Display(int id
)
390 bool success
= m_helpWindow
->Display(id
);
395 bool wxHtmlHelpController::DisplayContents()
398 bool success
= m_helpWindow
->DisplayContents();
403 bool wxHtmlHelpController::DisplayIndex()
406 bool success
= m_helpWindow
->DisplayIndex();
411 bool wxHtmlHelpController::KeywordSearch(const wxString
& keyword
,
412 wxHelpSearchMode mode
)
415 bool success
= m_helpWindow
->KeywordSearch(keyword
, mode
);
422 * A convenience class, to use like this:
424 * wxHtmlModalHelp help(parent, helpFile, topic);
427 wxHtmlModalHelp::wxHtmlModalHelp(wxWindow
* parent
, const wxString
& helpFile
, const wxString
& topic
, int style
)
429 // Force some mandatory styles
430 style
|= wxHF_DIALOG
| wxHF_MODAL
;
432 wxHtmlHelpController
controller(style
, parent
);
433 controller
.Initialize(helpFile
);
436 controller
.DisplayContents();
438 controller
.DisplaySection(topic
);
441 #endif // wxUSE_WXHTML_HELP