1 /////////////////////////////////////////////////////////////////////////////
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
8 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h"
14 #include "wx/wxprec.h"
26 #include "wx/object.h"
29 #include "wx/bmpbuttn.h"
30 #include "wx/statbox.h"
31 #include "wx/radiobox.h"
36 #include "wx/msgdlg.h"
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"
61 // what is considered "small index"?
62 #define INDEX_IS_SMALL 100
64 /* Motif defines this as a macro */
69 //--------------------------------------------------------------------------
70 // wxHtmlHelpTreeItemData (private)
71 //--------------------------------------------------------------------------
73 class wxHtmlHelpTreeItemData
: public wxTreeItemData
76 #if defined(__VISAGECPP__)
77 // VA needs a default ctor for some reason....
78 wxHtmlHelpTreeItemData() : wxTreeItemData()
81 wxHtmlHelpTreeItemData(int id
) : wxTreeItemData()
88 //--------------------------------------------------------------------------
89 // wxHtmlHelpHashData (private)
90 //--------------------------------------------------------------------------
92 class wxHtmlHelpHashData
: public wxObject
95 wxHtmlHelpHashData(int index
, wxTreeItemId id
) : wxObject()
96 { m_Index
= index
; m_Id
= id
;}
97 ~wxHtmlHelpHashData() {}
104 //--------------------------------------------------------------------------
105 // wxHtmlHelpHtmlWindow (private)
106 //--------------------------------------------------------------------------
108 DEFINE_EVENT_TYPE(wxEVT_COMMAND_HTMLWINDOW_URL_CLICKED
)
109 IMPLEMENT_DYNAMIC_CLASS(wxHtmlWindowEvent
, wxNotifyEvent
)
111 class wxHtmlHelpHtmlWindow
: public wxHtmlWindow
114 wxHtmlHelpHtmlWindow(wxHtmlHelpWindow
*win
, wxWindow
*parent
)
115 : wxHtmlWindow(parent
), m_Window(win
)
120 virtual void OnLinkClicked(const wxHtmlLinkInfo
& link
)
122 wxHtmlWindowEvent
event(wxEVT_COMMAND_HTMLWINDOW_URL_CLICKED
, GetId());
123 event
.SetURL(link
.GetHref());
124 if (!ProcessEvent(event
))
126 wxHtmlWindow::OnLinkClicked(link
);
128 const wxMouseEvent
*e
= link
.GetEvent();
129 if (e
== NULL
|| e
->LeftUp())
130 m_Window
->NotifyPageChanged();
133 // Returns full location with anchor (helper)
134 static wxString
GetOpenedPageWithAnchor(wxHtmlWindow
*win
)
137 return wxEmptyString
;
139 wxString an
= win
->GetOpenedAnchor();
140 wxString pg
= win
->GetOpenedPage();
150 wxHtmlHelpWindow
*m_Window
;
152 DECLARE_NO_COPY_CLASS(wxHtmlHelpHtmlWindow
)
156 //---------------------------------------------------------------------------
157 // wxHtmlHelpWindow::m_mergedIndex
158 //---------------------------------------------------------------------------
160 WX_DEFINE_ARRAY_PTR(const wxHtmlHelpDataItem
*, wxHtmlHelpDataItemPtrArray
);
162 struct wxHtmlHelpMergedIndexItem
164 wxHtmlHelpMergedIndexItem
*parent
;
166 wxHtmlHelpDataItemPtrArray items
;
169 WX_DECLARE_OBJARRAY(wxHtmlHelpMergedIndexItem
, wxHtmlHelpMergedIndex
);
170 #include "wx/arrimpl.cpp"
171 WX_DEFINE_OBJARRAY(wxHtmlHelpMergedIndex
)
173 void wxHtmlHelpWindow::UpdateMergedIndex()
175 delete m_mergedIndex
;
176 m_mergedIndex
= new wxHtmlHelpMergedIndex
;
177 wxHtmlHelpMergedIndex
& merged
= *m_mergedIndex
;
179 const wxHtmlHelpDataItems
& items
= m_Data
->GetIndexArray();
180 size_t len
= items
.size();
182 wxHtmlHelpMergedIndexItem
*history
[128] = {NULL
};
184 for (size_t i
= 0; i
< len
; i
++)
186 const wxHtmlHelpDataItem
& item
= items
[i
];
187 wxASSERT_MSG( item
.level
< 128, _T("nested index entries too deep") );
189 if (history
[item
.level
] &&
190 history
[item
.level
]->items
[0]->name
== item
.name
)
192 // same index entry as previous one, update list of items
193 history
[item
.level
]->items
.Add(&item
);
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
;
208 //---------------------------------------------------------------------------
210 //---------------------------------------------------------------------------
212 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpWindow
, wxWindow
)
214 BEGIN_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
)
230 wxHtmlHelpWindow::wxHtmlHelpWindow(wxWindow
* parent
, wxWindowID id
,
233 int style
, int helpStyle
, wxHtmlHelpData
* data
)
236 Create(parent
, id
, pos
, size
, style
, helpStyle
);
239 void wxHtmlHelpWindow::Init(wxHtmlHelpData
* data
)
244 m_DataCreated
= false;
248 m_Data
= new wxHtmlHelpData();
249 m_DataCreated
= true;
256 m_ContentsBox
= NULL
;
258 m_IndexButton
= NULL
;
259 m_IndexButtonAll
= NULL
;
262 m_SearchButton
= NULL
;
264 m_SearchChoice
= NULL
;
265 m_IndexCountInfo
= NULL
;
268 m_NavigNotebook
= NULL
;
271 m_SearchCaseSensitive
= NULL
;
272 m_SearchWholeWords
= NULL
;
274 m_mergedIndex
= NULL
;
277 m_ConfigRoot
= wxEmptyString
;
279 m_Cfg
.x
= m_Cfg
.y
= wxDefaultCoord
;
283 m_Cfg
.navig_on
= true;
285 m_NormalFonts
= m_FixedFonts
= NULL
;
286 m_NormalFace
= m_FixedFace
= wxEmptyString
;
293 #if wxUSE_PRINTING_ARCHITECTURE
298 m_UpdateContents
= true;
300 m_helpController
= (wxHtmlHelpController
*) NULL
;
303 // Create: builds the GUI components.
304 // with the style flag it's possible to toggle the toolbar, contents, index and search
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)
312 bool wxHtmlHelpWindow::Create(wxWindow
* parent
, wxWindowID id
,
313 const wxPoint
& pos
, const wxSize
& size
,
314 int style
, int helpStyle
)
316 m_hfStyle
= helpStyle
;
318 wxImageList
*ContentsImageList
= new wxImageList(16, 16);
319 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK
,
322 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER
,
325 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE
,
329 // Do the config in two steps. We read the HtmlWindow customization after we
330 // create the window.
332 ReadCustomization(m_Config
, m_ConfigRoot
);
334 wxWindow::Create(parent
, id
, pos
, size
, style
, wxT("wxHtmlHelp"));
336 SetHelpText(_("Displays help as you browse the books on the left."));
338 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
340 int notebook_page
= 0;
342 // The sizer for the whole top-level window.
343 wxSizer
*topWindowSizer
= new wxBoxSizer(wxVERTICAL
);
344 SetSizer(topWindowSizer
);
349 if (helpStyle
& (wxHF_TOOLBAR
| wxHF_FLAT_TOOLBAR
))
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
);
358 topWindowSizer
->Add(toolBar
, 0, wxEXPAND
);
361 #endif //wxUSE_TOOLBAR
363 wxSizer
*navigSizer
= NULL
;
365 if (helpStyle
& (wxHF_CONTENTS
| wxHF_INDEX
| wxHF_SEARCH
))
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);
371 topWindowSizer
->Add(m_Splitter
, 1, wxEXPAND
);
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
);
378 navigSizer
= new wxBoxSizer(wxVERTICAL
);
379 navigSizer
->Add(m_NavigNotebook
, 1, wxEXPAND
);
381 m_NavigPan
->SetSizer(navigSizer
);
385 // only html window, no notebook with index,contents etc
386 m_HtmlWin
= new wxHtmlWindow(this);
387 topWindowSizer
->Add(m_HtmlWin
, 1, wxEXPAND
);
391 m_HtmlWin
->ReadCustomization(m_Config
, m_ConfigRoot
);
393 // contents tree panel?
394 if ( helpStyle
& wxHF_CONTENTS
)
396 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
397 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
399 topsizer
->Add(0, 10);
401 dummy
->SetSizer(topsizer
);
403 if ( helpStyle
& wxHF_BOOKMARKS
)
405 m_Bookmarks
= new wxComboBox(dummy
, wxID_HTML_BOOKMARKSLIST
,
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);
414 wxBitmapButton
*bmpbt1
, *bmpbt2
;
415 bmpbt1
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSADD
,
416 wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK
,
418 bmpbt2
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSREMOVE
,
419 wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK
,
422 bmpbt1
->SetToolTip(_("Add current page to bookmarks"));
423 bmpbt2
->SetToolTip(_("Remove current page from bookmarks"));
424 #endif // wxUSE_TOOLTIPS
426 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
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);
432 topsizer
->Add(sizer
, 0, wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
, 10);
435 m_ContentsBox
= new wxTreeCtrl(dummy
, wxID_HTML_TREECTRL
,
436 wxDefaultPosition
, wxDefaultSize
,
439 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
443 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
448 m_ContentsBox
->AssignImageList(ContentsImageList
);
450 topsizer
->Add(m_ContentsBox
, 1,
451 wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
,
454 m_NavigNotebook
->AddPage(dummy
, _("Contents"));
455 m_ContentsPage
= notebook_page
++;
458 // index listbox panel?
459 if ( helpStyle
& wxHF_INDEX
)
461 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
462 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
464 dummy
->SetSizer(topsizer
);
466 m_IndexText
= new wxTextCtrl(dummy
, wxID_HTML_INDEXTEXT
, wxEmptyString
,
467 wxDefaultPosition
, wxDefaultSize
,
469 m_IndexButton
= new wxButton(dummy
, wxID_HTML_INDEXBUTTON
, _("Find"));
470 m_IndexButtonAll
= new wxButton(dummy
, wxID_HTML_INDEXBUTTONALL
,
472 m_IndexCountInfo
= new wxStaticText(dummy
, wxID_HTML_COUNTINFO
,
473 wxEmptyString
, wxDefaultPosition
,
475 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
476 m_IndexList
= new wxListBox(dummy
, wxID_HTML_INDEXLIST
,
477 wxDefaultPosition
, wxDefaultSize
,
478 0, NULL
, wxLB_SINGLE
);
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
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);
494 m_NavigNotebook
->AddPage(dummy
, _("Index"));
495 m_IndexPage
= notebook_page
++;
498 // search list panel?
499 if ( helpStyle
& wxHF_SEARCH
)
501 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
502 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
504 dummy
->SetSizer(sizer
);
506 m_SearchText
= new wxTextCtrl(dummy
, wxID_HTML_SEARCHTEXT
,
508 wxDefaultPosition
, wxDefaultSize
,
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"));
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
);
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);
529 m_NavigNotebook
->AddPage(dummy
, _("Search"));
530 m_SearchPage
= notebook_page
;
539 navigSizer
->SetSizeHints(m_NavigPan
);
540 m_NavigPan
->Layout();
544 if ( m_NavigPan
&& m_Splitter
)
546 m_Splitter
->SetMinimumPaneSize(20);
547 if ( m_Cfg
.navig_on
)
548 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
550 if ( m_Cfg
.navig_on
)
553 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
557 m_NavigPan
->Show(false);
558 m_Splitter
->Initialize(m_HtmlWin
);
562 // Reduce flicker by updating the splitter pane sizes before the
564 wxSizeEvent
sizeEvent(GetSize(), GetId());
565 ProcessEvent(sizeEvent
);
568 m_Splitter
->UpdateSize();
573 wxHtmlHelpWindow::~wxHtmlHelpWindow()
575 delete m_mergedIndex
;
577 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
580 if (m_NormalFonts
) delete m_NormalFonts
;
581 if (m_FixedFonts
) delete m_FixedFonts
;
584 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
587 #if wxUSE_PRINTING_ARCHITECTURE
588 if (m_Printer
) delete m_Printer
;
592 void wxHtmlHelpWindow::SetController(wxHtmlHelpController
* controller
)
596 m_helpController
= controller
;
597 m_Data
= controller
->GetHelpData();
598 m_DataCreated
= false;
602 void wxHtmlHelpWindow::AddToolbarButtons(wxToolBar
*toolBar
, int style
)
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
);
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
);
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.")) ;
631 toolBar
->AddTool(wxID_HTML_PANEL
, wpanelBitmap
, wxNullBitmap
,
632 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
633 _("Show/hide navigation panel"));
635 toolBar
->AddSeparator();
636 toolBar
->AddTool(wxID_HTML_BACK
, wbackBitmap
, wxNullBitmap
,
637 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
639 toolBar
->AddTool(wxID_HTML_FORWARD
, wforwardBitmap
, wxNullBitmap
,
640 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
642 toolBar
->AddSeparator();
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
,
650 toolBar
->AddTool(wxID_HTML_DOWN
, wdownBitmap
, wxNullBitmap
,
651 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
654 if ((style
& wxHF_PRINT
) || (style
& wxHF_OPEN_FILES
))
655 toolBar
->AddSeparator();
657 if (style
& wxHF_OPEN_FILES
)
658 toolBar
->AddTool(wxID_HTML_OPENFILE
, wopenBitmap
, wxNullBitmap
,
659 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
660 _("Open HTML document"));
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"));
669 toolBar
->AddSeparator();
670 toolBar
->AddTool(wxID_HTML_OPTIONS
, woptionsBitmap
, wxNullBitmap
,
671 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
672 _("Display options dialog"));
674 // Allow application to add custom buttons
675 wxHtmlHelpFrame
* parentFrame
= wxDynamicCast(GetParent(), wxHtmlHelpFrame
);
676 wxHtmlHelpDialog
* parentDialog
= wxDynamicCast(GetParent(), wxHtmlHelpDialog
);
678 parentFrame
->AddToolbarButtons(toolBar
, style
);
680 parentDialog
->AddToolbarButtons(toolBar
, style
);
682 #endif //wxUSE_TOOLBAR
685 bool wxHtmlHelpWindow::Display(const wxString
& x
)
687 wxString url
= m_Data
->FindPageByName(x
);
690 m_HtmlWin
->LoadPage(url
);
698 bool wxHtmlHelpWindow::Display(const int id
)
700 wxString url
= m_Data
->FindPageById(id
);
703 m_HtmlWin
->LoadPage(url
);
711 bool wxHtmlHelpWindow::DisplayContents()
716 if (!m_Splitter
->IsSplit())
720 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
721 m_Cfg
.navig_on
= true;
724 m_NavigNotebook
->SetSelection(m_ContentsPage
);
726 if (m_Data
->GetBookRecArray().GetCount() > 0)
728 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
729 if (!book
.GetStart().empty())
730 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
736 bool wxHtmlHelpWindow::DisplayIndex()
741 if (!m_Splitter
->IsSplit())
745 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
748 m_NavigNotebook
->SetSelection(m_IndexPage
);
750 if (m_Data
->GetBookRecArray().GetCount() > 0)
752 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
753 if (!book
.GetStart().empty())
754 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
760 void wxHtmlHelpWindow::DisplayIndexItem(const wxHtmlHelpMergedIndexItem
*it
)
762 if (it
->items
.size() == 1)
764 if (!it
->items
[0]->page
.empty())
766 m_HtmlWin
->LoadPage(it
->items
[0]->GetFullPath());
772 wxBusyCursor busy_cursor
;
774 // more pages associated with this index item -- let the user choose
775 // which one she/he wants from a list:
777 size_t len
= it
->items
.size();
778 for (size_t i
= 0; i
< len
; i
++)
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
++)
786 if (contents
[j
].page
== page
)
788 page
= contents
[j
].name
;
795 wxSingleChoiceDialog
dlg(this,
796 _("Please choose the page to display:"),
798 arr
, NULL
, wxCHOICEDLG_STYLE
& ~wxCENTRE
);
799 if (dlg
.ShowModal() == wxID_OK
)
801 m_HtmlWin
->LoadPage(it
->items
[dlg
.GetSelection()]->GetFullPath());
807 bool wxHtmlHelpWindow::KeywordSearch(const wxString
& keyword
,
808 wxHelpSearchMode mode
)
810 if (mode
== wxHELP_SEARCH_ALL
)
812 if ( !(m_SearchList
&&
813 m_SearchButton
&& m_SearchText
&& m_SearchChoice
) )
816 else if (mode
== wxHELP_SEARCH_INDEX
)
818 if ( !(m_IndexList
&&
819 m_IndexButton
&& m_IndexButtonAll
&& m_IndexText
) )
825 wxString book
= wxEmptyString
;
827 if (!m_Splitter
->IsSplit())
831 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
834 if (mode
== wxHELP_SEARCH_ALL
)
836 m_NavigNotebook
->SetSelection(m_SearchPage
);
837 m_SearchList
->Clear();
838 m_SearchText
->SetValue(keyword
);
839 m_SearchButton
->Disable();
841 if (m_SearchChoice
->GetSelection() != 0)
842 book
= m_SearchChoice
->GetStringSelection();
844 wxHtmlSearchStatus
status(m_Data
, keyword
,
845 m_SearchCaseSensitive
->GetValue(),
846 m_SearchWholeWords
->GetValue(),
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
);
857 while (status
.IsActive())
859 curi
= status
.GetCurIndex();
861 #if wxUSE_PROGRESSDLG
862 && !progress
.Update(curi
)
868 foundstr
.Printf(_("Found %i matches"), ++foundcnt
);
869 #if wxUSE_PROGRESSDLG
870 progress
.Update(status
.GetCurIndex(), foundstr
);
872 m_SearchList
->Append(status
.GetName(), (void*)status
.GetCurItem());
876 m_SearchButton
->Enable();
877 m_SearchText
->SetSelection(0, keyword
.Length());
878 m_SearchText
->SetFocus();
880 else if (mode
== wxHELP_SEARCH_INDEX
)
882 m_NavigNotebook
->SetSelection(m_IndexPage
);
883 m_IndexList
->Clear();
884 m_IndexButton
->Disable();
885 m_IndexButtonAll
->Disable();
886 m_IndexText
->SetValue(keyword
);
888 wxCommandEvent dummy
;
889 OnIndexFind(dummy
); // what a hack...
890 m_IndexButton
->Enable();
891 m_IndexButtonAll
->Enable();
892 foundcnt
= m_IndexList
->GetCount();
900 wxFAIL_MSG( _T("unknown help search mode") );
903 case wxHELP_SEARCH_ALL
:
905 wxHtmlHelpDataItem
*it
=
906 (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(0);
909 m_HtmlWin
->LoadPage(it
->GetFullPath());
915 case wxHELP_SEARCH_INDEX
:
917 wxHtmlHelpMergedIndexItem
* it
=
918 (wxHtmlHelpMergedIndexItem
*) m_IndexList
->GetClientData(0);
920 DisplayIndexItem(it
);
930 void wxHtmlHelpWindow::CreateContents()
937 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
941 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
943 size_t cnt
= contents
.size();
945 m_PagesHash
= new wxHashTable(wxKEY_STRING
, 2 * cnt
);
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();
958 roots
[0] = m_ContentsBox
->AddRoot(_("(Help)"));
961 for (size_t i
= 0; i
< cnt
; i
++)
963 wxHtmlHelpDataItem
*it
= &contents
[i
];
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
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);
983 // ...and their contents:
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;
992 m_PagesHash
->Put(it
->GetFullPath(),
993 new wxHtmlHelpHashData(i
, roots
[it
->level
+ 1]));
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
])
999 int image
= IMG_Folder
;
1000 if (m_hfStyle
& wxHF_ICONS_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;
1012 void wxHtmlHelpWindow::CreateIndex()
1017 m_IndexList
->Clear();
1019 size_t cnt
= m_mergedIndex
->size();
1022 if (cnt
> INDEX_IS_SMALL
)
1023 cnttext
.Printf(_("%i of %i"), 0, cnt
);
1025 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1026 m_IndexCountInfo
->SetLabel(cnttext
);
1027 if (cnt
> INDEX_IS_SMALL
)
1030 for (size_t i
= 0; i
< cnt
; i
++)
1031 m_IndexList
->Append((*m_mergedIndex
)[i
].name
,
1032 (char*)(&(*m_mergedIndex
)[i
]));
1035 void wxHtmlHelpWindow::CreateSearch()
1037 if (! (m_SearchList
&& m_SearchChoice
))
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);
1049 void wxHtmlHelpWindow::RefreshLists()
1051 // Update m_mergedIndex:
1052 UpdateMergedIndex();
1053 // Update the controls
1059 void wxHtmlHelpWindow::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1064 if (path
!= wxEmptyString
)
1066 oldpath
= cfg
->GetPath();
1067 cfg
->SetPath(_T("/") + path
);
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
);
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
);
1086 cnt
= cfg
->Read(wxT("hcBookmarksCnt"), 0L);
1089 m_BookmarksNames
.Clear();
1090 m_BookmarksPages
.Clear();
1093 m_Bookmarks
->Clear();
1094 m_Bookmarks
->Append(_("(bookmarks)"));
1097 for (i
= 0; i
< cnt
; i
++)
1099 val
.Printf(wxT("hcBookmark_%i"), i
);
1101 m_BookmarksNames
.Add(s
);
1102 if (m_Bookmarks
) m_Bookmarks
->Append(s
);
1103 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1105 m_BookmarksPages
.Add(s
);
1111 m_HtmlWin
->ReadCustomization(cfg
);
1113 if (path
!= wxEmptyString
)
1114 cfg
->SetPath(oldpath
);
1117 void wxHtmlHelpWindow::WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1122 if (path
!= wxEmptyString
)
1124 oldpath
= cfg
->GetPath();
1125 cfg
->SetPath(_T("/") + path
);
1128 cfg
->Write(wxT("hcNavigPanel"), m_Cfg
.navig_on
);
1129 cfg
->Write(wxT("hcSashPos"), (long)m_Cfg
.sashpos
);
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
);
1138 cfg
->Write(wxT("hcFixedFace"), m_FixedFace
);
1139 cfg
->Write(wxT("hcNormalFace"), m_NormalFace
);
1140 cfg
->Write(wxT("hcBaseFontSize"), (long)m_FontSize
);
1145 int cnt
= m_BookmarksNames
.GetCount();
1148 cfg
->Write(wxT("hcBookmarksCnt"), (long)cnt
);
1149 for (i
= 0; i
< cnt
; i
++)
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
]);
1159 m_HtmlWin
->WriteCustomization(cfg
);
1161 if (path
!= wxEmptyString
)
1162 cfg
->SetPath(oldpath
);
1165 static void SetFontsToHtmlWin(wxHtmlWindow
*win
, const wxString
& scalf
, const wxString
& fixf
, int size
)
1168 f_sizes
[0] = int(size
* 0.6);
1169 f_sizes
[1] = int(size
* 0.8);
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);
1176 win
->SetFonts(scalf
, fixf
, f_sizes
);
1179 class wxHtmlHelpWindowOptionsDialog
: public wxDialog
1182 wxComboBox
*NormalFont
, *FixedFont
;
1183 wxSpinCtrl
*FontSize
;
1184 wxHtmlWindow
*TestWin
;
1186 wxHtmlHelpWindowOptionsDialog(wxWindow
*parent
)
1187 : wxDialog(parent
, wxID_ANY
, wxString(_("Help Browser Options")))
1189 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
1190 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2, 3, 2, 5);
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:")));
1196 sizer
->Add(NormalFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1197 wxSize(200, wxDefaultCoord
),
1198 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1200 sizer
->Add(FixedFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1201 wxSize(200, wxDefaultCoord
),
1202 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1204 sizer
->Add(FontSize
= new wxSpinCtrl(this, wxID_ANY
));
1205 FontSize
->SetRange(2, 100);
1207 topsizer
->Add(sizer
, 0, wxLEFT
|wxRIGHT
|wxTOP
, 10);
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);
1215 wxBoxSizer
*sizer2
= new wxBoxSizer(wxHORIZONTAL
);
1217 sizer2
->Add(ok
= new wxButton(this, wxID_OK
), 0, wxALL
, 10);
1219 sizer2
->Add(new wxButton(this, wxID_CANCEL
), 0, wxALL
, 10);
1220 topsizer
->Add(sizer2
, 0, wxALIGN_RIGHT
);
1223 topsizer
->Fit(this);
1228 void UpdateTestWin()
1231 SetFontsToHtmlWin(TestWin
,
1232 NormalFont
->GetStringSelection(),
1233 FixedFont
->GetStringSelection(),
1234 FontSize
->GetValue());
1236 wxString
content(_("font size"));
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>") ;
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>") +
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>") +
1256 _T("</tt></td></tr></table></body></html>");
1258 TestWin
->SetPage( content
);
1261 void OnUpdate(wxCommandEvent
& WXUNUSED(event
))
1265 void OnUpdateSpin(wxSpinEvent
& WXUNUSED(event
))
1270 DECLARE_EVENT_TABLE()
1271 DECLARE_NO_COPY_CLASS(wxHtmlHelpWindowOptionsDialog
)
1274 BEGIN_EVENT_TABLE(wxHtmlHelpWindowOptionsDialog
, wxDialog
)
1275 EVT_COMBOBOX(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdate
)
1276 EVT_SPINCTRL(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdateSpin
)
1279 void wxHtmlHelpWindow::OptionsDialog()
1281 wxHtmlHelpWindowOptionsDialog
dlg(this);
1284 if (m_NormalFonts
== NULL
)
1286 wxFontEnumerator enu
;
1287 enu
.EnumerateFacenames();
1288 m_NormalFonts
= new wxArrayString
;
1289 *m_NormalFonts
= *enu
.GetFacenames();
1290 m_NormalFonts
->Sort(); // ascending sort
1292 if (m_FixedFonts
== NULL
)
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
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())
1307 wxFont
fnt(m_FontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false);
1308 m_NormalFace
= fnt
.GetFaceName();
1310 if (m_FixedFace
.empty())
1312 wxFont
fnt(m_FontSize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false);
1313 m_FixedFace
= fnt
.GetFaceName();
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
);
1323 dlg
.NormalFont
->SetSelection(0);
1324 if (!m_FixedFace
.empty())
1325 dlg
.FixedFont
->SetStringSelection(m_FixedFace
);
1327 dlg
.FixedFont
->SetSelection(0);
1328 dlg
.FontSize
->SetValue(m_FontSize
);
1329 dlg
.UpdateTestWin();
1331 if (dlg
.ShowModal() == wxID_OK
)
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
);
1340 void wxHtmlHelpWindow::NotifyPageChanged()
1342 if (m_UpdateContents
&& m_PagesHash
)
1344 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1345 wxHtmlHelpHashData
*ha
= NULL
;
1347 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
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
;
1365 void wxHtmlHelpWindow::OnToolbar(wxCommandEvent
& event
)
1367 switch (event
.GetId())
1369 case wxID_HTML_BACK
:
1370 m_HtmlWin
->HistoryBack();
1371 NotifyPageChanged();
1374 case wxID_HTML_FORWARD
:
1375 m_HtmlWin
->HistoryForward();
1376 NotifyPageChanged();
1382 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1383 wxHtmlHelpHashData
*ha
= NULL
;
1385 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1386 if (ha
&& ha
->m_Index
> 0)
1388 const wxHtmlHelpDataItem
& it
= m_Data
->GetContentsArray()[ha
->m_Index
- 1];
1389 if (!it
.page
.empty())
1391 m_HtmlWin
->LoadPage(it
.GetFullPath());
1392 NotifyPageChanged();
1398 case wxID_HTML_UPNODE
:
1401 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1402 wxHtmlHelpHashData
*ha
= NULL
;
1404 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1405 if (ha
&& ha
->m_Index
> 0)
1408 m_Data
->GetContentsArray()[ha
->m_Index
].level
- 1;
1409 int ind
= ha
->m_Index
- 1;
1411 const wxHtmlHelpDataItem
*it
=
1412 &m_Data
->GetContentsArray()[ind
];
1413 while (ind
>= 0 && it
->level
!= level
)
1416 it
= &m_Data
->GetContentsArray()[ind
];
1420 if (!it
->page
.empty())
1422 m_HtmlWin
->LoadPage(it
->GetFullPath());
1423 NotifyPageChanged();
1430 case wxID_HTML_DOWN
:
1433 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1434 wxHtmlHelpHashData
*ha
= NULL
;
1436 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1438 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1439 if (ha
&& ha
->m_Index
< (int)contents
.size() - 1)
1441 size_t idx
= ha
->m_Index
+ 1;
1443 while (contents
[idx
].GetFullPath() == page
) idx
++;
1445 if (!contents
[idx
].page
.empty())
1447 m_HtmlWin
->LoadPage(contents
[idx
].GetFullPath());
1448 NotifyPageChanged();
1454 case wxID_HTML_PANEL
:
1456 if (! (m_Splitter
&& m_NavigPan
))
1458 if (m_Splitter
->IsSplit())
1460 m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1461 m_Splitter
->Unsplit(m_NavigPan
);
1462 m_Cfg
.navig_on
= false;
1468 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
1469 m_Cfg
.navig_on
= true;
1474 case wxID_HTML_OPTIONS
:
1478 case wxID_HTML_BOOKMARKSADD
:
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
)
1489 m_Bookmarks
->Append(item
);
1490 m_BookmarksNames
.Add(item
);
1491 m_BookmarksPages
.Add(url
);
1496 case wxID_HTML_BOOKMARKSREMOVE
:
1501 item
= m_Bookmarks
->GetStringSelection();
1502 pos
= m_BookmarksNames
.Index(item
);
1503 if (pos
!= wxNOT_FOUND
)
1505 m_BookmarksNames
.RemoveAt(pos
);
1506 m_BookmarksPages
.RemoveAt(pos
);
1507 m_Bookmarks
->Delete(m_Bookmarks
->GetSelection());
1512 #if wxUSE_PRINTING_ARCHITECTURE
1513 case wxID_HTML_PRINT
:
1515 if (m_Printer
== NULL
)
1516 m_Printer
= new wxHtmlEasyPrinting(_("Help Printing"), this);
1517 if (!m_HtmlWin
->GetOpenedPage())
1518 wxLogWarning(_("Cannot print empty page."));
1520 m_Printer
->PrintFile(m_HtmlWin
->GetOpenedPage());
1525 case wxID_HTML_OPENFILE
:
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|") +
1532 _("Compressed HTML Help file (*.chm)|*.chm|") +
1534 _("All files (*.*)|*");
1535 wxString s
= wxFileSelector(_("Open HTML document"),
1540 wxOPEN
| wxFILE_MUST_EXIST
,
1544 wxString ext
= s
.Right(4).Lower();
1545 if (ext
== _T(".zip") || ext
== _T(".htb") ||
1547 ext
== _T(".chm") ||
1556 m_HtmlWin
->LoadPage(s
);
1563 void wxHtmlHelpWindow::OnContentsSel(wxTreeEvent
& event
)
1565 wxHtmlHelpTreeItemData
*pg
;
1567 pg
= (wxHtmlHelpTreeItemData
*) m_ContentsBox
->GetItemData(event
.GetItem());
1569 if (pg
&& m_UpdateContents
)
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;
1579 void wxHtmlHelpWindow::OnIndexSel(wxCommandEvent
& WXUNUSED(event
))
1581 wxHtmlHelpMergedIndexItem
*it
= (wxHtmlHelpMergedIndexItem
*)
1582 m_IndexList
->GetClientData(m_IndexList
->GetSelection());
1584 DisplayIndexItem(it
);
1587 void wxHtmlHelpWindow::OnIndexFind(wxCommandEvent
& event
)
1589 wxString sr
= m_IndexText
->GetLineText(0);
1591 if (sr
== wxEmptyString
)
1599 m_IndexList
->Clear();
1600 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1601 size_t cnt
= index
.size();
1604 for (size_t i
= 0; i
< cnt
; i
++)
1606 if (index
[i
].name
.Lower().find(sr
) != wxString::npos
)
1608 int pos
= m_IndexList
->Append(index
[i
].name
,
1609 (char*)(&index
[i
]));
1613 // don't automatically show topic selector if this
1614 // item points to multiple pages:
1615 if (index
[i
].items
.size() == 1)
1617 m_IndexList
->SetSelection(0);
1618 DisplayIndexItem(&index
[i
]);
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
1625 wxHtmlHelpMergedIndexItem
*parent
= index
[i
].parent
;
1629 (index
.Index(*(wxHtmlHelpMergedIndexItem
*)m_IndexList
->GetClientData(pos
-1))) < index
.Index(*parent
))
1631 m_IndexList
->Insert(parent
->name
,
1632 pos
, (char*)parent
);
1633 parent
= parent
->parent
;
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
;
1644 while (i
< cnt
&& index
[i
].items
[0]->level
> level
)
1646 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1654 cnttext
.Printf(_("%i of %i"), displ
, cnt
);
1655 m_IndexCountInfo
->SetLabel(cnttext
);
1657 m_IndexText
->SetSelection(0, sr
.Length());
1658 m_IndexText
->SetFocus();
1662 void wxHtmlHelpWindow::OnIndexAll(wxCommandEvent
& WXUNUSED(event
))
1666 m_IndexList
->Clear();
1667 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1668 size_t cnt
= index
.size();
1671 for (size_t i
= 0; i
< cnt
; i
++)
1673 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1676 // don't automatically show topic selector if this
1677 // item points to multiple pages:
1678 if (index
[i
].items
.size() == 1)
1680 DisplayIndexItem(&index
[i
]);
1687 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1688 m_IndexCountInfo
->SetLabel(cnttext
);
1691 void wxHtmlHelpWindow::OnSearchSel(wxCommandEvent
& WXUNUSED(event
))
1693 wxHtmlHelpDataItem
*it
= (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(m_SearchList
->GetSelection());
1696 if (!it
->page
.empty())
1697 m_HtmlWin
->LoadPage(it
->GetFullPath());
1698 NotifyPageChanged();
1702 void wxHtmlHelpWindow::OnSearch(wxCommandEvent
& WXUNUSED(event
))
1704 wxString sr
= m_SearchText
->GetLineText(0);
1707 KeywordSearch(sr
, wxHELP_SEARCH_ALL
);
1710 void wxHtmlHelpWindow::OnBookmarksSel(wxCommandEvent
& WXUNUSED(event
))
1712 wxString sr
= m_Bookmarks
->GetStringSelection();
1714 if (sr
!= wxEmptyString
&& sr
!= _("(bookmarks)"))
1716 m_HtmlWin
->LoadPage(m_BookmarksPages
[m_BookmarksNames
.Index(sr
)]);
1717 NotifyPageChanged();
1721 void wxHtmlHelpWindow::OnSize(wxSizeEvent
& WXUNUSED(event
))
1726 #endif // wxUSE_WXHTML_HELP