1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlHelpFrame
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/helpctrl.h"
41 #include "wx/textctrl.h"
42 #include "wx/notebook.h"
43 #include "wx/imaglist.h"
44 #include "wx/treectrl.h"
45 #include "wx/tokenzr.h"
46 #include "wx/wfstream.h"
47 #include "wx/html/htmlwin.h"
48 #include "wx/busyinfo.h"
49 #include "wx/progdlg.h"
50 #include "wx/toolbar.h"
51 #include "wx/fontenum.h"
52 #include "wx/stream.h"
53 #include "wx/filedlg.h"
54 #include "wx/artprov.h"
55 #include "wx/spinctrl.h"
56 #include "wx/dynarray.h"
57 #include "wx/choicdlg.h"
58 #include "wx/settings.h"
60 // what is considered "small index"?
61 #define INDEX_IS_SMALL 100
63 /* Motif defines this as a macro */
68 //--------------------------------------------------------------------------
69 // wxHtmlHelpTreeItemData (private)
70 //--------------------------------------------------------------------------
72 class wxHtmlHelpTreeItemData
: public wxTreeItemData
75 #if defined(__VISAGECPP__)
76 // VA needs a default ctor for some reason....
77 wxHtmlHelpTreeItemData() : wxTreeItemData()
80 wxHtmlHelpTreeItemData(int id
) : wxTreeItemData()
87 //--------------------------------------------------------------------------
88 // wxHtmlHelpHashData (private)
89 //--------------------------------------------------------------------------
91 class wxHtmlHelpHashData
: public wxObject
94 wxHtmlHelpHashData(int index
, wxTreeItemId id
) : wxObject()
95 { m_Index
= index
; m_Id
= id
;}
96 ~wxHtmlHelpHashData() {}
103 //--------------------------------------------------------------------------
104 // wxHtmlHelpHtmlWindow (private)
105 //--------------------------------------------------------------------------
107 class wxHtmlHelpHtmlWindow
: public wxHtmlWindow
110 wxHtmlHelpHtmlWindow(wxHtmlHelpFrame
*fr
, wxWindow
*parent
)
111 : wxHtmlWindow(parent
), m_Frame(fr
)
116 virtual void OnLinkClicked(const wxHtmlLinkInfo
& link
)
118 wxHtmlWindow::OnLinkClicked(link
);
119 const wxMouseEvent
*e
= link
.GetEvent();
120 if (e
== NULL
|| e
->LeftUp())
121 m_Frame
->NotifyPageChanged();
124 // Returns full location with anchor (helper)
125 static wxString
GetOpenedPageWithAnchor(wxHtmlWindow
*win
)
128 return wxEmptyString
;
130 wxString an
= win
->GetOpenedAnchor();
131 wxString pg
= win
->GetOpenedPage();
141 wxHtmlHelpFrame
*m_Frame
;
143 DECLARE_NO_COPY_CLASS(wxHtmlHelpHtmlWindow
)
147 //---------------------------------------------------------------------------
148 // wxHtmlHelpFrame::m_mergedIndex
149 //---------------------------------------------------------------------------
151 WX_DEFINE_ARRAY_PTR(const wxHtmlHelpDataItem
*, wxHtmlHelpDataItemPtrArray
);
153 struct wxHtmlHelpMergedIndexItem
155 wxHtmlHelpMergedIndexItem
*parent
;
157 wxHtmlHelpDataItemPtrArray items
;
160 WX_DECLARE_OBJARRAY(wxHtmlHelpMergedIndexItem
, wxHtmlHelpMergedIndex
);
161 #include "wx/arrimpl.cpp"
162 WX_DEFINE_OBJARRAY(wxHtmlHelpMergedIndex
)
164 void wxHtmlHelpFrame::UpdateMergedIndex()
166 delete m_mergedIndex
;
167 m_mergedIndex
= new wxHtmlHelpMergedIndex
;
168 wxHtmlHelpMergedIndex
& merged
= *m_mergedIndex
;
170 const wxHtmlHelpDataItems
& items
= m_Data
->GetIndexArray();
171 size_t len
= items
.size();
173 wxHtmlHelpMergedIndexItem
*history
[128] = {NULL
};
175 for (size_t i
= 0; i
< len
; i
++)
177 const wxHtmlHelpDataItem
& item
= items
[i
];
178 wxASSERT_MSG( item
.level
< 128, _T("nested index entries too deep") );
180 if (history
[item
.level
] &&
181 history
[item
.level
]->items
[0]->name
== item
.name
)
183 // same index entry as previous one, update list of items
184 history
[item
.level
]->items
.Add(&item
);
189 wxHtmlHelpMergedIndexItem
*mi
= new wxHtmlHelpMergedIndexItem();
190 mi
->name
= item
.GetIndentedName();
191 mi
->items
.Add(&item
);
192 mi
->parent
= (item
.level
== 0) ? NULL
: history
[item
.level
- 1];
193 history
[item
.level
] = mi
;
200 //---------------------------------------------------------------------------
202 //---------------------------------------------------------------------------
207 //wxID_HTML_HELPFRAME = wxID_HIGHEST + 1,
208 wxID_HTML_PANEL
= wxID_HIGHEST
+ 2,
217 wxID_HTML_BOOKMARKSLIST
,
218 wxID_HTML_BOOKMARKSADD
,
219 wxID_HTML_BOOKMARKSREMOVE
,
224 wxID_HTML_INDEXBUTTON
,
225 wxID_HTML_INDEXBUTTONALL
,
227 wxID_HTML_SEARCHPAGE
,
228 wxID_HTML_SEARCHTEXT
,
229 wxID_HTML_SEARCHLIST
,
230 wxID_HTML_SEARCHBUTTON
,
231 wxID_HTML_SEARCHCHOICE
,
236 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame
, wxFrame
)
238 wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow
* parent
, wxWindowID id
, const wxString
& title
,
239 int style
, wxHtmlHelpData
* data
)
242 Create(parent
, id
, title
, style
);
245 void wxHtmlHelpFrame::Init(wxHtmlHelpData
* data
)
250 m_DataCreated
= false;
253 m_Data
= new wxHtmlHelpData();
254 m_DataCreated
= true;
261 m_ContentsBox
= NULL
;
263 m_IndexButton
= NULL
;
264 m_IndexButtonAll
= NULL
;
267 m_SearchButton
= NULL
;
269 m_SearchChoice
= NULL
;
270 m_IndexCountInfo
= NULL
;
273 m_NavigNotebook
= NULL
;
276 m_SearchCaseSensitive
= NULL
;
277 m_SearchWholeWords
= NULL
;
279 m_mergedIndex
= NULL
;
282 m_ConfigRoot
= wxEmptyString
;
284 m_Cfg
.x
= m_Cfg
.y
= wxDefaultCoord
;
288 m_Cfg
.navig_on
= true;
290 m_NormalFonts
= m_FixedFonts
= NULL
;
291 m_NormalFace
= m_FixedFace
= wxEmptyString
;
298 #if wxUSE_PRINTING_ARCHITECTURE
303 m_UpdateContents
= true;
304 m_helpController
= (wxHelpControllerBase
*) NULL
;
307 // Create: builds the GUI components.
308 // with the style flag it's possible to toggle the toolbar, contents, index and search
310 // m_HtmlWin will *always* be created, but it's important to realize that
311 // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
312 // m_SearchButton may be NULL.
313 // moreover, if no contents, index or searchpage is needed, m_Splitter and
314 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
316 bool wxHtmlHelpFrame::Create(wxWindow
* parent
, wxWindowID id
,
317 const wxString
& WXUNUSED(title
), int style
)
321 wxImageList
*ContentsImageList
= new wxImageList(16, 16);
322 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK
,
325 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER
,
328 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE
,
332 // Do the config in two steps. We read the HtmlWindow customization after we
333 // create the window.
335 ReadCustomization(m_Config
, m_ConfigRoot
);
337 wxFrame::Create(parent
, id
, _("Help"),
338 wxPoint(m_Cfg
.x
, m_Cfg
.y
), wxSize(m_Cfg
.w
, m_Cfg
.h
),
339 wxDEFAULT_FRAME_STYLE
, wxT("wxHtmlHelp"));
341 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
343 SetIcon(wxArtProvider::GetIcon(wxART_HELP
, wxART_HELP_BROWSER
));
345 // On the Mac, each modeless frame must have a menubar.
346 // TODO: add more menu items, and perhaps add a style to show
347 // the menubar: compulsory on the Mac, optional elsewhere.
349 wxMenuBar
* menuBar
= new wxMenuBar
;
351 wxMenu
* fileMenu
= new wxMenu
;
352 fileMenu
->Append(wxID_HTML_OPENFILE
, _("&Open..."));
353 fileMenu
->AppendSeparator();
354 fileMenu
->Append(wxID_CLOSE
, _("&Close"));
356 wxMenu
* helpMenu
= new wxMenu
;
357 helpMenu
->Append(wxID_ABOUT
, _("&About..."));
358 // Ensures we don't get an empty help menu
359 helpMenu
->Append(wxID_HELP_CONTENTS
, _("&About..."));
361 menuBar
->Append(fileMenu
,_("&File"));
362 menuBar
->Append(helpMenu
,_("&Help"));
366 int notebook_page
= 0;
370 #endif // wxUSE_STATUSBAR
374 if (style
& (wxHF_TOOLBAR
| wxHF_FLAT_TOOLBAR
))
376 wxToolBar
*toolBar
= CreateToolBar(wxNO_BORDER
| wxTB_HORIZONTAL
|
378 (style
& wxHF_FLAT_TOOLBAR
? wxTB_FLAT
: 0));
379 toolBar
->SetMargins( 2, 2 );
380 AddToolbarButtons(toolBar
, style
);
383 #endif //wxUSE_TOOLBAR
385 wxSizer
*navigSizer
= NULL
;
387 if (style
& (wxHF_CONTENTS
| wxHF_INDEX
| wxHF_SEARCH
))
389 // traditional help controller; splitter window with html page on the
390 // right and a notebook containing various pages on the left
391 m_Splitter
= new wxSplitterWindow(this);
393 m_HtmlWin
= new wxHtmlHelpHtmlWindow(this, m_Splitter
);
394 m_NavigPan
= new wxPanel(m_Splitter
, wxID_ANY
);
395 m_NavigNotebook
= new wxNotebook(m_NavigPan
, wxID_HTML_NOTEBOOK
,
396 wxDefaultPosition
, wxDefaultSize
);
398 navigSizer
= new wxBoxSizer(wxVERTICAL
);
399 navigSizer
->Add(m_NavigNotebook
, 1, wxEXPAND
);
401 m_NavigPan
->SetSizer(navigSizer
);
404 { // only html window, no notebook with index,contents etc
405 m_HtmlWin
= new wxHtmlWindow(this);
408 m_HtmlWin
->SetRelatedFrame(this, m_TitleFormat
);
410 m_HtmlWin
->SetRelatedStatusBar(0);
411 #endif // wxUSE_STATUSBAR
413 m_HtmlWin
->ReadCustomization(m_Config
, m_ConfigRoot
);
415 // contents tree panel?
416 if ( style
& wxHF_CONTENTS
)
418 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
419 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
421 topsizer
->Add(0, 10);
423 dummy
->SetSizer(topsizer
);
425 if ( style
& wxHF_BOOKMARKS
)
427 m_Bookmarks
= new wxComboBox(dummy
, wxID_HTML_BOOKMARKSLIST
,
429 wxDefaultPosition
, wxDefaultSize
,
430 0, NULL
, wxCB_READONLY
| wxCB_SORT
);
431 m_Bookmarks
->Append(_("(bookmarks)"));
432 for (unsigned i
= 0; i
< m_BookmarksNames
.GetCount(); i
++)
433 m_Bookmarks
->Append(m_BookmarksNames
[i
]);
434 m_Bookmarks
->SetSelection(0);
436 wxBitmapButton
*bmpbt1
, *bmpbt2
;
437 bmpbt1
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSADD
,
438 wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK
,
440 bmpbt2
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSREMOVE
,
441 wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK
,
444 bmpbt1
->SetToolTip(_("Add current page to bookmarks"));
445 bmpbt2
->SetToolTip(_("Remove current page from bookmarks"));
446 #endif // wxUSE_TOOLTIPS
448 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
450 sizer
->Add(m_Bookmarks
, 1, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 5);
451 sizer
->Add(bmpbt1
, 0, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 2);
452 sizer
->Add(bmpbt2
, 0, wxALIGN_CENTRE_VERTICAL
, 0);
454 topsizer
->Add(sizer
, 0, wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
, 10);
457 m_ContentsBox
= new wxTreeCtrl(dummy
, wxID_HTML_TREECTRL
,
458 wxDefaultPosition
, wxDefaultSize
,
461 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
465 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
470 m_ContentsBox
->AssignImageList(ContentsImageList
);
472 topsizer
->Add(m_ContentsBox
, 1,
473 wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
,
476 m_NavigNotebook
->AddPage(dummy
, _("Contents"));
477 m_ContentsPage
= notebook_page
++;
480 // index listbox panel?
481 if ( style
& wxHF_INDEX
)
483 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
484 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
486 dummy
->SetSizer(topsizer
);
488 m_IndexText
= new wxTextCtrl(dummy
, wxID_HTML_INDEXTEXT
, wxEmptyString
,
489 wxDefaultPosition
, wxDefaultSize
,
491 m_IndexButton
= new wxButton(dummy
, wxID_HTML_INDEXBUTTON
, _("Find"));
492 m_IndexButtonAll
= new wxButton(dummy
, wxID_HTML_INDEXBUTTONALL
,
494 m_IndexCountInfo
= new wxStaticText(dummy
, wxID_HTML_COUNTINFO
,
495 wxEmptyString
, wxDefaultPosition
,
497 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
498 m_IndexList
= new wxListBox(dummy
, wxID_HTML_INDEXLIST
,
499 wxDefaultPosition
, wxDefaultSize
,
500 0, NULL
, wxLB_SINGLE
);
503 m_IndexButton
->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
504 m_IndexButtonAll
->SetToolTip(_("Show all items in index"));
505 #endif //wxUSE_TOOLTIPS
507 topsizer
->Add(m_IndexText
, 0, wxEXPAND
| wxALL
, 10);
508 wxSizer
*btsizer
= new wxBoxSizer(wxHORIZONTAL
);
509 btsizer
->Add(m_IndexButton
, 0, wxRIGHT
, 2);
510 btsizer
->Add(m_IndexButtonAll
);
511 topsizer
->Add(btsizer
, 0,
512 wxALIGN_RIGHT
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
513 topsizer
->Add(m_IndexCountInfo
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 2);
514 topsizer
->Add(m_IndexList
, 1, wxEXPAND
| wxALL
, 2);
516 m_NavigNotebook
->AddPage(dummy
, _("Index"));
517 m_IndexPage
= notebook_page
++;
520 // search list panel?
521 if ( style
& wxHF_SEARCH
)
523 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
524 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
526 dummy
->SetSizer(sizer
);
528 m_SearchText
= new wxTextCtrl(dummy
, wxID_HTML_SEARCHTEXT
,
530 wxDefaultPosition
, wxDefaultSize
,
532 m_SearchChoice
= new wxChoice(dummy
, wxID_HTML_SEARCHCHOICE
,
533 wxDefaultPosition
, wxSize(125,wxDefaultCoord
));
534 m_SearchCaseSensitive
= new wxCheckBox(dummy
, wxID_ANY
, _("Case sensitive"));
535 m_SearchWholeWords
= new wxCheckBox(dummy
, wxID_ANY
, _("Whole words only"));
536 m_SearchButton
= new wxButton(dummy
, wxID_HTML_SEARCHBUTTON
, _("Search"));
538 m_SearchButton
->SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
539 #endif //wxUSE_TOOLTIPS
540 m_SearchList
= new wxListBox(dummy
, wxID_HTML_SEARCHLIST
,
541 wxDefaultPosition
, wxDefaultSize
,
542 0, NULL
, wxLB_SINGLE
);
544 sizer
->Add(m_SearchText
, 0, wxEXPAND
| wxALL
, 10);
545 sizer
->Add(m_SearchChoice
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
546 sizer
->Add(m_SearchCaseSensitive
, 0, wxLEFT
| wxRIGHT
, 10);
547 sizer
->Add(m_SearchWholeWords
, 0, wxLEFT
| wxRIGHT
, 10);
548 sizer
->Add(m_SearchButton
, 0, wxALL
| wxALIGN_RIGHT
, 8);
549 sizer
->Add(m_SearchList
, 1, wxALL
| wxEXPAND
, 2);
551 m_NavigNotebook
->AddPage(dummy
, _("Search"));
552 m_SearchPage
= notebook_page
;
561 navigSizer
->SetSizeHints(m_NavigPan
);
562 m_NavigPan
->Layout();
566 if ( m_NavigPan
&& m_Splitter
)
568 m_Splitter
->SetMinimumPaneSize(20);
569 if ( m_Cfg
.navig_on
)
570 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
572 if ( m_Cfg
.navig_on
)
575 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
579 m_NavigPan
->Show(false);
580 m_Splitter
->Initialize(m_HtmlWin
);
584 // Reduce flicker by updating the splitter pane sizes before the
586 wxSizeEvent
sizeEvent(GetSize(), GetId());
587 ProcessEvent(sizeEvent
);
589 m_Splitter
->UpdateSize();
594 wxHtmlHelpFrame::~wxHtmlHelpFrame()
596 delete m_mergedIndex
;
598 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
601 if (m_NormalFonts
) delete m_NormalFonts
;
602 if (m_FixedFonts
) delete m_FixedFonts
;
605 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
608 #if wxUSE_PRINTING_ARCHITECTURE
609 if (m_Printer
) delete m_Printer
;
615 void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar
*toolBar
, int style
)
617 wxBitmap wpanelBitmap
=
618 wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL
, wxART_TOOLBAR
);
619 wxBitmap wbackBitmap
=
620 wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_TOOLBAR
);
621 wxBitmap wforwardBitmap
=
622 wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_TOOLBAR
);
623 wxBitmap wupnodeBitmap
=
624 wxArtProvider::GetBitmap(wxART_GO_TO_PARENT
, wxART_TOOLBAR
);
626 wxArtProvider::GetBitmap(wxART_GO_UP
, wxART_TOOLBAR
);
627 wxBitmap wdownBitmap
=
628 wxArtProvider::GetBitmap(wxART_GO_DOWN
, wxART_TOOLBAR
);
629 wxBitmap wopenBitmap
=
630 wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_TOOLBAR
);
631 wxBitmap wprintBitmap
=
632 wxArtProvider::GetBitmap(wxART_PRINT
, wxART_TOOLBAR
);
633 wxBitmap woptionsBitmap
=
634 wxArtProvider::GetBitmap(wxART_HELP_SETTINGS
, wxART_TOOLBAR
);
636 wxASSERT_MSG( (wpanelBitmap
.Ok() && wbackBitmap
.Ok() &&
637 wforwardBitmap
.Ok() && wupnodeBitmap
.Ok() &&
638 wupBitmap
.Ok() && wdownBitmap
.Ok() &&
639 wopenBitmap
.Ok() && wprintBitmap
.Ok() &&
640 woptionsBitmap
.Ok()),
641 wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
644 toolBar
->AddTool(wxID_HTML_PANEL
, wpanelBitmap
, wxNullBitmap
,
645 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
646 _("Show/hide navigation panel"));
648 toolBar
->AddSeparator();
649 toolBar
->AddTool(wxID_HTML_BACK
, wbackBitmap
, wxNullBitmap
,
650 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
652 toolBar
->AddTool(wxID_HTML_FORWARD
, wforwardBitmap
, wxNullBitmap
,
653 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
655 toolBar
->AddSeparator();
657 toolBar
->AddTool(wxID_HTML_UPNODE
, wupnodeBitmap
, wxNullBitmap
,
658 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
659 _("Go one level up in document hierarchy"));
660 toolBar
->AddTool(wxID_HTML_UP
, wupBitmap
, wxNullBitmap
,
661 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
663 toolBar
->AddTool(wxID_HTML_DOWN
, wdownBitmap
, wxNullBitmap
,
664 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
667 if ((style
& wxHF_PRINT
) || (style
& wxHF_OPEN_FILES
))
668 toolBar
->AddSeparator();
670 if (style
& wxHF_OPEN_FILES
)
671 toolBar
->AddTool(wxID_HTML_OPENFILE
, wopenBitmap
, wxNullBitmap
,
672 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
673 _("Open HTML document"));
675 #if wxUSE_PRINTING_ARCHITECTURE
676 if (style
& wxHF_PRINT
)
677 toolBar
->AddTool(wxID_HTML_PRINT
, wprintBitmap
, wxNullBitmap
,
678 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
679 _("Print this page"));
682 toolBar
->AddSeparator();
683 toolBar
->AddTool(wxID_HTML_OPTIONS
, woptionsBitmap
, wxNullBitmap
,
684 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
685 _("Display options dialog"));
687 #endif //wxUSE_TOOLBAR
690 void wxHtmlHelpFrame::SetTitleFormat(const wxString
& format
)
693 m_HtmlWin
->SetRelatedFrame(this, format
);
694 m_TitleFormat
= format
;
698 bool wxHtmlHelpFrame::Display(const wxString
& x
)
700 wxString url
= m_Data
->FindPageByName(x
);
703 m_HtmlWin
->LoadPage(url
);
711 bool wxHtmlHelpFrame::Display(const int id
)
713 wxString url
= m_Data
->FindPageById(id
);
716 m_HtmlWin
->LoadPage(url
);
726 bool wxHtmlHelpFrame::DisplayContents()
731 if (!m_Splitter
->IsSplit())
735 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
736 m_Cfg
.navig_on
= true;
739 m_NavigNotebook
->SetSelection(m_ContentsPage
);
741 if (m_Data
->GetBookRecArray().GetCount() > 0)
743 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
744 if (!book
.GetStart().empty())
745 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
753 bool wxHtmlHelpFrame::DisplayIndex()
758 if (!m_Splitter
->IsSplit())
762 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
765 m_NavigNotebook
->SetSelection(m_IndexPage
);
767 if (m_Data
->GetBookRecArray().GetCount() > 0)
769 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
770 if (!book
.GetStart().empty())
771 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
777 void wxHtmlHelpFrame::DisplayIndexItem(const wxHtmlHelpMergedIndexItem
*it
)
779 if (it
->items
.size() == 1)
781 if (!it
->items
[0]->page
.empty())
783 m_HtmlWin
->LoadPage(it
->items
[0]->GetFullPath());
789 wxBusyCursor busy_cursor
;
791 // more pages associated with this index item -- let the user choose
792 // which one she/he wants from a list:
794 size_t len
= it
->items
.size();
795 for (size_t i
= 0; i
< len
; i
++)
797 wxString page
= it
->items
[i
]->page
;
798 // try to find page's title in contents:
799 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
800 size_t clen
= contents
.size();
801 for (size_t j
= 0; j
< clen
; j
++)
803 if (contents
[j
].page
== page
)
805 page
= contents
[j
].name
;
812 wxSingleChoiceDialog
dlg(this,
813 _("Please choose the page to display:"),
815 arr
, NULL
, wxCHOICEDLG_STYLE
& ~wxCENTRE
);
816 if (dlg
.ShowModal() == wxID_OK
)
818 m_HtmlWin
->LoadPage(it
->items
[dlg
.GetSelection()]->GetFullPath());
825 bool wxHtmlHelpFrame::KeywordSearch(const wxString
& keyword
,
826 wxHelpSearchMode mode
)
828 if (mode
== wxHELP_SEARCH_ALL
)
830 if ( !(m_SearchList
&&
831 m_SearchButton
&& m_SearchText
&& m_SearchChoice
) )
834 else if (mode
== wxHELP_SEARCH_INDEX
)
836 if ( !(m_IndexList
&&
837 m_IndexButton
&& m_IndexButtonAll
&& m_IndexText
) )
843 wxString book
= wxEmptyString
;
845 if (!m_Splitter
->IsSplit())
849 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
852 if (mode
== wxHELP_SEARCH_ALL
)
854 m_NavigNotebook
->SetSelection(m_SearchPage
);
855 m_SearchList
->Clear();
856 m_SearchText
->SetValue(keyword
);
857 m_SearchButton
->Disable();
859 if (m_SearchChoice
->GetSelection() != 0)
860 book
= m_SearchChoice
->GetStringSelection();
862 wxHtmlSearchStatus
status(m_Data
, keyword
,
863 m_SearchCaseSensitive
->GetValue(),
864 m_SearchWholeWords
->GetValue(),
867 #if wxUSE_PROGRESSDLG
868 wxProgressDialog
progress(_("Searching..."),
869 _("No matching page found yet"),
870 status
.GetMaxIndex(), this,
871 wxPD_APP_MODAL
| wxPD_CAN_ABORT
| wxPD_AUTO_HIDE
);
875 while (status
.IsActive())
877 curi
= status
.GetCurIndex();
879 #if wxUSE_PROGRESSDLG
880 && !progress
.Update(curi
)
886 foundstr
.Printf(_("Found %i matches"), ++foundcnt
);
887 #if wxUSE_PROGRESSDLG
888 progress
.Update(status
.GetCurIndex(), foundstr
);
890 m_SearchList
->Append(status
.GetName(), (void*)status
.GetCurItem());
894 m_SearchButton
->Enable();
895 m_SearchText
->SetSelection(0, keyword
.Length());
896 m_SearchText
->SetFocus();
898 else if (mode
== wxHELP_SEARCH_INDEX
)
900 m_NavigNotebook
->SetSelection(m_IndexPage
);
901 m_IndexList
->Clear();
902 m_IndexButton
->Disable();
903 m_IndexButtonAll
->Disable();
904 m_IndexText
->SetValue(keyword
);
906 wxCommandEvent dummy
;
907 OnIndexFind(dummy
); // what a hack...
908 m_IndexButton
->Enable();
909 m_IndexButtonAll
->Enable();
910 foundcnt
= m_IndexList
->GetCount();
918 wxFAIL_MSG( _T("unknown help search mode") );
921 case wxHELP_SEARCH_ALL
:
923 wxHtmlHelpDataItem
*it
=
924 (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(0);
927 m_HtmlWin
->LoadPage(it
->GetFullPath());
933 case wxHELP_SEARCH_INDEX
:
935 wxHtmlHelpMergedIndexItem
* it
=
936 (wxHtmlHelpMergedIndexItem
*) m_IndexList
->GetClientData(0);
938 DisplayIndexItem(it
);
948 void wxHtmlHelpFrame::CreateContents()
955 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
959 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
961 size_t cnt
= contents
.size();
963 m_PagesHash
= new wxHashTable(wxKEY_STRING
, 2 * cnt
);
965 const int MAX_ROOTS
= 64;
966 wxTreeItemId roots
[MAX_ROOTS
];
967 // VS: this array holds information about whether we've set item icon at
968 // given level. This is necessary because m_Data has a flat structure
969 // and there's no way of recognizing if some item has subitems or not.
970 // We set the icon later: when we find an item with level=n, we know
971 // that the last item with level=n-1 was afolder with subitems, so we
972 // set its icon accordingly
973 bool imaged
[MAX_ROOTS
];
974 m_ContentsBox
->DeleteAllItems();
976 roots
[0] = m_ContentsBox
->AddRoot(_("(Help)"));
979 for (size_t i
= 0; i
< cnt
; i
++)
981 wxHtmlHelpDataItem
*it
= &contents
[i
];
985 if (m_hfStyle
& wxHF_MERGE_BOOKS
)
986 // VS: we don't want book nodes, books' content should
987 // appear under tree's root. This line will create a "fake"
988 // record about book node so that the rest of this look
989 // will believe there really _is_ a book node and will
994 roots
[1] = m_ContentsBox
->AppendItem(roots
[0],
995 it
->name
, IMG_Book
, -1,
996 new wxHtmlHelpTreeItemData(i
));
997 m_ContentsBox
->SetItemBold(roots
[1], true);
1001 // ...and their contents:
1004 roots
[it
->level
+ 1] = m_ContentsBox
->AppendItem(
1005 roots
[it
->level
], it
->name
, IMG_Page
,
1006 -1, new wxHtmlHelpTreeItemData(i
));
1007 imaged
[it
->level
+ 1] = false;
1010 m_PagesHash
->Put(it
->GetFullPath(),
1011 new wxHtmlHelpHashData(i
, roots
[it
->level
+ 1]));
1013 // Set the icon for the node one level up in the hierarchy,
1014 // unless already done (see comment above imaged[] declaration)
1015 if (!imaged
[it
->level
])
1017 int image
= IMG_Folder
;
1018 if (m_hfStyle
& wxHF_ICONS_BOOK
)
1020 else if (m_hfStyle
& wxHF_ICONS_BOOK_CHAPTER
)
1021 image
= (it
->level
== 1) ? IMG_Book
: IMG_Folder
;
1022 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
);
1023 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
,
1024 wxTreeItemIcon_Selected
);
1025 imaged
[it
->level
] = true;
1031 void wxHtmlHelpFrame::CreateIndex()
1036 m_IndexList
->Clear();
1038 size_t cnt
= m_mergedIndex
->size();
1041 if (cnt
> INDEX_IS_SMALL
)
1042 cnttext
.Printf(_("%i of %i"), 0, cnt
);
1044 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1045 m_IndexCountInfo
->SetLabel(cnttext
);
1046 if (cnt
> INDEX_IS_SMALL
)
1049 for (size_t i
= 0; i
< cnt
; i
++)
1050 m_IndexList
->Append((*m_mergedIndex
)[i
].name
,
1051 (char*)(&(*m_mergedIndex
)[i
]));
1054 void wxHtmlHelpFrame::CreateSearch()
1056 if (! (m_SearchList
&& m_SearchChoice
))
1058 m_SearchList
->Clear();
1059 m_SearchChoice
->Clear();
1060 m_SearchChoice
->Append(_("Search in all books"));
1061 const wxHtmlBookRecArray
& bookrec
= m_Data
->GetBookRecArray();
1062 int i
, cnt
= bookrec
.GetCount();
1063 for (i
= 0; i
< cnt
; i
++)
1064 m_SearchChoice
->Append(bookrec
[i
].GetTitle());
1065 m_SearchChoice
->SetSelection(0);
1069 void wxHtmlHelpFrame::RefreshLists()
1071 // Update m_mergedIndex:
1072 UpdateMergedIndex();
1073 // Update the controls
1079 void wxHtmlHelpFrame::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1084 if (path
!= wxEmptyString
)
1086 oldpath
= cfg
->GetPath();
1087 cfg
->SetPath(_T("/") + path
);
1090 m_Cfg
.navig_on
= cfg
->Read(wxT("hcNavigPanel"), m_Cfg
.navig_on
) != 0;
1091 m_Cfg
.sashpos
= cfg
->Read(wxT("hcSashPos"), m_Cfg
.sashpos
);
1092 m_Cfg
.x
= cfg
->Read(wxT("hcX"), m_Cfg
.x
);
1093 m_Cfg
.y
= cfg
->Read(wxT("hcY"), m_Cfg
.y
);
1094 m_Cfg
.w
= cfg
->Read(wxT("hcW"), m_Cfg
.w
);
1095 m_Cfg
.h
= cfg
->Read(wxT("hcH"), m_Cfg
.h
);
1097 m_FixedFace
= cfg
->Read(wxT("hcFixedFace"), m_FixedFace
);
1098 m_NormalFace
= cfg
->Read(wxT("hcNormalFace"), m_NormalFace
);
1099 m_FontSize
= cfg
->Read(wxT("hcBaseFontSize"), m_FontSize
);
1106 cnt
= cfg
->Read(wxT("hcBookmarksCnt"), 0L);
1109 m_BookmarksNames
.Clear();
1110 m_BookmarksPages
.Clear();
1113 m_Bookmarks
->Clear();
1114 m_Bookmarks
->Append(_("(bookmarks)"));
1117 for (i
= 0; i
< cnt
; i
++)
1119 val
.Printf(wxT("hcBookmark_%i"), i
);
1121 m_BookmarksNames
.Add(s
);
1122 if (m_Bookmarks
) m_Bookmarks
->Append(s
);
1123 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1125 m_BookmarksPages
.Add(s
);
1131 m_HtmlWin
->ReadCustomization(cfg
);
1133 if (path
!= wxEmptyString
)
1134 cfg
->SetPath(oldpath
);
1137 void wxHtmlHelpFrame::WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1142 if (path
!= wxEmptyString
)
1144 oldpath
= cfg
->GetPath();
1145 cfg
->SetPath(_T("/") + path
);
1148 cfg
->Write(wxT("hcNavigPanel"), m_Cfg
.navig_on
);
1149 cfg
->Write(wxT("hcSashPos"), (long)m_Cfg
.sashpos
);
1150 if ( !IsIconized() )
1152 // Don't write if iconized as this would make the window
1153 // disappear next time it is shown!
1154 cfg
->Write(wxT("hcX"), (long)m_Cfg
.x
);
1155 cfg
->Write(wxT("hcY"), (long)m_Cfg
.y
);
1156 cfg
->Write(wxT("hcW"), (long)m_Cfg
.w
);
1157 cfg
->Write(wxT("hcH"), (long)m_Cfg
.h
);
1159 cfg
->Write(wxT("hcFixedFace"), m_FixedFace
);
1160 cfg
->Write(wxT("hcNormalFace"), m_NormalFace
);
1161 cfg
->Write(wxT("hcBaseFontSize"), (long)m_FontSize
);
1166 int cnt
= m_BookmarksNames
.GetCount();
1169 cfg
->Write(wxT("hcBookmarksCnt"), (long)cnt
);
1170 for (i
= 0; i
< cnt
; i
++)
1172 val
.Printf(wxT("hcBookmark_%i"), i
);
1173 cfg
->Write(val
, m_BookmarksNames
[i
]);
1174 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1175 cfg
->Write(val
, m_BookmarksPages
[i
]);
1180 m_HtmlWin
->WriteCustomization(cfg
);
1182 if (path
!= wxEmptyString
)
1183 cfg
->SetPath(oldpath
);
1190 static void SetFontsToHtmlWin(wxHtmlWindow
*win
, const wxString
& scalf
, const wxString
& fixf
, int size
)
1193 f_sizes
[0] = int(size
* 0.6);
1194 f_sizes
[1] = int(size
* 0.8);
1196 f_sizes
[3] = int(size
* 1.2);
1197 f_sizes
[4] = int(size
* 1.4);
1198 f_sizes
[5] = int(size
* 1.6);
1199 f_sizes
[6] = int(size
* 1.8);
1201 win
->SetFonts(scalf
, fixf
, f_sizes
);
1205 class wxHtmlHelpFrameOptionsDialog
: public wxDialog
1208 wxComboBox
*NormalFont
, *FixedFont
;
1209 wxSpinCtrl
*FontSize
;
1210 wxHtmlWindow
*TestWin
;
1212 wxHtmlHelpFrameOptionsDialog(wxWindow
*parent
)
1213 : wxDialog(parent
, wxID_ANY
, wxString(_("Help Browser Options")))
1215 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
1216 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2, 3, 2, 5);
1218 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Normal font:")));
1219 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Fixed font:")));
1220 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Font size:")));
1222 sizer
->Add(NormalFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1223 wxSize(200, wxDefaultCoord
),
1224 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1226 sizer
->Add(FixedFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1227 wxSize(200, wxDefaultCoord
),
1228 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1230 sizer
->Add(FontSize
= new wxSpinCtrl(this, wxID_ANY
));
1231 FontSize
->SetRange(2, 100);
1233 topsizer
->Add(sizer
, 0, wxLEFT
|wxRIGHT
|wxTOP
, 10);
1235 topsizer
->Add(new wxStaticText(this, wxID_ANY
, _("Preview:")),
1236 0, wxLEFT
| wxTOP
, 10);
1237 topsizer
->Add(TestWin
= new wxHtmlWindow(this, wxID_ANY
, wxDefaultPosition
, wxSize(20, 150),
1238 wxHW_SCROLLBAR_AUTO
| wxSUNKEN_BORDER
),
1239 1, wxEXPAND
| wxLEFT
|wxTOP
|wxRIGHT
, 10);
1241 wxBoxSizer
*sizer2
= new wxBoxSizer(wxHORIZONTAL
);
1243 sizer2
->Add(ok
= new wxButton(this, wxID_OK
), 0, wxALL
, 10);
1245 sizer2
->Add(new wxButton(this, wxID_CANCEL
), 0, wxALL
, 10);
1246 topsizer
->Add(sizer2
, 0, wxALIGN_RIGHT
);
1249 topsizer
->Fit(this);
1254 void UpdateTestWin()
1257 SetFontsToHtmlWin(TestWin
,
1258 NormalFont
->GetStringSelection(),
1259 FixedFont
->GetStringSelection(),
1260 FontSize
->GetValue());
1262 wxString
content(_("font size"));
1264 content
= _T("<font size=-2>") + content
+ _T(" -2</font><br>")
1265 _T("<font size=-1>") + content
+ _T(" -1</font><br>")
1266 _T("<font size=+0>") + content
+ _T(" +0</font><br>")
1267 _T("<font size=+1>") + content
+ _T(" +1</font><br>")
1268 _T("<font size=+2>") + content
+ _T(" +2</font><br>")
1269 _T("<font size=+3>") + content
+ _T(" +3</font><br>")
1270 _T("<font size=+4>") + content
+ _T(" +4</font><br>") ;
1272 content
= wxString( _T("<html><body><table><tr><td>") ) +
1273 _("Normal face<br>and <u>underlined</u>. ") +
1274 _("<i>Italic face.</i> ") +
1275 _("<b>Bold face.</b> ") +
1276 _("<b><i>Bold italic face.</i></b><br>") +
1278 wxString( _T("</td><td><tt>") ) +
1279 _("Fixed size face.<br> <b>bold</b> <i>italic</i> ") +
1280 _("<b><i>bold italic <u>underlined</u></i></b><br>") +
1282 _T("</tt></td></tr></table></body></html>");
1284 TestWin
->SetPage( content
);
1287 void OnUpdate(wxCommandEvent
& WXUNUSED(event
))
1291 void OnUpdateSpin(wxSpinEvent
& WXUNUSED(event
))
1296 DECLARE_EVENT_TABLE()
1297 DECLARE_NO_COPY_CLASS(wxHtmlHelpFrameOptionsDialog
)
1300 BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog
, wxDialog
)
1301 EVT_COMBOBOX(wxID_ANY
, wxHtmlHelpFrameOptionsDialog::OnUpdate
)
1302 EVT_SPINCTRL(wxID_ANY
, wxHtmlHelpFrameOptionsDialog::OnUpdateSpin
)
1305 void wxHtmlHelpFrame::OptionsDialog()
1307 wxHtmlHelpFrameOptionsDialog
dlg(this);
1310 if (m_NormalFonts
== NULL
)
1312 wxFontEnumerator enu
;
1313 enu
.EnumerateFacenames();
1314 m_NormalFonts
= new wxArrayString
;
1315 *m_NormalFonts
= *enu
.GetFacenames();
1316 m_NormalFonts
->Sort(); // ascending sort
1318 if (m_FixedFonts
== NULL
)
1320 wxFontEnumerator enu
;
1321 enu
.EnumerateFacenames(wxFONTENCODING_SYSTEM
, true /*enum fixed width only*/);
1322 m_FixedFonts
= new wxArrayString
;
1323 *m_FixedFonts
= *enu
.GetFacenames();
1324 m_FixedFonts
->Sort(); // ascending sort
1327 // VS: We want to show the font that is actually used by wxHtmlWindow.
1328 // If customization dialog wasn't used yet, facenames are empty and
1329 // wxHtmlWindow uses default fonts -- let's find out what they
1330 // are so that we can pass them to the dialog:
1331 if (m_NormalFace
.empty())
1333 wxFont
fnt(m_FontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false);
1334 m_NormalFace
= fnt
.GetFaceName();
1336 if (m_FixedFace
.empty())
1338 wxFont
fnt(m_FontSize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false);
1339 m_FixedFace
= fnt
.GetFaceName();
1342 for (i
= 0; i
< m_NormalFonts
->GetCount(); i
++)
1343 dlg
.NormalFont
->Append((*m_NormalFonts
)[i
]);
1344 for (i
= 0; i
< m_FixedFonts
->GetCount(); i
++)
1345 dlg
.FixedFont
->Append((*m_FixedFonts
)[i
]);
1346 if (!m_NormalFace
.empty())
1347 dlg
.NormalFont
->SetStringSelection(m_NormalFace
);
1349 dlg
.NormalFont
->SetSelection(0);
1350 if (!m_FixedFace
.empty())
1351 dlg
.FixedFont
->SetStringSelection(m_FixedFace
);
1353 dlg
.FixedFont
->SetSelection(0);
1354 dlg
.FontSize
->SetValue(m_FontSize
);
1355 dlg
.UpdateTestWin();
1357 if (dlg
.ShowModal() == wxID_OK
)
1359 m_NormalFace
= dlg
.NormalFont
->GetStringSelection();
1360 m_FixedFace
= dlg
.FixedFont
->GetStringSelection();
1361 m_FontSize
= dlg
.FontSize
->GetValue();
1362 SetFontsToHtmlWin(m_HtmlWin
, m_NormalFace
, m_FixedFace
, m_FontSize
);
1368 void wxHtmlHelpFrame::NotifyPageChanged()
1370 if (m_UpdateContents
&& m_PagesHash
)
1372 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1373 wxHtmlHelpHashData
*ha
= NULL
;
1375 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1379 bool olduc
= m_UpdateContents
;
1380 m_UpdateContents
= false;
1381 m_ContentsBox
->SelectItem(ha
->m_Id
);
1382 m_ContentsBox
->EnsureVisible(ha
->m_Id
);
1383 m_UpdateContents
= olduc
;
1395 void wxHtmlHelpFrame::OnActivate(wxActivateEvent
& event
)
1397 // This saves one mouse click when using the
1398 // wxHTML for context sensitive help systems
1400 // NB: wxActivateEvent is a bit broken in wxGTK
1401 // and is sometimes sent when it should not be
1402 if (event
.GetActive() && m_HtmlWin
)
1403 m_HtmlWin
->SetFocus();
1409 void wxHtmlHelpFrame::OnToolbar(wxCommandEvent
& event
)
1411 switch (event
.GetId())
1413 case wxID_HTML_BACK
:
1414 m_HtmlWin
->HistoryBack();
1415 NotifyPageChanged();
1418 case wxID_HTML_FORWARD
:
1419 m_HtmlWin
->HistoryForward();
1420 NotifyPageChanged();
1426 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1427 wxHtmlHelpHashData
*ha
= NULL
;
1429 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1430 if (ha
&& ha
->m_Index
> 0)
1432 const wxHtmlHelpDataItem
& it
= m_Data
->GetContentsArray()[ha
->m_Index
- 1];
1433 if (!it
.page
.empty())
1435 m_HtmlWin
->LoadPage(it
.GetFullPath());
1436 NotifyPageChanged();
1442 case wxID_HTML_UPNODE
:
1445 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1446 wxHtmlHelpHashData
*ha
= NULL
;
1448 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1449 if (ha
&& ha
->m_Index
> 0)
1452 m_Data
->GetContentsArray()[ha
->m_Index
].level
- 1;
1453 int ind
= ha
->m_Index
- 1;
1455 const wxHtmlHelpDataItem
*it
=
1456 &m_Data
->GetContentsArray()[ind
];
1457 while (ind
>= 0 && it
->level
!= level
)
1460 it
= &m_Data
->GetContentsArray()[ind
];
1464 if (!it
->page
.empty())
1466 m_HtmlWin
->LoadPage(it
->GetFullPath());
1467 NotifyPageChanged();
1474 case wxID_HTML_DOWN
:
1477 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1478 wxHtmlHelpHashData
*ha
= NULL
;
1480 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1482 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1483 if (ha
&& ha
->m_Index
< (int)contents
.size() - 1)
1485 size_t idx
= ha
->m_Index
+ 1;
1487 while (contents
[idx
].GetFullPath() == page
) idx
++;
1489 if (!contents
[idx
].page
.empty())
1491 m_HtmlWin
->LoadPage(contents
[idx
].GetFullPath());
1492 NotifyPageChanged();
1498 case wxID_HTML_PANEL
:
1500 if (! (m_Splitter
&& m_NavigPan
))
1502 if (m_Splitter
->IsSplit())
1504 m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1505 m_Splitter
->Unsplit(m_NavigPan
);
1506 m_Cfg
.navig_on
= false;
1512 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
1513 m_Cfg
.navig_on
= true;
1518 case wxID_HTML_OPTIONS
:
1522 case wxID_HTML_BOOKMARKSADD
:
1527 item
= m_HtmlWin
->GetOpenedPageTitle();
1528 url
= m_HtmlWin
->GetOpenedPage();
1529 if (item
== wxEmptyString
)
1530 item
= url
.AfterLast(wxT('/'));
1531 if (m_BookmarksPages
.Index(url
) == wxNOT_FOUND
)
1533 m_Bookmarks
->Append(item
);
1534 m_BookmarksNames
.Add(item
);
1535 m_BookmarksPages
.Add(url
);
1540 case wxID_HTML_BOOKMARKSREMOVE
:
1545 item
= m_Bookmarks
->GetStringSelection();
1546 pos
= m_BookmarksNames
.Index(item
);
1547 if (pos
!= wxNOT_FOUND
)
1549 m_BookmarksNames
.RemoveAt(pos
);
1550 m_BookmarksPages
.RemoveAt(pos
);
1551 m_Bookmarks
->Delete(m_Bookmarks
->GetSelection());
1556 #if wxUSE_PRINTING_ARCHITECTURE
1557 case wxID_HTML_PRINT
:
1559 if (m_Printer
== NULL
)
1560 m_Printer
= new wxHtmlEasyPrinting(_("Help Printing"), this);
1561 if (!m_HtmlWin
->GetOpenedPage())
1562 wxLogWarning(_("Cannot print empty page."));
1564 m_Printer
->PrintFile(m_HtmlWin
->GetOpenedPage());
1569 case wxID_HTML_OPENFILE
:
1571 wxString filemask
= wxString(
1572 _("HTML files (*.html;*.htm)|*.html;*.htm|")) +
1573 _("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|") +
1574 _("HTML Help Project (*.hhp)|*.hhp|") +
1576 _("Compressed HTML Help file (*.chm)|*.chm|") +
1578 _("All files (*.*)|*");
1579 wxString s
= wxFileSelector(_("Open HTML document"),
1584 wxOPEN
| wxFILE_MUST_EXIST
,
1588 wxString ext
= s
.Right(4).Lower();
1589 if (ext
== _T(".zip") || ext
== _T(".htb") ||
1591 ext
== _T(".chm") ||
1600 m_HtmlWin
->LoadPage(s
);
1609 void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent
& event
)
1611 wxHtmlHelpTreeItemData
*pg
;
1613 pg
= (wxHtmlHelpTreeItemData
*) m_ContentsBox
->GetItemData(event
.GetItem());
1615 if (pg
&& m_UpdateContents
)
1617 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1618 m_UpdateContents
= false;
1619 if (!contents
[pg
->m_Id
].page
.empty())
1620 m_HtmlWin
->LoadPage(contents
[pg
->m_Id
].GetFullPath());
1621 m_UpdateContents
= true;
1627 void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent
& WXUNUSED(event
))
1629 wxHtmlHelpMergedIndexItem
*it
= (wxHtmlHelpMergedIndexItem
*)
1630 m_IndexList
->GetClientData(m_IndexList
->GetSelection());
1632 DisplayIndexItem(it
);
1636 void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent
& event
)
1638 wxString sr
= m_IndexText
->GetLineText(0);
1640 if (sr
== wxEmptyString
)
1648 m_IndexList
->Clear();
1649 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1650 size_t cnt
= index
.size();
1653 for (size_t i
= 0; i
< cnt
; i
++)
1655 if (index
[i
].name
.Lower().find(sr
) != wxString::npos
)
1657 int pos
= m_IndexList
->Append(index
[i
].name
,
1658 (char*)(&index
[i
]));
1662 // don't automatically show topic selector if this
1663 // item points to multiple pages:
1664 if (index
[i
].items
.size() == 1)
1666 m_IndexList
->SetSelection(0);
1667 DisplayIndexItem(&index
[i
]);
1671 // if this is nested item of the index, show its parent(s)
1672 // as well, otherwise it would not be clear what entry is
1674 wxHtmlHelpMergedIndexItem
*parent
= index
[i
].parent
;
1678 (index
.Index(*(wxHtmlHelpMergedIndexItem
*)m_IndexList
->GetClientData(pos
-1))) < index
.Index(*parent
))
1680 m_IndexList
->Insert(parent
->name
,
1681 pos
, (char*)parent
);
1682 parent
= parent
->parent
;
1687 // finally, it the item we just added is itself a parent for
1688 // other items, show them as well, because they are refinements
1689 // of the displayed index entry (i.e. it is implicitly contained
1690 // in them: "foo" with parent "bar" reads as "bar, foo"):
1691 int level
= index
[i
].items
[0]->level
;
1693 while (i
< cnt
&& index
[i
].items
[0]->level
> level
)
1695 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1703 cnttext
.Printf(_("%i of %i"), displ
, cnt
);
1704 m_IndexCountInfo
->SetLabel(cnttext
);
1706 m_IndexText
->SetSelection(0, sr
.Length());
1707 m_IndexText
->SetFocus();
1711 void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent
& WXUNUSED(event
))
1715 m_IndexList
->Clear();
1716 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1717 size_t cnt
= index
.size();
1720 for (size_t i
= 0; i
< cnt
; i
++)
1722 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1725 // don't automatically show topic selector if this
1726 // item points to multiple pages:
1727 if (index
[i
].items
.size() == 1)
1729 DisplayIndexItem(&index
[i
]);
1736 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1737 m_IndexCountInfo
->SetLabel(cnttext
);
1741 void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent
& WXUNUSED(event
))
1743 wxHtmlHelpDataItem
*it
= (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(m_SearchList
->GetSelection());
1746 if (!it
->page
.empty())
1747 m_HtmlWin
->LoadPage(it
->GetFullPath());
1748 NotifyPageChanged();
1752 void wxHtmlHelpFrame::OnSearch(wxCommandEvent
& WXUNUSED(event
))
1754 wxString sr
= m_SearchText
->GetLineText(0);
1757 KeywordSearch(sr
, wxHELP_SEARCH_ALL
);
1760 void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent
& WXUNUSED(event
))
1762 wxString sr
= m_Bookmarks
->GetStringSelection();
1764 if (sr
!= wxEmptyString
&& sr
!= _("(bookmarks)"))
1766 m_HtmlWin
->LoadPage(m_BookmarksPages
[m_BookmarksNames
.Index(sr
)]);
1767 NotifyPageChanged();
1771 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent
& evt
)
1773 GetSize(&m_Cfg
.w
, &m_Cfg
.h
);
1774 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
1783 if (m_Splitter
&& m_Cfg
.navig_on
) m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1786 WriteCustomization(m_Config
, m_ConfigRoot
);
1788 if (m_helpController
&& m_helpController
->IsKindOf(CLASSINFO(wxHtmlHelpController
)))
1790 ((wxHtmlHelpController
*) m_helpController
)->OnCloseFrame(evt
);
1797 void wxHtmlHelpFrame::OnClose(wxCommandEvent
& event
)
1802 void wxHtmlHelpFrame::OnAbout(wxCommandEvent
& event
)
1804 wxMessageBox(wxT("wxWidgets HTML Help Viewer (c) 1998-2004, Vaclav Slavik et al"), wxT("HelpView"),
1805 wxICON_INFORMATION
|wxOK
, this);
1809 BEGIN_EVENT_TABLE(wxHtmlHelpFrame
, wxFrame
)
1810 EVT_ACTIVATE(wxHtmlHelpFrame::OnActivate
)
1811 EVT_TOOL_RANGE(wxID_HTML_PANEL
, wxID_HTML_OPTIONS
, wxHtmlHelpFrame::OnToolbar
)
1812 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE
, wxHtmlHelpFrame::OnToolbar
)
1813 EVT_BUTTON(wxID_HTML_BOOKMARKSADD
, wxHtmlHelpFrame::OnToolbar
)
1814 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL
, wxHtmlHelpFrame::OnContentsSel
)
1815 EVT_LISTBOX(wxID_HTML_INDEXLIST
, wxHtmlHelpFrame::OnIndexSel
)
1816 EVT_LISTBOX(wxID_HTML_SEARCHLIST
, wxHtmlHelpFrame::OnSearchSel
)
1817 EVT_BUTTON(wxID_HTML_SEARCHBUTTON
, wxHtmlHelpFrame::OnSearch
)
1818 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT
, wxHtmlHelpFrame::OnSearch
)
1819 EVT_BUTTON(wxID_HTML_INDEXBUTTON
, wxHtmlHelpFrame::OnIndexFind
)
1820 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT
, wxHtmlHelpFrame::OnIndexFind
)
1821 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL
, wxHtmlHelpFrame::OnIndexAll
)
1822 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST
, wxHtmlHelpFrame::OnBookmarksSel
)
1823 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow
)
1825 EVT_MENU(wxID_CLOSE
, wxHtmlHelpFrame::OnClose
)
1826 EVT_MENU(wxID_ABOUT
, wxHtmlHelpFrame::OnAbout
)
1827 EVT_MENU(wxID_HELP_CONTENTS
, wxHtmlHelpFrame::OnAbout
)
1832 #endif // wxUSE_WXHTML_HELP