Repository navigation
Expand file tree
/
Copy pathhelpctrl.cpp
More file actions
442 lines (383 loc) · 11.5 KB
/
Copy pathhelpctrl.cpp
File metadata and controls
442 lines (383 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
/////////////////////////////////////////////////////////////////////////////
// Name: helpctrl.cpp
// Purpose: wxHtmlHelpController
// Notes: Based on htmlhelp.cpp, implementing a monolithic
// HTML Help controller class, by Vaclav Slavik
// Author: Harm van der Heijden and Vaclav Slavik
// RCS-ID: $Id: helpctrl.cpp 52470 2008-03-13 23:29:27Z VS $
// Copyright: (c) Harm van der Heijden and Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#if wxUSE_WXHTML_HELP
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/intl.h"
#endif // WX_PRECOMP
#include "wx/busyinfo.h"
#include "wx/html/helpctrl.h"
#include "wx/html/helpwnd.h"
#include "wx/html/helpfrm.h"
#include "wx/html/helpdlg.h"
#if wxUSE_HELP
#include "wx/tipwin.h"
#endif
#if wxUSE_LIBMSPACK
#include "wx/html/forcelnk.h"
FORCE_LINK(wxhtml_chm_support)
#endif
IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpController, wxHelpControllerBase)
wxHtmlHelpController::wxHtmlHelpController(int style, wxWindow* parentWindow):
wxHelpControllerBase(parentWindow)
{
m_helpWindow = NULL;
m_helpFrame = NULL;
m_helpDialog = NULL;
m_Config = NULL;
m_ConfigRoot = wxEmptyString;
m_titleFormat = _("Help: %s");
m_FrameStyle = style;
}
wxHtmlHelpController::~wxHtmlHelpController()
{
if (m_Config)
WriteCustomization(m_Config, m_ConfigRoot);
if (m_helpWindow)
DestroyHelpWindow();
}
void wxHtmlHelpController::DestroyHelpWindow()
{
if (m_FrameStyle & wxHF_EMBEDDED)
return;
// Find top-most parent window
// If a modal dialog
wxWindow* parent = FindTopLevelWindow();
if (parent)
{
wxDialog* dialog = wxDynamicCast(parent, wxDialog);
if (dialog && dialog->IsModal())
{
dialog->EndModal(wxID_OK);
}
parent->Destroy();
m_helpWindow = NULL;
}
m_helpDialog = NULL;
m_helpFrame = NULL;
}
void wxHtmlHelpController::OnCloseFrame(wxCloseEvent& evt)
{
if (m_Config)
WriteCustomization(m_Config, m_ConfigRoot);
evt.Skip();
OnQuit();
if ( m_helpWindow )
m_helpWindow->SetController(NULL);
m_helpWindow = NULL;
m_helpDialog = NULL;
m_helpFrame = NULL;
}
void wxHtmlHelpController::SetTitleFormat(const wxString& title)
{
m_titleFormat = title;
wxHtmlHelpFrame* frame = wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame);
wxHtmlHelpDialog* dialog = wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog);
if (frame)
{
frame->SetTitleFormat(title);
}
else if (dialog)
dialog->SetTitleFormat(title);
}
// Find the top-most parent window
wxWindow* wxHtmlHelpController::FindTopLevelWindow()
{
wxWindow* parent = m_helpWindow;
while (parent && !parent->IsTopLevel())
{
parent = parent->GetParent();
}
return parent;
}
bool wxHtmlHelpController::AddBook(const wxFileName& book_file, bool show_wait_msg)
{
return AddBook(wxFileSystem::FileNameTourl(/sitelet?url=https%3A%2F%2Fgithub.com%2Fadrianer%2FwxPython%2Fblob%2Fmaster%2Fsrc%2Fhtml%2Fbook_file), show_wait_msg);
}
bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg)
{
wxBusyCursor cur;
#if wxUSE_BUSYINFO
wxBusyInfo* busy = NULL;
wxString info;
if (show_wait_msg)
{
info.Printf(_("Adding book %s"), book.c_str());
busy = new wxBusyInfo(info);
}
#endif
bool retval = m_helpData.AddBook(book);
#if wxUSE_BUSYINFO
if (show_wait_msg)
delete busy;
#else
wxUnusedVar(show_wait_msg);
#endif
if (m_helpWindow)
m_helpWindow->RefreshLists();
return retval;
}
wxHtmlHelpFrame* wxHtmlHelpController::CreateHelpFrame(wxHtmlHelpData *data)
{
wxHtmlHelpFrame* frame = new wxHtmlHelpFrame(data);
frame->SetController(this);
frame->Create(m_parentWindow, -1, wxEmptyString, m_FrameStyle, m_Config, m_ConfigRoot);
frame->SetTitleFormat(m_titleFormat);
m_helpFrame = frame;
return frame;
}
wxHtmlHelpDialog* wxHtmlHelpController::CreateHelpDialog(wxHtmlHelpData *data)
{
wxHtmlHelpDialog* dialog = new wxHtmlHelpDialog(data);
dialog->SetController(this);
dialog->SetTitleFormat(m_titleFormat);
dialog->Create(m_parentWindow, -1, wxEmptyString, m_FrameStyle);
m_helpDialog = dialog;
return dialog;
}
wxWindow* wxHtmlHelpController::CreateHelpWindow()
{
if (m_helpWindow)
{
if (m_FrameStyle & wxHF_EMBEDDED)
return m_helpWindow;
wxWindow* topLevelWindow = FindTopLevelWindow();
if (topLevelWindow)
topLevelWindow->Raise();
return m_helpWindow;
}
if (m_Config == NULL)
{
m_Config = wxConfigBase::Get(false);
if (m_Config != NULL)
m_ConfigRoot = _T("wxWindows/wxHtmlHelpController");
}
if (m_FrameStyle & wxHF_DIALOG)
{
wxHtmlHelpDialog* dialog = CreateHelpDialog(&m_helpData);
m_helpWindow = dialog->GetHelpWindow();
}
else if ((m_FrameStyle & wxHF_EMBEDDED) && m_parentWindow)
{
m_helpWindow = new wxHtmlHelpWindow(m_parentWindow, -1, wxDefaultPosition, wxDefaultSize,
wxTAB_TRAVERSAL|wxNO_BORDER, m_FrameStyle, &m_helpData);
}
else // wxHF_FRAME
{
wxHtmlHelpFrame* frame = CreateHelpFrame(&m_helpData);
m_helpWindow = frame->GetHelpWindow();
frame->Show(true);
}
return m_helpWindow;
}
void wxHtmlHelpController::ReadCustomization(wxConfigBase* cfg, const wxString& path)
{
/* should not be called by the user; call UseConfig, and the controller
* will do the rest */
if (m_helpWindow && cfg)
m_helpWindow->ReadCustomization(cfg, path);
}
void wxHtmlHelpController::WriteCustomization(wxConfigBase* cfg, const wxString& path)
{
/* typically called by the controllers OnCloseFrame handler */
if (m_helpWindow && cfg)
m_helpWindow->WriteCustomization(cfg, path);
}
void wxHtmlHelpController::UseConfig(wxConfigBase *config, const wxString& rootpath)
{
m_Config = config;
m_ConfigRoot = rootpath;
if (m_helpWindow) m_helpWindow->UseConfig(config, rootpath);
ReadCustomization(config, rootpath);
}
//// Backward compatibility with wxHelpController API
bool wxHtmlHelpController::Initialize(const wxString& file)
{
wxString dir, filename, ext;
wxSplitPath(file, & dir, & filename, & ext);
if (!dir.empty())
dir = dir + wxFILE_SEP_PATH;
// Try to find a suitable file
wxString actualFilename = dir + filename + wxString(wxT(".zip"));
if (!wxFileExists(actualFilename))
{
actualFilename = dir + filename + wxString(wxT(".htb"));
if (!wxFileExists(actualFilename))
{
actualFilename = dir + filename + wxString(wxT(".hhp"));
if (!wxFileExists(actualFilename))
{
#if wxUSE_LIBMSPACK
actualFilename = dir + filename + wxString(wxT(".chm"));
if (!wxFileExists(actualFilename))
#endif
return false;
}
}
}
return AddBook(wxFileName(actualFilename));
}
bool wxHtmlHelpController::LoadFile(const wxString& WXUNUSED(file))
{
// Don't reload the file or we'll have it appear again, presumably.
return true;
}
bool wxHtmlHelpController::DisplaySection(int sectionNo)
{
return Display(sectionNo);
}
bool wxHtmlHelpController::DisplayTextPopup(const wxString& text, const wxPoint& WXUNUSED(pos))
{
#if wxUSE_TIPWINDOW
static wxTipWindow* s_tipWindow = NULL;
if (s_tipWindow)
{
// Prevent s_tipWindow being nulled in OnIdle,
// thereby removing the chance for the window to be closed by ShowHelp
s_tipWindow->SetTipWindowPtr(NULL);
s_tipWindow->Close();
}
s_tipWindow = NULL;
if ( !text.empty() )
{
s_tipWindow = new wxTipWindow(wxTheApp->GetTopWindow(), text, 100, & s_tipWindow);
return true;
}
#else
wxUnusedVar(text);
#endif // wxUSE_TIPWINDOW
return false;
}
void wxHtmlHelpController::SetHelpWindow(wxHtmlHelpWindow* helpWindow)
{
m_helpWindow = helpWindow;
if (helpWindow)
helpWindow->SetController(this);
}
void wxHtmlHelpController::SetFrameParameters(const wxString& title,
const wxSize& size,
const wxPoint& pos,
bool WXUNUSED(newFrameEachTime))
{
SetTitleFormat(title);
wxHtmlHelpFrame* frame = wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame);
wxHtmlHelpDialog* dialog = wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog);
if (frame)
frame->SetSize(pos.x, pos.y, size.x, size.y);
else if (dialog)
dialog->SetSize(pos.x, pos.y, size.x, size.y);
}
wxFrame* wxHtmlHelpController::GetFrameParameters(wxSize *size,
wxPoint *pos,
bool *newFrameEachTime)
{
if (newFrameEachTime)
(* newFrameEachTime) = false;
wxHtmlHelpFrame* frame = wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame);
wxHtmlHelpDialog* dialog = wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog);
if (frame)
{
if (size)
(* size) = frame->GetSize();
if (pos)
(* pos) = frame->GetPosition();
return frame;
}
else if (dialog)
{
if (size)
(* size) = dialog->GetSize();
if (pos)
(* pos) = dialog->GetPosition();
return NULL;
}
return NULL;
}
bool wxHtmlHelpController::Quit()
{
DestroyHelpWindow();
return true;
}
// Make the help controller's frame 'modal' if
// needed
void wxHtmlHelpController::MakeModalIfNeeded()
{
if ((m_FrameStyle & wxHF_EMBEDDED) == 0)
{
wxHtmlHelpFrame* frame = wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpFrame);
wxHtmlHelpDialog* dialog = wxDynamicCast(FindTopLevelWindow(), wxHtmlHelpDialog);
if (frame)
frame->AddGrabIfNeeded();
else if (dialog && (m_FrameStyle & wxHF_MODAL))
{
dialog->ShowModal();
}
}
}
bool wxHtmlHelpController::Display(const wxString& x)
{
CreateHelpWindow();
bool success = m_helpWindow->Display(x);
MakeModalIfNeeded();
return success;
}
bool wxHtmlHelpController::Display(int id)
{
CreateHelpWindow();
bool success = m_helpWindow->Display(id);
MakeModalIfNeeded();
return success;
}
bool wxHtmlHelpController::DisplayContents()
{
CreateHelpWindow();
bool success = m_helpWindow->DisplayContents();
MakeModalIfNeeded();
return success;
}
bool wxHtmlHelpController::DisplayIndex()
{
CreateHelpWindow();
bool success = m_helpWindow->DisplayIndex();
MakeModalIfNeeded();
return success;
}
bool wxHtmlHelpController::KeywordSearch(const wxString& keyword,
wxHelpSearchMode mode)
{
CreateHelpWindow();
bool success = m_helpWindow->KeywordSearch(keyword, mode);
MakeModalIfNeeded();
return success;
}
/*
* wxHtmlModalHelp
* A convenience class, to use like this:
*
* wxHtmlModalHelp help(parent, helpFile, topic);
*/
wxHtmlModalHelp::wxHtmlModalHelp(wxWindow* parent, const wxString& helpFile, const wxString& topic, int style)
{
// Force some mandatory styles
style |= wxHF_DIALOG | wxHF_MODAL;
wxHtmlHelpController controller(style, parent);
controller.Initialize(helpFile);
if (topic.IsEmpty())
controller.DisplayContents();
else
controller.DisplaySection(topic);
}
#endif // wxUSE_WXHTML_HELP