]> git.saurik.com Git - wxWidgets.git/blame - src/html/helpfrm.cpp
fixed path to wx/debugrpt.h header (had extra include subdir)
[wxWidgets.git] / src / html / helpfrm.cpp
CommitLineData
8ec2b484
HH
1/////////////////////////////////////////////////////////////////////////////
2// Name: helpfrm.cpp
3// Purpose: wxHtmlHelpFrame
d5bb85a0 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 8// Copyright: (c) Harm van der Heijden and Vaclav Slavik
65571936 9// Licence: wxWindows licence
8ec2b484
HH
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
1aedb1dd 13#pragma implementation "helpfrm.h"
8ec2b484
HH
14#endif
15
c32bfc10
VS
16// For compilers that support precompilation, includes "wx.h"
17
8ec2b484
HH
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
3379ed37 24#if wxUSE_WXHTML_HELP
07b8d7ec 25
8ec2b484 26#ifndef WXPRECOMP
07b8d7ec
VZ
27 #include "wx/intl.h"
28 #include "wx/log.h"
29
30 #include "wx/object.h"
07b8d7ec
VZ
31 #include "wx/sizer.h"
32
33 #include "wx/bmpbuttn.h"
34 #include "wx/statbox.h"
35 #include "wx/radiobox.h"
36#endif // WXPRECOMP
8ec2b484 37
c718e0b3
SC
38#ifdef __WXMAC__
39 #include "wx/menu.h"
40 #include "wx/msgdlg.h"
41#endif
42
8ec2b484 43#include "wx/html/helpfrm.h"
b4414c1f 44#include "wx/html/helpctrl.h"
618a5e38 45#include "wx/textctrl.h"
8ec2b484
HH
46#include "wx/notebook.h"
47#include "wx/imaglist.h"
48#include "wx/treectrl.h"
49#include "wx/tokenzr.h"
50#include "wx/wfstream.h"
51#include "wx/html/htmlwin.h"
52#include "wx/busyinfo.h"
53#include "wx/progdlg.h"
2bd5bbc9 54#include "wx/toolbar.h"
83efdf33 55#include "wx/fontenum.h"
0646614d
VS
56#include "wx/stream.h"
57#include "wx/filedlg.h"
f435c1f0 58#include "wx/artprov.h"
c269cf62 59#include "wx/spinctrl.h"
91fa114d
VS
60#include "wx/dynarray.h"
61#include "wx/choicdlg.h"
bfa7fb52 62#include "wx/settings.h"
8ec2b484 63
f0b6a33f
VS
64// what is considered "small index"?
65#define INDEX_IS_SMALL 100
66
9806a47c
JS
67/* Motif defines this as a macro */
68#ifdef Below
69#undef Below
70#endif
f0b6a33f 71
8ec2b484 72//--------------------------------------------------------------------------
382e6efe 73// wxHtmlHelpTreeItemData (private)
8ec2b484
HH
74//--------------------------------------------------------------------------
75
76class wxHtmlHelpTreeItemData : public wxTreeItemData
77{
0646614d 78 public:
da4cc40c
DW
79#if defined(__VISAGECPP__)
80// VA needs a default ctor for some reason....
81 wxHtmlHelpTreeItemData() : wxTreeItemData()
82 { m_Id = 0; }
83#endif
0646614d
VS
84 wxHtmlHelpTreeItemData(int id) : wxTreeItemData()
85 { m_Id = id;}
86
87 int m_Id;
88};
8ec2b484 89
0646614d
VS
90
91//--------------------------------------------------------------------------
92// wxHtmlHelpHashData (private)
93//--------------------------------------------------------------------------
94
95class wxHtmlHelpHashData : public wxObject
96{
8ec2b484 97 public:
0646614d
VS
98 wxHtmlHelpHashData(int index, wxTreeItemId id) : wxObject()
99 { m_Index = index; m_Id = id;}
f5ba273e 100 ~wxHtmlHelpHashData() {}
f6bcfd97 101
0646614d
VS
102 int m_Index;
103 wxTreeItemId m_Id;
8ec2b484
HH
104};
105
382e6efe 106
0646614d
VS
107//--------------------------------------------------------------------------
108// wxHtmlHelpHtmlWindow (private)
109//--------------------------------------------------------------------------
110
111class wxHtmlHelpHtmlWindow : public wxHtmlWindow
112{
113 public:
bfa7fb52
VS
114 wxHtmlHelpHtmlWindow(wxHtmlHelpFrame *fr, wxWindow *parent)
115 : wxHtmlWindow(parent), m_Frame(fr)
116 {
117 SetStandardFonts();
118 }
0646614d
VS
119
120 virtual void OnLinkClicked(const wxHtmlLinkInfo& link)
121 {
122 wxHtmlWindow::OnLinkClicked(link);
adf2eb2d
VS
123 const wxMouseEvent *e = link.GetEvent();
124 if (e == NULL || e->LeftUp())
125 m_Frame->NotifyPageChanged();
0646614d
VS
126 }
127
f6bcfd97 128 private:
0646614d 129 wxHtmlHelpFrame *m_Frame;
22f3361e
VZ
130
131 DECLARE_NO_COPY_CLASS(wxHtmlHelpHtmlWindow)
0646614d
VS
132};
133
382e6efe 134
91fa114d
VS
135//---------------------------------------------------------------------------
136// wxHtmlHelpFrame::m_mergedIndex
137//---------------------------------------------------------------------------
138
69b69d5a 139WX_DEFINE_ARRAY_PTR(const wxHtmlHelpDataItem*, wxHtmlHelpDataItemPtrArray);
91fa114d
VS
140
141struct wxHtmlHelpMergedIndexItem
142{
143 wxHtmlHelpMergedIndexItem *parent;
144 wxString name;
145 wxHtmlHelpDataItemPtrArray items;
146};
147
148WX_DECLARE_OBJARRAY(wxHtmlHelpMergedIndexItem, wxHtmlHelpMergedIndex);
149#include "wx/arrimpl.cpp"
150WX_DEFINE_OBJARRAY(wxHtmlHelpMergedIndex)
151
152void wxHtmlHelpFrame::UpdateMergedIndex()
153{
154 delete m_mergedIndex;
155 m_mergedIndex = new wxHtmlHelpMergedIndex;
156 wxHtmlHelpMergedIndex& merged = *m_mergedIndex;
157
158 const wxHtmlHelpDataItems& items = m_Data->GetIndexArray();
159 size_t len = items.size();
160
161 wxHtmlHelpMergedIndexItem *history[128] = {NULL};
d1da8872 162
91fa114d
VS
163 for (size_t i = 0; i < len; i++)
164 {
165 const wxHtmlHelpDataItem& item = items[i];
166 wxASSERT_MSG( item.level < 128, _T("nested index entries too deep") );
d1da8872 167
91fa114d
VS
168 if (history[item.level] &&
169 history[item.level]->items[0]->name == item.name)
170 {
171 // same index entry as previous one, update list of items
172 history[item.level]->items.Add(&item);
173 }
174 else
175 {
176 // new index entry
177 wxHtmlHelpMergedIndexItem *mi = new wxHtmlHelpMergedIndexItem();
178 mi->name = item.GetIndentedName();
179 mi->items.Add(&item);
180 mi->parent = (item.level == 0) ? NULL : history[item.level - 1];
181 history[item.level] = mi;
182 merged.Add(mi);
d1da8872 183 }
91fa114d
VS
184 }
185}
d1da8872 186
382e6efe 187
8ec2b484
HH
188//---------------------------------------------------------------------------
189// wxHtmlHelpFrame
190//---------------------------------------------------------------------------
191
576507e2
VS
192// Command IDs :
193enum
194{
195 //wxID_HTML_HELPFRAME = wxID_HIGHEST + 1,
196 wxID_HTML_PANEL = wxID_HIGHEST + 2,
197 wxID_HTML_BACK,
198 wxID_HTML_FORWARD,
199 wxID_HTML_UPNODE,
200 wxID_HTML_UP,
201 wxID_HTML_DOWN,
202 wxID_HTML_PRINT,
203 wxID_HTML_OPENFILE,
204 wxID_HTML_OPTIONS,
205 wxID_HTML_BOOKMARKSLIST,
206 wxID_HTML_BOOKMARKSADD,
207 wxID_HTML_BOOKMARKSREMOVE,
208 wxID_HTML_TREECTRL,
209 wxID_HTML_INDEXPAGE,
210 wxID_HTML_INDEXLIST,
211 wxID_HTML_INDEXTEXT,
212 wxID_HTML_INDEXBUTTON,
213 wxID_HTML_INDEXBUTTONALL,
214 wxID_HTML_NOTEBOOK,
215 wxID_HTML_SEARCHPAGE,
216 wxID_HTML_SEARCHTEXT,
217 wxID_HTML_SEARCHLIST,
218 wxID_HTML_SEARCHBUTTON,
219 wxID_HTML_SEARCHCHOICE,
220 wxID_HTML_COUNTINFO
221};
222
223
8ec2b484
HH
224IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame)
225
226wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title,
d5bb85a0 227 int style, wxHtmlHelpData* data)
8ec2b484
HH
228{
229 Init(data);
230 Create(parent, id, title, style);
231}
d5bb85a0 232
8ec2b484
HH
233void wxHtmlHelpFrame::Init(wxHtmlHelpData* data)
234{
da4cc40c 235 if (data)
4f9297b0 236 {
d5bb85a0 237 m_Data = data;
dabbc6a5 238 m_DataCreated = false;
da4cc40c 239 } else
4f9297b0 240 {
d5bb85a0 241 m_Data = new wxHtmlHelpData();
dabbc6a5 242 m_DataCreated = true;
8ec2b484
HH
243 }
244
8ec2b484 245 m_ContentsBox = NULL;
f0b6a33f
VS
246 m_IndexList = NULL;
247 m_IndexButton = NULL;
248 m_IndexButtonAll = NULL;
249 m_IndexText = NULL;
8ec2b484
HH
250 m_SearchList = NULL;
251 m_SearchButton = NULL;
252 m_SearchText = NULL;
253 m_SearchChoice = NULL;
240c2873 254 m_IndexCountInfo = NULL;
8ec2b484
HH
255 m_Splitter = NULL;
256 m_NavigPan = NULL;
5229b11d 257 m_NavigNotebook = NULL;
8ec2b484 258 m_HtmlWin = NULL;
382e6efe 259 m_Bookmarks = NULL;
c4971147
VS
260 m_SearchCaseSensitive = NULL;
261 m_SearchWholeWords = NULL;
262
91fa114d
VS
263 m_mergedIndex = NULL;
264
8ec2b484
HH
265 m_Config = NULL;
266 m_ConfigRoot = wxEmptyString;
267
268 m_Cfg.x = m_Cfg.y = 0;
d5bb85a0
VS
269 m_Cfg.w = 700;
270 m_Cfg.h = 480;
8ec2b484 271 m_Cfg.sashpos = 240;
dabbc6a5 272 m_Cfg.navig_on = true;
83efdf33
VS
273
274 m_NormalFonts = m_FixedFonts = NULL;
83efdf33 275 m_NormalFace = m_FixedFace = wxEmptyString;
c269cf62
VS
276#ifdef __WXMSW__
277 m_FontSize = 10;
278#else
279 m_FontSize = 14;
280#endif
f6bcfd97 281
0646614d
VS
282#if wxUSE_PRINTING_ARCHITECTURE
283 m_Printer = NULL;
284#endif
285
286 m_PagesHash = NULL;
dabbc6a5 287 m_UpdateContents = true;
b4414c1f 288 m_helpController = (wxHelpControllerBase*) NULL;
8ec2b484
HH
289}
290
d5bb85a0
VS
291// Create: builds the GUI components.
292// with the style flag it's possible to toggle the toolbar, contents, index and search
293// controls.
294// m_HtmlWin will *always* be created, but it's important to realize that
f0b6a33f 295// m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
d5bb85a0
VS
296// m_SearchButton may be NULL.
297// moreover, if no contents, index or searchpage is needed, m_Splitter and
298// m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
299
3379ed37 300bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id,
576507e2 301 const wxString& WXUNUSED(title), int style)
8ec2b484 302{
576507e2
VS
303 m_hfStyle = style;
304
8fd2b35c 305 wxImageList *ContentsImageList = new wxImageList(16, 16);
1dfab6bb
VS
306 ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK,
307 wxART_HELP_BROWSER,
308 wxSize(16, 16)));
309 ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER,
310 wxART_HELP_BROWSER,
311 wxSize(16, 16)));
312 ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE,
313 wxART_HELP_BROWSER,
314 wxSize(16, 16)));
8fd2b35c 315
8ec2b484
HH
316 // Do the config in two steps. We read the HtmlWindow customization after we
317 // create the window.
d5bb85a0
VS
318 if (m_Config)
319 ReadCustomization(m_Config, m_ConfigRoot);
8ec2b484 320
dabbc6a5
DS
321 wxFrame::Create(parent, id, _("Help"),
322 wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h),
5229b11d 323 wxDEFAULT_FRAME_STYLE, wxT("wxHtmlHelp"));
8ec2b484 324
5c172c17
VS
325 GetPosition(&m_Cfg.x, &m_Cfg.y);
326
79683a13 327 SetIcon(wxArtProvider::GetIcon(wxART_HELP, wxART_HELP_BROWSER));
9ffdee80 328
d9b21c9f
JS
329 // On the Mac, each modeless frame must have a menubar.
330 // TODO: add more menu items, and perhaps add a style to show
331 // the menubar: compulsory on the Mac, optional elsewhere.
332#ifdef __WXMAC__
333 wxMenuBar* menuBar = new wxMenuBar;
334
335 wxMenu* fileMenu = new wxMenu;
336 fileMenu->Append(wxID_HTML_OPENFILE, _("&Open..."));
d9b21c9f
JS
337 fileMenu->AppendSeparator();
338 fileMenu->Append(wxID_CLOSE, _("&Close"));
339
b05206c9
JS
340 wxMenu* helpMenu = new wxMenu;
341 helpMenu->Append(wxID_ABOUT, _("&About..."));
322a5b45
JS
342 // Ensures we don't get an empty help menu
343 helpMenu->Append(wxID_HELP_CONTENTS, _("&About..."));
d9b21c9f 344
c3eeb758
RD
345 menuBar->Append(fileMenu,_("&File"));
346 menuBar->Append(helpMenu,_("&Help"));
d9b21c9f
JS
347 SetMenuBar(menuBar);
348#endif
349
8ec2b484
HH
350 int notebook_page = 0;
351
67a99992 352#if wxUSE_STATUSBAR
8ec2b484 353 CreateStatusBar();
67a99992 354#endif // wxUSE_STATUSBAR
8ec2b484 355
ee2f6a93 356#if wxUSE_TOOLBAR
8ec2b484 357 // toolbar?
576507e2 358 if (style & (wxHF_TOOLBAR | wxHF_FLAT_TOOLBAR))
4f9297b0 359 {
f6bcfd97
BP
360 wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL |
361 wxTB_DOCKABLE |
576507e2 362 (style & wxHF_FLAT_TOOLBAR ? wxTB_FLAT : 0));
00655497 363 toolBar->SetMargins( 2, 2 );
b854b7b8 364 AddToolbarButtons(toolBar, style);
4f9297b0 365 toolBar->Realize();
8ec2b484 366 }
ee2f6a93 367#endif //wxUSE_TOOLBAR
d5bb85a0 368
5229b11d
VS
369 wxSizer *navigSizer = NULL;
370
da4cc40c 371 if (style & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH))
4f9297b0 372 {
d5bb85a0
VS
373 // traditional help controller; splitter window with html page on the
374 // right and a notebook containing various pages on the left
375 m_Splitter = new wxSplitterWindow(this);
376
0646614d 377 m_HtmlWin = new wxHtmlHelpHtmlWindow(this, m_Splitter);
dabbc6a5 378 m_NavigPan = new wxPanel(m_Splitter, wxID_ANY);
5229b11d
VS
379 m_NavigNotebook = new wxNotebook(m_NavigPan, wxID_HTML_NOTEBOOK,
380 wxDefaultPosition, wxDefaultSize);
dabbc6a5 381
5229b11d 382 navigSizer = new wxBoxSizer(wxVERTICAL);
adbf2d73 383 navigSizer->Add(m_NavigNotebook, 1, wxEXPAND);
5229b11d 384
5229b11d 385 m_NavigPan->SetSizer(navigSizer);
da4cc40c
DW
386 }
387 else
4f9297b0 388 { // only html window, no notebook with index,contents etc
d5bb85a0 389 m_HtmlWin = new wxHtmlWindow(this);
8ec2b484
HH
390 }
391
4f9297b0 392 m_HtmlWin->SetRelatedFrame(this, m_TitleFormat);
67a99992 393#if wxUSE_STATUSBAR
4f9297b0 394 m_HtmlWin->SetRelatedStatusBar(0);
67a99992 395#endif // wxUSE_STATUSBAR
5229b11d 396 if ( m_Config )
4f9297b0 397 m_HtmlWin->ReadCustomization(m_Config, m_ConfigRoot);
8ec2b484
HH
398
399 // contents tree panel?
5229b11d 400 if ( style & wxHF_CONTENTS )
4f9297b0 401 {
5229b11d
VS
402 wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE);
403 wxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
dabbc6a5 404
5229b11d 405 topsizer->Add(0, 10);
dabbc6a5 406
5229b11d
VS
407 dummy->SetSizer(topsizer);
408
5229b11d 409 if ( style & wxHF_BOOKMARKS )
3379ed37 410 {
dabbc6a5 411 m_Bookmarks = new wxComboBox(dummy, wxID_HTML_BOOKMARKSLIST,
5229b11d 412 wxEmptyString,
dabbc6a5 413 wxDefaultPosition, wxDefaultSize,
5229b11d 414 0, NULL, wxCB_READONLY | wxCB_SORT);
4f9297b0 415 m_Bookmarks->Append(_("(bookmarks)"));
ae80f837 416 for (unsigned i = 0; i < m_BookmarksNames.GetCount(); i++)
4f9297b0
VS
417 m_Bookmarks->Append(m_BookmarksNames[i]);
418 m_Bookmarks->SetSelection(0);
ae80f837 419
5229b11d 420 wxBitmapButton *bmpbt1, *bmpbt2;
dabbc6a5
DS
421 bmpbt1 = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSADD,
422 wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK,
61ba12f0 423 wxART_BUTTON));
dabbc6a5
DS
424 bmpbt2 = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSREMOVE,
425 wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK,
61ba12f0 426 wxART_BUTTON));
5229b11d
VS
427#if wxUSE_TOOLTIPS
428 bmpbt1->SetToolTip(_("Add current page to bookmarks"));
429 bmpbt2->SetToolTip(_("Remove current page from bookmarks"));
430#endif // wxUSE_TOOLTIPS
431
432 wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
dabbc6a5 433
f435c1f0
VS
434 sizer->Add(m_Bookmarks, 1, wxALIGN_CENTRE_VERTICAL | wxRIGHT, 5);
435 sizer->Add(bmpbt1, 0, wxALIGN_CENTRE_VERTICAL | wxRIGHT, 2);
436 sizer->Add(bmpbt2, 0, wxALIGN_CENTRE_VERTICAL, 0);
dabbc6a5 437
5229b11d 438 topsizer->Add(sizer, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, 10);
ae80f837
VS
439 }
440
5229b11d
VS
441 m_ContentsBox = new wxTreeCtrl(dummy, wxID_HTML_TREECTRL,
442 wxDefaultPosition, wxDefaultSize,
8fbc9912 443#ifdef __WXGTK20__
dabbc6a5 444 wxSUNKEN_BORDER |
e0952648 445 wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT |
8fbc9912
RR
446 wxTR_NO_LINES
447#else
448 wxSUNKEN_BORDER |
449 wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT |
450 wxTR_LINES_AT_ROOT
451#endif
452 );
e0952648 453
5229b11d 454 m_ContentsBox->AssignImageList(ContentsImageList);
dabbc6a5 455
d49520c3 456 topsizer->Add(m_ContentsBox, 1,
395a82b1 457 wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT,
d49520c3 458 2);
ae80f837 459
5229b11d 460 m_NavigNotebook->AddPage(dummy, _("Contents"));
d5bb85a0 461 m_ContentsPage = notebook_page++;
8ec2b484
HH
462 }
463
464 // index listbox panel?
5229b11d 465 if ( style & wxHF_INDEX )
4f9297b0 466 {
dabbc6a5 467 wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE);
5229b11d
VS
468 wxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
469
5229b11d
VS
470 dummy->SetSizer(topsizer);
471
dabbc6a5
DS
472 m_IndexText = new wxTextCtrl(dummy, wxID_HTML_INDEXTEXT, wxEmptyString,
473 wxDefaultPosition, wxDefaultSize,
5229b11d 474 wxTE_PROCESS_ENTER);
f0b6a33f 475 m_IndexButton = new wxButton(dummy, wxID_HTML_INDEXBUTTON, _("Find"));
dabbc6a5 476 m_IndexButtonAll = new wxButton(dummy, wxID_HTML_INDEXBUTTONALL,
5229b11d 477 _("Show all"));
dabbc6a5 478 m_IndexCountInfo = new wxStaticText(dummy, wxID_HTML_COUNTINFO,
5229b11d 479 wxEmptyString, wxDefaultPosition,
dabbc6a5 480 wxDefaultSize,
5229b11d 481 wxALIGN_RIGHT | wxST_NO_AUTORESIZE);
dabbc6a5
DS
482 m_IndexList = new wxListBox(dummy, wxID_HTML_INDEXLIST,
483 wxDefaultPosition, wxDefaultSize,
5229b11d 484 0, NULL, wxLB_SINGLE);
f0b6a33f 485
7618e374 486#if wxUSE_TOOLTIPS
4f9297b0 487 m_IndexButton->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
5229b11d 488 m_IndexButtonAll->SetToolTip(_("Show all items in index"));
7618e374
VS
489#endif //wxUSE_TOOLTIPS
490
5229b11d
VS
491 topsizer->Add(m_IndexText, 0, wxEXPAND | wxALL, 10);
492 wxSizer *btsizer = new wxBoxSizer(wxHORIZONTAL);
493 btsizer->Add(m_IndexButton, 0, wxRIGHT, 2);
494 btsizer->Add(m_IndexButtonAll);
dabbc6a5 495 topsizer->Add(btsizer, 0,
5229b11d
VS
496 wxALIGN_RIGHT | wxLEFT | wxRIGHT | wxBOTTOM, 10);
497 topsizer->Add(m_IndexCountInfo, 0, wxEXPAND | wxLEFT | wxRIGHT, 2);
395a82b1 498 topsizer->Add(m_IndexList, 1, wxEXPAND | wxALL, 2);
f0b6a33f 499
5229b11d 500 m_NavigNotebook->AddPage(dummy, _("Index"));
d5bb85a0 501 m_IndexPage = notebook_page++;
8ec2b484
HH
502 }
503
504 // search list panel?
5229b11d 505 if ( style & wxHF_SEARCH )
4f9297b0 506 {
dabbc6a5 507 wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE);
5229b11d 508 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
c4971147 509
5229b11d
VS
510 dummy->SetSizer(sizer);
511
dabbc6a5
DS
512 m_SearchText = new wxTextCtrl(dummy, wxID_HTML_SEARCHTEXT,
513 wxEmptyString,
514 wxDefaultPosition, wxDefaultSize,
5229b11d 515 wxTE_PROCESS_ENTER);
dabbc6a5 516 m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE,
13304c1b 517 wxDefaultPosition, wxSize(125,-1));
dabbc6a5
DS
518 m_SearchCaseSensitive = new wxCheckBox(dummy, wxID_ANY, _("Case sensitive"));
519 m_SearchWholeWords = new wxCheckBox(dummy, wxID_ANY, _("Whole words only"));
ae80f837
VS
520 m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search"));
521#if wxUSE_TOOLTIPS
4f9297b0 522 m_SearchButton->SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
ae80f837 523#endif //wxUSE_TOOLTIPS
dabbc6a5
DS
524 m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST,
525 wxDefaultPosition, wxDefaultSize,
5229b11d 526 0, NULL, wxLB_SINGLE);
dabbc6a5 527
5229b11d
VS
528 sizer->Add(m_SearchText, 0, wxEXPAND | wxALL, 10);
529 sizer->Add(m_SearchChoice, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
530 sizer->Add(m_SearchCaseSensitive, 0, wxLEFT | wxRIGHT, 10);
531 sizer->Add(m_SearchWholeWords, 0, wxLEFT | wxRIGHT, 10);
532 sizer->Add(m_SearchButton, 0, wxALL | wxALIGN_RIGHT, 8);
395a82b1 533 sizer->Add(m_SearchList, 1, wxALL | wxEXPAND, 2);
5229b11d
VS
534
535 m_NavigNotebook->AddPage(dummy, _("Search"));
999836aa 536 m_SearchPage = notebook_page;
8ec2b484 537 }
5229b11d 538
dabbc6a5 539 m_HtmlWin->Show();
f6bcfd97 540
b5a7b000 541 RefreshLists();
8ec2b484 542
5229b11d
VS
543 if ( navigSizer )
544 {
d49520c3 545 navigSizer->SetSizeHints(m_NavigPan);
5229b11d
VS
546 m_NavigPan->Layout();
547 }
548
8ec2b484 549 // showtime
5229b11d 550 if ( m_NavigPan && m_Splitter )
4f9297b0
VS
551 {
552 m_Splitter->SetMinimumPaneSize(20);
5229b11d 553 if ( m_Cfg.navig_on )
4f9297b0 554 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
4f9297b0 555
5229b11d 556 if ( m_Cfg.navig_on )
3379ed37 557 {
dabbc6a5 558 m_NavigPan->Show();
4f9297b0 559 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
c32bfc10 560 }
da4cc40c 561 else
3379ed37 562 {
dabbc6a5 563 m_NavigPan->Show(false);
4f9297b0 564 m_Splitter->Initialize(m_HtmlWin);
68364659 565 }
8ec2b484 566 }
dabbc6a5 567
7e521b01
JS
568 // Reduce flicker by updating the splitter pane sizes before the
569 // frame is shown
570 wxSizeEvent sizeEvent(GetSize(), GetId());
571 ProcessEvent(sizeEvent);
dabbc6a5 572
7e521b01 573 m_Splitter->UpdateSize();
dabbc6a5
DS
574
575 return true;
8ec2b484
HH
576}
577
578wxHtmlHelpFrame::~wxHtmlHelpFrame()
579{
418b7d6b 580 delete m_mergedIndex;
d1da8872 581
b4414c1f 582 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
8ec2b484 583 if (m_DataCreated)
d5bb85a0 584 delete m_Data;
83efdf33
VS
585 if (m_NormalFonts) delete m_NormalFonts;
586 if (m_FixedFonts) delete m_FixedFonts;
dabbc6a5 587 if (m_PagesHash)
ba8c1601
MB
588 {
589 WX_CLEAR_HASH_TABLE(*m_PagesHash);
590 delete m_PagesHash;
591 }
6c24d95c
VS
592#if wxUSE_PRINTING_ARCHITECTURE
593 if (m_Printer) delete m_Printer;
594#endif
8ec2b484
HH
595}
596
b854b7b8 597
ee2f6a93 598#if wxUSE_TOOLBAR
b854b7b8
VS
599void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar *toolBar, int style)
600{
dabbc6a5 601 wxBitmap wpanelBitmap =
61ba12f0 602 wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL, wxART_TOOLBAR);
dabbc6a5 603 wxBitmap wbackBitmap =
61ba12f0 604 wxArtProvider::GetBitmap(wxART_GO_BACK, wxART_TOOLBAR);
dabbc6a5 605 wxBitmap wforwardBitmap =
61ba12f0 606 wxArtProvider::GetBitmap(wxART_GO_FORWARD, wxART_TOOLBAR);
dabbc6a5 607 wxBitmap wupnodeBitmap =
61ba12f0 608 wxArtProvider::GetBitmap(wxART_GO_TO_PARENT, wxART_TOOLBAR);
dabbc6a5 609 wxBitmap wupBitmap =
61ba12f0 610 wxArtProvider::GetBitmap(wxART_GO_UP, wxART_TOOLBAR);
dabbc6a5 611 wxBitmap wdownBitmap =
61ba12f0 612 wxArtProvider::GetBitmap(wxART_GO_DOWN, wxART_TOOLBAR);
dabbc6a5 613 wxBitmap wopenBitmap =
61ba12f0 614 wxArtProvider::GetBitmap(wxART_FILE_OPEN, wxART_TOOLBAR);
dabbc6a5 615 wxBitmap wprintBitmap =
61ba12f0 616 wxArtProvider::GetBitmap(wxART_PRINT, wxART_TOOLBAR);
dabbc6a5 617 wxBitmap woptionsBitmap =
61ba12f0 618 wxArtProvider::GetBitmap(wxART_HELP_SETTINGS, wxART_TOOLBAR);
f6bcfd97
BP
619
620 wxASSERT_MSG( (wpanelBitmap.Ok() && wbackBitmap.Ok() &&
621 wforwardBitmap.Ok() && wupnodeBitmap.Ok() &&
622 wupBitmap.Ok() && wdownBitmap.Ok() &&
623 wopenBitmap.Ok() && wprintBitmap.Ok() &&
624 woptionsBitmap.Ok()),
625 wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
626
627
4f9297b0 628 toolBar->AddTool(wxID_HTML_PANEL, wpanelBitmap, wxNullBitmap,
d1da8872 629 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
b854b7b8 630 _("Show/hide navigation panel"));
0646614d 631
4f9297b0
VS
632 toolBar->AddSeparator();
633 toolBar->AddTool(wxID_HTML_BACK, wbackBitmap, wxNullBitmap,
d1da8872 634 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
0646614d 635 _("Go back"));
4f9297b0 636 toolBar->AddTool(wxID_HTML_FORWARD, wforwardBitmap, wxNullBitmap,
d1da8872 637 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
0646614d 638 _("Go forward"));
4f9297b0 639 toolBar->AddSeparator();
b854b7b8 640
4f9297b0 641 toolBar->AddTool(wxID_HTML_UPNODE, wupnodeBitmap, wxNullBitmap,
d1da8872 642 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
0646614d 643 _("Go one level up in document hierarchy"));
4f9297b0 644 toolBar->AddTool(wxID_HTML_UP, wupBitmap, wxNullBitmap,
d1da8872 645 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
0646614d 646 _("Previous page"));
4f9297b0 647 toolBar->AddTool(wxID_HTML_DOWN, wdownBitmap, wxNullBitmap,
d1da8872 648 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
0646614d
VS
649 _("Next page"));
650
576507e2 651 if ((style & wxHF_PRINT) || (style & wxHF_OPEN_FILES))
4f9297b0 652 toolBar->AddSeparator();
f6bcfd97 653
576507e2 654 if (style & wxHF_OPEN_FILES)
4f9297b0 655 toolBar->AddTool(wxID_HTML_OPENFILE, wopenBitmap, wxNullBitmap,
d1da8872 656 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
0646614d
VS
657 _("Open HTML document"));
658
659#if wxUSE_PRINTING_ARCHITECTURE
660 if (style & wxHF_PRINT)
4f9297b0 661 toolBar->AddTool(wxID_HTML_PRINT, wprintBitmap, wxNullBitmap,
d1da8872 662 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
0646614d
VS
663 _("Print this page"));
664#endif
665
4f9297b0
VS
666 toolBar->AddSeparator();
667 toolBar->AddTool(wxID_HTML_OPTIONS, woptionsBitmap, wxNullBitmap,
d1da8872 668 false, wxDefaultCoord, wxDefaultCoord, (wxObject *) NULL,
b854b7b8
VS
669 _("Display options dialog"));
670}
ee2f6a93 671#endif //wxUSE_TOOLBAR
b854b7b8
VS
672
673
721ab905
VS
674void wxHtmlHelpFrame::SetTitleFormat(const wxString& format)
675{
676 if (m_HtmlWin)
677 m_HtmlWin->SetRelatedFrame(this, format);
678 m_TitleFormat = format;
679}
680
b854b7b8 681
8ec2b484
HH
682bool wxHtmlHelpFrame::Display(const wxString& x)
683{
684 wxString url = m_Data->FindPageByName(x);
da4cc40c 685 if (!url.IsEmpty())
4f9297b0 686 {
d5bb85a0 687 m_HtmlWin->LoadPage(url);
0646614d 688 NotifyPageChanged();
dabbc6a5 689 return true;
8ec2b484 690 }
dabbc6a5
DS
691
692 return false;
8ec2b484
HH
693}
694
695bool wxHtmlHelpFrame::Display(const int id)
696{
697 wxString url = m_Data->FindPageById(id);
da4cc40c 698 if (!url.IsEmpty())
4f9297b0 699 {
d5bb85a0 700 m_HtmlWin->LoadPage(url);
0646614d 701 NotifyPageChanged();
dabbc6a5 702 return true;
8ec2b484 703 }
dabbc6a5
DS
704
705 return false;
8ec2b484
HH
706}
707
708
709
710bool wxHtmlHelpFrame::DisplayContents()
711{
712 if (! m_ContentsBox)
dabbc6a5
DS
713 return false;
714
da4cc40c 715 if (!m_Splitter->IsSplit())
4f9297b0 716 {
dabbc6a5
DS
717 m_NavigPan->Show();
718 m_HtmlWin->Show();
4f9297b0 719 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
dabbc6a5 720 m_Cfg.navig_on = true;
8ec2b484 721 }
dabbc6a5 722
5229b11d 723 m_NavigNotebook->SetSelection(0);
dabbc6a5 724
71d04f7f
JS
725 if (m_Data->GetBookRecArray().GetCount() > 0)
726 {
727 wxHtmlBookRecord& book = m_Data->GetBookRecArray()[0];
728 if (!book.GetStart().IsEmpty())
468ae730 729 m_HtmlWin->LoadPage(book.GetFullPath(book.GetStart()));
71d04f7f 730 }
dabbc6a5
DS
731
732 return true;
8ec2b484
HH
733}
734
735
736
737bool wxHtmlHelpFrame::DisplayIndex()
738{
f0b6a33f 739 if (! m_IndexList)
dabbc6a5
DS
740 return false;
741
da4cc40c 742 if (!m_Splitter->IsSplit())
4f9297b0 743 {
dabbc6a5
DS
744 m_NavigPan->Show();
745 m_HtmlWin->Show();
4f9297b0 746 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
8ec2b484 747 }
dabbc6a5 748
5229b11d 749 m_NavigNotebook->SetSelection(1);
dabbc6a5 750
71d04f7f
JS
751 if (m_Data->GetBookRecArray().GetCount() > 0)
752 {
753 wxHtmlBookRecord& book = m_Data->GetBookRecArray()[0];
754 if (!book.GetStart().IsEmpty())
468ae730 755 m_HtmlWin->LoadPage(book.GetFullPath(book.GetStart()));
71d04f7f 756 }
dabbc6a5
DS
757
758 return true;
8ec2b484 759}
020707bb 760
91fa114d
VS
761void wxHtmlHelpFrame::DisplayIndexItem(const wxHtmlHelpMergedIndexItem *it)
762{
763 if (it->items.size() == 1)
764 {
765 if (!it->items[0]->page.empty())
766 {
767 m_HtmlWin->LoadPage(it->items[0]->GetFullPath());
768 NotifyPageChanged();
769 }
770 }
771 else
772 {
773 wxBusyCursor busy_cursor;
8ec2b484 774
91fa114d
VS
775 // more pages associated with this index item -- let the user choose
776 // which one she/he wants from a list:
777 wxArrayString arr;
778 size_t len = it->items.size();
779 for (size_t i = 0; i < len; i++)
780 {
781 wxString page = it->items[i]->page;
782 // try to find page's title in contents:
783 const wxHtmlHelpDataItems& contents = m_Data->GetContentsArray();
784 size_t clen = contents.size();
785 for (size_t j = 0; j < clen; j++)
786 {
787 if (contents[j].page == page)
788 {
789 page = contents[j].name;
790 break;
791 }
792 }
793 arr.push_back(page);
794 }
795
796 wxSingleChoiceDialog dlg(this,
797 _("Please choose the page to display:"),
798 _("Help Topics"),
799 arr, NULL, wxCHOICEDLG_STYLE & ~wxCENTRE);
800 if (dlg.ShowModal() == wxID_OK)
801 {
802 m_HtmlWin->LoadPage(it->items[dlg.GetSelection()]->GetFullPath());
803 NotifyPageChanged();
804 }
805 }
806}
b854b7b8
VS
807
808
69b5cec2
VS
809bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword,
810 wxHelpSearchMode mode)
8ec2b484 811{
69b5cec2
VS
812 if (mode == wxHELP_SEARCH_ALL)
813 {
814 if ( !(m_SearchList &&
815 m_SearchButton && m_SearchText && m_SearchChoice) )
816 return false;
817 }
818 else if (mode == wxHELP_SEARCH_INDEX)
819 {
820 if ( !(m_IndexList &&
821 m_IndexButton && m_IndexButtonAll && m_IndexText) )
822 return false;
823 }
8ec2b484 824
69b5cec2 825 int foundcnt = 0;
8ec2b484
HH
826 wxString foundstr;
827 wxString book = wxEmptyString;
828
da4cc40c 829 if (!m_Splitter->IsSplit())
4f9297b0 830 {
dabbc6a5
DS
831 m_NavigPan->Show();
832 m_HtmlWin->Show();
4f9297b0 833 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
8ec2b484 834 }
8ec2b484 835
69b5cec2 836 if (mode == wxHELP_SEARCH_ALL)
4f9297b0 837 {
69b5cec2
VS
838 m_NavigNotebook->SetSelection(m_SearchPage);
839 m_SearchList->Clear();
840 m_SearchText->SetValue(keyword);
dabbc6a5 841 m_SearchButton->Disable();
69b5cec2
VS
842
843 if (m_SearchChoice->GetSelection() != 0)
844 book = m_SearchChoice->GetStringSelection();
845
846 wxHtmlSearchStatus status(m_Data, keyword,
847 m_SearchCaseSensitive->GetValue(),
848 m_SearchWholeWords->GetValue(),
849 book);
850
3511e024 851#if wxUSE_PROGRESSDLG
69b5cec2
VS
852 wxProgressDialog progress(_("Searching..."),
853 _("No matching page found yet"),
854 status.GetMaxIndex(), this,
855 wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE);
3511e024 856#endif
69b5cec2
VS
857
858 int curi;
859 while (status.IsActive())
3379ed37 860 {
69b5cec2 861 curi = status.GetCurIndex();
dabbc6a5 862 if (curi % 32 == 0
3511e024 863#if wxUSE_PROGRESSDLG
dabbc6a5 864 && !progress.Update(curi)
3511e024
WS
865#endif
866 )
69b5cec2
VS
867 break;
868 if (status.Search())
869 {
870 foundstr.Printf(_("Found %i matches"), ++foundcnt);
3511e024 871#if wxUSE_PROGRESSDLG
69b5cec2 872 progress.Update(status.GetCurIndex(), foundstr);
3511e024 873#endif
91fa114d 874 m_SearchList->Append(status.GetName(), (void*)status.GetCurItem());
69b5cec2 875 }
d5bb85a0 876 }
69b5cec2 877
dabbc6a5 878 m_SearchButton->Enable();
69b5cec2
VS
879 m_SearchText->SetSelection(0, keyword.Length());
880 m_SearchText->SetFocus();
881 }
882 else if (mode == wxHELP_SEARCH_INDEX)
883 {
884 m_NavigNotebook->SetSelection(m_IndexPage);
885 m_IndexList->Clear();
dabbc6a5
DS
886 m_IndexButton->Disable();
887 m_IndexButtonAll->Disable();
69b5cec2
VS
888 m_IndexText->SetValue(keyword);
889
890 wxCommandEvent dummy;
891 OnIndexFind(dummy); // what a hack...
dabbc6a5
DS
892 m_IndexButton->Enable();
893 m_IndexButtonAll->Enable();
69b5cec2 894 foundcnt = m_IndexList->GetCount();
8ec2b484
HH
895 }
896
da4cc40c 897 if (foundcnt)
4f9297b0 898 {
75d07c0a 899 switch ( mode )
69b5cec2 900 {
75d07c0a
VZ
901 default:
902 wxFAIL_MSG( _T("unknown help search mode") );
903 // fall back
904
905 case wxHELP_SEARCH_ALL:
91fa114d
VS
906 {
907 wxHtmlHelpDataItem *it =
908 (wxHtmlHelpDataItem*) m_SearchList->GetClientData(0);
909 if (it)
910 {
911 m_HtmlWin->LoadPage(it->GetFullPath());
912 NotifyPageChanged();
913 }
75d07c0a 914 break;
91fa114d 915 }
75d07c0a
VZ
916
917 case wxHELP_SEARCH_INDEX:
91fa114d 918 {
d1da8872 919 wxHtmlHelpMergedIndexItem* it =
91fa114d
VS
920 (wxHtmlHelpMergedIndexItem*) m_IndexList->GetClientData(0);
921 if (it)
922 DisplayIndexItem(it);
75d07c0a 923 break;
91fa114d 924 }
69b5cec2 925 }
75d07c0a 926
8ec2b484 927 }
75d07c0a
VZ
928
929 return foundcnt > 0;
8ec2b484
HH
930}
931
b5a7b000 932void wxHtmlHelpFrame::CreateContents()
8ec2b484
HH
933{
934 if (! m_ContentsBox)
d5bb85a0 935 return ;
8ec2b484 936
ba8c1601
MB
937 if (m_PagesHash)
938 {
939 WX_CLEAR_HASH_TABLE(*m_PagesHash);
940 delete m_PagesHash;
941 }
d1da8872 942
91fa114d 943 const wxHtmlHelpDataItems& contents = m_Data->GetContentsArray();
d1da8872 944
91fa114d 945 size_t cnt = contents.size();
8ec2b484 946
91fa114d 947 m_PagesHash = new wxHashTable(wxKEY_STRING, 2 * cnt);
d5bb85a0 948
576507e2 949 const int MAX_ROOTS = 64;
8ec2b484 950 wxTreeItemId roots[MAX_ROOTS];
576507e2
VS
951 // VS: this array holds information about whether we've set item icon at
952 // given level. This is neccessary because m_Data has flat structure
953 // and there's no way of recognizing if some item has subitems or not.
954 // We set the icon later: when we find an item with level=n, we know
955 // that the last item with level=n-1 was folder with subitems, so we
956 // set its icon accordingly
3379ed37 957 bool imaged[MAX_ROOTS];
4f9297b0 958 m_ContentsBox->DeleteAllItems();
dabbc6a5 959
e0952648 960 roots[0] = m_ContentsBox->AddRoot(_("(Help)"));
dabbc6a5 961 imaged[0] = true;
8ec2b484 962
91fa114d 963 for (size_t i = 0; i < cnt; i++)
4f9297b0 964 {
91fa114d 965 wxHtmlHelpDataItem *it = &contents[i];
576507e2 966 // Handle books:
91fa114d 967 if (it->level == 0)
576507e2 968 {
e0952648
VS
969 if (m_hfStyle & wxHF_MERGE_BOOKS)
970 // VS: we don't want book nodes, books' content should
971 // appear under tree's root. This line will create "fake"
972 // record about book node so that the rest of this look
973 // will believe there really _is_ book node and will
974 // behave correctly.
975 roots[1] = roots[0];
976 else
576507e2 977 {
e0952648 978 roots[1] = m_ContentsBox->AppendItem(roots[0],
91fa114d 979 it->name, IMG_Book, -1,
576507e2 980 new wxHtmlHelpTreeItemData(i));
dabbc6a5 981 m_ContentsBox->SetItemBold(roots[1], true);
576507e2 982 }
dabbc6a5 983 imaged[1] = true;
4f9297b0 984 }
576507e2 985 // ...and their contents:
3379ed37 986 else
576507e2 987 {
91fa114d
VS
988 roots[it->level + 1] = m_ContentsBox->AppendItem(
989 roots[it->level], it->name, IMG_Page,
576507e2 990 -1, new wxHtmlHelpTreeItemData(i));
91fa114d 991 imaged[it->level + 1] = false;
576507e2 992 }
4f9297b0 993
576507e2 994 m_PagesHash->Put(it->GetFullPath(),
91fa114d 995 new wxHtmlHelpHashData(i, roots[it->level + 1]));
576507e2
VS
996
997 // Set the icon for the node one level up in the hiearachy,
998 // unless already done (see comment above imaged[] declaration)
91fa114d 999 if (!imaged[it->level])
3379ed37 1000 {
576507e2
VS
1001 int image = IMG_Folder;
1002 if (m_hfStyle & wxHF_ICONS_BOOK)
1003 image = IMG_Book;
1004 else if (m_hfStyle & wxHF_ICONS_BOOK_CHAPTER)
91fa114d
VS
1005 image = (it->level == 1) ? IMG_Book : IMG_Folder;
1006 m_ContentsBox->SetItemImage(roots[it->level], image);
1007 m_ContentsBox->SetItemImage(roots[it->level], image,
b5f6b52a 1008 wxTreeItemIcon_Selected);
91fa114d 1009 imaged[it->level] = true;
8ec2b484
HH
1010 }
1011 }
8ec2b484
HH
1012}
1013
1014
b5a7b000 1015void wxHtmlHelpFrame::CreateIndex()
8ec2b484 1016{
f0b6a33f 1017 if (! m_IndexList)
d5bb85a0 1018 return ;
8ec2b484 1019
f0b6a33f 1020 m_IndexList->Clear();
8ec2b484 1021
91fa114d 1022 size_t cnt = m_mergedIndex->size();
f6bcfd97 1023
240c2873 1024 wxString cnttext;
91fa114d
VS
1025 if (cnt > INDEX_IS_SMALL)
1026 cnttext.Printf(_("%i of %i"), 0, cnt);
1027 else
1028 cnttext.Printf(_("%i of %i"), cnt, cnt);
4f9297b0 1029 m_IndexCountInfo->SetLabel(cnttext);
91fa114d
VS
1030 if (cnt > INDEX_IS_SMALL)
1031 return;
8ec2b484 1032
91fa114d
VS
1033 for (size_t i = 0; i < cnt; i++)
1034 m_IndexList->Append((*m_mergedIndex)[i].name,
1035 (char*)(&(*m_mergedIndex)[i]));
8ec2b484
HH
1036}
1037
1038void wxHtmlHelpFrame::CreateSearch()
1039{
1040 if (! (m_SearchList && m_SearchChoice))
d5bb85a0 1041 return ;
4f9297b0
VS
1042 m_SearchList->Clear();
1043 m_SearchChoice->Clear();
1044 m_SearchChoice->Append(_("Search in all books"));
8ec2b484
HH
1045 const wxHtmlBookRecArray& bookrec = m_Data->GetBookRecArray();
1046 int i, cnt = bookrec.GetCount();
d5bb85a0
VS
1047 for (i = 0; i < cnt; i++)
1048 m_SearchChoice->Append(bookrec[i].GetTitle());
8ec2b484
HH
1049 m_SearchChoice->SetSelection(0);
1050}
1051
1052
b5a7b000 1053void wxHtmlHelpFrame::RefreshLists()
8ec2b484 1054{
91fa114d
VS
1055 // Update m_mergedIndex:
1056 UpdateMergedIndex();
1057 // Update the controls
b5a7b000
VS
1058 CreateContents();
1059 CreateIndex();
8ec2b484
HH
1060 CreateSearch();
1061}
1062
1063void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path)
1064{
1065 wxString oldpath;
1066 wxString tmp;
1067
da4cc40c 1068 if (path != wxEmptyString)
4f9297b0
VS
1069 {
1070 oldpath = cfg->GetPath();
1071 cfg->SetPath(_T("/") + path);
8ec2b484
HH
1072 }
1073
4f9297b0
VS
1074 m_Cfg.navig_on = cfg->Read(wxT("hcNavigPanel"), m_Cfg.navig_on) != 0;
1075 m_Cfg.sashpos = cfg->Read(wxT("hcSashPos"), m_Cfg.sashpos);
1076 m_Cfg.x = cfg->Read(wxT("hcX"), m_Cfg.x);
1077 m_Cfg.y = cfg->Read(wxT("hcY"), m_Cfg.y);
1078 m_Cfg.w = cfg->Read(wxT("hcW"), m_Cfg.w);
1079 m_Cfg.h = cfg->Read(wxT("hcH"), m_Cfg.h);
8ec2b484 1080
4f9297b0
VS
1081 m_FixedFace = cfg->Read(wxT("hcFixedFace"), m_FixedFace);
1082 m_NormalFace = cfg->Read(wxT("hcNormalFace"), m_NormalFace);
c269cf62 1083 m_FontSize = cfg->Read(wxT("hcBaseFontSize"), m_FontSize);
83efdf33 1084
382e6efe
VS
1085 {
1086 int i;
1087 int cnt;
1088 wxString val, s;
f6bcfd97 1089
4f9297b0 1090 cnt = cfg->Read(wxT("hcBookmarksCnt"), 0L);
da4cc40c 1091 if (cnt != 0)
3379ed37 1092 {
382e6efe
VS
1093 m_BookmarksNames.Clear();
1094 m_BookmarksPages.Clear();
da4cc40c 1095 if (m_Bookmarks)
3379ed37 1096 {
4f9297b0
VS
1097 m_Bookmarks->Clear();
1098 m_Bookmarks->Append(_("(bookmarks)"));
382e6efe 1099 }
f6bcfd97 1100
da4cc40c 1101 for (i = 0; i < cnt; i++)
3379ed37 1102 {
0413cec5 1103 val.Printf(wxT("hcBookmark_%i"), i);
4f9297b0 1104 s = cfg->Read(val);
382e6efe 1105 m_BookmarksNames.Add(s);
4f9297b0 1106 if (m_Bookmarks) m_Bookmarks->Append(s);
0413cec5 1107 val.Printf(wxT("hcBookmark_%i_url"), i);
4f9297b0 1108 s = cfg->Read(val);
382e6efe
VS
1109 m_BookmarksPages.Add(s);
1110 }
1111 }
1112 }
1113
8ec2b484 1114 if (m_HtmlWin)
3e5296e7 1115 m_HtmlWin->ReadCustomization(cfg);
8ec2b484
HH
1116
1117 if (path != wxEmptyString)
4f9297b0 1118 cfg->SetPath(oldpath);
8ec2b484
HH
1119}
1120
1121void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path)
1122{
1123 wxString oldpath;
1124 wxString tmp;
8ec2b484 1125
da4cc40c 1126 if (path != wxEmptyString)
4f9297b0
VS
1127 {
1128 oldpath = cfg->GetPath();
1129 cfg->SetPath(_T("/") + path);
8ec2b484
HH
1130 }
1131
4f9297b0
VS
1132 cfg->Write(wxT("hcNavigPanel"), m_Cfg.navig_on);
1133 cfg->Write(wxT("hcSashPos"), (long)m_Cfg.sashpos);
2b5f62a0
VZ
1134 if ( !IsIconized() )
1135 {
1136 // Don't write if iconized as this would make the window
1137 // disappear next time it is shown!
1138 cfg->Write(wxT("hcX"), (long)m_Cfg.x);
1139 cfg->Write(wxT("hcY"), (long)m_Cfg.y);
1140 cfg->Write(wxT("hcW"), (long)m_Cfg.w);
1141 cfg->Write(wxT("hcH"), (long)m_Cfg.h);
1142 }
4f9297b0
VS
1143 cfg->Write(wxT("hcFixedFace"), m_FixedFace);
1144 cfg->Write(wxT("hcNormalFace"), m_NormalFace);
c269cf62 1145 cfg->Write(wxT("hcBaseFontSize"), (long)m_FontSize);
4f9297b0 1146
da4cc40c 1147 if (m_Bookmarks)
4f9297b0 1148 {
382e6efe
VS
1149 int i;
1150 int cnt = m_BookmarksNames.GetCount();
1151 wxString val;
f6bcfd97 1152
4f9297b0 1153 cfg->Write(wxT("hcBookmarksCnt"), (long)cnt);
da4cc40c 1154 for (i = 0; i < cnt; i++)
3379ed37 1155 {
0413cec5 1156 val.Printf(wxT("hcBookmark_%i"), i);
4f9297b0 1157 cfg->Write(val, m_BookmarksNames[i]);
0413cec5 1158 val.Printf(wxT("hcBookmark_%i_url"), i);
4f9297b0 1159 cfg->Write(val, m_BookmarksPages[i]);
382e6efe
VS
1160 }
1161 }
8ec2b484
HH
1162
1163 if (m_HtmlWin)
3e5296e7 1164 m_HtmlWin->WriteCustomization(cfg);
8ec2b484
HH
1165
1166 if (path != wxEmptyString)
4f9297b0 1167 cfg->SetPath(oldpath);
8ec2b484
HH
1168}
1169
1170
83efdf33
VS
1171
1172
1173
8eb2940f 1174static void SetFontsToHtmlWin(wxHtmlWindow *win, wxString scalf, wxString fixf, int size)
83efdf33 1175{
c269cf62
VS
1176 int f_sizes[7];
1177 f_sizes[0] = int(size * 0.6);
1178 f_sizes[1] = int(size * 0.8);
1179 f_sizes[2] = size;
1180 f_sizes[3] = int(size * 1.2);
1181 f_sizes[4] = int(size * 1.4);
1182 f_sizes[5] = int(size * 1.6);
1183 f_sizes[6] = int(size * 1.8);
1184
1185 win->SetFonts(scalf, fixf, f_sizes);
83efdf33
VS
1186}
1187
1188
1189class wxHtmlHelpFrameOptionsDialog : public wxDialog
1190{
c269cf62
VS
1191public:
1192 wxComboBox *NormalFont, *FixedFont;
1193 wxSpinCtrl *FontSize;
1194 wxHtmlWindow *TestWin;
83efdf33 1195
dabbc6a5
DS
1196 wxHtmlHelpFrameOptionsDialog(wxWindow *parent)
1197 : wxDialog(parent, wxID_ANY, wxString(_("Help Browser Options")))
c269cf62
VS
1198 {
1199 wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
1200 wxFlexGridSizer *sizer = new wxFlexGridSizer(2, 3, 2, 5);
1201
dabbc6a5
DS
1202 sizer->Add(new wxStaticText(this, wxID_ANY, _("Normal font:")));
1203 sizer->Add(new wxStaticText(this, wxID_ANY, _("Fixed font:")));
1204 sizer->Add(new wxStaticText(this, wxID_ANY, _("Font size:")));
c269cf62 1205
dabbc6a5 1206 sizer->Add(NormalFont = new wxComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
d1da8872 1207 wxSize(200, wxDefaultCoord),
c269cf62
VS
1208 0, NULL, wxCB_DROPDOWN | wxCB_READONLY));
1209
dabbc6a5 1210 sizer->Add(FixedFont = new wxComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
d1da8872 1211 wxSize(200, wxDefaultCoord),
c269cf62
VS
1212 0, NULL, wxCB_DROPDOWN | wxCB_READONLY));
1213
dabbc6a5 1214 sizer->Add(FontSize = new wxSpinCtrl(this, wxID_ANY));
c269cf62
VS
1215 FontSize->SetRange(2, 100);
1216
1217 topsizer->Add(sizer, 0, wxLEFT|wxRIGHT|wxTOP, 10);
1218
dabbc6a5 1219 topsizer->Add(new wxStaticText(this, wxID_ANY, _("Preview:")),
c269cf62 1220 0, wxLEFT | wxTOP, 10);
dabbc6a5 1221 topsizer->Add(TestWin = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxSize(20, 150),
c269cf62
VS
1222 wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER),
1223 1, wxEXPAND | wxLEFT|wxTOP|wxRIGHT, 10);
1224
1225 wxBoxSizer *sizer2 = new wxBoxSizer(wxHORIZONTAL);
1226 wxButton *ok;
5f7bcb48 1227 sizer2->Add(ok = new wxButton(this, wxID_OK), 0, wxALL, 10);
c269cf62 1228 ok->SetDefault();
5f7bcb48 1229 sizer2->Add(new wxButton(this, wxID_CANCEL), 0, wxALL, 10);
c269cf62
VS
1230 topsizer->Add(sizer2, 0, wxALIGN_RIGHT);
1231
c269cf62
VS
1232 SetSizer(topsizer);
1233 topsizer->Fit(this);
1234 Centre(wxBOTH);
1235 }
f6bcfd97 1236
83efdf33 1237
c269cf62
VS
1238 void UpdateTestWin()
1239 {
1240 wxBusyCursor bcur;
1241 SetFontsToHtmlWin(TestWin,
1242 NormalFont->GetStringSelection(),
1243 FixedFont->GetStringSelection(),
1244 FontSize->GetValue());
311ccb86
VZ
1245
1246 wxString content(_("font size"));
1247
1248 content = _T("<font size=-2>") + content + _T(" -2</font><br>")
1249 _T("<font size=-1>") + content + _T(" -1</font><br>")
1250 _T("<font size=+0>") + content + _T(" +0</font><br>")
1251 _T("<font size=+1>") + content + _T(" +1</font><br>")
1252 _T("<font size=+2>") + content + _T(" +2</font><br>")
1253 _T("<font size=+3>") + content + _T(" +3</font><br>")
1254 _T("<font size=+4>") + content + _T(" +4</font><br>") ;
1255
1256 content = wxString( _T("<html><body><table><tr><td>") ) +
1257 _("Normal face<br>and <u>underlined</u>. ") +
1258 _("<i>Italic face.</i> ") +
1259 _("<b>Bold face.</b> ") +
1260 _("<b><i>Bold italic face.</i></b><br>") +
1261 content +
1262 wxString( _T("</td><td><tt>") ) +
1263 _("Fixed size face.<br> <b>bold</b> <i>italic</i> ") +
1264 _("<b><i>bold italic <u>underlined</u></i></b><br>") +
1265 content +
1266 _T("</tt></td></tr></table></body></html>");
1267
1268 TestWin->SetPage( content );
c269cf62 1269 }
83efdf33 1270
c269cf62
VS
1271 void OnUpdate(wxCommandEvent& WXUNUSED(event))
1272 {
1273 UpdateTestWin();
1274 }
aab49a0b
JS
1275 void OnUpdateSpin(wxSpinEvent& WXUNUSED(event))
1276 {
1277 UpdateTestWin();
1278 }
83efdf33 1279
c269cf62 1280 DECLARE_EVENT_TABLE()
22f3361e 1281 DECLARE_NO_COPY_CLASS(wxHtmlHelpFrameOptionsDialog)
83efdf33
VS
1282};
1283
1284BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog, wxDialog)
dabbc6a5
DS
1285 EVT_COMBOBOX(wxID_ANY, wxHtmlHelpFrameOptionsDialog::OnUpdate)
1286 EVT_SPINCTRL(wxID_ANY, wxHtmlHelpFrameOptionsDialog::OnUpdateSpin)
83efdf33
VS
1287END_EVENT_TABLE()
1288
83efdf33
VS
1289void wxHtmlHelpFrame::OptionsDialog()
1290{
1291 wxHtmlHelpFrameOptionsDialog dlg(this);
1292 unsigned i;
f6bcfd97 1293
da4cc40c 1294 if (m_NormalFonts == NULL)
4f9297b0 1295 {
83efdf33
VS
1296 wxFontEnumerator enu;
1297 enu.EnumerateFacenames();
1298 m_NormalFonts = new wxArrayString;
1299 *m_NormalFonts = *enu.GetFacenames();
a2a03d78 1300 m_NormalFonts->Sort(); // ascending sort
83efdf33 1301 }
da4cc40c 1302 if (m_FixedFonts == NULL)
4f9297b0 1303 {
83efdf33 1304 wxFontEnumerator enu;
dabbc6a5 1305 enu.EnumerateFacenames(wxFONTENCODING_SYSTEM, true /*enum fixed width only*/);
83efdf33
VS
1306 m_FixedFonts = new wxArrayString;
1307 *m_FixedFonts = *enu.GetFacenames();
a2a03d78 1308 m_FixedFonts->Sort(); // ascending sort
83efdf33 1309 }
dabbc6a5 1310
c269cf62
VS
1311 // VS: We want to show the font that is actually used by wxHtmlWindow.
1312 // If customization dialog wasn't used yet, facenames are empty and
1313 // wxHtmlWindow uses default fonts -- let's find out what they
1314 // are so that we can pass them to the dialog:
1315 if (m_NormalFace.empty())
1316 {
dabbc6a5 1317 wxFont fnt(m_FontSize, wxSWISS, wxNORMAL, wxNORMAL, false);
c269cf62
VS
1318 m_NormalFace = fnt.GetFaceName();
1319 }
1320 if (m_FixedFace.empty())
1321 {
dabbc6a5 1322 wxFont fnt(m_FontSize, wxMODERN, wxNORMAL, wxNORMAL, false);
c269cf62
VS
1323 m_FixedFace = fnt.GetFaceName();
1324 }
f6bcfd97 1325
4f9297b0
VS
1326 for (i = 0; i < m_NormalFonts->GetCount(); i++)
1327 dlg.NormalFont->Append((*m_NormalFonts)[i]);
1328 for (i = 0; i < m_FixedFonts->GetCount(); i++)
1329 dlg.FixedFont->Append((*m_FixedFonts)[i]);
c269cf62
VS
1330 if (!m_NormalFace.empty())
1331 dlg.NormalFont->SetStringSelection(m_NormalFace);
1332 else
1affde0a 1333 dlg.NormalFont->SetSelection(0);
c269cf62
VS
1334 if (!m_FixedFace.empty())
1335 dlg.FixedFont->SetStringSelection(m_FixedFace);
1336 else
1337 dlg.FixedFont->SetSelection(0);
1338 dlg.FontSize->SetValue(m_FontSize);
83efdf33 1339 dlg.UpdateTestWin();
f6bcfd97 1340
da4cc40c 1341 if (dlg.ShowModal() == wxID_OK)
4f9297b0
VS
1342 {
1343 m_NormalFace = dlg.NormalFont->GetStringSelection();
1344 m_FixedFace = dlg.FixedFont->GetStringSelection();
c269cf62 1345 m_FontSize = dlg.FontSize->GetValue();
8eb2940f 1346 SetFontsToHtmlWin(m_HtmlWin, m_NormalFace, m_FixedFace, m_FontSize);
83efdf33
VS
1347 }
1348}
1349
1350
1351
0646614d
VS
1352void wxHtmlHelpFrame::NotifyPageChanged()
1353{
1354 if (m_UpdateContents && m_PagesHash)
1355 {
4f9297b0 1356 wxString an = m_HtmlWin->GetOpenedAnchor();
0646614d
VS
1357 wxHtmlHelpHashData *ha;
1358 if (an.IsEmpty())
4f9297b0 1359 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage());
0646614d 1360 else
4f9297b0 1361 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage() + wxT("#") + an);
0646614d
VS
1362 if (ha)
1363 {
1364 bool olduc = m_UpdateContents;
dabbc6a5 1365 m_UpdateContents = false;
4f9297b0
VS
1366 m_ContentsBox->SelectItem(ha->m_Id);
1367 m_ContentsBox->EnsureVisible(ha->m_Id);
0646614d
VS
1368 m_UpdateContents = olduc;
1369 }
1370 }
1371}
1372
83efdf33
VS
1373
1374
8ec2b484
HH
1375/*
1376EVENT HANDLING :
1377*/
1378
1379
d45bc436
RR
1380void wxHtmlHelpFrame::OnActivate(wxActivateEvent& event)
1381{
1382 // This saves one mouse click when using the
1383 // wxHTML for context sensitive help systems
2b5f62a0
VZ
1384#ifndef __WXGTK__
1385 // NB: wxActivateEvent is a bit broken in wxGTK
1386 // and is sometimes sent when it should not be
d45bc436
RR
1387 if (event.GetActive() && m_HtmlWin)
1388 m_HtmlWin->SetFocus();
2b5f62a0 1389#endif
fbd90401
VS
1390
1391 event.Skip();
d45bc436
RR
1392}
1393
8ec2b484
HH
1394void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event)
1395{
da4cc40c 1396 switch (event.GetId())
4f9297b0 1397 {
8ec2b484 1398 case wxID_HTML_BACK :
4f9297b0 1399 m_HtmlWin->HistoryBack();
0646614d 1400 NotifyPageChanged();
8ec2b484 1401 break;
382e6efe 1402
8ec2b484 1403 case wxID_HTML_FORWARD :
4f9297b0 1404 m_HtmlWin->HistoryForward();
0646614d
VS
1405 NotifyPageChanged();
1406 break;
f6bcfd97
BP
1407
1408 case wxID_HTML_UP :
1409 if (m_PagesHash)
0646614d 1410 {
4f9297b0 1411 wxString an = m_HtmlWin->GetOpenedAnchor();
0646614d
VS
1412 wxHtmlHelpHashData *ha;
1413 if (an.IsEmpty())
4f9297b0 1414 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage());
0646614d 1415 else
4f9297b0
VS
1416 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage() + wxT("#") + an);
1417 if (ha && ha->m_Index > 0)
0646614d 1418 {
91fa114d
VS
1419 const wxHtmlHelpDataItem& it = m_Data->GetContentsArray()[ha->m_Index - 1];
1420 if (!it.page.empty())
7df9fbc3 1421 {
91fa114d 1422 m_HtmlWin->LoadPage(it.GetFullPath());
7df9fbc3
JS
1423 NotifyPageChanged();
1424 }
0646614d
VS
1425 }
1426 }
1427 break;
1428
f6bcfd97
BP
1429 case wxID_HTML_UPNODE :
1430 if (m_PagesHash)
0646614d 1431 {
4f9297b0 1432 wxString an = m_HtmlWin->GetOpenedAnchor();
0646614d
VS
1433 wxHtmlHelpHashData *ha;
1434 if (an.IsEmpty())
4f9297b0 1435 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage());
0646614d 1436 else
4f9297b0
VS
1437 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage() + wxT("#") + an);
1438 if (ha && ha->m_Index > 0)
0646614d 1439 {
d1da8872 1440 int level =
91fa114d 1441 m_Data->GetContentsArray()[ha->m_Index].level - 1;
4f9297b0 1442 int ind = ha->m_Index - 1;
f6bcfd97 1443
d1da8872 1444 const wxHtmlHelpDataItem *it =
91fa114d
VS
1445 &m_Data->GetContentsArray()[ind];
1446 while (ind >= 0 && it->level != level)
1447 {
e123fe41 1448 ind--;
91fa114d
VS
1449 it = &m_Data->GetContentsArray()[ind];
1450 }
0646614d
VS
1451 if (ind >= 0)
1452 {
91fa114d 1453 if (!it->page.empty())
7df9fbc3 1454 {
468ae730 1455 m_HtmlWin->LoadPage(it->GetFullPath());
7df9fbc3
JS
1456 NotifyPageChanged();
1457 }
0646614d
VS
1458 }
1459 }
1460 }
1461 break;
1462
f6bcfd97
BP
1463 case wxID_HTML_DOWN :
1464 if (m_PagesHash)
0646614d 1465 {
4f9297b0 1466 wxString an = m_HtmlWin->GetOpenedAnchor();
721ab905 1467 wxString adr;
0646614d 1468 wxHtmlHelpHashData *ha;
f6bcfd97 1469
4f9297b0
VS
1470 if (an.IsEmpty()) adr = m_HtmlWin->GetOpenedPage();
1471 else adr = m_HtmlWin->GetOpenedPage() + wxT("#") + an;
721ab905 1472
4f9297b0 1473 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(adr);
0646614d 1474
91fa114d
VS
1475 const wxHtmlHelpDataItems& contents = m_Data->GetContentsArray();
1476 if (ha && ha->m_Index < (int)contents.size() - 1)
0646614d 1477 {
91fa114d 1478 size_t idx = ha->m_Index + 1;
f6bcfd97 1479
91fa114d 1480 while (contents[idx].GetFullPath() == adr) idx++;
7df9fbc3 1481
91fa114d 1482 if (!contents[idx].page.empty())
7df9fbc3 1483 {
91fa114d 1484 m_HtmlWin->LoadPage(contents[idx].GetFullPath());
7df9fbc3
JS
1485 NotifyPageChanged();
1486 }
0646614d
VS
1487 }
1488 }
8ec2b484 1489 break;
382e6efe 1490
8ec2b484 1491 case wxID_HTML_PANEL :
0646614d
VS
1492 {
1493 if (! (m_Splitter && m_NavigPan))
1494 return ;
da4cc40c 1495 if (m_Splitter->IsSplit())
3379ed37 1496 {
4f9297b0
VS
1497 m_Cfg.sashpos = m_Splitter->GetSashPosition();
1498 m_Splitter->Unsplit(m_NavigPan);
dabbc6a5 1499 m_Cfg.navig_on = false;
da4cc40c 1500 }
3379ed37
VZ
1501 else
1502 {
dabbc6a5
DS
1503 m_NavigPan->Show();
1504 m_HtmlWin->Show();
4f9297b0 1505 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
dabbc6a5 1506 m_Cfg.navig_on = true;
0646614d 1507 }
8ec2b484
HH
1508 }
1509 break;
382e6efe 1510
83efdf33
VS
1511 case wxID_HTML_OPTIONS :
1512 OptionsDialog();
1513 break;
f6bcfd97
BP
1514
1515 case wxID_HTML_BOOKMARKSADD :
382e6efe
VS
1516 {
1517 wxString item;
1518 wxString url;
f6bcfd97 1519
4f9297b0
VS
1520 item = m_HtmlWin->GetOpenedPageTitle();
1521 url = m_HtmlWin->GetOpenedPage();
da4cc40c 1522 if (item == wxEmptyString)
3379ed37 1523 item = url.AfterLast(wxT('/'));
da4cc40c 1524 if (m_BookmarksPages.Index(url) == wxNOT_FOUND)
3379ed37 1525 {
4f9297b0 1526 m_Bookmarks->Append(item);
382e6efe
VS
1527 m_BookmarksNames.Add(item);
1528 m_BookmarksPages.Add(url);
1529 }
1530 }
1531 break;
f6bcfd97
BP
1532
1533 case wxID_HTML_BOOKMARKSREMOVE :
382e6efe
VS
1534 {
1535 wxString item;
1536 int pos;
f6bcfd97 1537
4f9297b0 1538 item = m_Bookmarks->GetStringSelection();
382e6efe 1539 pos = m_BookmarksNames.Index(item);
da4cc40c 1540 if (pos != wxNOT_FOUND)
3379ed37 1541 {
ba8c1601
MB
1542 m_BookmarksNames.RemoveAt(pos);
1543 m_BookmarksPages.RemoveAt(pos);
4f9297b0 1544 m_Bookmarks->Delete(m_Bookmarks->GetSelection());
382e6efe
VS
1545 }
1546 }
1547 break;
0646614d
VS
1548
1549#if wxUSE_PRINTING_ARCHITECTURE
1550 case wxID_HTML_PRINT :
1551 {
f6bcfd97 1552 if (m_Printer == NULL)
0646614d 1553 m_Printer = new wxHtmlEasyPrinting(_("Help Printing"), this);
4f9297b0 1554 if (!m_HtmlWin->GetOpenedPage())
f5ba273e
VS
1555 wxLogWarning(_("Cannot print empty page."));
1556 else
4f9297b0 1557 m_Printer->PrintFile(m_HtmlWin->GetOpenedPage());
0646614d
VS
1558 }
1559 break;
1560#endif
1561
1562 case wxID_HTML_OPENFILE :
1563 {
3527f29c
VS
1564 wxString filemask = wxString(
1565 _("HTML files (*.html;*.htm)|*.html;*.htm|")) +
1566 _("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|") +
1567 _("HTML Help Project (*.hhp)|*.hhp|") +
1568#if wxUSE_LIBMSPACK
1569 _("Compressed HTML Help file (*.chm)|*.chm|") +
1570#endif
1571 _("All files (*.*)|*");
f6bcfd97
BP
1572 wxString s = wxFileSelector(_("Open HTML document"),
1573 wxEmptyString,
1574 wxEmptyString,
1575 wxEmptyString,
3527f29c 1576 filemask,
f6bcfd97
BP
1577 wxOPEN | wxFILE_MUST_EXIST,
1578 this);
0646614d
VS
1579 if (!s.IsEmpty())
1580 {
1581 wxString ext = s.Right(4).Lower();
3527f29c
VS
1582 if (ext == _T(".zip") || ext == _T(".htb") ||
1583#if wxUSE_LIBMSPACK
1584 ext == _T(".chm") ||
1585#endif
1586 ext == _T(".hhp"))
0646614d
VS
1587 {
1588 wxBusyCursor bcur;
4f9297b0 1589 m_Data->AddBook(s);
0646614d
VS
1590 RefreshLists();
1591 }
1592 else
4f9297b0 1593 m_HtmlWin->LoadPage(s);
0646614d
VS
1594 }
1595 }
1596 break;
8ec2b484
HH
1597 }
1598}
1599
1600
1601
1602void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent& event)
1603{
1604 wxHtmlHelpTreeItemData *pg;
1605
4f9297b0 1606 pg = (wxHtmlHelpTreeItemData*) m_ContentsBox->GetItemData(event.GetItem());
f6bcfd97
BP
1607
1608 if (pg && m_UpdateContents)
0646614d 1609 {
91fa114d 1610 const wxHtmlHelpDataItems& contents = m_Data->GetContentsArray();
dabbc6a5 1611 m_UpdateContents = false;
91fa114d
VS
1612 if (!contents[pg->m_Id].page.empty())
1613 m_HtmlWin->LoadPage(contents[pg->m_Id].GetFullPath());
dabbc6a5 1614 m_UpdateContents = true;
0646614d 1615 }
8ec2b484
HH
1616}
1617
1618
1619
a4c97004 1620void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent& WXUNUSED(event))
8ec2b484 1621{
d1da8872 1622 wxHtmlHelpMergedIndexItem *it = (wxHtmlHelpMergedIndexItem*)
91fa114d
VS
1623 m_IndexList->GetClientData(m_IndexList->GetSelection());
1624 if (it)
1625 DisplayIndexItem(it);
8ec2b484
HH
1626}
1627
1628
f0b6a33f
VS
1629void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent& event)
1630{
4f9297b0 1631 wxString sr = m_IndexText->GetLineText(0);
240c2873 1632 sr.MakeLower();
f6bcfd97 1633 if (sr == wxEmptyString)
4f9297b0 1634 {
f0b6a33f 1635 OnIndexAll(event);
4f9297b0 1636 }
da4cc40c 1637 else
4f9297b0 1638 {
f0b6a33f 1639 wxBusyCursor bcur;
f6bcfd97 1640
f0b6a33f 1641 m_IndexList->Clear();
91fa114d
VS
1642 const wxHtmlHelpMergedIndex& index = *m_mergedIndex;
1643 size_t cnt = index.size();
f0b6a33f 1644
240c2873 1645 int displ = 0;
91fa114d 1646 for (size_t i = 0; i < cnt; i++)
240c2873 1647 {
91fa114d 1648 if (index[i].name.Lower().find(sr) != wxString::npos)
3379ed37 1649 {
91fa114d
VS
1650 int pos = m_IndexList->Append(index[i].name,
1651 (char*)(&index[i]));
1652
1653 if (displ++ == 0)
3379ed37 1654 {
d8b5a517
VS
1655 // don't automatically show topic selector if this
1656 // item points to multiple pages:
1657 if (index[i].items.size() == 1)
1658 {
1659 m_IndexList->SetSelection(0);
1660 DisplayIndexItem(&index[i]);
1661 }
91fa114d
VS
1662 }
1663
1664 // if this is nested item of the index, show its parent(s)
1665 // as well, otherwise it would not be clear what entry is
1666 // shown:
1667 wxHtmlHelpMergedIndexItem *parent = index[i].parent;
1668 while (parent)
1669 {
d1da8872 1670 if (pos == 0 ||
91fa114d
VS
1671 (index.Index(*(wxHtmlHelpMergedIndexItem*)m_IndexList->GetClientData(pos-1))) < index.Index(*parent))
1672 {
1673 m_IndexList->Insert(parent->name,
1674 pos, (char*)parent);
1675 parent = parent->parent;
1676 }
1677 else break;
f0b6a33f 1678 }
1dfab6bb
VS
1679
1680 // finally, it the item we just added is itself a parent for
1681 // other items, show them as well, because they are refinements
1682 // of the displayed index entry (i.e. it is implicitly contained
1683 // in them: "foo" with parent "bar" reads as "bar, foo"):
42841dfc 1684 int level = index[i].items[0]->level;
1dfab6bb
VS
1685 i++;
1686 while (i < cnt && index[i].items[0]->level > level)
1687 {
1688 m_IndexList->Append(index[i].name, (char*)(&index[i]));
1689 i++;
1690 }
1691 i--;
f0b6a33f 1692 }
240c2873
VS
1693 }
1694
1695 wxString cnttext;
1696 cnttext.Printf(_("%i of %i"), displ, cnt);
4f9297b0 1697 m_IndexCountInfo->SetLabel(cnttext);
f0b6a33f 1698
4f9297b0
VS
1699 m_IndexText->SetSelection(0, sr.Length());
1700 m_IndexText->SetFocus();
f0b6a33f
VS
1701 }
1702}
1703
1704void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent& WXUNUSED(event))
1705{
1706 wxBusyCursor bcur;
f6bcfd97 1707
f0b6a33f 1708 m_IndexList->Clear();
91fa114d
VS
1709 const wxHtmlHelpMergedIndex& index = *m_mergedIndex;
1710 size_t cnt = index.size();
dabbc6a5 1711 bool first = true;
f0b6a33f 1712
91fa114d 1713 for (size_t i = 0; i < cnt; i++)
4f9297b0 1714 {
91fa114d 1715 m_IndexList->Append(index[i].name, (char*)(&index[i]));
da4cc40c 1716 if (first)
3379ed37 1717 {
d8b5a517
VS
1718 // don't automatically show topic selector if this
1719 // item points to multiple pages:
1720 if (index[i].items.size() == 1)
1721 {
1722 DisplayIndexItem(&index[i]);
1723 }
dabbc6a5 1724 first = false;
f0b6a33f
VS
1725 }
1726 }
240c2873
VS
1727
1728 wxString cnttext;
1729 cnttext.Printf(_("%i of %i"), cnt, cnt);
4f9297b0 1730 m_IndexCountInfo->SetLabel(cnttext);
f0b6a33f
VS
1731}
1732
8ec2b484 1733
a4c97004 1734void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent& WXUNUSED(event))
8ec2b484 1735{
91fa114d 1736 wxHtmlHelpDataItem *it = (wxHtmlHelpDataItem*) m_SearchList->GetClientData(m_SearchList->GetSelection());
f6bcfd97 1737 if (it)
0646614d 1738 {
91fa114d 1739 if (!it->page.empty())
468ae730 1740 m_HtmlWin->LoadPage(it->GetFullPath());
0646614d
VS
1741 NotifyPageChanged();
1742 }
8ec2b484
HH
1743}
1744
a4c97004 1745void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event))
8ec2b484 1746{
4f9297b0 1747 wxString sr = m_SearchText->GetLineText(0);
8ec2b484 1748
69b5cec2
VS
1749 if (!sr.empty())
1750 KeywordSearch(sr, wxHELP_SEARCH_ALL);
8ec2b484
HH
1751}
1752
382e6efe
VS
1753void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event))
1754{
4f9297b0 1755 wxString sr = m_Bookmarks->GetStringSelection();
382e6efe 1756
ae80f837 1757 if (sr != wxEmptyString && sr != _("(bookmarks)"))
0646614d 1758 {
4f9297b0 1759 m_HtmlWin->LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]);
0646614d
VS
1760 NotifyPageChanged();
1761 }
382e6efe
VS
1762}
1763
8ec2b484
HH
1764void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
1765{
68364659
VS
1766 GetSize(&m_Cfg.w, &m_Cfg.h);
1767 GetPosition(&m_Cfg.x, &m_Cfg.y);
5c172c17 1768
5152b0e5
JS
1769#ifdef __WXGTK__
1770 if (IsGrabbed())
1771 {
1772 RemoveGrab();
1773 }
1774#endif
dabbc6a5 1775
4f9297b0 1776 if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter->GetSashPosition();
68364659 1777
d5bb85a0
VS
1778 if (m_Config)
1779 WriteCustomization(m_Config, m_ConfigRoot);
68364659 1780
b4414c1f
JS
1781 if (m_helpController && m_helpController->IsKindOf(CLASSINFO(wxHtmlHelpController)))
1782 {
1783 ((wxHtmlHelpController*) m_helpController)->OnCloseFrame(evt);
1784 }
1785
8ec2b484
HH
1786 evt.Skip();
1787}
1788
d9b21c9f 1789#ifdef __WXMAC__
4aa31786 1790void wxHtmlHelpFrame::OnClose(wxCommandEvent& event)
d9b21c9f 1791{
dabbc6a5 1792 Close(true);
d9b21c9f
JS
1793}
1794
1795void wxHtmlHelpFrame::OnAbout(wxCommandEvent& event)
1796{
91fa114d 1797 wxMessageBox(wxT("wxWidgets HTML Help Viewer (c) 1998-2004, Vaclav Slavik et al"), wxT("HelpView"),
d9b21c9f
JS
1798 wxICON_INFORMATION|wxOK, this);
1799}
1800#endif
1801
8ec2b484 1802BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame)
d45bc436 1803 EVT_ACTIVATE(wxHtmlHelpFrame::OnActivate)
ae80f837
VS
1804 EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_OPTIONS, wxHtmlHelpFrame::OnToolbar)
1805 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE, wxHtmlHelpFrame::OnToolbar)
1806 EVT_BUTTON(wxID_HTML_BOOKMARKSADD, wxHtmlHelpFrame::OnToolbar)
8ec2b484
HH
1807 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpFrame::OnContentsSel)
1808 EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel)
1809 EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel)
1810 EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch)
1811 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpFrame::OnSearch)
f0b6a33f
VS
1812 EVT_BUTTON(wxID_HTML_INDEXBUTTON, wxHtmlHelpFrame::OnIndexFind)
1813 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT, wxHtmlHelpFrame::OnIndexFind)
1814 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL, wxHtmlHelpFrame::OnIndexAll)
382e6efe 1815 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST, wxHtmlHelpFrame::OnBookmarksSel)
f6bcfd97 1816 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow)
d9b21c9f 1817#ifdef __WXMAC__
4aa31786 1818 EVT_MENU(wxID_CLOSE, wxHtmlHelpFrame::OnClose)
d9b21c9f 1819 EVT_MENU(wxID_ABOUT, wxHtmlHelpFrame::OnAbout)
322a5b45 1820 EVT_MENU(wxID_HELP_CONTENTS, wxHtmlHelpFrame::OnAbout)
d9b21c9f
JS
1821#endif
1822
8ec2b484
HH
1823END_EVENT_TABLE()
1824
3379ed37
VZ
1825#endif // wxUSE_WXHTML_HELP
1826