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 // minimum width for content tree and index
64 // (we cannot let minimum size be determined from content, else long titles
65 // make the help frame unusable)
66 const wxCoord CONTENT_TREE_INDEX_MIN_WIDTH
= 150;
68 /* Motif defines this as a macro */
73 //--------------------------------------------------------------------------
74 // wxHtmlHelpTreeItemData (private)
75 //--------------------------------------------------------------------------
77 class wxHtmlHelpTreeItemData
: public wxTreeItemData
80 #if defined(__VISAGECPP__)
81 // VA needs a default ctor for some reason....
82 wxHtmlHelpTreeItemData() : wxTreeItemData()
85 wxHtmlHelpTreeItemData(int id
) : wxTreeItemData()
92 //--------------------------------------------------------------------------
93 // wxHtmlHelpHashData (private)
94 //--------------------------------------------------------------------------
96 class wxHtmlHelpHashData
: public wxObject
99 wxHtmlHelpHashData(int index
, wxTreeItemId id
) : wxObject()
100 { m_Index
= index
; m_Id
= id
;}
101 virtual ~wxHtmlHelpHashData() {}
108 //--------------------------------------------------------------------------
109 // wxHtmlHelpHtmlWindow (private)
110 //--------------------------------------------------------------------------
113 class wxHtmlHelpHtmlWindow
: public wxHtmlWindow
116 wxHtmlHelpHtmlWindow(wxHtmlHelpWindow
*win
, wxWindow
*parent
, wxWindowID id
= wxID_ANY
,
117 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= wxHW_DEFAULT_STYLE
)
118 : wxHtmlWindow(parent
, id
, pos
, sz
, style
), m_Window(win
)
123 void OnLink(wxHtmlLinkEvent
& ev
)
125 const wxMouseEvent
*e
= ev
.GetLinkInfo().GetEvent();
126 if (e
== NULL
|| e
->LeftUp())
127 m_Window
->NotifyPageChanged();
129 // skip the event so that normal processing (i.e. following the link)
134 // Returns full location with anchor (helper)
135 static wxString
GetOpenedPageWithAnchor(wxHtmlWindow
*win
)
138 return wxEmptyString
;
140 wxString an
= win
->GetOpenedAnchor();
141 wxString pg
= win
->GetOpenedPage();
144 pg
<< wxT("#") << an
;
150 wxHtmlHelpWindow
*m_Window
;
152 wxDECLARE_NO_COPY_CLASS(wxHtmlHelpHtmlWindow
);
153 DECLARE_EVENT_TABLE()
156 BEGIN_EVENT_TABLE(wxHtmlHelpHtmlWindow
, wxHtmlWindow
)
157 EVT_HTML_LINK_CLICKED(wxID_ANY
, wxHtmlHelpHtmlWindow::OnLink
)
161 //---------------------------------------------------------------------------
162 // wxHtmlHelpWindow::m_mergedIndex
163 //---------------------------------------------------------------------------
165 WX_DEFINE_ARRAY_PTR(const wxHtmlHelpDataItem
*, wxHtmlHelpDataItemPtrArray
);
167 struct wxHtmlHelpMergedIndexItem
169 wxHtmlHelpMergedIndexItem
*parent
;
171 wxHtmlHelpDataItemPtrArray items
;
174 WX_DECLARE_OBJARRAY(wxHtmlHelpMergedIndexItem
, wxHtmlHelpMergedIndex
);
175 #include "wx/arrimpl.cpp"
176 WX_DEFINE_OBJARRAY(wxHtmlHelpMergedIndex
)
178 void wxHtmlHelpWindow::UpdateMergedIndex()
180 delete m_mergedIndex
;
181 m_mergedIndex
= new wxHtmlHelpMergedIndex
;
182 wxHtmlHelpMergedIndex
& merged
= *m_mergedIndex
;
184 const wxHtmlHelpDataItems
& items
= m_Data
->GetIndexArray();
185 size_t len
= items
.size();
187 wxHtmlHelpMergedIndexItem
*history
[128] = {NULL
};
189 for (size_t i
= 0; i
< len
; i
++)
191 const wxHtmlHelpDataItem
& item
= items
[i
];
192 wxASSERT_MSG( item
.level
< 128, wxT("nested index entries too deep") );
194 if (history
[item
.level
] &&
195 history
[item
.level
]->items
[0]->name
== item
.name
)
197 // same index entry as previous one, update list of items
198 history
[item
.level
]->items
.Add(&item
);
203 wxHtmlHelpMergedIndexItem
*mi
= new wxHtmlHelpMergedIndexItem();
204 mi
->name
= item
.GetIndentedName();
205 mi
->items
.Add(&item
);
206 mi
->parent
= (item
.level
== 0) ? NULL
: history
[item
.level
- 1];
207 history
[item
.level
] = mi
;
213 //---------------------------------------------------------------------------
215 //---------------------------------------------------------------------------
217 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpWindow
, wxWindow
)
219 BEGIN_EVENT_TABLE(wxHtmlHelpWindow
, wxWindow
)
220 EVT_TOOL_RANGE(wxID_HTML_PANEL
, wxID_HTML_OPTIONS
, wxHtmlHelpWindow::OnToolbar
)
221 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE
, wxHtmlHelpWindow::OnToolbar
)
222 EVT_BUTTON(wxID_HTML_BOOKMARKSADD
, wxHtmlHelpWindow::OnToolbar
)
223 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL
, wxHtmlHelpWindow::OnContentsSel
)
224 EVT_LISTBOX(wxID_HTML_INDEXLIST
, wxHtmlHelpWindow::OnIndexSel
)
225 EVT_LISTBOX(wxID_HTML_SEARCHLIST
, wxHtmlHelpWindow::OnSearchSel
)
226 EVT_BUTTON(wxID_HTML_SEARCHBUTTON
, wxHtmlHelpWindow::OnSearch
)
227 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT
, wxHtmlHelpWindow::OnSearch
)
228 EVT_BUTTON(wxID_HTML_INDEXBUTTON
, wxHtmlHelpWindow::OnIndexFind
)
229 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT
, wxHtmlHelpWindow::OnIndexFind
)
230 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL
, wxHtmlHelpWindow::OnIndexAll
)
231 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST
, wxHtmlHelpWindow::OnBookmarksSel
)
232 EVT_SIZE(wxHtmlHelpWindow::OnSize
)
235 wxHtmlHelpWindow::wxHtmlHelpWindow(wxWindow
* parent
, wxWindowID id
,
238 int style
, int helpStyle
, wxHtmlHelpData
* data
)
241 Create(parent
, id
, pos
, size
, style
, helpStyle
);
244 void wxHtmlHelpWindow::Init(wxHtmlHelpData
* data
)
249 m_DataCreated
= false;
253 m_Data
= new wxHtmlHelpData();
254 m_DataCreated
= true;
261 m_ContentsBox
= NULL
;
263 m_IndexButton
= NULL
;
264 m_IndexButtonAll
= NULL
;
267 m_SearchButton
= NULL
;
269 m_SearchChoice
= NULL
;
270 m_IndexCountInfo
= NULL
;
273 m_NavigNotebook
= NULL
;
276 m_SearchCaseSensitive
= NULL
;
277 m_SearchWholeWords
= NULL
;
279 m_mergedIndex
= NULL
;
283 m_ConfigRoot
= wxEmptyString
;
284 #endif // wxUSE_CONFIG
286 m_Cfg
.x
= m_Cfg
.y
= wxDefaultCoord
;
290 m_Cfg
.navig_on
= true;
292 m_NormalFonts
= m_FixedFonts
= NULL
;
293 m_NormalFace
= m_FixedFace
= wxEmptyString
;
300 #if wxUSE_PRINTING_ARCHITECTURE
305 m_UpdateContents
= true;
307 m_helpController
= NULL
;
310 // Create: builds the GUI components.
311 // with the style flag it's possible to toggle the toolbar, contents, index and search
313 // m_HtmlWin will *always* be created, but it's important to realize that
314 // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
315 // m_SearchButton may be NULL.
316 // moreover, if no contents, index or searchpage is needed, m_Splitter and
317 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
319 bool wxHtmlHelpWindow::Create(wxWindow
* parent
, wxWindowID id
,
320 const wxPoint
& pos
, const wxSize
& size
,
321 int style
, int helpStyle
)
323 m_hfStyle
= helpStyle
;
326 // Do the config in two steps. We read the HtmlWindow customization after we
327 // create the window.
329 ReadCustomization(m_Config
, m_ConfigRoot
);
330 #endif // wxUSE_CONFIG
332 wxWindow::Create(parent
, id
, pos
, size
, style
, wxT("wxHtmlHelp"));
334 SetHelpText(_("Displays help as you browse the books on the left."));
336 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
338 int notebook_page
= 0;
340 // The sizer for the whole top-level window.
341 wxSizer
*topWindowSizer
= new wxBoxSizer(wxVERTICAL
);
342 SetSizer(topWindowSizer
);
347 if (helpStyle
& (wxHF_TOOLBAR
| wxHF_FLAT_TOOLBAR
))
349 wxToolBar
*toolBar
= new wxToolBar(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
350 wxNO_BORDER
| wxTB_HORIZONTAL
|
351 wxTB_DOCKABLE
| wxTB_NODIVIDER
|
352 (helpStyle
& wxHF_FLAT_TOOLBAR
? wxTB_FLAT
: 0));
353 toolBar
->SetMargins( 2, 2 );
354 toolBar
->SetToolBitmapSize( wxSize(22,22) );
355 AddToolbarButtons(toolBar
, helpStyle
);
357 topWindowSizer
->Add(toolBar
, 0, wxEXPAND
);
360 #endif //wxUSE_TOOLBAR
362 wxSizer
*navigSizer
= NULL
;
365 wxBorder htmlWindowBorder
= GetDefaultBorder();
366 htmlWindowBorder
= wxBORDER_THEME
;
368 wxBorder htmlWindowBorder
= wxBORDER_SUNKEN
;
371 if (helpStyle
& (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 long splitterStyle
= wxSP_3D
;
376 // Drawing moving sash can cause problems on wxMac
378 splitterStyle
|= wxSP_LIVE_UPDATE
;
380 m_Splitter
= new wxSplitterWindow(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, splitterStyle
);
382 topWindowSizer
->Add(m_Splitter
, 1, wxEXPAND
);
384 m_HtmlWin
= new wxHtmlHelpHtmlWindow(this, m_Splitter
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxHW_DEFAULT_STYLE
|htmlWindowBorder
);
385 m_NavigPan
= new wxPanel(m_Splitter
, wxID_ANY
);
386 m_NavigNotebook
= new wxNotebook(m_NavigPan
, wxID_HTML_NOTEBOOK
,
387 wxDefaultPosition
, wxDefaultSize
);
389 m_NavigNotebook
->SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
392 navigSizer
= new wxBoxSizer(wxVERTICAL
);
393 navigSizer
->Add(m_NavigNotebook
, 1, wxEXPAND
);
395 m_NavigPan
->SetSizer(navigSizer
);
399 // only html window, no notebook with index,contents etc
400 m_HtmlWin
= new wxHtmlWindow(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxHW_DEFAULT_STYLE
|htmlWindowBorder
);
401 topWindowSizer
->Add(m_HtmlWin
, 1, wxEXPAND
);
406 m_HtmlWin
->ReadCustomization(m_Config
, m_ConfigRoot
);
407 #endif // wxUSE_CONFIG
409 // contents tree panel?
410 if ( helpStyle
& wxHF_CONTENTS
)
412 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
414 dummy
->SetWindowVariant(wxWINDOW_VARIANT_NORMAL
);
416 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
418 topsizer
->Add(0, 10);
420 dummy
->SetSizer(topsizer
);
422 if ( helpStyle
& wxHF_BOOKMARKS
)
424 long comboStyle
= wxCB_READONLY
;
426 // Not supported on OSX/Cocoa presently
427 comboStyle
|= wxCB_SORT
;
430 m_Bookmarks
= new wxComboBox(dummy
, wxID_HTML_BOOKMARKSLIST
,
432 wxDefaultPosition
, wxDefaultSize
,
433 0, NULL
, comboStyle
);
434 m_Bookmarks
->Append(_("(bookmarks)"));
435 for (unsigned i
= 0; i
< m_BookmarksNames
.GetCount(); i
++)
436 m_Bookmarks
->Append(m_BookmarksNames
[i
]);
437 m_Bookmarks
->SetSelection(0);
439 wxBitmapButton
*bmpbt1
, *bmpbt2
;
440 bmpbt1
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSADD
,
441 wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK
,
443 bmpbt2
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSREMOVE
,
444 wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK
,
447 bmpbt1
->SetToolTip(_("Add current page to bookmarks"));
448 bmpbt2
->SetToolTip(_("Remove current page from bookmarks"));
449 #endif // wxUSE_TOOLTIPS
451 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
453 sizer
->Add(m_Bookmarks
, 1, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 5);
454 sizer
->Add(bmpbt1
, 0, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 2);
455 sizer
->Add(bmpbt2
, 0, wxALIGN_CENTRE_VERTICAL
, 0);
457 topsizer
->Add(sizer
, 0, wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
, 10);
460 m_ContentsBox
= new wxTreeCtrl(dummy
, wxID_HTML_TREECTRL
,
461 wxDefaultPosition
, wxDefaultSize
,
462 #if defined(__WXGTK20__) || defined(__WXMAC__)
464 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
468 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
473 wxImageList
*ContentsImageList
= new wxImageList(16, 16);
474 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK
,
477 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER
,
480 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE
,
484 m_ContentsBox
->AssignImageList(ContentsImageList
);
486 topsizer
->Add(m_ContentsBox
, 1,
487 wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
,
490 m_NavigNotebook
->AddPage(dummy
, _("Contents"));
491 m_ContentsPage
= notebook_page
++;
494 // index listbox panel?
495 if ( helpStyle
& wxHF_INDEX
)
497 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
499 dummy
->SetWindowVariant(wxWINDOW_VARIANT_NORMAL
);
501 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
503 dummy
->SetSizer(topsizer
);
505 m_IndexText
= new wxTextCtrl(dummy
, wxID_HTML_INDEXTEXT
, wxEmptyString
,
506 wxDefaultPosition
, wxDefaultSize
,
508 m_IndexButton
= new wxButton(dummy
, wxID_HTML_INDEXBUTTON
, _("Find"));
509 m_IndexButtonAll
= new wxButton(dummy
, wxID_HTML_INDEXBUTTONALL
,
511 m_IndexCountInfo
= new wxStaticText(dummy
, wxID_HTML_COUNTINFO
,
512 wxEmptyString
, wxDefaultPosition
,
514 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
515 m_IndexList
= new wxListBox(dummy
, wxID_HTML_INDEXLIST
,
516 wxDefaultPosition
, wxDefaultSize
,
517 0, NULL
, wxLB_SINGLE
);
520 m_IndexButton
->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
521 m_IndexButtonAll
->SetToolTip(_("Show all items in index"));
522 #endif //wxUSE_TOOLTIPS
524 topsizer
->Add(m_IndexText
, 0, wxEXPAND
| wxALL
, 10);
525 wxSizer
*btsizer
= new wxBoxSizer(wxHORIZONTAL
);
526 btsizer
->Add(m_IndexButton
, 0, wxRIGHT
, 2);
527 btsizer
->Add(m_IndexButtonAll
);
528 topsizer
->Add(btsizer
, 0,
529 wxALIGN_RIGHT
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
530 topsizer
->Add(m_IndexCountInfo
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 2);
531 topsizer
->Add(m_IndexList
, 1, wxEXPAND
| wxALL
, 2);
533 m_NavigNotebook
->AddPage(dummy
, _("Index"));
534 m_IndexPage
= notebook_page
++;
537 // search list panel?
538 if ( helpStyle
& wxHF_SEARCH
)
540 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
542 dummy
->SetWindowVariant(wxWINDOW_VARIANT_NORMAL
);
544 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
546 dummy
->SetSizer(sizer
);
548 m_SearchText
= new wxTextCtrl(dummy
, wxID_HTML_SEARCHTEXT
,
550 wxDefaultPosition
, wxDefaultSize
,
552 m_SearchChoice
= new wxChoice(dummy
, wxID_HTML_SEARCHCHOICE
,
553 wxDefaultPosition
, wxSize(125,wxDefaultCoord
));
554 m_SearchCaseSensitive
= new wxCheckBox(dummy
, wxID_ANY
, _("Case sensitive"));
555 m_SearchWholeWords
= new wxCheckBox(dummy
, wxID_ANY
, _("Whole words only"));
556 m_SearchButton
= new wxButton(dummy
, wxID_HTML_SEARCHBUTTON
, _("Search"));
558 m_SearchButton
->SetToolTip(_("Search contents of help book(s) for all occurrences of the text you typed above"));
559 #endif //wxUSE_TOOLTIPS
560 m_SearchList
= new wxListBox(dummy
, wxID_HTML_SEARCHLIST
,
561 wxDefaultPosition
, wxDefaultSize
,
562 0, NULL
, wxLB_SINGLE
);
564 sizer
->Add(m_SearchText
, 0, wxEXPAND
| wxALL
, 10);
565 sizer
->Add(m_SearchChoice
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
566 sizer
->Add(m_SearchCaseSensitive
, 0, wxLEFT
| wxRIGHT
, 10);
567 sizer
->Add(m_SearchWholeWords
, 0, wxLEFT
| wxRIGHT
, 10);
568 sizer
->Add(m_SearchButton
, 0, wxALL
| wxALIGN_RIGHT
, 8);
569 sizer
->Add(m_SearchList
, 1, wxALL
| wxEXPAND
, 2);
571 m_NavigNotebook
->AddPage(dummy
, _("Search"));
572 m_SearchPage
= notebook_page
;
581 navigSizer
->SetSizeHints(m_NavigPan
);
582 m_NavigPan
->Layout();
586 if ( m_NavigPan
&& m_Splitter
)
588 // The panel will have its own min size which the splitter
591 // m_Splitter->SetMinimumPaneSize(m_NavigPan->GetBestSize().x);
593 m_Splitter
->SetMinimumPaneSize(20);
595 if ( m_Cfg
.navig_on
)
598 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
602 m_NavigPan
->Show(false);
603 m_Splitter
->Initialize(m_HtmlWin
);
607 // Reduce flicker by updating the splitter pane sizes before the
609 wxSizeEvent
sizeEvent(GetSize(), GetId());
610 GetEventHandler()->ProcessEvent(sizeEvent
);
613 m_Splitter
->UpdateSize();
618 wxHtmlHelpWindow::~wxHtmlHelpWindow()
620 if ( m_helpController
)
621 m_helpController
->SetHelpWindow(NULL
);
623 delete m_mergedIndex
;
625 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
628 if (m_NormalFonts
) delete m_NormalFonts
;
629 if (m_FixedFonts
) delete m_FixedFonts
;
632 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
635 #if wxUSE_PRINTING_ARCHITECTURE
636 if (m_Printer
) delete m_Printer
;
640 void wxHtmlHelpWindow::SetController(wxHtmlHelpController
* controller
)
644 m_helpController
= controller
;
645 m_Data
= controller
->GetHelpData();
646 m_DataCreated
= false;
650 void wxHtmlHelpWindow::AddToolbarButtons(wxToolBar
*toolBar
, int style
)
652 wxBitmap wpanelBitmap
=
653 wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL
, wxART_TOOLBAR
);
654 wxBitmap wbackBitmap
=
655 wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_TOOLBAR
);
656 wxBitmap wforwardBitmap
=
657 wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_TOOLBAR
);
658 wxBitmap wupnodeBitmap
=
659 wxArtProvider::GetBitmap(wxART_GO_TO_PARENT
, wxART_TOOLBAR
);
661 wxArtProvider::GetBitmap(wxART_GO_UP
, wxART_TOOLBAR
);
662 wxBitmap wdownBitmap
=
663 wxArtProvider::GetBitmap(wxART_GO_DOWN
, wxART_TOOLBAR
);
664 wxBitmap wopenBitmap
=
665 wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_TOOLBAR
);
666 wxBitmap wprintBitmap
=
667 wxArtProvider::GetBitmap(wxART_PRINT
, wxART_TOOLBAR
);
668 wxBitmap woptionsBitmap
=
669 wxArtProvider::GetBitmap(wxART_HELP_SETTINGS
, wxART_TOOLBAR
);
671 wxASSERT_MSG( (wpanelBitmap
.IsOk() && wbackBitmap
.IsOk() &&
672 wforwardBitmap
.IsOk() && wupnodeBitmap
.IsOk() &&
673 wupBitmap
.IsOk() && wdownBitmap
.IsOk() &&
674 wopenBitmap
.IsOk() && wprintBitmap
.IsOk() &&
675 woptionsBitmap
.IsOk()),
676 wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
679 toolBar
->AddTool(wxID_HTML_PANEL
, wxEmptyString
, wpanelBitmap
, _("Show/hide navigation panel"));
680 toolBar
->AddSeparator();
681 toolBar
->AddTool(wxID_HTML_BACK
, wxEmptyString
, wbackBitmap
, _("Go back"));
682 toolBar
->AddTool(wxID_HTML_FORWARD
, wxEmptyString
, wforwardBitmap
, _("Go forward"));
683 toolBar
->AddSeparator();
684 toolBar
->AddTool(wxID_HTML_UPNODE
, wxEmptyString
, wupnodeBitmap
, _("Go one level up in document hierarchy"));
685 toolBar
->AddTool(wxID_HTML_UP
, wxEmptyString
, wupBitmap
, _("Previous page"));
686 toolBar
->AddTool(wxID_HTML_DOWN
, wxEmptyString
, wdownBitmap
, _("Next page"));
688 if ((style
& wxHF_PRINT
) || (style
& wxHF_OPEN_FILES
))
689 toolBar
->AddSeparator();
691 if (style
& wxHF_OPEN_FILES
)
692 toolBar
->AddTool(wxID_HTML_OPENFILE
, wxEmptyString
, wopenBitmap
, _("Open HTML document"));
694 #if wxUSE_PRINTING_ARCHITECTURE
695 if (style
& wxHF_PRINT
)
696 toolBar
->AddTool(wxID_HTML_PRINT
, wxEmptyString
, wprintBitmap
, _("Print this page"));
699 toolBar
->AddSeparator();
700 toolBar
->AddTool(wxID_HTML_OPTIONS
, wxEmptyString
, woptionsBitmap
, _("Display options dialog"));
702 // Allow application to add custom buttons
703 wxHtmlHelpFrame
* parentFrame
= wxDynamicCast(GetParent(), wxHtmlHelpFrame
);
704 wxHtmlHelpDialog
* parentDialog
= wxDynamicCast(GetParent(), wxHtmlHelpDialog
);
706 parentFrame
->AddToolbarButtons(toolBar
, style
);
708 parentDialog
->AddToolbarButtons(toolBar
, style
);
710 #endif //wxUSE_TOOLBAR
713 bool wxHtmlHelpWindow::Display(const wxString
& x
)
715 wxString url
= m_Data
->FindPageByName(x
);
718 m_HtmlWin
->LoadPage(url
);
726 bool wxHtmlHelpWindow::Display(const int id
)
728 wxString url
= m_Data
->FindPageById(id
);
731 m_HtmlWin
->LoadPage(url
);
739 bool wxHtmlHelpWindow::DisplayContents()
744 if (!m_Splitter
->IsSplit())
748 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
749 m_Cfg
.navig_on
= true;
752 m_NavigNotebook
->SetSelection(m_ContentsPage
);
754 if (m_Data
->GetBookRecArray().GetCount() > 0)
756 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
757 if (!book
.GetStart().empty())
758 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
764 bool wxHtmlHelpWindow::DisplayIndex()
769 if (!m_Splitter
->IsSplit())
773 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
776 m_NavigNotebook
->SetSelection(m_IndexPage
);
778 if (m_Data
->GetBookRecArray().GetCount() > 0)
780 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
781 if (!book
.GetStart().empty())
782 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
788 void wxHtmlHelpWindow::DisplayIndexItem(const wxHtmlHelpMergedIndexItem
*it
)
790 if (it
->items
.size() == 1)
792 if (!it
->items
[0]->page
.empty())
794 m_HtmlWin
->LoadPage(it
->items
[0]->GetFullPath());
800 wxBusyCursor busy_cursor
;
802 // more pages associated with this index item -- let the user choose
803 // which one she/he wants from a list:
805 size_t len
= it
->items
.size();
806 for (size_t i
= 0; i
< len
; i
++)
808 wxString page
= it
->items
[i
]->page
;
809 // try to find page's title in contents:
810 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
811 size_t clen
= contents
.size();
812 for (size_t j
= 0; j
< clen
; j
++)
814 if (contents
[j
].page
== page
)
816 page
= contents
[j
].name
;
823 wxSingleChoiceDialog
dlg(this,
824 _("Please choose the page to display:"),
827 (void**)NULL
, // No client data
828 wxCHOICEDLG_STYLE
& ~wxCENTRE
);
829 if (dlg
.ShowModal() == wxID_OK
)
831 m_HtmlWin
->LoadPage(it
->items
[dlg
.GetSelection()]->GetFullPath());
837 bool wxHtmlHelpWindow::KeywordSearch(const wxString
& keyword
,
838 wxHelpSearchMode mode
)
840 wxCHECK_MSG( !keyword
.empty(), false, "must have a non empty keyword" );
842 if (mode
== wxHELP_SEARCH_ALL
)
844 if ( !(m_SearchList
&&
845 m_SearchButton
&& m_SearchText
&& m_SearchChoice
) )
848 else if (mode
== wxHELP_SEARCH_INDEX
)
850 if ( !(m_IndexList
&&
851 m_IndexButton
&& m_IndexButtonAll
&& m_IndexText
) )
857 wxString book
= wxEmptyString
;
859 if (!m_Splitter
->IsSplit())
863 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
866 if (mode
== wxHELP_SEARCH_ALL
)
868 m_NavigNotebook
->SetSelection(m_SearchPage
);
869 m_SearchList
->Clear();
870 m_SearchText
->SetValue(keyword
);
871 m_SearchButton
->Disable();
873 if (m_SearchChoice
->GetSelection() != 0)
874 book
= m_SearchChoice
->GetStringSelection();
876 wxHtmlSearchStatus
status(m_Data
, keyword
,
877 m_SearchCaseSensitive
->GetValue(),
878 m_SearchWholeWords
->GetValue(),
881 #if wxUSE_PROGRESSDLG
882 wxProgressDialog
progress(_("Searching..."),
883 _("No matching page found yet"),
884 status
.GetMaxIndex(), this,
885 wxPD_APP_MODAL
| wxPD_CAN_ABORT
| wxPD_AUTO_HIDE
);
889 while (status
.IsActive())
891 curi
= status
.GetCurIndex();
893 #if wxUSE_PROGRESSDLG
894 && !progress
.Update(curi
)
900 foundstr
.Printf(_("Found %i matches"), ++foundcnt
);
901 #if wxUSE_PROGRESSDLG
902 progress
.Update(status
.GetCurIndex(), foundstr
);
904 m_SearchList
->Append(status
.GetName(), (void*)status
.GetCurItem());
908 m_SearchButton
->Enable();
909 m_SearchText
->SetSelection(0, keyword
.length());
910 m_SearchText
->SetFocus();
912 else if (mode
== wxHELP_SEARCH_INDEX
)
914 m_NavigNotebook
->SetSelection(m_IndexPage
);
915 m_IndexList
->Clear();
916 m_IndexButton
->Disable();
917 m_IndexButtonAll
->Disable();
918 m_IndexText
->SetValue(keyword
);
921 m_IndexButton
->Enable();
922 m_IndexButtonAll
->Enable();
923 foundcnt
= m_IndexList
->GetCount();
931 wxFAIL_MSG( wxT("unknown help search mode") );
934 case wxHELP_SEARCH_ALL
:
936 wxHtmlHelpDataItem
*it
=
937 (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(0);
940 m_HtmlWin
->LoadPage(it
->GetFullPath());
946 case wxHELP_SEARCH_INDEX
:
948 wxHtmlHelpMergedIndexItem
* it
=
949 (wxHtmlHelpMergedIndexItem
*) m_IndexList
->GetClientData(0);
951 DisplayIndexItem(it
);
961 void wxHtmlHelpWindow::CreateContents()
968 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
972 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
974 size_t cnt
= contents
.size();
976 m_PagesHash
= new wxHashTable(wxKEY_STRING
, 2 * cnt
);
978 const int MAX_ROOTS
= 64;
979 wxTreeItemId roots
[MAX_ROOTS
];
980 // VS: this array holds information about whether we've set item icon at
981 // given level. This is necessary because m_Data has a flat structure
982 // and there's no way of recognizing if some item has subitems or not.
983 // We set the icon later: when we find an item with level=n, we know
984 // that the last item with level=n-1 was afolder with subitems, so we
985 // set its icon accordingly
986 bool imaged
[MAX_ROOTS
];
987 m_ContentsBox
->DeleteAllItems();
989 roots
[0] = m_ContentsBox
->AddRoot(_("(Help)"));
992 for (size_t i
= 0; i
< cnt
; i
++)
994 wxHtmlHelpDataItem
*it
= &contents
[i
];
998 if (m_hfStyle
& wxHF_MERGE_BOOKS
)
999 // VS: we don't want book nodes, books' content should
1000 // appear under tree's root. This line will create a "fake"
1001 // record about book node so that the rest of this look
1002 // will believe there really _is_ a book node and will
1003 // behave correctly.
1004 roots
[1] = roots
[0];
1007 roots
[1] = m_ContentsBox
->AppendItem(roots
[0],
1008 it
->name
, IMG_Book
, -1,
1009 new wxHtmlHelpTreeItemData(i
));
1010 m_ContentsBox
->SetItemBold(roots
[1], true);
1014 // ...and their contents:
1017 roots
[it
->level
+ 1] = m_ContentsBox
->AppendItem(
1018 roots
[it
->level
], it
->name
, IMG_Page
,
1019 -1, new wxHtmlHelpTreeItemData(i
));
1020 imaged
[it
->level
+ 1] = false;
1023 m_PagesHash
->Put(it
->GetFullPath(),
1024 new wxHtmlHelpHashData(i
, roots
[it
->level
+ 1]));
1026 // Set the icon for the node one level up in the hierarchy,
1027 // unless already done (see comment above imaged[] declaration)
1028 if (!imaged
[it
->level
])
1030 int image
= IMG_Folder
;
1031 if (m_hfStyle
& wxHF_ICONS_BOOK
)
1033 else if (m_hfStyle
& wxHF_ICONS_BOOK_CHAPTER
)
1034 image
= (it
->level
== 1) ? IMG_Book
: IMG_Folder
;
1035 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
);
1036 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
,
1037 wxTreeItemIcon_Selected
);
1038 imaged
[it
->level
] = true;
1042 m_ContentsBox
->SetMinSize(wxSize(CONTENT_TREE_INDEX_MIN_WIDTH
,
1043 m_ContentsBox
->GetMinHeight()));
1046 void wxHtmlHelpWindow::CreateIndex()
1051 m_IndexList
->Clear();
1053 unsigned long cnt
= m_mergedIndex
->size();
1056 if (cnt
> INDEX_IS_SMALL
)
1057 cnttext
.Printf(_("%d of %lu"), 0, cnt
);
1059 cnttext
.Printf(_("%lu of %lu"), cnt
, cnt
);
1060 m_IndexCountInfo
->SetLabel(cnttext
);
1061 if (cnt
> INDEX_IS_SMALL
)
1064 for (size_t i
= 0; i
< cnt
; i
++)
1065 m_IndexList
->Append((*m_mergedIndex
)[i
].name
,
1066 (char*)(&(*m_mergedIndex
)[i
]));
1068 m_IndexList
->SetMinSize(wxSize(CONTENT_TREE_INDEX_MIN_WIDTH
,
1069 m_IndexList
->GetMinHeight()));
1072 void wxHtmlHelpWindow::CreateSearch()
1074 if (! (m_SearchList
&& m_SearchChoice
))
1076 m_SearchList
->Clear();
1077 m_SearchChoice
->Clear();
1078 m_SearchChoice
->Append(_("Search in all books"));
1079 const wxHtmlBookRecArray
& bookrec
= m_Data
->GetBookRecArray();
1080 int i
, cnt
= bookrec
.GetCount();
1081 for (i
= 0; i
< cnt
; i
++)
1082 m_SearchChoice
->Append(bookrec
[i
].GetTitle());
1083 m_SearchChoice
->SetSelection(0);
1086 void wxHtmlHelpWindow::RefreshLists()
1088 // Update m_mergedIndex:
1089 UpdateMergedIndex();
1090 // Update the controls
1097 void wxHtmlHelpWindow::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1102 if (path
!= wxEmptyString
)
1104 oldpath
= cfg
->GetPath();
1105 cfg
->SetPath(wxT("/") + path
);
1108 m_Cfg
.navig_on
= cfg
->Read(wxT("hcNavigPanel"), m_Cfg
.navig_on
) != 0;
1109 m_Cfg
.sashpos
= cfg
->Read(wxT("hcSashPos"), m_Cfg
.sashpos
);
1110 m_Cfg
.x
= cfg
->Read(wxT("hcX"), m_Cfg
.x
);
1111 m_Cfg
.y
= cfg
->Read(wxT("hcY"), m_Cfg
.y
);
1112 m_Cfg
.w
= cfg
->Read(wxT("hcW"), m_Cfg
.w
);
1113 m_Cfg
.h
= cfg
->Read(wxT("hcH"), m_Cfg
.h
);
1115 m_FixedFace
= cfg
->Read(wxT("hcFixedFace"), m_FixedFace
);
1116 m_NormalFace
= cfg
->Read(wxT("hcNormalFace"), m_NormalFace
);
1117 m_FontSize
= cfg
->Read(wxT("hcBaseFontSize"), m_FontSize
);
1124 cnt
= cfg
->Read(wxT("hcBookmarksCnt"), 0L);
1127 m_BookmarksNames
.Clear();
1128 m_BookmarksPages
.Clear();
1131 m_Bookmarks
->Clear();
1132 m_Bookmarks
->Append(_("(bookmarks)"));
1135 for (i
= 0; i
< cnt
; i
++)
1137 val
.Printf(wxT("hcBookmark_%i"), i
);
1139 m_BookmarksNames
.Add(s
);
1140 if (m_Bookmarks
) m_Bookmarks
->Append(s
);
1141 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1143 m_BookmarksPages
.Add(s
);
1149 m_HtmlWin
->ReadCustomization(cfg
);
1151 if (path
!= wxEmptyString
)
1152 cfg
->SetPath(oldpath
);
1155 void wxHtmlHelpWindow::WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1160 if (path
!= wxEmptyString
)
1162 oldpath
= cfg
->GetPath();
1163 cfg
->SetPath(wxT("/") + path
);
1166 cfg
->Write(wxT("hcNavigPanel"), m_Cfg
.navig_on
);
1167 cfg
->Write(wxT("hcSashPos"), (long)m_Cfg
.sashpos
);
1169 // Don't write if iconized as this would make the window
1170 // disappear next time it is shown!
1171 cfg
->Write(wxT("hcX"), (long)m_Cfg
.x
);
1172 cfg
->Write(wxT("hcY"), (long)m_Cfg
.y
);
1173 cfg
->Write(wxT("hcW"), (long)m_Cfg
.w
);
1174 cfg
->Write(wxT("hcH"), (long)m_Cfg
.h
);
1176 cfg
->Write(wxT("hcFixedFace"), m_FixedFace
);
1177 cfg
->Write(wxT("hcNormalFace"), m_NormalFace
);
1178 cfg
->Write(wxT("hcBaseFontSize"), (long)m_FontSize
);
1183 int cnt
= m_BookmarksNames
.GetCount();
1186 cfg
->Write(wxT("hcBookmarksCnt"), (long)cnt
);
1187 for (i
= 0; i
< cnt
; i
++)
1189 val
.Printf(wxT("hcBookmark_%i"), i
);
1190 cfg
->Write(val
, m_BookmarksNames
[i
]);
1191 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1192 cfg
->Write(val
, m_BookmarksPages
[i
]);
1197 m_HtmlWin
->WriteCustomization(cfg
);
1199 if (path
!= wxEmptyString
)
1200 cfg
->SetPath(oldpath
);
1202 #endif // wxUSE_CONFIG
1204 static void SetFontsToHtmlWin(wxHtmlWindow
*win
, const wxString
& scalf
, const wxString
& fixf
, int size
)
1207 f_sizes
[0] = int(size
* 0.6);
1208 f_sizes
[1] = int(size
* 0.8);
1210 f_sizes
[3] = int(size
* 1.2);
1211 f_sizes
[4] = int(size
* 1.4);
1212 f_sizes
[5] = int(size
* 1.6);
1213 f_sizes
[6] = int(size
* 1.8);
1215 win
->SetFonts(scalf
, fixf
, f_sizes
);
1218 class wxHtmlHelpWindowOptionsDialog
: public wxDialog
1221 wxComboBox
*NormalFont
, *FixedFont
;
1222 wxSpinCtrl
*FontSize
;
1223 wxHtmlWindow
*TestWin
;
1225 wxHtmlHelpWindowOptionsDialog(wxWindow
*parent
)
1226 : wxDialog(parent
, wxID_ANY
, wxString(_("Help Browser Options")))
1228 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
1229 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2, 3, 2, 5);
1231 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Normal font:")));
1232 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Fixed font:")));
1233 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Font size:")));
1235 sizer
->Add(NormalFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1236 wxSize(200, wxDefaultCoord
),
1237 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1239 sizer
->Add(FixedFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1240 wxSize(200, wxDefaultCoord
),
1241 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1243 sizer
->Add(FontSize
= new wxSpinCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1244 wxDefaultSize
, wxSP_ARROW_KEYS
, 2, 100, 2, wxT("wxSpinCtrl")));
1246 topsizer
->Add(sizer
, 0, wxLEFT
|wxRIGHT
|wxTOP
, 10);
1248 topsizer
->Add(new wxStaticText(this, wxID_ANY
, _("Preview:")),
1249 0, wxLEFT
| wxTOP
, 10);
1251 topsizer
->AddSpacer(5);
1253 topsizer
->Add(TestWin
= new wxHtmlWindow(this, wxID_ANY
, wxDefaultPosition
, wxSize(20, 150),
1254 wxHW_SCROLLBAR_AUTO
|wxBORDER_THEME
),
1255 1, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
1257 wxBoxSizer
*sizer2
= new wxBoxSizer(wxHORIZONTAL
);
1259 sizer2
->Add(ok
= new wxButton(this, wxID_OK
), 0, wxALL
, 10);
1261 sizer2
->Add(new wxButton(this, wxID_CANCEL
), 0, wxALL
, 10);
1262 topsizer
->Add(sizer2
, 0, wxALIGN_RIGHT
);
1265 topsizer
->Fit(this);
1270 void UpdateTestWin()
1273 SetFontsToHtmlWin(TestWin
,
1274 NormalFont
->GetStringSelection(),
1275 FixedFont
->GetStringSelection(),
1276 FontSize
->GetValue());
1278 wxString
content(_("font size"));
1280 content
= wxT("<font size=-2>") + content
+ wxT(" -2</font><br>")
1281 wxT("<font size=-1>") + content
+ wxT(" -1</font><br>")
1282 wxT("<font size=+0>") + content
+ wxT(" +0</font><br>")
1283 wxT("<font size=+1>") + content
+ wxT(" +1</font><br>")
1284 wxT("<font size=+2>") + content
+ wxT(" +2</font><br>")
1285 wxT("<font size=+3>") + content
+ wxT(" +3</font><br>")
1286 wxT("<font size=+4>") + content
+ wxT(" +4</font><br>") ;
1288 content
= wxString( wxT("<html><body><table><tr><td>") ) +
1289 _("Normal face<br>and <u>underlined</u>. ") +
1290 _("<i>Italic face.</i> ") +
1291 _("<b>Bold face.</b> ") +
1292 _("<b><i>Bold italic face.</i></b><br>") +
1294 wxString( wxT("</td><td><tt>") ) +
1295 _("Fixed size face.<br> <b>bold</b> <i>italic</i> ") +
1296 _("<b><i>bold italic <u>underlined</u></i></b><br>") +
1298 wxT("</tt></td></tr></table></body></html>");
1300 TestWin
->SetPage( content
);
1303 void OnUpdate(wxCommandEvent
& WXUNUSED(event
))
1307 void OnUpdateSpin(wxSpinEvent
& WXUNUSED(event
))
1312 DECLARE_EVENT_TABLE()
1313 wxDECLARE_NO_COPY_CLASS(wxHtmlHelpWindowOptionsDialog
);
1316 BEGIN_EVENT_TABLE(wxHtmlHelpWindowOptionsDialog
, wxDialog
)
1317 EVT_COMBOBOX(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdate
)
1318 EVT_SPINCTRL(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdateSpin
)
1321 void wxHtmlHelpWindow::OptionsDialog()
1323 wxHtmlHelpWindowOptionsDialog
dlg(this);
1326 if (m_NormalFonts
== NULL
)
1328 m_NormalFonts
= new wxArrayString(wxFontEnumerator::GetFacenames());
1329 m_NormalFonts
->Sort(); // ascending sort
1331 if (m_FixedFonts
== NULL
)
1333 m_FixedFonts
= new wxArrayString(
1334 wxFontEnumerator::GetFacenames(wxFONTENCODING_SYSTEM
,
1335 true /*enum fixed width only*/));
1336 m_FixedFonts
->Sort(); // ascending sort
1339 // VS: We want to show the font that is actually used by wxHtmlWindow.
1340 // If customization dialog wasn't used yet, facenames are empty and
1341 // wxHtmlWindow uses default fonts -- let's find out what they
1342 // are so that we can pass them to the dialog:
1343 if (m_NormalFace
.empty())
1345 wxFont
fnt(m_FontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false);
1346 m_NormalFace
= fnt
.GetFaceName();
1348 if (m_FixedFace
.empty())
1350 wxFont
fnt(m_FontSize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false);
1351 m_FixedFace
= fnt
.GetFaceName();
1354 for (i
= 0; i
< m_NormalFonts
->GetCount(); i
++)
1355 dlg
.NormalFont
->Append((*m_NormalFonts
)[i
]);
1356 for (i
= 0; i
< m_FixedFonts
->GetCount(); i
++)
1357 dlg
.FixedFont
->Append((*m_FixedFonts
)[i
]);
1358 if (!m_NormalFace
.empty())
1359 dlg
.NormalFont
->SetStringSelection(m_NormalFace
);
1361 dlg
.NormalFont
->SetSelection(0);
1362 if (!m_FixedFace
.empty())
1363 dlg
.FixedFont
->SetStringSelection(m_FixedFace
);
1365 dlg
.FixedFont
->SetSelection(0);
1366 dlg
.FontSize
->SetValue(m_FontSize
);
1367 dlg
.UpdateTestWin();
1369 if (dlg
.ShowModal() == wxID_OK
)
1371 m_NormalFace
= dlg
.NormalFont
->GetStringSelection();
1372 m_FixedFace
= dlg
.FixedFont
->GetStringSelection();
1373 m_FontSize
= dlg
.FontSize
->GetValue();
1374 SetFontsToHtmlWin(m_HtmlWin
, m_NormalFace
, m_FixedFace
, m_FontSize
);
1378 void wxHtmlHelpWindow::NotifyPageChanged()
1380 if (m_UpdateContents
&& m_PagesHash
)
1382 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1383 wxHtmlHelpHashData
*ha
= NULL
;
1385 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1389 bool olduc
= m_UpdateContents
;
1390 m_UpdateContents
= false;
1391 m_ContentsBox
->SelectItem(ha
->m_Id
);
1392 m_ContentsBox
->EnsureVisible(ha
->m_Id
);
1393 m_UpdateContents
= olduc
;
1403 void wxHtmlHelpWindow::OnToolbar(wxCommandEvent
& event
)
1405 switch (event
.GetId())
1407 case wxID_HTML_BACK
:
1408 m_HtmlWin
->HistoryBack();
1409 NotifyPageChanged();
1412 case wxID_HTML_FORWARD
:
1413 m_HtmlWin
->HistoryForward();
1414 NotifyPageChanged();
1420 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1421 wxHtmlHelpHashData
*ha
= NULL
;
1423 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1424 if (ha
&& ha
->m_Index
> 0)
1426 const wxHtmlHelpDataItem
& it
= m_Data
->GetContentsArray()[ha
->m_Index
- 1];
1427 if (!it
.page
.empty())
1429 m_HtmlWin
->LoadPage(it
.GetFullPath());
1430 NotifyPageChanged();
1436 case wxID_HTML_UPNODE
:
1439 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1440 wxHtmlHelpHashData
*ha
= NULL
;
1442 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1443 if (ha
&& ha
->m_Index
> 0)
1446 m_Data
->GetContentsArray()[ha
->m_Index
].level
- 1;
1447 int ind
= ha
->m_Index
- 1;
1449 const wxHtmlHelpDataItem
*it
=
1450 &m_Data
->GetContentsArray()[ind
];
1451 while (ind
>= 0 && it
->level
!= level
)
1454 it
= &m_Data
->GetContentsArray()[ind
];
1458 if (!it
->page
.empty())
1460 m_HtmlWin
->LoadPage(it
->GetFullPath());
1461 NotifyPageChanged();
1468 case wxID_HTML_DOWN
:
1471 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1472 wxHtmlHelpHashData
*ha
= NULL
;
1474 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1476 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1477 if (ha
&& ha
->m_Index
< (int)contents
.size() - 1)
1479 size_t idx
= ha
->m_Index
+ 1;
1481 while (contents
[idx
].GetFullPath() == page
) idx
++;
1483 if (!contents
[idx
].page
.empty())
1485 m_HtmlWin
->LoadPage(contents
[idx
].GetFullPath());
1486 NotifyPageChanged();
1492 case wxID_HTML_PANEL
:
1494 if (! (m_Splitter
&& m_NavigPan
))
1496 if (m_Splitter
->IsSplit())
1498 m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1499 m_Splitter
->Unsplit(m_NavigPan
);
1500 m_Cfg
.navig_on
= false;
1506 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
1507 m_Cfg
.navig_on
= true;
1512 case wxID_HTML_OPTIONS
:
1516 case wxID_HTML_BOOKMARKSADD
:
1521 item
= m_HtmlWin
->GetOpenedPageTitle();
1522 url
= m_HtmlWin
->GetOpenedPage();
1523 if (item
== wxEmptyString
)
1524 item
= url
.AfterLast(wxT('/'));
1525 if (m_BookmarksPages
.Index(url
) == wxNOT_FOUND
)
1527 m_Bookmarks
->Append(item
);
1528 m_BookmarksNames
.Add(item
);
1529 m_BookmarksPages
.Add(url
);
1534 case wxID_HTML_BOOKMARKSREMOVE
:
1539 item
= m_Bookmarks
->GetStringSelection();
1540 pos
= m_BookmarksNames
.Index(item
);
1541 if (pos
!= wxNOT_FOUND
)
1543 m_BookmarksNames
.RemoveAt(pos
);
1544 m_BookmarksPages
.RemoveAt(pos
);
1545 pos
= m_Bookmarks
->GetSelection();
1546 wxASSERT_MSG( pos
!= wxNOT_FOUND
, wxT("Unknown bookmark position") ) ;
1547 m_Bookmarks
->Delete((unsigned int)pos
);
1552 #if wxUSE_PRINTING_ARCHITECTURE
1553 case wxID_HTML_PRINT
:
1555 if (m_Printer
== NULL
)
1556 m_Printer
= new wxHtmlEasyPrinting(_("Help Printing"), this);
1557 if (!m_HtmlWin
->GetOpenedPage())
1559 wxLogWarning(_("Cannot print empty page."));
1563 m_Printer
->PrintFile(m_HtmlWin
->GetOpenedPage());
1569 case wxID_HTML_OPENFILE
:
1571 wxString filemask
= wxString(
1572 _("HTML files (*.html;*.htm)|*.html;*.htm|")) +
1573 _("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|") +
1574 _("HTML Help Project (*.hhp)|*.hhp|") +
1576 _("Compressed HTML Help file (*.chm)|*.chm|") +
1579 wxString s
= wxFileSelector(_("Open HTML document"),
1584 wxFD_OPEN
| wxFD_FILE_MUST_EXIST
,
1588 wxString ext
= s
.Right(4).Lower();
1589 if (ext
== wxT(".zip") || ext
== wxT(".htb") ||
1591 ext
== wxT(".chm") ||
1600 m_HtmlWin
->LoadPage(s
);
1607 void wxHtmlHelpWindow::OnContentsSel(wxTreeEvent
& event
)
1609 wxHtmlHelpTreeItemData
*pg
;
1611 pg
= (wxHtmlHelpTreeItemData
*) m_ContentsBox
->GetItemData(event
.GetItem());
1613 if (pg
&& m_UpdateContents
)
1615 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1616 m_UpdateContents
= false;
1617 if (!contents
[pg
->m_Id
].page
.empty())
1618 m_HtmlWin
->LoadPage(contents
[pg
->m_Id
].GetFullPath());
1619 m_UpdateContents
= true;
1623 void wxHtmlHelpWindow::OnIndexSel(wxCommandEvent
& WXUNUSED(event
))
1625 wxHtmlHelpMergedIndexItem
*it
= (wxHtmlHelpMergedIndexItem
*)
1626 m_IndexList
->GetClientData(m_IndexList
->GetSelection());
1628 DisplayIndexItem(it
);
1631 void wxHtmlHelpWindow::OnIndexFind(wxCommandEvent
& WXUNUSED(event
))
1636 void wxHtmlHelpWindow::DoIndexFind()
1638 wxString sr
= m_IndexText
->GetLineText(0);
1640 if (sr
== wxEmptyString
)
1648 m_IndexList
->Clear();
1649 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1650 size_t cnt
= index
.size();
1653 for (size_t i
= 0; i
< cnt
; i
++)
1655 if (index
[i
].name
.Lower().find(sr
) != wxString::npos
)
1657 int pos
= m_IndexList
->Append(index
[i
].name
,
1658 (char*)(&index
[i
]));
1662 // don't automatically show topic selector if this
1663 // item points to multiple pages:
1664 if (index
[i
].items
.size() == 1)
1666 m_IndexList
->SetSelection(0);
1667 DisplayIndexItem(&index
[i
]);
1671 // if this is nested item of the index, show its parent(s)
1672 // as well, otherwise it would not be clear what entry is
1674 wxHtmlHelpMergedIndexItem
*parent
= index
[i
].parent
;
1678 (index
.Index(*(wxHtmlHelpMergedIndexItem
*)m_IndexList
->GetClientData(pos
-1))) < index
.Index(*parent
))
1680 m_IndexList
->Insert(parent
->name
,
1681 pos
, (char*)parent
);
1682 parent
= parent
->parent
;
1687 // finally, it the item we just added is itself a parent for
1688 // other items, show them as well, because they are refinements
1689 // of the displayed index entry (i.e. it is implicitly contained
1690 // in them: "foo" with parent "bar" reads as "bar, foo"):
1691 int level
= index
[i
].items
[0]->level
;
1693 while (i
< cnt
&& index
[i
].items
[0]->level
> level
)
1695 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1703 cnttext
.Printf(_("%i of %i"), displ
, cnt
);
1704 m_IndexCountInfo
->SetLabel(cnttext
);
1706 m_IndexText
->SetSelection(0, sr
.length());
1707 m_IndexText
->SetFocus();
1711 void wxHtmlHelpWindow::OnIndexAll(wxCommandEvent
& WXUNUSED(event
))
1716 void wxHtmlHelpWindow::DoIndexAll()
1720 m_IndexList
->Clear();
1721 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1722 size_t cnt
= index
.size();
1725 for (size_t i
= 0; i
< cnt
; i
++)
1727 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1730 // don't automatically show topic selector if this
1731 // item points to multiple pages:
1732 if (index
[i
].items
.size() == 1)
1734 DisplayIndexItem(&index
[i
]);
1741 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1742 m_IndexCountInfo
->SetLabel(cnttext
);
1745 void wxHtmlHelpWindow::OnSearchSel(wxCommandEvent
& WXUNUSED(event
))
1747 wxHtmlHelpDataItem
*it
= (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(m_SearchList
->GetSelection());
1750 if (!it
->page
.empty())
1751 m_HtmlWin
->LoadPage(it
->GetFullPath());
1752 NotifyPageChanged();
1756 void wxHtmlHelpWindow::OnSearch(wxCommandEvent
& WXUNUSED(event
))
1758 wxString sr
= m_SearchText
->GetLineText(0);
1761 KeywordSearch(sr
, wxHELP_SEARCH_ALL
);
1764 void wxHtmlHelpWindow::OnBookmarksSel(wxCommandEvent
& WXUNUSED(event
))
1766 wxString str
= m_Bookmarks
->GetStringSelection();
1767 int idx
= m_BookmarksNames
.Index(str
);
1768 if (!str
.empty() && str
!= _("(bookmarks)") && idx
!= wxNOT_FOUND
)
1770 m_HtmlWin
->LoadPage(m_BookmarksPages
[(size_t)idx
]);
1771 NotifyPageChanged();
1775 void wxHtmlHelpWindow::OnSize(wxSizeEvent
& WXUNUSED(event
))
1780 #endif // wxUSE_WXHTML_HELP