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/html/helpctrl.h"
27 #include "wx/busyinfo.h"
30 // for the hack in AddGrabIfNeeded()
31 #include "wx/dialog.h"
35 #include "wx/tipwin.h"
40 #include "wx/html/forcelnk.h"
41 FORCE_LINK(wxhtml_chm_support
)
44 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController
, wxHelpControllerBase
)
46 wxHtmlHelpController::wxHtmlHelpController(int style
, wxWindow
* parentWindow
):
47 wxHelpControllerBase(parentWindow
)
51 m_ConfigRoot
= wxEmptyString
;
52 m_titleFormat
= _("Help: %s");
56 wxHtmlHelpController::~wxHtmlHelpController()
59 WriteCustomization(m_Config
, m_ConfigRoot
);
65 void wxHtmlHelpController::DestroyHelpWindow()
67 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
69 m_helpFrame
->Destroy();
72 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent
& evt
)
78 m_helpFrame
->SetController((wxHelpControllerBase
*) NULL
);
82 void wxHtmlHelpController::SetTitleFormat(const wxString
& title
)
84 m_titleFormat
= title
;
86 m_helpFrame
->SetTitleFormat(title
);
90 bool wxHtmlHelpController::AddBook(const wxFileName
& book_file
, bool show_wait_msg
)
92 return AddBook(wxFileSystem::FileNameToURL(book_file
), show_wait_msg
);
95 bool wxHtmlHelpController::AddBook(const wxString
& book
, bool show_wait_msg
)
99 wxBusyInfo
* busy
= NULL
;
103 info
.Printf(_("Adding book %s"), book
.c_str());
104 busy
= new wxBusyInfo(info
);
107 bool retval
= m_helpData
.AddBook(book
);
112 wxUnusedVar(show_wait_msg
);
115 m_helpFrame
->RefreshLists();
121 wxHtmlHelpFrame
*wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
123 return new wxHtmlHelpFrame(data
);
127 void wxHtmlHelpController::CreateHelpWindow()
131 m_helpFrame
->Raise();
135 if (m_Config
== NULL
)
137 m_Config
= wxConfigBase::Get(false);
138 if (m_Config
!= NULL
)
139 m_ConfigRoot
= _T("wxWindows/wxHtmlHelpController");
142 m_helpFrame
= CreateHelpFrame(&m_helpData
);
143 m_helpFrame
->SetController(this);
146 m_helpFrame
->UseConfig(m_Config
, m_ConfigRoot
);
148 m_helpFrame
->Create(GetParentWindow(), wxID_HTML_HELPFRAME
, wxEmptyString
, m_FrameStyle
);
149 m_helpFrame
->SetTitleFormat(m_titleFormat
);
151 m_helpFrame
->Show(true);
154 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
156 /* should not be called by the user; call UseConfig, and the controller
157 * will do the rest */
158 if (m_helpFrame
&& cfg
)
159 m_helpFrame
->ReadCustomization(cfg
, path
);
162 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
164 /* typically called by the controllers OnCloseFrame handler */
165 if (m_helpFrame
&& cfg
)
166 m_helpFrame
->WriteCustomization(cfg
, path
);
169 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
172 m_ConfigRoot
= rootpath
;
173 if (m_helpFrame
) m_helpFrame
->UseConfig(config
, rootpath
);
174 ReadCustomization(config
, rootpath
);
177 //// Backward compatibility with wxHelpController API
179 bool wxHtmlHelpController::Initialize(const wxString
& file
)
181 wxString dir
, filename
, ext
;
182 wxSplitPath(file
, & dir
, & filename
, & ext
);
185 dir
= dir
+ wxFILE_SEP_PATH
;
187 // Try to find a suitable file
188 wxString actualFilename
= dir
+ filename
+ wxString(wxT(".zip"));
189 if (!wxFileExists(actualFilename
))
191 actualFilename
= dir
+ filename
+ wxString(wxT(".htb"));
192 if (!wxFileExists(actualFilename
))
194 actualFilename
= dir
+ filename
+ wxString(wxT(".hhp"));
195 if (!wxFileExists(actualFilename
))
198 actualFilename
= dir
+ filename
+ wxString(wxT(".chm"));
199 if (!wxFileExists(actualFilename
))
205 return AddBook(wxFileName(actualFilename
));
208 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
210 // Don't reload the file or we'll have it appear again, presumably.
214 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
216 return Display(sectionNo
);
219 bool wxHtmlHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& WXUNUSED(pos
))
222 static wxTipWindow
* s_tipWindow
= NULL
;
226 // Prevent s_tipWindow being nulled in OnIdle,
227 // thereby removing the chance for the window to be closed by ShowHelp
228 s_tipWindow
->SetTipWindowPtr(NULL
);
229 s_tipWindow
->Close();
235 s_tipWindow
= new wxTipWindow(wxTheApp
->GetTopWindow(), text
, 100, & s_tipWindow
);
241 #endif // wxUSE_TIPWINDOW
246 void wxHtmlHelpController::SetFrameParameters(const wxString
& title
,
249 bool WXUNUSED(newFrameEachTime
))
251 SetTitleFormat(title
);
254 m_helpFrame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
258 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize
*size
,
260 bool *newFrameEachTime
)
262 if (newFrameEachTime
)
263 (* newFrameEachTime
) = false;
264 if (size
&& m_helpFrame
)
265 (* size
) = m_helpFrame
->GetSize();
266 if (pos
&& m_helpFrame
)
267 (* pos
) = m_helpFrame
->GetPosition();
271 bool wxHtmlHelpController::Quit()
277 // Make the help controller's frame 'modal' if
279 void wxHtmlHelpController::AddGrabIfNeeded()
281 // So far, wxGTK only
283 bool needGrab
= false;
285 // Check if there are any modal windows present,
286 // in which case we need to add a grab.
287 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
289 node
= node
->GetNext() )
291 wxWindow
*win
= node
->GetData();
292 wxDialog
*dialog
= wxDynamicCast(win
, wxDialog
);
294 if (dialog
&& dialog
->IsModal())
298 if (needGrab
&& m_helpFrame
)
299 m_helpFrame
->AddGrab();
303 bool wxHtmlHelpController::Display(const wxString
& x
)
306 bool success
= m_helpFrame
->Display(x
);
311 bool wxHtmlHelpController::Display(int id
)
314 bool success
= m_helpFrame
->Display(id
);
319 bool wxHtmlHelpController::DisplayContents()
322 bool success
= m_helpFrame
->DisplayContents();
327 bool wxHtmlHelpController::DisplayIndex()
330 bool success
= m_helpFrame
->DisplayIndex();
335 bool wxHtmlHelpController::KeywordSearch(const wxString
& keyword
,
336 wxHelpSearchMode mode
)
339 bool success
= m_helpFrame
->KeywordSearch(keyword
, mode
);
344 #endif // wxUSE_WXHTML_HELP