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"
23 #include "wx/object.h"
24 #include "wx/dynarray.h"
28 #include "wx/stream.h"
33 #include "wx/bmpbuttn.h"
34 #include "wx/statbox.h"
35 #include "wx/radiobox.h"
40 #include "wx/msgdlg.h"
43 #include "wx/html/helpfrm.h"
44 #include "wx/html/helpdlg.h"
45 #include "wx/html/helpctrl.h"
46 #include "wx/textctrl.h"
47 #include "wx/notebook.h"
48 #include "wx/imaglist.h"
49 #include "wx/treectrl.h"
50 #include "wx/tokenzr.h"
51 #include "wx/wfstream.h"
52 #include "wx/html/htmlwin.h"
53 #include "wx/busyinfo.h"
54 #include "wx/progdlg.h"
55 #include "wx/toolbar.h"
56 #include "wx/fontenum.h"
57 #include "wx/filedlg.h"
58 #include "wx/artprov.h"
59 #include "wx/spinctrl.h"
60 #include "wx/choicdlg.h"
61 #include "wx/settings.h"
63 // what is considered "small index"?
64 #define INDEX_IS_SMALL 100
66 /* Motif defines this as a macro */
71 //--------------------------------------------------------------------------
72 // wxHtmlHelpTreeItemData (private)
73 //--------------------------------------------------------------------------
75 class wxHtmlHelpTreeItemData
: public wxTreeItemData
78 #if defined(__VISAGECPP__)
79 // VA needs a default ctor for some reason....
80 wxHtmlHelpTreeItemData() : wxTreeItemData()
83 wxHtmlHelpTreeItemData(int id
) : wxTreeItemData()
90 //--------------------------------------------------------------------------
91 // wxHtmlHelpHashData (private)
92 //--------------------------------------------------------------------------
94 class wxHtmlHelpHashData
: public wxObject
97 wxHtmlHelpHashData(int index
, wxTreeItemId id
) : wxObject()
98 { m_Index
= index
; m_Id
= id
;}
99 ~wxHtmlHelpHashData() {}
106 //--------------------------------------------------------------------------
107 // wxHtmlHelpHtmlWindow (private)
108 //--------------------------------------------------------------------------
110 DEFINE_EVENT_TYPE(wxEVT_COMMAND_HTMLWINDOW_URL_CLICKED
)
111 IMPLEMENT_DYNAMIC_CLASS(wxHtmlWindowEvent
, wxNotifyEvent
)
113 class wxHtmlHelpHtmlWindow
: public wxHtmlWindow
116 wxHtmlHelpHtmlWindow(wxHtmlHelpWindow
*win
, wxWindow
*parent
)
117 : wxHtmlWindow(parent
), m_Window(win
)
122 virtual void OnLinkClicked(const wxHtmlLinkInfo
& link
)
124 wxHtmlWindowEvent
event(wxEVT_COMMAND_HTMLWINDOW_URL_CLICKED
, GetId());
125 event
.SetURL(link
.GetHref());
126 if (!ProcessEvent(event
))
128 wxHtmlWindow::OnLinkClicked(link
);
130 const wxMouseEvent
*e
= link
.GetEvent();
131 if (e
== NULL
|| e
->LeftUp())
132 m_Window
->NotifyPageChanged();
135 // Returns full location with anchor (helper)
136 static wxString
GetOpenedPageWithAnchor(wxHtmlWindow
*win
)
139 return wxEmptyString
;
141 wxString an
= win
->GetOpenedAnchor();
142 wxString pg
= win
->GetOpenedPage();
152 wxHtmlHelpWindow
*m_Window
;
154 DECLARE_NO_COPY_CLASS(wxHtmlHelpHtmlWindow
)
158 //---------------------------------------------------------------------------
159 // wxHtmlHelpWindow::m_mergedIndex
160 //---------------------------------------------------------------------------
162 WX_DEFINE_ARRAY_PTR(const wxHtmlHelpDataItem
*, wxHtmlHelpDataItemPtrArray
);
164 struct wxHtmlHelpMergedIndexItem
166 wxHtmlHelpMergedIndexItem
*parent
;
168 wxHtmlHelpDataItemPtrArray items
;
171 WX_DECLARE_OBJARRAY(wxHtmlHelpMergedIndexItem
, wxHtmlHelpMergedIndex
);
172 #include "wx/arrimpl.cpp"
173 WX_DEFINE_OBJARRAY(wxHtmlHelpMergedIndex
)
175 void wxHtmlHelpWindow::UpdateMergedIndex()
177 delete m_mergedIndex
;
178 m_mergedIndex
= new wxHtmlHelpMergedIndex
;
179 wxHtmlHelpMergedIndex
& merged
= *m_mergedIndex
;
181 const wxHtmlHelpDataItems
& items
= m_Data
->GetIndexArray();
182 size_t len
= items
.size();
184 wxHtmlHelpMergedIndexItem
*history
[128] = {NULL
};
186 for (size_t i
= 0; i
< len
; i
++)
188 const wxHtmlHelpDataItem
& item
= items
[i
];
189 wxASSERT_MSG( item
.level
< 128, _T("nested index entries too deep") );
191 if (history
[item
.level
] &&
192 history
[item
.level
]->items
[0]->name
== item
.name
)
194 // same index entry as previous one, update list of items
195 history
[item
.level
]->items
.Add(&item
);
200 wxHtmlHelpMergedIndexItem
*mi
= new wxHtmlHelpMergedIndexItem();
201 mi
->name
= item
.GetIndentedName();
202 mi
->items
.Add(&item
);
203 mi
->parent
= (item
.level
== 0) ? NULL
: history
[item
.level
- 1];
204 history
[item
.level
] = mi
;
210 //---------------------------------------------------------------------------
212 //---------------------------------------------------------------------------
214 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpWindow
, wxWindow
)
216 BEGIN_EVENT_TABLE(wxHtmlHelpWindow
, wxWindow
)
217 EVT_TOOL_RANGE(wxID_HTML_PANEL
, wxID_HTML_OPTIONS
, wxHtmlHelpWindow::OnToolbar
)
218 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE
, wxHtmlHelpWindow::OnToolbar
)
219 EVT_BUTTON(wxID_HTML_BOOKMARKSADD
, wxHtmlHelpWindow::OnToolbar
)
220 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL
, wxHtmlHelpWindow::OnContentsSel
)
221 EVT_LISTBOX(wxID_HTML_INDEXLIST
, wxHtmlHelpWindow::OnIndexSel
)
222 EVT_LISTBOX(wxID_HTML_SEARCHLIST
, wxHtmlHelpWindow::OnSearchSel
)
223 EVT_BUTTON(wxID_HTML_SEARCHBUTTON
, wxHtmlHelpWindow::OnSearch
)
224 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT
, wxHtmlHelpWindow::OnSearch
)
225 EVT_BUTTON(wxID_HTML_INDEXBUTTON
, wxHtmlHelpWindow::OnIndexFind
)
226 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT
, wxHtmlHelpWindow::OnIndexFind
)
227 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL
, wxHtmlHelpWindow::OnIndexAll
)
228 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST
, wxHtmlHelpWindow::OnBookmarksSel
)
229 EVT_SIZE(wxHtmlHelpWindow::OnSize
)
232 wxHtmlHelpWindow::wxHtmlHelpWindow(wxWindow
* parent
, wxWindowID id
,
235 int style
, int helpStyle
, wxHtmlHelpData
* data
)
238 Create(parent
, id
, pos
, size
, style
, helpStyle
);
241 void wxHtmlHelpWindow::Init(wxHtmlHelpData
* data
)
246 m_DataCreated
= false;
250 m_Data
= new wxHtmlHelpData();
251 m_DataCreated
= true;
258 m_ContentsBox
= NULL
;
260 m_IndexButton
= NULL
;
261 m_IndexButtonAll
= NULL
;
264 m_SearchButton
= NULL
;
266 m_SearchChoice
= NULL
;
267 m_IndexCountInfo
= NULL
;
270 m_NavigNotebook
= NULL
;
273 m_SearchCaseSensitive
= NULL
;
274 m_SearchWholeWords
= NULL
;
276 m_mergedIndex
= NULL
;
279 m_ConfigRoot
= wxEmptyString
;
281 m_Cfg
.x
= m_Cfg
.y
= wxDefaultCoord
;
285 m_Cfg
.navig_on
= true;
287 m_NormalFonts
= m_FixedFonts
= NULL
;
288 m_NormalFace
= m_FixedFace
= wxEmptyString
;
295 #if wxUSE_PRINTING_ARCHITECTURE
300 m_UpdateContents
= true;
302 m_helpController
= (wxHtmlHelpController
*) NULL
;
305 // Create: builds the GUI components.
306 // with the style flag it's possible to toggle the toolbar, contents, index and search
308 // m_HtmlWin will *always* be created, but it's important to realize that
309 // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
310 // m_SearchButton may be NULL.
311 // moreover, if no contents, index or searchpage is needed, m_Splitter and
312 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
314 bool wxHtmlHelpWindow::Create(wxWindow
* parent
, wxWindowID id
,
315 const wxPoint
& pos
, const wxSize
& size
,
316 int style
, int helpStyle
)
318 m_hfStyle
= helpStyle
;
320 wxImageList
*ContentsImageList
= new wxImageList(16, 16);
321 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK
,
324 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER
,
327 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE
,
331 // Do the config in two steps. We read the HtmlWindow customization after we
332 // create the window.
334 ReadCustomization(m_Config
, m_ConfigRoot
);
336 wxWindow::Create(parent
, id
, pos
, size
, style
, wxT("wxHtmlHelp"));
338 SetHelpText(_("Displays help as you browse the books on the left."));
340 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
342 int notebook_page
= 0;
344 // The sizer for the whole top-level window.
345 wxSizer
*topWindowSizer
= new wxBoxSizer(wxVERTICAL
);
346 SetSizer(topWindowSizer
);
351 if (helpStyle
& (wxHF_TOOLBAR
| wxHF_FLAT_TOOLBAR
))
353 wxToolBar
*toolBar
= new wxToolBar(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
354 wxNO_BORDER
| wxTB_HORIZONTAL
|
355 wxTB_DOCKABLE
| wxTB_NODIVIDER
|
356 (helpStyle
& wxHF_FLAT_TOOLBAR
? wxTB_FLAT
: 0));
357 toolBar
->SetMargins( 2, 2 );
358 AddToolbarButtons(toolBar
, helpStyle
);
360 topWindowSizer
->Add(toolBar
, 0, wxEXPAND
);
363 #endif //wxUSE_TOOLBAR
365 wxSizer
*navigSizer
= NULL
;
367 if (helpStyle
& (wxHF_CONTENTS
| wxHF_INDEX
| wxHF_SEARCH
))
369 // traditional help controller; splitter window with html page on the
370 // right and a notebook containing various pages on the left
371 m_Splitter
= new wxSplitterWindow(this);
373 topWindowSizer
->Add(m_Splitter
, 1, wxEXPAND
);
375 m_HtmlWin
= new wxHtmlHelpHtmlWindow(this, m_Splitter
);
376 m_NavigPan
= new wxPanel(m_Splitter
, wxID_ANY
);
377 m_NavigNotebook
= new wxNotebook(m_NavigPan
, wxID_HTML_NOTEBOOK
,
378 wxDefaultPosition
, wxDefaultSize
);
380 navigSizer
= new wxBoxSizer(wxVERTICAL
);
381 navigSizer
->Add(m_NavigNotebook
, 1, wxEXPAND
);
383 m_NavigPan
->SetSizer(navigSizer
);
387 // only html window, no notebook with index,contents etc
388 m_HtmlWin
= new wxHtmlWindow(this);
389 topWindowSizer
->Add(m_HtmlWin
, 1, wxEXPAND
);
393 m_HtmlWin
->ReadCustomization(m_Config
, m_ConfigRoot
);
395 // contents tree panel?
396 if ( helpStyle
& wxHF_CONTENTS
)
398 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
399 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
401 topsizer
->Add(0, 10);
403 dummy
->SetSizer(topsizer
);
405 if ( helpStyle
& wxHF_BOOKMARKS
)
407 m_Bookmarks
= new wxComboBox(dummy
, wxID_HTML_BOOKMARKSLIST
,
409 wxDefaultPosition
, wxDefaultSize
,
410 0, NULL
, wxCB_READONLY
| wxCB_SORT
);
411 m_Bookmarks
->Append(_("(bookmarks)"));
412 for (unsigned i
= 0; i
< m_BookmarksNames
.GetCount(); i
++)
413 m_Bookmarks
->Append(m_BookmarksNames
[i
]);
414 m_Bookmarks
->SetSelection(0);
416 wxBitmapButton
*bmpbt1
, *bmpbt2
;
417 bmpbt1
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSADD
,
418 wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK
,
420 bmpbt2
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSREMOVE
,
421 wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK
,
424 bmpbt1
->SetToolTip(_("Add current page to bookmarks"));
425 bmpbt2
->SetToolTip(_("Remove current page from bookmarks"));
426 #endif // wxUSE_TOOLTIPS
428 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
430 sizer
->Add(m_Bookmarks
, 1, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 5);
431 sizer
->Add(bmpbt1
, 0, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 2);
432 sizer
->Add(bmpbt2
, 0, wxALIGN_CENTRE_VERTICAL
, 0);
434 topsizer
->Add(sizer
, 0, wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
, 10);
437 m_ContentsBox
= new wxTreeCtrl(dummy
, wxID_HTML_TREECTRL
,
438 wxDefaultPosition
, wxDefaultSize
,
441 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
445 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
450 m_ContentsBox
->AssignImageList(ContentsImageList
);
452 topsizer
->Add(m_ContentsBox
, 1,
453 wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
,
456 m_NavigNotebook
->AddPage(dummy
, _("Contents"));
457 m_ContentsPage
= notebook_page
++;
460 // index listbox panel?
461 if ( helpStyle
& wxHF_INDEX
)
463 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
464 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
466 dummy
->SetSizer(topsizer
);
468 m_IndexText
= new wxTextCtrl(dummy
, wxID_HTML_INDEXTEXT
, wxEmptyString
,
469 wxDefaultPosition
, wxDefaultSize
,
471 m_IndexButton
= new wxButton(dummy
, wxID_HTML_INDEXBUTTON
, _("Find"));
472 m_IndexButtonAll
= new wxButton(dummy
, wxID_HTML_INDEXBUTTONALL
,
474 m_IndexCountInfo
= new wxStaticText(dummy
, wxID_HTML_COUNTINFO
,
475 wxEmptyString
, wxDefaultPosition
,
477 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
478 m_IndexList
= new wxListBox(dummy
, wxID_HTML_INDEXLIST
,
479 wxDefaultPosition
, wxDefaultSize
,
480 0, NULL
, wxLB_SINGLE
);
483 m_IndexButton
->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
484 m_IndexButtonAll
->SetToolTip(_("Show all items in index"));
485 #endif //wxUSE_TOOLTIPS
487 topsizer
->Add(m_IndexText
, 0, wxEXPAND
| wxALL
, 10);
488 wxSizer
*btsizer
= new wxBoxSizer(wxHORIZONTAL
);
489 btsizer
->Add(m_IndexButton
, 0, wxRIGHT
, 2);
490 btsizer
->Add(m_IndexButtonAll
);
491 topsizer
->Add(btsizer
, 0,
492 wxALIGN_RIGHT
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
493 topsizer
->Add(m_IndexCountInfo
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 2);
494 topsizer
->Add(m_IndexList
, 1, wxEXPAND
| wxALL
, 2);
496 m_NavigNotebook
->AddPage(dummy
, _("Index"));
497 m_IndexPage
= notebook_page
++;
500 // search list panel?
501 if ( helpStyle
& wxHF_SEARCH
)
503 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
504 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
506 dummy
->SetSizer(sizer
);
508 m_SearchText
= new wxTextCtrl(dummy
, wxID_HTML_SEARCHTEXT
,
510 wxDefaultPosition
, wxDefaultSize
,
512 m_SearchChoice
= new wxChoice(dummy
, wxID_HTML_SEARCHCHOICE
,
513 wxDefaultPosition
, wxSize(125,wxDefaultCoord
));
514 m_SearchCaseSensitive
= new wxCheckBox(dummy
, wxID_ANY
, _("Case sensitive"));
515 m_SearchWholeWords
= new wxCheckBox(dummy
, wxID_ANY
, _("Whole words only"));
516 m_SearchButton
= new wxButton(dummy
, wxID_HTML_SEARCHBUTTON
, _("Search"));
518 m_SearchButton
->SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
519 #endif //wxUSE_TOOLTIPS
520 m_SearchList
= new wxListBox(dummy
, wxID_HTML_SEARCHLIST
,
521 wxDefaultPosition
, wxDefaultSize
,
522 0, NULL
, wxLB_SINGLE
);
524 sizer
->Add(m_SearchText
, 0, wxEXPAND
| wxALL
, 10);
525 sizer
->Add(m_SearchChoice
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
526 sizer
->Add(m_SearchCaseSensitive
, 0, wxLEFT
| wxRIGHT
, 10);
527 sizer
->Add(m_SearchWholeWords
, 0, wxLEFT
| wxRIGHT
, 10);
528 sizer
->Add(m_SearchButton
, 0, wxALL
| wxALIGN_RIGHT
, 8);
529 sizer
->Add(m_SearchList
, 1, wxALL
| wxEXPAND
, 2);
531 m_NavigNotebook
->AddPage(dummy
, _("Search"));
532 m_SearchPage
= notebook_page
;
541 navigSizer
->SetSizeHints(m_NavigPan
);
542 m_NavigPan
->Layout();
546 if ( m_NavigPan
&& m_Splitter
)
548 m_Splitter
->SetMinimumPaneSize(20);
549 if ( m_Cfg
.navig_on
)
550 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
552 if ( m_Cfg
.navig_on
)
555 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
559 m_NavigPan
->Show(false);
560 m_Splitter
->Initialize(m_HtmlWin
);
564 // Reduce flicker by updating the splitter pane sizes before the
566 wxSizeEvent
sizeEvent(GetSize(), GetId());
567 ProcessEvent(sizeEvent
);
570 m_Splitter
->UpdateSize();
575 wxHtmlHelpWindow::~wxHtmlHelpWindow()
577 delete m_mergedIndex
;
579 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
582 if (m_NormalFonts
) delete m_NormalFonts
;
583 if (m_FixedFonts
) delete m_FixedFonts
;
586 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
589 #if wxUSE_PRINTING_ARCHITECTURE
590 if (m_Printer
) delete m_Printer
;
594 void wxHtmlHelpWindow::SetController(wxHtmlHelpController
* controller
)
598 m_helpController
= controller
;
599 m_Data
= controller
->GetHelpData();
600 m_DataCreated
= false;
604 void wxHtmlHelpWindow::AddToolbarButtons(wxToolBar
*toolBar
, int style
)
606 wxBitmap wpanelBitmap
=
607 wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL
, wxART_TOOLBAR
);
608 wxBitmap wbackBitmap
=
609 wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_TOOLBAR
);
610 wxBitmap wforwardBitmap
=
611 wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_TOOLBAR
);
612 wxBitmap wupnodeBitmap
=
613 wxArtProvider::GetBitmap(wxART_GO_TO_PARENT
, wxART_TOOLBAR
);
615 wxArtProvider::GetBitmap(wxART_GO_UP
, wxART_TOOLBAR
);
616 wxBitmap wdownBitmap
=
617 wxArtProvider::GetBitmap(wxART_GO_DOWN
, wxART_TOOLBAR
);
618 wxBitmap wopenBitmap
=
619 wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_TOOLBAR
);
620 wxBitmap wprintBitmap
=
621 wxArtProvider::GetBitmap(wxART_PRINT
, wxART_TOOLBAR
);
622 wxBitmap woptionsBitmap
=
623 wxArtProvider::GetBitmap(wxART_HELP_SETTINGS
, wxART_TOOLBAR
);
625 wxASSERT_MSG( (wpanelBitmap
.Ok() && wbackBitmap
.Ok() &&
626 wforwardBitmap
.Ok() && wupnodeBitmap
.Ok() &&
627 wupBitmap
.Ok() && wdownBitmap
.Ok() &&
628 wopenBitmap
.Ok() && wprintBitmap
.Ok() &&
629 woptionsBitmap
.Ok()),
630 wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
633 toolBar
->AddTool(wxID_HTML_PANEL
, wpanelBitmap
, wxNullBitmap
,
634 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
635 _("Show/hide navigation panel"));
637 toolBar
->AddSeparator();
638 toolBar
->AddTool(wxID_HTML_BACK
, wbackBitmap
, wxNullBitmap
,
639 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
641 toolBar
->AddTool(wxID_HTML_FORWARD
, wforwardBitmap
, wxNullBitmap
,
642 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
644 toolBar
->AddSeparator();
646 toolBar
->AddTool(wxID_HTML_UPNODE
, wupnodeBitmap
, wxNullBitmap
,
647 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
648 _("Go one level up in document hierarchy"));
649 toolBar
->AddTool(wxID_HTML_UP
, wupBitmap
, wxNullBitmap
,
650 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
652 toolBar
->AddTool(wxID_HTML_DOWN
, wdownBitmap
, wxNullBitmap
,
653 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
656 if ((style
& wxHF_PRINT
) || (style
& wxHF_OPEN_FILES
))
657 toolBar
->AddSeparator();
659 if (style
& wxHF_OPEN_FILES
)
660 toolBar
->AddTool(wxID_HTML_OPENFILE
, wopenBitmap
, wxNullBitmap
,
661 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
662 _("Open HTML document"));
664 #if wxUSE_PRINTING_ARCHITECTURE
665 if (style
& wxHF_PRINT
)
666 toolBar
->AddTool(wxID_HTML_PRINT
, wprintBitmap
, wxNullBitmap
,
667 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
668 _("Print this page"));
671 toolBar
->AddSeparator();
672 toolBar
->AddTool(wxID_HTML_OPTIONS
, woptionsBitmap
, wxNullBitmap
,
673 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
674 _("Display options dialog"));
676 // Allow application to add custom buttons
677 wxHtmlHelpFrame
* parentFrame
= wxDynamicCast(GetParent(), wxHtmlHelpFrame
);
678 wxHtmlHelpDialog
* parentDialog
= wxDynamicCast(GetParent(), wxHtmlHelpDialog
);
680 parentFrame
->AddToolbarButtons(toolBar
, style
);
682 parentDialog
->AddToolbarButtons(toolBar
, style
);
684 #endif //wxUSE_TOOLBAR
687 bool wxHtmlHelpWindow::Display(const wxString
& x
)
689 wxString url
= m_Data
->FindPageByName(x
);
692 m_HtmlWin
->LoadPage(url
);
700 bool wxHtmlHelpWindow::Display(const int id
)
702 wxString url
= m_Data
->FindPageById(id
);
705 m_HtmlWin
->LoadPage(url
);
713 bool wxHtmlHelpWindow::DisplayContents()
718 if (!m_Splitter
->IsSplit())
722 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
723 m_Cfg
.navig_on
= true;
726 m_NavigNotebook
->SetSelection(m_ContentsPage
);
728 if (m_Data
->GetBookRecArray().GetCount() > 0)
730 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
731 if (!book
.GetStart().empty())
732 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
738 bool wxHtmlHelpWindow::DisplayIndex()
743 if (!m_Splitter
->IsSplit())
747 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
750 m_NavigNotebook
->SetSelection(m_IndexPage
);
752 if (m_Data
->GetBookRecArray().GetCount() > 0)
754 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
755 if (!book
.GetStart().empty())
756 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
762 void wxHtmlHelpWindow::DisplayIndexItem(const wxHtmlHelpMergedIndexItem
*it
)
764 if (it
->items
.size() == 1)
766 if (!it
->items
[0]->page
.empty())
768 m_HtmlWin
->LoadPage(it
->items
[0]->GetFullPath());
774 wxBusyCursor busy_cursor
;
776 // more pages associated with this index item -- let the user choose
777 // which one she/he wants from a list:
779 size_t len
= it
->items
.size();
780 for (size_t i
= 0; i
< len
; i
++)
782 wxString page
= it
->items
[i
]->page
;
783 // try to find page's title in contents:
784 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
785 size_t clen
= contents
.size();
786 for (size_t j
= 0; j
< clen
; j
++)
788 if (contents
[j
].page
== page
)
790 page
= contents
[j
].name
;
797 wxSingleChoiceDialog
dlg(this,
798 _("Please choose the page to display:"),
800 arr
, NULL
, wxCHOICEDLG_STYLE
& ~wxCENTRE
);
801 if (dlg
.ShowModal() == wxID_OK
)
803 m_HtmlWin
->LoadPage(it
->items
[dlg
.GetSelection()]->GetFullPath());
809 bool wxHtmlHelpWindow::KeywordSearch(const wxString
& keyword
,
810 wxHelpSearchMode mode
)
812 if (mode
== wxHELP_SEARCH_ALL
)
814 if ( !(m_SearchList
&&
815 m_SearchButton
&& m_SearchText
&& m_SearchChoice
) )
818 else if (mode
== wxHELP_SEARCH_INDEX
)
820 if ( !(m_IndexList
&&
821 m_IndexButton
&& m_IndexButtonAll
&& m_IndexText
) )
827 wxString book
= wxEmptyString
;
829 if (!m_Splitter
->IsSplit())
833 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
836 if (mode
== wxHELP_SEARCH_ALL
)
838 m_NavigNotebook
->SetSelection(m_SearchPage
);
839 m_SearchList
->Clear();
840 m_SearchText
->SetValue(keyword
);
841 m_SearchButton
->Disable();
843 if (m_SearchChoice
->GetSelection() != 0)
844 book
= m_SearchChoice
->GetStringSelection();
846 wxHtmlSearchStatus
status(m_Data
, keyword
,
847 m_SearchCaseSensitive
->GetValue(),
848 m_SearchWholeWords
->GetValue(),
851 #if wxUSE_PROGRESSDLG
852 wxProgressDialog
progress(_("Searching..."),
853 _("No matching page found yet"),
854 status
.GetMaxIndex(), this,
855 wxPD_APP_MODAL
| wxPD_CAN_ABORT
| wxPD_AUTO_HIDE
);
859 while (status
.IsActive())
861 curi
= status
.GetCurIndex();
863 #if wxUSE_PROGRESSDLG
864 && !progress
.Update(curi
)
870 foundstr
.Printf(_("Found %i matches"), ++foundcnt
);
871 #if wxUSE_PROGRESSDLG
872 progress
.Update(status
.GetCurIndex(), foundstr
);
874 m_SearchList
->Append(status
.GetName(), (void*)status
.GetCurItem());
878 m_SearchButton
->Enable();
879 m_SearchText
->SetSelection(0, keyword
.length());
880 m_SearchText
->SetFocus();
882 else if (mode
== wxHELP_SEARCH_INDEX
)
884 m_NavigNotebook
->SetSelection(m_IndexPage
);
885 m_IndexList
->Clear();
886 m_IndexButton
->Disable();
887 m_IndexButtonAll
->Disable();
888 m_IndexText
->SetValue(keyword
);
891 m_IndexButton
->Enable();
892 m_IndexButtonAll
->Enable();
893 foundcnt
= m_IndexList
->GetCount();
901 wxFAIL_MSG( _T("unknown help search mode") );
904 case wxHELP_SEARCH_ALL
:
906 wxHtmlHelpDataItem
*it
=
907 (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(0);
910 m_HtmlWin
->LoadPage(it
->GetFullPath());
916 case wxHELP_SEARCH_INDEX
:
918 wxHtmlHelpMergedIndexItem
* it
=
919 (wxHtmlHelpMergedIndexItem
*) m_IndexList
->GetClientData(0);
921 DisplayIndexItem(it
);
931 void wxHtmlHelpWindow::CreateContents()
938 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
942 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
944 size_t cnt
= contents
.size();
946 m_PagesHash
= new wxHashTable(wxKEY_STRING
, 2 * cnt
);
948 const int MAX_ROOTS
= 64;
949 wxTreeItemId roots
[MAX_ROOTS
];
950 // VS: this array holds information about whether we've set item icon at
951 // given level. This is necessary because m_Data has a flat structure
952 // and there's no way of recognizing if some item has subitems or not.
953 // We set the icon later: when we find an item with level=n, we know
954 // that the last item with level=n-1 was afolder with subitems, so we
955 // set its icon accordingly
956 bool imaged
[MAX_ROOTS
];
957 m_ContentsBox
->DeleteAllItems();
959 roots
[0] = m_ContentsBox
->AddRoot(_("(Help)"));
962 for (size_t i
= 0; i
< cnt
; i
++)
964 wxHtmlHelpDataItem
*it
= &contents
[i
];
968 if (m_hfStyle
& wxHF_MERGE_BOOKS
)
969 // VS: we don't want book nodes, books' content should
970 // appear under tree's root. This line will create a "fake"
971 // record about book node so that the rest of this look
972 // will believe there really _is_ a book node and will
977 roots
[1] = m_ContentsBox
->AppendItem(roots
[0],
978 it
->name
, IMG_Book
, -1,
979 new wxHtmlHelpTreeItemData(i
));
980 m_ContentsBox
->SetItemBold(roots
[1], true);
984 // ...and their contents:
987 roots
[it
->level
+ 1] = m_ContentsBox
->AppendItem(
988 roots
[it
->level
], it
->name
, IMG_Page
,
989 -1, new wxHtmlHelpTreeItemData(i
));
990 imaged
[it
->level
+ 1] = false;
993 m_PagesHash
->Put(it
->GetFullPath(),
994 new wxHtmlHelpHashData(i
, roots
[it
->level
+ 1]));
996 // Set the icon for the node one level up in the hierarchy,
997 // unless already done (see comment above imaged[] declaration)
998 if (!imaged
[it
->level
])
1000 int image
= IMG_Folder
;
1001 if (m_hfStyle
& wxHF_ICONS_BOOK
)
1003 else if (m_hfStyle
& wxHF_ICONS_BOOK_CHAPTER
)
1004 image
= (it
->level
== 1) ? IMG_Book
: IMG_Folder
;
1005 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
);
1006 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
,
1007 wxTreeItemIcon_Selected
);
1008 imaged
[it
->level
] = true;
1013 void wxHtmlHelpWindow::CreateIndex()
1018 m_IndexList
->Clear();
1020 size_t cnt
= m_mergedIndex
->size();
1023 if (cnt
> INDEX_IS_SMALL
)
1024 cnttext
.Printf(_("%i of %i"), 0, cnt
);
1026 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1027 m_IndexCountInfo
->SetLabel(cnttext
);
1028 if (cnt
> INDEX_IS_SMALL
)
1031 for (size_t i
= 0; i
< cnt
; i
++)
1032 m_IndexList
->Append((*m_mergedIndex
)[i
].name
,
1033 (char*)(&(*m_mergedIndex
)[i
]));
1036 void wxHtmlHelpWindow::CreateSearch()
1038 if (! (m_SearchList
&& m_SearchChoice
))
1040 m_SearchList
->Clear();
1041 m_SearchChoice
->Clear();
1042 m_SearchChoice
->Append(_("Search in all books"));
1043 const wxHtmlBookRecArray
& bookrec
= m_Data
->GetBookRecArray();
1044 int i
, cnt
= bookrec
.GetCount();
1045 for (i
= 0; i
< cnt
; i
++)
1046 m_SearchChoice
->Append(bookrec
[i
].GetTitle());
1047 m_SearchChoice
->SetSelection(0);
1050 void wxHtmlHelpWindow::RefreshLists()
1052 // Update m_mergedIndex:
1053 UpdateMergedIndex();
1054 // Update the controls
1060 void wxHtmlHelpWindow::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1065 if (path
!= wxEmptyString
)
1067 oldpath
= cfg
->GetPath();
1068 cfg
->SetPath(_T("/") + path
);
1071 m_Cfg
.navig_on
= cfg
->Read(wxT("hcNavigPanel"), m_Cfg
.navig_on
) != 0;
1072 m_Cfg
.sashpos
= cfg
->Read(wxT("hcSashPos"), m_Cfg
.sashpos
);
1073 m_Cfg
.x
= cfg
->Read(wxT("hcX"), m_Cfg
.x
);
1074 m_Cfg
.y
= cfg
->Read(wxT("hcY"), m_Cfg
.y
);
1075 m_Cfg
.w
= cfg
->Read(wxT("hcW"), m_Cfg
.w
);
1076 m_Cfg
.h
= cfg
->Read(wxT("hcH"), m_Cfg
.h
);
1078 m_FixedFace
= cfg
->Read(wxT("hcFixedFace"), m_FixedFace
);
1079 m_NormalFace
= cfg
->Read(wxT("hcNormalFace"), m_NormalFace
);
1080 m_FontSize
= cfg
->Read(wxT("hcBaseFontSize"), m_FontSize
);
1087 cnt
= cfg
->Read(wxT("hcBookmarksCnt"), 0L);
1090 m_BookmarksNames
.Clear();
1091 m_BookmarksPages
.Clear();
1094 m_Bookmarks
->Clear();
1095 m_Bookmarks
->Append(_("(bookmarks)"));
1098 for (i
= 0; i
< cnt
; i
++)
1100 val
.Printf(wxT("hcBookmark_%i"), i
);
1102 m_BookmarksNames
.Add(s
);
1103 if (m_Bookmarks
) m_Bookmarks
->Append(s
);
1104 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1106 m_BookmarksPages
.Add(s
);
1112 m_HtmlWin
->ReadCustomization(cfg
);
1114 if (path
!= wxEmptyString
)
1115 cfg
->SetPath(oldpath
);
1118 void wxHtmlHelpWindow::WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1123 if (path
!= wxEmptyString
)
1125 oldpath
= cfg
->GetPath();
1126 cfg
->SetPath(_T("/") + path
);
1129 cfg
->Write(wxT("hcNavigPanel"), m_Cfg
.navig_on
);
1130 cfg
->Write(wxT("hcSashPos"), (long)m_Cfg
.sashpos
);
1132 // Don't write if iconized as this would make the window
1133 // disappear next time it is shown!
1134 cfg
->Write(wxT("hcX"), (long)m_Cfg
.x
);
1135 cfg
->Write(wxT("hcY"), (long)m_Cfg
.y
);
1136 cfg
->Write(wxT("hcW"), (long)m_Cfg
.w
);
1137 cfg
->Write(wxT("hcH"), (long)m_Cfg
.h
);
1139 cfg
->Write(wxT("hcFixedFace"), m_FixedFace
);
1140 cfg
->Write(wxT("hcNormalFace"), m_NormalFace
);
1141 cfg
->Write(wxT("hcBaseFontSize"), (long)m_FontSize
);
1146 int cnt
= m_BookmarksNames
.GetCount();
1149 cfg
->Write(wxT("hcBookmarksCnt"), (long)cnt
);
1150 for (i
= 0; i
< cnt
; i
++)
1152 val
.Printf(wxT("hcBookmark_%i"), i
);
1153 cfg
->Write(val
, m_BookmarksNames
[i
]);
1154 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1155 cfg
->Write(val
, m_BookmarksPages
[i
]);
1160 m_HtmlWin
->WriteCustomization(cfg
);
1162 if (path
!= wxEmptyString
)
1163 cfg
->SetPath(oldpath
);
1166 static void SetFontsToHtmlWin(wxHtmlWindow
*win
, const wxString
& scalf
, const wxString
& fixf
, int size
)
1169 f_sizes
[0] = int(size
* 0.6);
1170 f_sizes
[1] = int(size
* 0.8);
1172 f_sizes
[3] = int(size
* 1.2);
1173 f_sizes
[4] = int(size
* 1.4);
1174 f_sizes
[5] = int(size
* 1.6);
1175 f_sizes
[6] = int(size
* 1.8);
1177 win
->SetFonts(scalf
, fixf
, f_sizes
);
1180 class wxHtmlHelpWindowOptionsDialog
: public wxDialog
1183 wxComboBox
*NormalFont
, *FixedFont
;
1184 wxSpinCtrl
*FontSize
;
1185 wxHtmlWindow
*TestWin
;
1187 wxHtmlHelpWindowOptionsDialog(wxWindow
*parent
)
1188 : wxDialog(parent
, wxID_ANY
, wxString(_("Help Browser Options")))
1190 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
1191 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2, 3, 2, 5);
1193 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Normal font:")));
1194 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Fixed font:")));
1195 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Font size:")));
1197 sizer
->Add(NormalFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1198 wxSize(200, wxDefaultCoord
),
1199 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1201 sizer
->Add(FixedFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1202 wxSize(200, wxDefaultCoord
),
1203 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1205 sizer
->Add(FontSize
= new wxSpinCtrl(this, wxID_ANY
));
1206 FontSize
->SetRange(2, 100);
1208 topsizer
->Add(sizer
, 0, wxLEFT
|wxRIGHT
|wxTOP
, 10);
1210 topsizer
->Add(new wxStaticText(this, wxID_ANY
, _("Preview:")),
1211 0, wxLEFT
| wxTOP
, 10);
1212 topsizer
->Add(TestWin
= new wxHtmlWindow(this, wxID_ANY
, wxDefaultPosition
, wxSize(20, 150),
1213 wxHW_SCROLLBAR_AUTO
| wxSUNKEN_BORDER
),
1214 1, wxEXPAND
| wxLEFT
|wxTOP
|wxRIGHT
, 10);
1216 wxBoxSizer
*sizer2
= new wxBoxSizer(wxHORIZONTAL
);
1218 sizer2
->Add(ok
= new wxButton(this, wxID_OK
), 0, wxALL
, 10);
1220 sizer2
->Add(new wxButton(this, wxID_CANCEL
), 0, wxALL
, 10);
1221 topsizer
->Add(sizer2
, 0, wxALIGN_RIGHT
);
1224 topsizer
->Fit(this);
1229 void UpdateTestWin()
1232 SetFontsToHtmlWin(TestWin
,
1233 NormalFont
->GetStringSelection(),
1234 FixedFont
->GetStringSelection(),
1235 FontSize
->GetValue());
1237 wxString
content(_("font size"));
1239 content
= _T("<font size=-2>") + content
+ _T(" -2</font><br>")
1240 _T("<font size=-1>") + content
+ _T(" -1</font><br>")
1241 _T("<font size=+0>") + content
+ _T(" +0</font><br>")
1242 _T("<font size=+1>") + content
+ _T(" +1</font><br>")
1243 _T("<font size=+2>") + content
+ _T(" +2</font><br>")
1244 _T("<font size=+3>") + content
+ _T(" +3</font><br>")
1245 _T("<font size=+4>") + content
+ _T(" +4</font><br>") ;
1247 content
= wxString( _T("<html><body><table><tr><td>") ) +
1248 _("Normal face<br>and <u>underlined</u>. ") +
1249 _("<i>Italic face.</i> ") +
1250 _("<b>Bold face.</b> ") +
1251 _("<b><i>Bold italic face.</i></b><br>") +
1253 wxString( _T("</td><td><tt>") ) +
1254 _("Fixed size face.<br> <b>bold</b> <i>italic</i> ") +
1255 _("<b><i>bold italic <u>underlined</u></i></b><br>") +
1257 _T("</tt></td></tr></table></body></html>");
1259 TestWin
->SetPage( content
);
1262 void OnUpdate(wxCommandEvent
& WXUNUSED(event
))
1266 void OnUpdateSpin(wxSpinEvent
& WXUNUSED(event
))
1271 DECLARE_EVENT_TABLE()
1272 DECLARE_NO_COPY_CLASS(wxHtmlHelpWindowOptionsDialog
)
1275 BEGIN_EVENT_TABLE(wxHtmlHelpWindowOptionsDialog
, wxDialog
)
1276 EVT_COMBOBOX(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdate
)
1277 EVT_SPINCTRL(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdateSpin
)
1280 void wxHtmlHelpWindow::OptionsDialog()
1282 wxHtmlHelpWindowOptionsDialog
dlg(this);
1285 if (m_NormalFonts
== NULL
)
1287 wxFontEnumerator enu
;
1288 enu
.EnumerateFacenames();
1289 m_NormalFonts
= new wxArrayString
;
1290 *m_NormalFonts
= *enu
.GetFacenames();
1291 m_NormalFonts
->Sort(); // ascending sort
1293 if (m_FixedFonts
== NULL
)
1295 wxFontEnumerator enu
;
1296 enu
.EnumerateFacenames(wxFONTENCODING_SYSTEM
, true /*enum fixed width only*/);
1297 m_FixedFonts
= new wxArrayString
;
1298 *m_FixedFonts
= *enu
.GetFacenames();
1299 m_FixedFonts
->Sort(); // ascending sort
1302 // VS: We want to show the font that is actually used by wxHtmlWindow.
1303 // If customization dialog wasn't used yet, facenames are empty and
1304 // wxHtmlWindow uses default fonts -- let's find out what they
1305 // are so that we can pass them to the dialog:
1306 if (m_NormalFace
.empty())
1308 wxFont
fnt(m_FontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false);
1309 m_NormalFace
= fnt
.GetFaceName();
1311 if (m_FixedFace
.empty())
1313 wxFont
fnt(m_FontSize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false);
1314 m_FixedFace
= fnt
.GetFaceName();
1317 for (i
= 0; i
< m_NormalFonts
->GetCount(); i
++)
1318 dlg
.NormalFont
->Append((*m_NormalFonts
)[i
]);
1319 for (i
= 0; i
< m_FixedFonts
->GetCount(); i
++)
1320 dlg
.FixedFont
->Append((*m_FixedFonts
)[i
]);
1321 if (!m_NormalFace
.empty())
1322 dlg
.NormalFont
->SetStringSelection(m_NormalFace
);
1324 dlg
.NormalFont
->SetSelection(0);
1325 if (!m_FixedFace
.empty())
1326 dlg
.FixedFont
->SetStringSelection(m_FixedFace
);
1328 dlg
.FixedFont
->SetSelection(0);
1329 dlg
.FontSize
->SetValue(m_FontSize
);
1330 dlg
.UpdateTestWin();
1332 if (dlg
.ShowModal() == wxID_OK
)
1334 m_NormalFace
= dlg
.NormalFont
->GetStringSelection();
1335 m_FixedFace
= dlg
.FixedFont
->GetStringSelection();
1336 m_FontSize
= dlg
.FontSize
->GetValue();
1337 SetFontsToHtmlWin(m_HtmlWin
, m_NormalFace
, m_FixedFace
, m_FontSize
);
1341 void wxHtmlHelpWindow::NotifyPageChanged()
1343 if (m_UpdateContents
&& m_PagesHash
)
1345 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1346 wxHtmlHelpHashData
*ha
= NULL
;
1348 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1352 bool olduc
= m_UpdateContents
;
1353 m_UpdateContents
= false;
1354 m_ContentsBox
->SelectItem(ha
->m_Id
);
1355 m_ContentsBox
->EnsureVisible(ha
->m_Id
);
1356 m_UpdateContents
= olduc
;
1366 void wxHtmlHelpWindow::OnToolbar(wxCommandEvent
& event
)
1368 switch (event
.GetId())
1370 case wxID_HTML_BACK
:
1371 m_HtmlWin
->HistoryBack();
1372 NotifyPageChanged();
1375 case wxID_HTML_FORWARD
:
1376 m_HtmlWin
->HistoryForward();
1377 NotifyPageChanged();
1383 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1384 wxHtmlHelpHashData
*ha
= NULL
;
1386 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1387 if (ha
&& ha
->m_Index
> 0)
1389 const wxHtmlHelpDataItem
& it
= m_Data
->GetContentsArray()[ha
->m_Index
- 1];
1390 if (!it
.page
.empty())
1392 m_HtmlWin
->LoadPage(it
.GetFullPath());
1393 NotifyPageChanged();
1399 case wxID_HTML_UPNODE
:
1402 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1403 wxHtmlHelpHashData
*ha
= NULL
;
1405 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1406 if (ha
&& ha
->m_Index
> 0)
1409 m_Data
->GetContentsArray()[ha
->m_Index
].level
- 1;
1410 int ind
= ha
->m_Index
- 1;
1412 const wxHtmlHelpDataItem
*it
=
1413 &m_Data
->GetContentsArray()[ind
];
1414 while (ind
>= 0 && it
->level
!= level
)
1417 it
= &m_Data
->GetContentsArray()[ind
];
1421 if (!it
->page
.empty())
1423 m_HtmlWin
->LoadPage(it
->GetFullPath());
1424 NotifyPageChanged();
1431 case wxID_HTML_DOWN
:
1434 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1435 wxHtmlHelpHashData
*ha
= NULL
;
1437 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1439 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1440 if (ha
&& ha
->m_Index
< (int)contents
.size() - 1)
1442 size_t idx
= ha
->m_Index
+ 1;
1444 while (contents
[idx
].GetFullPath() == page
) idx
++;
1446 if (!contents
[idx
].page
.empty())
1448 m_HtmlWin
->LoadPage(contents
[idx
].GetFullPath());
1449 NotifyPageChanged();
1455 case wxID_HTML_PANEL
:
1457 if (! (m_Splitter
&& m_NavigPan
))
1459 if (m_Splitter
->IsSplit())
1461 m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1462 m_Splitter
->Unsplit(m_NavigPan
);
1463 m_Cfg
.navig_on
= false;
1469 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
1470 m_Cfg
.navig_on
= true;
1475 case wxID_HTML_OPTIONS
:
1479 case wxID_HTML_BOOKMARKSADD
:
1484 item
= m_HtmlWin
->GetOpenedPageTitle();
1485 url
= m_HtmlWin
->GetOpenedPage();
1486 if (item
== wxEmptyString
)
1487 item
= url
.AfterLast(wxT('/'));
1488 if (m_BookmarksPages
.Index(url
) == wxNOT_FOUND
)
1490 m_Bookmarks
->Append(item
);
1491 m_BookmarksNames
.Add(item
);
1492 m_BookmarksPages
.Add(url
);
1497 case wxID_HTML_BOOKMARKSREMOVE
:
1502 item
= m_Bookmarks
->GetStringSelection();
1503 pos
= m_BookmarksNames
.Index(item
);
1504 if (pos
!= wxNOT_FOUND
)
1506 m_BookmarksNames
.RemoveAt(pos
);
1507 m_BookmarksPages
.RemoveAt(pos
);
1508 pos
= m_Bookmarks
->GetSelection();
1509 wxASSERT_MSG( pos
!= wxNOT_FOUND
, wxT("Unknown bookmark position") ) ;
1510 m_Bookmarks
->Delete((unsigned int)pos
);
1515 #if wxUSE_PRINTING_ARCHITECTURE
1516 case wxID_HTML_PRINT
:
1518 if (m_Printer
== NULL
)
1519 m_Printer
= new wxHtmlEasyPrinting(_("Help Printing"), this);
1520 if (!m_HtmlWin
->GetOpenedPage())
1521 wxLogWarning(_("Cannot print empty page."));
1523 m_Printer
->PrintFile(m_HtmlWin
->GetOpenedPage());
1528 case wxID_HTML_OPENFILE
:
1530 wxString filemask
= wxString(
1531 _("HTML files (*.html;*.htm)|*.html;*.htm|")) +
1532 _("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|") +
1533 _("HTML Help Project (*.hhp)|*.hhp|") +
1535 _("Compressed HTML Help file (*.chm)|*.chm|") +
1537 _("All files (*.*)|*");
1538 wxString s
= wxFileSelector(_("Open HTML document"),
1543 wxOPEN
| wxFILE_MUST_EXIST
,
1547 wxString ext
= s
.Right(4).Lower();
1548 if (ext
== _T(".zip") || ext
== _T(".htb") ||
1550 ext
== _T(".chm") ||
1559 m_HtmlWin
->LoadPage(s
);
1566 void wxHtmlHelpWindow::OnContentsSel(wxTreeEvent
& event
)
1568 wxHtmlHelpTreeItemData
*pg
;
1570 pg
= (wxHtmlHelpTreeItemData
*) m_ContentsBox
->GetItemData(event
.GetItem());
1572 if (pg
&& m_UpdateContents
)
1574 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1575 m_UpdateContents
= false;
1576 if (!contents
[pg
->m_Id
].page
.empty())
1577 m_HtmlWin
->LoadPage(contents
[pg
->m_Id
].GetFullPath());
1578 m_UpdateContents
= true;
1582 void wxHtmlHelpWindow::OnIndexSel(wxCommandEvent
& WXUNUSED(event
))
1584 wxHtmlHelpMergedIndexItem
*it
= (wxHtmlHelpMergedIndexItem
*)
1585 m_IndexList
->GetClientData(m_IndexList
->GetSelection());
1587 DisplayIndexItem(it
);
1590 void wxHtmlHelpWindow::OnIndexFind(wxCommandEvent
& WXUNUSED(event
))
1595 void wxHtmlHelpWindow::DoIndexFind()
1597 wxString sr
= m_IndexText
->GetLineText(0);
1599 if (sr
== wxEmptyString
)
1607 m_IndexList
->Clear();
1608 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1609 size_t cnt
= index
.size();
1612 for (size_t i
= 0; i
< cnt
; i
++)
1614 if (index
[i
].name
.Lower().find(sr
) != wxString::npos
)
1616 int pos
= m_IndexList
->Append(index
[i
].name
,
1617 (char*)(&index
[i
]));
1621 // don't automatically show topic selector if this
1622 // item points to multiple pages:
1623 if (index
[i
].items
.size() == 1)
1625 m_IndexList
->SetSelection(0);
1626 DisplayIndexItem(&index
[i
]);
1630 // if this is nested item of the index, show its parent(s)
1631 // as well, otherwise it would not be clear what entry is
1633 wxHtmlHelpMergedIndexItem
*parent
= index
[i
].parent
;
1637 (index
.Index(*(wxHtmlHelpMergedIndexItem
*)m_IndexList
->GetClientData(pos
-1))) < index
.Index(*parent
))
1639 m_IndexList
->Insert(parent
->name
,
1640 pos
, (char*)parent
);
1641 parent
= parent
->parent
;
1646 // finally, it the item we just added is itself a parent for
1647 // other items, show them as well, because they are refinements
1648 // of the displayed index entry (i.e. it is implicitly contained
1649 // in them: "foo" with parent "bar" reads as "bar, foo"):
1650 int level
= index
[i
].items
[0]->level
;
1652 while (i
< cnt
&& index
[i
].items
[0]->level
> level
)
1654 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1662 cnttext
.Printf(_("%i of %i"), displ
, cnt
);
1663 m_IndexCountInfo
->SetLabel(cnttext
);
1665 m_IndexText
->SetSelection(0, sr
.length());
1666 m_IndexText
->SetFocus();
1670 void wxHtmlHelpWindow::OnIndexAll(wxCommandEvent
& WXUNUSED(event
))
1675 void wxHtmlHelpWindow::DoIndexAll()
1679 m_IndexList
->Clear();
1680 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1681 size_t cnt
= index
.size();
1684 for (size_t i
= 0; i
< cnt
; i
++)
1686 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1689 // don't automatically show topic selector if this
1690 // item points to multiple pages:
1691 if (index
[i
].items
.size() == 1)
1693 DisplayIndexItem(&index
[i
]);
1700 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1701 m_IndexCountInfo
->SetLabel(cnttext
);
1704 void wxHtmlHelpWindow::OnSearchSel(wxCommandEvent
& WXUNUSED(event
))
1706 wxHtmlHelpDataItem
*it
= (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(m_SearchList
->GetSelection());
1709 if (!it
->page
.empty())
1710 m_HtmlWin
->LoadPage(it
->GetFullPath());
1711 NotifyPageChanged();
1715 void wxHtmlHelpWindow::OnSearch(wxCommandEvent
& WXUNUSED(event
))
1717 wxString sr
= m_SearchText
->GetLineText(0);
1720 KeywordSearch(sr
, wxHELP_SEARCH_ALL
);
1723 void wxHtmlHelpWindow::OnBookmarksSel(wxCommandEvent
& WXUNUSED(event
))
1725 wxString str
= m_Bookmarks
->GetStringSelection();
1726 int idx
= m_BookmarksNames
.Index(str
);
1727 if (!str
.empty() && str
!= _("(bookmarks)") && idx
!= wxNOT_FOUND
)
1729 m_HtmlWin
->LoadPage(m_BookmarksPages
[(size_t)idx
]);
1730 NotifyPageChanged();
1734 void wxHtmlHelpWindow::OnSize(wxSizeEvent
& WXUNUSED(event
))
1739 #endif // wxUSE_WXHTML_HELP