]>
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
)
51 m_ConfigRoot
= wxEmptyString
;
52 #endif // wxUSE_CONFIG
53 m_titleFormat
= _("Help: %s");
55 m_shouldPreventAppExit
= false;
58 wxHtmlHelpController::~wxHtmlHelpController()
62 WriteCustomization(m_Config
, m_ConfigRoot
);
63 #endif // wxUSE_CONFIG
69 void wxHtmlHelpController::DestroyHelpWindow()
71 if (m_FrameStyle
& wxHF_EMBEDDED
)
74 // Find top-most parent window
76 wxWindow
* parent
= FindTopLevelWindow();
79 wxDialog
* dialog
= wxDynamicCast(parent
, wxDialog
);
80 if (dialog
&& dialog
->IsModal())
82 dialog
->EndModal(wxID_OK
);
91 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent
& evt
)
95 WriteCustomization(m_Config
, m_ConfigRoot
);
96 #endif // wxUSE_CONFIG
103 m_helpWindow
->SetController(NULL
);
109 void wxHtmlHelpController::SetShouldPreventAppExit(bool enable
)
111 m_shouldPreventAppExit
= enable
;
113 m_helpFrame
->SetShouldPreventAppExit(enable
);
116 void wxHtmlHelpController::SetTitleFormat(const wxString
& title
)
118 m_titleFormat
= title
;
119 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
120 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
123 frame
->SetTitleFormat(title
);
126 dialog
->SetTitleFormat(title
);
129 // Find the top-most parent window
130 wxWindow
* wxHtmlHelpController::FindTopLevelWindow()
132 return wxGetTopLevelParent(m_helpWindow
);
135 bool wxHtmlHelpController::AddBook(const wxFileName
& book_file
, bool show_wait_msg
)
137 return AddBook(wxFileSystem::FileNameToURL(book_file
), show_wait_msg
);
140 bool wxHtmlHelpController::AddBook(const wxString
& book
, bool show_wait_msg
)
144 wxBusyInfo
* busy
= NULL
;
148 info
.Printf(_("Adding book %s"), book
.c_str());
149 busy
= new wxBusyInfo(info
);
152 bool retval
= m_helpData
.AddBook(book
);
157 wxUnusedVar(show_wait_msg
);
160 m_helpWindow
->RefreshLists();
164 wxHtmlHelpFrame
* wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
166 wxHtmlHelpFrame
* frame
= new wxHtmlHelpFrame(data
);
167 frame
->SetController(this);
168 frame
->Create(m_parentWindow
, -1, wxEmptyString
, m_FrameStyle
170 , m_Config
, m_ConfigRoot
171 #endif // wxUSE_CONFIG
173 frame
->SetTitleFormat(m_titleFormat
);
174 frame
->SetShouldPreventAppExit(m_shouldPreventAppExit
);
179 wxHtmlHelpDialog
* wxHtmlHelpController::CreateHelpDialog(wxHtmlHelpData
*data
)
181 wxHtmlHelpDialog
* dialog
= new wxHtmlHelpDialog(data
);
182 dialog
->SetController(this);
183 dialog
->SetTitleFormat(m_titleFormat
);
184 dialog
->Create(m_parentWindow
, -1, wxEmptyString
, m_FrameStyle
);
185 m_helpDialog
= dialog
;
189 wxWindow
* wxHtmlHelpController::CreateHelpWindow()
193 if (m_FrameStyle
& wxHF_EMBEDDED
)
196 wxWindow
* topLevelWindow
= FindTopLevelWindow();
198 topLevelWindow
->Raise();
203 if (m_Config
== NULL
)
205 m_Config
= wxConfigBase::Get(false);
206 if (m_Config
!= NULL
)
207 m_ConfigRoot
= wxT("wxWindows/wxHtmlHelpController");
209 #endif // wxUSE_CONFIG
211 if (m_FrameStyle
& wxHF_DIALOG
)
213 wxHtmlHelpDialog
* dialog
= CreateHelpDialog(&m_helpData
);
214 m_helpWindow
= dialog
->GetHelpWindow();
216 else if ((m_FrameStyle
& wxHF_EMBEDDED
) && m_parentWindow
)
218 m_helpWindow
= new wxHtmlHelpWindow(m_parentWindow
, -1, wxDefaultPosition
, wxDefaultSize
,
219 wxTAB_TRAVERSAL
|wxNO_BORDER
, m_FrameStyle
, &m_helpData
);
223 wxHtmlHelpFrame
* frame
= CreateHelpFrame(&m_helpData
);
224 m_helpWindow
= frame
->GetHelpWindow();
232 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
234 /* should not be called by the user; call UseConfig, and the controller
235 * will do the rest */
236 if (m_helpWindow
&& cfg
)
237 m_helpWindow
->ReadCustomization(cfg
, path
);
240 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
242 /* typically called by the controllers OnCloseFrame handler */
243 if (m_helpWindow
&& cfg
)
244 m_helpWindow
->WriteCustomization(cfg
, path
);
247 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
250 m_ConfigRoot
= rootpath
;
251 if (m_helpWindow
) m_helpWindow
->UseConfig(config
, rootpath
);
252 ReadCustomization(config
, rootpath
);
254 #endif // wxUSE_CONFIG
256 //// Backward compatibility with wxHelpController API
258 bool wxHtmlHelpController::Initialize(const wxString
& file
)
260 wxString dir
, filename
, ext
;
261 wxFileName::SplitPath(file
, & dir
, & filename
, & ext
);
264 dir
= dir
+ wxFILE_SEP_PATH
;
266 // Try to find a suitable file
267 wxString actualFilename
= dir
+ filename
+ wxString(wxT(".zip"));
268 if (!wxFileExists(actualFilename
))
270 actualFilename
= dir
+ filename
+ wxString(wxT(".htb"));
271 if (!wxFileExists(actualFilename
))
273 actualFilename
= dir
+ filename
+ wxString(wxT(".hhp"));
274 if (!wxFileExists(actualFilename
))
277 actualFilename
= dir
+ filename
+ wxString(wxT(".chm"));
278 if (!wxFileExists(actualFilename
))
284 return AddBook(wxFileName(actualFilename
));
287 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
289 // Don't reload the file or we'll have it appear again, presumably.
293 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
295 return Display(sectionNo
);
298 bool wxHtmlHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& WXUNUSED(pos
))
301 static wxTipWindow
* s_tipWindow
= NULL
;
305 // Prevent s_tipWindow being nulled in OnIdle,
306 // thereby removing the chance for the window to be closed by ShowHelp
307 s_tipWindow
->SetTipWindowPtr(NULL
);
308 s_tipWindow
->Close();
314 s_tipWindow
= new wxTipWindow(wxTheApp
->GetTopWindow(), text
, 100, & s_tipWindow
);
320 #endif // wxUSE_TIPWINDOW
325 void wxHtmlHelpController::SetHelpWindow(wxHtmlHelpWindow
* helpWindow
)
327 m_helpWindow
= helpWindow
;
329 helpWindow
->SetController(this);
332 void wxHtmlHelpController::SetFrameParameters(const wxString
& title
,
335 bool WXUNUSED(newFrameEachTime
))
337 SetTitleFormat(title
);
338 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
339 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
341 frame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
343 dialog
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
346 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize
*size
,
348 bool *newFrameEachTime
)
350 if (newFrameEachTime
)
351 (* newFrameEachTime
) = false;
353 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
354 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
358 (* size
) = frame
->GetSize();
360 (* pos
) = frame
->GetPosition();
366 (* size
) = dialog
->GetSize();
368 (* pos
) = dialog
->GetPosition();
374 bool wxHtmlHelpController::Quit()
380 // Make the help controller's frame 'modal' if
382 void wxHtmlHelpController::MakeModalIfNeeded()
384 if ((m_FrameStyle
& wxHF_EMBEDDED
) == 0)
386 wxHtmlHelpFrame
* frame
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame
);
387 wxHtmlHelpDialog
* dialog
= wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog
);
389 frame
->AddGrabIfNeeded();
390 else if (dialog
&& (m_FrameStyle
& wxHF_MODAL
))
397 bool wxHtmlHelpController::Display(const wxString
& x
)
400 bool success
= m_helpWindow
->Display(x
);
405 bool wxHtmlHelpController::Display(int id
)
408 bool success
= m_helpWindow
->Display(id
);
413 bool wxHtmlHelpController::DisplayContents()
416 bool success
= m_helpWindow
->DisplayContents();
421 bool wxHtmlHelpController::DisplayIndex()
424 bool success
= m_helpWindow
->DisplayIndex();
429 bool wxHtmlHelpController::KeywordSearch(const wxString
& keyword
,
430 wxHelpSearchMode mode
)
433 bool success
= m_helpWindow
->KeywordSearch(keyword
, mode
);
440 * A convenience class, to use like this:
442 * wxHtmlModalHelp help(parent, helpFile, topic);
445 wxHtmlModalHelp::wxHtmlModalHelp(wxWindow
* parent
, const wxString
& helpFile
, const wxString
& topic
, int style
)
447 // Force some mandatory styles
448 style
|= wxHF_DIALOG
| wxHF_MODAL
;
450 wxHtmlHelpController
controller(style
, parent
);
451 controller
.Initialize(helpFile
);
454 controller
.DisplayContents();
456 controller
.DisplaySection(topic
);
459 #endif // wxUSE_WXHTML_HELP