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