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