]> git.saurik.com Git - wxWidgets.git/blame - src/html/helpfrm.cpp
patch from Dimitri fixing crashes when decoding the invalid GIFs
[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
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
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"
31 #include "wx/layout.h"
32 #include "wx/sizer.h"
33
34 #include "wx/bmpbuttn.h"
35 #include "wx/statbox.h"
36 #include "wx/radiobox.h"
37#endif // WXPRECOMP
8ec2b484
HH
38
39#include "wx/html/helpfrm.h"
b4414c1f 40#include "wx/html/helpctrl.h"
618a5e38 41#include "wx/textctrl.h"
8ec2b484
HH
42#include "wx/notebook.h"
43#include "wx/imaglist.h"
44#include "wx/treectrl.h"
45#include "wx/tokenzr.h"
46#include "wx/wfstream.h"
47#include "wx/html/htmlwin.h"
48#include "wx/busyinfo.h"
49#include "wx/progdlg.h"
2bd5bbc9 50#include "wx/toolbar.h"
83efdf33 51#include "wx/fontenum.h"
0646614d
VS
52#include "wx/stream.h"
53#include "wx/filedlg.h"
8ec2b484
HH
54
55// Bitmaps:
56
57#ifndef __WXMSW__
83efdf33
VS
58#include "bitmaps/wpanel.xpm"
59#include "bitmaps/wback.xpm"
60#include "bitmaps/wforward.xpm"
61#include "bitmaps/wbook.xpm"
62#include "bitmaps/woptions.xpm"
63#include "bitmaps/wfolder.xpm"
64#include "bitmaps/wpage.xpm"
65#include "bitmaps/whelp.xpm"
66#include "bitmaps/whlproot.xpm"
382e6efe
VS
67#include "bitmaps/wbkadd.xpm"
68#include "bitmaps/wbkdel.xpm"
0646614d
VS
69#include "bitmaps/wup.xpm"
70#include "bitmaps/wupnode.xpm"
71#include "bitmaps/wdown.xpm"
72#include "bitmaps/wopen.xpm"
73#include "bitmaps/wprint.xpm"
8ec2b484
HH
74#endif
75
8ec2b484 76
f0b6a33f
VS
77// what is considered "small index"?
78#define INDEX_IS_SMALL 100
79
9806a47c
JS
80/* Motif defines this as a macro */
81#ifdef Below
82#undef Below
83#endif
f0b6a33f 84
8ec2b484 85//--------------------------------------------------------------------------
382e6efe 86// wxHtmlHelpTreeItemData (private)
8ec2b484
HH
87//--------------------------------------------------------------------------
88
89class wxHtmlHelpTreeItemData : public wxTreeItemData
90{
0646614d 91 public:
da4cc40c
DW
92#if defined(__VISAGECPP__)
93// VA needs a default ctor for some reason....
94 wxHtmlHelpTreeItemData() : wxTreeItemData()
95 { m_Id = 0; }
96#endif
0646614d
VS
97 wxHtmlHelpTreeItemData(int id) : wxTreeItemData()
98 { m_Id = id;}
99
100 int m_Id;
101};
8ec2b484 102
0646614d
VS
103
104//--------------------------------------------------------------------------
105// wxHtmlHelpHashData (private)
106//--------------------------------------------------------------------------
107
108class wxHtmlHelpHashData : public wxObject
109{
8ec2b484 110 public:
0646614d
VS
111 wxHtmlHelpHashData(int index, wxTreeItemId id) : wxObject()
112 { m_Index = index; m_Id = id;}
f5ba273e 113 ~wxHtmlHelpHashData() {}
f6bcfd97 114
0646614d
VS
115 int m_Index;
116 wxTreeItemId m_Id;
8ec2b484
HH
117};
118
382e6efe 119
0646614d
VS
120//--------------------------------------------------------------------------
121// wxHtmlHelpHtmlWindow (private)
122//--------------------------------------------------------------------------
123
124class wxHtmlHelpHtmlWindow : public wxHtmlWindow
125{
126 public:
127 wxHtmlHelpHtmlWindow(wxHtmlHelpFrame *fr, wxWindow *parent) : wxHtmlWindow(parent), m_Frame(fr) {}
128
129 virtual void OnLinkClicked(const wxHtmlLinkInfo& link)
130 {
131 wxHtmlWindow::OnLinkClicked(link);
4f9297b0 132 m_Frame->NotifyPageChanged();
0646614d
VS
133 }
134
f6bcfd97 135 private:
0646614d
VS
136 wxHtmlHelpFrame *m_Frame;
137};
138
382e6efe
VS
139
140
8ec2b484
HH
141//---------------------------------------------------------------------------
142// wxHtmlHelpFrame
143//---------------------------------------------------------------------------
144
576507e2
VS
145// Command IDs :
146enum
147{
148 //wxID_HTML_HELPFRAME = wxID_HIGHEST + 1,
149 wxID_HTML_PANEL = wxID_HIGHEST + 2,
150 wxID_HTML_BACK,
151 wxID_HTML_FORWARD,
152 wxID_HTML_UPNODE,
153 wxID_HTML_UP,
154 wxID_HTML_DOWN,
155 wxID_HTML_PRINT,
156 wxID_HTML_OPENFILE,
157 wxID_HTML_OPTIONS,
158 wxID_HTML_BOOKMARKSLIST,
159 wxID_HTML_BOOKMARKSADD,
160 wxID_HTML_BOOKMARKSREMOVE,
161 wxID_HTML_TREECTRL,
162 wxID_HTML_INDEXPAGE,
163 wxID_HTML_INDEXLIST,
164 wxID_HTML_INDEXTEXT,
165 wxID_HTML_INDEXBUTTON,
166 wxID_HTML_INDEXBUTTONALL,
167 wxID_HTML_NOTEBOOK,
168 wxID_HTML_SEARCHPAGE,
169 wxID_HTML_SEARCHTEXT,
170 wxID_HTML_SEARCHLIST,
171 wxID_HTML_SEARCHBUTTON,
172 wxID_HTML_SEARCHCHOICE,
173 wxID_HTML_COUNTINFO
174};
175
176
8ec2b484
HH
177IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame)
178
179wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title,
d5bb85a0 180 int style, wxHtmlHelpData* data)
8ec2b484
HH
181{
182 Init(data);
183 Create(parent, id, title, style);
184}
d5bb85a0 185
8ec2b484
HH
186void wxHtmlHelpFrame::Init(wxHtmlHelpData* data)
187{
da4cc40c 188 if (data)
4f9297b0 189 {
d5bb85a0
VS
190 m_Data = data;
191 m_DataCreated = FALSE;
da4cc40c 192 } else
4f9297b0 193 {
d5bb85a0
VS
194 m_Data = new wxHtmlHelpData();
195 m_DataCreated = TRUE;
8ec2b484
HH
196 }
197
8ec2b484 198 m_ContentsBox = NULL;
f0b6a33f
VS
199 m_IndexList = NULL;
200 m_IndexButton = NULL;
201 m_IndexButtonAll = NULL;
202 m_IndexText = NULL;
8ec2b484
HH
203 m_SearchList = NULL;
204 m_SearchButton = NULL;
205 m_SearchText = NULL;
206 m_SearchChoice = NULL;
240c2873 207 m_IndexCountInfo = NULL;
8ec2b484
HH
208 m_Splitter = NULL;
209 m_NavigPan = NULL;
210 m_HtmlWin = NULL;
382e6efe 211 m_Bookmarks = NULL;
c4971147
VS
212 m_SearchCaseSensitive = NULL;
213 m_SearchWholeWords = NULL;
214
8ec2b484
HH
215 m_Config = NULL;
216 m_ConfigRoot = wxEmptyString;
217
218 m_Cfg.x = m_Cfg.y = 0;
d5bb85a0
VS
219 m_Cfg.w = 700;
220 m_Cfg.h = 480;
8ec2b484
HH
221 m_Cfg.sashpos = 240;
222 m_Cfg.navig_on = TRUE;
83efdf33
VS
223
224 m_NormalFonts = m_FixedFonts = NULL;
83efdf33 225 m_NormalFace = m_FixedFace = wxEmptyString;
0646614d 226 m_FontSize = 1;
f6bcfd97 227
0646614d
VS
228#if wxUSE_PRINTING_ARCHITECTURE
229 m_Printer = NULL;
230#endif
231
232 m_PagesHash = NULL;
233 m_UpdateContents = TRUE;
b4414c1f 234 m_helpController = (wxHelpControllerBase*) NULL;
8ec2b484
HH
235}
236
d5bb85a0
VS
237// Create: builds the GUI components.
238// with the style flag it's possible to toggle the toolbar, contents, index and search
239// controls.
240// m_HtmlWin will *always* be created, but it's important to realize that
f0b6a33f 241// m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
d5bb85a0
VS
242// m_SearchButton may be NULL.
243// moreover, if no contents, index or searchpage is needed, m_Splitter and
244// m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
245
3379ed37 246bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id,
576507e2 247 const wxString& WXUNUSED(title), int style)
8ec2b484 248{
576507e2
VS
249 m_hfStyle = style;
250
8fd2b35c
VS
251 wxImageList *ContentsImageList = new wxImageList(16, 16);
252 ContentsImageList->Add(wxICON(wbook));
253 ContentsImageList->Add(wxICON(wfolder));
254 ContentsImageList->Add(wxICON(wpage));
255 ContentsImageList->Add(wxICON(whlproot));
256
8ec2b484
HH
257 // Do the config in two steps. We read the HtmlWindow customization after we
258 // create the window.
d5bb85a0
VS
259 if (m_Config)
260 ReadCustomization(m_Config, m_ConfigRoot);
8ec2b484 261
8eb2940f 262 wxFrame::Create(parent, id, _("Help"), wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h), wxDEFAULT_FRAME_STYLE, "wxHtmlHelp");
8ec2b484 263
5c172c17
VS
264 GetPosition(&m_Cfg.x, &m_Cfg.y);
265
83efdf33 266 SetIcon(wxICON(whelp));
9ffdee80 267
8ec2b484
HH
268 int notebook_page = 0;
269
270 CreateStatusBar();
271
272 // toolbar?
576507e2 273 if (style & (wxHF_TOOLBAR | wxHF_FLAT_TOOLBAR))
4f9297b0 274 {
f6bcfd97
BP
275 wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL |
276 wxTB_DOCKABLE |
576507e2 277 (style & wxHF_FLAT_TOOLBAR ? wxTB_FLAT : 0));
00655497 278 toolBar->SetMargins( 2, 2 );
b854b7b8 279 AddToolbarButtons(toolBar, style);
4f9297b0 280 toolBar->Realize();
8ec2b484 281 }
d5bb85a0 282
da4cc40c 283 if (style & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH))
4f9297b0 284 {
d5bb85a0
VS
285 // traditional help controller; splitter window with html page on the
286 // right and a notebook containing various pages on the left
287 m_Splitter = new wxSplitterWindow(this);
288
0646614d 289 m_HtmlWin = new wxHtmlHelpHtmlWindow(this, m_Splitter);
d5bb85a0
VS
290 m_NavigPan = new wxNotebook(m_Splitter, wxID_HTML_NOTEBOOK,
291 wxDefaultPosition, wxDefaultSize);
da4cc40c
DW
292 }
293 else
4f9297b0 294 { // only html window, no notebook with index,contents etc
d5bb85a0 295 m_HtmlWin = new wxHtmlWindow(this);
8ec2b484
HH
296 }
297
4f9297b0
VS
298 m_HtmlWin->SetRelatedFrame(this, m_TitleFormat);
299 m_HtmlWin->SetRelatedStatusBar(0);
d5bb85a0 300 if (m_Config)
4f9297b0 301 m_HtmlWin->ReadCustomization(m_Config, m_ConfigRoot);
8ec2b484
HH
302
303 // contents tree panel?
da4cc40c 304 if (style & wxHF_CONTENTS)
4f9297b0 305 {
ae80f837 306 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_INDEXPAGE);
c7c72b41
VS
307
308 long treeStyle = wxSUNKEN_BORDER | wxTR_HAS_BUTTONS;
309 #ifndef __WXMSW__ // FIXME - temporary, till MSW supports wxTR_HIDE_ROOT
310 treeStyle |= wxTR_HIDE_ROOT;
311 #endif
ae80f837 312
da4cc40c 313 if (style & wxHF_BOOKMARKS)
3379ed37 314 {
ae80f837
VS
315 wxLayoutConstraints *b1 = new wxLayoutConstraints;
316 wxBitmapButton *bmpbt = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSREMOVE, wxBITMAP(wbkdel), wxDefaultPosition, wxSize(20,20));
317
4f9297b0
VS
318 b1->top.SameAs (dummy, wxTop, 10);
319 b1->right.SameAs (dummy, wxRight, 10);
320 b1->height.AsIs();
321 b1->width.AsIs();
322 bmpbt->SetConstraints(b1);
ae80f837
VS
323
324 wxLayoutConstraints *b2 = new wxLayoutConstraints;
325 wxBitmapButton *bmpbt2 = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSADD, wxBITMAP(wbkadd), wxDefaultPosition, wxSize(20,20));
326
4f9297b0
VS
327 b2->top.SameAs (dummy, wxTop, 10);
328 b2->right.LeftOf (bmpbt, 2);
329 b2->height.AsIs();
330 b2->width.AsIs();
331 bmpbt2->SetConstraints(b2);
ae80f837
VS
332
333#if wxUSE_TOOLTIPS
4f9297b0
VS
334 bmpbt->SetToolTip(_("Remove current page from bookmarks"));
335 bmpbt2->SetToolTip(_("Add current page to bookmarks"));
ae80f837
VS
336#endif //wxUSE_TOOLTIPS
337
338 wxLayoutConstraints *b3 = new wxLayoutConstraints;
339 m_Bookmarks = new wxComboBox(dummy, wxID_HTML_BOOKMARKSLIST, wxEmptyString,
340 wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY | wxCB_SORT);
4f9297b0 341 m_Bookmarks->Append(_("(bookmarks)"));
ae80f837 342 for (unsigned i = 0; i < m_BookmarksNames.GetCount(); i++)
4f9297b0
VS
343 m_Bookmarks->Append(m_BookmarksNames[i]);
344 m_Bookmarks->SetSelection(0);
ae80f837 345
4f9297b0
VS
346 b3->centreY.SameAs (bmpbt2, wxCentreY);
347 b3->left.SameAs (dummy, wxLeft, 10);
348 b3->right.LeftOf (bmpbt2, 5);
349 b3->height.AsIs();
350 m_Bookmarks->SetConstraints(b3);
ae80f837
VS
351
352
353 wxLayoutConstraints *b4 = new wxLayoutConstraints;
96873b79 354 m_ContentsBox = new wxTreeCtrl(dummy, wxID_HTML_TREECTRL,
c7c72b41
VS
355 wxDefaultPosition, wxDefaultSize,
356 treeStyle);
4f9297b0 357 m_ContentsBox->AssignImageList(ContentsImageList);
ae80f837 358
4f9297b0
VS
359 b4->top.Below (m_Bookmarks, 10);
360 b4->left.SameAs (dummy, wxLeft, 0);
361 b4->right.SameAs (dummy, wxRight, 0);
362 b4->bottom.SameAs (dummy, wxBottom, 0);
363 m_ContentsBox->SetConstraints(b4);
ae80f837 364
4f9297b0
VS
365 dummy->SetAutoLayout(TRUE);
366 dummy->Layout();
ae80f837 367
4f9297b0 368 m_NavigPan->AddPage(dummy, _("Contents"));
ae80f837
VS
369 }
370
371 else
372 {
373 m_ContentsBox = new wxTreeCtrl(m_NavigPan, wxID_HTML_TREECTRL,
374 wxDefaultPosition, wxDefaultSize,
c7c72b41 375 treeStyle);
4f9297b0
VS
376 m_ContentsBox->AssignImageList(ContentsImageList);
377 m_NavigPan->AddPage(m_ContentsBox, _("Contents"));
ae80f837
VS
378 }
379
d5bb85a0 380 m_ContentsPage = notebook_page++;
8ec2b484
HH
381 }
382
383 // index listbox panel?
da4cc40c 384 if (style & wxHF_INDEX)
4f9297b0 385 {
d5bb85a0 386 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_INDEXPAGE);
f0b6a33f 387
d5bb85a0 388 wxLayoutConstraints *b1 = new wxLayoutConstraints;
f0b6a33f 389 m_IndexText = new wxTextCtrl(dummy, wxID_HTML_INDEXTEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
4f9297b0
VS
390 b1->top.SameAs (dummy, wxTop, 10);
391 b1->left.SameAs (dummy, wxLeft, 10);
392 b1->right.SameAs (dummy, wxRight, 10);
393 b1->height.AsIs();
394 m_IndexText->SetConstraints(b1);
f0b6a33f
VS
395
396 wxLayoutConstraints *b4 = new wxLayoutConstraints;
397 m_IndexButtonAll = new wxButton(dummy, wxID_HTML_INDEXBUTTONALL, _("Show all"));
7618e374 398
4f9297b0
VS
399 b4->top.Below (m_IndexText, 10);
400 b4->right.SameAs (dummy, wxRight, 10);
401 b4->width.AsIs();
402 b4->height.AsIs();
403 m_IndexButtonAll->SetConstraints(b4);
f0b6a33f
VS
404
405 wxLayoutConstraints *b2 = new wxLayoutConstraints;
406 m_IndexButton = new wxButton(dummy, wxID_HTML_INDEXBUTTON, _("Find"));
4f9297b0
VS
407 b2->top.Below (m_IndexText, 10);
408 b2->right.LeftOf (m_IndexButtonAll, 10);
409 b2->width.AsIs();
410 b2->height.AsIs();
411 m_IndexButton->SetConstraints(b2);
f0b6a33f 412
240c2873
VS
413 wxLayoutConstraints *b5 = new wxLayoutConstraints;
414 m_IndexCountInfo = new wxStaticText(dummy, wxID_HTML_COUNTINFO, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT | wxST_NO_AUTORESIZE);
415
4f9297b0
VS
416 b5->top.Below (m_IndexButton, 5);
417 b5->right.SameAs (dummy, wxRight, 10);
418 b5->left.SameAs (dummy, wxLeft, 10);
419 b5->height.AsIs();
420 m_IndexCountInfo->SetConstraints(b5);
240c2873 421
f0b6a33f 422 wxLayoutConstraints *b3 = new wxLayoutConstraints;
721ab905 423 m_IndexList = new wxListBox(dummy, wxID_HTML_INDEXLIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE);
4f9297b0
VS
424 b3->top.Below (m_IndexCountInfo, 5);
425 b3->left.SameAs (dummy, wxLeft, 0);
426 b3->right.SameAs (dummy, wxRight, 0);
427 b3->bottom.SameAs (dummy, wxBottom, 0);
428 m_IndexList->SetConstraints(b3);
f0b6a33f 429
7618e374 430#if wxUSE_TOOLTIPS
4f9297b0
VS
431 m_IndexButtonAll->SetToolTip(_("Show all items in index"));
432 m_IndexButton->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
7618e374
VS
433#endif //wxUSE_TOOLTIPS
434
4f9297b0
VS
435 dummy->SetAutoLayout(TRUE);
436 dummy->Layout();
f0b6a33f 437
4f9297b0 438 m_NavigPan->AddPage(dummy, _("Index"));
d5bb85a0 439 m_IndexPage = notebook_page++;
8ec2b484
HH
440 }
441
442 // search list panel?
da4cc40c 443 if (style & wxHF_SEARCH)
4f9297b0 444 {
d5bb85a0
VS
445 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_SEARCHPAGE);
446
447 wxLayoutConstraints *b1 = new wxLayoutConstraints;
f0b6a33f 448 m_SearchText = new wxTextCtrl(dummy, wxID_HTML_SEARCHTEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
4f9297b0
VS
449 b1->top.SameAs (dummy, wxTop, 10);
450 b1->left.SameAs (dummy, wxLeft, 10);
451 b1->right.SameAs (dummy, wxRight, 10);
452 b1->height.AsIs();
453 m_SearchText->SetConstraints(b1);
d5bb85a0 454
d5bb85a0
VS
455 wxLayoutConstraints *b4 = new wxLayoutConstraints;
456 m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE, wxDefaultPosition,
457 wxDefaultSize);
4f9297b0
VS
458 b4->top.Below (m_SearchText, 10);
459 b4->left.SameAs (dummy, wxLeft, 10);
460 b4->right.SameAs (dummy, wxRight, 10);
461 b4->height.AsIs();
462 m_SearchChoice->SetConstraints(b4);
d5bb85a0 463
c4971147
VS
464 wxLayoutConstraints *b5 = new wxLayoutConstraints;
465 m_SearchCaseSensitive = new wxCheckBox(dummy, -1, _("Case sensitive"));
4f9297b0
VS
466 b5->top.Below (m_SearchChoice, 10);
467 b5->left.SameAs (dummy, wxLeft, 10);
468 b5->width.AsIs();
469 b5->height.AsIs ();
470 m_SearchCaseSensitive->SetConstraints(b5);
c4971147
VS
471
472 wxLayoutConstraints *b6 = new wxLayoutConstraints;
473 m_SearchWholeWords = new wxCheckBox(dummy, -1, _("Whole words only"));
4f9297b0
VS
474 b6->top.Below (m_SearchCaseSensitive, 0);
475 b6->left.SameAs (dummy, wxLeft, 10);
476 b6->width.AsIs();
477 b6->height.AsIs ();
478 m_SearchWholeWords->SetConstraints(b6);
c4971147 479
ae80f837
VS
480 wxLayoutConstraints *b2 = new wxLayoutConstraints;
481 m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search"));
482#if wxUSE_TOOLTIPS
4f9297b0 483 m_SearchButton->SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
ae80f837 484#endif //wxUSE_TOOLTIPS
4f9297b0
VS
485 b2->top.Below (m_SearchWholeWords, 0);
486 b2->right.SameAs (dummy, wxRight, 10);
487 b2->width.AsIs();
488 b2->height.AsIs();
489 m_SearchButton->SetConstraints(b2);
ae80f837 490
954269e6 491 wxLayoutConstraints *b3 = new wxLayoutConstraints;
721ab905 492 m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE);
4f9297b0
VS
493 b3->top.Below (m_SearchButton, 10);
494 b3->left.SameAs (dummy, wxLeft, 0);
495 b3->right.SameAs (dummy, wxRight, 0);
496 b3->bottom.SameAs (dummy, wxBottom, 0);
497 m_SearchList->SetConstraints(b3);
498
499 dummy->SetAutoLayout(TRUE);
500 dummy->Layout();
501 m_NavigPan->AddPage(dummy, _("Search"));
d5bb85a0 502 m_SearchPage = notebook_page++;
8ec2b484 503 }
4f9297b0 504 m_HtmlWin->Show(TRUE);
f6bcfd97 505
b5a7b000 506 RefreshLists();
8ec2b484
HH
507
508 // showtime
da4cc40c 509 if (m_NavigPan && m_Splitter)
4f9297b0
VS
510 {
511 m_Splitter->SetMinimumPaneSize(20);
f38374d0 512 if (m_Cfg.navig_on)
4f9297b0 513 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
da4cc40c 514 else
3379ed37 515 {
4f9297b0
VS
516 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
517 m_Splitter->Unsplit();
f38374d0 518 }
4f9297b0 519
3379ed37
VZ
520 if (m_Cfg.navig_on)
521 {
4f9297b0
VS
522 m_NavigPan->Show(TRUE);
523 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
c32bfc10 524 }
da4cc40c 525 else
3379ed37 526 {
4f9297b0
VS
527 m_NavigPan->Show(FALSE);
528 m_Splitter->Initialize(m_HtmlWin);
68364659 529 }
8ec2b484 530 }
8ec2b484
HH
531 return TRUE;
532}
533
534wxHtmlHelpFrame::~wxHtmlHelpFrame()
535{
b4414c1f 536 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
8ec2b484 537 if (m_DataCreated)
d5bb85a0 538 delete m_Data;
83efdf33
VS
539 if (m_NormalFonts) delete m_NormalFonts;
540 if (m_FixedFonts) delete m_FixedFonts;
70aedad6 541 if (m_PagesHash) delete m_PagesHash;
8ec2b484
HH
542}
543
b854b7b8
VS
544
545void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar *toolBar, int style)
546{
f6bcfd97
BP
547 wxBitmap wpanelBitmap = wxBITMAP(wpanel);
548 wxBitmap wbackBitmap = wxBITMAP(wback);
549 wxBitmap wforwardBitmap = wxBITMAP(wforward);
550 wxBitmap wupnodeBitmap = wxBITMAP(wupnode);
551 wxBitmap wupBitmap = wxBITMAP(wup);
552 wxBitmap wdownBitmap = wxBITMAP(wdown);
553 wxBitmap wopenBitmap = wxBITMAP(wopen);
554 wxBitmap wprintBitmap = wxBITMAP(wprint);
555 wxBitmap woptionsBitmap = wxBITMAP(woptions);
556
557 wxASSERT_MSG( (wpanelBitmap.Ok() && wbackBitmap.Ok() &&
558 wforwardBitmap.Ok() && wupnodeBitmap.Ok() &&
559 wupBitmap.Ok() && wdownBitmap.Ok() &&
560 wopenBitmap.Ok() && wprintBitmap.Ok() &&
561 woptionsBitmap.Ok()),
562 wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
563
564
4f9297b0 565 toolBar->AddTool(wxID_HTML_PANEL, wpanelBitmap, wxNullBitmap,
b854b7b8
VS
566 FALSE, -1, -1, (wxObject *) NULL,
567 _("Show/hide navigation panel"));
0646614d 568
4f9297b0
VS
569 toolBar->AddSeparator();
570 toolBar->AddTool(wxID_HTML_BACK, wbackBitmap, wxNullBitmap,
b854b7b8 571 FALSE, -1, -1, (wxObject *) NULL,
0646614d 572 _("Go back"));
4f9297b0 573 toolBar->AddTool(wxID_HTML_FORWARD, wforwardBitmap, wxNullBitmap,
b854b7b8 574 FALSE, -1, -1, (wxObject *) NULL,
0646614d 575 _("Go forward"));
4f9297b0 576 toolBar->AddSeparator();
b854b7b8 577
4f9297b0 578 toolBar->AddTool(wxID_HTML_UPNODE, wupnodeBitmap, wxNullBitmap,
0646614d
VS
579 FALSE, -1, -1, (wxObject *) NULL,
580 _("Go one level up in document hierarchy"));
4f9297b0 581 toolBar->AddTool(wxID_HTML_UP, wupBitmap, wxNullBitmap,
0646614d
VS
582 FALSE, -1, -1, (wxObject *) NULL,
583 _("Previous page"));
4f9297b0 584 toolBar->AddTool(wxID_HTML_DOWN, wdownBitmap, wxNullBitmap,
0646614d
VS
585 FALSE, -1, -1, (wxObject *) NULL,
586 _("Next page"));
587
576507e2 588 if ((style & wxHF_PRINT) || (style & wxHF_OPEN_FILES))
4f9297b0 589 toolBar->AddSeparator();
f6bcfd97 590
576507e2 591 if (style & wxHF_OPEN_FILES)
4f9297b0 592 toolBar->AddTool(wxID_HTML_OPENFILE, wopenBitmap, wxNullBitmap,
0646614d
VS
593 FALSE, -1, -1, (wxObject *) NULL,
594 _("Open HTML document"));
595
596#if wxUSE_PRINTING_ARCHITECTURE
597 if (style & wxHF_PRINT)
4f9297b0 598 toolBar->AddTool(wxID_HTML_PRINT, wprintBitmap, wxNullBitmap,
0646614d
VS
599 FALSE, -1, -1, (wxObject *) NULL,
600 _("Print this page"));
601#endif
602
4f9297b0
VS
603 toolBar->AddSeparator();
604 toolBar->AddTool(wxID_HTML_OPTIONS, woptionsBitmap, wxNullBitmap,
b854b7b8
VS
605 FALSE, -1, -1, (wxObject *) NULL,
606 _("Display options dialog"));
607}
608
609
721ab905
VS
610void wxHtmlHelpFrame::SetTitleFormat(const wxString& format)
611{
612 if (m_HtmlWin)
613 m_HtmlWin->SetRelatedFrame(this, format);
614 m_TitleFormat = format;
615}
616
b854b7b8 617
8ec2b484
HH
618bool wxHtmlHelpFrame::Display(const wxString& x)
619{
620 wxString url = m_Data->FindPageByName(x);
da4cc40c 621 if (!url.IsEmpty())
4f9297b0 622 {
d5bb85a0 623 m_HtmlWin->LoadPage(url);
0646614d 624 NotifyPageChanged();
d5bb85a0 625 return TRUE;
8ec2b484
HH
626 }
627 return FALSE;
628}
629
630bool wxHtmlHelpFrame::Display(const int id)
631{
632 wxString url = m_Data->FindPageById(id);
da4cc40c 633 if (!url.IsEmpty())
4f9297b0 634 {
d5bb85a0 635 m_HtmlWin->LoadPage(url);
0646614d 636 NotifyPageChanged();
d5bb85a0 637 return TRUE;
8ec2b484
HH
638 }
639 return FALSE;
640}
641
642
643
644bool wxHtmlHelpFrame::DisplayContents()
645{
646 if (! m_ContentsBox)
d5bb85a0 647 return FALSE;
da4cc40c 648 if (!m_Splitter->IsSplit())
4f9297b0
VS
649 {
650 m_NavigPan->Show(TRUE);
651 m_HtmlWin->Show(TRUE);
652 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
c32bfc10 653 m_Cfg.navig_on = TRUE;
8ec2b484 654 }
4f9297b0 655 m_NavigPan->SetSelection(0);
71d04f7f
JS
656 if (m_Data->GetBookRecArray().GetCount() > 0)
657 {
658 wxHtmlBookRecord& book = m_Data->GetBookRecArray()[0];
659 if (!book.GetStart().IsEmpty())
468ae730 660 m_HtmlWin->LoadPage(book.GetFullPath(book.GetStart()));
71d04f7f 661 }
8ec2b484
HH
662 return TRUE;
663}
664
665
666
667bool wxHtmlHelpFrame::DisplayIndex()
668{
f0b6a33f 669 if (! m_IndexList)
d5bb85a0 670 return FALSE;
da4cc40c 671 if (!m_Splitter->IsSplit())
4f9297b0
VS
672 {
673 m_NavigPan->Show(TRUE);
674 m_HtmlWin->Show(TRUE);
675 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
8ec2b484 676 }
4f9297b0 677 m_NavigPan->SetSelection(1);
71d04f7f
JS
678 if (m_Data->GetBookRecArray().GetCount() > 0)
679 {
680 wxHtmlBookRecord& book = m_Data->GetBookRecArray()[0];
681 if (!book.GetStart().IsEmpty())
468ae730 682 m_HtmlWin->LoadPage(book.GetFullPath(book.GetStart()));
71d04f7f 683 }
8ec2b484
HH
684 return TRUE;
685}
686
b854b7b8
VS
687
688
8ec2b484
HH
689bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword)
690{
691 if (! (m_SearchList && m_SearchButton && m_SearchText && m_SearchChoice))
d5bb85a0 692 return FALSE;
8ec2b484 693
c4971147 694 int foundcnt = 0, curi;
8ec2b484
HH
695 wxString foundstr;
696 wxString book = wxEmptyString;
697
da4cc40c 698 if (!m_Splitter->IsSplit())
4f9297b0
VS
699 {
700 m_NavigPan->Show(TRUE);
701 m_HtmlWin->Show(TRUE);
702 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
8ec2b484 703 }
4f9297b0
VS
704 m_NavigPan->SetSelection(m_SearchPage);
705 m_SearchList->Clear();
706 m_SearchText->SetValue(keyword);
707 m_SearchButton->Enable(FALSE);
8ec2b484
HH
708
709 if (m_SearchChoice->GetSelection() != 0)
d5bb85a0 710 book = m_SearchChoice->GetStringSelection();
8ec2b484 711
f6bcfd97 712 wxHtmlSearchStatus status(m_Data, keyword,
4f9297b0 713 m_SearchCaseSensitive->GetValue(), m_SearchWholeWords->GetValue(),
c4971147 714 book);
8ec2b484 715
d5bb85a0
VS
716 wxProgressDialog progress(_("Searching..."), _("No matching page found yet"),
717 status.GetMaxIndex(), this,
b4414c1f 718 wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE);
8ec2b484 719
da4cc40c 720 while (status.IsActive())
4f9297b0 721 {
c4971147 722 curi = status.GetCurIndex();
b5a7b000 723 if (curi % 32 == 0 && progress.Update(curi) == FALSE)
d5bb85a0 724 break;
da4cc40c 725 if (status.Search())
3379ed37 726 {
d5bb85a0
VS
727 foundstr.Printf(_("Found %i matches"), ++foundcnt);
728 progress.Update(status.GetCurIndex(), foundstr);
4f9297b0 729 m_SearchList->Append(status.GetName(), status.GetContentsItem());
d5bb85a0 730 }
8ec2b484
HH
731 }
732
4f9297b0
VS
733 m_SearchButton->Enable(TRUE);
734 m_SearchText->SetSelection(0, keyword.Length());
735 m_SearchText->SetFocus();
da4cc40c 736 if (foundcnt)
4f9297b0
VS
737 {
738 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList->GetClientData(0);
f6bcfd97 739 if (it)
0646614d 740 {
468ae730 741 m_HtmlWin->LoadPage(it->GetFullPath());
0646614d
VS
742 NotifyPageChanged();
743 }
8ec2b484
HH
744 }
745 return (foundcnt > 0);
746}
747
b5a7b000 748void wxHtmlHelpFrame::CreateContents()
8ec2b484
HH
749{
750 if (! m_ContentsBox)
d5bb85a0 751 return ;
8ec2b484 752
8ec2b484 753 m_ContentsBox->Clear();
f6bcfd97 754
0646614d 755 if (m_PagesHash) delete m_PagesHash;
4f9297b0
VS
756 m_PagesHash = new wxHashTable(wxKEY_STRING, 2 * m_Data->GetContentsCnt());
757 m_PagesHash->DeleteContents(TRUE);
8ec2b484
HH
758
759 int cnt = m_Data->GetContentsCnt();
8ec2b484 760 int i;
576507e2 761 size_t booksCnt = m_Data->GetBookRecArray().GetCount();
8ec2b484 762
83efdf33 763 wxHtmlContentsItem *it;
d5bb85a0 764
576507e2 765 const int MAX_ROOTS = 64;
8ec2b484 766 wxTreeItemId roots[MAX_ROOTS];
576507e2
VS
767 // VS: this array holds information about whether we've set item icon at
768 // given level. This is neccessary because m_Data has flat structure
769 // and there's no way of recognizing if some item has subitems or not.
770 // We set the icon later: when we find an item with level=n, we know
771 // that the last item with level=n-1 was folder with subitems, so we
772 // set its icon accordingly
3379ed37 773 bool imaged[MAX_ROOTS];
4f9297b0 774 m_ContentsBox->DeleteAllItems();
96873b79
VS
775
776 // FIXME - will go away when wxMSW's wxTreeCtrl supports wxTR_HIDE_ROOT!
777 bool hasSuperRoot = (booksCnt > 1) ||
778 (m_ContentsBox->GetWindowStyle() & wxTR_HIDE_ROOT);
0c55409f 779
576507e2 780 // Don't show (Help) root if there's only one boook
96873b79 781 if (hasSuperRoot)
576507e2
VS
782 {
783 roots[0] = m_ContentsBox->AddRoot(_("(Help)"));
784 m_ContentsBox->SetItemImage(roots[0], IMG_RootFolder);
785 m_ContentsBox->SetItemSelectedImage(roots[0], IMG_RootFolder);
786 imaged[0] = TRUE;
787 }
8ec2b484 788
da4cc40c 789 for (it = m_Data->GetContents(), i = 0; i < cnt; i++, it++)
4f9297b0 790 {
576507e2 791 // Handle books:
da4cc40c 792 if (it->m_Level == 0)
576507e2
VS
793 {
794 // special case, only one book, make it tree's root:
96873b79 795 if (!hasSuperRoot)
576507e2
VS
796 {
797 roots[0] = roots[1] = m_ContentsBox->AddRoot(
0c55409f 798 it->m_Name, IMG_Book, -1,
576507e2 799 new wxHtmlHelpTreeItemData(i));
0c55409f
VS
800 imaged[0] = imaged[1] = TRUE;
801 m_ContentsBox->SetItemBold(roots[1], TRUE);
576507e2
VS
802 }
803 // multiple books:
804 else
805 {
806 if (m_hfStyle & wxHF_MERGE_BOOKS)
807 // VS: we don't want book nodes, books' content should
808 // appear under tree's root. This line will create "fake"
809 // record about book node so that the rest of this look
810 // will believe there really _is_ book node and will
811 // behave correctly.
812 roots[1] = roots[0];
813 else
814 {
815 roots[1] = m_ContentsBox->AppendItem(roots[0],
3379ed37 816 it->m_Name, IMG_Book, -1,
576507e2
VS
817 new wxHtmlHelpTreeItemData(i));
818 m_ContentsBox->SetItemBold(roots[1], TRUE);
819 }
820 imaged[1] = TRUE;
821 }
4f9297b0 822 }
576507e2 823 // ...and their contents:
3379ed37 824 else
576507e2
VS
825 {
826 roots[it->m_Level + 1] = m_ContentsBox->AppendItem(
3379ed37 827 roots[it->m_Level], it->m_Name, IMG_Page,
576507e2 828 -1, new wxHtmlHelpTreeItemData(i));
3379ed37 829 imaged[it->m_Level + 1] = FALSE;
576507e2 830 }
4f9297b0 831
576507e2
VS
832 m_PagesHash->Put(it->GetFullPath(),
833 new wxHtmlHelpHashData(i, roots[it->m_Level + 1]));
834
835 // Set the icon for the node one level up in the hiearachy,
836 // unless already done (see comment above imaged[] declaration)
da4cc40c 837 if (!imaged[it->m_Level])
3379ed37 838 {
576507e2
VS
839 int image = IMG_Folder;
840 if (m_hfStyle & wxHF_ICONS_BOOK)
841 image = IMG_Book;
842 else if (m_hfStyle & wxHF_ICONS_BOOK_CHAPTER)
843 image = (it->m_Level == 1) ? IMG_Book : IMG_Folder;
844 m_ContentsBox->SetItemImage(roots[it->m_Level], image);
845 m_ContentsBox->SetItemSelectedImage(roots[it->m_Level], image);
4f9297b0 846 imaged[it->m_Level] = TRUE;
8ec2b484
HH
847 }
848 }
576507e2 849
4f9297b0 850 m_ContentsBox->Expand(roots[0]);
8ec2b484
HH
851}
852
853
b5a7b000 854void wxHtmlHelpFrame::CreateIndex()
8ec2b484 855{
f0b6a33f 856 if (! m_IndexList)
d5bb85a0 857 return ;
8ec2b484 858
f0b6a33f 859 m_IndexList->Clear();
8ec2b484
HH
860
861 int cnt = m_Data->GetIndexCnt();
f6bcfd97 862
240c2873
VS
863 wxString cnttext;
864 if (cnt > INDEX_IS_SMALL) cnttext.Printf(_("%i of %i"), 0, cnt);
865 else cnttext.Printf(_("%i of %i"), cnt, cnt);
4f9297b0 866 m_IndexCountInfo->SetLabel(cnttext);
f0b6a33f 867 if (cnt > INDEX_IS_SMALL) return;
f6bcfd97 868
8ec2b484
HH
869 wxHtmlContentsItem* index = m_Data->GetIndex();
870
f6bcfd97 871 for (int i = 0; i < cnt; i++)
4f9297b0 872 m_IndexList->Append(index[i].m_Name, (char*)(index + i));
8ec2b484
HH
873}
874
875void wxHtmlHelpFrame::CreateSearch()
876{
877 if (! (m_SearchList && m_SearchChoice))
d5bb85a0 878 return ;
4f9297b0
VS
879 m_SearchList->Clear();
880 m_SearchChoice->Clear();
881 m_SearchChoice->Append(_("Search in all books"));
8ec2b484
HH
882 const wxHtmlBookRecArray& bookrec = m_Data->GetBookRecArray();
883 int i, cnt = bookrec.GetCount();
d5bb85a0
VS
884 for (i = 0; i < cnt; i++)
885 m_SearchChoice->Append(bookrec[i].GetTitle());
8ec2b484
HH
886 m_SearchChoice->SetSelection(0);
887}
888
889
b5a7b000 890void wxHtmlHelpFrame::RefreshLists()
8ec2b484 891{
b5a7b000
VS
892 CreateContents();
893 CreateIndex();
8ec2b484
HH
894 CreateSearch();
895}
896
897void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path)
898{
899 wxString oldpath;
900 wxString tmp;
901
da4cc40c 902 if (path != wxEmptyString)
4f9297b0
VS
903 {
904 oldpath = cfg->GetPath();
905 cfg->SetPath(_T("/") + path);
8ec2b484
HH
906 }
907
4f9297b0
VS
908 m_Cfg.navig_on = cfg->Read(wxT("hcNavigPanel"), m_Cfg.navig_on) != 0;
909 m_Cfg.sashpos = cfg->Read(wxT("hcSashPos"), m_Cfg.sashpos);
910 m_Cfg.x = cfg->Read(wxT("hcX"), m_Cfg.x);
911 m_Cfg.y = cfg->Read(wxT("hcY"), m_Cfg.y);
912 m_Cfg.w = cfg->Read(wxT("hcW"), m_Cfg.w);
913 m_Cfg.h = cfg->Read(wxT("hcH"), m_Cfg.h);
8ec2b484 914
4f9297b0
VS
915 m_FixedFace = cfg->Read(wxT("hcFixedFace"), m_FixedFace);
916 m_NormalFace = cfg->Read(wxT("hcNormalFace"), m_NormalFace);
917 m_FontSize = cfg->Read(wxT("hcFontSize"), m_FontSize);
83efdf33 918
382e6efe
VS
919 {
920 int i;
921 int cnt;
922 wxString val, s;
f6bcfd97 923
4f9297b0 924 cnt = cfg->Read(wxT("hcBookmarksCnt"), 0L);
da4cc40c 925 if (cnt != 0)
3379ed37 926 {
382e6efe
VS
927 m_BookmarksNames.Clear();
928 m_BookmarksPages.Clear();
da4cc40c 929 if (m_Bookmarks)
3379ed37 930 {
4f9297b0
VS
931 m_Bookmarks->Clear();
932 m_Bookmarks->Append(_("(bookmarks)"));
382e6efe 933 }
f6bcfd97 934
da4cc40c 935 for (i = 0; i < cnt; i++)
3379ed37 936 {
0413cec5 937 val.Printf(wxT("hcBookmark_%i"), i);
4f9297b0 938 s = cfg->Read(val);
382e6efe 939 m_BookmarksNames.Add(s);
4f9297b0 940 if (m_Bookmarks) m_Bookmarks->Append(s);
0413cec5 941 val.Printf(wxT("hcBookmark_%i_url"), i);
4f9297b0 942 s = cfg->Read(val);
382e6efe
VS
943 m_BookmarksPages.Add(s);
944 }
945 }
946 }
947
8ec2b484 948 if (m_HtmlWin)
3e5296e7 949 m_HtmlWin->ReadCustomization(cfg);
8ec2b484
HH
950
951 if (path != wxEmptyString)
4f9297b0 952 cfg->SetPath(oldpath);
8ec2b484
HH
953}
954
955void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path)
956{
957 wxString oldpath;
958 wxString tmp;
8ec2b484 959
da4cc40c 960 if (path != wxEmptyString)
4f9297b0
VS
961 {
962 oldpath = cfg->GetPath();
963 cfg->SetPath(_T("/") + path);
8ec2b484
HH
964 }
965
4f9297b0
VS
966 cfg->Write(wxT("hcNavigPanel"), m_Cfg.navig_on);
967 cfg->Write(wxT("hcSashPos"), (long)m_Cfg.sashpos);
968 cfg->Write(wxT("hcX"), (long)m_Cfg.x);
969 cfg->Write(wxT("hcY"), (long)m_Cfg.y);
970 cfg->Write(wxT("hcW"), (long)m_Cfg.w);
971 cfg->Write(wxT("hcH"), (long)m_Cfg.h);
972 cfg->Write(wxT("hcFixedFace"), m_FixedFace);
973 cfg->Write(wxT("hcNormalFace"), m_NormalFace);
974 cfg->Write(wxT("hcFontSize"), (long)m_FontSize);
975
da4cc40c 976 if (m_Bookmarks)
4f9297b0 977 {
382e6efe
VS
978 int i;
979 int cnt = m_BookmarksNames.GetCount();
980 wxString val;
f6bcfd97 981
4f9297b0 982 cfg->Write(wxT("hcBookmarksCnt"), (long)cnt);
da4cc40c 983 for (i = 0; i < cnt; i++)
3379ed37 984 {
0413cec5 985 val.Printf(wxT("hcBookmark_%i"), i);
4f9297b0 986 cfg->Write(val, m_BookmarksNames[i]);
0413cec5 987 val.Printf(wxT("hcBookmark_%i_url"), i);
4f9297b0 988 cfg->Write(val, m_BookmarksPages[i]);
382e6efe
VS
989 }
990 }
8ec2b484
HH
991
992 if (m_HtmlWin)
3e5296e7 993 m_HtmlWin->WriteCustomization(cfg);
8ec2b484
HH
994
995 if (path != wxEmptyString)
4f9297b0 996 cfg->SetPath(oldpath);
8ec2b484
HH
997}
998
999
83efdf33
VS
1000
1001
1002
8eb2940f 1003static void SetFontsToHtmlWin(wxHtmlWindow *win, wxString scalf, wxString fixf, int size)
83efdf33 1004{
f6bcfd97 1005 static int f_sizes[5][7] =
83efdf33 1006 {
0646614d 1007 { 6, 7, 9, 12, 14, 16, 19},
f151e8b5 1008 { 8, 9, 12, 14, 16, 19, 22},
83efdf33 1009 {10, 12, 14, 16, 19, 24, 32},
0646614d
VS
1010 {14, 16, 18, 24, 32, 38, 45},
1011 {16, 20, 24, 32, 38, 45, 50}
83efdf33 1012 };
f151e8b5 1013
4f9297b0 1014 win->SetFonts(scalf, fixf, f_sizes[size]);
83efdf33
VS
1015}
1016
1017
1018class wxHtmlHelpFrameOptionsDialog : public wxDialog
1019{
1020 public:
f151e8b5 1021 wxComboBox *NormalFont, *FixedFont;
83efdf33
VS
1022 wxRadioBox *RadioBox;
1023 wxHtmlWindow *TestWin;
1024
1025 wxHtmlHelpFrameOptionsDialog(wxWindow *parent) : wxDialog(parent, -1, wxString(_("Help Browser Options")))
1026 {
0646614d 1027 wxString choices[5] = {_("very small"), _("small"), _("medium"), _("large"), _("very large")};
8eb2940f 1028 wxBoxSizer *topsizer, *sizer, *sizer2;
83efdf33
VS
1029
1030 topsizer = new wxBoxSizer(wxVERTICAL);
1031
1032 sizer = new wxBoxSizer(wxHORIZONTAL);
1033
6f67eafe 1034 sizer2 = new wxStaticBoxSizer( new wxStaticBox(this, -1, _("Normal font:")), wxVERTICAL);
4f9297b0 1035 sizer2->Add(NormalFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
f6bcfd97 1036 wxSize(200, 200),
382e6efe 1037 0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
83efdf33
VS
1038 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
1039
4f9297b0 1040 sizer->Add(sizer2, 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10);
83efdf33 1041
6f67eafe 1042 sizer2 = new wxStaticBoxSizer( new wxStaticBox(this, -1, _("Fixed font:")), wxVERTICAL);
4f9297b0 1043 sizer2->Add(FixedFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
f6bcfd97
BP
1044 wxSize(200, 200),
1045 0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
83efdf33
VS
1046 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
1047
4f9297b0 1048 sizer->Add(sizer2, 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10);
83efdf33 1049
4f9297b0 1050 topsizer->Add(sizer);
83efdf33 1051
4f9297b0 1052 topsizer->Add(RadioBox = new wxRadioBox(this, -1, _("Font size:"),
f6bcfd97 1053 wxDefaultPosition, wxDefaultSize, 5, choices, 5),
6f67eafe 1054 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10);
f6bcfd97 1055
4f9297b0 1056 topsizer->Add(new wxStaticText(this, -1, _("Preview:")),
83efdf33 1057 0, wxLEFT | wxTOP, 10);
4f9297b0 1058 topsizer->Add(TestWin = new wxHtmlWindow(this, -1, wxDefaultPosition, wxSize(-1, 150)),
6f67eafe 1059 1, wxEXPAND | wxLEFT|wxTOP|wxRIGHT, 10);
83efdf33
VS
1060
1061 sizer = new wxBoxSizer(wxHORIZONTAL);
4f9297b0
VS
1062 sizer->Add(new wxButton(this, wxID_OK, _("OK")), 0, wxALL, 10);
1063 sizer->Add(new wxButton(this, wxID_CANCEL, _("Cancel")), 0, wxALL, 10);
1064 topsizer->Add(sizer, 0, wxALIGN_RIGHT);
83efdf33
VS
1065
1066 SetAutoLayout(TRUE);
1067 SetSizer(topsizer);
4f9297b0 1068 topsizer->Fit(this);
83efdf33
VS
1069 Centre(wxBOTH);
1070 }
f6bcfd97 1071
83efdf33
VS
1072
1073 void UpdateTestWin()
1074 {
1075 wxBusyCursor bcur;
f6bcfd97 1076 SetFontsToHtmlWin(TestWin,
4f9297b0
VS
1077 NormalFont->GetStringSelection(),
1078 FixedFont->GetStringSelection(),
1079 RadioBox->GetSelection());
1080 TestWin->SetPage(_(
f6bcfd97
BP
1081"<html><body>\
1082Normal face<br>(and <u>underlined</u>. <i>Italic face.</i> \
1083<b>Bold face.</b> <b><i>Bold italic face.</i></b><br>\
1084<font size=-2>font size -2</font><br>\
1085<font size=-1>font size -1</font><br>\
1086<font size=+0>font size +0</font><br>\
1087<font size=+1>font size +1</font><br>\
1088<font size=+2>font size +2</font><br>\
1089<font size=+3>font size +3</font><br>\
1090<font size=+4>font size +4</font><br>\
1091\
1092<p><tt>Fixed size face.<br> <b>bold</b> <i>italic</i> \
1093<b><i>bold italic <u>underlined</u></i></b><br>\
1094<font size=-2>font size -2</font><br>\
1095<font size=-1>font size -1</font><br>\
1096<font size=+0>font size +0</font><br>\
1097<font size=+1>font size +1</font><br>\
1098<font size=+2>font size +2</font><br>\
1099<font size=+3>font size +3</font><br>\
1100<font size=+4>font size +4</font></tt>\
1101</body></html>"
1102 ));
83efdf33
VS
1103 }
1104
33ac7e6f 1105 void OnUpdate(wxCommandEvent& WXUNUSED(event))
83efdf33
VS
1106 {
1107 UpdateTestWin();
1108 }
1109
1110 DECLARE_EVENT_TABLE()
1111};
1112
1113BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog, wxDialog)
f151e8b5 1114 EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
83efdf33 1115 EVT_RADIOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
83efdf33
VS
1116END_EVENT_TABLE()
1117
1118
1119void wxHtmlHelpFrame::OptionsDialog()
1120{
1121 wxHtmlHelpFrameOptionsDialog dlg(this);
1122 unsigned i;
f6bcfd97 1123
da4cc40c 1124 if (m_NormalFonts == NULL)
4f9297b0 1125 {
83efdf33
VS
1126 wxFontEnumerator enu;
1127 enu.EnumerateFacenames();
1128 m_NormalFonts = new wxArrayString;
1129 *m_NormalFonts = *enu.GetFacenames();
4f9297b0 1130 m_NormalFonts->Sort();
83efdf33 1131 }
da4cc40c 1132 if (m_FixedFonts == NULL)
4f9297b0 1133 {
83efdf33
VS
1134 wxFontEnumerator enu;
1135 enu.EnumerateFacenames(wxFONTENCODING_SYSTEM, TRUE);
1136 m_FixedFonts = new wxArrayString;
1137 *m_FixedFonts = *enu.GetFacenames();
4f9297b0 1138 m_FixedFonts->Sort();
83efdf33 1139 }
f6bcfd97 1140
4f9297b0
VS
1141 for (i = 0; i < m_NormalFonts->GetCount(); i++)
1142 dlg.NormalFont->Append((*m_NormalFonts)[i]);
1143 for (i = 0; i < m_FixedFonts->GetCount(); i++)
1144 dlg.FixedFont->Append((*m_FixedFonts)[i]);
1145 if (!m_NormalFace.IsEmpty()) dlg.NormalFont->SetStringSelection(m_NormalFace);
1146 else dlg.NormalFont->SetSelection(0);
1147 if (!m_FixedFace.IsEmpty()) dlg.FixedFont->SetStringSelection(m_FixedFace);
1148 else dlg.FixedFont->SetSelection(0);
1149 dlg.RadioBox->SetSelection(m_FontSize);
83efdf33 1150 dlg.UpdateTestWin();
f6bcfd97 1151
da4cc40c 1152 if (dlg.ShowModal() == wxID_OK)
4f9297b0
VS
1153 {
1154 m_NormalFace = dlg.NormalFont->GetStringSelection();
1155 m_FixedFace = dlg.FixedFont->GetStringSelection();
1156 m_FontSize = dlg.RadioBox->GetSelection();
8eb2940f 1157 SetFontsToHtmlWin(m_HtmlWin, m_NormalFace, m_FixedFace, m_FontSize);
83efdf33
VS
1158 }
1159}
1160
1161
1162
0646614d
VS
1163void wxHtmlHelpFrame::NotifyPageChanged()
1164{
1165 if (m_UpdateContents && m_PagesHash)
1166 {
4f9297b0 1167 wxString an = m_HtmlWin->GetOpenedAnchor();
0646614d
VS
1168 wxHtmlHelpHashData *ha;
1169 if (an.IsEmpty())
4f9297b0 1170 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage());
0646614d 1171 else
4f9297b0 1172 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage() + wxT("#") + an);
0646614d
VS
1173 if (ha)
1174 {
1175 bool olduc = m_UpdateContents;
1176 m_UpdateContents = FALSE;
4f9297b0
VS
1177 m_ContentsBox->SelectItem(ha->m_Id);
1178 m_ContentsBox->EnsureVisible(ha->m_Id);
0646614d
VS
1179 m_UpdateContents = olduc;
1180 }
1181 }
1182}
1183
83efdf33
VS
1184
1185
8ec2b484
HH
1186/*
1187EVENT HANDLING :
1188*/
1189
1190
1191void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event)
1192{
da4cc40c 1193 switch (event.GetId())
4f9297b0 1194 {
8ec2b484 1195 case wxID_HTML_BACK :
4f9297b0 1196 m_HtmlWin->HistoryBack();
0646614d 1197 NotifyPageChanged();
8ec2b484 1198 break;
382e6efe 1199
8ec2b484 1200 case wxID_HTML_FORWARD :
4f9297b0 1201 m_HtmlWin->HistoryForward();
0646614d
VS
1202 NotifyPageChanged();
1203 break;
f6bcfd97
BP
1204
1205 case wxID_HTML_UP :
1206 if (m_PagesHash)
0646614d 1207 {
4f9297b0 1208 wxString an = m_HtmlWin->GetOpenedAnchor();
0646614d
VS
1209 wxHtmlHelpHashData *ha;
1210 if (an.IsEmpty())
4f9297b0 1211 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage());
0646614d 1212 else
4f9297b0
VS
1213 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage() + wxT("#") + an);
1214 if (ha && ha->m_Index > 0)
0646614d 1215 {
4f9297b0 1216 wxHtmlContentsItem *it = m_Data->GetContents() + (ha->m_Index - 1);
7df9fbc3
JS
1217 if (it->m_Page[0] != 0)
1218 {
468ae730 1219 m_HtmlWin->LoadPage(it->GetFullPath());
7df9fbc3
JS
1220 NotifyPageChanged();
1221 }
0646614d
VS
1222 }
1223 }
1224 break;
1225
f6bcfd97
BP
1226 case wxID_HTML_UPNODE :
1227 if (m_PagesHash)
0646614d 1228 {
4f9297b0 1229 wxString an = m_HtmlWin->GetOpenedAnchor();
0646614d
VS
1230 wxHtmlHelpHashData *ha;
1231 if (an.IsEmpty())
4f9297b0 1232 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage());
0646614d 1233 else
4f9297b0
VS
1234 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage() + wxT("#") + an);
1235 if (ha && ha->m_Index > 0)
0646614d 1236 {
4f9297b0 1237 int level = m_Data->GetContents()[ha->m_Index].m_Level - 1;
0646614d 1238 wxHtmlContentsItem *it;
4f9297b0 1239 int ind = ha->m_Index - 1;
f6bcfd97 1240
4f9297b0
VS
1241 it = m_Data->GetContents() + ind;
1242 while (ind >= 0 && it->m_Level != level) ind--, it--;
0646614d
VS
1243 if (ind >= 0)
1244 {
7df9fbc3
JS
1245 if (it->m_Page[0] != 0)
1246 {
468ae730 1247 m_HtmlWin->LoadPage(it->GetFullPath());
7df9fbc3
JS
1248 NotifyPageChanged();
1249 }
0646614d
VS
1250 }
1251 }
1252 }
1253 break;
1254
f6bcfd97
BP
1255 case wxID_HTML_DOWN :
1256 if (m_PagesHash)
0646614d 1257 {
4f9297b0 1258 wxString an = m_HtmlWin->GetOpenedAnchor();
721ab905 1259 wxString adr;
0646614d 1260 wxHtmlHelpHashData *ha;
f6bcfd97 1261
4f9297b0
VS
1262 if (an.IsEmpty()) adr = m_HtmlWin->GetOpenedPage();
1263 else adr = m_HtmlWin->GetOpenedPage() + wxT("#") + an;
721ab905 1264
4f9297b0 1265 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(adr);
0646614d 1266
4f9297b0 1267 if (ha && ha->m_Index < m_Data->GetContentsCnt() - 1)
0646614d 1268 {
4f9297b0 1269 wxHtmlContentsItem *it = m_Data->GetContents() + (ha->m_Index + 1);
f6bcfd97 1270
468ae730 1271 while (it->GetFullPath() == adr) it++;
7df9fbc3
JS
1272
1273 if (it->m_Page[0] != 0)
1274 {
468ae730 1275 m_HtmlWin->LoadPage(it->GetFullPath());
7df9fbc3
JS
1276 NotifyPageChanged();
1277 }
0646614d
VS
1278 }
1279 }
8ec2b484 1280 break;
382e6efe 1281
8ec2b484 1282 case wxID_HTML_PANEL :
0646614d
VS
1283 {
1284 if (! (m_Splitter && m_NavigPan))
1285 return ;
da4cc40c 1286 if (m_Splitter->IsSplit())
3379ed37 1287 {
4f9297b0
VS
1288 m_Cfg.sashpos = m_Splitter->GetSashPosition();
1289 m_Splitter->Unsplit(m_NavigPan);
0646614d 1290 m_Cfg.navig_on = FALSE;
da4cc40c 1291 }
3379ed37
VZ
1292 else
1293 {
4f9297b0
VS
1294 m_NavigPan->Show(TRUE);
1295 m_HtmlWin->Show(TRUE);
1296 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
0646614d
VS
1297 m_Cfg.navig_on = TRUE;
1298 }
8ec2b484
HH
1299 }
1300 break;
382e6efe 1301
83efdf33
VS
1302 case wxID_HTML_OPTIONS :
1303 OptionsDialog();
1304 break;
f6bcfd97
BP
1305
1306 case wxID_HTML_BOOKMARKSADD :
382e6efe
VS
1307 {
1308 wxString item;
1309 wxString url;
f6bcfd97 1310
4f9297b0
VS
1311 item = m_HtmlWin->GetOpenedPageTitle();
1312 url = m_HtmlWin->GetOpenedPage();
da4cc40c 1313 if (item == wxEmptyString)
3379ed37 1314 item = url.AfterLast(wxT('/'));
da4cc40c 1315 if (m_BookmarksPages.Index(url) == wxNOT_FOUND)
3379ed37 1316 {
4f9297b0 1317 m_Bookmarks->Append(item);
382e6efe
VS
1318 m_BookmarksNames.Add(item);
1319 m_BookmarksPages.Add(url);
1320 }
1321 }
1322 break;
f6bcfd97
BP
1323
1324 case wxID_HTML_BOOKMARKSREMOVE :
382e6efe
VS
1325 {
1326 wxString item;
1327 int pos;
f6bcfd97 1328
4f9297b0 1329 item = m_Bookmarks->GetStringSelection();
382e6efe 1330 pos = m_BookmarksNames.Index(item);
da4cc40c 1331 if (pos != wxNOT_FOUND)
3379ed37 1332 {
382e6efe
VS
1333 m_BookmarksNames.Remove(pos);
1334 m_BookmarksPages.Remove(pos);
4f9297b0 1335 m_Bookmarks->Delete(m_Bookmarks->GetSelection());
382e6efe
VS
1336 }
1337 }
1338 break;
0646614d
VS
1339
1340#if wxUSE_PRINTING_ARCHITECTURE
1341 case wxID_HTML_PRINT :
1342 {
f6bcfd97 1343 if (m_Printer == NULL)
0646614d 1344 m_Printer = new wxHtmlEasyPrinting(_("Help Printing"), this);
4f9297b0 1345 if (!m_HtmlWin->GetOpenedPage())
f5ba273e
VS
1346 wxLogWarning(_("Cannot print empty page."));
1347 else
4f9297b0 1348 m_Printer->PrintFile(m_HtmlWin->GetOpenedPage());
0646614d
VS
1349 }
1350 break;
1351#endif
1352
1353 case wxID_HTML_OPENFILE :
1354 {
f6bcfd97
BP
1355 wxString s = wxFileSelector(_("Open HTML document"),
1356 wxEmptyString,
1357 wxEmptyString,
1358 wxEmptyString,
1359 _(
1360"HTML files (*.htm)|*.htm|HTML files (*.html)|*.html|\
1361Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
1362HTML Help Project (*.hhp)|*.hhp|\
1363All files (*.*)|*"
1364 ),
1365 wxOPEN | wxFILE_MUST_EXIST,
1366 this);
0646614d
VS
1367 if (!s.IsEmpty())
1368 {
1369 wxString ext = s.Right(4).Lower();
1370 if (ext == _T(".zip") || ext == _T(".htb") || ext == _T(".hhp"))
1371 {
1372 wxBusyCursor bcur;
4f9297b0 1373 m_Data->AddBook(s);
0646614d
VS
1374 RefreshLists();
1375 }
1376 else
4f9297b0 1377 m_HtmlWin->LoadPage(s);
0646614d
VS
1378 }
1379 }
1380 break;
8ec2b484
HH
1381 }
1382}
1383
1384
1385
1386void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent& event)
1387{
1388 wxHtmlHelpTreeItemData *pg;
0646614d 1389 wxHtmlContentsItem *it;
8ec2b484 1390
4f9297b0 1391 pg = (wxHtmlHelpTreeItemData*) m_ContentsBox->GetItemData(event.GetItem());
f6bcfd97
BP
1392
1393 if (pg && m_UpdateContents)
0646614d 1394 {
4f9297b0 1395 it = m_Data->GetContents() + (pg->m_Id);
0646614d 1396 m_UpdateContents = FALSE;
7df9fbc3 1397 if (it->m_Page[0] != 0)
468ae730 1398 m_HtmlWin->LoadPage(it->GetFullPath());
0646614d
VS
1399 m_UpdateContents = TRUE;
1400 }
8ec2b484
HH
1401}
1402
1403
1404
a4c97004 1405void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent& WXUNUSED(event))
8ec2b484 1406{
4f9297b0 1407 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_IndexList->GetClientData(m_IndexList->GetSelection());
7df9fbc3 1408 if (it->m_Page[0] != 0)
468ae730 1409 m_HtmlWin->LoadPage(it->GetFullPath());
0646614d 1410 NotifyPageChanged();
8ec2b484
HH
1411}
1412
1413
f0b6a33f
VS
1414void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent& event)
1415{
4f9297b0 1416 wxString sr = m_IndexText->GetLineText(0);
240c2873 1417 sr.MakeLower();
f6bcfd97 1418 if (sr == wxEmptyString)
4f9297b0 1419 {
f0b6a33f 1420 OnIndexAll(event);
4f9297b0 1421 }
da4cc40c 1422 else
4f9297b0 1423 {
f0b6a33f
VS
1424 wxBusyCursor bcur;
1425 const wxChar *cstr = sr.c_str();
33ac7e6f 1426 wxChar mybuff[512];
3379ed37 1427 wxChar *ptr;
f0b6a33f 1428 bool first = TRUE;
f6bcfd97 1429
f0b6a33f
VS
1430 m_IndexList->Clear();
1431 int cnt = m_Data->GetIndexCnt();
1432 wxHtmlContentsItem* index = m_Data->GetIndex();
1433
240c2873 1434 int displ = 0;
f0b6a33f 1435 for (int i = 0; i < cnt; i++)
240c2873
VS
1436 {
1437 wxStrncpy(mybuff, index[i].m_Name, 512);
f6bcfd97
BP
1438 mybuff[511] = _T('\0');
1439 for (ptr = mybuff; *ptr != 0; ptr++)
1440 if (*ptr >= _T('A') && *ptr <= _T('Z'))
1441 *ptr -= (wxChar)(_T('A') - _T('a'));
da4cc40c 1442 if (wxStrstr(mybuff, cstr) != NULL)
3379ed37 1443 {
4f9297b0 1444 m_IndexList->Append(index[i].m_Name, (char*)(index + i));
240c2873 1445 displ++;
da4cc40c 1446 if (first)
3379ed37 1447 {
7df9fbc3 1448 if (index[i].m_Page[0] != 0)
468ae730 1449 m_HtmlWin->LoadPage(index[i].GetFullPath());
0646614d 1450 NotifyPageChanged();
f0b6a33f
VS
1451 first = FALSE;
1452 }
1453 }
240c2873
VS
1454 }
1455
1456 wxString cnttext;
1457 cnttext.Printf(_("%i of %i"), displ, cnt);
4f9297b0 1458 m_IndexCountInfo->SetLabel(cnttext);
f0b6a33f 1459
4f9297b0
VS
1460 m_IndexText->SetSelection(0, sr.Length());
1461 m_IndexText->SetFocus();
f0b6a33f
VS
1462 }
1463}
1464
1465void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent& WXUNUSED(event))
1466{
1467 wxBusyCursor bcur;
f6bcfd97 1468
f0b6a33f
VS
1469 m_IndexList->Clear();
1470 int cnt = m_Data->GetIndexCnt();
1471 bool first = TRUE;
1472 wxHtmlContentsItem* index = m_Data->GetIndex();
1473
da4cc40c 1474 for (int i = 0; i < cnt; i++)
4f9297b0
VS
1475 {
1476 m_IndexList->Append(index[i].m_Name, (char*)(index + i));
da4cc40c 1477 if (first)
3379ed37 1478 {
7df9fbc3 1479 if (index[i].m_Page[0] != 0)
468ae730 1480 m_HtmlWin->LoadPage(index[i].GetFullPath());
0646614d 1481 NotifyPageChanged();
f0b6a33f
VS
1482 first = FALSE;
1483 }
1484 }
240c2873
VS
1485
1486 wxString cnttext;
1487 cnttext.Printf(_("%i of %i"), cnt, cnt);
4f9297b0 1488 m_IndexCountInfo->SetLabel(cnttext);
f0b6a33f
VS
1489}
1490
8ec2b484 1491
a4c97004 1492void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent& WXUNUSED(event))
8ec2b484 1493{
4f9297b0 1494 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList->GetClientData(m_SearchList->GetSelection());
f6bcfd97 1495 if (it)
0646614d 1496 {
7df9fbc3 1497 if (it->m_Page[0] != 0)
468ae730 1498 m_HtmlWin->LoadPage(it->GetFullPath());
0646614d
VS
1499 NotifyPageChanged();
1500 }
8ec2b484
HH
1501}
1502
a4c97004 1503void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event))
8ec2b484 1504{
4f9297b0 1505 wxString sr = m_SearchText->GetLineText(0);
8ec2b484
HH
1506
1507 if (sr != wxEmptyString) KeywordSearch(sr);
1508}
1509
382e6efe
VS
1510void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event))
1511{
4f9297b0 1512 wxString sr = m_Bookmarks->GetStringSelection();
382e6efe 1513
ae80f837 1514 if (sr != wxEmptyString && sr != _("(bookmarks)"))
0646614d 1515 {
4f9297b0 1516 m_HtmlWin->LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]);
0646614d
VS
1517 NotifyPageChanged();
1518 }
382e6efe
VS
1519}
1520
8ec2b484
HH
1521void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
1522{
68364659
VS
1523 GetSize(&m_Cfg.w, &m_Cfg.h);
1524 GetPosition(&m_Cfg.x, &m_Cfg.y);
5c172c17 1525
4f9297b0 1526 if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter->GetSashPosition();
68364659 1527
d5bb85a0
VS
1528 if (m_Config)
1529 WriteCustomization(m_Config, m_ConfigRoot);
68364659 1530
b4414c1f
JS
1531 if (m_helpController && m_helpController->IsKindOf(CLASSINFO(wxHtmlHelpController)))
1532 {
1533 ((wxHtmlHelpController*) m_helpController)->OnCloseFrame(evt);
1534 }
1535
8ec2b484
HH
1536 evt.Skip();
1537}
1538
1539BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame)
ae80f837
VS
1540 EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_OPTIONS, wxHtmlHelpFrame::OnToolbar)
1541 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE, wxHtmlHelpFrame::OnToolbar)
1542 EVT_BUTTON(wxID_HTML_BOOKMARKSADD, wxHtmlHelpFrame::OnToolbar)
8ec2b484
HH
1543 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpFrame::OnContentsSel)
1544 EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel)
1545 EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel)
1546 EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch)
1547 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpFrame::OnSearch)
f0b6a33f
VS
1548 EVT_BUTTON(wxID_HTML_INDEXBUTTON, wxHtmlHelpFrame::OnIndexFind)
1549 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT, wxHtmlHelpFrame::OnIndexFind)
1550 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL, wxHtmlHelpFrame::OnIndexAll)
382e6efe 1551 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST, wxHtmlHelpFrame::OnBookmarksSel)
f6bcfd97 1552 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow)
8ec2b484
HH
1553END_EVENT_TABLE()
1554
3379ed37
VZ
1555#endif // wxUSE_WXHTML_HELP
1556