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 virtual bool LoadPage(const wxString
& location
)
125 if ( !wxHtmlWindow::LoadPage(location
) )
128 m_Window
->NotifyPageChanged();
132 // Returns full location with anchor (helper)
133 static wxString
GetOpenedPageWithAnchor(wxHtmlWindow
*win
)
136 return wxEmptyString
;
138 wxString an
= win
->GetOpenedAnchor();
139 wxString pg
= win
->GetOpenedPage();
142 pg
<< wxT("#") << an
;
148 wxHtmlHelpWindow
*m_Window
;
150 wxDECLARE_NO_COPY_CLASS(wxHtmlHelpHtmlWindow
);
154 //---------------------------------------------------------------------------
155 // wxHtmlHelpWindow::m_mergedIndex
156 //---------------------------------------------------------------------------
158 WX_DEFINE_ARRAY_PTR(const wxHtmlHelpDataItem
*, wxHtmlHelpDataItemPtrArray
);
160 struct wxHtmlHelpMergedIndexItem
162 wxHtmlHelpMergedIndexItem
*parent
;
164 wxHtmlHelpDataItemPtrArray items
;
167 WX_DECLARE_OBJARRAY(wxHtmlHelpMergedIndexItem
, wxHtmlHelpMergedIndex
);
168 #include "wx/arrimpl.cpp"
169 WX_DEFINE_OBJARRAY(wxHtmlHelpMergedIndex
)
171 void wxHtmlHelpWindow::UpdateMergedIndex()
173 delete m_mergedIndex
;
174 m_mergedIndex
= new wxHtmlHelpMergedIndex
;
175 wxHtmlHelpMergedIndex
& merged
= *m_mergedIndex
;
177 const wxHtmlHelpDataItems
& items
= m_Data
->GetIndexArray();
178 size_t len
= items
.size();
180 wxHtmlHelpMergedIndexItem
*history
[128] = {NULL
};
182 for (size_t i
= 0; i
< len
; i
++)
184 const wxHtmlHelpDataItem
& item
= items
[i
];
185 wxASSERT_MSG( item
.level
< 128, wxT("nested index entries too deep") );
187 if (history
[item
.level
] &&
188 history
[item
.level
]->items
[0]->name
== item
.name
)
190 // same index entry as previous one, update list of items
191 history
[item
.level
]->items
.Add(&item
);
196 wxHtmlHelpMergedIndexItem
*mi
= new wxHtmlHelpMergedIndexItem();
197 mi
->name
= item
.GetIndentedName();
198 mi
->items
.Add(&item
);
199 mi
->parent
= (item
.level
== 0) ? NULL
: history
[item
.level
- 1];
200 history
[item
.level
] = mi
;
206 //---------------------------------------------------------------------------
208 //---------------------------------------------------------------------------
210 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpWindow
, wxWindow
)
212 BEGIN_EVENT_TABLE(wxHtmlHelpWindow
, wxWindow
)
213 EVT_TOOL_RANGE(wxID_HTML_PANEL
, wxID_HTML_OPTIONS
, wxHtmlHelpWindow::OnToolbar
)
214 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE
, wxHtmlHelpWindow::OnToolbar
)
215 EVT_BUTTON(wxID_HTML_BOOKMARKSADD
, wxHtmlHelpWindow::OnToolbar
)
216 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL
, wxHtmlHelpWindow::OnContentsSel
)
217 EVT_LISTBOX(wxID_HTML_INDEXLIST
, wxHtmlHelpWindow::OnIndexSel
)
218 EVT_LISTBOX(wxID_HTML_SEARCHLIST
, wxHtmlHelpWindow::OnSearchSel
)
219 EVT_BUTTON(wxID_HTML_SEARCHBUTTON
, wxHtmlHelpWindow::OnSearch
)
220 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT
, wxHtmlHelpWindow::OnSearch
)
221 EVT_BUTTON(wxID_HTML_INDEXBUTTON
, wxHtmlHelpWindow::OnIndexFind
)
222 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT
, wxHtmlHelpWindow::OnIndexFind
)
223 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL
, wxHtmlHelpWindow::OnIndexAll
)
224 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST
, wxHtmlHelpWindow::OnBookmarksSel
)
225 EVT_SIZE(wxHtmlHelpWindow::OnSize
)
228 wxHtmlHelpWindow::wxHtmlHelpWindow(wxWindow
* parent
, wxWindowID id
,
231 int style
, int helpStyle
, wxHtmlHelpData
* data
)
234 Create(parent
, id
, pos
, size
, style
, helpStyle
);
237 void wxHtmlHelpWindow::Init(wxHtmlHelpData
* data
)
242 m_DataCreated
= false;
246 m_Data
= new wxHtmlHelpData();
247 m_DataCreated
= true;
254 m_ContentsBox
= NULL
;
256 m_IndexButton
= NULL
;
257 m_IndexButtonAll
= NULL
;
260 m_SearchButton
= NULL
;
262 m_SearchChoice
= NULL
;
263 m_IndexCountInfo
= NULL
;
266 m_NavigNotebook
= NULL
;
269 m_SearchCaseSensitive
= NULL
;
270 m_SearchWholeWords
= NULL
;
272 m_mergedIndex
= NULL
;
276 m_ConfigRoot
= wxEmptyString
;
277 #endif // wxUSE_CONFIG
279 m_Cfg
.x
= m_Cfg
.y
= wxDefaultCoord
;
283 m_Cfg
.navig_on
= true;
285 m_NormalFonts
= m_FixedFonts
= NULL
;
286 m_NormalFace
= m_FixedFace
= wxEmptyString
;
293 #if wxUSE_PRINTING_ARCHITECTURE
298 m_UpdateContents
= true;
300 m_helpController
= NULL
;
303 // Create: builds the GUI components.
304 // with the style flag it's possible to toggle the toolbar, contents, index and search
306 // m_HtmlWin will *always* be created, but it's important to realize that
307 // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
308 // m_SearchButton may be NULL.
309 // moreover, if no contents, index or searchpage is needed, m_Splitter and
310 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
312 bool wxHtmlHelpWindow::Create(wxWindow
* parent
, wxWindowID id
,
313 const wxPoint
& pos
, const wxSize
& size
,
314 int style
, int helpStyle
)
316 m_hfStyle
= helpStyle
;
319 // Do the config in two steps. We read the HtmlWindow customization after we
320 // create the window.
322 ReadCustomization(m_Config
, m_ConfigRoot
);
323 #endif // wxUSE_CONFIG
325 wxWindow::Create(parent
, id
, pos
, size
, style
, wxT("wxHtmlHelp"));
327 SetHelpText(_("Displays help as you browse the books on the left."));
329 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
331 int notebook_page
= 0;
333 // The sizer for the whole top-level window.
334 wxSizer
*topWindowSizer
= new wxBoxSizer(wxVERTICAL
);
335 SetSizer(topWindowSizer
);
340 if (helpStyle
& (wxHF_TOOLBAR
| wxHF_FLAT_TOOLBAR
))
342 wxToolBar
*toolBar
= new wxToolBar(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
343 wxNO_BORDER
| wxTB_HORIZONTAL
|
344 wxTB_DOCKABLE
| wxTB_NODIVIDER
|
345 (helpStyle
& wxHF_FLAT_TOOLBAR
? wxTB_FLAT
: 0));
346 toolBar
->SetMargins( 2, 2 );
347 toolBar
->SetToolBitmapSize( wxSize(22,22) );
348 AddToolbarButtons(toolBar
, helpStyle
);
350 topWindowSizer
->Add(toolBar
, 0, wxEXPAND
);
353 #endif //wxUSE_TOOLBAR
355 wxSizer
*navigSizer
= NULL
;
358 wxBorder htmlWindowBorder
= wxBORDER_THEME
;
360 wxBorder htmlWindowBorder
= wxBORDER_SUNKEN
;
363 if (helpStyle
& (wxHF_CONTENTS
| wxHF_INDEX
| wxHF_SEARCH
))
365 // traditional help controller; splitter window with html page on the
366 // right and a notebook containing various pages on the left
367 long splitterStyle
= wxSP_3D
;
368 // Drawing moving sash can cause problems on wxMac
370 splitterStyle
= 0; // 3D style looks poor on Mac
371 splitterStyle
|= wxSP_LIVE_UPDATE
;
373 m_Splitter
= new wxSplitterWindow(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, splitterStyle
);
375 topWindowSizer
->Add(m_Splitter
, 1, wxEXPAND
);
377 m_HtmlWin
= new wxHtmlHelpHtmlWindow(this, m_Splitter
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxHW_DEFAULT_STYLE
|htmlWindowBorder
);
378 m_NavigPan
= new wxPanel(m_Splitter
, wxID_ANY
);
379 m_NavigNotebook
= new wxNotebook(m_NavigPan
, wxID_HTML_NOTEBOOK
,
380 wxDefaultPosition
, wxDefaultSize
);
382 m_NavigNotebook
->SetWindowVariant(wxWINDOW_VARIANT_SMALL
);
385 navigSizer
= new wxBoxSizer(wxVERTICAL
);
386 navigSizer
->Add(m_NavigNotebook
, 1, wxEXPAND
);
388 m_NavigPan
->SetSizer(navigSizer
);
392 // only html window, no notebook with index,contents etc
393 m_HtmlWin
= new wxHtmlWindow(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
, wxHW_DEFAULT_STYLE
|htmlWindowBorder
);
394 topWindowSizer
->Add(m_HtmlWin
, 1, wxEXPAND
);
399 m_HtmlWin
->ReadCustomization(m_Config
, m_ConfigRoot
);
400 #endif // wxUSE_CONFIG
402 // contents tree panel?
403 if ( helpStyle
& wxHF_CONTENTS
)
405 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
407 dummy
->SetWindowVariant(wxWINDOW_VARIANT_NORMAL
);
409 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
411 topsizer
->Add(0, 10);
413 dummy
->SetSizer(topsizer
);
415 if ( helpStyle
& wxHF_BOOKMARKS
)
417 long comboStyle
= wxCB_READONLY
;
419 // Not supported on OSX/Cocoa presently
420 comboStyle
|= wxCB_SORT
;
423 m_Bookmarks
= new wxComboBox(dummy
, wxID_HTML_BOOKMARKSLIST
,
425 wxDefaultPosition
, wxDefaultSize
,
426 0, NULL
, comboStyle
);
427 m_Bookmarks
->Append(_("(bookmarks)"));
428 for (unsigned i
= 0; i
< m_BookmarksNames
.GetCount(); i
++)
429 m_Bookmarks
->Append(m_BookmarksNames
[i
]);
430 m_Bookmarks
->SetSelection(0);
432 wxBitmapButton
*bmpbt1
, *bmpbt2
;
433 bmpbt1
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSADD
,
434 wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK
,
436 bmpbt2
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSREMOVE
,
437 wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK
,
440 bmpbt1
->SetToolTip(_("Add current page to bookmarks"));
441 bmpbt2
->SetToolTip(_("Remove current page from bookmarks"));
442 #endif // wxUSE_TOOLTIPS
444 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
446 sizer
->Add(m_Bookmarks
, 1, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 5);
447 sizer
->Add(bmpbt1
, 0, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 2);
448 sizer
->Add(bmpbt2
, 0, wxALIGN_CENTRE_VERTICAL
, 0);
450 topsizer
->Add(sizer
, 0, wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
, 10);
453 m_ContentsBox
= new wxTreeCtrl(dummy
, wxID_HTML_TREECTRL
,
454 wxDefaultPosition
, wxDefaultSize
,
455 #if defined(__WXGTK20__) || defined(__WXMAC__)
457 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
461 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
466 wxImageList
*ContentsImageList
= new wxImageList(16, 16);
467 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK
,
470 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER
,
473 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE
,
477 m_ContentsBox
->AssignImageList(ContentsImageList
);
479 topsizer
->Add(m_ContentsBox
, 1,
480 wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
,
483 m_NavigNotebook
->AddPage(dummy
, _("Contents"));
484 m_ContentsPage
= notebook_page
++;
487 // index listbox panel?
488 if ( helpStyle
& wxHF_INDEX
)
490 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
492 dummy
->SetWindowVariant(wxWINDOW_VARIANT_NORMAL
);
494 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
496 dummy
->SetSizer(topsizer
);
498 m_IndexText
= new wxTextCtrl(dummy
, wxID_HTML_INDEXTEXT
, wxEmptyString
,
499 wxDefaultPosition
, wxDefaultSize
,
501 m_IndexButton
= new wxButton(dummy
, wxID_HTML_INDEXBUTTON
, _("Find"));
502 m_IndexButtonAll
= new wxButton(dummy
, wxID_HTML_INDEXBUTTONALL
,
504 m_IndexCountInfo
= new wxStaticText(dummy
, wxID_HTML_COUNTINFO
,
505 wxEmptyString
, wxDefaultPosition
,
507 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
508 m_IndexList
= new wxListBox(dummy
, wxID_HTML_INDEXLIST
,
509 wxDefaultPosition
, wxDefaultSize
,
510 0, NULL
, wxLB_SINGLE
);
513 m_IndexButton
->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
514 m_IndexButtonAll
->SetToolTip(_("Show all items in index"));
515 #endif //wxUSE_TOOLTIPS
517 topsizer
->Add(m_IndexText
, 0, wxEXPAND
| wxALL
, 10);
518 wxSizer
*btsizer
= new wxBoxSizer(wxHORIZONTAL
);
519 btsizer
->Add(m_IndexButton
, 0, wxRIGHT
, 2);
520 btsizer
->Add(m_IndexButtonAll
);
521 topsizer
->Add(btsizer
, 0,
522 wxALIGN_RIGHT
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
523 topsizer
->Add(m_IndexCountInfo
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 2);
524 topsizer
->Add(m_IndexList
, 1, wxEXPAND
| wxALL
, 2);
526 m_NavigNotebook
->AddPage(dummy
, _("Index"));
527 m_IndexPage
= notebook_page
++;
530 // search list panel?
531 if ( helpStyle
& wxHF_SEARCH
)
533 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
535 dummy
->SetWindowVariant(wxWINDOW_VARIANT_NORMAL
);
537 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
539 dummy
->SetSizer(sizer
);
541 m_SearchText
= new wxTextCtrl(dummy
, wxID_HTML_SEARCHTEXT
,
543 wxDefaultPosition
, wxDefaultSize
,
545 m_SearchChoice
= new wxChoice(dummy
, wxID_HTML_SEARCHCHOICE
,
546 wxDefaultPosition
, wxSize(125,wxDefaultCoord
));
547 m_SearchCaseSensitive
= new wxCheckBox(dummy
, wxID_ANY
, _("Case sensitive"));
548 m_SearchWholeWords
= new wxCheckBox(dummy
, wxID_ANY
, _("Whole words only"));
549 m_SearchButton
= new wxButton(dummy
, wxID_HTML_SEARCHBUTTON
, _("Search"));
551 m_SearchButton
->SetToolTip(_("Search contents of help book(s) for all occurrences of the text you typed above"));
552 #endif //wxUSE_TOOLTIPS
553 m_SearchList
= new wxListBox(dummy
, wxID_HTML_SEARCHLIST
,
554 wxDefaultPosition
, wxDefaultSize
,
555 0, NULL
, wxLB_SINGLE
);
557 sizer
->Add(m_SearchText
, 0, wxEXPAND
| wxALL
, 10);
558 sizer
->Add(m_SearchChoice
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
559 sizer
->Add(m_SearchCaseSensitive
, 0, wxLEFT
| wxRIGHT
, 10);
560 sizer
->Add(m_SearchWholeWords
, 0, wxLEFT
| wxRIGHT
, 10);
561 sizer
->Add(m_SearchButton
, 0, wxALL
| wxALIGN_RIGHT
, 8);
562 sizer
->Add(m_SearchList
, 1, wxALL
| wxEXPAND
, 2);
564 m_NavigNotebook
->AddPage(dummy
, _("Search"));
565 m_SearchPage
= notebook_page
;
574 navigSizer
->SetSizeHints(m_NavigPan
);
575 m_NavigPan
->Layout();
579 if ( m_NavigPan
&& m_Splitter
)
581 // The panel will have its own min size which the splitter
584 // m_Splitter->SetMinimumPaneSize(m_NavigPan->GetBestSize().x);
586 m_Splitter
->SetMinimumPaneSize(20);
588 if ( m_Cfg
.navig_on
)
591 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
595 m_NavigPan
->Show(false);
596 m_Splitter
->Initialize(m_HtmlWin
);
600 // Reduce flicker by updating the splitter pane sizes before the
602 wxSizeEvent
sizeEvent(GetSize(), GetId());
603 GetEventHandler()->ProcessEvent(sizeEvent
);
606 m_Splitter
->UpdateSize();
611 wxHtmlHelpWindow::~wxHtmlHelpWindow()
613 if ( m_helpController
)
614 m_helpController
->SetHelpWindow(NULL
);
616 delete m_mergedIndex
;
618 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
621 if (m_NormalFonts
) delete m_NormalFonts
;
622 if (m_FixedFonts
) delete m_FixedFonts
;
625 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
628 #if wxUSE_PRINTING_ARCHITECTURE
629 if (m_Printer
) delete m_Printer
;
633 void wxHtmlHelpWindow::SetController(wxHtmlHelpController
* controller
)
637 m_helpController
= controller
;
638 m_Data
= controller
->GetHelpData();
639 m_DataCreated
= false;
643 void wxHtmlHelpWindow::AddToolbarButtons(wxToolBar
*toolBar
, int style
)
645 wxBitmap wpanelBitmap
=
646 wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL
, wxART_TOOLBAR
);
647 wxBitmap wbackBitmap
=
648 wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_TOOLBAR
);
649 wxBitmap wforwardBitmap
=
650 wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_TOOLBAR
);
651 wxBitmap wupnodeBitmap
=
652 wxArtProvider::GetBitmap(wxART_GO_TO_PARENT
, wxART_TOOLBAR
);
654 wxArtProvider::GetBitmap(wxART_GO_UP
, wxART_TOOLBAR
);
655 wxBitmap wdownBitmap
=
656 wxArtProvider::GetBitmap(wxART_GO_DOWN
, wxART_TOOLBAR
);
657 wxBitmap wopenBitmap
=
658 wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_TOOLBAR
);
659 wxBitmap wprintBitmap
=
660 wxArtProvider::GetBitmap(wxART_PRINT
, wxART_TOOLBAR
);
661 wxBitmap woptionsBitmap
=
662 wxArtProvider::GetBitmap(wxART_HELP_SETTINGS
, wxART_TOOLBAR
);
664 wxASSERT_MSG( (wpanelBitmap
.IsOk() && wbackBitmap
.IsOk() &&
665 wforwardBitmap
.IsOk() && wupnodeBitmap
.IsOk() &&
666 wupBitmap
.IsOk() && wdownBitmap
.IsOk() &&
667 wopenBitmap
.IsOk() && wprintBitmap
.IsOk() &&
668 woptionsBitmap
.IsOk()),
669 wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
672 toolBar
->AddTool(wxID_HTML_PANEL
, wxEmptyString
, wpanelBitmap
, _("Show/hide navigation panel"));
673 toolBar
->AddSeparator();
674 toolBar
->AddTool(wxID_HTML_BACK
, wxEmptyString
, wbackBitmap
, _("Go back"));
675 toolBar
->AddTool(wxID_HTML_FORWARD
, wxEmptyString
, wforwardBitmap
, _("Go forward"));
676 toolBar
->AddSeparator();
677 toolBar
->AddTool(wxID_HTML_UPNODE
, wxEmptyString
, wupnodeBitmap
, _("Go one level up in document hierarchy"));
678 toolBar
->AddTool(wxID_HTML_UP
, wxEmptyString
, wupBitmap
, _("Previous page"));
679 toolBar
->AddTool(wxID_HTML_DOWN
, wxEmptyString
, wdownBitmap
, _("Next page"));
681 if ((style
& wxHF_PRINT
) || (style
& wxHF_OPEN_FILES
))
682 toolBar
->AddSeparator();
684 if (style
& wxHF_OPEN_FILES
)
685 toolBar
->AddTool(wxID_HTML_OPENFILE
, wxEmptyString
, wopenBitmap
, _("Open HTML document"));
687 #if wxUSE_PRINTING_ARCHITECTURE
688 if (style
& wxHF_PRINT
)
689 toolBar
->AddTool(wxID_HTML_PRINT
, wxEmptyString
, wprintBitmap
, _("Print this page"));
692 toolBar
->AddSeparator();
693 toolBar
->AddTool(wxID_HTML_OPTIONS
, wxEmptyString
, woptionsBitmap
, _("Display options dialog"));
695 // Allow application to add custom buttons
696 wxHtmlHelpFrame
* parentFrame
= wxDynamicCast(GetParent(), wxHtmlHelpFrame
);
697 wxHtmlHelpDialog
* parentDialog
= wxDynamicCast(GetParent(), wxHtmlHelpDialog
);
699 parentFrame
->AddToolbarButtons(toolBar
, style
);
701 parentDialog
->AddToolbarButtons(toolBar
, style
);
703 #endif //wxUSE_TOOLBAR
706 bool wxHtmlHelpWindow::Display(const wxString
& x
)
708 wxString url
= m_Data
->FindPageByName(x
);
711 m_HtmlWin
->LoadPage(url
);
718 bool wxHtmlHelpWindow::Display(const int id
)
720 wxString url
= m_Data
->FindPageById(id
);
723 m_HtmlWin
->LoadPage(url
);
730 bool wxHtmlHelpWindow::DisplayContents()
735 if (!m_Splitter
->IsSplit())
739 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
740 m_Cfg
.navig_on
= true;
743 m_NavigNotebook
->SetSelection(m_ContentsPage
);
745 if (m_Data
->GetBookRecArray().GetCount() > 0)
747 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
748 if (!book
.GetStart().empty())
749 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
755 bool wxHtmlHelpWindow::DisplayIndex()
760 if (!m_Splitter
->IsSplit())
764 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
767 m_NavigNotebook
->SetSelection(m_IndexPage
);
769 if (m_Data
->GetBookRecArray().GetCount() > 0)
771 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
772 if (!book
.GetStart().empty())
773 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
779 void wxHtmlHelpWindow::DisplayIndexItem(const wxHtmlHelpMergedIndexItem
*it
)
781 if (it
->items
.size() == 1)
783 if (!it
->items
[0]->page
.empty())
785 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:"),
817 (void**)NULL
, // No client data
818 wxCHOICEDLG_STYLE
& ~wxCENTRE
);
819 if (dlg
.ShowModal() == wxID_OK
)
821 m_HtmlWin
->LoadPage(it
->items
[dlg
.GetSelection()]->GetFullPath());
826 bool wxHtmlHelpWindow::KeywordSearch(const wxString
& keyword
,
827 wxHelpSearchMode mode
)
829 wxCHECK_MSG( !keyword
.empty(), false, "must have a non empty keyword" );
831 if (mode
== wxHELP_SEARCH_ALL
)
833 if ( !(m_SearchList
&&
834 m_SearchButton
&& m_SearchText
&& m_SearchChoice
) )
837 else if (mode
== wxHELP_SEARCH_INDEX
)
839 if ( !(m_IndexList
&&
840 m_IndexButton
&& m_IndexButtonAll
&& m_IndexText
) )
846 wxString book
= wxEmptyString
;
848 if (!m_Splitter
->IsSplit())
852 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
855 if (mode
== wxHELP_SEARCH_ALL
)
857 m_NavigNotebook
->SetSelection(m_SearchPage
);
858 m_SearchList
->Clear();
859 m_SearchText
->SetValue(keyword
);
860 m_SearchButton
->Disable();
862 if (m_SearchChoice
->GetSelection() != 0)
863 book
= m_SearchChoice
->GetStringSelection();
865 wxHtmlSearchStatus
status(m_Data
, keyword
,
866 m_SearchCaseSensitive
->GetValue(),
867 m_SearchWholeWords
->GetValue(),
870 #if wxUSE_PROGRESSDLG
871 wxProgressDialog
progress(_("Searching..."),
872 _("No matching page found yet"),
873 status
.GetMaxIndex(), this,
874 wxPD_APP_MODAL
| wxPD_CAN_ABORT
| wxPD_AUTO_HIDE
);
878 while (status
.IsActive())
880 curi
= status
.GetCurIndex();
882 #if wxUSE_PROGRESSDLG
883 && !progress
.Update(curi
)
889 foundstr
.Printf(_("Found %i matches"), ++foundcnt
);
890 #if wxUSE_PROGRESSDLG
891 progress
.Update(status
.GetCurIndex(), foundstr
);
893 m_SearchList
->Append(status
.GetName(), (void*)status
.GetCurItem());
897 m_SearchButton
->Enable();
898 m_SearchText
->SetSelection(0, keyword
.length());
899 m_SearchText
->SetFocus();
901 else if (mode
== wxHELP_SEARCH_INDEX
)
903 m_NavigNotebook
->SetSelection(m_IndexPage
);
904 m_IndexList
->Clear();
905 m_IndexButton
->Disable();
906 m_IndexButtonAll
->Disable();
907 m_IndexText
->SetValue(keyword
);
910 m_IndexButton
->Enable();
911 m_IndexButtonAll
->Enable();
912 foundcnt
= m_IndexList
->GetCount();
920 wxFAIL_MSG( wxT("unknown help search mode") );
923 case wxHELP_SEARCH_ALL
:
925 wxHtmlHelpDataItem
*it
=
926 (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(0);
929 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;
1030 m_ContentsBox
->SetMinSize(wxSize(CONTENT_TREE_INDEX_MIN_WIDTH
,
1031 m_ContentsBox
->GetMinHeight()));
1034 void wxHtmlHelpWindow::CreateIndex()
1039 m_IndexList
->Clear();
1041 unsigned long cnt
= m_mergedIndex
->size();
1044 if (cnt
> INDEX_IS_SMALL
)
1045 cnttext
.Printf(_("%d of %lu"), 0, cnt
);
1047 cnttext
.Printf(_("%lu of %lu"), cnt
, cnt
);
1048 m_IndexCountInfo
->SetLabel(cnttext
);
1049 if (cnt
> INDEX_IS_SMALL
)
1052 for (size_t i
= 0; i
< cnt
; i
++)
1053 m_IndexList
->Append((*m_mergedIndex
)[i
].name
,
1054 (char*)(&(*m_mergedIndex
)[i
]));
1056 m_IndexList
->SetMinSize(wxSize(CONTENT_TREE_INDEX_MIN_WIDTH
,
1057 m_IndexList
->GetMinHeight()));
1060 void wxHtmlHelpWindow::CreateSearch()
1062 if (! (m_SearchList
&& m_SearchChoice
))
1064 m_SearchList
->Clear();
1065 m_SearchChoice
->Clear();
1066 m_SearchChoice
->Append(_("Search in all books"));
1067 const wxHtmlBookRecArray
& bookrec
= m_Data
->GetBookRecArray();
1068 int i
, cnt
= bookrec
.GetCount();
1069 for (i
= 0; i
< cnt
; i
++)
1070 m_SearchChoice
->Append(bookrec
[i
].GetTitle());
1071 m_SearchChoice
->SetSelection(0);
1074 void wxHtmlHelpWindow::RefreshLists()
1076 // Update m_mergedIndex:
1077 UpdateMergedIndex();
1078 // Update the controls
1085 void wxHtmlHelpWindow::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1090 if (path
!= wxEmptyString
)
1092 oldpath
= cfg
->GetPath();
1093 cfg
->SetPath(wxT("/") + path
);
1096 m_Cfg
.navig_on
= cfg
->Read(wxT("hcNavigPanel"), m_Cfg
.navig_on
) != 0;
1097 m_Cfg
.sashpos
= cfg
->Read(wxT("hcSashPos"), m_Cfg
.sashpos
);
1098 m_Cfg
.x
= cfg
->Read(wxT("hcX"), m_Cfg
.x
);
1099 m_Cfg
.y
= cfg
->Read(wxT("hcY"), m_Cfg
.y
);
1100 m_Cfg
.w
= cfg
->Read(wxT("hcW"), m_Cfg
.w
);
1101 m_Cfg
.h
= cfg
->Read(wxT("hcH"), m_Cfg
.h
);
1103 m_FixedFace
= cfg
->Read(wxT("hcFixedFace"), m_FixedFace
);
1104 m_NormalFace
= cfg
->Read(wxT("hcNormalFace"), m_NormalFace
);
1105 m_FontSize
= cfg
->Read(wxT("hcBaseFontSize"), m_FontSize
);
1112 cnt
= cfg
->Read(wxT("hcBookmarksCnt"), 0L);
1115 m_BookmarksNames
.Clear();
1116 m_BookmarksPages
.Clear();
1119 m_Bookmarks
->Clear();
1120 m_Bookmarks
->Append(_("(bookmarks)"));
1123 for (i
= 0; i
< cnt
; i
++)
1125 val
.Printf(wxT("hcBookmark_%i"), i
);
1127 m_BookmarksNames
.Add(s
);
1128 if (m_Bookmarks
) m_Bookmarks
->Append(s
);
1129 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1131 m_BookmarksPages
.Add(s
);
1137 m_HtmlWin
->ReadCustomization(cfg
);
1139 if (path
!= wxEmptyString
)
1140 cfg
->SetPath(oldpath
);
1143 void wxHtmlHelpWindow::WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
)
1148 if (path
!= wxEmptyString
)
1150 oldpath
= cfg
->GetPath();
1151 cfg
->SetPath(wxT("/") + path
);
1154 cfg
->Write(wxT("hcNavigPanel"), m_Cfg
.navig_on
);
1155 cfg
->Write(wxT("hcSashPos"), (long)m_Cfg
.sashpos
);
1157 // Don't write if iconized as this would make the window
1158 // disappear next time it is shown!
1159 cfg
->Write(wxT("hcX"), (long)m_Cfg
.x
);
1160 cfg
->Write(wxT("hcY"), (long)m_Cfg
.y
);
1161 cfg
->Write(wxT("hcW"), (long)m_Cfg
.w
);
1162 cfg
->Write(wxT("hcH"), (long)m_Cfg
.h
);
1164 cfg
->Write(wxT("hcFixedFace"), m_FixedFace
);
1165 cfg
->Write(wxT("hcNormalFace"), m_NormalFace
);
1166 cfg
->Write(wxT("hcBaseFontSize"), (long)m_FontSize
);
1171 int cnt
= m_BookmarksNames
.GetCount();
1174 cfg
->Write(wxT("hcBookmarksCnt"), (long)cnt
);
1175 for (i
= 0; i
< cnt
; i
++)
1177 val
.Printf(wxT("hcBookmark_%i"), i
);
1178 cfg
->Write(val
, m_BookmarksNames
[i
]);
1179 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1180 cfg
->Write(val
, m_BookmarksPages
[i
]);
1185 m_HtmlWin
->WriteCustomization(cfg
);
1187 if (path
!= wxEmptyString
)
1188 cfg
->SetPath(oldpath
);
1190 #endif // wxUSE_CONFIG
1192 static void SetFontsToHtmlWin(wxHtmlWindow
*win
, const wxString
& scalf
, const wxString
& fixf
, int size
)
1195 f_sizes
[0] = int(size
* 0.6);
1196 f_sizes
[1] = int(size
* 0.8);
1198 f_sizes
[3] = int(size
* 1.2);
1199 f_sizes
[4] = int(size
* 1.4);
1200 f_sizes
[5] = int(size
* 1.6);
1201 f_sizes
[6] = int(size
* 1.8);
1203 win
->SetFonts(scalf
, fixf
, f_sizes
);
1206 class wxHtmlHelpWindowOptionsDialog
: public wxDialog
1209 wxComboBox
*NormalFont
, *FixedFont
;
1210 wxSpinCtrl
*FontSize
;
1211 wxHtmlWindow
*TestWin
;
1213 wxHtmlHelpWindowOptionsDialog(wxWindow
*parent
)
1214 : wxDialog(parent
, wxID_ANY
, wxString(_("Help Browser Options")))
1216 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
1217 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2, 3, 2, 5);
1219 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Normal font:")));
1220 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Fixed font:")));
1221 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Font size:")));
1223 sizer
->Add(NormalFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1224 wxSize(200, wxDefaultCoord
),
1225 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1227 sizer
->Add(FixedFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1228 wxSize(200, wxDefaultCoord
),
1229 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1231 sizer
->Add(FontSize
= new wxSpinCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1232 wxDefaultSize
, wxSP_ARROW_KEYS
, 2, 100, 2, wxT("wxSpinCtrl")));
1234 topsizer
->Add(sizer
, 0, wxLEFT
|wxRIGHT
|wxTOP
, 10);
1236 topsizer
->Add(new wxStaticText(this, wxID_ANY
, _("Preview:")),
1237 0, wxLEFT
| wxTOP
, 10);
1239 topsizer
->AddSpacer(5);
1241 topsizer
->Add(TestWin
= new wxHtmlWindow(this, wxID_ANY
, wxDefaultPosition
, wxSize(20, 150),
1242 wxHW_SCROLLBAR_AUTO
|wxBORDER_THEME
),
1243 1, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
1245 wxBoxSizer
*sizer2
= new wxBoxSizer(wxHORIZONTAL
);
1247 sizer2
->Add(ok
= new wxButton(this, wxID_OK
), 0, wxALL
, 10);
1249 sizer2
->Add(new wxButton(this, wxID_CANCEL
), 0, wxALL
, 10);
1250 topsizer
->Add(sizer2
, 0, wxALIGN_RIGHT
);
1253 topsizer
->Fit(this);
1258 void UpdateTestWin()
1261 SetFontsToHtmlWin(TestWin
,
1262 NormalFont
->GetStringSelection(),
1263 FixedFont
->GetStringSelection(),
1264 FontSize
->GetValue());
1266 wxString
content(_("font size"));
1268 content
= wxT("<font size=-2>") + content
+ wxT(" -2</font><br>")
1269 wxT("<font size=-1>") + content
+ wxT(" -1</font><br>")
1270 wxT("<font size=+0>") + content
+ wxT(" +0</font><br>")
1271 wxT("<font size=+1>") + content
+ wxT(" +1</font><br>")
1272 wxT("<font size=+2>") + content
+ wxT(" +2</font><br>")
1273 wxT("<font size=+3>") + content
+ wxT(" +3</font><br>")
1274 wxT("<font size=+4>") + content
+ wxT(" +4</font><br>") ;
1276 content
= wxString( wxT("<html><body><table><tr><td>") ) +
1277 _("Normal face<br>and <u>underlined</u>. ") +
1278 _("<i>Italic face.</i> ") +
1279 _("<b>Bold face.</b> ") +
1280 _("<b><i>Bold italic face.</i></b><br>") +
1282 wxString( wxT("</td><td><tt>") ) +
1283 _("Fixed size face.<br> <b>bold</b> <i>italic</i> ") +
1284 _("<b><i>bold italic <u>underlined</u></i></b><br>") +
1286 wxT("</tt></td></tr></table></body></html>");
1288 TestWin
->SetPage( content
);
1291 void OnUpdate(wxCommandEvent
& WXUNUSED(event
))
1295 void OnUpdateSpin(wxSpinEvent
& WXUNUSED(event
))
1300 DECLARE_EVENT_TABLE()
1301 wxDECLARE_NO_COPY_CLASS(wxHtmlHelpWindowOptionsDialog
);
1304 BEGIN_EVENT_TABLE(wxHtmlHelpWindowOptionsDialog
, wxDialog
)
1305 EVT_COMBOBOX(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdate
)
1306 EVT_SPINCTRL(wxID_ANY
, wxHtmlHelpWindowOptionsDialog::OnUpdateSpin
)
1309 void wxHtmlHelpWindow::OptionsDialog()
1311 wxHtmlHelpWindowOptionsDialog
dlg(this);
1314 if (m_NormalFonts
== NULL
)
1316 m_NormalFonts
= new wxArrayString(wxFontEnumerator::GetFacenames());
1317 m_NormalFonts
->Sort(); // ascending sort
1319 if (m_FixedFonts
== NULL
)
1321 m_FixedFonts
= new wxArrayString(
1322 wxFontEnumerator::GetFacenames(wxFONTENCODING_SYSTEM
,
1323 true /*enum fixed width only*/));
1324 m_FixedFonts
->Sort(); // ascending sort
1327 // VS: We want to show the font that is actually used by wxHtmlWindow.
1328 // If customization dialog wasn't used yet, facenames are empty and
1329 // wxHtmlWindow uses default fonts -- let's find out what they
1330 // are so that we can pass them to the dialog:
1331 if (m_NormalFace
.empty())
1333 wxFont
fnt(m_FontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false);
1334 m_NormalFace
= fnt
.GetFaceName();
1336 if (m_FixedFace
.empty())
1338 wxFont
fnt(m_FontSize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false);
1339 m_FixedFace
= fnt
.GetFaceName();
1342 for (i
= 0; i
< m_NormalFonts
->GetCount(); i
++)
1343 dlg
.NormalFont
->Append((*m_NormalFonts
)[i
]);
1344 for (i
= 0; i
< m_FixedFonts
->GetCount(); i
++)
1345 dlg
.FixedFont
->Append((*m_FixedFonts
)[i
]);
1346 if (!m_NormalFace
.empty())
1347 dlg
.NormalFont
->SetStringSelection(m_NormalFace
);
1349 dlg
.NormalFont
->SetSelection(0);
1350 if (!m_FixedFace
.empty())
1351 dlg
.FixedFont
->SetStringSelection(m_FixedFace
);
1353 dlg
.FixedFont
->SetSelection(0);
1354 dlg
.FontSize
->SetValue(m_FontSize
);
1355 dlg
.UpdateTestWin();
1357 if (dlg
.ShowModal() == wxID_OK
)
1359 m_NormalFace
= dlg
.NormalFont
->GetStringSelection();
1360 m_FixedFace
= dlg
.FixedFont
->GetStringSelection();
1361 m_FontSize
= dlg
.FontSize
->GetValue();
1362 SetFontsToHtmlWin(m_HtmlWin
, m_NormalFace
, m_FixedFace
, m_FontSize
);
1366 void wxHtmlHelpWindow::NotifyPageChanged()
1368 if (m_UpdateContents
&& m_PagesHash
)
1370 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1371 wxHtmlHelpHashData
*ha
= NULL
;
1373 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1377 bool olduc
= m_UpdateContents
;
1378 m_UpdateContents
= false;
1379 m_ContentsBox
->SelectItem(ha
->m_Id
);
1380 m_ContentsBox
->EnsureVisible(ha
->m_Id
);
1381 m_UpdateContents
= olduc
;
1391 void wxHtmlHelpWindow::OnToolbar(wxCommandEvent
& event
)
1393 switch (event
.GetId())
1395 case wxID_HTML_BACK
:
1396 m_HtmlWin
->HistoryBack();
1399 case wxID_HTML_FORWARD
:
1400 m_HtmlWin
->HistoryForward();
1406 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1407 wxHtmlHelpHashData
*ha
= NULL
;
1409 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1410 if (ha
&& ha
->m_Index
> 0)
1412 const wxHtmlHelpDataItem
& it
= m_Data
->GetContentsArray()[ha
->m_Index
- 1];
1413 if (!it
.page
.empty())
1415 m_HtmlWin
->LoadPage(it
.GetFullPath());
1421 case wxID_HTML_UPNODE
:
1424 wxString page
= wxHtmlHelpHtmlWindow::GetOpenedPageWithAnchor(m_HtmlWin
);
1425 wxHtmlHelpHashData
*ha
= NULL
;
1427 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(page
);
1428 if (ha
&& ha
->m_Index
> 0)
1431 m_Data
->GetContentsArray()[ha
->m_Index
].level
- 1;
1432 int ind
= ha
->m_Index
- 1;
1434 const wxHtmlHelpDataItem
*it
=
1435 &m_Data
->GetContentsArray()[ind
];
1436 while (ind
>= 0 && it
->level
!= level
)
1439 it
= &m_Data
->GetContentsArray()[ind
];
1443 if (!it
->page
.empty())
1444 m_HtmlWin
->LoadPage(it
->GetFullPath());
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())
1466 m_HtmlWin
->LoadPage(contents
[idx
].GetFullPath());
1471 case wxID_HTML_PANEL
:
1473 if (! (m_Splitter
&& m_NavigPan
))
1475 if (m_Splitter
->IsSplit())
1477 m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1478 m_Splitter
->Unsplit(m_NavigPan
);
1479 m_Cfg
.navig_on
= false;
1485 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
1486 m_Cfg
.navig_on
= true;
1491 case wxID_HTML_OPTIONS
:
1495 case wxID_HTML_BOOKMARKSADD
:
1500 item
= m_HtmlWin
->GetOpenedPageTitle();
1501 url
= m_HtmlWin
->GetOpenedPage();
1502 if (item
== wxEmptyString
)
1503 item
= url
.AfterLast(wxT('/'));
1504 if (m_BookmarksPages
.Index(url
) == wxNOT_FOUND
)
1506 m_Bookmarks
->Append(item
);
1507 m_BookmarksNames
.Add(item
);
1508 m_BookmarksPages
.Add(url
);
1513 case wxID_HTML_BOOKMARKSREMOVE
:
1518 item
= m_Bookmarks
->GetStringSelection();
1519 pos
= m_BookmarksNames
.Index(item
);
1520 if (pos
!= wxNOT_FOUND
)
1522 m_BookmarksNames
.RemoveAt(pos
);
1523 m_BookmarksPages
.RemoveAt(pos
);
1524 pos
= m_Bookmarks
->GetSelection();
1525 wxASSERT_MSG( pos
!= wxNOT_FOUND
, wxT("Unknown bookmark position") ) ;
1526 m_Bookmarks
->Delete((unsigned int)pos
);
1531 #if wxUSE_PRINTING_ARCHITECTURE
1532 case wxID_HTML_PRINT
:
1534 if (m_Printer
== NULL
)
1535 m_Printer
= new wxHtmlEasyPrinting(_("Help Printing"), this);
1536 if (!m_HtmlWin
->GetOpenedPage())
1538 wxLogWarning(_("Cannot print empty page."));
1542 m_Printer
->PrintFile(m_HtmlWin
->GetOpenedPage());
1548 case wxID_HTML_OPENFILE
:
1550 wxString filemask
= wxString(
1551 _("HTML files (*.html;*.htm)|*.html;*.htm|")) +
1552 _("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|") +
1553 _("HTML Help Project (*.hhp)|*.hhp|") +
1555 _("Compressed HTML Help file (*.chm)|*.chm|") +
1558 wxString s
= wxFileSelector(_("Open HTML document"),
1563 wxFD_OPEN
| wxFD_FILE_MUST_EXIST
,
1567 wxString ext
= s
.Right(4).Lower();
1568 if (ext
== wxT(".zip") || ext
== wxT(".htb") ||
1570 ext
== wxT(".chm") ||
1579 m_HtmlWin
->LoadPage(s
);
1586 void wxHtmlHelpWindow::OnContentsSel(wxTreeEvent
& event
)
1588 wxHtmlHelpTreeItemData
*pg
;
1590 pg
= (wxHtmlHelpTreeItemData
*) m_ContentsBox
->GetItemData(event
.GetItem());
1592 if (pg
&& m_UpdateContents
)
1594 const wxHtmlHelpDataItems
& contents
= m_Data
->GetContentsArray();
1595 m_UpdateContents
= false;
1596 if (!contents
[pg
->m_Id
].page
.empty())
1597 m_HtmlWin
->LoadPage(contents
[pg
->m_Id
].GetFullPath());
1598 m_UpdateContents
= true;
1602 void wxHtmlHelpWindow::OnIndexSel(wxCommandEvent
& WXUNUSED(event
))
1604 wxHtmlHelpMergedIndexItem
*it
= (wxHtmlHelpMergedIndexItem
*)
1605 m_IndexList
->GetClientData(m_IndexList
->GetSelection());
1607 DisplayIndexItem(it
);
1610 void wxHtmlHelpWindow::OnIndexFind(wxCommandEvent
& WXUNUSED(event
))
1615 void wxHtmlHelpWindow::DoIndexFind()
1617 wxString sr
= m_IndexText
->GetLineText(0);
1619 if (sr
== wxEmptyString
)
1627 m_IndexList
->Clear();
1628 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1629 size_t cnt
= index
.size();
1632 for (size_t i
= 0; i
< cnt
; i
++)
1634 if (index
[i
].name
.Lower().find(sr
) != wxString::npos
)
1636 int pos
= m_IndexList
->Append(index
[i
].name
,
1637 (char*)(&index
[i
]));
1641 // don't automatically show topic selector if this
1642 // item points to multiple pages:
1643 if (index
[i
].items
.size() == 1)
1645 m_IndexList
->SetSelection(0);
1646 DisplayIndexItem(&index
[i
]);
1650 // if this is nested item of the index, show its parent(s)
1651 // as well, otherwise it would not be clear what entry is
1653 wxHtmlHelpMergedIndexItem
*parent
= index
[i
].parent
;
1657 (index
.Index(*(wxHtmlHelpMergedIndexItem
*)m_IndexList
->GetClientData(pos
-1))) < index
.Index(*parent
))
1659 m_IndexList
->Insert(parent
->name
,
1660 pos
, (char*)parent
);
1661 parent
= parent
->parent
;
1666 // finally, it the item we just added is itself a parent for
1667 // other items, show them as well, because they are refinements
1668 // of the displayed index entry (i.e. it is implicitly contained
1669 // in them: "foo" with parent "bar" reads as "bar, foo"):
1670 int level
= index
[i
].items
[0]->level
;
1672 while (i
< cnt
&& index
[i
].items
[0]->level
> level
)
1674 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1682 cnttext
.Printf(_("%i of %i"), displ
, cnt
);
1683 m_IndexCountInfo
->SetLabel(cnttext
);
1685 m_IndexText
->SetSelection(0, sr
.length());
1686 m_IndexText
->SetFocus();
1690 void wxHtmlHelpWindow::OnIndexAll(wxCommandEvent
& WXUNUSED(event
))
1695 void wxHtmlHelpWindow::DoIndexAll()
1699 m_IndexList
->Clear();
1700 const wxHtmlHelpMergedIndex
& index
= *m_mergedIndex
;
1701 size_t cnt
= index
.size();
1704 for (size_t i
= 0; i
< cnt
; i
++)
1706 m_IndexList
->Append(index
[i
].name
, (char*)(&index
[i
]));
1709 // don't automatically show topic selector if this
1710 // item points to multiple pages:
1711 if (index
[i
].items
.size() == 1)
1713 DisplayIndexItem(&index
[i
]);
1720 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1721 m_IndexCountInfo
->SetLabel(cnttext
);
1724 void wxHtmlHelpWindow::OnSearchSel(wxCommandEvent
& WXUNUSED(event
))
1726 wxHtmlHelpDataItem
*it
= (wxHtmlHelpDataItem
*) m_SearchList
->GetClientData(m_SearchList
->GetSelection());
1729 if (!it
->page
.empty())
1730 m_HtmlWin
->LoadPage(it
->GetFullPath());
1734 void wxHtmlHelpWindow::OnSearch(wxCommandEvent
& WXUNUSED(event
))
1736 wxString sr
= m_SearchText
->GetLineText(0);
1739 KeywordSearch(sr
, wxHELP_SEARCH_ALL
);
1742 void wxHtmlHelpWindow::OnBookmarksSel(wxCommandEvent
& WXUNUSED(event
))
1744 wxString str
= m_Bookmarks
->GetStringSelection();
1745 int idx
= m_BookmarksNames
.Index(str
);
1746 if (!str
.empty() && str
!= _("(bookmarks)") && idx
!= wxNOT_FOUND
)
1748 m_HtmlWin
->LoadPage(m_BookmarksPages
[(size_t)idx
]);
1752 void wxHtmlHelpWindow::OnSize(wxSizeEvent
& WXUNUSED(event
))
1757 #endif // wxUSE_WXHTML_HELP