]> git.saurik.com Git - wxWidgets.git/blame - src/html/helpctrl.cpp
No change
[wxWidgets.git] / src / html / helpctrl.cpp
CommitLineData
8ec2b484
HH
1/////////////////////////////////////////////////////////////////////////////
2// Name: helpctrl.cpp
3// Purpose: wxHtmlHelpController
f42b1601 4// Notes: Based on htmlhelp.cpp, implementing a monolithic
8ec2b484
HH
5// HTML Help controller class, by Vaclav Slavik
6// Author: Harm van der Heijden and Vaclav Slavik
69941f05 7// RCS-ID: $Id$
8ec2b484
HH
8// Copyright: (c) Harm van der Heijden and Vaclav Slavik
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
69941f05 13#pragma implementation
8ec2b484
HH
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
3379ed37 23#if wxUSE_WXHTML_HELP
8ec2b484 24
07b8d7ec
VZ
25#ifndef WX_PRECOMP
26 #include "wx/app.h"
27 #include "wx/intl.h"
28#endif // WX_PRECOMP
29
8ec2b484 30#include "wx/html/helpctrl.h"
8ec2b484
HH
31#include "wx/busyinfo.h"
32
673dfcfa
JS
33#if wxUSE_HELP
34#include "wx/tipwin.h"
35#endif
36
b4414c1f 37IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase)
f42b1601 38
d5bb85a0 39wxHtmlHelpController::wxHtmlHelpController(int style)
8ec2b484
HH
40{
41 m_helpFrame = NULL;
42 m_Config = NULL;
43 m_ConfigRoot = wxEmptyString;
44 m_titleFormat = _("Help: %s");
d5bb85a0 45 m_FrameStyle = style;
8ec2b484
HH
46}
47
48wxHtmlHelpController::~wxHtmlHelpController()
49{
f6bcfd97
BP
50 if (m_Config)
51 WriteCustomization(m_Config, m_ConfigRoot);
8ec2b484 52 if (m_helpFrame)
b854b7b8 53 DestroyHelpWindow();
8ec2b484
HH
54}
55
b854b7b8
VS
56
57void wxHtmlHelpController::DestroyHelpWindow()
58{
59 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
60 if (m_helpFrame)
61 m_helpFrame->Destroy();
62}
63
b4414c1f 64void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
b854b7b8 65{
b4414c1f 66 evt.Skip();
b854b7b8 67
b4414c1f 68 OnQuit();
b854b7b8 69
b4414c1f
JS
70 m_helpFrame->SetController((wxHelpControllerBase*) NULL);
71 m_helpFrame = NULL;
72}
b854b7b8 73
8ec2b484
HH
74void wxHtmlHelpController::SetTitleFormat(const wxString& title)
75{
76 m_titleFormat = title;
77 if (m_helpFrame)
d5bb85a0 78 m_helpFrame->SetTitleFormat(title);
8ec2b484
HH
79}
80
d5bb85a0 81
8ec2b484
HH
82bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
83{
84 wxBusyCursor cur;
85#if wxUSE_BUSYINFO
69941f05 86 wxBusyInfo* busy = NULL;
8ec2b484 87 wxString info;
33ac7e6f 88 if (show_wait_msg)
4f9297b0 89 {
d5bb85a0
VS
90 info.Printf(_("Adding book %s"), book.c_str());
91 busy = new wxBusyInfo(info);
8ec2b484
HH
92 }
93#endif
94 bool retval = m_helpData.AddBook(book);
95#if wxUSE_BUSYINFO
96 if (show_wait_msg)
d5bb85a0 97 delete busy;
33ac7e6f 98#endif
fc799548 99 if (m_helpFrame)
5ecdcaa7 100 m_helpFrame->RefreshLists();
8ec2b484
HH
101 return retval;
102}
103
b854b7b8
VS
104
105
106wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
107{
108 return new wxHtmlHelpFrame(data);
109}
110
111
052e12db 112void wxHtmlHelpController::CreateHelpWindow()
8ec2b484 113{
4f9297b0
VS
114 if (m_helpFrame)
115 {
d5bb85a0
VS
116 m_helpFrame->Raise();
117 return ;
8ec2b484 118 }
d5bb85a0 119
33ac7e6f 120 if (m_Config == NULL)
74accc50
VS
121 {
122 m_Config = wxConfigBase::Get(FALSE);
123 if (m_Config != NULL)
124 m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
125 }
126
b854b7b8 127 m_helpFrame = CreateHelpFrame(&m_helpData);
b4414c1f 128 m_helpFrame->SetController(this);
74accc50 129
8ec2b484 130 if (m_Config)
d5bb85a0 131 m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
74accc50 132
d5bb85a0 133 m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
8ec2b484
HH
134 m_helpFrame->SetTitleFormat(m_titleFormat);
135 m_helpFrame->Show(TRUE);
136}
137
138void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path)
139{
140 /* should not be called by the user; call UseConfig, and the controller
141 * will do the rest */
f6bcfd97 142 if (m_helpFrame && cfg)
d5bb85a0 143 m_helpFrame->ReadCustomization(cfg, path);
8ec2b484
HH
144}
145
146void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
147{
148 /* typically called by the controllers OnCloseFrame handler */
f6bcfd97 149 if (m_helpFrame && cfg)
d5bb85a0 150 m_helpFrame->WriteCustomization(cfg, path);
8ec2b484
HH
151}
152
721ab905
VS
153void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
154{
155 m_Config = config;
156 m_ConfigRoot = rootpath;
4f9297b0 157 if (m_helpFrame) m_helpFrame->UseConfig(config, rootpath);
721ab905
VS
158 ReadCustomization(config, rootpath);
159}
160
b4414c1f
JS
161//// Backward compatibility with wxHelpController API
162
163bool wxHtmlHelpController::Initialize(const wxString& file)
164{
165 wxString dir, filename, ext;
166 wxSplitPath(file, & dir, & filename, & ext);
167
168 if (!dir.IsEmpty())
e81910e0 169 dir = dir + wxString(wxT("/"));
b4414c1f
JS
170
171 // Try to find a suitable file
e81910e0 172 wxString actualFilename = dir + filename + wxString(wxT(".zip"));
b4414c1f
JS
173 if (!wxFileExists(actualFilename))
174 {
e81910e0 175 actualFilename = dir + filename + wxString(wxT(".htb"));
b4414c1f
JS
176 if (!wxFileExists(actualFilename))
177 {
e81910e0 178 actualFilename = dir + filename + wxString(wxT(".hhp"));
b4414c1f
JS
179 if (!wxFileExists(actualFilename))
180 return FALSE;
181 }
182 }
183
184 return AddBook(actualFilename);
185}
186
187bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
188{
189 // Don't reload the file or we'll have it appear again, presumably.
190 return TRUE;
191}
192
193bool wxHtmlHelpController::DisplaySection(int sectionNo)
194{
195 return Display(sectionNo);
196}
197
673dfcfa
JS
198bool wxHtmlHelpController::DisplayTextPopup(const wxString& text, const wxPoint& WXUNUSED(pos))
199{
f38bcae5 200#if wxUSE_TIPWINDOW
673dfcfa
JS
201 static wxTipWindow* s_tipWindow = NULL;
202
203 if (s_tipWindow)
204 {
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();
209 }
210 s_tipWindow = NULL;
211
212 if ( !text.empty() )
213 {
214 s_tipWindow = new wxTipWindow(wxTheApp->GetTopWindow(), text, 100, & s_tipWindow);
215
216 return TRUE;
217 }
f38bcae5
VZ
218#endif // wxUSE_TIPWINDOW
219
33ac7e6f 220 return FALSE;
673dfcfa
JS
221}
222
b4414c1f
JS
223void wxHtmlHelpController::SetFrameParameters(const wxString& title,
224 const wxSize& size,
225 const wxPoint& pos,
226 bool WXUNUSED(newFrameEachTime))
227{
228 SetTitleFormat(title);
229 if (m_helpFrame)
230 {
231 m_helpFrame->SetSize(pos.x, pos.y, size.x, size.y);
232 }
233}
234
235wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size,
236 wxPoint *pos,
237 bool *newFrameEachTime)
238{
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();
245 return m_helpFrame;
246}
247
248bool wxHtmlHelpController::Quit()
249{
250 DestroyHelpWindow();
251 return TRUE;
252}
253
3379ed37
VZ
254#endif // wxUSE_WXHTML_HELP
255