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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "helpfrm.h"
16 // For compilers that support precompilation, includes "wx.h"
18 #include "wx/wxprec.h"
30 #include "wx/object.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/helpctrl.h"
45 #include "wx/textctrl.h"
46 #include "wx/notebook.h"
47 #include "wx/imaglist.h"
48 #include "wx/treectrl.h"
49 #include "wx/tokenzr.h"
50 #include "wx/wfstream.h"
51 #include "wx/html/htmlwin.h"
52 #include "wx/busyinfo.h"
53 #include "wx/progdlg.h"
54 #include "wx/toolbar.h"
55 #include "wx/fontenum.h"
56 #include "wx/stream.h"
57 #include "wx/filedlg.h"
58 #include "wx/artprov.h"
59 #include "wx/spinctrl.h"
60 #include "wx/dynarray.h"
61 #include "wx/choicdlg.h"
62 #include "wx/settings.h"
64 // what is considered "small index"?
65 #define INDEX_IS_SMALL 100
67 /* Motif defines this as a macro */
72 //--------------------------------------------------------------------------
73 // wxHtmlHelpTreeItemData (private)
74 //--------------------------------------------------------------------------
76 class wxHtmlHelpTreeItemData
: public wxTreeItemData
79 #if defined(__VISAGECPP__)
80 // VA needs a default ctor for some reason....
81 wxHtmlHelpTreeItemData() : wxTreeItemData()
84 wxHtmlHelpTreeItemData(int id
) : wxTreeItemData()
91 //--------------------------------------------------------------------------
92 // wxHtmlHelpHashData (private)
93 //--------------------------------------------------------------------------
95 class wxHtmlHelpHashData
: public wxObject
98 wxHtmlHelpHashData(int index
, wxTreeItemId id
) : wxObject()
99 { m_Index
= index
; m_Id
= id
;}
100 ~wxHtmlHelpHashData() {}
107 //--------------------------------------------------------------------------
108 // wxHtmlHelpHtmlWindow (private)
109 //--------------------------------------------------------------------------
111 class wxHtmlHelpHtmlWindow
: public wxHtmlWindow
114 wxHtmlHelpHtmlWindow(wxHtmlHelpFrame
*fr
, wxWindow
*parent
)
115 : wxHtmlWindow(parent
), m_Frame(fr
)
120 virtual void OnLinkClicked(const wxHtmlLinkInfo
& link
)
122 wxHtmlWindow::OnLinkClicked(link
);
123 const wxMouseEvent
*e
= link
.GetEvent();
124 if (e
== NULL
|| e
->LeftUp())
125 m_Frame
->NotifyPageChanged();
129 wxHtmlHelpFrame
*m_Frame
;
131 DECLARE_NO_COPY_CLASS(wxHtmlHelpHtmlWindow
)
135 //---------------------------------------------------------------------------
136 // wxHtmlHelpFrame::m_mergedIndex
137 //---------------------------------------------------------------------------
139 WX_DEFINE_ARRAY_PTR(const wxHtmlHelpDataItem
*, wxHtmlHelpDataItemPtrArray
);
141 struct wxHtmlHelpMergedIndexItem
143 wxHtmlHelpMergedIndexItem
*parent
;
145 wxHtmlHelpDataItemPtrArray items
;
148 WX_DECLARE_OBJARRAY(wxHtmlHelpMergedIndexItem
, wxHtmlHelpMergedIndex
);
149 #include "wx/arrimpl.cpp"
150 WX_DEFINE_OBJARRAY(wxHtmlHelpMergedIndex
)
152 void wxHtmlHelpFrame::UpdateMergedIndex()
154 delete m_mergedIndex
;
155 m_mergedIndex
= new wxHtmlHelpMergedIndex
;
156 wxHtmlHelpMergedIndex
& merged
= *m_mergedIndex
;
158 const wxHtmlHelpDataItems
& items
= m_Data
->GetIndexArray();
159 size_t len
= items
.size();
161 wxHtmlHelpMergedIndexItem
*history
[128] = {NULL
};
163 for (size_t i
= 0; i
< len
; i
++)
165 const wxHtmlHelpDataItem
& item
= items
[i
];
166 wxASSERT_MSG( item
.level
< 128, _T("nested index entries too deep") );
168 if (history
[item
.level
] &&
169 history
[item
.level
]->items
[0]->name
== item
.name
)
171 // same index entry as previous one, update list of items
172 history
[item
.level
]->items
.Add(&item
);
177 wxHtmlHelpMergedIndexItem
*mi
= new wxHtmlHelpMergedIndexItem();
178 mi
->name
= item
.GetIndentedName();
179 mi
->items
.Add(&item
);
180 mi
->parent
= (item
.level
== 0) ? NULL
: history
[item
.level
- 1];
181 history
[item
.level
] = mi
;
188 //---------------------------------------------------------------------------
190 //---------------------------------------------------------------------------
195 //wxID_HTML_HELPFRAME = wxID_HIGHEST + 1,
196 wxID_HTML_PANEL
= wxID_HIGHEST
+ 2,
205 wxID_HTML_BOOKMARKSLIST
,
206 wxID_HTML_BOOKMARKSADD
,
207 wxID_HTML_BOOKMARKSREMOVE
,
212 wxID_HTML_INDEXBUTTON
,
213 wxID_HTML_INDEXBUTTONALL
,
215 wxID_HTML_SEARCHPAGE
,
216 wxID_HTML_SEARCHTEXT
,
217 wxID_HTML_SEARCHLIST
,
218 wxID_HTML_SEARCHBUTTON
,
219 wxID_HTML_SEARCHCHOICE
,
224 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame
, wxFrame
)
226 wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow
* parent
, wxWindowID id
, const wxString
& title
,
227 int style
, wxHtmlHelpData
* data
)
230 Create(parent
, id
, title
, style
);
233 void wxHtmlHelpFrame::Init(wxHtmlHelpData
* data
)
238 m_DataCreated
= false;
241 m_Data
= new wxHtmlHelpData();
242 m_DataCreated
= true;
245 m_ContentsBox
= NULL
;
247 m_IndexButton
= NULL
;
248 m_IndexButtonAll
= NULL
;
251 m_SearchButton
= NULL
;
253 m_SearchChoice
= NULL
;
254 m_IndexCountInfo
= NULL
;
257 m_NavigNotebook
= NULL
;
260 m_SearchCaseSensitive
= NULL
;
261 m_SearchWholeWords
= NULL
;
263 m_mergedIndex
= NULL
;
266 m_ConfigRoot
= wxEmptyString
;
268 m_Cfg
.x
= m_Cfg
.y
= 0;
272 m_Cfg
.navig_on
= true;
274 m_NormalFonts
= m_FixedFonts
= NULL
;
275 m_NormalFace
= m_FixedFace
= wxEmptyString
;
282 #if wxUSE_PRINTING_ARCHITECTURE
287 m_UpdateContents
= true;
288 m_helpController
= (wxHelpControllerBase
*) NULL
;
291 // Create: builds the GUI components.
292 // with the style flag it's possible to toggle the toolbar, contents, index and search
294 // m_HtmlWin will *always* be created, but it's important to realize that
295 // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
296 // m_SearchButton may be NULL.
297 // moreover, if no contents, index or searchpage is needed, m_Splitter and
298 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
300 bool wxHtmlHelpFrame::Create(wxWindow
* parent
, wxWindowID id
,
301 const wxString
& WXUNUSED(title
), int style
)
305 wxImageList
*ContentsImageList
= new wxImageList(16, 16);
306 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK
,
309 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER
,
312 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE
,
316 // Do the config in two steps. We read the HtmlWindow customization after we
317 // create the window.
319 ReadCustomization(m_Config
, m_ConfigRoot
);
321 wxFrame::Create(parent
, id
, _("Help"),
322 wxPoint(m_Cfg
.x
, m_Cfg
.y
), wxSize(m_Cfg
.w
, m_Cfg
.h
),
323 wxDEFAULT_FRAME_STYLE
, wxT("wxHtmlHelp"));
325 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
327 SetIcon(wxArtProvider::GetIcon(wxART_HELP
, wxART_HELP_BROWSER
));
329 // On the Mac, each modeless frame must have a menubar.
330 // TODO: add more menu items, and perhaps add a style to show
331 // the menubar: compulsory on the Mac, optional elsewhere.
333 wxMenuBar
* menuBar
= new wxMenuBar
;
335 wxMenu
* fileMenu
= new wxMenu
;
336 fileMenu
->Append(wxID_HTML_OPENFILE
, _("&Open..."));
337 fileMenu
->AppendSeparator();
338 fileMenu
->Append(wxID_CLOSE
, _("&Close"));
340 wxMenu
* helpMenu
= new wxMenu
;
341 helpMenu
->Append(wxID_ABOUT
, _("&About..."));
342 // Ensures we don't get an empty help menu
343 helpMenu
->Append(wxID_HELP_CONTENTS
, _("&About..."));
345 menuBar
->Append(fileMenu
,_("&File"));
346 menuBar
->Append(helpMenu
,_("&Help"));
350 int notebook_page
= 0;
354 #endif // wxUSE_STATUSBAR
358 if (style
& (wxHF_TOOLBAR
| wxHF_FLAT_TOOLBAR
))
360 wxToolBar
*toolBar
= CreateToolBar(wxNO_BORDER
| wxTB_HORIZONTAL
|
362 (style
& wxHF_FLAT_TOOLBAR
? wxTB_FLAT
: 0));
363 toolBar
->SetMargins( 2, 2 );
364 AddToolbarButtons(toolBar
, style
);
367 #endif //wxUSE_TOOLBAR
369 wxSizer
*navigSizer
= NULL
;
371 if (style
& (wxHF_CONTENTS
| wxHF_INDEX
| wxHF_SEARCH
))
373 // traditional help controller; splitter window with html page on the
374 // right and a notebook containing various pages on the left
375 m_Splitter
= new wxSplitterWindow(this);
377 m_HtmlWin
= new wxHtmlHelpHtmlWindow(this, m_Splitter
);
378 m_NavigPan
= new wxPanel(m_Splitter
, wxID_ANY
);
379 m_NavigNotebook
= new wxNotebook(m_NavigPan
, wxID_HTML_NOTEBOOK
,
380 wxDefaultPosition
, wxDefaultSize
);
382 navigSizer
= new wxBoxSizer(wxVERTICAL
);
383 navigSizer
->Add(m_NavigNotebook
, 1, wxEXPAND
);
385 m_NavigPan
->SetSizer(navigSizer
);
388 { // only html window, no notebook with index,contents etc
389 m_HtmlWin
= new wxHtmlWindow(this);
392 m_HtmlWin
->SetRelatedFrame(this, m_TitleFormat
);
394 m_HtmlWin
->SetRelatedStatusBar(0);
395 #endif // wxUSE_STATUSBAR
397 m_HtmlWin
->ReadCustomization(m_Config
, m_ConfigRoot
);
399 // contents tree panel?
400 if ( style
& wxHF_CONTENTS
)
402 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
403 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
405 topsizer
->Add(0, 10);
407 dummy
->SetSizer(topsizer
);
409 if ( style
& wxHF_BOOKMARKS
)
411 m_Bookmarks
= new wxComboBox(dummy
, wxID_HTML_BOOKMARKSLIST
,
413 wxDefaultPosition
, wxDefaultSize
,
414 0, NULL
, wxCB_READONLY
| wxCB_SORT
);
415 m_Bookmarks
->Append(_("(bookmarks)"));
416 for (unsigned i
= 0; i
< m_BookmarksNames
.GetCount(); i
++)
417 m_Bookmarks
->Append(m_BookmarksNames
[i
]);
418 m_Bookmarks
->SetSelection(0);
420 wxBitmapButton
*bmpbt1
, *bmpbt2
;
421 bmpbt1
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSADD
,
422 wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK
,
424 bmpbt2
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSREMOVE
,
425 wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK
,
428 bmpbt1
->SetToolTip(_("Add current page to bookmarks"));
429 bmpbt2
->SetToolTip(_("Remove current page from bookmarks"));
430 #endif // wxUSE_TOOLTIPS
432 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
434 sizer
->Add(m_Bookmarks
, 1, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 5);
435 sizer
->Add(bmpbt1
, 0, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 2);
436 sizer
->Add(bmpbt2
, 0, wxALIGN_CENTRE_VERTICAL
, 0);
438 topsizer
->Add(sizer
, 0, wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
, 10);
441 m_ContentsBox
= new wxTreeCtrl(dummy
, wxID_HTML_TREECTRL
,
442 wxDefaultPosition
, wxDefaultSize
,
445 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
449 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
454 m_ContentsBox
->AssignImageList(ContentsImageList
);
456 topsizer
->Add(m_ContentsBox
, 1,
457 wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
,
460 m_NavigNotebook
->AddPage(dummy
, _("Contents"));
461 m_ContentsPage
= notebook_page
++;
464 // index listbox panel?
465 if ( style
& wxHF_INDEX
)
467 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
468 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
470 dummy
->SetSizer(topsizer
);
472 m_IndexText
= new wxTextCtrl(dummy
, wxID_HTML_INDEXTEXT
, wxEmptyString
,
473 wxDefaultPosition
, wxDefaultSize
,
475 m_IndexButton
= new wxButton(dummy
, wxID_HTML_INDEXBUTTON
, _("Find"));
476 m_IndexButtonAll
= new wxButton(dummy
, wxID_HTML_INDEXBUTTONALL
,
478 m_IndexCountInfo
= new wxStaticText(dummy
, wxID_HTML_COUNTINFO
,
479 wxEmptyString
, wxDefaultPosition
,
481 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
482 m_IndexList
= new wxListBox(dummy
, wxID_HTML_INDEXLIST
,
483 wxDefaultPosition
, wxDefaultSize
,
484 0, NULL
, wxLB_SINGLE
);
487 m_IndexButton
->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
488 m_IndexButtonAll
->SetToolTip(_("Show all items in index"));
489 #endif //wxUSE_TOOLTIPS
491 topsizer
->Add(m_IndexText
, 0, wxEXPAND
| wxALL
, 10);
492 wxSizer
*btsizer
= new wxBoxSizer(wxHORIZONTAL
);
493 btsizer
->Add(m_IndexButton
, 0, wxRIGHT
, 2);
494 btsizer
->Add(m_IndexButtonAll
);
495 topsizer
->Add(btsizer
, 0,
496 wxALIGN_RIGHT
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
497 topsizer
->Add(m_IndexCountInfo
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 2);
498 topsizer
->Add(m_IndexList
, 1, wxEXPAND
| wxALL
, 2);
500 m_NavigNotebook
->AddPage(dummy
, _("Index"));
501 m_IndexPage
= notebook_page
++;
504 // search list panel?
505 if ( style
& wxHF_SEARCH
)
507 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
508 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
510 dummy
->SetSizer(sizer
);
512 m_SearchText
= new wxTextCtrl(dummy
, wxID_HTML_SEARCHTEXT
,
514 wxDefaultPosition
, wxDefaultSize
,
516 m_SearchChoice
= new wxChoice(dummy
, wxID_HTML_SEARCHCHOICE
,
517 wxDefaultPosition
, wxSize(125,-1));
518 m_SearchCaseSensitive
= new wxCheckBox(dummy
, wxID_ANY
, _("Case sensitive"));
519 m_SearchWholeWords
= new wxCheckBox(dummy
, wxID_ANY
, _("Whole words only"));
520 m_SearchButton
= new wxButton(dummy
, wxID_HTML_SEARCHBUTTON
, _("Search"));
522 m_SearchButton
->SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
523 #endif //wxUSE_TOOLTIPS
524 m_SearchList
= new wxListBox(dummy
, wxID_HTML_SEARCHLIST
,
525 wxDefaultPosition
, wxDefaultSize
,
526 0, NULL
, wxLB_SINGLE
);
528 sizer
->Add(m_SearchText
, 0, wxEXPAND
| wxALL
, 10);
529 sizer
->Add(m_SearchChoice
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
530 sizer
->Add(m_SearchCaseSensitive
, 0, wxLEFT
| wxRIGHT
, 10);
531 sizer
->Add(m_SearchWholeWords
, 0, wxLEFT
| wxRIGHT
, 10);
532 sizer
->Add(m_SearchButton
, 0, wxALL
| wxALIGN_RIGHT
, 8);
533 sizer
->Add(m_SearchList
, 1, wxALL
| wxEXPAND
, 2);
535 m_NavigNotebook
->AddPage(dummy
, _("Search"));
536 m_SearchPage
= notebook_page
;
545 navigSizer
->SetSizeHints(m_NavigPan
);
546 m_NavigPan
->Layout();
550 if ( m_NavigPan
&& m_Splitter
)
552 m_Splitter
->SetMinimumPaneSize(20);
553 if ( m_Cfg
.navig_on
)
554 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
556 if ( m_Cfg
.navig_on
)
559 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
563 m_NavigPan
->Show(false);
564 m_Splitter
->Initialize(m_HtmlWin
);
568 // Reduce flicker by updating the splitter pane sizes before the
570 wxSizeEvent
sizeEvent(GetSize(), GetId());
571 ProcessEvent(sizeEvent
);
573 m_Splitter
->UpdateSize();
578 wxHtmlHelpFrame::~wxHtmlHelpFrame()
580 delete m_mergedIndex
;
582 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
585 if (m_NormalFonts
) delete m_NormalFonts
;
586 if (m_FixedFonts
) delete m_FixedFonts
;
589 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
592 #if wxUSE_PRINTING_ARCHITECTURE
593 if (m_Printer
) delete m_Printer
;
599 void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar
*toolBar
, int style
)
601 wxBitmap wpanelBitmap
=
602 wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL
, wxART_TOOLBAR
);
603 wxBitmap wbackBitmap
=
604 wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_TOOLBAR
);
605 wxBitmap wforwardBitmap
=
606 wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_TOOLBAR
);
607 wxBitmap wupnodeBitmap
=
608 wxArtProvider::GetBitmap(wxART_GO_TO_PARENT
, wxART_TOOLBAR
);
610 wxArtProvider::GetBitmap(wxART_GO_UP
, wxART_TOOLBAR
);
611 wxBitmap wdownBitmap
=
612 wxArtProvider::GetBitmap(wxART_GO_DOWN
, wxART_TOOLBAR
);
613 wxBitmap wopenBitmap
=
614 wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_TOOLBAR
);
615 wxBitmap wprintBitmap
=
616 wxArtProvider::GetBitmap(wxART_PRINT
, wxART_TOOLBAR
);
617 wxBitmap woptionsBitmap
=
618 wxArtProvider::GetBitmap(wxART_HELP_SETTINGS
, wxART_TOOLBAR
);
620 wxASSERT_MSG( (wpanelBitmap
.Ok() && wbackBitmap
.Ok() &&
621 wforwardBitmap
.Ok() && wupnodeBitmap
.Ok() &&
622 wupBitmap
.Ok() && wdownBitmap
.Ok() &&
623 wopenBitmap
.Ok() && wprintBitmap
.Ok() &&
624 woptionsBitmap
.Ok()),
625 wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
628 toolBar
->AddTool(wxID_HTML_PANEL
, wpanelBitmap
, wxNullBitmap
,
629 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
630 _("Show/hide navigation panel"));
632 toolBar
->AddSeparator();
633 toolBar
->AddTool(wxID_HTML_BACK
, wbackBitmap
, wxNullBitmap
,
634 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
636 toolBar
->AddTool(wxID_HTML_FORWARD
, wforwardBitmap
, wxNullBitmap
,
637 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
639 toolBar
->AddSeparator();
641 toolBar
->AddTool(wxID_HTML_UPNODE
, wupnodeBitmap
, wxNullBitmap
,
642 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
643 _("Go one level up in document hierarchy"));
644 toolBar
->AddTool(wxID_HTML_UP
, wupBitmap
, wxNullBitmap
,
645 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
647 toolBar
->AddTool(wxID_HTML_DOWN
, wdownBitmap
, wxNullBitmap
,
648 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
651 if ((style
& wxHF_PRINT
) || (style
& wxHF_OPEN_FILES
))
652 toolBar
->AddSeparator();
654 if (style
& wxHF_OPEN_FILES
)
655 toolBar
->AddTool(wxID_HTML_OPENFILE
, wopenBitmap
, wxNullBitmap
,
656 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
657 _("Open HTML document"));
659 #if wxUSE_PRINTING_ARCHITECTURE
660 if (style
& wxHF_PRINT
)
661 toolBar
->AddTool(wxID_HTML_PRINT
, wprintBitmap
, wxNullBitmap
,
662 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
663 _("Print this page"));
666 toolBar
->AddSeparator();
667 toolBar
->AddTool(wxID_HTML_OPTIONS
, woptionsBitmap
, wxNullBitmap
,
668 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
669 _("Display options dialog"));
671 #endif //wxUSE_TOOLBAR
674 void wxHtmlHelpFrame::SetTitleFormat(const wxString
& format
)
677 m_HtmlWin
->SetRelatedFrame(this, format
);
678 m_TitleFormat
= format
;
682 bool wxHtmlHelpFrame::Display(const wxString
& x
)
684 wxString url
= m_Data
->FindPageByName(x
);
687 m_HtmlWin
->LoadPage(url
);
695 bool wxHtmlHelpFrame::Display(const int id
)
697 wxString url
= m_Data
->FindPageById(id
);
700 m_HtmlWin
->LoadPage(url
);
710 bool wxHtmlHelpFrame::DisplayContents()
715 if (!m_Splitter
->IsSplit())
719 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
720 m_Cfg
.navig_on
= true;
723 m_NavigNotebook
->SetSelection(0);
725 if (m_Data
->GetBookRecArray().GetCount() > 0)
727 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
728 if (!book
.GetStart().IsEmpty())
729 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
737 bool wxHtmlHelpFrame::DisplayIndex()
742 if (!m_Splitter
->IsSplit())
746 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
749 m_NavigNotebook
->SetSelection(1);
751 if (m_Data
->GetBookRecArray().GetCount() > 0)
753 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
754 if (!book
.GetStart().IsEmpty())
755 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
761 void wxHtmlHelpFrame::DisplayIndexItem(const wxHtmlHelpMergedIndexItem
*it
)
763 if (it
->items
.size() == 1)
765 if (!it
->items
[0]->page
.empty())
767 m_HtmlWin
->LoadPage(it
->items
[0]->GetFullPath());
773 wxBusyCursor busy_cursor
;
775 // more pages associated with this index item -- let the user choose
776 // which one she/he wants from a list:
778 size_t len
= it
->items
.size();
779 for (size_t i
= 0; i
< len
; i
++)
781 wxString page
= it
->items
[i
]->page
;
782 // try to find page's title in contents:
783 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
784 size_t clen
= contents
.size();
785 for (size_t j
= 0; j
< clen
; j
++)
787 if (contents
[j
].page
== page
)
789 page
= contents
[j
].name
;
796 wxSingleChoiceDialog
dlg(this,
797 _("Please choose the page to display:"),
799 arr
, NULL
, wxCHOICEDLG_STYLE
& ~wxCENTRE
);
800 if (dlg
.ShowModal() == wxID_OK
)
802 m_HtmlWin
->LoadPage(it
->items
[dlg
.GetSelection()]->GetFullPath());
809 bool wxHtmlHelpFrame::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
);
890 wxCommandEvent dummy
;
891 OnIndexFind(dummy
); // what a hack...
892 m_IndexButton
->Enable();
893 m_IndexButtonAll
->Enable();
894 foundcnt
= m_IndexList
->GetCount();
902 wxFAIL_MSG( _T("unknown help search mode") );
905 case wxHELP_SEARCH_ALL
:
907 wxHtmlHelpDataItem
*it
=
908 (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(0);
911 m_HtmlWin
->LoadPage(it
->GetFullPath());
917 case wxHELP_SEARCH_INDEX
:
919 wxHtmlHelpMergedIndexItem
* it
=
920 (wxHtmlHelpMergedIndexItem
*) m_IndexList
->GetClientData(0);
922 DisplayIndexItem(it
);
932 void wxHtmlHelpFrame::CreateContents()
939 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
943 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
945 size_t cnt
= contents
.size();
947 m_PagesHash
= new wxHashTable(wxKEY_STRING
, 2 * cnt
);
949 const int MAX_ROOTS
= 64;
950 wxTreeItemId roots
[MAX_ROOTS
];
951 // VS: this array holds information about whether we've set item icon at
952 // given level. This is neccessary because m_Data has flat structure
953 // and there's no way of recognizing if some item has subitems or not.
954 // We set the icon later: when we find an item with level=n, we know
955 // that the last item with level=n-1 was folder with subitems, so we
956 // set its icon accordingly
957 bool imaged
[MAX_ROOTS
];
958 m_ContentsBox
->DeleteAllItems();
960 roots
[0] = m_ContentsBox
->AddRoot(_("(Help)"));
963 for (size_t i
= 0; i
< cnt
; i
++)
965 wxHtmlHelpDataItem
*it
= &contents
[i
];
969 if (m_hfStyle
& wxHF_MERGE_BOOKS
)
970 // VS: we don't want book nodes, books' content should
971 // appear under tree's root. This line will create "fake"
972 // record about book node so that the rest of this look
973 // will believe there really _is_ book node and will
978 roots
[1] = m_ContentsBox
->AppendItem(roots
[0],
979 it
->name
, IMG_Book
, -1,
980 new wxHtmlHelpTreeItemData(i
));
981 m_ContentsBox
->SetItemBold(roots
[1], true);
985 // ...and their contents:
988 roots
[it
->level
+ 1] = m_ContentsBox
->AppendItem(
989 roots
[it
->level
], it
->name
, IMG_Page
,
990 -1, new wxHtmlHelpTreeItemData(i
));
991 imaged
[it
->level
+ 1] = false;
994 m_PagesHash
->Put(it
->GetFullPath(),
995 new wxHtmlHelpHashData(i
, roots
[it
->level
+ 1]));
997 // Set the icon for the node one level up in the hiearachy,
998 // unless already done (see comment above imaged[] declaration)
999 if (!imaged
[it
->level
])
1001 int image
= IMG_Folder
;
1002 if (m_hfStyle
& wxHF_ICONS_BOOK
)
1004 else if (m_hfStyle
& wxHF_ICONS_BOOK_CHAPTER
)
1005 image
= (it
->level
== 1) ? IMG_Book
: IMG_Folder
;
1006 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
);
1007 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
,
1008 wxTreeItemIcon_Selected
);
1009 imaged
[it
->level
] = true;
1015 void wxHtmlHelpFrame::CreateIndex()
1020 m_IndexList
->Clear();
1022 size_t cnt
= m_mergedIndex
->size();
1025 if (cnt
> INDEX_IS_SMALL
)
1026 cnttext
.Printf(_("%i of %i"), 0, cnt
);
1028 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1029 m_IndexCountInfo
->SetLabel(cnttext
);
1030 if (cnt
> INDEX_IS_SMALL
)
1033 for (size_t i
= 0; i
< cnt
; i
++)
1034 m_IndexList
->Append((*m_mergedIndex
)[i
].name
,
1035 (char*)(&(*m_mergedIndex
)[i
]));
1038 void wxHtmlHelpFrame::CreateSearch()
1040 if (! (m_SearchList
&& m_SearchChoice
))
1042 m_SearchList
->Clear();
1043 m_SearchChoice
->Clear();
1044 m_SearchChoice
->Append(_("Search in all books"));
1045 const wxHtmlBookRecArray
& bookrec
= m_Data
->GetBookRecArray();
1046 int i
, cnt
= bookrec
.GetCount();
1047 for (i
= 0; i
< cnt
; i
++)
1048 m_SearchChoice
->Append(bookrec
[i
].GetTitle());
1049 m_SearchChoice
->SetSelection(0);
1053 void wxHtmlHelpFrame::RefreshLists()
1055 // Update m_mergedIndex:
1056 UpdateMergedIndex();
1057 // Update the controls
1063 void wxHtmlHelpFrame::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1068 if (path
!= wxEmptyString
)
1070 oldpath
= cfg
->GetPath();
1071 cfg
->SetPath(_T("/") + path
);
1074 m_Cfg
.navig_on
= cfg
->Read(wxT("hcNavigPanel"), m_Cfg
.navig_on
) != 0;
1075 m_Cfg
.sashpos
= cfg
->Read(wxT("hcSashPos"), m_Cfg
.sashpos
);
1076 m_Cfg
.x
= cfg
->Read(wxT("hcX"), m_Cfg
.x
);
1077 m_Cfg
.y
= cfg
->Read(wxT("hcY"), m_Cfg
.y
);
1078 m_Cfg
.w
= cfg
->Read(wxT("hcW"), m_Cfg
.w
);
1079 m_Cfg
.h
= cfg
->Read(wxT("hcH"), m_Cfg
.h
);
1081 m_FixedFace
= cfg
->Read(wxT("hcFixedFace"), m_FixedFace
);
1082 m_NormalFace
= cfg
->Read(wxT("hcNormalFace"), m_NormalFace
);
1083 m_FontSize
= cfg
->Read(wxT("hcBaseFontSize"), m_FontSize
);
1090 cnt
= cfg
->Read(wxT("hcBookmarksCnt"), 0L);
1093 m_BookmarksNames
.Clear();
1094 m_BookmarksPages
.Clear();
1097 m_Bookmarks
->Clear();
1098 m_Bookmarks
->Append(_("(bookmarks)"));
1101 for (i
= 0; i
< cnt
; i
++)
1103 val
.Printf(wxT("hcBookmark_%i"), i
);
1105 m_BookmarksNames
.Add(s
);
1106 if (m_Bookmarks
) m_Bookmarks
->Append(s
);
1107 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1109 m_BookmarksPages
.Add(s
);
1115 m_HtmlWin
->ReadCustomization(cfg
);
1117 if (path
!= wxEmptyString
)
1118 cfg
->SetPath(oldpath
);
1121 void wxHtmlHelpFrame::WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1126 if (path
!= wxEmptyString
)
1128 oldpath
= cfg
->GetPath();
1129 cfg
->SetPath(_T("/") + path
);
1132 cfg
->Write(wxT("hcNavigPanel"), m_Cfg
.navig_on
);
1133 cfg
->Write(wxT("hcSashPos"), (long)m_Cfg
.sashpos
);
1134 if ( !IsIconized() )
1136 // Don't write if iconized as this would make the window
1137 // disappear next time it is shown!
1138 cfg
->Write(wxT("hcX"), (long)m_Cfg
.x
);
1139 cfg
->Write(wxT("hcY"), (long)m_Cfg
.y
);
1140 cfg
->Write(wxT("hcW"), (long)m_Cfg
.w
);
1141 cfg
->Write(wxT("hcH"), (long)m_Cfg
.h
);
1143 cfg
->Write(wxT("hcFixedFace"), m_FixedFace
);
1144 cfg
->Write(wxT("hcNormalFace"), m_NormalFace
);
1145 cfg
->Write(wxT("hcBaseFontSize"), (long)m_FontSize
);
1150 int cnt
= m_BookmarksNames
.GetCount();
1153 cfg
->Write(wxT("hcBookmarksCnt"), (long)cnt
);
1154 for (i
= 0; i
< cnt
; i
++)
1156 val
.Printf(wxT("hcBookmark_%i"), i
);
1157 cfg
->Write(val
, m_BookmarksNames
[i
]);
1158 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1159 cfg
->Write(val
, m_BookmarksPages
[i
]);
1164 m_HtmlWin
->WriteCustomization(cfg
);
1166 if (path
!= wxEmptyString
)
1167 cfg
->SetPath(oldpath
);
1174 static void SetFontsToHtmlWin(wxHtmlWindow
*win
, wxString scalf
, wxString fixf
, int size
)
1177 f_sizes
[0] = int(size
* 0.6);
1178 f_sizes
[1] = int(size
* 0.8);
1180 f_sizes
[3] = int(size
* 1.2);
1181 f_sizes
[4] = int(size
* 1.4);
1182 f_sizes
[5] = int(size
* 1.6);
1183 f_sizes
[6] = int(size
* 1.8);
1185 win
->SetFonts(scalf
, fixf
, f_sizes
);
1189 class wxHtmlHelpFrameOptionsDialog
: public wxDialog
1192 wxComboBox
*NormalFont
, *FixedFont
;
1193 wxSpinCtrl
*FontSize
;
1194 wxHtmlWindow
*TestWin
;
1196 wxHtmlHelpFrameOptionsDialog(wxWindow
*parent
)
1197 : wxDialog(parent
, wxID_ANY
, wxString(_("Help Browser Options")))
1199 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
1200 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2, 3, 2, 5);
1202 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Normal font:")));
1203 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Fixed font:")));
1204 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Font size:")));
1206 sizer
->Add(NormalFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1207 wxSize(200, wxDefaultCoord
),
1208 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1210 sizer
->Add(FixedFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1211 wxSize(200, wxDefaultCoord
),
1212 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1214 sizer
->Add(FontSize
= new wxSpinCtrl(this, wxID_ANY
));
1215 FontSize
->SetRange(2, 100);
1217 topsizer
->Add(sizer
, 0, wxLEFT
|wxRIGHT
|wxTOP
, 10);
1219 topsizer
->Add(new wxStaticText(this, wxID_ANY
, _("Preview:")),
1220 0, wxLEFT
| wxTOP
, 10);
1221 topsizer
->Add(TestWin
= new wxHtmlWindow(this, wxID_ANY
, wxDefaultPosition
, wxSize(20, 150),
1222 wxHW_SCROLLBAR_AUTO
| wxSUNKEN_BORDER
),
1223 1, wxEXPAND
| wxLEFT
|wxTOP
|wxRIGHT
, 10);
1225 wxBoxSizer
*sizer2
= new wxBoxSizer(wxHORIZONTAL
);
1227 sizer2
->Add(ok
= new wxButton(this, wxID_OK
), 0, wxALL
, 10);
1229 sizer2
->Add(new wxButton(this, wxID_CANCEL
), 0, wxALL
, 10);
1230 topsizer
->Add(sizer2
, 0, wxALIGN_RIGHT
);
1233 topsizer
->Fit(this);
1238 void UpdateTestWin()
1241 SetFontsToHtmlWin(TestWin
,
1242 NormalFont
->GetStringSelection(),
1243 FixedFont
->GetStringSelection(),
1244 FontSize
->GetValue());
1246 wxString
content(_("font size"));
1248 content
= _T("<font size=-2>") + content
+ _T(" -2</font><br>")
1249 _T("<font size=-1>") + content
+ _T(" -1</font><br>")
1250 _T("<font size=+0>") + content
+ _T(" +0</font><br>")
1251 _T("<font size=+1>") + content
+ _T(" +1</font><br>")
1252 _T("<font size=+2>") + content
+ _T(" +2</font><br>")
1253 _T("<font size=+3>") + content
+ _T(" +3</font><br>")
1254 _T("<font size=+4>") + content
+ _T(" +4</font><br>") ;
1256 content
= wxString( _T("<html><body><table><tr><td>") ) +
1257 _("Normal face<br>and <u>underlined</u>. ") +
1258 _("<i>Italic face.</i> ") +
1259 _("<b>Bold face.</b> ") +
1260 _("<b><i>Bold italic face.</i></b><br>") +
1262 wxString( _T("</td><td><tt>") ) +
1263 _("Fixed size face.<br> <b>bold</b> <i>italic</i> ") +
1264 _("<b><i>bold italic <u>underlined</u></i></b><br>") +
1266 _T("</tt></td></tr></table></body></html>");
1268 TestWin
->SetPage( content
);
1271 void OnUpdate(wxCommandEvent
& WXUNUSED(event
))
1275 void OnUpdateSpin(wxSpinEvent
& WXUNUSED(event
))
1280 DECLARE_EVENT_TABLE()
1281 DECLARE_NO_COPY_CLASS(wxHtmlHelpFrameOptionsDialog
)
1284 BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog
, wxDialog
)
1285 EVT_COMBOBOX(wxID_ANY
, wxHtmlHelpFrameOptionsDialog::OnUpdate
)
1286 EVT_SPINCTRL(wxID_ANY
, wxHtmlHelpFrameOptionsDialog::OnUpdateSpin
)
1289 void wxHtmlHelpFrame::OptionsDialog()
1291 wxHtmlHelpFrameOptionsDialog
dlg(this);
1294 if (m_NormalFonts
== NULL
)
1296 wxFontEnumerator enu
;
1297 enu
.EnumerateFacenames();
1298 m_NormalFonts
= new wxArrayString
;
1299 *m_NormalFonts
= *enu
.GetFacenames();
1300 m_NormalFonts
->Sort(); // ascending sort
1302 if (m_FixedFonts
== NULL
)
1304 wxFontEnumerator enu
;
1305 enu
.EnumerateFacenames(wxFONTENCODING_SYSTEM
, true /*enum fixed width only*/);
1306 m_FixedFonts
= new wxArrayString
;
1307 *m_FixedFonts
= *enu
.GetFacenames();
1308 m_FixedFonts
->Sort(); // ascending sort
1311 // VS: We want to show the font that is actually used by wxHtmlWindow.
1312 // If customization dialog wasn't used yet, facenames are empty and
1313 // wxHtmlWindow uses default fonts -- let's find out what they
1314 // are so that we can pass them to the dialog:
1315 if (m_NormalFace
.empty())
1317 wxFont
fnt(m_FontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false);
1318 m_NormalFace
= fnt
.GetFaceName();
1320 if (m_FixedFace
.empty())
1322 wxFont
fnt(m_FontSize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false);
1323 m_FixedFace
= fnt
.GetFaceName();
1326 for (i
= 0; i
< m_NormalFonts
->GetCount(); i
++)
1327 dlg
.NormalFont
->Append((*m_NormalFonts
)[i
]);
1328 for (i
= 0; i
< m_FixedFonts
->GetCount(); i
++)
1329 dlg
.FixedFont
->Append((*m_FixedFonts
)[i
]);
1330 if (!m_NormalFace
.empty())
1331 dlg
.NormalFont
->SetStringSelection(m_NormalFace
);
1333 dlg
.NormalFont
->SetSelection(0);
1334 if (!m_FixedFace
.empty())
1335 dlg
.FixedFont
->SetStringSelection(m_FixedFace
);
1337 dlg
.FixedFont
->SetSelection(0);
1338 dlg
.FontSize
->SetValue(m_FontSize
);
1339 dlg
.UpdateTestWin();
1341 if (dlg
.ShowModal() == wxID_OK
)
1343 m_NormalFace
= dlg
.NormalFont
->GetStringSelection();
1344 m_FixedFace
= dlg
.FixedFont
->GetStringSelection();
1345 m_FontSize
= dlg
.FontSize
->GetValue();
1346 SetFontsToHtmlWin(m_HtmlWin
, m_NormalFace
, m_FixedFace
, m_FontSize
);
1352 void wxHtmlHelpFrame::NotifyPageChanged()
1354 if (m_UpdateContents
&& m_PagesHash
)
1356 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1357 wxHtmlHelpHashData
*ha
;
1359 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage());
1361 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage() + wxT("#") + an
);
1364 bool olduc
= m_UpdateContents
;
1365 m_UpdateContents
= false;
1366 m_ContentsBox
->SelectItem(ha
->m_Id
);
1367 m_ContentsBox
->EnsureVisible(ha
->m_Id
);
1368 m_UpdateContents
= olduc
;
1380 void wxHtmlHelpFrame::OnActivate(wxActivateEvent
& event
)
1382 // This saves one mouse click when using the
1383 // wxHTML for context sensitive help systems
1385 // NB: wxActivateEvent is a bit broken in wxGTK
1386 // and is sometimes sent when it should not be
1387 if (event
.GetActive() && m_HtmlWin
)
1388 m_HtmlWin
->SetFocus();
1394 void wxHtmlHelpFrame::OnToolbar(wxCommandEvent
& event
)
1396 switch (event
.GetId())
1398 case wxID_HTML_BACK
:
1399 m_HtmlWin
->HistoryBack();
1400 NotifyPageChanged();
1403 case wxID_HTML_FORWARD
:
1404 m_HtmlWin
->HistoryForward();
1405 NotifyPageChanged();
1411 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1412 wxHtmlHelpHashData
*ha
;
1414 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage());
1416 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage() + wxT("#") + an
);
1417 if (ha
&& ha
->m_Index
> 0)
1419 const wxHtmlHelpDataItem
& it
= m_Data
->GetContentsArray()[ha
->m_Index
- 1];
1420 if (!it
.page
.empty())
1422 m_HtmlWin
->LoadPage(it
.GetFullPath());
1423 NotifyPageChanged();
1429 case wxID_HTML_UPNODE
:
1432 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1433 wxHtmlHelpHashData
*ha
;
1435 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage());
1437 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage() + wxT("#") + an
);
1438 if (ha
&& ha
->m_Index
> 0)
1441 m_Data
->GetContentsArray()[ha
->m_Index
].level
- 1;
1442 int ind
= ha
->m_Index
- 1;
1444 const wxHtmlHelpDataItem
*it
=
1445 &m_Data
->GetContentsArray()[ind
];
1446 while (ind
>= 0 && it
->level
!= level
)
1449 it
= &m_Data
->GetContentsArray()[ind
];
1453 if (!it
->page
.empty())
1455 m_HtmlWin
->LoadPage(it
->GetFullPath());
1456 NotifyPageChanged();
1463 case wxID_HTML_DOWN
:
1466 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1468 wxHtmlHelpHashData
*ha
;
1470 if (an
.IsEmpty()) adr
= m_HtmlWin
->GetOpenedPage();
1471 else adr
= m_HtmlWin
->GetOpenedPage() + wxT("#") + an
;
1473 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(adr
);
1475 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1476 if (ha
&& ha
->m_Index
< (int)contents
.size() - 1)
1478 size_t idx
= ha
->m_Index
+ 1;
1480 while (contents
[idx
].GetFullPath() == adr
) idx
++;
1482 if (!contents
[idx
].page
.empty())
1484 m_HtmlWin
->LoadPage(contents
[idx
].GetFullPath());
1485 NotifyPageChanged();
1491 case wxID_HTML_PANEL
:
1493 if (! (m_Splitter
&& m_NavigPan
))
1495 if (m_Splitter
->IsSplit())
1497 m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1498 m_Splitter
->Unsplit(m_NavigPan
);
1499 m_Cfg
.navig_on
= false;
1505 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
1506 m_Cfg
.navig_on
= true;
1511 case wxID_HTML_OPTIONS
:
1515 case wxID_HTML_BOOKMARKSADD
:
1520 item
= m_HtmlWin
->GetOpenedPageTitle();
1521 url
= m_HtmlWin
->GetOpenedPage();
1522 if (item
== wxEmptyString
)
1523 item
= url
.AfterLast(wxT('/'));
1524 if (m_BookmarksPages
.Index(url
) == wxNOT_FOUND
)
1526 m_Bookmarks
->Append(item
);
1527 m_BookmarksNames
.Add(item
);
1528 m_BookmarksPages
.Add(url
);
1533 case wxID_HTML_BOOKMARKSREMOVE
:
1538 item
= m_Bookmarks
->GetStringSelection();
1539 pos
= m_BookmarksNames
.Index(item
);
1540 if (pos
!= wxNOT_FOUND
)
1542 m_BookmarksNames
.RemoveAt(pos
);
1543 m_BookmarksPages
.RemoveAt(pos
);
1544 m_Bookmarks
->Delete(m_Bookmarks
->GetSelection());
1549 #if wxUSE_PRINTING_ARCHITECTURE
1550 case wxID_HTML_PRINT
:
1552 if (m_Printer
== NULL
)
1553 m_Printer
= new wxHtmlEasyPrinting(_("Help Printing"), this);
1554 if (!m_HtmlWin
->GetOpenedPage())
1555 wxLogWarning(_("Cannot print empty page."));
1557 m_Printer
->PrintFile(m_HtmlWin
->GetOpenedPage());
1562 case wxID_HTML_OPENFILE
:
1564 wxString filemask
= wxString(
1565 _("HTML files (*.html;*.htm)|*.html;*.htm|")) +
1566 _("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|") +
1567 _("HTML Help Project (*.hhp)|*.hhp|") +
1569 _("Compressed HTML Help file (*.chm)|*.chm|") +
1571 _("All files (*.*)|*");
1572 wxString s
= wxFileSelector(_("Open HTML document"),
1577 wxOPEN
| wxFILE_MUST_EXIST
,
1581 wxString ext
= s
.Right(4).Lower();
1582 if (ext
== _T(".zip") || ext
== _T(".htb") ||
1584 ext
== _T(".chm") ||
1593 m_HtmlWin
->LoadPage(s
);
1602 void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent
& event
)
1604 wxHtmlHelpTreeItemData
*pg
;
1606 pg
= (wxHtmlHelpTreeItemData
*) m_ContentsBox
->GetItemData(event
.GetItem());
1608 if (pg
&& m_UpdateContents
)
1610 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1611 m_UpdateContents
= false;
1612 if (!contents
[pg
->m_Id
].page
.empty())
1613 m_HtmlWin
->LoadPage(contents
[pg
->m_Id
].GetFullPath());
1614 m_UpdateContents
= true;
1620 void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent
& WXUNUSED(event
))
1622 wxHtmlHelpMergedIndexItem
*it
= (wxHtmlHelpMergedIndexItem
*)
1623 m_IndexList
->GetClientData(m_IndexList
->GetSelection());
1625 DisplayIndexItem(it
);
1629 void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent
& event
)
1631 wxString sr
= m_IndexText
->GetLineText(0);
1633 if (sr
== wxEmptyString
)
1641 m_IndexList
->Clear();
1642 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1643 size_t cnt
= index
.size();
1646 for (size_t i
= 0; i
< cnt
; i
++)
1648 if (index
[i
].name
.Lower().find(sr
) != wxString::npos
)
1650 int pos
= m_IndexList
->Append(index
[i
].name
,
1651 (char*)(&index
[i
]));
1655 // don't automatically show topic selector if this
1656 // item points to multiple pages:
1657 if (index
[i
].items
.size() == 1)
1659 m_IndexList
->SetSelection(0);
1660 DisplayIndexItem(&index
[i
]);
1664 // if this is nested item of the index, show its parent(s)
1665 // as well, otherwise it would not be clear what entry is
1667 wxHtmlHelpMergedIndexItem
*parent
= index
[i
].parent
;
1671 (index
.Index(*(wxHtmlHelpMergedIndexItem
*)m_IndexList
->GetClientData(pos
-1))) < index
.Index(*parent
))
1673 m_IndexList
->Insert(parent
->name
,
1674 pos
, (char*)parent
);
1675 parent
= parent
->parent
;
1680 // finally, it the item we just added is itself a parent for
1681 // other items, show them as well, because they are refinements
1682 // of the displayed index entry (i.e. it is implicitly contained
1683 // in them: "foo" with parent "bar" reads as "bar, foo"):
1684 int level
= index
[i
].items
[0]->level
;
1686 while (i
< cnt
&& index
[i
].items
[0]->level
> level
)
1688 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1696 cnttext
.Printf(_("%i of %i"), displ
, cnt
);
1697 m_IndexCountInfo
->SetLabel(cnttext
);
1699 m_IndexText
->SetSelection(0, sr
.Length());
1700 m_IndexText
->SetFocus();
1704 void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent
& WXUNUSED(event
))
1708 m_IndexList
->Clear();
1709 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1710 size_t cnt
= index
.size();
1713 for (size_t i
= 0; i
< cnt
; i
++)
1715 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1718 // don't automatically show topic selector if this
1719 // item points to multiple pages:
1720 if (index
[i
].items
.size() == 1)
1722 DisplayIndexItem(&index
[i
]);
1729 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1730 m_IndexCountInfo
->SetLabel(cnttext
);
1734 void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent
& WXUNUSED(event
))
1736 wxHtmlHelpDataItem
*it
= (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(m_SearchList
->GetSelection());
1739 if (!it
->page
.empty())
1740 m_HtmlWin
->LoadPage(it
->GetFullPath());
1741 NotifyPageChanged();
1745 void wxHtmlHelpFrame::OnSearch(wxCommandEvent
& WXUNUSED(event
))
1747 wxString sr
= m_SearchText
->GetLineText(0);
1750 KeywordSearch(sr
, wxHELP_SEARCH_ALL
);
1753 void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent
& WXUNUSED(event
))
1755 wxString sr
= m_Bookmarks
->GetStringSelection();
1757 if (sr
!= wxEmptyString
&& sr
!= _("(bookmarks)"))
1759 m_HtmlWin
->LoadPage(m_BookmarksPages
[m_BookmarksNames
.Index(sr
)]);
1760 NotifyPageChanged();
1764 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent
& evt
)
1766 GetSize(&m_Cfg
.w
, &m_Cfg
.h
);
1767 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
1776 if (m_Splitter
&& m_Cfg
.navig_on
) m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1779 WriteCustomization(m_Config
, m_ConfigRoot
);
1781 if (m_helpController
&& m_helpController
->IsKindOf(CLASSINFO(wxHtmlHelpController
)))
1783 ((wxHtmlHelpController
*) m_helpController
)->OnCloseFrame(evt
);
1790 void wxHtmlHelpFrame::OnClose(wxCommandEvent
& event
)
1795 void wxHtmlHelpFrame::OnAbout(wxCommandEvent
& event
)
1797 wxMessageBox(wxT("wxWidgets HTML Help Viewer (c) 1998-2004, Vaclav Slavik et al"), wxT("HelpView"),
1798 wxICON_INFORMATION
|wxOK
, this);
1802 BEGIN_EVENT_TABLE(wxHtmlHelpFrame
, wxFrame
)
1803 EVT_ACTIVATE(wxHtmlHelpFrame::OnActivate
)
1804 EVT_TOOL_RANGE(wxID_HTML_PANEL
, wxID_HTML_OPTIONS
, wxHtmlHelpFrame::OnToolbar
)
1805 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE
, wxHtmlHelpFrame::OnToolbar
)
1806 EVT_BUTTON(wxID_HTML_BOOKMARKSADD
, wxHtmlHelpFrame::OnToolbar
)
1807 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL
, wxHtmlHelpFrame::OnContentsSel
)
1808 EVT_LISTBOX(wxID_HTML_INDEXLIST
, wxHtmlHelpFrame::OnIndexSel
)
1809 EVT_LISTBOX(wxID_HTML_SEARCHLIST
, wxHtmlHelpFrame::OnSearchSel
)
1810 EVT_BUTTON(wxID_HTML_SEARCHBUTTON
, wxHtmlHelpFrame::OnSearch
)
1811 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT
, wxHtmlHelpFrame::OnSearch
)
1812 EVT_BUTTON(wxID_HTML_INDEXBUTTON
, wxHtmlHelpFrame::OnIndexFind
)
1813 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT
, wxHtmlHelpFrame::OnIndexFind
)
1814 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL
, wxHtmlHelpFrame::OnIndexAll
)
1815 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST
, wxHtmlHelpFrame::OnBookmarksSel
)
1816 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow
)
1818 EVT_MENU(wxID_CLOSE
, wxHtmlHelpFrame::OnClose
)
1819 EVT_MENU(wxID_ABOUT
, wxHtmlHelpFrame::OnAbout
)
1820 EVT_MENU(wxID_HELP_CONTENTS
, wxHtmlHelpFrame::OnAbout
)
1825 #endif // wxUSE_WXHTML_HELP