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
);
116 m_helpFrame
->RefreshLists();
122 wxHtmlHelpFrame
*wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
124 return new wxHtmlHelpFrame(data
);
128 void wxHtmlHelpController::CreateHelpWindow()
132 m_helpFrame
->Raise();
136 if (m_Config
== NULL
)
138 m_Config
= wxConfigBase::Get(FALSE
);
139 if (m_Config
!= NULL
)
140 m_ConfigRoot
= _T("wxWidgets/wxHtmlHelpController");
143 m_helpFrame
= CreateHelpFrame(&m_helpData
);
144 m_helpFrame
->SetController(this);
147 m_helpFrame
->UseConfig(m_Config
, m_ConfigRoot
);
149 m_helpFrame
->Create(NULL
, wxID_HTML_HELPFRAME
, wxEmptyString
, m_FrameStyle
);
150 m_helpFrame
->SetTitleFormat(m_titleFormat
);
152 m_helpFrame
->Show(TRUE
);
155 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
157 /* should not be called by the user; call UseConfig, and the controller
158 * will do the rest */
159 if (m_helpFrame
&& cfg
)
160 m_helpFrame
->ReadCustomization(cfg
, path
);
163 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
165 /* typically called by the controllers OnCloseFrame handler */
166 if (m_helpFrame
&& cfg
)
167 m_helpFrame
->WriteCustomization(cfg
, path
);
170 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
173 m_ConfigRoot
= rootpath
;
174 if (m_helpFrame
) m_helpFrame
->UseConfig(config
, rootpath
);
175 ReadCustomization(config
, rootpath
);
178 //// Backward compatibility with wxHelpController API
180 bool wxHtmlHelpController::Initialize(const wxString
& file
)
182 wxString dir
, filename
, ext
;
183 wxSplitPath(file
, & dir
, & filename
, & ext
);
186 dir
= dir
+ wxFILE_SEP_PATH
;
188 // Try to find a suitable file
189 wxString actualFilename
= dir
+ filename
+ wxString(wxT(".zip"));
190 if (!wxFileExists(actualFilename
))
192 actualFilename
= dir
+ filename
+ wxString(wxT(".htb"));
193 if (!wxFileExists(actualFilename
))
195 actualFilename
= dir
+ filename
+ wxString(wxT(".hhp"));
196 if (!wxFileExists(actualFilename
))
199 actualFilename
= dir
+ filename
+ wxString(wxT(".chm"));
200 if (!wxFileExists(actualFilename
))
206 return AddBook(wxFileName(actualFilename
));
209 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
211 // Don't reload the file or we'll have it appear again, presumably.
215 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
217 return Display(sectionNo
);
220 bool wxHtmlHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& WXUNUSED(pos
))
223 static wxTipWindow
* s_tipWindow
= NULL
;
227 // Prevent s_tipWindow being nulled in OnIdle,
228 // thereby removing the chance for the window to be closed by ShowHelp
229 s_tipWindow
->SetTipWindowPtr(NULL
);
230 s_tipWindow
->Close();
236 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