]>
git.saurik.com Git - wxWidgets.git/blob - src/html/helpctrl.cpp
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
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 #if wxUSE_HTML && wxUSE_STREAMS
27 #include "wx/html/helpctrl.h"
29 #include "wx/busyinfo.h"
32 #include "wx/tipwin.h"
35 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController
, wxHelpControllerBase
)
37 wxHtmlHelpController::wxHtmlHelpController(int style
)
41 m_ConfigRoot
= wxEmptyString
;
42 m_titleFormat
= _("Help: %s");
46 wxHtmlHelpController::~wxHtmlHelpController()
49 WriteCustomization(m_Config
, m_ConfigRoot
);
55 void wxHtmlHelpController::DestroyHelpWindow()
57 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
59 m_helpFrame
->Destroy();
62 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent
& evt
)
68 m_helpFrame
->SetController((wxHelpControllerBase
*) NULL
);
72 void wxHtmlHelpController::SetTitleFormat(const wxString
& title
)
74 m_titleFormat
= title
;
76 m_helpFrame
->SetTitleFormat(title
);
80 bool wxHtmlHelpController::AddBook(const wxString
& book
, bool show_wait_msg
)
84 wxBusyInfo
* busy
= NULL
;
88 info
.Printf(_("Adding book %s"), book
.c_str());
89 busy
= new wxBusyInfo(info
);
92 bool retval
= m_helpData
.AddBook(book
);
102 wxHtmlHelpFrame
*wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
104 return new wxHtmlHelpFrame(data
);
108 void wxHtmlHelpController::CreateHelpWindow()
112 m_helpFrame
->Raise();
116 if (m_Config
== NULL
)
118 m_Config
= wxConfigBase::Get(FALSE
);
119 if (m_Config
!= NULL
)
120 m_ConfigRoot
= _T("wxWindows/wxHtmlHelpController");
123 m_helpFrame
= CreateHelpFrame(&m_helpData
);
124 m_helpFrame
->SetController(this);
127 m_helpFrame
->UseConfig(m_Config
, m_ConfigRoot
);
129 m_helpFrame
->Create(NULL
, wxID_HTML_HELPFRAME
, wxEmptyString
, m_FrameStyle
);
130 m_helpFrame
->SetTitleFormat(m_titleFormat
);
131 m_helpFrame
->Show(TRUE
);
134 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
136 /* should not be called by the user; call UseConfig, and the controller
137 * will do the rest */
138 if (m_helpFrame
&& cfg
)
139 m_helpFrame
->ReadCustomization(cfg
, path
);
142 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
144 /* typically called by the controllers OnCloseFrame handler */
145 if (m_helpFrame
&& cfg
)
146 m_helpFrame
->WriteCustomization(cfg
, path
);
149 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
152 m_ConfigRoot
= rootpath
;
153 if (m_helpFrame
) m_helpFrame
->UseConfig(config
, rootpath
);
154 ReadCustomization(config
, rootpath
);
157 //// Backward compatibility with wxHelpController API
159 bool wxHtmlHelpController::Initialize(const wxString
& file
)
161 wxString dir
, filename
, ext
;
162 wxSplitPath(file
, & dir
, & filename
, & ext
);
165 dir
= dir
+ wxString(wxT("/"));
167 // Try to find a suitable file
168 wxString actualFilename
= dir
+ filename
+ wxString(wxT(".zip"));
169 if (!wxFileExists(actualFilename
))
171 actualFilename
= dir
+ filename
+ wxString(wxT(".htb"));
172 if (!wxFileExists(actualFilename
))
174 actualFilename
= dir
+ filename
+ wxString(wxT(".hhp"));
175 if (!wxFileExists(actualFilename
))
180 return AddBook(actualFilename
);
183 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
185 // Don't reload the file or we'll have it appear again, presumably.
189 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
191 return Display(sectionNo
);
194 bool wxHtmlHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& WXUNUSED(pos
))
197 static wxTipWindow
* s_tipWindow
= NULL
;
201 // Prevent s_tipWindow being nulled in OnIdle,
202 // thereby removing the chance for the window to be closed by ShowHelp
203 s_tipWindow
->SetTipWindowPtr(NULL
);
204 s_tipWindow
->Close();
210 s_tipWindow
= new wxTipWindow(wxTheApp
->GetTopWindow(), text
, 100, & s_tipWindow
);
220 void wxHtmlHelpController::SetFrameParameters(const wxString
& title
,
223 bool WXUNUSED(newFrameEachTime
))
225 SetTitleFormat(title
);
228 m_helpFrame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
232 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize
*size
,
234 bool *newFrameEachTime
)
236 if (newFrameEachTime
)
237 (* newFrameEachTime
) = FALSE
;
238 if (size
&& m_helpFrame
)
239 (* size
) = m_helpFrame
->GetSize();
240 if (pos
&& m_helpFrame
)
241 (* pos
) = m_helpFrame
->GetPosition();
245 bool wxHtmlHelpController::Quit()