]>
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"
30 #include "wx/html/helpctrl.h"
31 #include "wx/busyinfo.h"
34 #include "wx/tipwin.h"
37 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController
, wxHelpControllerBase
)
39 wxHtmlHelpController::wxHtmlHelpController(int style
)
43 m_ConfigRoot
= wxEmptyString
;
44 m_titleFormat
= _("Help: %s");
48 wxHtmlHelpController::~wxHtmlHelpController()
51 WriteCustomization(m_Config
, m_ConfigRoot
);
57 void wxHtmlHelpController::DestroyHelpWindow()
59 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
61 m_helpFrame
->Destroy();
64 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent
& evt
)
70 m_helpFrame
->SetController((wxHelpControllerBase
*) NULL
);
74 void wxHtmlHelpController::SetTitleFormat(const wxString
& title
)
76 m_titleFormat
= title
;
78 m_helpFrame
->SetTitleFormat(title
);
82 bool wxHtmlHelpController::AddBook(const wxString
& book
, bool show_wait_msg
)
86 wxBusyInfo
* busy
= NULL
;
90 info
.Printf(_("Adding book %s"), book
.c_str());
91 busy
= new wxBusyInfo(info
);
94 bool retval
= m_helpData
.AddBook(book
);
100 m_helpFrame
->RefreshLists();
106 wxHtmlHelpFrame
*wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
108 return new wxHtmlHelpFrame(data
);
112 void wxHtmlHelpController::CreateHelpWindow()
116 m_helpFrame
->Raise();
120 if (m_Config
== NULL
)
122 m_Config
= wxConfigBase::Get(FALSE
);
123 if (m_Config
!= NULL
)
124 m_ConfigRoot
= _T("wxWindows/wxHtmlHelpController");
127 m_helpFrame
= CreateHelpFrame(&m_helpData
);
128 m_helpFrame
->SetController(this);
131 m_helpFrame
->UseConfig(m_Config
, m_ConfigRoot
);
133 m_helpFrame
->Create(NULL
, wxID_HTML_HELPFRAME
, wxEmptyString
, m_FrameStyle
);
134 m_helpFrame
->SetTitleFormat(m_titleFormat
);
135 m_helpFrame
->Show(TRUE
);
138 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
140 /* should not be called by the user; call UseConfig, and the controller
141 * will do the rest */
142 if (m_helpFrame
&& cfg
)
143 m_helpFrame
->ReadCustomization(cfg
, path
);
146 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
148 /* typically called by the controllers OnCloseFrame handler */
149 if (m_helpFrame
&& cfg
)
150 m_helpFrame
->WriteCustomization(cfg
, path
);
153 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
156 m_ConfigRoot
= rootpath
;
157 if (m_helpFrame
) m_helpFrame
->UseConfig(config
, rootpath
);
158 ReadCustomization(config
, rootpath
);
161 //// Backward compatibility with wxHelpController API
163 bool wxHtmlHelpController::Initialize(const wxString
& file
)
165 wxString dir
, filename
, ext
;
166 wxSplitPath(file
, & dir
, & filename
, & ext
);
169 dir
= dir
+ wxString(wxT("/"));
171 // Try to find a suitable file
172 wxString actualFilename
= dir
+ filename
+ wxString(wxT(".zip"));
173 if (!wxFileExists(actualFilename
))
175 actualFilename
= dir
+ filename
+ wxString(wxT(".htb"));
176 if (!wxFileExists(actualFilename
))
178 actualFilename
= dir
+ filename
+ wxString(wxT(".hhp"));
179 if (!wxFileExists(actualFilename
))
184 return AddBook(actualFilename
);
187 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
189 // Don't reload the file or we'll have it appear again, presumably.
193 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
195 return Display(sectionNo
);
198 bool wxHtmlHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& WXUNUSED(pos
))
201 static wxTipWindow
* s_tipWindow
= NULL
;
205 // Prevent s_tipWindow being nulled in OnIdle,
206 // thereby removing the chance for the window to be closed by ShowHelp
207 s_tipWindow
->SetTipWindowPtr(NULL
);
208 s_tipWindow
->Close();
214 s_tipWindow
= new wxTipWindow(wxTheApp
->GetTopWindow(), text
, 100, & s_tipWindow
);
218 #endif // wxUSE_TIPWINDOW
223 void wxHtmlHelpController::SetFrameParameters(const wxString
& title
,
226 bool WXUNUSED(newFrameEachTime
))
228 SetTitleFormat(title
);
231 m_helpFrame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
235 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize
*size
,
237 bool *newFrameEachTime
)
239 if (newFrameEachTime
)
240 (* newFrameEachTime
) = FALSE
;
241 if (size
&& m_helpFrame
)
242 (* size
) = m_helpFrame
->GetSize();
243 if (pos
&& m_helpFrame
)
244 (* pos
) = m_helpFrame
->GetPosition();
248 bool wxHtmlHelpController::Quit()
254 #endif // wxUSE_WXHTML_HELP