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
7 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h"
13 #include "wx/wxprec.h"
22 #include "wx/object.h"
23 #include "wx/dynarray.h"
27 #include "wx/stream.h"
32 #include "wx/bmpbuttn.h"
33 #include "wx/statbox.h"
34 #include "wx/radiobox.h"
36 #include "wx/settings.h"
37 #include "wx/msgdlg.h"
38 #include "wx/textctrl.h"
39 #include "wx/toolbar.h"
40 #include "wx/choicdlg.h"
41 #include "wx/filedlg.h"
44 #include "wx/html/helpfrm.h"
45 #include "wx/html/helpdlg.h"
46 #include "wx/html/helpctrl.h"
47 #include "wx/notebook.h"
48 #include "wx/imaglist.h"
49 #include "wx/treectrl.h"
50 #include "wx/tokenzr.h"
51 #include "wx/wfstream.h"
52 #include "wx/html/htmlwin.h"
53 #include "wx/busyinfo.h"
54 #include "wx/progdlg.h"
55 #include "wx/fontenum.h"
56 #include "wx/artprov.h"
57 #include "wx/spinctrl.h"
59 // what is considered "small index"?
60 #define INDEX_IS_SMALL 1000
62 // minimum width for content tree and index
63 // (we cannot let minimum size be determined from content, else long titles
64 // make the help frame unusable)
65 const wxCoord CONTENT_TREE_INDEX_MIN_WIDTH
= 150;
67 /* Motif defines this as a macro */
72 //--------------------------------------------------------------------------
73 // wxHtmlHelpTreeItemData (private)
74 //--------------------------------------------------------------------------
76 class wxHtmlHelpTreeItemData
: public wxTreeItemData
79 #if defined(__VISAGECPP__)
80 // VA needs a default ctor for some reason....
81 wxHtmlHelpTreeItemData() : wxTreeItemData()
84 wxHtmlHelpTreeItemData(int id
) : wxTreeItemData()
91 //--------------------------------------------------------------------------
92 // wxHtmlHelpHashData (private)
93 //--------------------------------------------------------------------------
95 class wxHtmlHelpHashData
: public wxObject
98 wxHtmlHelpHashData(int index
, wxTreeItemId id
) : wxObject()
99 { m_Index
= index
; m_Id
= id
;}
100 virtual ~wxHtmlHelpHashData() {}
107 //--------------------------------------------------------------------------
108 // wxHtmlHelpHtmlWindow (private)
109 //--------------------------------------------------------------------------
112 class wxHtmlHelpHtmlWindow
: public wxHtmlWindow
115 wxHtmlHelpHtmlWindow(wxHtmlHelpWindow
*win
, wxWindow
*parent
, wxWindowID id
= wxID_ANY
,
116 const wxPoint
& pos
= wxDefaultPosition
, const wxSize
& sz
= wxDefaultSize
, long style
= wxHW_DEFAULT_STYLE
)
117 : wxHtmlWindow(parent
, id
, pos
, sz
, style
), m_Window(win
)
122 virtual bool LoadPage(const wxString
& location
)
124 if ( !wxHtmlWindow::LoadPage(location
) )
127 m_Window
->NotifyPageChanged();
131 // Returns full location with anchor (helper)
132 static wxString
GetOpenedPageWithAnchor(wxHtmlWindow
*win
)
135 return wxEmptyString
;
137 wxString an
= win
->GetOpenedAnchor();
138 wxString pg
= win
->GetOpenedPage();
141 pg
<< wxT("#") << an
;
147 wxHtmlHelpWindow
*m_Window
;
149 wxDECLARE_NO_COPY_CLASS(wxHtmlHelpHtmlWindow
);
153 //---------------------------------------------------------------------------
154 // wxHtmlHelpWindow::m_mergedIndex
155 //---------------------------------------------------------------------------
157 WX_DEFINE_ARRAY_PTR(const wxHtmlHelpDataItem
*, wxHtmlHelpDataItemPtrArray
);
159 struct wxHtmlHelpMergedIndexItem
161 wxHtmlHelpMergedIndexItem
*parent
;
163 wxHtmlHelpDataItemPtrArray items
;
166 WX_DECLARE_OBJARRAY(wxHtmlHelpMergedIndexItem
, wxHtmlHelpMergedIndex
);
167 #include "wx/arrimpl.cpp"
168 WX_DEFINE_OBJARRAY(wxHtmlHelpMergedIndex
)
170 void wxHtmlHelpWindow::UpdateMergedIndex()
172 delete m_mergedIndex
;
173 m_mergedIndex
= new wxHtmlHelpMergedIndex
;
174 wxHtmlHelpMergedIndex
& merged
= *m_mergedIndex
;
176 const wxHtmlHelpDataItems
& items
= m_Data
->GetIndexArray();
177 size_t len
= items
.size();
179 wxHtmlHelpMergedIndexItem
*history
[128] = {NULL
};
181 for (size_t i
= 0; i
< len
; i
++)
183 const wxHtmlHelpDataItem
& item
= items
[i
];
184 wxASSERT_MSG( item
.level
< 128, wxT("nested index entries too deep") );
186 if (history
[item
.level
] &&
187 history
[item
.level
]->items
[0]->name
== item
.name
)
189 // same index entry as previous one, update list of items
190 history
[item
.level
]->items
.Add(&item
);
195 wxHtmlHelpMergedIndexItem
*mi
= new wxHtmlHelpMergedIndexItem();
196 mi
->name
= item
.GetIndentedName();
197 mi
->items
.Add(&item
);
198 mi
->parent
= (item
.level
== 0) ? NULL
: history
[item
.level
- 1];
199 history
[item
.level
] = mi
;
205 //---------------------------------------------------------------------------
207 //---------------------------------------------------------------------------
209 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpWindow
, wxWindow
)
211 BEGIN_EVENT_TABLE(wxHtmlHelpWindow
, wxWindow
)
212 EVT_TOOL_RANGE(wxID_HTML_PANEL
, wxID_HTML_OPTIONS
, wxHtmlHelpWindow::OnToolbar
)
213 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE
, wxHtmlHelpWindow::OnToolbar
)
214 EVT_BUTTON(wxID_HTML_BOOKMARKSADD
, wxHtmlHelpWindow::OnToolbar
)
215 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL
, wxHtmlHelpWindow::OnContentsSel
)
216 EVT_LISTBOX(wxID_HTML_INDEXLIST
, wxHtmlHelpWindow::OnIndexSel
)
217 EVT_LISTBOX(wxID_HTML_SEARCHLIST
, wxHtmlHelpWindow::OnSearchSel
)
218 EVT_BUTTON(wxID_HTML_SEARCHBUTTON
, wxHtmlHelpWindow::OnSearch
)
219 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT
, wxHtmlHelpWindow::OnSearch
)
220 EVT_BUTTON(wxID_HTML_INDEXBUTTON
, wxHtmlHelpWindow::OnIndexFind
)
221 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT
, wxHtmlHelpWindow::OnIndexFind
)
222 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL
, wxHtmlHelpWindow::OnIndexAll
)
223 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST
, wxHtmlHelpWindow::OnBookmarksSel
)
224 EVT_SIZE(wxHtmlHelpWindow::OnSize
)
227 wxHtmlHelpWindow::wxHtmlHelpWindow(wxWindow
* parent
, wxWindowID id
,
230 int style
, int helpStyle
, wxHtmlHelpData
* data
)
233 Create(parent
, id
, pos
, size
, style
, helpStyle
);
236 void wxHtmlHelpWindow::Init(wxHtmlHelpData
* data
)
241 m_DataCreated
= false;
245 m_Data
= new wxHtmlHelpData();
246 m_DataCreated
= true;
253 m_ContentsBox
= NULL
;
255 m_IndexButton
= NULL
;
256 m_IndexButtonAll
= NULL
;
259 m_SearchButton
= NULL
;
261 m_SearchChoice
= NULL
;
262 m_IndexCountInfo
= NULL
;
265 m_NavigNotebook
= NULL
;
268 m_SearchCaseSensitive
= NULL
;
269 m_SearchWholeWords
= NULL
;
271 m_mergedIndex
= NULL
;
275 m_ConfigRoot
= wxEmptyString
;
276 #endif // wxUSE_CONFIG
278 m_Cfg
.x
= m_Cfg
.y
= wxDefaultCoord
;
282 m_Cfg
.navig_on
= true;
284 m_NormalFonts
= m_FixedFonts
= NULL
;
285 m_NormalFace
= m_FixedFace
= wxEmptyString
;
292 #if wxUSE_PRINTING_ARCHITECTURE
297 m_UpdateContents
= true;
299 m_helpController
= NULL
;
302 // Create: builds the GUI components.
303 // with the style flag it's possible to toggle the toolbar, contents, index and search
305 // m_HtmlWin will *always* be created, but it's important to realize that
306 // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
307 // m_SearchButton may be NULL.
308 // moreover, if no contents, index or searchpage is needed, m_Splitter and
309 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
311 bool wxHtmlHelpWindow::Create(wxWindow
* parent
, wxWindowID id
,
312 const wxPoint
& pos
, const wxSize
& size
,
313 int style
, int helpStyle
)
315 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
);
322 #endif // wxUSE_CONFIG
324 wxWindow::Create(parent
, id
, pos
, size
, style
, wxT("wxHtmlHelp"));
326 SetHelpText(_("Displays help as you browse the books on the left."));
328 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
330 int notebook_page
= 0;
332 // The sizer for the whole top-level window.
333 wxSizer
*topWindowSizer
= new wxBoxSizer(wxVERTICAL
);
334 SetSizer(topWindowSizer
);
339 if (helpStyle
& (wxHF_TOOLBAR
| wxHF_FLAT_TOOLBAR
))
341 wxToolBar
*toolBar
= new wxToolBar(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
342 wxNO_BORDER
| wxTB_HORIZONTAL
|
343 wxTB_DOCKABLE
| wxTB_NODIVIDER
|
344 (helpStyle
& wxHF_FLAT_TOOLBAR
? wxTB_FLAT
: 0));
345 toolBar
->SetMargins( 2, 2 );
346 toolBar
->SetToolBitmapSize( wxSize(22,22) );
347 AddToolbarButtons(toolBar
, helpStyle
);
349 topWindowSizer
->Add(toolBar
, 0, wxEXPAND
);
352 #endif //wxUSE_TOOLBAR
354 wxSizer
*navigSizer
= NULL
;
357 wxBorder htmlWindowBorder
= wxBORDER_THEME
;
359 wxBorder htmlWindowBorder
= wxBORDER_SUNKEN
;
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 long splitterStyle
= wxSP_3D
;
367 // Drawing moving sash can cause problems on wxMac
369 splitterStyle
= 0; // 3D style looks poor on Mac
370 splitterStyle
|= wxSP_LIVE_UPDATE
;
372 m_Splitter
= new wxSplitterWindow(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, splitterStyle
);
374 topWindowSizer
->Add(m_Splitter
, 1, wxEXPAND
);
376 m_HtmlWin
= new wxHtmlHelpHtmlWindow(this, m_Splitter
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxHW_DEFAULT_STYLE
|htmlWindowBorder
);
377 m_NavigPan
= new wxPanel(m_Splitter
, wxID_ANY
);
378 m_NavigNotebook
= new wxNotebook(m_NavigPan
, wxID_HTML_NOTEBOOK
,
379 wxDefaultPosition
, wxDefaultSize
);
381 m_NavigNotebook
->SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
384 navigSizer
= new wxBoxSizer(wxVERTICAL
);
385 navigSizer
->Add(m_NavigNotebook
, 1, wxEXPAND
);
387 m_NavigPan
->SetSizer(navigSizer
);
391 // only html window, no notebook with index,contents etc
392 m_HtmlWin
= new wxHtmlWindow(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxHW_DEFAULT_STYLE
|htmlWindowBorder
);
393 topWindowSizer
->Add(m_HtmlWin
, 1, wxEXPAND
);
398 m_HtmlWin
->ReadCustomization(m_Config
, m_ConfigRoot
);
399 #endif // wxUSE_CONFIG
401 // contents tree panel?
402 if ( helpStyle
& wxHF_CONTENTS
)
404 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
406 dummy
->SetWindowVariant(wxWINDOW_VARIANT_NORMAL
);
408 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
410 topsizer
->Add(0, 10);
412 dummy
->SetSizer(topsizer
);
414 if ( helpStyle
& wxHF_BOOKMARKS
)
416 long comboStyle
= wxCB_READONLY
;
418 // Not supported on OSX/Cocoa presently
419 comboStyle
|= wxCB_SORT
;
422 m_Bookmarks
= new wxComboBox(dummy
, wxID_HTML_BOOKMARKSLIST
,
424 wxDefaultPosition
, wxDefaultSize
,
425 0, NULL
, comboStyle
);
426 m_Bookmarks
->Append(_("(bookmarks)"));
427 for (unsigned i
= 0; i
< m_BookmarksNames
.GetCount(); i
++)
428 m_Bookmarks
->Append(m_BookmarksNames
[i
]);
429 m_Bookmarks
->SetSelection(0);
431 wxBitmapButton
*bmpbt1
, *bmpbt2
;
432 bmpbt1
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSADD
,
433 wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK
,
435 bmpbt2
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSREMOVE
,
436 wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK
,
439 bmpbt1
->SetToolTip(_("Add current page to bookmarks"));
440 bmpbt2
->SetToolTip(_("Remove current page from bookmarks"));
441 #endif // wxUSE_TOOLTIPS
443 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
445 sizer
->Add(m_Bookmarks
, 1, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 5);
446 sizer
->Add(bmpbt1
, 0, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 2);
447 sizer
->Add(bmpbt2
, 0, wxALIGN_CENTRE_VERTICAL
, 0);
449 topsizer
->Add(sizer
, 0, wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
, 10);
452 m_ContentsBox
= new wxTreeCtrl(dummy
, wxID_HTML_TREECTRL
,
453 wxDefaultPosition
, wxDefaultSize
,
454 #if defined(__WXGTK20__) || defined(__WXMAC__)
456 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
460 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
465 wxImageList
*ContentsImageList
= new wxImageList(16, 16);
466 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK
,
469 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER
,
472 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE
,
476 m_ContentsBox
->AssignImageList(ContentsImageList
);
478 topsizer
->Add(m_ContentsBox
, 1,
479 wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
,
482 m_NavigNotebook
->AddPage(dummy
, _("Contents"));
483 m_ContentsPage
= notebook_page
++;
486 // index listbox panel?
487 if ( helpStyle
& wxHF_INDEX
)
489 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
491 dummy
->SetWindowVariant(wxWINDOW_VARIANT_NORMAL
);
493 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
495 dummy
->SetSizer(topsizer
);
497 m_IndexText
= new wxTextCtrl(dummy
, wxID_HTML_INDEXTEXT
, wxEmptyString
,
498 wxDefaultPosition
, wxDefaultSize
,
500 m_IndexButton
= new wxButton(dummy
, wxID_HTML_INDEXBUTTON
, _("Find"));
501 m_IndexButtonAll
= new wxButton(dummy
, wxID_HTML_INDEXBUTTONALL
,
503 m_IndexCountInfo
= new wxStaticText(dummy
, wxID_HTML_COUNTINFO
,
504 wxEmptyString
, wxDefaultPosition
,
506 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
507 m_IndexList
= new wxListBox(dummy
, wxID_HTML_INDEXLIST
,
508 wxDefaultPosition
, wxDefaultSize
,
509 0, NULL
, wxLB_SINGLE
);
512 m_IndexButton
->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
513 m_IndexButtonAll
->SetToolTip(_("Show all items in index"));
514 #endif //wxUSE_TOOLTIPS
516 topsizer
->Add(m_IndexText
, 0, wxEXPAND
| wxALL
, 10);
517 wxSizer
*btsizer
= new wxBoxSizer(wxHORIZONTAL
);
518 btsizer
->Add(m_IndexButton
, 0, wxRIGHT
, 2);
519 btsizer
->Add(m_IndexButtonAll
);
520 topsizer
->Add(btsizer
, 0,
521 wxALIGN_RIGHT
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
522 topsizer
->Add(m_IndexCountInfo
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 2);
523 topsizer
->Add(m_IndexList
, 1, wxEXPAND
| wxALL
, 2);
525 m_NavigNotebook
->AddPage(dummy
, _("Index"));
526 m_IndexPage
= notebook_page
++;
529 // search list panel?
530 if ( helpStyle
& wxHF_SEARCH
)
532 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
534 dummy
->SetWindowVariant(wxWINDOW_VARIANT_NORMAL
);
536 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
538 dummy
->SetSizer(sizer
);
540 m_SearchText
= new wxTextCtrl(dummy
, wxID_HTML_SEARCHTEXT
,
542 wxDefaultPosition
, wxDefaultSize
,
544 m_SearchChoice
= new wxChoice(dummy
, wxID_HTML_SEARCHCHOICE
,
545 wxDefaultPosition
, wxSize(125,wxDefaultCoord
));
546 m_SearchCaseSensitive
= new wxCheckBox(dummy
, wxID_ANY
, _("Case sensitive"));
547 m_SearchWholeWords
= new wxCheckBox(dummy
, wxID_ANY
, _("Whole words only"));
548 m_SearchButton
= new wxButton(dummy
, wxID_HTML_SEARCHBUTTON
, _("Search"));
550 m_SearchButton
->SetToolTip(_("Search contents of help book(s) for all occurrences of the text you typed above"));
551 #endif //wxUSE_TOOLTIPS
552 m_SearchList
= new wxListBox(dummy
, wxID_HTML_SEARCHLIST
,
553 wxDefaultPosition
, wxDefaultSize
,
554 0, NULL
, wxLB_SINGLE
);
556 sizer
->Add(m_SearchText
, 0, wxEXPAND
| wxALL
, 10);
557 sizer
->Add(m_SearchChoice
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
558 sizer
->Add(m_SearchCaseSensitive
, 0, wxLEFT
| wxRIGHT
, 10);
559 sizer
->Add(m_SearchWholeWords
, 0, wxLEFT
| wxRIGHT
, 10);
560 sizer
->Add(m_SearchButton
, 0, wxALL
| wxALIGN_RIGHT
, 8);
561 sizer
->Add(m_SearchList
, 1, wxALL
| wxEXPAND
, 2);
563 m_NavigNotebook
->AddPage(dummy
, _("Search"));
564 m_SearchPage
= notebook_page
;
573 navigSizer
->SetSizeHints(m_NavigPan
);
574 m_NavigPan
->Layout();
578 if ( m_NavigPan
&& m_Splitter
)
580 // The panel will have its own min size which the splitter
583 // m_Splitter->SetMinimumPaneSize(m_NavigPan->GetBestSize().x);
585 m_Splitter
->SetMinimumPaneSize(20);
587 if ( m_Cfg
.navig_on
)
590 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
594 m_NavigPan
->Show(false);
595 m_Splitter
->Initialize(m_HtmlWin
);
599 // Reduce flicker by updating the splitter pane sizes before the
601 wxSizeEvent
sizeEvent(GetSize(), GetId());
602 GetEventHandler()->ProcessEvent(sizeEvent
);
605 m_Splitter
->UpdateSize();
610 wxHtmlHelpWindow::~wxHtmlHelpWindow()
612 if ( m_helpController
)
613 m_helpController
->SetHelpWindow(NULL
);
615 delete m_mergedIndex
;
617 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
620 if (m_NormalFonts
) delete m_NormalFonts
;
621 if (m_FixedFonts
) delete m_FixedFonts
;
624 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
627 #if wxUSE_PRINTING_ARCHITECTURE
628 if (m_Printer
) delete m_Printer
;
632 void wxHtmlHelpWindow::SetController(wxHtmlHelpController
* controller
)
636 m_helpController
= controller
;
637 m_Data
= controller
->GetHelpData();
638 m_DataCreated
= false;
642 void wxHtmlHelpWindow::AddToolbarButtons(wxToolBar
*toolBar
, int style
)
644 wxBitmap wpanelBitmap
=
645 wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL
, wxART_TOOLBAR
);
646 wxBitmap wbackBitmap
=
647 wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_TOOLBAR
);
648 wxBitmap wforwardBitmap
=
649 wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_TOOLBAR
);
650 wxBitmap wupnodeBitmap
=
651 wxArtProvider::GetBitmap(wxART_GO_TO_PARENT
, wxART_TOOLBAR
);
653 wxArtProvider::GetBitmap(wxART_GO_UP
, wxART_TOOLBAR
);
654 wxBitmap wdownBitmap
=
655 wxArtProvider::GetBitmap(wxART_GO_DOWN
, wxART_TOOLBAR
);
656 wxBitmap wopenBitmap
=
657 wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_TOOLBAR
);
658 wxBitmap wprintBitmap
=
659 wxArtProvider::GetBitmap(wxART_PRINT
, wxART_TOOLBAR
);
660 wxBitmap woptionsBitmap
=
661 wxArtProvider::GetBitmap(wxART_HELP_SETTINGS
, wxART_TOOLBAR
);
663 wxASSERT_MSG( (wpanelBitmap
.IsOk() && wbackBitmap
.IsOk() &&
664 wforwardBitmap
.IsOk() && wupnodeBitmap
.IsOk() &&
665 wupBitmap
.IsOk() && wdownBitmap
.IsOk() &&
666 wopenBitmap
.IsOk() && wprintBitmap
.IsOk() &&
667 woptionsBitmap
.IsOk()),
668 wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
671 toolBar
->AddTool(wxID_HTML_PANEL
, wxEmptyString
, wpanelBitmap
, _("Show/hide navigation panel"));
672 toolBar
->AddSeparator();
673 toolBar
->AddTool(wxID_HTML_BACK
, wxEmptyString
, wbackBitmap
, _("Go back"));
674 toolBar
->AddTool(wxID_HTML_FORWARD
, wxEmptyString
, wforwardBitmap
, _("Go forward"));
675 toolBar
->AddSeparator();
676 toolBar
->AddTool(wxID_HTML_UPNODE
, wxEmptyString
, wupnodeBitmap
, _("Go one level up in document hierarchy"));
677 toolBar
->AddTool(wxID_HTML_UP
, wxEmptyString
, wupBitmap
, _("Previous page"));
678 toolBar
->AddTool(wxID_HTML_DOWN
, wxEmptyString
, wdownBitmap
, _("Next page"));
680 if ((style
& wxHF_PRINT
) || (style
& wxHF_OPEN_FILES
))
681 toolBar
->AddSeparator();
683 if (style
& wxHF_OPEN_FILES
)
684 toolBar
->AddTool(wxID_HTML_OPENFILE
, wxEmptyString
, wopenBitmap
, _("Open HTML document"));
686 #if wxUSE_PRINTING_ARCHITECTURE
687 if (style
& wxHF_PRINT
)
688 toolBar
->AddTool(wxID_HTML_PRINT
, wxEmptyString
, wprintBitmap
, _("Print this page"));
691 toolBar
->AddSeparator();
692 toolBar
->AddTool(wxID_HTML_OPTIONS
, wxEmptyString
, woptionsBitmap
, _("Display options dialog"));
694 // Allow application to add custom buttons
695 wxHtmlHelpFrame
* parentFrame
= wxDynamicCast(GetParent(), wxHtmlHelpFrame
);
696 wxHtmlHelpDialog
* parentDialog
= wxDynamicCast(GetParent(), wxHtmlHelpDialog
);
698 parentFrame
->AddToolbarButtons(toolBar
, style
);
700 parentDialog
->AddToolbarButtons(toolBar
, style
);
702 #endif //wxUSE_TOOLBAR
705 bool wxHtmlHelpWindow::Display(const wxString
& x
)
707 wxString url
= m_Data
->FindPageByName(x
);
710 m_HtmlWin
->LoadPage(url
);
717 bool wxHtmlHelpWindow::Display(const int id
)
719 wxString url
= m_Data
->FindPageById(id
);
722 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());
789 wxBusyCursor busy_cursor
;
791 // more pages associated with this index item -- let the user choose
792 // which one she/he wants from a list:
794 size_t len
= it
->items
.size();
795 for (size_t i
= 0; i
< len
; i
++)
797 wxString page
= it
->items
[i
]->page
;
798 // try to find page's title in contents:
799 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
800 size_t clen
= contents
.size();
801 for (size_t j
= 0; j
< clen
; j
++)
803 if (contents
[j
].page
== page
)
805 page
= contents
[j
].name
;
812 wxSingleChoiceDialog
dlg(this,
813 _("Please choose the page to display:"),
816 (void**)NULL
, // No client data
817 wxCHOICEDLG_STYLE
& ~wxCENTRE
);
818 if (dlg
.ShowModal() == wxID_OK
)
820 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());
933 case wxHELP_SEARCH_INDEX
:
935 wxHtmlHelpMergedIndexItem
* it
=
936 (wxHtmlHelpMergedIndexItem
*) m_IndexList
->GetClientData(0);
938 DisplayIndexItem(it
);
948 void wxHtmlHelpWindow::CreateContents()
955 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
959 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
961 size_t cnt
= contents
.size();
963 m_PagesHash
= new wxHashTable(wxKEY_STRING
, 2 * cnt
);
965 const int MAX_ROOTS
= 64;
966 wxTreeItemId roots
[MAX_ROOTS
];
967 // VS: this array holds information about whether we've set item icon at
968 // given level. This is necessary because m_Data has a flat structure
969 // and there's no way of recognizing if some item has subitems or not.
970 // We set the icon later: when we find an item with level=n, we know
971 // that the last item with level=n-1 was afolder with subitems, so we
972 // set its icon accordingly
973 bool imaged
[MAX_ROOTS
];
974 m_ContentsBox
->DeleteAllItems();
976 roots
[0] = m_ContentsBox
->AddRoot(_("(Help)"));
979 for (size_t i
= 0; i
< cnt
; i
++)
981 wxHtmlHelpDataItem
*it
= &contents
[i
];
985 if (m_hfStyle
& wxHF_MERGE_BOOKS
)
986 // VS: we don't want book nodes, books' content should
987 // appear under tree's root. This line will create a "fake"
988 // record about book node so that the rest of this look
989 // will believe there really _is_ a book node and will
994 roots
[1] = m_ContentsBox
->AppendItem(roots
[0],
995 it
->name
, IMG_Book
, -1,
996 new wxHtmlHelpTreeItemData(i
));
997 m_ContentsBox
->SetItemBold(roots
[1], true);
1001 // ...and their contents:
1004 roots
[it
->level
+ 1] = m_ContentsBox
->AppendItem(
1005 roots
[it
->level
], it
->name
, IMG_Page
,
1006 -1, new wxHtmlHelpTreeItemData(i
));
1007 imaged
[it
->level
+ 1] = false;
1010 m_PagesHash
->Put(it
->GetFullPath(),
1011 new wxHtmlHelpHashData(i
, roots
[it
->level
+ 1]));
1013 // Set the icon for the node one level up in the hierarchy,
1014 // unless already done (see comment above imaged[] declaration)
1015 if (!imaged
[it
->level
])
1017 int image
= IMG_Folder
;
1018 if (m_hfStyle
& wxHF_ICONS_BOOK
)
1020 else if (m_hfStyle
& wxHF_ICONS_BOOK_CHAPTER
)
1021 image
= (it
->level
== 1) ? IMG_Book
: IMG_Folder
;
1022 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
);
1023 m_ContentsBox
->SetItemImage(roots
[it
->level
], image
,
1024 wxTreeItemIcon_Selected
);
1025 imaged
[it
->level
] = true;
1029 m_ContentsBox
->SetMinSize(wxSize(CONTENT_TREE_INDEX_MIN_WIDTH
,
1030 m_ContentsBox
->GetMinHeight()));
1033 void wxHtmlHelpWindow::CreateIndex()
1038 m_IndexList
->Clear();
1040 unsigned long cnt
= m_mergedIndex
->size();
1043 if (cnt
> INDEX_IS_SMALL
)
1044 cnttext
.Printf(_("%d of %lu"), 0, cnt
);
1046 cnttext
.Printf(_("%lu of %lu"), cnt
, cnt
);
1047 m_IndexCountInfo
->SetLabel(cnttext
);
1048 if (cnt
> INDEX_IS_SMALL
)
1051 for (size_t i
= 0; i
< cnt
; i
++)
1052 m_IndexList
->Append((*m_mergedIndex
)[i
].name
,
1053 (char*)(&(*m_mergedIndex
)[i
]));
1055 m_IndexList
->SetMinSize(wxSize(CONTENT_TREE_INDEX_MIN_WIDTH
,
1056 m_IndexList
->GetMinHeight()));
1059 void wxHtmlHelpWindow::CreateSearch()
1061 if (! (m_SearchList
&& m_SearchChoice
))
1063 m_SearchList
->Clear();
1064 m_SearchChoice
->Clear();
1065 m_SearchChoice
->Append(_("Search in all books"));
1066 const wxHtmlBookRecArray
& bookrec
= m_Data
->GetBookRecArray();
1067 int i
, cnt
= bookrec
.GetCount();
1068 for (i
= 0; i
< cnt
; i
++)
1069 m_SearchChoice
->Append(bookrec
[i
].GetTitle());
1070 m_SearchChoice
->SetSelection(0);
1073 void wxHtmlHelpWindow::RefreshLists()
1075 // Update m_mergedIndex:
1076 UpdateMergedIndex();
1077 // Update the controls
1084 void wxHtmlHelpWindow::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1089 if (path
!= wxEmptyString
)
1091 oldpath
= cfg
->GetPath();
1092 cfg
->SetPath(wxT("/") + 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(wxT("/") + 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
);
1189 #endif // wxUSE_CONFIG
1191 static void SetFontsToHtmlWin(wxHtmlWindow
*win
, const wxString
& scalf
, const wxString
& fixf
, int size
)
1194 f_sizes
[0] = int(size
* 0.6);
1195 f_sizes
[1] = int(size
* 0.8);
1197 f_sizes
[3] = int(size
* 1.2);
1198 f_sizes
[4] = int(size
* 1.4);
1199 f_sizes
[5] = int(size
* 1.6);
1200 f_sizes
[6] = int(size
* 1.8);
1202 win
->SetFonts(scalf
, fixf
, f_sizes
);
1205 class wxHtmlHelpWindowOptionsDialog
: public wxDialog
1208 wxComboBox
*NormalFont
, *FixedFont
;
1209 wxSpinCtrl
*FontSize
;
1210 wxHtmlWindow
*TestWin
;
1212 wxHtmlHelpWindowOptionsDialog(wxWindow
*parent
)
1213 : wxDialog(parent
, wxID_ANY
, wxString(_("Help Browser Options")))
1215 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
1216 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2, 3, 2, 5);
1218 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Normal font:")));
1219 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Fixed font:")));
1220 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Font size:")));
1222 sizer
->Add(NormalFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1223 wxSize(200, wxDefaultCoord
),
1224 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1226 sizer
->Add(FixedFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1227 wxSize(200, wxDefaultCoord
),
1228 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1230 sizer
->Add(FontSize
= new wxSpinCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1231 wxDefaultSize
, wxSP_ARROW_KEYS
, 2, 100, 2, wxT("wxSpinCtrl")));
1233 topsizer
->Add(sizer
, 0, wxLEFT
|wxRIGHT
|wxTOP
, 10);
1235 topsizer
->Add(new wxStaticText(this, wxID_ANY
, _("Preview:")),
1236 0, wxLEFT
| wxTOP
, 10);
1238 topsizer
->AddSpacer(5);
1240 topsizer
->Add(TestWin
= new wxHtmlWindow(this, wxID_ANY
, wxDefaultPosition
, wxSize(20, 150),
1241 wxHW_SCROLLBAR_AUTO
|wxBORDER_THEME
),
1242 1, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
1244 wxBoxSizer
*sizer2
= new wxBoxSizer(wxHORIZONTAL
);
1246 sizer2
->Add(ok
= new wxButton(this, wxID_OK
), 0, wxALL
, 10);
1248 sizer2
->Add(new wxButton(this, wxID_CANCEL
), 0, wxALL
, 10);
1249 topsizer
->Add(sizer2
, 0, wxALIGN_RIGHT
);
1252 topsizer
->Fit(this);
1257 void UpdateTestWin()
1260 SetFontsToHtmlWin(TestWin
,
1261 NormalFont
->GetStringSelection(),
1262 FixedFont
->GetStringSelection(),
1263 FontSize
->GetValue());
1265 wxString
content(_("font size"));
1267 content
= wxT("<font size=-2>") + content
+ wxT(" -2</font><br>")
1268 wxT("<font size=-1>") + content
+ wxT(" -1</font><br>")
1269 wxT("<font size=+0>") + content
+ wxT(" +0</font><br>")
1270 wxT("<font size=+1>") + content
+ wxT(" +1</font><br>")
1271 wxT("<font size=+2>") + content
+ wxT(" +2</font><br>")
1272 wxT("<font size=+3>") + content
+ wxT(" +3</font><br>")
1273 wxT("<font size=+4>") + content
+ wxT(" +4</font><br>") ;
1275 content
= wxString( wxT("<html><body><table><tr><td>") ) +
1276 _("Normal face<br>and <u>underlined</u>. ") +
1277 _("<i>Italic face.</i> ") +
1278 _("<b>Bold face.</b> ") +
1279 _("<b><i>Bold italic face.</i></b><br>") +
1281 wxString( wxT("</td><td><tt>") ) +
1282 _("Fixed size face.<br> <b>bold</b> <i>italic</i> ") +
1283 _("<b><i>bold italic <u>underlined</u></i></b><br>") +
1285 wxT("</tt></td></tr></table></body></html>");
1287 TestWin
->SetPage( content
);
1290 void OnUpdate(wxCommandEvent
& WXUNUSED(event
))
1294 void OnUpdateSpin(wxSpinEvent
& WXUNUSED(event
))
1299 DECLARE_EVENT_TABLE()
1300 wxDECLARE_NO_COPY_CLASS(wxHtmlHelpWindowOptionsDialog
);
1303 BEGIN_EVENT_TABLE(wxHtmlHelpWindowOptionsDialog
, wxDialog
)
1304 EVT_COMBOBOX(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdate
)
1305 EVT_SPINCTRL(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdateSpin
)
1308 void wxHtmlHelpWindow::OptionsDialog()
1310 wxHtmlHelpWindowOptionsDialog
dlg(this);
1313 if (m_NormalFonts
== NULL
)
1315 m_NormalFonts
= new wxArrayString(wxFontEnumerator::GetFacenames());
1316 m_NormalFonts
->Sort(); // ascending sort
1318 if (m_FixedFonts
== NULL
)
1320 m_FixedFonts
= new wxArrayString(
1321 wxFontEnumerator::GetFacenames(wxFONTENCODING_SYSTEM
,
1322 true /*enum fixed width only*/));
1323 m_FixedFonts
->Sort(); // ascending sort
1326 // VS: We want to show the font that is actually used by wxHtmlWindow.
1327 // If customization dialog wasn't used yet, facenames are empty and
1328 // wxHtmlWindow uses default fonts -- let's find out what they
1329 // are so that we can pass them to the dialog:
1330 if (m_NormalFace
.empty())
1332 wxFont
fnt(m_FontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false);
1333 m_NormalFace
= fnt
.GetFaceName();
1335 if (m_FixedFace
.empty())
1337 wxFont
fnt(m_FontSize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false);
1338 m_FixedFace
= fnt
.GetFaceName();
1341 for (i
= 0; i
< m_NormalFonts
->GetCount(); i
++)
1342 dlg
.NormalFont
->Append((*m_NormalFonts
)[i
]);
1343 for (i
= 0; i
< m_FixedFonts
->GetCount(); i
++)
1344 dlg
.FixedFont
->Append((*m_FixedFonts
)[i
]);
1345 if (!m_NormalFace
.empty())
1346 dlg
.NormalFont
->SetStringSelection(m_NormalFace
);
1348 dlg
.NormalFont
->SetSelection(0);
1349 if (!m_FixedFace
.empty())
1350 dlg
.FixedFont
->SetStringSelection(m_FixedFace
);
1352 dlg
.FixedFont
->SetSelection(0);
1353 dlg
.FontSize
->SetValue(m_FontSize
);
1354 dlg
.UpdateTestWin();
1356 if (dlg
.ShowModal() == wxID_OK
)
1358 m_NormalFace
= dlg
.NormalFont
->GetStringSelection();
1359 m_FixedFace
= dlg
.FixedFont
->GetStringSelection();
1360 m_FontSize
= dlg
.FontSize
->GetValue();
1361 SetFontsToHtmlWin(m_HtmlWin
, m_NormalFace
, m_FixedFace
, m_FontSize
);
1365 void wxHtmlHelpWindow::NotifyPageChanged()
1367 if (m_UpdateContents
&& m_PagesHash
)
1369 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1370 wxHtmlHelpHashData
*ha
= NULL
;
1372 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1376 bool olduc
= m_UpdateContents
;
1377 m_UpdateContents
= false;
1378 m_ContentsBox
->SelectItem(ha
->m_Id
);
1379 m_ContentsBox
->EnsureVisible(ha
->m_Id
);
1380 m_UpdateContents
= olduc
;
1390 void wxHtmlHelpWindow::OnToolbar(wxCommandEvent
& event
)
1392 switch (event
.GetId())
1394 case wxID_HTML_BACK
:
1395 m_HtmlWin
->HistoryBack();
1398 case wxID_HTML_FORWARD
:
1399 m_HtmlWin
->HistoryForward();
1405 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1406 wxHtmlHelpHashData
*ha
= NULL
;
1408 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1409 if (ha
&& ha
->m_Index
> 0)
1411 const wxHtmlHelpDataItem
& it
= m_Data
->GetContentsArray()[ha
->m_Index
- 1];
1412 if (!it
.page
.empty())
1414 m_HtmlWin
->LoadPage(it
.GetFullPath());
1420 case wxID_HTML_UPNODE
:
1423 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1424 wxHtmlHelpHashData
*ha
= NULL
;
1426 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1427 if (ha
&& ha
->m_Index
> 0)
1430 m_Data
->GetContentsArray()[ha
->m_Index
].level
- 1;
1431 int ind
= ha
->m_Index
- 1;
1433 const wxHtmlHelpDataItem
*it
=
1434 &m_Data
->GetContentsArray()[ind
];
1435 while (ind
>= 0 && it
->level
!= level
)
1438 it
= &m_Data
->GetContentsArray()[ind
];
1442 if (!it
->page
.empty())
1443 m_HtmlWin
->LoadPage(it
->GetFullPath());
1449 case wxID_HTML_DOWN
:
1452 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1453 wxHtmlHelpHashData
*ha
= NULL
;
1455 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1457 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1458 if (ha
&& ha
->m_Index
< (int)contents
.size() - 1)
1460 size_t idx
= ha
->m_Index
+ 1;
1462 while (contents
[idx
].GetFullPath() == page
) idx
++;
1464 if (!contents
[idx
].page
.empty())
1465 m_HtmlWin
->LoadPage(contents
[idx
].GetFullPath());
1470 case wxID_HTML_PANEL
:
1472 if (! (m_Splitter
&& m_NavigPan
))
1474 if (m_Splitter
->IsSplit())
1476 m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1477 m_Splitter
->Unsplit(m_NavigPan
);
1478 m_Cfg
.navig_on
= false;
1484 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
1485 m_Cfg
.navig_on
= true;
1490 case wxID_HTML_OPTIONS
:
1494 case wxID_HTML_BOOKMARKSADD
:
1499 item
= m_HtmlWin
->GetOpenedPageTitle();
1500 url
= m_HtmlWin
->GetOpenedPage();
1501 if (item
== wxEmptyString
)
1502 item
= url
.AfterLast(wxT('/'));
1503 if (m_BookmarksPages
.Index(url
) == wxNOT_FOUND
)
1505 m_Bookmarks
->Append(item
);
1506 m_BookmarksNames
.Add(item
);
1507 m_BookmarksPages
.Add(url
);
1512 case wxID_HTML_BOOKMARKSREMOVE
:
1517 item
= m_Bookmarks
->GetStringSelection();
1518 pos
= m_BookmarksNames
.Index(item
);
1519 if (pos
!= wxNOT_FOUND
)
1521 m_BookmarksNames
.RemoveAt(pos
);
1522 m_BookmarksPages
.RemoveAt(pos
);
1523 pos
= m_Bookmarks
->GetSelection();
1524 wxASSERT_MSG( pos
!= wxNOT_FOUND
, wxT("Unknown bookmark position") ) ;
1525 m_Bookmarks
->Delete((unsigned int)pos
);
1530 #if wxUSE_PRINTING_ARCHITECTURE
1531 case wxID_HTML_PRINT
:
1533 if (m_Printer
== NULL
)
1534 m_Printer
= new wxHtmlEasyPrinting(_("Help Printing"), this);
1535 if (!m_HtmlWin
->GetOpenedPage())
1537 wxLogWarning(_("Cannot print empty page."));
1541 m_Printer
->PrintFile(m_HtmlWin
->GetOpenedPage());
1547 case wxID_HTML_OPENFILE
:
1549 wxString filemask
= wxString(
1550 _("HTML files (*.html;*.htm)|*.html;*.htm|")) +
1551 _("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|") +
1552 _("HTML Help Project (*.hhp)|*.hhp|") +
1554 _("Compressed HTML Help file (*.chm)|*.chm|") +
1557 wxString s
= wxFileSelector(_("Open HTML document"),
1562 wxFD_OPEN
| wxFD_FILE_MUST_EXIST
,
1566 wxString ext
= s
.Right(4).Lower();
1567 if (ext
== wxT(".zip") || ext
== wxT(".htb") ||
1569 ext
== wxT(".chm") ||
1578 m_HtmlWin
->LoadPage(s
);
1585 void wxHtmlHelpWindow::OnContentsSel(wxTreeEvent
& event
)
1587 wxHtmlHelpTreeItemData
*pg
;
1589 pg
= (wxHtmlHelpTreeItemData
*) m_ContentsBox
->GetItemData(event
.GetItem());
1591 if (pg
&& m_UpdateContents
)
1593 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1594 m_UpdateContents
= false;
1595 if (!contents
[pg
->m_Id
].page
.empty())
1596 m_HtmlWin
->LoadPage(contents
[pg
->m_Id
].GetFullPath());
1597 m_UpdateContents
= true;
1601 void wxHtmlHelpWindow::OnIndexSel(wxCommandEvent
& WXUNUSED(event
))
1603 wxHtmlHelpMergedIndexItem
*it
= (wxHtmlHelpMergedIndexItem
*)
1604 m_IndexList
->GetClientData(m_IndexList
->GetSelection());
1606 DisplayIndexItem(it
);
1609 void wxHtmlHelpWindow::OnIndexFind(wxCommandEvent
& WXUNUSED(event
))
1614 void wxHtmlHelpWindow::DoIndexFind()
1616 wxString sr
= m_IndexText
->GetLineText(0);
1618 if (sr
== wxEmptyString
)
1626 m_IndexList
->Clear();
1627 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1628 size_t cnt
= index
.size();
1631 for (size_t i
= 0; i
< cnt
; i
++)
1633 if (index
[i
].name
.Lower().find(sr
) != wxString::npos
)
1635 int pos
= m_IndexList
->Append(index
[i
].name
,
1636 (char*)(&index
[i
]));
1640 // don't automatically show topic selector if this
1641 // item points to multiple pages:
1642 if (index
[i
].items
.size() == 1)
1644 m_IndexList
->SetSelection(0);
1645 DisplayIndexItem(&index
[i
]);
1649 // if this is nested item of the index, show its parent(s)
1650 // as well, otherwise it would not be clear what entry is
1652 wxHtmlHelpMergedIndexItem
*parent
= index
[i
].parent
;
1656 (index
.Index(*(wxHtmlHelpMergedIndexItem
*)m_IndexList
->GetClientData(pos
-1))) < index
.Index(*parent
))
1658 m_IndexList
->Insert(parent
->name
,
1659 pos
, (char*)parent
);
1660 parent
= parent
->parent
;
1665 // finally, it the item we just added is itself a parent for
1666 // other items, show them as well, because they are refinements
1667 // of the displayed index entry (i.e. it is implicitly contained
1668 // in them: "foo" with parent "bar" reads as "bar, foo"):
1669 int level
= index
[i
].items
[0]->level
;
1671 while (i
< cnt
&& index
[i
].items
[0]->level
> level
)
1673 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1681 cnttext
.Printf(_("%i of %i"), displ
, cnt
);
1682 m_IndexCountInfo
->SetLabel(cnttext
);
1684 m_IndexText
->SetSelection(0, sr
.length());
1685 m_IndexText
->SetFocus();
1689 void wxHtmlHelpWindow::OnIndexAll(wxCommandEvent
& WXUNUSED(event
))
1694 void wxHtmlHelpWindow::DoIndexAll()
1698 m_IndexList
->Clear();
1699 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1700 size_t cnt
= index
.size();
1703 for (size_t i
= 0; i
< cnt
; i
++)
1705 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1708 // don't automatically show topic selector if this
1709 // item points to multiple pages:
1710 if (index
[i
].items
.size() == 1)
1712 DisplayIndexItem(&index
[i
]);
1719 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1720 m_IndexCountInfo
->SetLabel(cnttext
);
1723 void wxHtmlHelpWindow::OnSearchSel(wxCommandEvent
& WXUNUSED(event
))
1725 wxHtmlHelpDataItem
*it
= (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(m_SearchList
->GetSelection());
1728 if (!it
->page
.empty())
1729 m_HtmlWin
->LoadPage(it
->GetFullPath());
1733 void wxHtmlHelpWindow::OnSearch(wxCommandEvent
& WXUNUSED(event
))
1735 wxString sr
= m_SearchText
->GetLineText(0);
1738 KeywordSearch(sr
, wxHELP_SEARCH_ALL
);
1741 void wxHtmlHelpWindow::OnBookmarksSel(wxCommandEvent
& WXUNUSED(event
))
1743 wxString str
= m_Bookmarks
->GetStringSelection();
1744 int idx
= m_BookmarksNames
.Index(str
);
1745 if (!str
.empty() && str
!= _("(bookmarks)") && idx
!= wxNOT_FOUND
)
1747 m_HtmlWin
->LoadPage(m_BookmarksPages
[(size_t)idx
]);
1751 void wxHtmlHelpWindow::OnSize(wxSizeEvent
& WXUNUSED(event
))
1756 #endif // wxUSE_WXHTML_HELP