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