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 /////////////////////////////////////////////////////////////////////////////
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"
42 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase)
44 wxHtmlHelpController::wxHtmlHelpController(int style)
48 m_ConfigRoot = wxEmptyString;
49 m_titleFormat = _("Help: %s");
53 wxHtmlHelpController::~wxHtmlHelpController()
56 WriteCustomization(m_Config, m_ConfigRoot);
62 void wxHtmlHelpController::DestroyHelpWindow()
64 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
66 m_helpFrame->Destroy();
69 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
75 m_helpFrame->SetController((wxHelpControllerBase*) NULL);
79 void wxHtmlHelpController::SetTitleFormat(const wxString& title)
81 m_titleFormat = title;
83 m_helpFrame->SetTitleFormat(title);
87 bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
91 wxBusyInfo* busy = NULL;
95 info.Printf(_("Adding book %s"), book.c_str());
96 busy = new wxBusyInfo(info);
99 bool retval = m_helpData.AddBook(book);
105 m_helpFrame->RefreshLists();
111 wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
113 return new wxHtmlHelpFrame(data);
117 void wxHtmlHelpController::CreateHelpWindow()
121 m_helpFrame->Raise();
125 if (m_Config == NULL)
127 m_Config = wxConfigBase::Get(FALSE);
128 if (m_Config != NULL)
129 m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
132 m_helpFrame = CreateHelpFrame(&m_helpData);
133 m_helpFrame->SetController(this);
136 m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
138 m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
139 m_helpFrame->SetTitleFormat(m_titleFormat);
140 m_helpFrame->Show(TRUE);
143 void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path)
145 /* should not be called by the user; call UseConfig, and the controller
146 * will do the rest */
147 if (m_helpFrame && cfg)
148 m_helpFrame->ReadCustomization(cfg, path);
151 void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
153 /* typically called by the controllers OnCloseFrame handler */
154 if (m_helpFrame && cfg)
155 m_helpFrame->WriteCustomization(cfg, path);
158 void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
161 m_ConfigRoot = rootpath;
162 if (m_helpFrame) m_helpFrame->UseConfig(config, rootpath);
163 ReadCustomization(config, rootpath);
166 //// Backward compatibility with wxHelpController API
168 bool wxHtmlHelpController::Initialize(const wxString& file)
170 wxString dir, filename, ext;
171 wxSplitPath(file, & dir, & filename, & ext);
174 dir = dir + wxString(wxT("/"));
176 // Try to find a suitable file
177 wxString actualFilename = dir + filename + wxString(wxT(".zip"));
178 if (!wxFileExists(actualFilename))
180 actualFilename = dir + filename + wxString(wxT(".htb"));
181 if (!wxFileExists(actualFilename))
183 actualFilename = dir + filename + wxString(wxT(".hhp"));
184 if (!wxFileExists(actualFilename))
189 return AddBook(actualFilename);
192 bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
194 // Don't reload the file or we'll have it appear again, presumably.
198 bool wxHtmlHelpController::DisplaySection(int sectionNo)
200 return Display(sectionNo);
203 bool wxHtmlHelpController::DisplayTextPopup(const wxString& text, const wxPoint& WXUNUSED(pos))
206 static wxTipWindow* s_tipWindow = NULL;
210 // Prevent s_tipWindow being nulled in OnIdle,
211 // thereby removing the chance for the window to be closed by ShowHelp
212 s_tipWindow->SetTipWindowPtr(NULL);
213 s_tipWindow->Close();
219 s_tipWindow = new wxTipWindow(wxTheApp->GetTopWindow(), text, 100, & s_tipWindow);
223 #endif // wxUSE_TIPWINDOW
228 void wxHtmlHelpController::SetFrameParameters(const wxString& title,
231 bool WXUNUSED(newFrameEachTime))
233 SetTitleFormat(title);
236 m_helpFrame->SetSize(pos.x, pos.y, size.x, size.y);
240 wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size,
242 bool *newFrameEachTime)
244 if (newFrameEachTime)
245 (* newFrameEachTime) = FALSE;
246 if (size && m_helpFrame)
247 (* size) = m_helpFrame->GetSize();
248 if (pos && m_helpFrame)
249 (* pos) = m_helpFrame->GetPosition();
253 bool wxHtmlHelpController::Quit()
259 // Make the help controller's frame 'modal' if
261 void wxHtmlHelpController::AddGrabIfNeeded()
263 // So far, wxGTK only
265 bool needGrab = FALSE;
267 // Check if there are any modal windows present,
268 // in which case we need to add a grab.
269 for ( wxWindowList::Node * node = wxTopLevelWindows.GetFirst();
271 node = node->GetNext() )
273 wxWindow *win = node->GetData();
274 wxDialog *dialog = wxDynamicCast(win, wxDialog);
276 if (dialog && dialog->IsModal())
280 if (needGrab && m_helpFrame)
281 m_helpFrame->AddGrab();
285 bool wxHtmlHelpController::Display(const wxString& x)
288 bool success = m_helpFrame->Display(x);
293 bool wxHtmlHelpController::Display(int id)
296 bool success = m_helpFrame->Display(id);
301 bool wxHtmlHelpController::DisplayContents()
304 bool success = m_helpFrame->DisplayContents();
309 bool wxHtmlHelpController::DisplayIndex()
312 bool success = m_helpFrame->DisplayIndex();
317 bool wxHtmlHelpController::KeywordSearch(const wxString& keyword)
320 bool success = m_helpFrame->KeywordSearch(keyword);
325 #endif // wxUSE_WXHTML_HELP