]> git.saurik.com Git - wxWidgets.git/blob - src/html/helpctrl.cpp
multilib mode compilation fix
[wxWidgets.git] / src / html / helpctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: helpctrl.cpp
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
7 // RCS-ID: $Id$
8 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "helpctrl.h"
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 #if wxUSE_WXHTML_HELP
24
25 #ifndef WX_PRECOMP
26 #include "wx/app.h"
27 #include "wx/intl.h"
28 #endif // WX_PRECOMP
29
30 #include "wx/html/helpctrl.h"
31 #include "wx/busyinfo.h"
32
33 #ifdef __WXGTK__
34 // for the hack in AddGrabIfNeeded()
35 #include "wx/dialog.h"
36 #endif // __WXGTK__
37
38 #if wxUSE_HELP
39 #include "wx/tipwin.h"
40 #endif
41
42 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase)
43
44 wxHtmlHelpController::wxHtmlHelpController(int style)
45 {
46 m_helpFrame = NULL;
47 m_Config = NULL;
48 m_ConfigRoot = wxEmptyString;
49 m_titleFormat = _("Help: %s");
50 m_FrameStyle = style;
51 }
52
53 wxHtmlHelpController::~wxHtmlHelpController()
54 {
55 if (m_Config)
56 WriteCustomization(m_Config, m_ConfigRoot);
57 if (m_helpFrame)
58 DestroyHelpWindow();
59 }
60
61
62 void wxHtmlHelpController::DestroyHelpWindow()
63 {
64 //if (m_Config) WriteCustomization(m_Config, m_ConfigRoot);
65 if (m_helpFrame)
66 m_helpFrame->Destroy();
67 }
68
69 void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
70 {
71 evt.Skip();
72
73 OnQuit();
74
75 m_helpFrame->SetController((wxHelpControllerBase*) NULL);
76 m_helpFrame = NULL;
77 }
78
79 void wxHtmlHelpController::SetTitleFormat(const wxString& title)
80 {
81 m_titleFormat = title;
82 if (m_helpFrame)
83 m_helpFrame->SetTitleFormat(title);
84 }
85
86
87 bool wxHtmlHelpController::AddBook(const wxFileName& book_file, bool show_wait_msg)
88 {
89 return AddBook(wxFileSystem::FileNameToURL(book_file), show_wait_msg);
90 }
91
92 bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
93 {
94 wxBusyCursor cur;
95 #if wxUSE_BUSYINFO
96 wxBusyInfo* busy = NULL;
97 wxString info;
98 if (show_wait_msg)
99 {
100 info.Printf(_("Adding book %s"), book.c_str());
101 busy = new wxBusyInfo(info);
102 }
103 #endif
104 bool retval = m_helpData.AddBook(book);
105 #if wxUSE_BUSYINFO
106 if (show_wait_msg)
107 delete busy;
108 #endif
109 if (m_helpFrame)
110 m_helpFrame->RefreshLists();
111 return retval;
112 }
113
114
115
116 wxHtmlHelpFrame *wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
117 {
118 return new wxHtmlHelpFrame(data);
119 }
120
121
122 void wxHtmlHelpController::CreateHelpWindow()
123 {
124 if (m_helpFrame)
125 {
126 m_helpFrame->Raise();
127 return ;
128 }
129
130 if (m_Config == NULL)
131 {
132 m_Config = wxConfigBase::Get(FALSE);
133 if (m_Config != NULL)
134 m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
135 }
136
137 m_helpFrame = CreateHelpFrame(&m_helpData);
138 m_helpFrame->SetController(this);
139
140 if (m_Config)
141 m_helpFrame->UseConfig(m_Config, m_ConfigRoot);
142
143 m_helpFrame->Create(NULL, wxID_HTML_HELPFRAME, wxEmptyString, m_FrameStyle);
144 m_helpFrame->SetTitleFormat(m_titleFormat);
145 m_helpFrame->Show(TRUE);
146 }
147
148 void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path)
149 {
150 /* should not be called by the user; call UseConfig, and the controller
151 * will do the rest */
152 if (m_helpFrame && cfg)
153 m_helpFrame->ReadCustomization(cfg, path);
154 }
155
156 void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
157 {
158 /* typically called by the controllers OnCloseFrame handler */
159 if (m_helpFrame && cfg)
160 m_helpFrame->WriteCustomization(cfg, path);
161 }
162
163 void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
164 {
165 m_Config = config;
166 m_ConfigRoot = rootpath;
167 if (m_helpFrame) m_helpFrame->UseConfig(config, rootpath);
168 ReadCustomization(config, rootpath);
169 }
170
171 //// Backward compatibility with wxHelpController API
172
173 bool wxHtmlHelpController::Initialize(const wxString& file)
174 {
175 wxString dir, filename, ext;
176 wxSplitPath(file, & dir, & filename, & ext);
177
178 if (!dir.IsEmpty())
179 dir = dir + wxFILE_SEP_PATH;
180
181 // Try to find a suitable file
182 wxString actualFilename = dir + filename + wxString(wxT(".zip"));
183 if (!wxFileExists(actualFilename))
184 {
185 actualFilename = dir + filename + wxString(wxT(".htb"));
186 if (!wxFileExists(actualFilename))
187 {
188 actualFilename = dir + filename + wxString(wxT(".hhp"));
189 if (!wxFileExists(actualFilename))
190 return FALSE;
191 }
192 }
193
194 return AddBook(wxFileName(actualFilename));
195 }
196
197 bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
198 {
199 // Don't reload the file or we'll have it appear again, presumably.
200 return TRUE;
201 }
202
203 bool wxHtmlHelpController::DisplaySection(int sectionNo)
204 {
205 return Display(sectionNo);
206 }
207
208 bool wxHtmlHelpController::DisplayTextPopup(const wxString& text, const wxPoint& WXUNUSED(pos))
209 {
210 #if wxUSE_TIPWINDOW
211 static wxTipWindow* s_tipWindow = NULL;
212
213 if (s_tipWindow)
214 {
215 // Prevent s_tipWindow being nulled in OnIdle,
216 // thereby removing the chance for the window to be closed by ShowHelp
217 s_tipWindow->SetTipWindowPtr(NULL);
218 s_tipWindow->Close();
219 }
220 s_tipWindow = NULL;
221
222 if ( !text.empty() )
223 {
224 s_tipWindow = new wxTipWindow(wxTheApp->GetTopWindow(), text, 100, & s_tipWindow);
225
226 return TRUE;
227 }
228 #endif // wxUSE_TIPWINDOW
229
230 return FALSE;
231 }
232
233 void wxHtmlHelpController::SetFrameParameters(const wxString& title,
234 const wxSize& size,
235 const wxPoint& pos,
236 bool WXUNUSED(newFrameEachTime))
237 {
238 SetTitleFormat(title);
239 if (m_helpFrame)
240 {
241 m_helpFrame->SetSize(pos.x, pos.y, size.x, size.y);
242 }
243 }
244
245 wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size,
246 wxPoint *pos,
247 bool *newFrameEachTime)
248 {
249 if (newFrameEachTime)
250 (* newFrameEachTime) = FALSE;
251 if (size && m_helpFrame)
252 (* size) = m_helpFrame->GetSize();
253 if (pos && m_helpFrame)
254 (* pos) = m_helpFrame->GetPosition();
255 return m_helpFrame;
256 }
257
258 bool wxHtmlHelpController::Quit()
259 {
260 DestroyHelpWindow();
261 return TRUE;
262 }
263
264 // Make the help controller's frame 'modal' if
265 // needed
266 void wxHtmlHelpController::AddGrabIfNeeded()
267 {
268 // So far, wxGTK only
269 #ifdef __WXGTK__
270 bool needGrab = FALSE;
271
272 // Check if there are any modal windows present,
273 // in which case we need to add a grab.
274 for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
275 node;
276 node = node->GetNext() )
277 {
278 wxWindow *win = node->GetData();
279 wxDialog *dialog = wxDynamicCast(win, wxDialog);
280
281 if (dialog && dialog->IsModal())
282 needGrab = TRUE;
283 }
284
285 if (needGrab && m_helpFrame)
286 m_helpFrame->AddGrab();
287 #endif // __WXGTK__
288 }
289
290 bool wxHtmlHelpController::Display(const wxString& x)
291 {
292 CreateHelpWindow();
293 bool success = m_helpFrame->Display(x);
294 AddGrabIfNeeded();
295 return success;
296 }
297
298 bool wxHtmlHelpController::Display(int id)
299 {
300 CreateHelpWindow();
301 bool success = m_helpFrame->Display(id);
302 AddGrabIfNeeded();
303 return success;
304 }
305
306 bool wxHtmlHelpController::DisplayContents()
307 {
308 CreateHelpWindow();
309 bool success = m_helpFrame->DisplayContents();
310 AddGrabIfNeeded();
311 return success;
312 }
313
314 bool wxHtmlHelpController::DisplayIndex()
315 {
316 CreateHelpWindow();
317 bool success = m_helpFrame->DisplayIndex();
318 AddGrabIfNeeded();
319 return success;
320 }
321
322 bool wxHtmlHelpController::KeywordSearch(const wxString& keyword)
323 {
324 CreateHelpWindow();
325 bool success = m_helpFrame->KeywordSearch(keyword);
326 AddGrabIfNeeded();
327 return success;
328 }
329
330 #endif // wxUSE_WXHTML_HELP
331