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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "helpctrl.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
30 #include "wx/html/helpctrl.h"
31 #include "wx/busyinfo.h"
34 // for the hack in AddGrabIfNeeded()
35 #include "wx/dialog.h"
39 #include "wx/tipwin.h"
44 #include "wx/html/forcelnk.h"
45 FORCE_LINK(wxhtml_chm_support
)
48 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController
, wxHelpControllerBase
)
50 wxHtmlHelpController::wxHtmlHelpController(int style
)
54 m_ConfigRoot
= wxEmptyString
;
55 m_titleFormat
= _("Help: %s");
59 wxHtmlHelpController::~wxHtmlHelpController()
62 WriteCustomization(m_Config
, m_ConfigRoot
);
68 void wxHtmlHelpController::DestroyHelpWindow()
70 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
72 m_helpFrame
->Destroy();
75 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent
& evt
)
81 m_helpFrame
->SetController((wxHelpControllerBase
*) NULL
);
85 void wxHtmlHelpController::SetTitleFormat(const wxString
& title
)
87 m_titleFormat
= title
;
89 m_helpFrame
->SetTitleFormat(title
);
93 bool wxHtmlHelpController::AddBook(const wxFileName
& book_file
, bool show_wait_msg
)
95 return AddBook(wxFileSystem::FileNameToURL(book_file
), show_wait_msg
);
98 bool wxHtmlHelpController::AddBook(const wxString
& book
, bool show_wait_msg
)
102 wxBusyInfo
* busy
= NULL
;
106 info
.Printf(_("Adding book %s"), book
.c_str());
107 busy
= new wxBusyInfo(info
);
110 bool retval
= m_helpData
.AddBook(book
);
115 wxUnusedVar(show_wait_msg
);
118 m_helpFrame
->RefreshLists();
124 wxHtmlHelpFrame
*wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
126 return new wxHtmlHelpFrame(data
);
130 void wxHtmlHelpController::CreateHelpWindow()
134 m_helpFrame
->Raise();
138 if (m_Config
== NULL
)
140 m_Config
= wxConfigBase::Get(false);
141 if (m_Config
!= NULL
)
142 m_ConfigRoot
= _T("wxWindows/wxHtmlHelpController");
145 m_helpFrame
= CreateHelpFrame(&m_helpData
);
146 m_helpFrame
->SetController(this);
149 m_helpFrame
->UseConfig(m_Config
, m_ConfigRoot
);
151 m_helpFrame
->Create(NULL
, wxID_HTML_HELPFRAME
, wxEmptyString
, m_FrameStyle
);
152 m_helpFrame
->SetTitleFormat(m_titleFormat
);
154 m_helpFrame
->Show(true);
157 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
159 /* should not be called by the user; call UseConfig, and the controller
160 * will do the rest */
161 if (m_helpFrame
&& cfg
)
162 m_helpFrame
->ReadCustomization(cfg
, path
);
165 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
167 /* typically called by the controllers OnCloseFrame handler */
168 if (m_helpFrame
&& cfg
)
169 m_helpFrame
->WriteCustomization(cfg
, path
);
172 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
175 m_ConfigRoot
= rootpath
;
176 if (m_helpFrame
) m_helpFrame
->UseConfig(config
, rootpath
);
177 ReadCustomization(config
, rootpath
);
180 //// Backward compatibility with wxHelpController API
182 bool wxHtmlHelpController::Initialize(const wxString
& file
)
184 wxString dir
, filename
, ext
;
185 wxSplitPath(file
, & dir
, & filename
, & ext
);
188 dir
= dir
+ wxFILE_SEP_PATH
;
190 // Try to find a suitable file
191 wxString actualFilename
= dir
+ filename
+ wxString(wxT(".zip"));
192 if (!wxFileExists(actualFilename
))
194 actualFilename
= dir
+ filename
+ wxString(wxT(".htb"));
195 if (!wxFileExists(actualFilename
))
197 actualFilename
= dir
+ filename
+ wxString(wxT(".hhp"));
198 if (!wxFileExists(actualFilename
))
201 actualFilename
= dir
+ filename
+ wxString(wxT(".chm"));
202 if (!wxFileExists(actualFilename
))
208 return AddBook(wxFileName(actualFilename
));
211 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
213 // Don't reload the file or we'll have it appear again, presumably.
217 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
219 return Display(sectionNo
);
222 bool wxHtmlHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& WXUNUSED(pos
))
225 static wxTipWindow
* s_tipWindow
= NULL
;
229 // Prevent s_tipWindow being nulled in OnIdle,
230 // thereby removing the chance for the window to be closed by ShowHelp
231 s_tipWindow
->SetTipWindowPtr(NULL
);
232 s_tipWindow
->Close();
238 s_tipWindow
= new wxTipWindow(wxTheApp
->GetTopWindow(), text
, 100, & s_tipWindow
);
244 #endif // wxUSE_TIPWINDOW
249 void wxHtmlHelpController::SetFrameParameters(const wxString
& title
,
252 bool WXUNUSED(newFrameEachTime
))
254 SetTitleFormat(title
);
257 m_helpFrame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
261 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize
*size
,
263 bool *newFrameEachTime
)
265 if (newFrameEachTime
)
266 (* newFrameEachTime
) = false;
267 if (size
&& m_helpFrame
)
268 (* size
) = m_helpFrame
->GetSize();
269 if (pos
&& m_helpFrame
)
270 (* pos
) = m_helpFrame
->GetPosition();
274 bool wxHtmlHelpController::Quit()
280 // Make the help controller's frame 'modal' if
282 void wxHtmlHelpController::AddGrabIfNeeded()
284 // So far, wxGTK only
286 bool needGrab
= false;
288 // Check if there are any modal windows present,
289 // in which case we need to add a grab.
290 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
292 node
= node
->GetNext() )
294 wxWindow
*win
= node
->GetData();
295 wxDialog
*dialog
= wxDynamicCast(win
, wxDialog
);
297 if (dialog
&& dialog
->IsModal())
301 if (needGrab
&& m_helpFrame
)
302 m_helpFrame
->AddGrab();
306 bool wxHtmlHelpController::Display(const wxString
& x
)
309 bool success
= m_helpFrame
->Display(x
);
314 bool wxHtmlHelpController::Display(int id
)
317 bool success
= m_helpFrame
->Display(id
);
322 bool wxHtmlHelpController::DisplayContents()
325 bool success
= m_helpFrame
->DisplayContents();
330 bool wxHtmlHelpController::DisplayIndex()
333 bool success
= m_helpFrame
->DisplayIndex();
338 bool wxHtmlHelpController::KeywordSearch(const wxString
& keyword
,
339 wxHelpSearchMode mode
)
342 bool success
= m_helpFrame
->KeywordSearch(keyword
, mode
);
347 #endif // wxUSE_WXHTML_HELP