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
)
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_Config) WriteCustomization(m_Config, m_ConfigRoot);
68 m_helpFrame
->Destroy();
71 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent
& evt
)
77 m_helpFrame
->SetController((wxHelpControllerBase
*) NULL
);
81 void wxHtmlHelpController::SetTitleFormat(const wxString
& title
)
83 m_titleFormat
= title
;
85 m_helpFrame
->SetTitleFormat(title
);
89 bool wxHtmlHelpController::AddBook(const wxFileName
& book_file
, bool show_wait_msg
)
91 return AddBook(wxFileSystem::FileNameToURL(book_file
), show_wait_msg
);
94 bool wxHtmlHelpController::AddBook(const wxString
& book
, bool show_wait_msg
)
98 wxBusyInfo
* busy
= NULL
;
102 info
.Printf(_("Adding book %s"), book
.c_str());
103 busy
= new wxBusyInfo(info
);
106 bool retval
= m_helpData
.AddBook(book
);
111 wxUnusedVar(show_wait_msg
);
114 m_helpFrame
->RefreshLists();
120 wxHtmlHelpFrame
*wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
122 return new wxHtmlHelpFrame(data
);
126 void wxHtmlHelpController::CreateHelpWindow()
130 m_helpFrame
->Raise();
134 if (m_Config
== NULL
)
136 m_Config
= wxConfigBase::Get(false);
137 if (m_Config
!= NULL
)
138 m_ConfigRoot
= _T("wxWindows/wxHtmlHelpController");
141 m_helpFrame
= CreateHelpFrame(&m_helpData
);
142 m_helpFrame
->SetController(this);
145 m_helpFrame
->UseConfig(m_Config
, m_ConfigRoot
);
147 m_helpFrame
->Create(NULL
, wxID_HTML_HELPFRAME
, wxEmptyString
, m_FrameStyle
);
148 m_helpFrame
->SetTitleFormat(m_titleFormat
);
150 m_helpFrame
->Show(true);
153 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
155 /* should not be called by the user; call UseConfig, and the controller
156 * will do the rest */
157 if (m_helpFrame
&& cfg
)
158 m_helpFrame
->ReadCustomization(cfg
, path
);
161 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
163 /* typically called by the controllers OnCloseFrame handler */
164 if (m_helpFrame
&& cfg
)
165 m_helpFrame
->WriteCustomization(cfg
, path
);
168 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
171 m_ConfigRoot
= rootpath
;
172 if (m_helpFrame
) m_helpFrame
->UseConfig(config
, rootpath
);
173 ReadCustomization(config
, rootpath
);
176 //// Backward compatibility with wxHelpController API
178 bool wxHtmlHelpController::Initialize(const wxString
& file
)
180 wxString dir
, filename
, ext
;
181 wxSplitPath(file
, & dir
, & filename
, & ext
);
184 dir
= dir
+ wxFILE_SEP_PATH
;
186 // Try to find a suitable file
187 wxString actualFilename
= dir
+ filename
+ wxString(wxT(".zip"));
188 if (!wxFileExists(actualFilename
))
190 actualFilename
= dir
+ filename
+ wxString(wxT(".htb"));
191 if (!wxFileExists(actualFilename
))
193 actualFilename
= dir
+ filename
+ wxString(wxT(".hhp"));
194 if (!wxFileExists(actualFilename
))
197 actualFilename
= dir
+ filename
+ wxString(wxT(".chm"));
198 if (!wxFileExists(actualFilename
))
204 return AddBook(wxFileName(actualFilename
));
207 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
209 // Don't reload the file or we'll have it appear again, presumably.
213 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
215 return Display(sectionNo
);
218 bool wxHtmlHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& WXUNUSED(pos
))
221 static wxTipWindow
* s_tipWindow
= NULL
;
225 // Prevent s_tipWindow being nulled in OnIdle,
226 // thereby removing the chance for the window to be closed by ShowHelp
227 s_tipWindow
->SetTipWindowPtr(NULL
);
228 s_tipWindow
->Close();
234 s_tipWindow
= new wxTipWindow(wxTheApp
->GetTopWindow(), text
, 100, & s_tipWindow
);
240 #endif // wxUSE_TIPWINDOW
245 void wxHtmlHelpController::SetFrameParameters(const wxString
& title
,
248 bool WXUNUSED(newFrameEachTime
))
250 SetTitleFormat(title
);
253 m_helpFrame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
257 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize
*size
,
259 bool *newFrameEachTime
)
261 if (newFrameEachTime
)
262 (* newFrameEachTime
) = false;
263 if (size
&& m_helpFrame
)
264 (* size
) = m_helpFrame
->GetSize();
265 if (pos
&& m_helpFrame
)
266 (* pos
) = m_helpFrame
->GetPosition();
270 bool wxHtmlHelpController::Quit()
276 // Make the help controller's frame 'modal' if
278 void wxHtmlHelpController::AddGrabIfNeeded()
280 // So far, wxGTK only
282 bool needGrab
= false;
284 // Check if there are any modal windows present,
285 // in which case we need to add a grab.
286 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
288 node
= node
->GetNext() )
290 wxWindow
*win
= node
->GetData();
291 wxDialog
*dialog
= wxDynamicCast(win
, wxDialog
);
293 if (dialog
&& dialog
->IsModal())
297 if (needGrab
&& m_helpFrame
)
298 m_helpFrame
->AddGrab();
302 bool wxHtmlHelpController::Display(const wxString
& x
)
305 bool success
= m_helpFrame
->Display(x
);
310 bool wxHtmlHelpController::Display(int id
)
313 bool success
= m_helpFrame
->Display(id
);
318 bool wxHtmlHelpController::DisplayContents()
321 bool success
= m_helpFrame
->DisplayContents();
326 bool wxHtmlHelpController::DisplayIndex()
329 bool success
= m_helpFrame
->DisplayIndex();
334 bool wxHtmlHelpController::KeywordSearch(const wxString
& keyword
,
335 wxHelpSearchMode mode
)
338 bool success
= m_helpFrame
->KeywordSearch(keyword
, mode
);
343 #endif // wxUSE_WXHTML_HELP