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 wxFileName
& book_file
, bool show_wait_msg
)
89 return AddBook(wxFileSystem::FileNameToURL(book_file
), show_wait_msg
);
92 bool wxHtmlHelpController::AddBook(const wxString
& book
, bool show_wait_msg
)
96 wxBusyInfo
* busy
= NULL
;
100 info
.Printf(_("Adding book %s"), book
.c_str());
101 busy
= new wxBusyInfo(info
);
104 bool retval
= m_helpData
.AddBook(book
);
110 m_helpFrame
->RefreshLists();
116 wxHtmlHelpFrame
*wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
118 return new wxHtmlHelpFrame(data
);
122 void wxHtmlHelpController::CreateHelpWindow()
126 m_helpFrame
->Raise();
130 if (m_Config
== NULL
)
132 m_Config
= wxConfigBase::Get(FALSE
);
133 if (m_Config
!= NULL
)
134 m_ConfigRoot
= _T("wxWindows/wxHtmlHelpController");
137 m_helpFrame
= CreateHelpFrame(&m_helpData
);
138 m_helpFrame
->SetController(this);
141 m_helpFrame
->UseConfig(m_Config
, m_ConfigRoot
);
143 m_helpFrame
->Create(NULL
, wxID_HTML_HELPFRAME
, wxEmptyString
, m_FrameStyle
);
144 m_helpFrame
->SetTitleFormat(m_titleFormat
);
145 m_helpFrame
->Show(TRUE
);
148 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
150 /* should not be called by the user; call UseConfig, and the controller
151 * will do the rest */
152 if (m_helpFrame
&& cfg
)
153 m_helpFrame
->ReadCustomization(cfg
, path
);
156 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
158 /* typically called by the controllers OnCloseFrame handler */
159 if (m_helpFrame
&& cfg
)
160 m_helpFrame
->WriteCustomization(cfg
, path
);
163 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
166 m_ConfigRoot
= rootpath
;
167 if (m_helpFrame
) m_helpFrame
->UseConfig(config
, rootpath
);
168 ReadCustomization(config
, rootpath
);
171 //// Backward compatibility with wxHelpController API
173 bool wxHtmlHelpController::Initialize(const wxString
& file
)
175 wxString dir
, filename
, ext
;
176 wxSplitPath(file
, & dir
, & filename
, & ext
);
179 dir
= dir
+ wxFILE_SEP_PATH
;
181 // Try to find a suitable file
182 wxString actualFilename
= dir
+ filename
+ wxString(wxT(".zip"));
183 if (!wxFileExists(actualFilename
))
185 actualFilename
= dir
+ filename
+ wxString(wxT(".htb"));
186 if (!wxFileExists(actualFilename
))
188 actualFilename
= dir
+ filename
+ wxString(wxT(".hhp"));
189 if (!wxFileExists(actualFilename
))
194 return AddBook(wxFileName(actualFilename
));
197 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
199 // Don't reload the file or we'll have it appear again, presumably.
203 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
205 return Display(sectionNo
);
208 bool wxHtmlHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& WXUNUSED(pos
))
211 static wxTipWindow
* s_tipWindow
= NULL
;
215 // Prevent s_tipWindow being nulled in OnIdle,
216 // thereby removing the chance for the window to be closed by ShowHelp
217 s_tipWindow
->SetTipWindowPtr(NULL
);
218 s_tipWindow
->Close();
224 s_tipWindow
= new wxTipWindow(wxTheApp
->GetTopWindow(), text
, 100, & s_tipWindow
);
228 #endif // wxUSE_TIPWINDOW
233 void wxHtmlHelpController::SetFrameParameters(const wxString
& title
,
236 bool WXUNUSED(newFrameEachTime
))
238 SetTitleFormat(title
);
241 m_helpFrame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
245 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize
*size
,
247 bool *newFrameEachTime
)
249 if (newFrameEachTime
)
250 (* newFrameEachTime
) = FALSE
;
251 if (size
&& m_helpFrame
)
252 (* size
) = m_helpFrame
->GetSize();
253 if (pos
&& m_helpFrame
)
254 (* pos
) = m_helpFrame
->GetPosition();
258 bool wxHtmlHelpController::Quit()
264 // Make the help controller's frame 'modal' if
266 void wxHtmlHelpController::AddGrabIfNeeded()
268 // So far, wxGTK only
270 bool needGrab
= FALSE
;
272 // Check if there are any modal windows present,
273 // in which case we need to add a grab.
274 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
276 node
= node
->GetNext() )
278 wxWindow
*win
= node
->GetData();
279 wxDialog
*dialog
= wxDynamicCast(win
, wxDialog
);
281 if (dialog
&& dialog
->IsModal())
285 if (needGrab
&& m_helpFrame
)
286 m_helpFrame
->AddGrab();
290 bool wxHtmlHelpController::Display(const wxString
& x
)
293 bool success
= m_helpFrame
->Display(x
);
298 bool wxHtmlHelpController::Display(int id
)
301 bool success
= m_helpFrame
->Display(id
);
306 bool wxHtmlHelpController::DisplayContents()
309 bool success
= m_helpFrame
->DisplayContents();
314 bool wxHtmlHelpController::DisplayIndex()
317 bool success
= m_helpFrame
->DisplayIndex();
322 bool wxHtmlHelpController::KeywordSearch(const wxString
& keyword
)
325 bool success
= m_helpFrame
->KeywordSearch(keyword
);
330 #endif // wxUSE_WXHTML_HELP