]>
Commit | Line | Data |
---|---|---|
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 | ||
f6bcfd97 | 23 | #if wxUSE_HTML && wxUSE_STREAMS |
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 | 37 | IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase) |
f42b1601 | 38 | |
d5bb85a0 | 39 | wxHtmlHelpController::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 | ||
48 | wxHtmlHelpController::~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 | |
57 | void wxHtmlHelpController::DestroyHelpWindow() | |
58 | { | |
59 | //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot); | |
60 | if (m_helpFrame) | |
61 | m_helpFrame->Destroy(); | |
62 | } | |
63 | ||
b4414c1f | 64 | void 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 |
74 | void 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 |
82 | bool 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 |
8ec2b484 HH |
99 | return retval; |
100 | } | |
101 | ||
b854b7b8 VS |
102 | |
103 | ||
104 | wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data) | |
105 | { | |
106 | return new wxHtmlHelpFrame(data); | |
107 | } | |
108 | ||
109 | ||
052e12db | 110 | void wxHtmlHelpController::CreateHelpWindow() |
8ec2b484 | 111 | { |
4f9297b0 VS |
112 | if (m_helpFrame) |
113 | { | |
d5bb85a0 VS |
114 | m_helpFrame->Raise(); |
115 | return ; | |
8ec2b484 | 116 | } |
d5bb85a0 | 117 | |
33ac7e6f | 118 | if (m_Config == NULL) |
74accc50 VS |
119 | { |
120 | m_Config = wxConfigBase::Get(FALSE); | |
121 | if (m_Config != NULL) | |
122 | m_ConfigRoot = _T("wxWindows/wxHtmlHelpController"); | |
123 | } | |
124 | ||
b854b7b8 | 125 | m_helpFrame = CreateHelpFrame(&m_helpData); |
b4414c1f | 126 | m_helpFrame->SetController(this); |
74accc50 | 127 | |
8ec2b484 | 128 | if (m_Config) |
d5bb85a0 | 129 | m_helpFrame->UseConfig(m_Config, m_ConfigRoot); |
74accc50 | 130 | |
d5bb85a0 | 131 | m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle); |
8ec2b484 HH |
132 | m_helpFrame->SetTitleFormat(m_titleFormat); |
133 | m_helpFrame->Show(TRUE); | |
134 | } | |
135 | ||
136 | void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path) | |
137 | { | |
138 | /* should not be called by the user; call UseConfig, and the controller | |
139 | * will do the rest */ | |
f6bcfd97 | 140 | if (m_helpFrame && cfg) |
d5bb85a0 | 141 | m_helpFrame->ReadCustomization(cfg, path); |
8ec2b484 HH |
142 | } |
143 | ||
144 | void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path) | |
145 | { | |
146 | /* typically called by the controllers OnCloseFrame handler */ | |
f6bcfd97 | 147 | if (m_helpFrame && cfg) |
d5bb85a0 | 148 | m_helpFrame->WriteCustomization(cfg, path); |
8ec2b484 HH |
149 | } |
150 | ||
721ab905 VS |
151 | void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath) |
152 | { | |
153 | m_Config = config; | |
154 | m_ConfigRoot = rootpath; | |
4f9297b0 | 155 | if (m_helpFrame) m_helpFrame->UseConfig(config, rootpath); |
721ab905 VS |
156 | ReadCustomization(config, rootpath); |
157 | } | |
158 | ||
b4414c1f JS |
159 | //// Backward compatibility with wxHelpController API |
160 | ||
161 | bool wxHtmlHelpController::Initialize(const wxString& file) | |
162 | { | |
163 | wxString dir, filename, ext; | |
164 | wxSplitPath(file, & dir, & filename, & ext); | |
165 | ||
166 | if (!dir.IsEmpty()) | |
e81910e0 | 167 | dir = dir + wxString(wxT("/")); |
b4414c1f JS |
168 | |
169 | // Try to find a suitable file | |
e81910e0 | 170 | wxString actualFilename = dir + filename + wxString(wxT(".zip")); |
b4414c1f JS |
171 | if (!wxFileExists(actualFilename)) |
172 | { | |
e81910e0 | 173 | actualFilename = dir + filename + wxString(wxT(".htb")); |
b4414c1f JS |
174 | if (!wxFileExists(actualFilename)) |
175 | { | |
e81910e0 | 176 | actualFilename = dir + filename + wxString(wxT(".hhp")); |
b4414c1f JS |
177 | if (!wxFileExists(actualFilename)) |
178 | return FALSE; | |
179 | } | |
180 | } | |
181 | ||
182 | return AddBook(actualFilename); | |
183 | } | |
184 | ||
185 | bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file)) | |
186 | { | |
187 | // Don't reload the file or we'll have it appear again, presumably. | |
188 | return TRUE; | |
189 | } | |
190 | ||
191 | bool wxHtmlHelpController::DisplaySection(int sectionNo) | |
192 | { | |
193 | return Display(sectionNo); | |
194 | } | |
195 | ||
673dfcfa JS |
196 | bool wxHtmlHelpController::DisplayTextPopup(const wxString& text, const wxPoint& WXUNUSED(pos)) |
197 | { | |
198 | #if wxUSE_HELP | |
199 | static wxTipWindow* s_tipWindow = NULL; | |
200 | ||
201 | if (s_tipWindow) | |
202 | { | |
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(); | |
207 | } | |
208 | s_tipWindow = NULL; | |
209 | ||
210 | if ( !text.empty() ) | |
211 | { | |
212 | s_tipWindow = new wxTipWindow(wxTheApp->GetTopWindow(), text, 100, & s_tipWindow); | |
213 | ||
214 | return TRUE; | |
215 | } | |
963a1fcd | 216 | #endif |
33ac7e6f | 217 | return FALSE; |
673dfcfa JS |
218 | } |
219 | ||
b4414c1f JS |
220 | void wxHtmlHelpController::SetFrameParameters(const wxString& title, |
221 | const wxSize& size, | |
222 | const wxPoint& pos, | |
223 | bool WXUNUSED(newFrameEachTime)) | |
224 | { | |
225 | SetTitleFormat(title); | |
226 | if (m_helpFrame) | |
227 | { | |
228 | m_helpFrame->SetSize(pos.x, pos.y, size.x, size.y); | |
229 | } | |
230 | } | |
231 | ||
232 | wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size, | |
233 | wxPoint *pos, | |
234 | bool *newFrameEachTime) | |
235 | { | |
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(); | |
242 | return m_helpFrame; | |
243 | } | |
244 | ||
245 | bool wxHtmlHelpController::Quit() | |
246 | { | |
247 | DestroyHelpWindow(); | |
248 | return TRUE; | |
249 | } | |
250 | ||
8ec2b484 | 251 | #endif |