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