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 1000
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 wxDECLARE_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, wxT("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
;
278 m_ConfigRoot
= wxEmptyString
;
279 #endif // wxUSE_CONFIG
281 m_Cfg
.x
= m_Cfg
.y
= wxDefaultCoord
;
285 m_Cfg
.navig_on
= true;
287 m_NormalFonts
= m_FixedFonts
= NULL
;
288 m_NormalFace
= m_FixedFace
= wxEmptyString
;
295 #if wxUSE_PRINTING_ARCHITECTURE
300 m_UpdateContents
= true;
302 m_helpController
= NULL
;
305 // Create: builds the GUI components.
306 // with the style flag it's possible to toggle the toolbar, contents, index and search
308 // m_HtmlWin will *always* be created, but it's important to realize that
309 // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
310 // m_SearchButton may be NULL.
311 // moreover, if no contents, index or searchpage is needed, m_Splitter and
312 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
314 bool wxHtmlHelpWindow::Create(wxWindow
* parent
, wxWindowID id
,
315 const wxPoint
& pos
, const wxSize
& size
,
316 int style
, int helpStyle
)
318 m_hfStyle
= helpStyle
;
321 // Do the config in two steps. We read the HtmlWindow customization after we
322 // create the window.
324 ReadCustomization(m_Config
, m_ConfigRoot
);
325 #endif // wxUSE_CONFIG
327 wxWindow::Create(parent
, id
, pos
, size
, style
, wxT("wxHtmlHelp"));
329 SetHelpText(_("Displays help as you browse the books on the left."));
331 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
333 int notebook_page
= 0;
335 // The sizer for the whole top-level window.
336 wxSizer
*topWindowSizer
= new wxBoxSizer(wxVERTICAL
);
337 SetSizer(topWindowSizer
);
342 if (helpStyle
& (wxHF_TOOLBAR
| wxHF_FLAT_TOOLBAR
))
344 wxToolBar
*toolBar
= new wxToolBar(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
345 wxNO_BORDER
| wxTB_HORIZONTAL
|
346 wxTB_DOCKABLE
| wxTB_NODIVIDER
|
347 (helpStyle
& wxHF_FLAT_TOOLBAR
? wxTB_FLAT
: 0));
348 toolBar
->SetMargins( 2, 2 );
349 toolBar
->SetToolBitmapSize( wxSize(22,22) );
350 AddToolbarButtons(toolBar
, helpStyle
);
352 topWindowSizer
->Add(toolBar
, 0, wxEXPAND
);
355 #endif //wxUSE_TOOLBAR
357 wxSizer
*navigSizer
= NULL
;
360 wxBorder htmlWindowBorder
= GetDefaultBorder();
361 if (htmlWindowBorder
== wxBORDER_SUNKEN
)
362 htmlWindowBorder
= wxBORDER_SIMPLE
;
364 wxBorder htmlWindowBorder
= wxBORDER_SUNKEN
;
367 if (helpStyle
& (wxHF_CONTENTS
| wxHF_INDEX
| wxHF_SEARCH
))
369 // traditional help controller; splitter window with html page on the
370 // right and a notebook containing various pages on the left
371 long splitterStyle
= wxSP_3D
;
372 // Drawing moving sash can cause problems on wxMac
374 splitterStyle
|= wxSP_LIVE_UPDATE
;
376 m_Splitter
= new wxSplitterWindow(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, splitterStyle
);
378 topWindowSizer
->Add(m_Splitter
, 1, wxEXPAND
);
380 m_HtmlWin
= new wxHtmlHelpHtmlWindow(this, m_Splitter
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxHW_DEFAULT_STYLE
|htmlWindowBorder
);
381 m_NavigPan
= new wxPanel(m_Splitter
, wxID_ANY
);
382 m_NavigNotebook
= new wxNotebook(m_NavigPan
, wxID_HTML_NOTEBOOK
,
383 wxDefaultPosition
, wxDefaultSize
);
385 m_NavigNotebook
->SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
388 navigSizer
= new wxBoxSizer(wxVERTICAL
);
389 navigSizer
->Add(m_NavigNotebook
, 1, wxEXPAND
);
391 m_NavigPan
->SetSizer(navigSizer
);
395 // only html window, no notebook with index,contents etc
396 m_HtmlWin
= new wxHtmlWindow(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxHW_DEFAULT_STYLE
|htmlWindowBorder
);
397 topWindowSizer
->Add(m_HtmlWin
, 1, wxEXPAND
);
402 m_HtmlWin
->ReadCustomization(m_Config
, m_ConfigRoot
);
403 #endif // wxUSE_CONFIG
405 // contents tree panel?
406 if ( helpStyle
& wxHF_CONTENTS
)
408 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
410 dummy
->SetWindowVariant(wxWINDOW_VARIANT_NORMAL
);
412 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
414 topsizer
->Add(0, 10);
416 dummy
->SetSizer(topsizer
);
418 if ( helpStyle
& wxHF_BOOKMARKS
)
420 m_Bookmarks
= new wxComboBox(dummy
, wxID_HTML_BOOKMARKSLIST
,
422 wxDefaultPosition
, wxDefaultSize
,
423 0, NULL
, wxCB_READONLY
| wxCB_SORT
);
424 m_Bookmarks
->Append(_("(bookmarks)"));
425 for (unsigned i
= 0; i
< m_BookmarksNames
.GetCount(); i
++)
426 m_Bookmarks
->Append(m_BookmarksNames
[i
]);
427 m_Bookmarks
->SetSelection(0);
429 wxBitmapButton
*bmpbt1
, *bmpbt2
;
430 bmpbt1
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSADD
,
431 wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK
,
433 bmpbt2
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSREMOVE
,
434 wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK
,
437 bmpbt1
->SetToolTip(_("Add current page to bookmarks"));
438 bmpbt2
->SetToolTip(_("Remove current page from bookmarks"));
439 #endif // wxUSE_TOOLTIPS
441 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
443 sizer
->Add(m_Bookmarks
, 1, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 5);
444 sizer
->Add(bmpbt1
, 0, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 2);
445 sizer
->Add(bmpbt2
, 0, wxALIGN_CENTRE_VERTICAL
, 0);
447 topsizer
->Add(sizer
, 0, wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
, 10);
450 m_ContentsBox
= new wxTreeCtrl(dummy
, wxID_HTML_TREECTRL
,
451 wxDefaultPosition
, wxDefaultSize
,
452 #if defined(__WXGTK20__) || defined(__WXMAC__)
454 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
458 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
463 wxImageList
*ContentsImageList
= new wxImageList(16, 16);
464 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK
,
467 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER
,
470 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE
,
474 m_ContentsBox
->AssignImageList(ContentsImageList
);
476 topsizer
->Add(m_ContentsBox
, 1,
477 wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
,
480 m_NavigNotebook
->AddPage(dummy
, _("Contents"));
481 m_ContentsPage
= notebook_page
++;
484 // index listbox panel?
485 if ( helpStyle
& wxHF_INDEX
)
487 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
489 dummy
->SetWindowVariant(wxWINDOW_VARIANT_NORMAL
);
491 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
493 dummy
->SetSizer(topsizer
);
495 m_IndexText
= new wxTextCtrl(dummy
, wxID_HTML_INDEXTEXT
, wxEmptyString
,
496 wxDefaultPosition
, wxDefaultSize
,
498 m_IndexButton
= new wxButton(dummy
, wxID_HTML_INDEXBUTTON
, _("Find"));
499 m_IndexButtonAll
= new wxButton(dummy
, wxID_HTML_INDEXBUTTONALL
,
501 m_IndexCountInfo
= new wxStaticText(dummy
, wxID_HTML_COUNTINFO
,
502 wxEmptyString
, wxDefaultPosition
,
504 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
505 m_IndexList
= new wxListBox(dummy
, wxID_HTML_INDEXLIST
,
506 wxDefaultPosition
, wxDefaultSize
,
507 0, NULL
, wxLB_SINGLE
);
510 m_IndexButton
->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
511 m_IndexButtonAll
->SetToolTip(_("Show all items in index"));
512 #endif //wxUSE_TOOLTIPS
514 topsizer
->Add(m_IndexText
, 0, wxEXPAND
| wxALL
, 10);
515 wxSizer
*btsizer
= new wxBoxSizer(wxHORIZONTAL
);
516 btsizer
->Add(m_IndexButton
, 0, wxRIGHT
, 2);
517 btsizer
->Add(m_IndexButtonAll
);
518 topsizer
->Add(btsizer
, 0,
519 wxALIGN_RIGHT
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
520 topsizer
->Add(m_IndexCountInfo
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 2);
521 topsizer
->Add(m_IndexList
, 1, wxEXPAND
| wxALL
, 2);
523 m_NavigNotebook
->AddPage(dummy
, _("Index"));
524 m_IndexPage
= notebook_page
++;
527 // search list panel?
528 if ( helpStyle
& wxHF_SEARCH
)
530 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
532 dummy
->SetWindowVariant(wxWINDOW_VARIANT_NORMAL
);
534 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
536 dummy
->SetSizer(sizer
);
538 m_SearchText
= new wxTextCtrl(dummy
, wxID_HTML_SEARCHTEXT
,
540 wxDefaultPosition
, wxDefaultSize
,
542 m_SearchChoice
= new wxChoice(dummy
, wxID_HTML_SEARCHCHOICE
,
543 wxDefaultPosition
, wxSize(125,wxDefaultCoord
));
544 m_SearchCaseSensitive
= new wxCheckBox(dummy
, wxID_ANY
, _("Case sensitive"));
545 m_SearchWholeWords
= new wxCheckBox(dummy
, wxID_ANY
, _("Whole words only"));
546 m_SearchButton
= new wxButton(dummy
, wxID_HTML_SEARCHBUTTON
, _("Search"));
548 m_SearchButton
->SetToolTip(_("Search contents of help book(s) for all occurrences of the text you typed above"));
549 #endif //wxUSE_TOOLTIPS
550 m_SearchList
= new wxListBox(dummy
, wxID_HTML_SEARCHLIST
,
551 wxDefaultPosition
, wxDefaultSize
,
552 0, NULL
, wxLB_SINGLE
);
554 sizer
->Add(m_SearchText
, 0, wxEXPAND
| wxALL
, 10);
555 sizer
->Add(m_SearchChoice
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
556 sizer
->Add(m_SearchCaseSensitive
, 0, wxLEFT
| wxRIGHT
, 10);
557 sizer
->Add(m_SearchWholeWords
, 0, wxLEFT
| wxRIGHT
, 10);
558 sizer
->Add(m_SearchButton
, 0, wxALL
| wxALIGN_RIGHT
, 8);
559 sizer
->Add(m_SearchList
, 1, wxALL
| wxEXPAND
, 2);
561 m_NavigNotebook
->AddPage(dummy
, _("Search"));
562 m_SearchPage
= notebook_page
;
571 navigSizer
->SetSizeHints(m_NavigPan
);
572 m_NavigPan
->Layout();
576 if ( m_NavigPan
&& m_Splitter
)
578 // The panel will have its own min size which the splitter
581 // m_Splitter->SetMinimumPaneSize(m_NavigPan->GetBestSize().x);
583 m_Splitter
->SetMinimumPaneSize(20);
585 if ( m_Cfg
.navig_on
)
588 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
592 m_NavigPan
->Show(false);
593 m_Splitter
->Initialize(m_HtmlWin
);
597 // Reduce flicker by updating the splitter pane sizes before the
599 wxSizeEvent
sizeEvent(GetSize(), GetId());
600 GetEventHandler()->ProcessEvent(sizeEvent
);
603 m_Splitter
->UpdateSize();
608 wxHtmlHelpWindow::~wxHtmlHelpWindow()
610 if ( m_helpController
)
611 m_helpController
->SetHelpWindow(NULL
);
613 delete m_mergedIndex
;
615 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
618 if (m_NormalFonts
) delete m_NormalFonts
;
619 if (m_FixedFonts
) delete m_FixedFonts
;
622 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
625 #if wxUSE_PRINTING_ARCHITECTURE
626 if (m_Printer
) delete m_Printer
;
630 void wxHtmlHelpWindow::SetController(wxHtmlHelpController
* controller
)
634 m_helpController
= controller
;
635 m_Data
= controller
->GetHelpData();
636 m_DataCreated
= false;
640 void wxHtmlHelpWindow::AddToolbarButtons(wxToolBar
*toolBar
, int style
)
642 wxBitmap wpanelBitmap
=
643 wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL
, wxART_TOOLBAR
);
644 wxBitmap wbackBitmap
=
645 wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_TOOLBAR
);
646 wxBitmap wforwardBitmap
=
647 wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_TOOLBAR
);
648 wxBitmap wupnodeBitmap
=
649 wxArtProvider::GetBitmap(wxART_GO_TO_PARENT
, wxART_TOOLBAR
);
651 wxArtProvider::GetBitmap(wxART_GO_UP
, wxART_TOOLBAR
);
652 wxBitmap wdownBitmap
=
653 wxArtProvider::GetBitmap(wxART_GO_DOWN
, wxART_TOOLBAR
);
654 wxBitmap wopenBitmap
=
655 wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_TOOLBAR
);
656 wxBitmap wprintBitmap
=
657 wxArtProvider::GetBitmap(wxART_PRINT
, wxART_TOOLBAR
);
658 wxBitmap woptionsBitmap
=
659 wxArtProvider::GetBitmap(wxART_HELP_SETTINGS
, wxART_TOOLBAR
);
661 wxASSERT_MSG( (wpanelBitmap
.IsOk() && wbackBitmap
.IsOk() &&
662 wforwardBitmap
.IsOk() && wupnodeBitmap
.IsOk() &&
663 wupBitmap
.IsOk() && wdownBitmap
.IsOk() &&
664 wopenBitmap
.IsOk() && wprintBitmap
.IsOk() &&
665 woptionsBitmap
.IsOk()),
666 wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
669 toolBar
->AddTool(wxID_HTML_PANEL
, wxEmptyString
, wpanelBitmap
, _("Show/hide navigation panel"));
670 toolBar
->AddSeparator();
671 toolBar
->AddTool(wxID_HTML_BACK
, wxEmptyString
, wbackBitmap
, _("Go back"));
672 toolBar
->AddTool(wxID_HTML_FORWARD
, wxEmptyString
, wforwardBitmap
, _("Go forward"));
673 toolBar
->AddSeparator();
674 toolBar
->AddTool(wxID_HTML_UPNODE
, wxEmptyString
, wupnodeBitmap
, _("Go one level up in document hierarchy"));
675 toolBar
->AddTool(wxID_HTML_UP
, wxEmptyString
, wupBitmap
, _("Previous page"));
676 toolBar
->AddTool(wxID_HTML_DOWN
, wxEmptyString
, wdownBitmap
, _("Next page"));
678 if ((style
& wxHF_PRINT
) || (style
& wxHF_OPEN_FILES
))
679 toolBar
->AddSeparator();
681 if (style
& wxHF_OPEN_FILES
)
682 toolBar
->AddTool(wxID_HTML_OPENFILE
, wxEmptyString
, wopenBitmap
, _("Open HTML document"));
684 #if wxUSE_PRINTING_ARCHITECTURE
685 if (style
& wxHF_PRINT
)
686 toolBar
->AddTool(wxID_HTML_PRINT
, wxEmptyString
, wprintBitmap
, _("Print this page"));
689 toolBar
->AddSeparator();
690 toolBar
->AddTool(wxID_HTML_OPTIONS
, wxEmptyString
, woptionsBitmap
, _("Display options dialog"));
692 // Allow application to add custom buttons
693 wxHtmlHelpFrame
* parentFrame
= wxDynamicCast(GetParent(), wxHtmlHelpFrame
);
694 wxHtmlHelpDialog
* parentDialog
= wxDynamicCast(GetParent(), wxHtmlHelpDialog
);
696 parentFrame
->AddToolbarButtons(toolBar
, style
);
698 parentDialog
->AddToolbarButtons(toolBar
, style
);
700 #endif //wxUSE_TOOLBAR
703 bool wxHtmlHelpWindow::Display(const wxString
& x
)
705 wxString url
= m_Data
->FindPageByName(x
);
708 m_HtmlWin
->LoadPage(url
);
716 bool wxHtmlHelpWindow::Display(const int id
)
718 wxString url
= m_Data
->FindPageById(id
);
721 m_HtmlWin
->LoadPage(url
);
729 bool wxHtmlHelpWindow::DisplayContents()
734 if (!m_Splitter
->IsSplit())
738 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
739 m_Cfg
.navig_on
= true;
742 m_NavigNotebook
->SetSelection(m_ContentsPage
);
744 if (m_Data
->GetBookRecArray().GetCount() > 0)
746 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
747 if (!book
.GetStart().empty())
748 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
754 bool wxHtmlHelpWindow::DisplayIndex()
759 if (!m_Splitter
->IsSplit())
763 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
766 m_NavigNotebook
->SetSelection(m_IndexPage
);
768 if (m_Data
->GetBookRecArray().GetCount() > 0)
770 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
771 if (!book
.GetStart().empty())
772 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
778 void wxHtmlHelpWindow::DisplayIndexItem(const wxHtmlHelpMergedIndexItem
*it
)
780 if (it
->items
.size() == 1)
782 if (!it
->items
[0]->page
.empty())
784 m_HtmlWin
->LoadPage(it
->items
[0]->GetFullPath());
790 wxBusyCursor busy_cursor
;
792 // more pages associated with this index item -- let the user choose
793 // which one she/he wants from a list:
795 size_t len
= it
->items
.size();
796 for (size_t i
= 0; i
< len
; i
++)
798 wxString page
= it
->items
[i
]->page
;
799 // try to find page's title in contents:
800 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
801 size_t clen
= contents
.size();
802 for (size_t j
= 0; j
< clen
; j
++)
804 if (contents
[j
].page
== page
)
806 page
= contents
[j
].name
;
813 wxSingleChoiceDialog
dlg(this,
814 _("Please choose the page to display:"),
816 arr
, NULL
, wxCHOICEDLG_STYLE
& ~wxCENTRE
);
817 if (dlg
.ShowModal() == wxID_OK
)
819 m_HtmlWin
->LoadPage(it
->items
[dlg
.GetSelection()]->GetFullPath());
825 bool wxHtmlHelpWindow::KeywordSearch(const wxString
& keyword
,
826 wxHelpSearchMode mode
)
828 wxCHECK_MSG( !keyword
.empty(), false, "must have a non empty keyword" );
830 if (mode
== wxHELP_SEARCH_ALL
)
832 if ( !(m_SearchList
&&
833 m_SearchButton
&& m_SearchText
&& m_SearchChoice
) )
836 else if (mode
== wxHELP_SEARCH_INDEX
)
838 if ( !(m_IndexList
&&
839 m_IndexButton
&& m_IndexButtonAll
&& m_IndexText
) )
845 wxString book
= wxEmptyString
;
847 if (!m_Splitter
->IsSplit())
851 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
854 if (mode
== wxHELP_SEARCH_ALL
)
856 m_NavigNotebook
->SetSelection(m_SearchPage
);
857 m_SearchList
->Clear();
858 m_SearchText
->SetValue(keyword
);
859 m_SearchButton
->Disable();
861 if (m_SearchChoice
->GetSelection() != 0)
862 book
= m_SearchChoice
->GetStringSelection();
864 wxHtmlSearchStatus
status(m_Data
, keyword
,
865 m_SearchCaseSensitive
->GetValue(),
866 m_SearchWholeWords
->GetValue(),
869 #if wxUSE_PROGRESSDLG
870 wxProgressDialog
progress(_("Searching..."),
871 _("No matching page found yet"),
872 status
.GetMaxIndex(), this,
873 wxPD_APP_MODAL
| wxPD_CAN_ABORT
| wxPD_AUTO_HIDE
);
877 while (status
.IsActive())
879 curi
= status
.GetCurIndex();
881 #if wxUSE_PROGRESSDLG
882 && !progress
.Update(curi
)
888 foundstr
.Printf(_("Found %i matches"), ++foundcnt
);
889 #if wxUSE_PROGRESSDLG
890 progress
.Update(status
.GetCurIndex(), foundstr
);
892 m_SearchList
->Append(status
.GetName(), (void*)status
.GetCurItem());
896 m_SearchButton
->Enable();
897 m_SearchText
->SetSelection(0, keyword
.length());
898 m_SearchText
->SetFocus();
900 else if (mode
== wxHELP_SEARCH_INDEX
)
902 m_NavigNotebook
->SetSelection(m_IndexPage
);
903 m_IndexList
->Clear();
904 m_IndexButton
->Disable();
905 m_IndexButtonAll
->Disable();
906 m_IndexText
->SetValue(keyword
);
909 m_IndexButton
->Enable();
910 m_IndexButtonAll
->Enable();
911 foundcnt
= m_IndexList
->GetCount();
919 wxFAIL_MSG( wxT("unknown help search mode") );
922 case wxHELP_SEARCH_ALL
:
924 wxHtmlHelpDataItem
*it
=
925 (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(0);
928 m_HtmlWin
->LoadPage(it
->GetFullPath());
934 case wxHELP_SEARCH_INDEX
:
936 wxHtmlHelpMergedIndexItem
* it
=
937 (wxHtmlHelpMergedIndexItem
*) m_IndexList
->GetClientData(0);
939 DisplayIndexItem(it
);
949 void wxHtmlHelpWindow::CreateContents()
956 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
960 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
962 size_t cnt
= contents
.size();
964 m_PagesHash
= new wxHashTable(wxKEY_STRING
, 2 * cnt
);
966 const int MAX_ROOTS
= 64;
967 wxTreeItemId roots
[MAX_ROOTS
];
968 // VS: this array holds information about whether we've set item icon at
969 // given level. This is necessary because m_Data has a flat structure
970 // and there's no way of recognizing if some item has subitems or not.
971 // We set the icon later: when we find an item with level=n, we know
972 // that the last item with level=n-1 was afolder with subitems, so we
973 // set its icon accordingly
974 bool imaged
[MAX_ROOTS
];
975 m_ContentsBox
->DeleteAllItems();
977 roots
[0] = m_ContentsBox
->AddRoot(_("(Help)"));
980 for (size_t i
= 0; i
< cnt
; i
++)
982 wxHtmlHelpDataItem
*it
= &contents
[i
];
986 if (m_hfStyle
& wxHF_MERGE_BOOKS
)
987 // VS: we don't want book nodes, books' content should
988 // appear under tree's root. This line will create a "fake"
989 // record about book node so that the rest of this look
990 // will believe there really _is_ a book node and will
995 roots
[1] = m_ContentsBox
->AppendItem(roots
[0],
996 it
->name
, IMG_Book
, -1,
997 new wxHtmlHelpTreeItemData(i
));
998 m_ContentsBox
->SetItemBold(roots
[1], true);
1002 // ...and their contents:
1005 roots
[it
->level
+ 1] = m_ContentsBox
->AppendItem(
1006 roots
[it
->level
], it
->name
, IMG_Page
,
1007 -1, new wxHtmlHelpTreeItemData(i
));
1008 imaged
[it
->level
+ 1] = false;
1011 m_PagesHash
->Put(it
->GetFullPath(),
1012 new wxHtmlHelpHashData(i
, roots
[it
->level
+ 1]));
1014 // Set the icon for the node one level up in the hierarchy,
1015 // unless already done (see comment above imaged[] declaration)
1016 if (!imaged
[it
->level
])
1018 int image
= IMG_Folder
;
1019 if (m_hfStyle
& wxHF_ICONS_BOOK
)
1021 else if (m_hfStyle
& wxHF_ICONS_BOOK_CHAPTER
)
1022 image
= (it
->level
== 1) ? IMG_Book
: IMG_Folder
;
1023 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
);
1024 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
,
1025 wxTreeItemIcon_Selected
);
1026 imaged
[it
->level
] = true;
1031 void wxHtmlHelpWindow::CreateIndex()
1036 m_IndexList
->Clear();
1038 unsigned long cnt
= m_mergedIndex
->size();
1041 if (cnt
> INDEX_IS_SMALL
)
1042 cnttext
.Printf(_("%d of %lu"), 0, cnt
);
1044 cnttext
.Printf(_("%lu of %lu"), 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 wxHtmlHelpWindow::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);
1068 void wxHtmlHelpWindow::RefreshLists()
1070 // Update m_mergedIndex:
1071 UpdateMergedIndex();
1072 // Update the controls
1079 void wxHtmlHelpWindow::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1084 if (path
!= wxEmptyString
)
1086 oldpath
= cfg
->GetPath();
1087 cfg
->SetPath(wxT("/") + 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 wxHtmlHelpWindow::WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1142 if (path
!= wxEmptyString
)
1144 oldpath
= cfg
->GetPath();
1145 cfg
->SetPath(wxT("/") + path
);
1148 cfg
->Write(wxT("hcNavigPanel"), m_Cfg
.navig_on
);
1149 cfg
->Write(wxT("hcSashPos"), (long)m_Cfg
.sashpos
);
1151 // Don't write if iconized as this would make the window
1152 // disappear next time it is shown!
1153 cfg
->Write(wxT("hcX"), (long)m_Cfg
.x
);
1154 cfg
->Write(wxT("hcY"), (long)m_Cfg
.y
);
1155 cfg
->Write(wxT("hcW"), (long)m_Cfg
.w
);
1156 cfg
->Write(wxT("hcH"), (long)m_Cfg
.h
);
1158 cfg
->Write(wxT("hcFixedFace"), m_FixedFace
);
1159 cfg
->Write(wxT("hcNormalFace"), m_NormalFace
);
1160 cfg
->Write(wxT("hcBaseFontSize"), (long)m_FontSize
);
1165 int cnt
= m_BookmarksNames
.GetCount();
1168 cfg
->Write(wxT("hcBookmarksCnt"), (long)cnt
);
1169 for (i
= 0; i
< cnt
; i
++)
1171 val
.Printf(wxT("hcBookmark_%i"), i
);
1172 cfg
->Write(val
, m_BookmarksNames
[i
]);
1173 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1174 cfg
->Write(val
, m_BookmarksPages
[i
]);
1179 m_HtmlWin
->WriteCustomization(cfg
);
1181 if (path
!= wxEmptyString
)
1182 cfg
->SetPath(oldpath
);
1184 #endif // wxUSE_CONFIG
1186 static void SetFontsToHtmlWin(wxHtmlWindow
*win
, const wxString
& scalf
, const wxString
& fixf
, int size
)
1189 f_sizes
[0] = int(size
* 0.6);
1190 f_sizes
[1] = int(size
* 0.8);
1192 f_sizes
[3] = int(size
* 1.2);
1193 f_sizes
[4] = int(size
* 1.4);
1194 f_sizes
[5] = int(size
* 1.6);
1195 f_sizes
[6] = int(size
* 1.8);
1197 win
->SetFonts(scalf
, fixf
, f_sizes
);
1200 class wxHtmlHelpWindowOptionsDialog
: public wxDialog
1203 wxComboBox
*NormalFont
, *FixedFont
;
1204 wxSpinCtrl
*FontSize
;
1205 wxHtmlWindow
*TestWin
;
1207 wxHtmlHelpWindowOptionsDialog(wxWindow
*parent
)
1208 : wxDialog(parent
, wxID_ANY
, wxString(_("Help Browser Options")))
1210 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
1211 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2, 3, 2, 5);
1213 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Normal font:")));
1214 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Fixed font:")));
1215 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Font size:")));
1217 sizer
->Add(NormalFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1218 wxSize(200, wxDefaultCoord
),
1219 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1221 sizer
->Add(FixedFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1222 wxSize(200, wxDefaultCoord
),
1223 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1225 sizer
->Add(FontSize
= new wxSpinCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1226 wxDefaultSize
, wxSP_ARROW_KEYS
, 2, 100, 2, wxT("wxSpinCtrl")));
1228 topsizer
->Add(sizer
, 0, wxLEFT
|wxRIGHT
|wxTOP
, 10);
1230 topsizer
->Add(new wxStaticText(this, wxID_ANY
, _("Preview:")),
1231 0, wxLEFT
| wxTOP
, 10);
1233 topsizer
->AddSpacer(5);
1235 topsizer
->Add(TestWin
= new wxHtmlWindow(this, wxID_ANY
, wxDefaultPosition
, wxSize(20, 150),
1236 wxHW_SCROLLBAR_AUTO
|wxBORDER_THEME
),
1237 1, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
1239 wxBoxSizer
*sizer2
= new wxBoxSizer(wxHORIZONTAL
);
1241 sizer2
->Add(ok
= new wxButton(this, wxID_OK
), 0, wxALL
, 10);
1243 sizer2
->Add(new wxButton(this, wxID_CANCEL
), 0, wxALL
, 10);
1244 topsizer
->Add(sizer2
, 0, wxALIGN_RIGHT
);
1247 topsizer
->Fit(this);
1252 void UpdateTestWin()
1255 SetFontsToHtmlWin(TestWin
,
1256 NormalFont
->GetStringSelection(),
1257 FixedFont
->GetStringSelection(),
1258 FontSize
->GetValue());
1260 wxString
content(_("font size"));
1262 content
= wxT("<font size=-2>") + content
+ wxT(" -2</font><br>")
1263 wxT("<font size=-1>") + content
+ wxT(" -1</font><br>")
1264 wxT("<font size=+0>") + content
+ wxT(" +0</font><br>")
1265 wxT("<font size=+1>") + content
+ wxT(" +1</font><br>")
1266 wxT("<font size=+2>") + content
+ wxT(" +2</font><br>")
1267 wxT("<font size=+3>") + content
+ wxT(" +3</font><br>")
1268 wxT("<font size=+4>") + content
+ wxT(" +4</font><br>") ;
1270 content
= wxString( wxT("<html><body><table><tr><td>") ) +
1271 _("Normal face<br>and <u>underlined</u>. ") +
1272 _("<i>Italic face.</i> ") +
1273 _("<b>Bold face.</b> ") +
1274 _("<b><i>Bold italic face.</i></b><br>") +
1276 wxString( wxT("</td><td><tt>") ) +
1277 _("Fixed size face.<br> <b>bold</b> <i>italic</i> ") +
1278 _("<b><i>bold italic <u>underlined</u></i></b><br>") +
1280 wxT("</tt></td></tr></table></body></html>");
1282 TestWin
->SetPage( content
);
1285 void OnUpdate(wxCommandEvent
& WXUNUSED(event
))
1289 void OnUpdateSpin(wxSpinEvent
& WXUNUSED(event
))
1294 DECLARE_EVENT_TABLE()
1295 wxDECLARE_NO_COPY_CLASS(wxHtmlHelpWindowOptionsDialog
);
1298 BEGIN_EVENT_TABLE(wxHtmlHelpWindowOptionsDialog
, wxDialog
)
1299 EVT_COMBOBOX(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdate
)
1300 EVT_SPINCTRL(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdateSpin
)
1303 void wxHtmlHelpWindow::OptionsDialog()
1305 wxHtmlHelpWindowOptionsDialog
dlg(this);
1308 if (m_NormalFonts
== NULL
)
1310 m_NormalFonts
= new wxArrayString(wxFontEnumerator::GetFacenames());
1311 m_NormalFonts
->Sort(); // ascending sort
1313 if (m_FixedFonts
== NULL
)
1315 m_FixedFonts
= new wxArrayString(
1316 wxFontEnumerator::GetFacenames(wxFONTENCODING_SYSTEM
,
1317 true /*enum fixed width only*/));
1318 m_FixedFonts
->Sort(); // ascending sort
1321 // VS: We want to show the font that is actually used by wxHtmlWindow.
1322 // If customization dialog wasn't used yet, facenames are empty and
1323 // wxHtmlWindow uses default fonts -- let's find out what they
1324 // are so that we can pass them to the dialog:
1325 if (m_NormalFace
.empty())
1327 wxFont
fnt(m_FontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false);
1328 m_NormalFace
= fnt
.GetFaceName();
1330 if (m_FixedFace
.empty())
1332 wxFont
fnt(m_FontSize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false);
1333 m_FixedFace
= fnt
.GetFaceName();
1336 for (i
= 0; i
< m_NormalFonts
->GetCount(); i
++)
1337 dlg
.NormalFont
->Append((*m_NormalFonts
)[i
]);
1338 for (i
= 0; i
< m_FixedFonts
->GetCount(); i
++)
1339 dlg
.FixedFont
->Append((*m_FixedFonts
)[i
]);
1340 if (!m_NormalFace
.empty())
1341 dlg
.NormalFont
->SetStringSelection(m_NormalFace
);
1343 dlg
.NormalFont
->SetSelection(0);
1344 if (!m_FixedFace
.empty())
1345 dlg
.FixedFont
->SetStringSelection(m_FixedFace
);
1347 dlg
.FixedFont
->SetSelection(0);
1348 dlg
.FontSize
->SetValue(m_FontSize
);
1349 dlg
.UpdateTestWin();
1351 if (dlg
.ShowModal() == wxID_OK
)
1353 m_NormalFace
= dlg
.NormalFont
->GetStringSelection();
1354 m_FixedFace
= dlg
.FixedFont
->GetStringSelection();
1355 m_FontSize
= dlg
.FontSize
->GetValue();
1356 SetFontsToHtmlWin(m_HtmlWin
, m_NormalFace
, m_FixedFace
, m_FontSize
);
1360 void wxHtmlHelpWindow::NotifyPageChanged()
1362 if (m_UpdateContents
&& m_PagesHash
)
1364 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1365 wxHtmlHelpHashData
*ha
= NULL
;
1367 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1371 bool olduc
= m_UpdateContents
;
1372 m_UpdateContents
= false;
1373 m_ContentsBox
->SelectItem(ha
->m_Id
);
1374 m_ContentsBox
->EnsureVisible(ha
->m_Id
);
1375 m_UpdateContents
= olduc
;
1385 void wxHtmlHelpWindow::OnToolbar(wxCommandEvent
& event
)
1387 switch (event
.GetId())
1389 case wxID_HTML_BACK
:
1390 m_HtmlWin
->HistoryBack();
1391 NotifyPageChanged();
1394 case wxID_HTML_FORWARD
:
1395 m_HtmlWin
->HistoryForward();
1396 NotifyPageChanged();
1402 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1403 wxHtmlHelpHashData
*ha
= NULL
;
1405 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1406 if (ha
&& ha
->m_Index
> 0)
1408 const wxHtmlHelpDataItem
& it
= m_Data
->GetContentsArray()[ha
->m_Index
- 1];
1409 if (!it
.page
.empty())
1411 m_HtmlWin
->LoadPage(it
.GetFullPath());
1412 NotifyPageChanged();
1418 case wxID_HTML_UPNODE
:
1421 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1422 wxHtmlHelpHashData
*ha
= NULL
;
1424 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1425 if (ha
&& ha
->m_Index
> 0)
1428 m_Data
->GetContentsArray()[ha
->m_Index
].level
- 1;
1429 int ind
= ha
->m_Index
- 1;
1431 const wxHtmlHelpDataItem
*it
=
1432 &m_Data
->GetContentsArray()[ind
];
1433 while (ind
>= 0 && it
->level
!= level
)
1436 it
= &m_Data
->GetContentsArray()[ind
];
1440 if (!it
->page
.empty())
1442 m_HtmlWin
->LoadPage(it
->GetFullPath());
1443 NotifyPageChanged();
1450 case wxID_HTML_DOWN
:
1453 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1454 wxHtmlHelpHashData
*ha
= NULL
;
1456 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1458 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1459 if (ha
&& ha
->m_Index
< (int)contents
.size() - 1)
1461 size_t idx
= ha
->m_Index
+ 1;
1463 while (contents
[idx
].GetFullPath() == page
) idx
++;
1465 if (!contents
[idx
].page
.empty())
1467 m_HtmlWin
->LoadPage(contents
[idx
].GetFullPath());
1468 NotifyPageChanged();
1474 case wxID_HTML_PANEL
:
1476 if (! (m_Splitter
&& m_NavigPan
))
1478 if (m_Splitter
->IsSplit())
1480 m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1481 m_Splitter
->Unsplit(m_NavigPan
);
1482 m_Cfg
.navig_on
= false;
1488 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
1489 m_Cfg
.navig_on
= true;
1494 case wxID_HTML_OPTIONS
:
1498 case wxID_HTML_BOOKMARKSADD
:
1503 item
= m_HtmlWin
->GetOpenedPageTitle();
1504 url
= m_HtmlWin
->GetOpenedPage();
1505 if (item
== wxEmptyString
)
1506 item
= url
.AfterLast(wxT('/'));
1507 if (m_BookmarksPages
.Index(url
) == wxNOT_FOUND
)
1509 m_Bookmarks
->Append(item
);
1510 m_BookmarksNames
.Add(item
);
1511 m_BookmarksPages
.Add(url
);
1516 case wxID_HTML_BOOKMARKSREMOVE
:
1521 item
= m_Bookmarks
->GetStringSelection();
1522 pos
= m_BookmarksNames
.Index(item
);
1523 if (pos
!= wxNOT_FOUND
)
1525 m_BookmarksNames
.RemoveAt(pos
);
1526 m_BookmarksPages
.RemoveAt(pos
);
1527 pos
= m_Bookmarks
->GetSelection();
1528 wxASSERT_MSG( pos
!= wxNOT_FOUND
, wxT("Unknown bookmark position") ) ;
1529 m_Bookmarks
->Delete((unsigned int)pos
);
1534 #if wxUSE_PRINTING_ARCHITECTURE
1535 case wxID_HTML_PRINT
:
1537 if (m_Printer
== NULL
)
1538 m_Printer
= new wxHtmlEasyPrinting(_("Help Printing"), this);
1539 if (!m_HtmlWin
->GetOpenedPage())
1541 wxLogWarning(_("Cannot print empty page."));
1545 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
== wxT(".zip") || ext
== wxT(".htb") ||
1573 ext
== wxT(".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