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"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/textctrl.h"
40 #include "wx/toolbar.h"
41 #include "wx/choicdlg.h"
42 #include "wx/filedlg.h"
45 #include "wx/html/helpfrm.h"
46 #include "wx/html/helpdlg.h"
47 #include "wx/html/helpctrl.h"
48 #include "wx/notebook.h"
49 #include "wx/imaglist.h"
50 #include "wx/treectrl.h"
51 #include "wx/tokenzr.h"
52 #include "wx/wfstream.h"
53 #include "wx/html/htmlwin.h"
54 #include "wx/busyinfo.h"
55 #include "wx/progdlg.h"
56 #include "wx/fontenum.h"
57 #include "wx/artprov.h"
58 #include "wx/spinctrl.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 virtual ~wxHtmlHelpHashData() {}
103 //--------------------------------------------------------------------------
104 // wxHtmlHelpHtmlWindow (private)
105 //--------------------------------------------------------------------------
108 class wxHtmlHelpHtmlWindow
: public wxHtmlWindow
111 wxHtmlHelpHtmlWindow(wxHtmlHelpWindow
*win
, wxWindow
*parent
, wxWindowID id
= wxID_ANY
,
112 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= wxHW_DEFAULT_STYLE
)
113 : wxHtmlWindow(parent
, id
, pos
, sz
, style
), m_Window(win
)
118 void OnLink(wxHtmlLinkEvent
& ev
)
120 const wxMouseEvent
*e
= ev
.GetLinkInfo().GetEvent();
121 if (e
== NULL
|| e
->LeftUp())
122 m_Window
->NotifyPageChanged();
124 // skip the event so that normal processing (i.e. following the link)
129 // Returns full location with anchor (helper)
130 static wxString
GetOpenedPageWithAnchor(wxHtmlWindow
*win
)
133 return wxEmptyString
;
135 wxString an
= win
->GetOpenedAnchor();
136 wxString pg
= win
->GetOpenedPage();
139 pg
<< wxT("#") << an
;
145 wxHtmlHelpWindow
*m_Window
;
147 DECLARE_NO_COPY_CLASS(wxHtmlHelpHtmlWindow
)
148 DECLARE_EVENT_TABLE()
151 BEGIN_EVENT_TABLE(wxHtmlHelpHtmlWindow
, wxHtmlWindow
)
152 EVT_HTML_LINK_CLICKED(wxID_ANY
, wxHtmlHelpHtmlWindow::OnLink
)
156 //---------------------------------------------------------------------------
157 // wxHtmlHelpWindow::m_mergedIndex
158 //---------------------------------------------------------------------------
160 WX_DEFINE_ARRAY_PTR(const wxHtmlHelpDataItem
*, wxHtmlHelpDataItemPtrArray
);
162 struct wxHtmlHelpMergedIndexItem
164 wxHtmlHelpMergedIndexItem
*parent
;
166 wxHtmlHelpDataItemPtrArray items
;
169 WX_DECLARE_OBJARRAY(wxHtmlHelpMergedIndexItem
, wxHtmlHelpMergedIndex
);
170 #include "wx/arrimpl.cpp"
171 WX_DEFINE_OBJARRAY(wxHtmlHelpMergedIndex
)
173 void wxHtmlHelpWindow::UpdateMergedIndex()
175 delete m_mergedIndex
;
176 m_mergedIndex
= new wxHtmlHelpMergedIndex
;
177 wxHtmlHelpMergedIndex
& merged
= *m_mergedIndex
;
179 const wxHtmlHelpDataItems
& items
= m_Data
->GetIndexArray();
180 size_t len
= items
.size();
182 wxHtmlHelpMergedIndexItem
*history
[128] = {NULL
};
184 for (size_t i
= 0; i
< len
; i
++)
186 const wxHtmlHelpDataItem
& item
= items
[i
];
187 wxASSERT_MSG( item
.level
< 128, _T("nested index entries too deep") );
189 if (history
[item
.level
] &&
190 history
[item
.level
]->items
[0]->name
== item
.name
)
192 // same index entry as previous one, update list of items
193 history
[item
.level
]->items
.Add(&item
);
198 wxHtmlHelpMergedIndexItem
*mi
= new wxHtmlHelpMergedIndexItem();
199 mi
->name
= item
.GetIndentedName();
200 mi
->items
.Add(&item
);
201 mi
->parent
= (item
.level
== 0) ? NULL
: history
[item
.level
- 1];
202 history
[item
.level
] = mi
;
208 //---------------------------------------------------------------------------
210 //---------------------------------------------------------------------------
212 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpWindow
, wxWindow
)
214 BEGIN_EVENT_TABLE(wxHtmlHelpWindow
, wxWindow
)
215 EVT_TOOL_RANGE(wxID_HTML_PANEL
, wxID_HTML_OPTIONS
, wxHtmlHelpWindow::OnToolbar
)
216 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE
, wxHtmlHelpWindow::OnToolbar
)
217 EVT_BUTTON(wxID_HTML_BOOKMARKSADD
, wxHtmlHelpWindow::OnToolbar
)
218 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL
, wxHtmlHelpWindow::OnContentsSel
)
219 EVT_LISTBOX(wxID_HTML_INDEXLIST
, wxHtmlHelpWindow::OnIndexSel
)
220 EVT_LISTBOX(wxID_HTML_SEARCHLIST
, wxHtmlHelpWindow::OnSearchSel
)
221 EVT_BUTTON(wxID_HTML_SEARCHBUTTON
, wxHtmlHelpWindow::OnSearch
)
222 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT
, wxHtmlHelpWindow::OnSearch
)
223 EVT_BUTTON(wxID_HTML_INDEXBUTTON
, wxHtmlHelpWindow::OnIndexFind
)
224 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT
, wxHtmlHelpWindow::OnIndexFind
)
225 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL
, wxHtmlHelpWindow::OnIndexAll
)
226 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST
, wxHtmlHelpWindow::OnBookmarksSel
)
227 EVT_SIZE(wxHtmlHelpWindow::OnSize
)
230 wxHtmlHelpWindow::wxHtmlHelpWindow(wxWindow
* parent
, wxWindowID id
,
233 int style
, int helpStyle
, wxHtmlHelpData
* data
)
236 Create(parent
, id
, pos
, size
, style
, helpStyle
);
239 void wxHtmlHelpWindow::Init(wxHtmlHelpData
* data
)
244 m_DataCreated
= false;
248 m_Data
= new wxHtmlHelpData();
249 m_DataCreated
= true;
256 m_ContentsBox
= NULL
;
258 m_IndexButton
= NULL
;
259 m_IndexButtonAll
= NULL
;
262 m_SearchButton
= NULL
;
264 m_SearchChoice
= NULL
;
265 m_IndexCountInfo
= NULL
;
268 m_NavigNotebook
= NULL
;
271 m_SearchCaseSensitive
= NULL
;
272 m_SearchWholeWords
= NULL
;
274 m_mergedIndex
= NULL
;
277 m_ConfigRoot
= wxEmptyString
;
279 m_Cfg
.x
= m_Cfg
.y
= wxDefaultCoord
;
283 m_Cfg
.navig_on
= true;
285 m_NormalFonts
= m_FixedFonts
= NULL
;
286 m_NormalFace
= m_FixedFace
= wxEmptyString
;
293 #if wxUSE_PRINTING_ARCHITECTURE
298 m_UpdateContents
= true;
300 m_helpController
= (wxHtmlHelpController
*) NULL
;
303 // Create: builds the GUI components.
304 // with the style flag it's possible to toggle the toolbar, contents, index and search
306 // m_HtmlWin will *always* be created, but it's important to realize that
307 // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
308 // m_SearchButton may be NULL.
309 // moreover, if no contents, index or searchpage is needed, m_Splitter and
310 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
312 bool wxHtmlHelpWindow::Create(wxWindow
* parent
, wxWindowID id
,
313 const wxPoint
& pos
, const wxSize
& size
,
314 int style
, int helpStyle
)
316 m_hfStyle
= helpStyle
;
318 // Do the config in two steps. We read the HtmlWindow customization after we
319 // create the window.
321 ReadCustomization(m_Config
, m_ConfigRoot
);
323 wxWindow::Create(parent
, id
, pos
, size
, style
, wxT("wxHtmlHelp"));
325 SetHelpText(_("Displays help as you browse the books on the left."));
327 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
329 int notebook_page
= 0;
331 // The sizer for the whole top-level window.
332 wxSizer
*topWindowSizer
= new wxBoxSizer(wxVERTICAL
);
333 SetSizer(topWindowSizer
);
338 if (helpStyle
& (wxHF_TOOLBAR
| wxHF_FLAT_TOOLBAR
))
340 wxToolBar
*toolBar
= new wxToolBar(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
341 wxNO_BORDER
| wxTB_HORIZONTAL
|
342 wxTB_DOCKABLE
| wxTB_NODIVIDER
|
343 (helpStyle
& wxHF_FLAT_TOOLBAR
? wxTB_FLAT
: 0));
344 toolBar
->SetMargins( 2, 2 );
345 AddToolbarButtons(toolBar
, helpStyle
);
347 topWindowSizer
->Add(toolBar
, 0, wxEXPAND
);
350 #endif //wxUSE_TOOLBAR
352 wxSizer
*navigSizer
= NULL
;
355 wxBorder htmlWindowBorder
= GetDefaultBorder();
356 if (htmlWindowBorder
== wxBORDER_SUNKEN
)
357 htmlWindowBorder
= wxBORDER_SIMPLE
;
359 wxBorder htmlWindowBorder
= wxBORDER_SIMPLE
;
362 if (helpStyle
& (wxHF_CONTENTS
| wxHF_INDEX
| wxHF_SEARCH
))
364 // traditional help controller; splitter window with html page on the
365 // right and a notebook containing various pages on the left
366 m_Splitter
= new wxSplitterWindow(this);
368 topWindowSizer
->Add(m_Splitter
, 1, wxEXPAND
);
370 m_HtmlWin
= new wxHtmlHelpHtmlWindow(this, m_Splitter
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxHW_DEFAULT_STYLE
|htmlWindowBorder
);
371 m_NavigPan
= new wxPanel(m_Splitter
, wxID_ANY
);
372 m_NavigNotebook
= new wxNotebook(m_NavigPan
, wxID_HTML_NOTEBOOK
,
373 wxDefaultPosition
, wxDefaultSize
);
375 m_NavigNotebook
->SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
378 navigSizer
= new wxBoxSizer(wxVERTICAL
);
379 navigSizer
->Add(m_NavigNotebook
, 1, wxEXPAND
);
381 m_NavigPan
->SetSizer(navigSizer
);
385 // only html window, no notebook with index,contents etc
386 m_HtmlWin
= new wxHtmlWindow(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxHW_DEFAULT_STYLE
|htmlWindowBorder
);
387 topWindowSizer
->Add(m_HtmlWin
, 1, wxEXPAND
);
391 m_HtmlWin
->ReadCustomization(m_Config
, m_ConfigRoot
);
393 // contents tree panel?
394 if ( helpStyle
& wxHF_CONTENTS
)
396 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
398 dummy
->SetWindowVariant(wxWINDOW_VARIANT_NORMAL
);
400 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
402 topsizer
->Add(0, 10);
404 dummy
->SetSizer(topsizer
);
406 if ( helpStyle
& wxHF_BOOKMARKS
)
408 m_Bookmarks
= new wxComboBox(dummy
, wxID_HTML_BOOKMARKSLIST
,
410 wxDefaultPosition
, wxDefaultSize
,
411 0, NULL
, wxCB_READONLY
| wxCB_SORT
);
412 m_Bookmarks
->Append(_("(bookmarks)"));
413 for (unsigned i
= 0; i
< m_BookmarksNames
.GetCount(); i
++)
414 m_Bookmarks
->Append(m_BookmarksNames
[i
]);
415 m_Bookmarks
->SetSelection(0);
417 wxBitmapButton
*bmpbt1
, *bmpbt2
;
418 bmpbt1
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSADD
,
419 wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK
,
421 bmpbt2
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSREMOVE
,
422 wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK
,
425 bmpbt1
->SetToolTip(_("Add current page to bookmarks"));
426 bmpbt2
->SetToolTip(_("Remove current page from bookmarks"));
427 #endif // wxUSE_TOOLTIPS
429 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
431 sizer
->Add(m_Bookmarks
, 1, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 5);
432 sizer
->Add(bmpbt1
, 0, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 2);
433 sizer
->Add(bmpbt2
, 0, wxALIGN_CENTRE_VERTICAL
, 0);
435 topsizer
->Add(sizer
, 0, wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
, 10);
438 m_ContentsBox
= new wxTreeCtrl(dummy
, wxID_HTML_TREECTRL
,
439 wxDefaultPosition
, wxDefaultSize
,
442 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
446 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
451 wxImageList
*ContentsImageList
= new wxImageList(16, 16);
452 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK
,
455 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER
,
458 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE
,
462 m_ContentsBox
->AssignImageList(ContentsImageList
);
464 topsizer
->Add(m_ContentsBox
, 1,
465 wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
,
468 m_NavigNotebook
->AddPage(dummy
, _("Contents"));
469 m_ContentsPage
= notebook_page
++;
472 // index listbox panel?
473 if ( helpStyle
& wxHF_INDEX
)
475 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
477 dummy
->SetWindowVariant(wxWINDOW_VARIANT_NORMAL
);
479 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
481 dummy
->SetSizer(topsizer
);
483 m_IndexText
= new wxTextCtrl(dummy
, wxID_HTML_INDEXTEXT
, wxEmptyString
,
484 wxDefaultPosition
, wxDefaultSize
,
486 m_IndexButton
= new wxButton(dummy
, wxID_HTML_INDEXBUTTON
, _("Find"));
487 m_IndexButtonAll
= new wxButton(dummy
, wxID_HTML_INDEXBUTTONALL
,
489 m_IndexCountInfo
= new wxStaticText(dummy
, wxID_HTML_COUNTINFO
,
490 wxEmptyString
, wxDefaultPosition
,
492 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
493 m_IndexList
= new wxListBox(dummy
, wxID_HTML_INDEXLIST
,
494 wxDefaultPosition
, wxDefaultSize
,
495 0, NULL
, wxLB_SINGLE
);
498 m_IndexButton
->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
499 m_IndexButtonAll
->SetToolTip(_("Show all items in index"));
500 #endif //wxUSE_TOOLTIPS
502 topsizer
->Add(m_IndexText
, 0, wxEXPAND
| wxALL
, 10);
503 wxSizer
*btsizer
= new wxBoxSizer(wxHORIZONTAL
);
504 btsizer
->Add(m_IndexButton
, 0, wxRIGHT
, 2);
505 btsizer
->Add(m_IndexButtonAll
);
506 topsizer
->Add(btsizer
, 0,
507 wxALIGN_RIGHT
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
508 topsizer
->Add(m_IndexCountInfo
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 2);
509 topsizer
->Add(m_IndexList
, 1, wxEXPAND
| wxALL
, 2);
511 m_NavigNotebook
->AddPage(dummy
, _("Index"));
512 m_IndexPage
= notebook_page
++;
515 // search list panel?
516 if ( helpStyle
& wxHF_SEARCH
)
518 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
520 dummy
->SetWindowVariant(wxWINDOW_VARIANT_NORMAL
);
522 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
524 dummy
->SetSizer(sizer
);
526 m_SearchText
= new wxTextCtrl(dummy
, wxID_HTML_SEARCHTEXT
,
528 wxDefaultPosition
, wxDefaultSize
,
530 m_SearchChoice
= new wxChoice(dummy
, wxID_HTML_SEARCHCHOICE
,
531 wxDefaultPosition
, wxSize(125,wxDefaultCoord
));
532 m_SearchCaseSensitive
= new wxCheckBox(dummy
, wxID_ANY
, _("Case sensitive"));
533 m_SearchWholeWords
= new wxCheckBox(dummy
, wxID_ANY
, _("Whole words only"));
534 m_SearchButton
= new wxButton(dummy
, wxID_HTML_SEARCHBUTTON
, _("Search"));
536 m_SearchButton
->SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
537 #endif //wxUSE_TOOLTIPS
538 m_SearchList
= new wxListBox(dummy
, wxID_HTML_SEARCHLIST
,
539 wxDefaultPosition
, wxDefaultSize
,
540 0, NULL
, wxLB_SINGLE
);
542 sizer
->Add(m_SearchText
, 0, wxEXPAND
| wxALL
, 10);
543 sizer
->Add(m_SearchChoice
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
544 sizer
->Add(m_SearchCaseSensitive
, 0, wxLEFT
| wxRIGHT
, 10);
545 sizer
->Add(m_SearchWholeWords
, 0, wxLEFT
| wxRIGHT
, 10);
546 sizer
->Add(m_SearchButton
, 0, wxALL
| wxALIGN_RIGHT
, 8);
547 sizer
->Add(m_SearchList
, 1, wxALL
| wxEXPAND
, 2);
549 m_NavigNotebook
->AddPage(dummy
, _("Search"));
550 m_SearchPage
= notebook_page
;
559 navigSizer
->SetSizeHints(m_NavigPan
);
560 m_NavigPan
->Layout();
564 if ( m_NavigPan
&& m_Splitter
)
567 m_Splitter
->SetMinimumPaneSize(m_NavigPan
->GetBestSize().x
);
569 m_Splitter
->SetMinimumPaneSize(20);
571 if ( m_Cfg
.navig_on
)
574 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
578 m_NavigPan
->Show(false);
579 m_Splitter
->Initialize(m_HtmlWin
);
583 // Reduce flicker by updating the splitter pane sizes before the
585 wxSizeEvent
sizeEvent(GetSize(), GetId());
586 ProcessEvent(sizeEvent
);
589 m_Splitter
->UpdateSize();
594 wxHtmlHelpWindow::~wxHtmlHelpWindow()
596 if ( m_helpController
)
597 m_helpController
->SetHelpWindow(NULL
);
599 delete m_mergedIndex
;
601 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
604 if (m_NormalFonts
) delete m_NormalFonts
;
605 if (m_FixedFonts
) delete m_FixedFonts
;
608 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
611 #if wxUSE_PRINTING_ARCHITECTURE
612 if (m_Printer
) delete m_Printer
;
616 void wxHtmlHelpWindow::SetController(wxHtmlHelpController
* controller
)
620 m_helpController
= controller
;
621 m_Data
= controller
->GetHelpData();
622 m_DataCreated
= false;
626 void wxHtmlHelpWindow::AddToolbarButtons(wxToolBar
*toolBar
, int style
)
628 wxBitmap wpanelBitmap
=
629 wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL
, wxART_TOOLBAR
);
630 wxBitmap wbackBitmap
=
631 wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_TOOLBAR
);
632 wxBitmap wforwardBitmap
=
633 wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_TOOLBAR
);
634 wxBitmap wupnodeBitmap
=
635 wxArtProvider::GetBitmap(wxART_GO_TO_PARENT
, wxART_TOOLBAR
);
637 wxArtProvider::GetBitmap(wxART_GO_UP
, wxART_TOOLBAR
);
638 wxBitmap wdownBitmap
=
639 wxArtProvider::GetBitmap(wxART_GO_DOWN
, wxART_TOOLBAR
);
640 wxBitmap wopenBitmap
=
641 wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_TOOLBAR
);
642 wxBitmap wprintBitmap
=
643 wxArtProvider::GetBitmap(wxART_PRINT
, wxART_TOOLBAR
);
644 wxBitmap woptionsBitmap
=
645 wxArtProvider::GetBitmap(wxART_HELP_SETTINGS
, wxART_TOOLBAR
);
647 wxASSERT_MSG( (wpanelBitmap
.Ok() && wbackBitmap
.Ok() &&
648 wforwardBitmap
.Ok() && wupnodeBitmap
.Ok() &&
649 wupBitmap
.Ok() && wdownBitmap
.Ok() &&
650 wopenBitmap
.Ok() && wprintBitmap
.Ok() &&
651 woptionsBitmap
.Ok()),
652 wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
655 toolBar
->AddTool(wxID_HTML_PANEL
, wpanelBitmap
, wxNullBitmap
,
656 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
657 _("Show/hide navigation panel"));
659 toolBar
->AddSeparator();
660 toolBar
->AddTool(wxID_HTML_BACK
, wbackBitmap
, wxNullBitmap
,
661 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
663 toolBar
->AddTool(wxID_HTML_FORWARD
, wforwardBitmap
, wxNullBitmap
,
664 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
666 toolBar
->AddSeparator();
668 toolBar
->AddTool(wxID_HTML_UPNODE
, wupnodeBitmap
, wxNullBitmap
,
669 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
670 _("Go one level up in document hierarchy"));
671 toolBar
->AddTool(wxID_HTML_UP
, wupBitmap
, wxNullBitmap
,
672 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
674 toolBar
->AddTool(wxID_HTML_DOWN
, wdownBitmap
, wxNullBitmap
,
675 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
678 if ((style
& wxHF_PRINT
) || (style
& wxHF_OPEN_FILES
))
679 toolBar
->AddSeparator();
681 if (style
& wxHF_OPEN_FILES
)
682 toolBar
->AddTool(wxID_HTML_OPENFILE
, wopenBitmap
, wxNullBitmap
,
683 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
684 _("Open HTML document"));
686 #if wxUSE_PRINTING_ARCHITECTURE
687 if (style
& wxHF_PRINT
)
688 toolBar
->AddTool(wxID_HTML_PRINT
, wprintBitmap
, wxNullBitmap
,
689 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
690 _("Print this page"));
693 toolBar
->AddSeparator();
694 toolBar
->AddTool(wxID_HTML_OPTIONS
, woptionsBitmap
, wxNullBitmap
,
695 false, wxDefaultCoord
, wxDefaultCoord
, (wxObject
*) NULL
,
696 _("Display options dialog"));
698 // Allow application to add custom buttons
699 wxHtmlHelpFrame
* parentFrame
= wxDynamicCast(GetParent(), wxHtmlHelpFrame
);
700 wxHtmlHelpDialog
* parentDialog
= wxDynamicCast(GetParent(), wxHtmlHelpDialog
);
702 parentFrame
->AddToolbarButtons(toolBar
, style
);
704 parentDialog
->AddToolbarButtons(toolBar
, style
);
706 #endif //wxUSE_TOOLBAR
709 bool wxHtmlHelpWindow::Display(const wxString
& x
)
711 wxString url
= m_Data
->FindPageByName(x
);
714 m_HtmlWin
->LoadPage(url
);
722 bool wxHtmlHelpWindow::Display(const int id
)
724 wxString url
= m_Data
->FindPageById(id
);
727 m_HtmlWin
->LoadPage(url
);
735 bool wxHtmlHelpWindow::DisplayContents()
740 if (!m_Splitter
->IsSplit())
744 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
745 m_Cfg
.navig_on
= true;
748 m_NavigNotebook
->SetSelection(m_ContentsPage
);
750 if (m_Data
->GetBookRecArray().GetCount() > 0)
752 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
753 if (!book
.GetStart().empty())
754 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
760 bool wxHtmlHelpWindow::DisplayIndex()
765 if (!m_Splitter
->IsSplit())
769 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
772 m_NavigNotebook
->SetSelection(m_IndexPage
);
774 if (m_Data
->GetBookRecArray().GetCount() > 0)
776 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
777 if (!book
.GetStart().empty())
778 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
784 void wxHtmlHelpWindow::DisplayIndexItem(const wxHtmlHelpMergedIndexItem
*it
)
786 if (it
->items
.size() == 1)
788 if (!it
->items
[0]->page
.empty())
790 m_HtmlWin
->LoadPage(it
->items
[0]->GetFullPath());
796 wxBusyCursor busy_cursor
;
798 // more pages associated with this index item -- let the user choose
799 // which one she/he wants from a list:
801 size_t len
= it
->items
.size();
802 for (size_t i
= 0; i
< len
; i
++)
804 wxString page
= it
->items
[i
]->page
;
805 // try to find page's title in contents:
806 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
807 size_t clen
= contents
.size();
808 for (size_t j
= 0; j
< clen
; j
++)
810 if (contents
[j
].page
== page
)
812 page
= contents
[j
].name
;
819 wxSingleChoiceDialog
dlg(this,
820 _("Please choose the page to display:"),
822 arr
, NULL
, wxCHOICEDLG_STYLE
& ~wxCENTRE
);
823 if (dlg
.ShowModal() == wxID_OK
)
825 m_HtmlWin
->LoadPage(it
->items
[dlg
.GetSelection()]->GetFullPath());
831 bool wxHtmlHelpWindow::KeywordSearch(const wxString
& keyword
,
832 wxHelpSearchMode mode
)
834 wxCHECK_MSG( !keyword
.empty(), false, "must have a non empty keyword" );
836 if (mode
== wxHELP_SEARCH_ALL
)
838 if ( !(m_SearchList
&&
839 m_SearchButton
&& m_SearchText
&& m_SearchChoice
) )
842 else if (mode
== wxHELP_SEARCH_INDEX
)
844 if ( !(m_IndexList
&&
845 m_IndexButton
&& m_IndexButtonAll
&& m_IndexText
) )
851 wxString book
= wxEmptyString
;
853 if (!m_Splitter
->IsSplit())
857 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
860 if (mode
== wxHELP_SEARCH_ALL
)
862 m_NavigNotebook
->SetSelection(m_SearchPage
);
863 m_SearchList
->Clear();
864 m_SearchText
->SetValue(keyword
);
865 m_SearchButton
->Disable();
867 if (m_SearchChoice
->GetSelection() != 0)
868 book
= m_SearchChoice
->GetStringSelection();
870 wxHtmlSearchStatus
status(m_Data
, keyword
,
871 m_SearchCaseSensitive
->GetValue(),
872 m_SearchWholeWords
->GetValue(),
875 #if wxUSE_PROGRESSDLG
876 wxProgressDialog
progress(_("Searching..."),
877 _("No matching page found yet"),
878 status
.GetMaxIndex(), this,
879 wxPD_APP_MODAL
| wxPD_CAN_ABORT
| wxPD_AUTO_HIDE
);
883 while (status
.IsActive())
885 curi
= status
.GetCurIndex();
887 #if wxUSE_PROGRESSDLG
888 && !progress
.Update(curi
)
894 foundstr
.Printf(_("Found %i matches"), ++foundcnt
);
895 #if wxUSE_PROGRESSDLG
896 progress
.Update(status
.GetCurIndex(), foundstr
);
898 m_SearchList
->Append(status
.GetName(), (void*)status
.GetCurItem());
902 m_SearchButton
->Enable();
903 m_SearchText
->SetSelection(0, keyword
.length());
904 m_SearchText
->SetFocus();
906 else if (mode
== wxHELP_SEARCH_INDEX
)
908 m_NavigNotebook
->SetSelection(m_IndexPage
);
909 m_IndexList
->Clear();
910 m_IndexButton
->Disable();
911 m_IndexButtonAll
->Disable();
912 m_IndexText
->SetValue(keyword
);
915 m_IndexButton
->Enable();
916 m_IndexButtonAll
->Enable();
917 foundcnt
= m_IndexList
->GetCount();
925 wxFAIL_MSG( _T("unknown help search mode") );
928 case wxHELP_SEARCH_ALL
:
930 wxHtmlHelpDataItem
*it
=
931 (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(0);
934 m_HtmlWin
->LoadPage(it
->GetFullPath());
940 case wxHELP_SEARCH_INDEX
:
942 wxHtmlHelpMergedIndexItem
* it
=
943 (wxHtmlHelpMergedIndexItem
*) m_IndexList
->GetClientData(0);
945 DisplayIndexItem(it
);
955 void wxHtmlHelpWindow::CreateContents()
962 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
966 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
968 size_t cnt
= contents
.size();
970 m_PagesHash
= new wxHashTable(wxKEY_STRING
, 2 * cnt
);
972 const int MAX_ROOTS
= 64;
973 wxTreeItemId roots
[MAX_ROOTS
];
974 // VS: this array holds information about whether we've set item icon at
975 // given level. This is necessary because m_Data has a flat structure
976 // and there's no way of recognizing if some item has subitems or not.
977 // We set the icon later: when we find an item with level=n, we know
978 // that the last item with level=n-1 was afolder with subitems, so we
979 // set its icon accordingly
980 bool imaged
[MAX_ROOTS
];
981 m_ContentsBox
->DeleteAllItems();
983 roots
[0] = m_ContentsBox
->AddRoot(_("(Help)"));
986 for (size_t i
= 0; i
< cnt
; i
++)
988 wxHtmlHelpDataItem
*it
= &contents
[i
];
992 if (m_hfStyle
& wxHF_MERGE_BOOKS
)
993 // VS: we don't want book nodes, books' content should
994 // appear under tree's root. This line will create a "fake"
995 // record about book node so that the rest of this look
996 // will believe there really _is_ a book node and will
1001 roots
[1] = m_ContentsBox
->AppendItem(roots
[0],
1002 it
->name
, IMG_Book
, -1,
1003 new wxHtmlHelpTreeItemData(i
));
1004 m_ContentsBox
->SetItemBold(roots
[1], true);
1008 // ...and their contents:
1011 roots
[it
->level
+ 1] = m_ContentsBox
->AppendItem(
1012 roots
[it
->level
], it
->name
, IMG_Page
,
1013 -1, new wxHtmlHelpTreeItemData(i
));
1014 imaged
[it
->level
+ 1] = false;
1017 m_PagesHash
->Put(it
->GetFullPath(),
1018 new wxHtmlHelpHashData(i
, roots
[it
->level
+ 1]));
1020 // Set the icon for the node one level up in the hierarchy,
1021 // unless already done (see comment above imaged[] declaration)
1022 if (!imaged
[it
->level
])
1024 int image
= IMG_Folder
;
1025 if (m_hfStyle
& wxHF_ICONS_BOOK
)
1027 else if (m_hfStyle
& wxHF_ICONS_BOOK_CHAPTER
)
1028 image
= (it
->level
== 1) ? IMG_Book
: IMG_Folder
;
1029 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
);
1030 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
,
1031 wxTreeItemIcon_Selected
);
1032 imaged
[it
->level
] = true;
1037 void wxHtmlHelpWindow::CreateIndex()
1042 m_IndexList
->Clear();
1044 size_t cnt
= m_mergedIndex
->size();
1047 if (cnt
> INDEX_IS_SMALL
)
1048 cnttext
.Printf(_("%i of %i"), 0, cnt
);
1050 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1051 m_IndexCountInfo
->SetLabel(cnttext
);
1052 if (cnt
> INDEX_IS_SMALL
)
1055 for (size_t i
= 0; i
< cnt
; i
++)
1056 m_IndexList
->Append((*m_mergedIndex
)[i
].name
,
1057 (char*)(&(*m_mergedIndex
)[i
]));
1060 void wxHtmlHelpWindow::CreateSearch()
1062 if (! (m_SearchList
&& m_SearchChoice
))
1064 m_SearchList
->Clear();
1065 m_SearchChoice
->Clear();
1066 m_SearchChoice
->Append(_("Search in all books"));
1067 const wxHtmlBookRecArray
& bookrec
= m_Data
->GetBookRecArray();
1068 int i
, cnt
= bookrec
.GetCount();
1069 for (i
= 0; i
< cnt
; i
++)
1070 m_SearchChoice
->Append(bookrec
[i
].GetTitle());
1071 m_SearchChoice
->SetSelection(0);
1074 void wxHtmlHelpWindow::RefreshLists()
1076 // Update m_mergedIndex:
1077 UpdateMergedIndex();
1078 // Update the controls
1084 void wxHtmlHelpWindow::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1089 if (path
!= wxEmptyString
)
1091 oldpath
= cfg
->GetPath();
1092 cfg
->SetPath(_T("/") + path
);
1095 m_Cfg
.navig_on
= cfg
->Read(wxT("hcNavigPanel"), m_Cfg
.navig_on
) != 0;
1096 m_Cfg
.sashpos
= cfg
->Read(wxT("hcSashPos"), m_Cfg
.sashpos
);
1097 m_Cfg
.x
= cfg
->Read(wxT("hcX"), m_Cfg
.x
);
1098 m_Cfg
.y
= cfg
->Read(wxT("hcY"), m_Cfg
.y
);
1099 m_Cfg
.w
= cfg
->Read(wxT("hcW"), m_Cfg
.w
);
1100 m_Cfg
.h
= cfg
->Read(wxT("hcH"), m_Cfg
.h
);
1102 m_FixedFace
= cfg
->Read(wxT("hcFixedFace"), m_FixedFace
);
1103 m_NormalFace
= cfg
->Read(wxT("hcNormalFace"), m_NormalFace
);
1104 m_FontSize
= cfg
->Read(wxT("hcBaseFontSize"), m_FontSize
);
1111 cnt
= cfg
->Read(wxT("hcBookmarksCnt"), 0L);
1114 m_BookmarksNames
.Clear();
1115 m_BookmarksPages
.Clear();
1118 m_Bookmarks
->Clear();
1119 m_Bookmarks
->Append(_("(bookmarks)"));
1122 for (i
= 0; i
< cnt
; i
++)
1124 val
.Printf(wxT("hcBookmark_%i"), i
);
1126 m_BookmarksNames
.Add(s
);
1127 if (m_Bookmarks
) m_Bookmarks
->Append(s
);
1128 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1130 m_BookmarksPages
.Add(s
);
1136 m_HtmlWin
->ReadCustomization(cfg
);
1138 if (path
!= wxEmptyString
)
1139 cfg
->SetPath(oldpath
);
1142 void wxHtmlHelpWindow::WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1147 if (path
!= wxEmptyString
)
1149 oldpath
= cfg
->GetPath();
1150 cfg
->SetPath(_T("/") + path
);
1153 cfg
->Write(wxT("hcNavigPanel"), m_Cfg
.navig_on
);
1154 cfg
->Write(wxT("hcSashPos"), (long)m_Cfg
.sashpos
);
1156 // Don't write if iconized as this would make the window
1157 // disappear next time it is shown!
1158 cfg
->Write(wxT("hcX"), (long)m_Cfg
.x
);
1159 cfg
->Write(wxT("hcY"), (long)m_Cfg
.y
);
1160 cfg
->Write(wxT("hcW"), (long)m_Cfg
.w
);
1161 cfg
->Write(wxT("hcH"), (long)m_Cfg
.h
);
1163 cfg
->Write(wxT("hcFixedFace"), m_FixedFace
);
1164 cfg
->Write(wxT("hcNormalFace"), m_NormalFace
);
1165 cfg
->Write(wxT("hcBaseFontSize"), (long)m_FontSize
);
1170 int cnt
= m_BookmarksNames
.GetCount();
1173 cfg
->Write(wxT("hcBookmarksCnt"), (long)cnt
);
1174 for (i
= 0; i
< cnt
; i
++)
1176 val
.Printf(wxT("hcBookmark_%i"), i
);
1177 cfg
->Write(val
, m_BookmarksNames
[i
]);
1178 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1179 cfg
->Write(val
, m_BookmarksPages
[i
]);
1184 m_HtmlWin
->WriteCustomization(cfg
);
1186 if (path
!= wxEmptyString
)
1187 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
);
1204 class wxHtmlHelpWindowOptionsDialog
: public wxDialog
1207 wxComboBox
*NormalFont
, *FixedFont
;
1208 wxSpinCtrl
*FontSize
;
1209 wxHtmlWindow
*TestWin
;
1211 wxHtmlHelpWindowOptionsDialog(wxWindow
*parent
)
1212 : wxDialog(parent
, wxID_ANY
, wxString(_("Help Browser Options")))
1214 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
1215 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2, 3, 2, 5);
1217 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Normal font:")));
1218 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Fixed font:")));
1219 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Font size:")));
1221 sizer
->Add(NormalFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1222 wxSize(200, wxDefaultCoord
),
1223 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1225 sizer
->Add(FixedFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1226 wxSize(200, wxDefaultCoord
),
1227 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1229 sizer
->Add(FontSize
= new wxSpinCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1230 wxDefaultSize
, wxSP_ARROW_KEYS
, 2, 100, 2, _T("wxSpinCtrl")));
1232 topsizer
->Add(sizer
, 0, wxLEFT
|wxRIGHT
|wxTOP
, 10);
1234 topsizer
->Add(new wxStaticText(this, wxID_ANY
, _("Preview:")),
1235 0, wxLEFT
| wxTOP
, 10);
1237 topsizer
->AddSpacer(5);
1239 topsizer
->Add(TestWin
= new wxHtmlWindow(this, wxID_ANY
, wxDefaultPosition
, wxSize(20, 150),
1240 wxHW_SCROLLBAR_AUTO
|wxBORDER_THEME
),
1241 1, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
1243 wxBoxSizer
*sizer2
= new wxBoxSizer(wxHORIZONTAL
);
1245 sizer2
->Add(ok
= new wxButton(this, wxID_OK
), 0, wxALL
, 10);
1247 sizer2
->Add(new wxButton(this, wxID_CANCEL
), 0, wxALL
, 10);
1248 topsizer
->Add(sizer2
, 0, wxALIGN_RIGHT
);
1251 topsizer
->Fit(this);
1256 void UpdateTestWin()
1259 SetFontsToHtmlWin(TestWin
,
1260 NormalFont
->GetStringSelection(),
1261 FixedFont
->GetStringSelection(),
1262 FontSize
->GetValue());
1264 wxString
content(_("font size"));
1266 content
= _T("<font size=-2>") + content
+ _T(" -2</font><br>")
1267 _T("<font size=-1>") + content
+ _T(" -1</font><br>")
1268 _T("<font size=+0>") + content
+ _T(" +0</font><br>")
1269 _T("<font size=+1>") + content
+ _T(" +1</font><br>")
1270 _T("<font size=+2>") + content
+ _T(" +2</font><br>")
1271 _T("<font size=+3>") + content
+ _T(" +3</font><br>")
1272 _T("<font size=+4>") + content
+ _T(" +4</font><br>") ;
1274 content
= wxString( _T("<html><body><table><tr><td>") ) +
1275 _("Normal face<br>and <u>underlined</u>. ") +
1276 _("<i>Italic face.</i> ") +
1277 _("<b>Bold face.</b> ") +
1278 _("<b><i>Bold italic face.</i></b><br>") +
1280 wxString( _T("</td><td><tt>") ) +
1281 _("Fixed size face.<br> <b>bold</b> <i>italic</i> ") +
1282 _("<b><i>bold italic <u>underlined</u></i></b><br>") +
1284 _T("</tt></td></tr></table></body></html>");
1286 TestWin
->SetPage( content
);
1289 void OnUpdate(wxCommandEvent
& WXUNUSED(event
))
1293 void OnUpdateSpin(wxSpinEvent
& WXUNUSED(event
))
1298 DECLARE_EVENT_TABLE()
1299 DECLARE_NO_COPY_CLASS(wxHtmlHelpWindowOptionsDialog
)
1302 BEGIN_EVENT_TABLE(wxHtmlHelpWindowOptionsDialog
, wxDialog
)
1303 EVT_COMBOBOX(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdate
)
1304 EVT_SPINCTRL(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdateSpin
)
1307 void wxHtmlHelpWindow::OptionsDialog()
1309 wxHtmlHelpWindowOptionsDialog
dlg(this);
1312 if (m_NormalFonts
== NULL
)
1314 m_NormalFonts
= new wxArrayString(wxFontEnumerator::GetFacenames());
1315 m_NormalFonts
->Sort(); // ascending sort
1317 if (m_FixedFonts
== NULL
)
1319 m_FixedFonts
= new wxArrayString(
1320 wxFontEnumerator::GetFacenames(wxFONTENCODING_SYSTEM
,
1321 true /*enum fixed width only*/));
1322 m_FixedFonts
->Sort(); // ascending sort
1325 // VS: We want to show the font that is actually used by wxHtmlWindow.
1326 // If customization dialog wasn't used yet, facenames are empty and
1327 // wxHtmlWindow uses default fonts -- let's find out what they
1328 // are so that we can pass them to the dialog:
1329 if (m_NormalFace
.empty())
1331 wxFont
fnt(m_FontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false);
1332 m_NormalFace
= fnt
.GetFaceName();
1334 if (m_FixedFace
.empty())
1336 wxFont
fnt(m_FontSize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false);
1337 m_FixedFace
= fnt
.GetFaceName();
1340 for (i
= 0; i
< m_NormalFonts
->GetCount(); i
++)
1341 dlg
.NormalFont
->Append((*m_NormalFonts
)[i
]);
1342 for (i
= 0; i
< m_FixedFonts
->GetCount(); i
++)
1343 dlg
.FixedFont
->Append((*m_FixedFonts
)[i
]);
1344 if (!m_NormalFace
.empty())
1345 dlg
.NormalFont
->SetStringSelection(m_NormalFace
);
1347 dlg
.NormalFont
->SetSelection(0);
1348 if (!m_FixedFace
.empty())
1349 dlg
.FixedFont
->SetStringSelection(m_FixedFace
);
1351 dlg
.FixedFont
->SetSelection(0);
1352 dlg
.FontSize
->SetValue(m_FontSize
);
1353 dlg
.UpdateTestWin();
1355 if (dlg
.ShowModal() == wxID_OK
)
1357 m_NormalFace
= dlg
.NormalFont
->GetStringSelection();
1358 m_FixedFace
= dlg
.FixedFont
->GetStringSelection();
1359 m_FontSize
= dlg
.FontSize
->GetValue();
1360 SetFontsToHtmlWin(m_HtmlWin
, m_NormalFace
, m_FixedFace
, m_FontSize
);
1364 void wxHtmlHelpWindow::NotifyPageChanged()
1366 if (m_UpdateContents
&& m_PagesHash
)
1368 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1369 wxHtmlHelpHashData
*ha
= NULL
;
1371 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1375 bool olduc
= m_UpdateContents
;
1376 m_UpdateContents
= false;
1377 m_ContentsBox
->SelectItem(ha
->m_Id
);
1378 m_ContentsBox
->EnsureVisible(ha
->m_Id
);
1379 m_UpdateContents
= olduc
;
1389 void wxHtmlHelpWindow::OnToolbar(wxCommandEvent
& event
)
1391 switch (event
.GetId())
1393 case wxID_HTML_BACK
:
1394 m_HtmlWin
->HistoryBack();
1395 NotifyPageChanged();
1398 case wxID_HTML_FORWARD
:
1399 m_HtmlWin
->HistoryForward();
1400 NotifyPageChanged();
1406 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1407 wxHtmlHelpHashData
*ha
= NULL
;
1409 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1410 if (ha
&& ha
->m_Index
> 0)
1412 const wxHtmlHelpDataItem
& it
= m_Data
->GetContentsArray()[ha
->m_Index
- 1];
1413 if (!it
.page
.empty())
1415 m_HtmlWin
->LoadPage(it
.GetFullPath());
1416 NotifyPageChanged();
1422 case wxID_HTML_UPNODE
:
1425 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1426 wxHtmlHelpHashData
*ha
= NULL
;
1428 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1429 if (ha
&& ha
->m_Index
> 0)
1432 m_Data
->GetContentsArray()[ha
->m_Index
].level
- 1;
1433 int ind
= ha
->m_Index
- 1;
1435 const wxHtmlHelpDataItem
*it
=
1436 &m_Data
->GetContentsArray()[ind
];
1437 while (ind
>= 0 && it
->level
!= level
)
1440 it
= &m_Data
->GetContentsArray()[ind
];
1444 if (!it
->page
.empty())
1446 m_HtmlWin
->LoadPage(it
->GetFullPath());
1447 NotifyPageChanged();
1454 case wxID_HTML_DOWN
:
1457 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1458 wxHtmlHelpHashData
*ha
= NULL
;
1460 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1462 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1463 if (ha
&& ha
->m_Index
< (int)contents
.size() - 1)
1465 size_t idx
= ha
->m_Index
+ 1;
1467 while (contents
[idx
].GetFullPath() == page
) idx
++;
1469 if (!contents
[idx
].page
.empty())
1471 m_HtmlWin
->LoadPage(contents
[idx
].GetFullPath());
1472 NotifyPageChanged();
1478 case wxID_HTML_PANEL
:
1480 if (! (m_Splitter
&& m_NavigPan
))
1482 if (m_Splitter
->IsSplit())
1484 m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1485 m_Splitter
->Unsplit(m_NavigPan
);
1486 m_Cfg
.navig_on
= false;
1492 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
1493 m_Cfg
.navig_on
= true;
1498 case wxID_HTML_OPTIONS
:
1502 case wxID_HTML_BOOKMARKSADD
:
1507 item
= m_HtmlWin
->GetOpenedPageTitle();
1508 url
= m_HtmlWin
->GetOpenedPage();
1509 if (item
== wxEmptyString
)
1510 item
= url
.AfterLast(wxT('/'));
1511 if (m_BookmarksPages
.Index(url
) == wxNOT_FOUND
)
1513 m_Bookmarks
->Append(item
);
1514 m_BookmarksNames
.Add(item
);
1515 m_BookmarksPages
.Add(url
);
1520 case wxID_HTML_BOOKMARKSREMOVE
:
1525 item
= m_Bookmarks
->GetStringSelection();
1526 pos
= m_BookmarksNames
.Index(item
);
1527 if (pos
!= wxNOT_FOUND
)
1529 m_BookmarksNames
.RemoveAt(pos
);
1530 m_BookmarksPages
.RemoveAt(pos
);
1531 pos
= m_Bookmarks
->GetSelection();
1532 wxASSERT_MSG( pos
!= wxNOT_FOUND
, wxT("Unknown bookmark position") ) ;
1533 m_Bookmarks
->Delete((unsigned int)pos
);
1538 #if wxUSE_PRINTING_ARCHITECTURE
1539 case wxID_HTML_PRINT
:
1541 if (m_Printer
== NULL
)
1542 m_Printer
= new wxHtmlEasyPrinting(_("Help Printing"), this);
1543 if (!m_HtmlWin
->GetOpenedPage())
1544 wxLogWarning(_("Cannot print empty page."));
1546 m_Printer
->PrintFile(m_HtmlWin
->GetOpenedPage());
1551 case wxID_HTML_OPENFILE
:
1553 wxString filemask
= wxString(
1554 _("HTML files (*.html;*.htm)|*.html;*.htm|")) +
1555 _("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|") +
1556 _("HTML Help Project (*.hhp)|*.hhp|") +
1558 _("Compressed HTML Help file (*.chm)|*.chm|") +
1560 _("All files (*.*)|*");
1561 wxString s
= wxFileSelector(_("Open HTML document"),
1566 wxFD_OPEN
| wxFD_FILE_MUST_EXIST
,
1570 wxString ext
= s
.Right(4).Lower();
1571 if (ext
== _T(".zip") || ext
== _T(".htb") ||
1573 ext
== _T(".chm") ||
1582 m_HtmlWin
->LoadPage(s
);
1589 void wxHtmlHelpWindow::OnContentsSel(wxTreeEvent
& event
)
1591 wxHtmlHelpTreeItemData
*pg
;
1593 pg
= (wxHtmlHelpTreeItemData
*) m_ContentsBox
->GetItemData(event
.GetItem());
1595 if (pg
&& m_UpdateContents
)
1597 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1598 m_UpdateContents
= false;
1599 if (!contents
[pg
->m_Id
].page
.empty())
1600 m_HtmlWin
->LoadPage(contents
[pg
->m_Id
].GetFullPath());
1601 m_UpdateContents
= true;
1605 void wxHtmlHelpWindow::OnIndexSel(wxCommandEvent
& WXUNUSED(event
))
1607 wxHtmlHelpMergedIndexItem
*it
= (wxHtmlHelpMergedIndexItem
*)
1608 m_IndexList
->GetClientData(m_IndexList
->GetSelection());
1610 DisplayIndexItem(it
);
1613 void wxHtmlHelpWindow::OnIndexFind(wxCommandEvent
& WXUNUSED(event
))
1618 void wxHtmlHelpWindow::DoIndexFind()
1620 wxString sr
= m_IndexText
->GetLineText(0);
1622 if (sr
== wxEmptyString
)
1630 m_IndexList
->Clear();
1631 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1632 size_t cnt
= index
.size();
1635 for (size_t i
= 0; i
< cnt
; i
++)
1637 if (index
[i
].name
.Lower().find(sr
) != wxString::npos
)
1639 int pos
= m_IndexList
->Append(index
[i
].name
,
1640 (char*)(&index
[i
]));
1644 // don't automatically show topic selector if this
1645 // item points to multiple pages:
1646 if (index
[i
].items
.size() == 1)
1648 m_IndexList
->SetSelection(0);
1649 DisplayIndexItem(&index
[i
]);
1653 // if this is nested item of the index, show its parent(s)
1654 // as well, otherwise it would not be clear what entry is
1656 wxHtmlHelpMergedIndexItem
*parent
= index
[i
].parent
;
1660 (index
.Index(*(wxHtmlHelpMergedIndexItem
*)m_IndexList
->GetClientData(pos
-1))) < index
.Index(*parent
))
1662 m_IndexList
->Insert(parent
->name
,
1663 pos
, (char*)parent
);
1664 parent
= parent
->parent
;
1669 // finally, it the item we just added is itself a parent for
1670 // other items, show them as well, because they are refinements
1671 // of the displayed index entry (i.e. it is implicitly contained
1672 // in them: "foo" with parent "bar" reads as "bar, foo"):
1673 int level
= index
[i
].items
[0]->level
;
1675 while (i
< cnt
&& index
[i
].items
[0]->level
> level
)
1677 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1685 cnttext
.Printf(_("%i of %i"), displ
, cnt
);
1686 m_IndexCountInfo
->SetLabel(cnttext
);
1688 m_IndexText
->SetSelection(0, sr
.length());
1689 m_IndexText
->SetFocus();
1693 void wxHtmlHelpWindow::OnIndexAll(wxCommandEvent
& WXUNUSED(event
))
1698 void wxHtmlHelpWindow::DoIndexAll()
1702 m_IndexList
->Clear();
1703 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1704 size_t cnt
= index
.size();
1707 for (size_t i
= 0; i
< cnt
; i
++)
1709 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1712 // don't automatically show topic selector if this
1713 // item points to multiple pages:
1714 if (index
[i
].items
.size() == 1)
1716 DisplayIndexItem(&index
[i
]);
1723 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1724 m_IndexCountInfo
->SetLabel(cnttext
);
1727 void wxHtmlHelpWindow::OnSearchSel(wxCommandEvent
& WXUNUSED(event
))
1729 wxHtmlHelpDataItem
*it
= (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(m_SearchList
->GetSelection());
1732 if (!it
->page
.empty())
1733 m_HtmlWin
->LoadPage(it
->GetFullPath());
1734 NotifyPageChanged();
1738 void wxHtmlHelpWindow::OnSearch(wxCommandEvent
& WXUNUSED(event
))
1740 wxString sr
= m_SearchText
->GetLineText(0);
1743 KeywordSearch(sr
, wxHELP_SEARCH_ALL
);
1746 void wxHtmlHelpWindow::OnBookmarksSel(wxCommandEvent
& WXUNUSED(event
))
1748 wxString str
= m_Bookmarks
->GetStringSelection();
1749 int idx
= m_BookmarksNames
.Index(str
);
1750 if (!str
.empty() && str
!= _("(bookmarks)") && idx
!= wxNOT_FOUND
)
1752 m_HtmlWin
->LoadPage(m_BookmarksPages
[(size_t)idx
]);
1753 NotifyPageChanged();
1757 void wxHtmlHelpWindow::OnSize(wxSizeEvent
& WXUNUSED(event
))
1762 #endif // wxUSE_WXHTML_HELP