1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/helpwnd.cpp
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, wxID_ANY
, 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
);
889 m_IndexButton
->Enable();
890 m_IndexButtonAll
->Enable();
891 foundcnt
= m_IndexList
->GetCount();
899 wxFAIL_MSG( _T("unknown help search mode") );
902 case wxHELP_SEARCH_ALL
:
904 wxHtmlHelpDataItem
*it
=
905 (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(0);
908 m_HtmlWin
->LoadPage(it
->GetFullPath());
914 case wxHELP_SEARCH_INDEX
:
916 wxHtmlHelpMergedIndexItem
* it
=
917 (wxHtmlHelpMergedIndexItem
*) m_IndexList
->GetClientData(0);
919 DisplayIndexItem(it
);
929 void wxHtmlHelpWindow::CreateContents()
936 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
940 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
942 size_t cnt
= contents
.size();
944 m_PagesHash
= new wxHashTable(wxKEY_STRING
, 2 * cnt
);
946 const int MAX_ROOTS
= 64;
947 wxTreeItemId roots
[MAX_ROOTS
];
948 // VS: this array holds information about whether we've set item icon at
949 // given level. This is necessary because m_Data has a flat structure
950 // and there's no way of recognizing if some item has subitems or not.
951 // We set the icon later: when we find an item with level=n, we know
952 // that the last item with level=n-1 was afolder with subitems, so we
953 // set its icon accordingly
954 bool imaged
[MAX_ROOTS
];
955 m_ContentsBox
->DeleteAllItems();
957 roots
[0] = m_ContentsBox
->AddRoot(_("(Help)"));
960 for (size_t i
= 0; i
< cnt
; i
++)
962 wxHtmlHelpDataItem
*it
= &contents
[i
];
966 if (m_hfStyle
& wxHF_MERGE_BOOKS
)
967 // VS: we don't want book nodes, books' content should
968 // appear under tree's root. This line will create a "fake"
969 // record about book node so that the rest of this look
970 // will believe there really _is_ a book node and will
975 roots
[1] = m_ContentsBox
->AppendItem(roots
[0],
976 it
->name
, IMG_Book
, -1,
977 new wxHtmlHelpTreeItemData(i
));
978 m_ContentsBox
->SetItemBold(roots
[1], true);
982 // ...and their contents:
985 roots
[it
->level
+ 1] = m_ContentsBox
->AppendItem(
986 roots
[it
->level
], it
->name
, IMG_Page
,
987 -1, new wxHtmlHelpTreeItemData(i
));
988 imaged
[it
->level
+ 1] = false;
991 m_PagesHash
->Put(it
->GetFullPath(),
992 new wxHtmlHelpHashData(i
, roots
[it
->level
+ 1]));
994 // Set the icon for the node one level up in the hierarchy,
995 // unless already done (see comment above imaged[] declaration)
996 if (!imaged
[it
->level
])
998 int image
= IMG_Folder
;
999 if (m_hfStyle
& wxHF_ICONS_BOOK
)
1001 else if (m_hfStyle
& wxHF_ICONS_BOOK_CHAPTER
)
1002 image
= (it
->level
== 1) ? IMG_Book
: IMG_Folder
;
1003 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
);
1004 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
,
1005 wxTreeItemIcon_Selected
);
1006 imaged
[it
->level
] = true;
1011 void wxHtmlHelpWindow::CreateIndex()
1016 m_IndexList
->Clear();
1018 size_t cnt
= m_mergedIndex
->size();
1021 if (cnt
> INDEX_IS_SMALL
)
1022 cnttext
.Printf(_("%i of %i"), 0, cnt
);
1024 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1025 m_IndexCountInfo
->SetLabel(cnttext
);
1026 if (cnt
> INDEX_IS_SMALL
)
1029 for (size_t i
= 0; i
< cnt
; i
++)
1030 m_IndexList
->Append((*m_mergedIndex
)[i
].name
,
1031 (char*)(&(*m_mergedIndex
)[i
]));
1034 void wxHtmlHelpWindow::CreateSearch()
1036 if (! (m_SearchList
&& m_SearchChoice
))
1038 m_SearchList
->Clear();
1039 m_SearchChoice
->Clear();
1040 m_SearchChoice
->Append(_("Search in all books"));
1041 const wxHtmlBookRecArray
& bookrec
= m_Data
->GetBookRecArray();
1042 int i
, cnt
= bookrec
.GetCount();
1043 for (i
= 0; i
< cnt
; i
++)
1044 m_SearchChoice
->Append(bookrec
[i
].GetTitle());
1045 m_SearchChoice
->SetSelection(0);
1048 void wxHtmlHelpWindow::RefreshLists()
1050 // Update m_mergedIndex:
1051 UpdateMergedIndex();
1052 // Update the controls
1058 void wxHtmlHelpWindow::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1063 if (path
!= wxEmptyString
)
1065 oldpath
= cfg
->GetPath();
1066 cfg
->SetPath(_T("/") + path
);
1069 m_Cfg
.navig_on
= cfg
->Read(wxT("hcNavigPanel"), m_Cfg
.navig_on
) != 0;
1070 m_Cfg
.sashpos
= cfg
->Read(wxT("hcSashPos"), m_Cfg
.sashpos
);
1071 m_Cfg
.x
= cfg
->Read(wxT("hcX"), m_Cfg
.x
);
1072 m_Cfg
.y
= cfg
->Read(wxT("hcY"), m_Cfg
.y
);
1073 m_Cfg
.w
= cfg
->Read(wxT("hcW"), m_Cfg
.w
);
1074 m_Cfg
.h
= cfg
->Read(wxT("hcH"), m_Cfg
.h
);
1076 m_FixedFace
= cfg
->Read(wxT("hcFixedFace"), m_FixedFace
);
1077 m_NormalFace
= cfg
->Read(wxT("hcNormalFace"), m_NormalFace
);
1078 m_FontSize
= cfg
->Read(wxT("hcBaseFontSize"), m_FontSize
);
1085 cnt
= cfg
->Read(wxT("hcBookmarksCnt"), 0L);
1088 m_BookmarksNames
.Clear();
1089 m_BookmarksPages
.Clear();
1092 m_Bookmarks
->Clear();
1093 m_Bookmarks
->Append(_("(bookmarks)"));
1096 for (i
= 0; i
< cnt
; i
++)
1098 val
.Printf(wxT("hcBookmark_%i"), i
);
1100 m_BookmarksNames
.Add(s
);
1101 if (m_Bookmarks
) m_Bookmarks
->Append(s
);
1102 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1104 m_BookmarksPages
.Add(s
);
1110 m_HtmlWin
->ReadCustomization(cfg
);
1112 if (path
!= wxEmptyString
)
1113 cfg
->SetPath(oldpath
);
1116 void wxHtmlHelpWindow::WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1121 if (path
!= wxEmptyString
)
1123 oldpath
= cfg
->GetPath();
1124 cfg
->SetPath(_T("/") + path
);
1127 cfg
->Write(wxT("hcNavigPanel"), m_Cfg
.navig_on
);
1128 cfg
->Write(wxT("hcSashPos"), (long)m_Cfg
.sashpos
);
1130 // Don't write if iconized as this would make the window
1131 // disappear next time it is shown!
1132 cfg
->Write(wxT("hcX"), (long)m_Cfg
.x
);
1133 cfg
->Write(wxT("hcY"), (long)m_Cfg
.y
);
1134 cfg
->Write(wxT("hcW"), (long)m_Cfg
.w
);
1135 cfg
->Write(wxT("hcH"), (long)m_Cfg
.h
);
1137 cfg
->Write(wxT("hcFixedFace"), m_FixedFace
);
1138 cfg
->Write(wxT("hcNormalFace"), m_NormalFace
);
1139 cfg
->Write(wxT("hcBaseFontSize"), (long)m_FontSize
);
1144 int cnt
= m_BookmarksNames
.GetCount();
1147 cfg
->Write(wxT("hcBookmarksCnt"), (long)cnt
);
1148 for (i
= 0; i
< cnt
; i
++)
1150 val
.Printf(wxT("hcBookmark_%i"), i
);
1151 cfg
->Write(val
, m_BookmarksNames
[i
]);
1152 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1153 cfg
->Write(val
, m_BookmarksPages
[i
]);
1158 m_HtmlWin
->WriteCustomization(cfg
);
1160 if (path
!= wxEmptyString
)
1161 cfg
->SetPath(oldpath
);
1164 static void SetFontsToHtmlWin(wxHtmlWindow
*win
, const wxString
& scalf
, const wxString
& fixf
, int size
)
1167 f_sizes
[0] = int(size
* 0.6);
1168 f_sizes
[1] = int(size
* 0.8);
1170 f_sizes
[3] = int(size
* 1.2);
1171 f_sizes
[4] = int(size
* 1.4);
1172 f_sizes
[5] = int(size
* 1.6);
1173 f_sizes
[6] = int(size
* 1.8);
1175 win
->SetFonts(scalf
, fixf
, f_sizes
);
1178 class wxHtmlHelpWindowOptionsDialog
: public wxDialog
1181 wxComboBox
*NormalFont
, *FixedFont
;
1182 wxSpinCtrl
*FontSize
;
1183 wxHtmlWindow
*TestWin
;
1185 wxHtmlHelpWindowOptionsDialog(wxWindow
*parent
)
1186 : wxDialog(parent
, wxID_ANY
, wxString(_("Help Browser Options")))
1188 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
1189 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2, 3, 2, 5);
1191 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Normal font:")));
1192 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Fixed font:")));
1193 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Font size:")));
1195 sizer
->Add(NormalFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1196 wxSize(200, wxDefaultCoord
),
1197 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1199 sizer
->Add(FixedFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1200 wxSize(200, wxDefaultCoord
),
1201 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1203 sizer
->Add(FontSize
= new wxSpinCtrl(this, wxID_ANY
));
1204 FontSize
->SetRange(2, 100);
1206 topsizer
->Add(sizer
, 0, wxLEFT
|wxRIGHT
|wxTOP
, 10);
1208 topsizer
->Add(new wxStaticText(this, wxID_ANY
, _("Preview:")),
1209 0, wxLEFT
| wxTOP
, 10);
1210 topsizer
->Add(TestWin
= new wxHtmlWindow(this, wxID_ANY
, wxDefaultPosition
, wxSize(20, 150),
1211 wxHW_SCROLLBAR_AUTO
| wxSUNKEN_BORDER
),
1212 1, wxEXPAND
| wxLEFT
|wxTOP
|wxRIGHT
, 10);
1214 wxBoxSizer
*sizer2
= new wxBoxSizer(wxHORIZONTAL
);
1216 sizer2
->Add(ok
= new wxButton(this, wxID_OK
), 0, wxALL
, 10);
1218 sizer2
->Add(new wxButton(this, wxID_CANCEL
), 0, wxALL
, 10);
1219 topsizer
->Add(sizer2
, 0, wxALIGN_RIGHT
);
1222 topsizer
->Fit(this);
1227 void UpdateTestWin()
1230 SetFontsToHtmlWin(TestWin
,
1231 NormalFont
->GetStringSelection(),
1232 FixedFont
->GetStringSelection(),
1233 FontSize
->GetValue());
1235 wxString
content(_("font size"));
1237 content
= _T("<font size=-2>") + content
+ _T(" -2</font><br>")
1238 _T("<font size=-1>") + content
+ _T(" -1</font><br>")
1239 _T("<font size=+0>") + content
+ _T(" +0</font><br>")
1240 _T("<font size=+1>") + content
+ _T(" +1</font><br>")
1241 _T("<font size=+2>") + content
+ _T(" +2</font><br>")
1242 _T("<font size=+3>") + content
+ _T(" +3</font><br>")
1243 _T("<font size=+4>") + content
+ _T(" +4</font><br>") ;
1245 content
= wxString( _T("<html><body><table><tr><td>") ) +
1246 _("Normal face<br>and <u>underlined</u>. ") +
1247 _("<i>Italic face.</i> ") +
1248 _("<b>Bold face.</b> ") +
1249 _("<b><i>Bold italic face.</i></b><br>") +
1251 wxString( _T("</td><td><tt>") ) +
1252 _("Fixed size face.<br> <b>bold</b> <i>italic</i> ") +
1253 _("<b><i>bold italic <u>underlined</u></i></b><br>") +
1255 _T("</tt></td></tr></table></body></html>");
1257 TestWin
->SetPage( content
);
1260 void OnUpdate(wxCommandEvent
& WXUNUSED(event
))
1264 void OnUpdateSpin(wxSpinEvent
& WXUNUSED(event
))
1269 DECLARE_EVENT_TABLE()
1270 DECLARE_NO_COPY_CLASS(wxHtmlHelpWindowOptionsDialog
)
1273 BEGIN_EVENT_TABLE(wxHtmlHelpWindowOptionsDialog
, wxDialog
)
1274 EVT_COMBOBOX(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdate
)
1275 EVT_SPINCTRL(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdateSpin
)
1278 void wxHtmlHelpWindow::OptionsDialog()
1280 wxHtmlHelpWindowOptionsDialog
dlg(this);
1283 if (m_NormalFonts
== NULL
)
1285 wxFontEnumerator enu
;
1286 enu
.EnumerateFacenames();
1287 m_NormalFonts
= new wxArrayString
;
1288 *m_NormalFonts
= *enu
.GetFacenames();
1289 m_NormalFonts
->Sort(); // ascending sort
1291 if (m_FixedFonts
== NULL
)
1293 wxFontEnumerator enu
;
1294 enu
.EnumerateFacenames(wxFONTENCODING_SYSTEM
, true /*enum fixed width only*/);
1295 m_FixedFonts
= new wxArrayString
;
1296 *m_FixedFonts
= *enu
.GetFacenames();
1297 m_FixedFonts
->Sort(); // ascending sort
1300 // VS: We want to show the font that is actually used by wxHtmlWindow.
1301 // If customization dialog wasn't used yet, facenames are empty and
1302 // wxHtmlWindow uses default fonts -- let's find out what they
1303 // are so that we can pass them to the dialog:
1304 if (m_NormalFace
.empty())
1306 wxFont
fnt(m_FontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false);
1307 m_NormalFace
= fnt
.GetFaceName();
1309 if (m_FixedFace
.empty())
1311 wxFont
fnt(m_FontSize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false);
1312 m_FixedFace
= fnt
.GetFaceName();
1315 for (i
= 0; i
< m_NormalFonts
->GetCount(); i
++)
1316 dlg
.NormalFont
->Append((*m_NormalFonts
)[i
]);
1317 for (i
= 0; i
< m_FixedFonts
->GetCount(); i
++)
1318 dlg
.FixedFont
->Append((*m_FixedFonts
)[i
]);
1319 if (!m_NormalFace
.empty())
1320 dlg
.NormalFont
->SetStringSelection(m_NormalFace
);
1322 dlg
.NormalFont
->SetSelection(0);
1323 if (!m_FixedFace
.empty())
1324 dlg
.FixedFont
->SetStringSelection(m_FixedFace
);
1326 dlg
.FixedFont
->SetSelection(0);
1327 dlg
.FontSize
->SetValue(m_FontSize
);
1328 dlg
.UpdateTestWin();
1330 if (dlg
.ShowModal() == wxID_OK
)
1332 m_NormalFace
= dlg
.NormalFont
->GetStringSelection();
1333 m_FixedFace
= dlg
.FixedFont
->GetStringSelection();
1334 m_FontSize
= dlg
.FontSize
->GetValue();
1335 SetFontsToHtmlWin(m_HtmlWin
, m_NormalFace
, m_FixedFace
, m_FontSize
);
1339 void wxHtmlHelpWindow::NotifyPageChanged()
1341 if (m_UpdateContents
&& m_PagesHash
)
1343 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1344 wxHtmlHelpHashData
*ha
= NULL
;
1346 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1350 bool olduc
= m_UpdateContents
;
1351 m_UpdateContents
= false;
1352 m_ContentsBox
->SelectItem(ha
->m_Id
);
1353 m_ContentsBox
->EnsureVisible(ha
->m_Id
);
1354 m_UpdateContents
= olduc
;
1364 void wxHtmlHelpWindow::OnToolbar(wxCommandEvent
& event
)
1366 switch (event
.GetId())
1368 case wxID_HTML_BACK
:
1369 m_HtmlWin
->HistoryBack();
1370 NotifyPageChanged();
1373 case wxID_HTML_FORWARD
:
1374 m_HtmlWin
->HistoryForward();
1375 NotifyPageChanged();
1381 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1382 wxHtmlHelpHashData
*ha
= NULL
;
1384 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1385 if (ha
&& ha
->m_Index
> 0)
1387 const wxHtmlHelpDataItem
& it
= m_Data
->GetContentsArray()[ha
->m_Index
- 1];
1388 if (!it
.page
.empty())
1390 m_HtmlWin
->LoadPage(it
.GetFullPath());
1391 NotifyPageChanged();
1397 case wxID_HTML_UPNODE
:
1400 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1401 wxHtmlHelpHashData
*ha
= NULL
;
1403 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1404 if (ha
&& ha
->m_Index
> 0)
1407 m_Data
->GetContentsArray()[ha
->m_Index
].level
- 1;
1408 int ind
= ha
->m_Index
- 1;
1410 const wxHtmlHelpDataItem
*it
=
1411 &m_Data
->GetContentsArray()[ind
];
1412 while (ind
>= 0 && it
->level
!= level
)
1415 it
= &m_Data
->GetContentsArray()[ind
];
1419 if (!it
->page
.empty())
1421 m_HtmlWin
->LoadPage(it
->GetFullPath());
1422 NotifyPageChanged();
1429 case wxID_HTML_DOWN
:
1432 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1433 wxHtmlHelpHashData
*ha
= NULL
;
1435 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1437 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1438 if (ha
&& ha
->m_Index
< (int)contents
.size() - 1)
1440 size_t idx
= ha
->m_Index
+ 1;
1442 while (contents
[idx
].GetFullPath() == page
) idx
++;
1444 if (!contents
[idx
].page
.empty())
1446 m_HtmlWin
->LoadPage(contents
[idx
].GetFullPath());
1447 NotifyPageChanged();
1453 case wxID_HTML_PANEL
:
1455 if (! (m_Splitter
&& m_NavigPan
))
1457 if (m_Splitter
->IsSplit())
1459 m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1460 m_Splitter
->Unsplit(m_NavigPan
);
1461 m_Cfg
.navig_on
= false;
1467 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
1468 m_Cfg
.navig_on
= true;
1473 case wxID_HTML_OPTIONS
:
1477 case wxID_HTML_BOOKMARKSADD
:
1482 item
= m_HtmlWin
->GetOpenedPageTitle();
1483 url
= m_HtmlWin
->GetOpenedPage();
1484 if (item
== wxEmptyString
)
1485 item
= url
.AfterLast(wxT('/'));
1486 if (m_BookmarksPages
.Index(url
) == wxNOT_FOUND
)
1488 m_Bookmarks
->Append(item
);
1489 m_BookmarksNames
.Add(item
);
1490 m_BookmarksPages
.Add(url
);
1495 case wxID_HTML_BOOKMARKSREMOVE
:
1500 item
= m_Bookmarks
->GetStringSelection();
1501 pos
= m_BookmarksNames
.Index(item
);
1502 if (pos
!= wxNOT_FOUND
)
1504 m_BookmarksNames
.RemoveAt(pos
);
1505 m_BookmarksPages
.RemoveAt(pos
);
1506 m_Bookmarks
->Delete(m_Bookmarks
->GetSelection());
1511 #if wxUSE_PRINTING_ARCHITECTURE
1512 case wxID_HTML_PRINT
:
1514 if (m_Printer
== NULL
)
1515 m_Printer
= new wxHtmlEasyPrinting(_("Help Printing"), this);
1516 if (!m_HtmlWin
->GetOpenedPage())
1517 wxLogWarning(_("Cannot print empty page."));
1519 m_Printer
->PrintFile(m_HtmlWin
->GetOpenedPage());
1524 case wxID_HTML_OPENFILE
:
1526 wxString filemask
= wxString(
1527 _("HTML files (*.html;*.htm)|*.html;*.htm|")) +
1528 _("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|") +
1529 _("HTML Help Project (*.hhp)|*.hhp|") +
1531 _("Compressed HTML Help file (*.chm)|*.chm|") +
1533 _("All files (*.*)|*");
1534 wxString s
= wxFileSelector(_("Open HTML document"),
1539 wxOPEN
| wxFILE_MUST_EXIST
,
1543 wxString ext
= s
.Right(4).Lower();
1544 if (ext
== _T(".zip") || ext
== _T(".htb") ||
1546 ext
== _T(".chm") ||
1555 m_HtmlWin
->LoadPage(s
);
1562 void wxHtmlHelpWindow::OnContentsSel(wxTreeEvent
& event
)
1564 wxHtmlHelpTreeItemData
*pg
;
1566 pg
= (wxHtmlHelpTreeItemData
*) m_ContentsBox
->GetItemData(event
.GetItem());
1568 if (pg
&& m_UpdateContents
)
1570 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1571 m_UpdateContents
= false;
1572 if (!contents
[pg
->m_Id
].page
.empty())
1573 m_HtmlWin
->LoadPage(contents
[pg
->m_Id
].GetFullPath());
1574 m_UpdateContents
= true;
1578 void wxHtmlHelpWindow::OnIndexSel(wxCommandEvent
& WXUNUSED(event
))
1580 wxHtmlHelpMergedIndexItem
*it
= (wxHtmlHelpMergedIndexItem
*)
1581 m_IndexList
->GetClientData(m_IndexList
->GetSelection());
1583 DisplayIndexItem(it
);
1586 void wxHtmlHelpWindow::OnIndexFind(wxCommandEvent
& WXUNUSED(event
))
1591 void wxHtmlHelpWindow::DoIndexFind()
1593 wxString sr
= m_IndexText
->GetLineText(0);
1595 if (sr
== wxEmptyString
)
1603 m_IndexList
->Clear();
1604 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1605 size_t cnt
= index
.size();
1608 for (size_t i
= 0; i
< cnt
; i
++)
1610 if (index
[i
].name
.Lower().find(sr
) != wxString::npos
)
1612 int pos
= m_IndexList
->Append(index
[i
].name
,
1613 (char*)(&index
[i
]));
1617 // don't automatically show topic selector if this
1618 // item points to multiple pages:
1619 if (index
[i
].items
.size() == 1)
1621 m_IndexList
->SetSelection(0);
1622 DisplayIndexItem(&index
[i
]);
1626 // if this is nested item of the index, show its parent(s)
1627 // as well, otherwise it would not be clear what entry is
1629 wxHtmlHelpMergedIndexItem
*parent
= index
[i
].parent
;
1633 (index
.Index(*(wxHtmlHelpMergedIndexItem
*)m_IndexList
->GetClientData(pos
-1))) < index
.Index(*parent
))
1635 m_IndexList
->Insert(parent
->name
,
1636 pos
, (char*)parent
);
1637 parent
= parent
->parent
;
1642 // finally, it the item we just added is itself a parent for
1643 // other items, show them as well, because they are refinements
1644 // of the displayed index entry (i.e. it is implicitly contained
1645 // in them: "foo" with parent "bar" reads as "bar, foo"):
1646 int level
= index
[i
].items
[0]->level
;
1648 while (i
< cnt
&& index
[i
].items
[0]->level
> level
)
1650 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1658 cnttext
.Printf(_("%i of %i"), displ
, cnt
);
1659 m_IndexCountInfo
->SetLabel(cnttext
);
1661 m_IndexText
->SetSelection(0, sr
.length());
1662 m_IndexText
->SetFocus();
1666 void wxHtmlHelpWindow::OnIndexAll(wxCommandEvent
& WXUNUSED(event
))
1671 void wxHtmlHelpWindow::DoIndexAll()
1675 m_IndexList
->Clear();
1676 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1677 size_t cnt
= index
.size();
1680 for (size_t i
= 0; i
< cnt
; i
++)
1682 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1685 // don't automatically show topic selector if this
1686 // item points to multiple pages:
1687 if (index
[i
].items
.size() == 1)
1689 DisplayIndexItem(&index
[i
]);
1696 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1697 m_IndexCountInfo
->SetLabel(cnttext
);
1700 void wxHtmlHelpWindow::OnSearchSel(wxCommandEvent
& WXUNUSED(event
))
1702 wxHtmlHelpDataItem
*it
= (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(m_SearchList
->GetSelection());
1705 if (!it
->page
.empty())
1706 m_HtmlWin
->LoadPage(it
->GetFullPath());
1707 NotifyPageChanged();
1711 void wxHtmlHelpWindow::OnSearch(wxCommandEvent
& WXUNUSED(event
))
1713 wxString sr
= m_SearchText
->GetLineText(0);
1716 KeywordSearch(sr
, wxHELP_SEARCH_ALL
);
1719 void wxHtmlHelpWindow::OnBookmarksSel(wxCommandEvent
& WXUNUSED(event
))
1721 wxString sr
= m_Bookmarks
->GetStringSelection();
1723 if (sr
!= wxEmptyString
&& sr
!= _("(bookmarks)"))
1725 m_HtmlWin
->LoadPage(m_BookmarksPages
[m_BookmarksNames
.Index(sr
)]);
1726 NotifyPageChanged();
1730 void wxHtmlHelpWindow::OnSize(wxSizeEvent
& WXUNUSED(event
))
1735 #endif // wxUSE_WXHTML_HELP