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