]>
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
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
)
49 wxHtmlHelpController::wxHtmlHelpController(wxWindow
* parentWindow
, int style
):
50 wxHelpControllerBase(parentWindow
)
55 void wxHtmlHelpController::Init(int style
)
62 m_ConfigRoot
= wxEmptyString
;
63 #endif // wxUSE_CONFIG
64 m_titleFormat
= _("Help: %s");
66 m_shouldPreventAppExit
= false;
70 wxHtmlHelpController::~wxHtmlHelpController()
74 WriteCustomization(m_Config
, m_ConfigRoot
);
75 #endif // wxUSE_CONFIG
81 void wxHtmlHelpController::DestroyHelpWindow()
83 if (m_FrameStyle
& wxHF_EMBEDDED
)
86 // Find top-most parent window
88 wxWindow
* parent
= FindTopLevelWindow();
91 wxDialog
* dialog
= wxDynamicCast(parent
, wxDialog
);
92 if (dialog
&& dialog
->IsModal())
94 dialog
->EndModal(wxID_OK
);
103 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent
& evt
)
107 WriteCustomization(m_Config
, m_ConfigRoot
);
108 #endif // wxUSE_CONFIG
115 m_helpWindow
->SetController(NULL
);
121 void wxHtmlHelpController::SetShouldPreventAppExit(bool enable
)
123 m_shouldPreventAppExit
= enable
;
125 m_helpFrame
->SetShouldPreventAppExit(enable
);
128 void wxHtmlHelpController::SetTitleFormat(const wxString
& title
)
130 m_titleFormat
= title
;
131 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
132 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
135 frame
->SetTitleFormat(title
);
138 dialog
->SetTitleFormat(title
);
141 // Find the top-most parent window
142 wxWindow
* wxHtmlHelpController::FindTopLevelWindow()
144 return wxGetTopLevelParent(m_helpWindow
);
147 bool wxHtmlHelpController::AddBook(const wxFileName
& book_file
, bool show_wait_msg
)
149 return AddBook(wxFileSystem::FileNameToURL(book_file
), show_wait_msg
);
152 bool wxHtmlHelpController::AddBook(const wxString
& book
, bool show_wait_msg
)
156 wxBusyInfo
* busy
= NULL
;
160 info
.Printf(_("Adding book %s"), book
.c_str());
161 busy
= new wxBusyInfo(info
);
164 bool retval
= m_helpData
.AddBook(book
);
169 wxUnusedVar(show_wait_msg
);
172 m_helpWindow
->RefreshLists();
176 wxHtmlHelpFrame
* wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
178 wxHtmlHelpFrame
* frame
= new wxHtmlHelpFrame(data
);
179 frame
->SetController(this);
180 frame
->Create(m_parentWindow
, -1, wxEmptyString
, m_FrameStyle
182 , m_Config
, m_ConfigRoot
183 #endif // wxUSE_CONFIG
185 frame
->SetTitleFormat(m_titleFormat
);
186 frame
->SetShouldPreventAppExit(m_shouldPreventAppExit
);
191 wxHtmlHelpDialog
* wxHtmlHelpController::CreateHelpDialog(wxHtmlHelpData
*data
)
193 wxHtmlHelpDialog
* dialog
= new wxHtmlHelpDialog(data
);
194 dialog
->SetController(this);
195 dialog
->SetTitleFormat(m_titleFormat
);
196 dialog
->Create(m_parentWindow
, -1, wxEmptyString
, m_FrameStyle
);
197 m_helpDialog
= dialog
;
201 wxWindow
* wxHtmlHelpController::CreateHelpWindow()
205 if (m_FrameStyle
& wxHF_EMBEDDED
)
208 wxWindow
* topLevelWindow
= FindTopLevelWindow();
210 topLevelWindow
->Raise();
215 if (m_Config
== NULL
)
217 m_Config
= wxConfigBase::Get(false);
218 if (m_Config
!= NULL
)
219 m_ConfigRoot
= wxT("wxWindows/wxHtmlHelpController");
221 #endif // wxUSE_CONFIG
223 if (m_FrameStyle
& wxHF_DIALOG
)
225 wxHtmlHelpDialog
* dialog
= CreateHelpDialog(&m_helpData
);
226 m_helpWindow
= dialog
->GetHelpWindow();
228 else if ((m_FrameStyle
& wxHF_EMBEDDED
) && m_parentWindow
)
230 m_helpWindow
= new wxHtmlHelpWindow(m_parentWindow
, -1, wxDefaultPosition
, wxDefaultSize
,
231 wxTAB_TRAVERSAL
|wxNO_BORDER
, m_FrameStyle
, &m_helpData
);
235 wxHtmlHelpFrame
* frame
= CreateHelpFrame(&m_helpData
);
236 m_helpWindow
= frame
->GetHelpWindow();
244 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
246 /* should not be called by the user; call UseConfig, and the controller
247 * will do the rest */
248 if (m_helpWindow
&& cfg
)
249 m_helpWindow
->ReadCustomization(cfg
, path
);
252 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
254 /* typically called by the controllers OnCloseFrame handler */
255 if (m_helpWindow
&& cfg
)
256 m_helpWindow
->WriteCustomization(cfg
, path
);
259 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
262 m_ConfigRoot
= rootpath
;
263 if (m_helpWindow
) m_helpWindow
->UseConfig(config
, rootpath
);
264 ReadCustomization(config
, rootpath
);
266 #endif // wxUSE_CONFIG
268 //// Backward compatibility with wxHelpController API
270 bool wxHtmlHelpController::Initialize(const wxString
& file
)
272 wxString dir
, filename
, ext
;
273 wxFileName::SplitPath(file
, & dir
, & filename
, & ext
);
276 dir
= dir
+ wxFILE_SEP_PATH
;
278 // Try to find a suitable file
279 wxString actualFilename
= dir
+ filename
+ wxString(wxT(".zip"));
280 if (!wxFileExists(actualFilename
))
282 actualFilename
= dir
+ filename
+ wxString(wxT(".htb"));
283 if (!wxFileExists(actualFilename
))
285 actualFilename
= dir
+ filename
+ wxString(wxT(".hhp"));
286 if (!wxFileExists(actualFilename
))
289 actualFilename
= dir
+ filename
+ wxString(wxT(".chm"));
290 if (!wxFileExists(actualFilename
))
296 return AddBook(wxFileName(actualFilename
));
299 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
301 // Don't reload the file or we'll have it appear again, presumably.
305 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
307 return Display(sectionNo
);
310 bool wxHtmlHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& WXUNUSED(pos
))
313 static wxTipWindow
* s_tipWindow
= NULL
;
317 // Prevent s_tipWindow being nulled in OnIdle,
318 // thereby removing the chance for the window to be closed by ShowHelp
319 s_tipWindow
->SetTipWindowPtr(NULL
);
320 s_tipWindow
->Close();
326 s_tipWindow
= new wxTipWindow(wxTheApp
->GetTopWindow(), text
, 100, & s_tipWindow
);
332 #endif // wxUSE_TIPWINDOW
337 void wxHtmlHelpController::SetHelpWindow(wxHtmlHelpWindow
* helpWindow
)
339 m_helpWindow
= helpWindow
;
341 helpWindow
->SetController(this);
344 void wxHtmlHelpController::SetFrameParameters(const wxString
& title
,
347 bool WXUNUSED(newFrameEachTime
))
349 SetTitleFormat(title
);
350 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
351 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
353 frame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
355 dialog
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
358 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize
*size
,
360 bool *newFrameEachTime
)
362 if (newFrameEachTime
)
363 (* newFrameEachTime
) = false;
365 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
366 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
370 (* size
) = frame
->GetSize();
372 (* pos
) = frame
->GetPosition();
378 (* size
) = dialog
->GetSize();
380 (* pos
) = dialog
->GetPosition();
386 bool wxHtmlHelpController::Quit()
392 // Make the help controller's frame 'modal' if
394 void wxHtmlHelpController::MakeModalIfNeeded()
396 if ((m_FrameStyle
& wxHF_EMBEDDED
) == 0)
398 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
399 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
401 frame
->AddGrabIfNeeded();
402 else if (dialog
&& (m_FrameStyle
& wxHF_MODAL
))
409 bool wxHtmlHelpController::Display(const wxString
& x
)
412 bool success
= m_helpWindow
->Display(x
);
417 bool wxHtmlHelpController::Display(int id
)
420 bool success
= m_helpWindow
->Display(id
);
425 bool wxHtmlHelpController::DisplayContents()
428 bool success
= m_helpWindow
->DisplayContents();
433 bool wxHtmlHelpController::DisplayIndex()
436 bool success
= m_helpWindow
->DisplayIndex();
441 bool wxHtmlHelpController::KeywordSearch(const wxString
& keyword
,
442 wxHelpSearchMode mode
)
445 bool success
= m_helpWindow
->KeywordSearch(keyword
, mode
);
452 * A convenience class, to use like this:
454 * wxHtmlModalHelp help(parent, helpFile, topic);
457 wxHtmlModalHelp::wxHtmlModalHelp(wxWindow
* parent
, const wxString
& helpFile
, const wxString
& topic
, int style
)
459 // Force some mandatory styles
460 style
|= wxHF_DIALOG
| wxHF_MODAL
;
462 wxHtmlHelpController
controller(style
, parent
);
463 controller
.Initialize(helpFile
);
466 controller
.DisplayContents();
468 controller
.DisplaySection(topic
);
471 #endif // wxUSE_WXHTML_HELP