]>
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
);
104 wxHtmlHelpFrame
*wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData
*data
)
106 return new wxHtmlHelpFrame(data
);
110 void wxHtmlHelpController::CreateHelpWindow()
114 m_helpFrame
->Raise();
118 if (m_Config
== NULL
)
120 m_Config
= wxConfigBase::Get(FALSE
);
121 if (m_Config
!= NULL
)
122 m_ConfigRoot
= _T("wxWindows/wxHtmlHelpController");
125 m_helpFrame
= CreateHelpFrame(&m_helpData
);
126 m_helpFrame
->SetController(this);
129 m_helpFrame
->UseConfig(m_Config
, m_ConfigRoot
);
131 m_helpFrame
->Create(NULL
, wxID_HTML_HELPFRAME
, wxEmptyString
, m_FrameStyle
);
132 m_helpFrame
->SetTitleFormat(m_titleFormat
);
133 m_helpFrame
->Show(TRUE
);
136 void wxHtmlHelpController::ReadCustomization(wxConfigBase
* cfg
, const wxString
& path
)
138 /* should not be called by the user; call UseConfig, and the controller
139 * will do the rest */
140 if (m_helpFrame
&& cfg
)
141 m_helpFrame
->ReadCustomization(cfg
, path
);
144 void wxHtmlHelpController::WriteCustomization(wxConfigBase
* cfg
, const wxString
& path
)
146 /* typically called by the controllers OnCloseFrame handler */
147 if (m_helpFrame
&& cfg
)
148 m_helpFrame
->WriteCustomization(cfg
, path
);
151 void wxHtmlHelpController::UseConfig(wxConfigBase
*config
, const wxString
& rootpath
)
154 m_ConfigRoot
= rootpath
;
155 if (m_helpFrame
) m_helpFrame
->UseConfig(config
, rootpath
);
156 ReadCustomization(config
, rootpath
);
159 //// Backward compatibility with wxHelpController API
161 bool wxHtmlHelpController::Initialize(const wxString
& file
)
163 wxString dir
, filename
, ext
;
164 wxSplitPath(file
, & dir
, & filename
, & ext
);
167 dir
= dir
+ wxString(wxT("/"));
169 // Try to find a suitable file
170 wxString actualFilename
= dir
+ filename
+ wxString(wxT(".zip"));
171 if (!wxFileExists(actualFilename
))
173 actualFilename
= dir
+ filename
+ wxString(wxT(".htb"));
174 if (!wxFileExists(actualFilename
))
176 actualFilename
= dir
+ filename
+ wxString(wxT(".hhp"));
177 if (!wxFileExists(actualFilename
))
182 return AddBook(actualFilename
);
185 bool wxHtmlHelpController::LoadFile(const wxString
& WXUNUSED(file
))
187 // Don't reload the file or we'll have it appear again, presumably.
191 bool wxHtmlHelpController::DisplaySection(int sectionNo
)
193 return Display(sectionNo
);
196 bool wxHtmlHelpController::DisplayTextPopup(const wxString
& text
, const wxPoint
& WXUNUSED(pos
))
199 static wxTipWindow
* s_tipWindow
= NULL
;
203 // Prevent s_tipWindow being nulled in OnIdle,
204 // thereby removing the chance for the window to be closed by ShowHelp
205 s_tipWindow
->SetTipWindowPtr(NULL
);
206 s_tipWindow
->Close();
212 s_tipWindow
= new wxTipWindow(wxTheApp
->GetTopWindow(), text
, 100, & s_tipWindow
);
216 #endif // wxUSE_TIPWINDOW
221 void wxHtmlHelpController::SetFrameParameters(const wxString
& title
,
224 bool WXUNUSED(newFrameEachTime
))
226 SetTitleFormat(title
);
229 m_helpFrame
->SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
233 wxFrame
* wxHtmlHelpController::GetFrameParameters(wxSize
*size
,
235 bool *newFrameEachTime
)
237 if (newFrameEachTime
)
238 (* newFrameEachTime
) = FALSE
;
239 if (size
&& m_helpFrame
)
240 (* size
) = m_helpFrame
->GetSize();
241 if (pos
&& m_helpFrame
)
242 (* pos
) = m_helpFrame
->GetPosition();
246 bool wxHtmlHelpController::Quit()
252 #endif // wxUSE_WXHTML_HELP