1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlHelpFrame
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "helpfrm.h"
16 // For compilers that support precompilation, includes "wx.h"
18 #include "wx/wxprec.h"
30 #include "wx/object.h"
33 #include "wx/bmpbuttn.h"
34 #include "wx/statbox.h"
35 #include "wx/radiobox.h"
40 #include "wx/msgdlg.h"
43 #include "wx/html/helpfrm.h"
44 #include "wx/html/helpctrl.h"
45 #include "wx/textctrl.h"
46 #include "wx/notebook.h"
47 #include "wx/imaglist.h"
48 #include "wx/treectrl.h"
49 #include "wx/tokenzr.h"
50 #include "wx/wfstream.h"
51 #include "wx/html/htmlwin.h"
52 #include "wx/busyinfo.h"
53 #include "wx/progdlg.h"
54 #include "wx/toolbar.h"
55 #include "wx/fontenum.h"
56 #include "wx/stream.h"
57 #include "wx/filedlg.h"
58 #include "wx/artprov.h"
59 #include "wx/spinctrl.h"
61 // what is considered "small index"?
62 #define INDEX_IS_SMALL 100
64 /* Motif defines this as a macro */
69 //--------------------------------------------------------------------------
70 // wxHtmlHelpTreeItemData (private)
71 //--------------------------------------------------------------------------
73 class wxHtmlHelpTreeItemData
: public wxTreeItemData
76 #if defined(__VISAGECPP__)
77 // VA needs a default ctor for some reason....
78 wxHtmlHelpTreeItemData() : wxTreeItemData()
81 wxHtmlHelpTreeItemData(int id
) : wxTreeItemData()
88 //--------------------------------------------------------------------------
89 // wxHtmlHelpHashData (private)
90 //--------------------------------------------------------------------------
92 class wxHtmlHelpHashData
: public wxObject
95 wxHtmlHelpHashData(int index
, wxTreeItemId id
) : wxObject()
96 { m_Index
= index
; m_Id
= id
;}
97 ~wxHtmlHelpHashData() {}
104 //--------------------------------------------------------------------------
105 // wxHtmlHelpHtmlWindow (private)
106 //--------------------------------------------------------------------------
108 class wxHtmlHelpHtmlWindow
: public wxHtmlWindow
111 wxHtmlHelpHtmlWindow(wxHtmlHelpFrame
*fr
, wxWindow
*parent
) : wxHtmlWindow(parent
), m_Frame(fr
) {}
113 virtual void OnLinkClicked(const wxHtmlLinkInfo
& link
)
115 wxHtmlWindow::OnLinkClicked(link
);
116 const wxMouseEvent
*e
= link
.GetEvent();
117 if (e
== NULL
|| e
->LeftUp())
118 m_Frame
->NotifyPageChanged();
122 wxHtmlHelpFrame
*m_Frame
;
124 DECLARE_NO_COPY_CLASS(wxHtmlHelpHtmlWindow
)
129 //---------------------------------------------------------------------------
131 //---------------------------------------------------------------------------
136 //wxID_HTML_HELPFRAME = wxID_HIGHEST + 1,
137 wxID_HTML_PANEL
= wxID_HIGHEST
+ 2,
146 wxID_HTML_BOOKMARKSLIST
,
147 wxID_HTML_BOOKMARKSADD
,
148 wxID_HTML_BOOKMARKSREMOVE
,
153 wxID_HTML_INDEXBUTTON
,
154 wxID_HTML_INDEXBUTTONALL
,
156 wxID_HTML_SEARCHPAGE
,
157 wxID_HTML_SEARCHTEXT
,
158 wxID_HTML_SEARCHLIST
,
159 wxID_HTML_SEARCHBUTTON
,
160 wxID_HTML_SEARCHCHOICE
,
165 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame
, wxFrame
)
167 wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow
* parent
, wxWindowID id
, const wxString
& title
,
168 int style
, wxHtmlHelpData
* data
)
171 Create(parent
, id
, title
, style
);
174 void wxHtmlHelpFrame::Init(wxHtmlHelpData
* data
)
179 m_DataCreated
= FALSE
;
182 m_Data
= new wxHtmlHelpData();
183 m_DataCreated
= TRUE
;
186 m_ContentsBox
= NULL
;
188 m_IndexButton
= NULL
;
189 m_IndexButtonAll
= NULL
;
192 m_SearchButton
= NULL
;
194 m_SearchChoice
= NULL
;
195 m_IndexCountInfo
= NULL
;
198 m_NavigNotebook
= NULL
;
201 m_SearchCaseSensitive
= NULL
;
202 m_SearchWholeWords
= NULL
;
205 m_ConfigRoot
= wxEmptyString
;
207 m_Cfg
.x
= m_Cfg
.y
= 0;
211 m_Cfg
.navig_on
= TRUE
;
213 m_NormalFonts
= m_FixedFonts
= NULL
;
214 m_NormalFace
= m_FixedFace
= wxEmptyString
;
221 #if wxUSE_PRINTING_ARCHITECTURE
226 m_UpdateContents
= TRUE
;
227 m_helpController
= (wxHelpControllerBase
*) NULL
;
230 // Create: builds the GUI components.
231 // with the style flag it's possible to toggle the toolbar, contents, index and search
233 // m_HtmlWin will *always* be created, but it's important to realize that
234 // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
235 // m_SearchButton may be NULL.
236 // moreover, if no contents, index or searchpage is needed, m_Splitter and
237 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
239 bool wxHtmlHelpFrame::Create(wxWindow
* parent
, wxWindowID id
,
240 const wxString
& WXUNUSED(title
), int style
)
244 wxImageList
*ContentsImageList
= new wxImageList(16, 16);
245 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK
, wxART_HELP_BROWSER
));
246 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER
, wxART_HELP_BROWSER
));
247 ContentsImageList
->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE
, wxART_HELP_BROWSER
));
249 // Do the config in two steps. We read the HtmlWindow customization after we
250 // create the window.
252 ReadCustomization(m_Config
, m_ConfigRoot
);
254 wxFrame::Create(parent
, id
, _("Help"),
255 wxPoint(m_Cfg
.x
, m_Cfg
.y
), wxSize(m_Cfg
.w
, m_Cfg
.h
),
256 wxDEFAULT_FRAME_STYLE
, wxT("wxHtmlHelp"));
258 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
260 SetIcon(wxArtProvider::GetIcon(wxART_HELP
, wxART_HELP_BROWSER
));
262 // On the Mac, each modeless frame must have a menubar.
263 // TODO: add more menu items, and perhaps add a style to show
264 // the menubar: compulsory on the Mac, optional elsewhere.
266 wxMenuBar
* menuBar
= new wxMenuBar
;
268 wxMenu
* fileMenu
= new wxMenu
;
269 fileMenu
->Append(wxID_HTML_OPENFILE
, _("&Open..."));
270 fileMenu
->AppendSeparator();
271 fileMenu
->Append(wxID_CLOSE
, _("&Close"));
273 wxMenu
* helpMenu
= new wxMenu
;
274 helpMenu
->Append(wxID_ABOUT
, _("&About..."));
276 menuBar
->Append(fileMenu
,_("File"));
277 menuBar
->Append(helpMenu
,_("Help"));
281 int notebook_page
= 0;
286 if (style
& (wxHF_TOOLBAR
| wxHF_FLAT_TOOLBAR
))
288 wxToolBar
*toolBar
= CreateToolBar(wxNO_BORDER
| wxTB_HORIZONTAL
|
290 (style
& wxHF_FLAT_TOOLBAR
? wxTB_FLAT
: 0));
291 toolBar
->SetMargins( 2, 2 );
292 AddToolbarButtons(toolBar
, style
);
296 wxSizer
*navigSizer
= NULL
;
298 if (style
& (wxHF_CONTENTS
| wxHF_INDEX
| wxHF_SEARCH
))
300 // traditional help controller; splitter window with html page on the
301 // right and a notebook containing various pages on the left
302 m_Splitter
= new wxSplitterWindow(this);
304 m_HtmlWin
= new wxHtmlHelpHtmlWindow(this, m_Splitter
);
305 m_NavigPan
= new wxPanel(m_Splitter
, -1);
306 m_NavigNotebook
= new wxNotebook(m_NavigPan
, wxID_HTML_NOTEBOOK
,
307 wxDefaultPosition
, wxDefaultSize
);
308 wxNotebookSizer
*nbs
= new wxNotebookSizer(m_NavigNotebook
);
310 navigSizer
= new wxBoxSizer(wxVERTICAL
);
311 navigSizer
->Add(nbs
, 1, wxEXPAND
);
313 m_NavigPan
->SetAutoLayout(TRUE
);
314 m_NavigPan
->SetSizer(navigSizer
);
317 { // only html window, no notebook with index,contents etc
318 m_HtmlWin
= new wxHtmlWindow(this);
321 m_HtmlWin
->SetRelatedFrame(this, m_TitleFormat
);
322 m_HtmlWin
->SetRelatedStatusBar(0);
324 m_HtmlWin
->ReadCustomization(m_Config
, m_ConfigRoot
);
326 // contents tree panel?
327 if ( style
& wxHF_CONTENTS
)
329 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
330 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
332 topsizer
->Add(0, 10);
334 dummy
->SetAutoLayout(TRUE
);
335 dummy
->SetSizer(topsizer
);
337 if ( style
& wxHF_BOOKMARKS
)
339 m_Bookmarks
= new wxComboBox(dummy
, wxID_HTML_BOOKMARKSLIST
,
341 wxDefaultPosition
, wxDefaultSize
,
342 0, NULL
, wxCB_READONLY
| wxCB_SORT
);
343 m_Bookmarks
->Append(_("(bookmarks)"));
344 for (unsigned i
= 0; i
< m_BookmarksNames
.GetCount(); i
++)
345 m_Bookmarks
->Append(m_BookmarksNames
[i
]);
346 m_Bookmarks
->SetSelection(0);
348 wxBitmapButton
*bmpbt1
, *bmpbt2
;
349 bmpbt1
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSADD
,
350 wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK
,
351 wxART_HELP_BROWSER
));
352 bmpbt2
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSREMOVE
,
353 wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK
,
354 wxART_HELP_BROWSER
));
356 bmpbt1
->SetToolTip(_("Add current page to bookmarks"));
357 bmpbt2
->SetToolTip(_("Remove current page from bookmarks"));
358 #endif // wxUSE_TOOLTIPS
360 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
362 sizer
->Add(m_Bookmarks
, 1, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 5);
363 sizer
->Add(bmpbt1
, 0, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 2);
364 sizer
->Add(bmpbt2
, 0, wxALIGN_CENTRE_VERTICAL
, 0);
366 topsizer
->Add(sizer
, 0, wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
, 10);
369 m_ContentsBox
= new wxTreeCtrl(dummy
, wxID_HTML_TREECTRL
,
370 wxDefaultPosition
, wxDefaultSize
,
372 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
375 m_ContentsBox
->AssignImageList(ContentsImageList
);
377 topsizer
->Add(m_ContentsBox
, 1, wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
, 2);
379 m_NavigNotebook
->AddPage(dummy
, _("Contents"));
380 m_ContentsPage
= notebook_page
++;
383 // index listbox panel?
384 if ( style
& wxHF_INDEX
)
386 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
387 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
389 dummy
->SetAutoLayout(TRUE
);
390 dummy
->SetSizer(topsizer
);
392 m_IndexText
= new wxTextCtrl(dummy
, wxID_HTML_INDEXTEXT
, wxEmptyString
,
393 wxDefaultPosition
, wxDefaultSize
,
395 m_IndexButton
= new wxButton(dummy
, wxID_HTML_INDEXBUTTON
, _("Find"));
396 m_IndexButtonAll
= new wxButton(dummy
, wxID_HTML_INDEXBUTTONALL
,
398 m_IndexCountInfo
= new wxStaticText(dummy
, wxID_HTML_COUNTINFO
,
399 wxEmptyString
, wxDefaultPosition
,
401 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
402 m_IndexList
= new wxListBox(dummy
, wxID_HTML_INDEXLIST
,
403 wxDefaultPosition
, wxDefaultSize
,
404 0, NULL
, wxLB_SINGLE
);
407 m_IndexButton
->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
408 m_IndexButtonAll
->SetToolTip(_("Show all items in index"));
409 #endif //wxUSE_TOOLTIPS
411 topsizer
->Add(m_IndexText
, 0, wxEXPAND
| wxALL
, 10);
412 wxSizer
*btsizer
= new wxBoxSizer(wxHORIZONTAL
);
413 btsizer
->Add(m_IndexButton
, 0, wxRIGHT
, 2);
414 btsizer
->Add(m_IndexButtonAll
);
415 topsizer
->Add(btsizer
, 0,
416 wxALIGN_RIGHT
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
417 topsizer
->Add(m_IndexCountInfo
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 2);
418 topsizer
->Add(m_IndexList
, 1, wxEXPAND
| wxALL
, 2);
420 m_NavigNotebook
->AddPage(dummy
, _("Index"));
421 m_IndexPage
= notebook_page
++;
424 // search list panel?
425 if ( style
& wxHF_SEARCH
)
427 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
428 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
430 dummy
->SetAutoLayout(TRUE
);
431 dummy
->SetSizer(sizer
);
433 m_SearchText
= new wxTextCtrl(dummy
, wxID_HTML_SEARCHTEXT
,
435 wxDefaultPosition
, wxDefaultSize
,
437 m_SearchChoice
= new wxChoice(dummy
, wxID_HTML_SEARCHCHOICE
,
438 wxDefaultPosition
, wxDefaultSize
);
439 m_SearchCaseSensitive
= new wxCheckBox(dummy
, -1, _("Case sensitive"));
440 m_SearchWholeWords
= new wxCheckBox(dummy
, -1, _("Whole words only"));
441 m_SearchButton
= new wxButton(dummy
, wxID_HTML_SEARCHBUTTON
, _("Search"));
443 m_SearchButton
->SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
444 #endif //wxUSE_TOOLTIPS
445 m_SearchList
= new wxListBox(dummy
, wxID_HTML_SEARCHLIST
,
446 wxDefaultPosition
, wxDefaultSize
,
447 0, NULL
, wxLB_SINGLE
);
449 sizer
->Add(m_SearchText
, 0, wxEXPAND
| wxALL
, 10);
450 sizer
->Add(m_SearchChoice
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
451 sizer
->Add(m_SearchCaseSensitive
, 0, wxLEFT
| wxRIGHT
, 10);
452 sizer
->Add(m_SearchWholeWords
, 0, wxLEFT
| wxRIGHT
, 10);
453 sizer
->Add(m_SearchButton
, 0, wxALL
| wxALIGN_RIGHT
, 8);
454 sizer
->Add(m_SearchList
, 1, wxALL
| wxEXPAND
, 2);
456 m_NavigNotebook
->AddPage(dummy
, _("Search"));
457 m_SearchPage
= notebook_page
++;
460 m_HtmlWin
->Show(TRUE
);
466 navigSizer
->SetSizeHints(m_NavigPan
);
467 m_NavigPan
->Layout();
471 if ( m_NavigPan
&& m_Splitter
)
473 m_Splitter
->SetMinimumPaneSize(20);
474 if ( m_Cfg
.navig_on
)
475 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
477 if ( m_Cfg
.navig_on
)
479 m_NavigPan
->Show(TRUE
);
480 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
484 m_NavigPan
->Show(FALSE
);
485 m_Splitter
->Initialize(m_HtmlWin
);
492 wxHtmlHelpFrame::~wxHtmlHelpFrame()
494 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
497 if (m_NormalFonts
) delete m_NormalFonts
;
498 if (m_FixedFonts
) delete m_FixedFonts
;
501 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
507 void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar
*toolBar
, int style
)
509 wxBitmap wpanelBitmap
=
510 wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL
, wxART_HELP_BROWSER
);
511 wxBitmap wbackBitmap
=
512 wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_HELP_BROWSER
);
513 wxBitmap wforwardBitmap
=
514 wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_HELP_BROWSER
);
515 wxBitmap wupnodeBitmap
=
516 wxArtProvider::GetBitmap(wxART_GO_TO_PARENT
, wxART_HELP_BROWSER
);
518 wxArtProvider::GetBitmap(wxART_GO_UP
, wxART_HELP_BROWSER
);
519 wxBitmap wdownBitmap
=
520 wxArtProvider::GetBitmap(wxART_GO_DOWN
, wxART_HELP_BROWSER
);
521 wxBitmap wopenBitmap
=
522 wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_HELP_BROWSER
);
523 wxBitmap wprintBitmap
=
524 wxArtProvider::GetBitmap(wxART_PRINT
, wxART_HELP_BROWSER
);
525 wxBitmap woptionsBitmap
=
526 wxArtProvider::GetBitmap(wxART_HELP_SETTINGS
, wxART_HELP_BROWSER
);
528 wxASSERT_MSG( (wpanelBitmap
.Ok() && wbackBitmap
.Ok() &&
529 wforwardBitmap
.Ok() && wupnodeBitmap
.Ok() &&
530 wupBitmap
.Ok() && wdownBitmap
.Ok() &&
531 wopenBitmap
.Ok() && wprintBitmap
.Ok() &&
532 woptionsBitmap
.Ok()),
533 wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
536 toolBar
->AddTool(wxID_HTML_PANEL
, wpanelBitmap
, wxNullBitmap
,
537 FALSE
, -1, -1, (wxObject
*) NULL
,
538 _("Show/hide navigation panel"));
540 toolBar
->AddSeparator();
541 toolBar
->AddTool(wxID_HTML_BACK
, wbackBitmap
, wxNullBitmap
,
542 FALSE
, -1, -1, (wxObject
*) NULL
,
544 toolBar
->AddTool(wxID_HTML_FORWARD
, wforwardBitmap
, wxNullBitmap
,
545 FALSE
, -1, -1, (wxObject
*) NULL
,
547 toolBar
->AddSeparator();
549 toolBar
->AddTool(wxID_HTML_UPNODE
, wupnodeBitmap
, wxNullBitmap
,
550 FALSE
, -1, -1, (wxObject
*) NULL
,
551 _("Go one level up in document hierarchy"));
552 toolBar
->AddTool(wxID_HTML_UP
, wupBitmap
, wxNullBitmap
,
553 FALSE
, -1, -1, (wxObject
*) NULL
,
555 toolBar
->AddTool(wxID_HTML_DOWN
, wdownBitmap
, wxNullBitmap
,
556 FALSE
, -1, -1, (wxObject
*) NULL
,
559 if ((style
& wxHF_PRINT
) || (style
& wxHF_OPEN_FILES
))
560 toolBar
->AddSeparator();
562 if (style
& wxHF_OPEN_FILES
)
563 toolBar
->AddTool(wxID_HTML_OPENFILE
, wopenBitmap
, wxNullBitmap
,
564 FALSE
, -1, -1, (wxObject
*) NULL
,
565 _("Open HTML document"));
567 #if wxUSE_PRINTING_ARCHITECTURE
568 if (style
& wxHF_PRINT
)
569 toolBar
->AddTool(wxID_HTML_PRINT
, wprintBitmap
, wxNullBitmap
,
570 FALSE
, -1, -1, (wxObject
*) NULL
,
571 _("Print this page"));
574 toolBar
->AddSeparator();
575 toolBar
->AddTool(wxID_HTML_OPTIONS
, woptionsBitmap
, wxNullBitmap
,
576 FALSE
, -1, -1, (wxObject
*) NULL
,
577 _("Display options dialog"));
581 void wxHtmlHelpFrame::SetTitleFormat(const wxString
& format
)
584 m_HtmlWin
->SetRelatedFrame(this, format
);
585 m_TitleFormat
= format
;
589 bool wxHtmlHelpFrame::Display(const wxString
& x
)
591 wxString url
= m_Data
->FindPageByName(x
);
594 m_HtmlWin
->LoadPage(url
);
601 bool wxHtmlHelpFrame::Display(const int id
)
603 wxString url
= m_Data
->FindPageById(id
);
606 m_HtmlWin
->LoadPage(url
);
615 bool wxHtmlHelpFrame::DisplayContents()
619 if (!m_Splitter
->IsSplit())
621 m_NavigPan
->Show(TRUE
);
622 m_HtmlWin
->Show(TRUE
);
623 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
624 m_Cfg
.navig_on
= TRUE
;
626 m_NavigNotebook
->SetSelection(0);
627 if (m_Data
->GetBookRecArray().GetCount() > 0)
629 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
630 if (!book
.GetStart().IsEmpty())
631 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
638 bool wxHtmlHelpFrame::DisplayIndex()
642 if (!m_Splitter
->IsSplit())
644 m_NavigPan
->Show(TRUE
);
645 m_HtmlWin
->Show(TRUE
);
646 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
648 m_NavigNotebook
->SetSelection(1);
649 if (m_Data
->GetBookRecArray().GetCount() > 0)
651 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
652 if (!book
.GetStart().IsEmpty())
653 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
660 bool wxHtmlHelpFrame::KeywordSearch(const wxString
& keyword
)
662 if (! (m_SearchList
&& m_SearchButton
&& m_SearchText
&& m_SearchChoice
))
665 int foundcnt
= 0, curi
;
667 wxString book
= wxEmptyString
;
669 if (!m_Splitter
->IsSplit())
671 m_NavigPan
->Show(TRUE
);
672 m_HtmlWin
->Show(TRUE
);
673 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
675 m_NavigNotebook
->SetSelection(m_SearchPage
);
676 m_SearchList
->Clear();
677 m_SearchText
->SetValue(keyword
);
678 m_SearchButton
->Enable(FALSE
);
680 if (m_SearchChoice
->GetSelection() != 0)
681 book
= m_SearchChoice
->GetStringSelection();
683 wxHtmlSearchStatus
status(m_Data
, keyword
,
684 m_SearchCaseSensitive
->GetValue(), m_SearchWholeWords
->GetValue(),
687 wxProgressDialog
progress(_("Searching..."), _("No matching page found yet"),
688 status
.GetMaxIndex(), this,
689 wxPD_APP_MODAL
| wxPD_CAN_ABORT
| wxPD_AUTO_HIDE
);
691 while (status
.IsActive())
693 curi
= status
.GetCurIndex();
694 if (curi
% 32 == 0 && progress
.Update(curi
) == FALSE
)
698 foundstr
.Printf(_("Found %i matches"), ++foundcnt
);
699 progress
.Update(status
.GetCurIndex(), foundstr
);
700 m_SearchList
->Append(status
.GetName(), status
.GetContentsItem());
704 m_SearchButton
->Enable(TRUE
);
705 m_SearchText
->SetSelection(0, keyword
.Length());
706 m_SearchText
->SetFocus();
709 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_SearchList
->GetClientData(0);
712 m_HtmlWin
->LoadPage(it
->GetFullPath());
716 return (foundcnt
> 0);
719 void wxHtmlHelpFrame::CreateContents()
726 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
729 m_PagesHash
= new wxHashTable(wxKEY_STRING
, 2 * m_Data
->GetContentsCnt());
731 int cnt
= m_Data
->GetContentsCnt();
734 wxHtmlContentsItem
*it
;
736 const int MAX_ROOTS
= 64;
737 wxTreeItemId roots
[MAX_ROOTS
];
738 // VS: this array holds information about whether we've set item icon at
739 // given level. This is neccessary because m_Data has flat structure
740 // and there's no way of recognizing if some item has subitems or not.
741 // We set the icon later: when we find an item with level=n, we know
742 // that the last item with level=n-1 was folder with subitems, so we
743 // set its icon accordingly
744 bool imaged
[MAX_ROOTS
];
745 m_ContentsBox
->DeleteAllItems();
747 roots
[0] = m_ContentsBox
->AddRoot(_("(Help)"));
750 for (it
= m_Data
->GetContents(), i
= 0; i
< cnt
; i
++, it
++)
753 if (it
->m_Level
== 0)
755 if (m_hfStyle
& wxHF_MERGE_BOOKS
)
756 // VS: we don't want book nodes, books' content should
757 // appear under tree's root. This line will create "fake"
758 // record about book node so that the rest of this look
759 // will believe there really _is_ book node and will
764 roots
[1] = m_ContentsBox
->AppendItem(roots
[0],
765 it
->m_Name
, IMG_Book
, -1,
766 new wxHtmlHelpTreeItemData(i
));
767 m_ContentsBox
->SetItemBold(roots
[1], TRUE
);
771 // ...and their contents:
774 roots
[it
->m_Level
+ 1] = m_ContentsBox
->AppendItem(
775 roots
[it
->m_Level
], it
->m_Name
, IMG_Page
,
776 -1, new wxHtmlHelpTreeItemData(i
));
777 imaged
[it
->m_Level
+ 1] = FALSE
;
780 m_PagesHash
->Put(it
->GetFullPath(),
781 new wxHtmlHelpHashData(i
, roots
[it
->m_Level
+ 1]));
783 // Set the icon for the node one level up in the hiearachy,
784 // unless already done (see comment above imaged[] declaration)
785 if (!imaged
[it
->m_Level
])
787 int image
= IMG_Folder
;
788 if (m_hfStyle
& wxHF_ICONS_BOOK
)
790 else if (m_hfStyle
& wxHF_ICONS_BOOK_CHAPTER
)
791 image
= (it
->m_Level
== 1) ? IMG_Book
: IMG_Folder
;
792 m_ContentsBox
->SetItemImage(roots
[it
->m_Level
], image
);
793 m_ContentsBox
->SetItemImage(roots
[it
->m_Level
], image
,
794 wxTreeItemIcon_Selected
);
795 imaged
[it
->m_Level
] = TRUE
;
801 void wxHtmlHelpFrame::CreateIndex()
806 m_IndexList
->Clear();
808 int cnt
= m_Data
->GetIndexCnt();
811 if (cnt
> INDEX_IS_SMALL
) cnttext
.Printf(_("%i of %i"), 0, cnt
);
812 else cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
813 m_IndexCountInfo
->SetLabel(cnttext
);
814 if (cnt
> INDEX_IS_SMALL
) return;
816 wxHtmlContentsItem
* index
= m_Data
->GetIndex();
818 for (int i
= 0; i
< cnt
; i
++)
819 m_IndexList
->Append(index
[i
].m_Name
, (char*)(index
+ i
));
822 void wxHtmlHelpFrame::CreateSearch()
824 if (! (m_SearchList
&& m_SearchChoice
))
826 m_SearchList
->Clear();
827 m_SearchChoice
->Clear();
828 m_SearchChoice
->Append(_("Search in all books"));
829 const wxHtmlBookRecArray
& bookrec
= m_Data
->GetBookRecArray();
830 int i
, cnt
= bookrec
.GetCount();
831 for (i
= 0; i
< cnt
; i
++)
832 m_SearchChoice
->Append(bookrec
[i
].GetTitle());
833 m_SearchChoice
->SetSelection(0);
837 void wxHtmlHelpFrame::RefreshLists()
844 void wxHtmlHelpFrame::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
849 if (path
!= wxEmptyString
)
851 oldpath
= cfg
->GetPath();
852 cfg
->SetPath(_T("/") + path
);
855 m_Cfg
.navig_on
= cfg
->Read(wxT("hcNavigPanel"), m_Cfg
.navig_on
) != 0;
856 m_Cfg
.sashpos
= cfg
->Read(wxT("hcSashPos"), m_Cfg
.sashpos
);
857 m_Cfg
.x
= cfg
->Read(wxT("hcX"), m_Cfg
.x
);
858 m_Cfg
.y
= cfg
->Read(wxT("hcY"), m_Cfg
.y
);
859 m_Cfg
.w
= cfg
->Read(wxT("hcW"), m_Cfg
.w
);
860 m_Cfg
.h
= cfg
->Read(wxT("hcH"), m_Cfg
.h
);
862 m_FixedFace
= cfg
->Read(wxT("hcFixedFace"), m_FixedFace
);
863 m_NormalFace
= cfg
->Read(wxT("hcNormalFace"), m_NormalFace
);
864 m_FontSize
= cfg
->Read(wxT("hcBaseFontSize"), m_FontSize
);
871 cnt
= cfg
->Read(wxT("hcBookmarksCnt"), 0L);
874 m_BookmarksNames
.Clear();
875 m_BookmarksPages
.Clear();
878 m_Bookmarks
->Clear();
879 m_Bookmarks
->Append(_("(bookmarks)"));
882 for (i
= 0; i
< cnt
; i
++)
884 val
.Printf(wxT("hcBookmark_%i"), i
);
886 m_BookmarksNames
.Add(s
);
887 if (m_Bookmarks
) m_Bookmarks
->Append(s
);
888 val
.Printf(wxT("hcBookmark_%i_url"), i
);
890 m_BookmarksPages
.Add(s
);
896 m_HtmlWin
->ReadCustomization(cfg
);
898 if (path
!= wxEmptyString
)
899 cfg
->SetPath(oldpath
);
902 void wxHtmlHelpFrame::WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
)
907 if (path
!= wxEmptyString
)
909 oldpath
= cfg
->GetPath();
910 cfg
->SetPath(_T("/") + path
);
913 cfg
->Write(wxT("hcNavigPanel"), m_Cfg
.navig_on
);
914 cfg
->Write(wxT("hcSashPos"), (long)m_Cfg
.sashpos
);
917 // Don't write if iconized as this would make the window
918 // disappear next time it is shown!
919 cfg
->Write(wxT("hcX"), (long)m_Cfg
.x
);
920 cfg
->Write(wxT("hcY"), (long)m_Cfg
.y
);
921 cfg
->Write(wxT("hcW"), (long)m_Cfg
.w
);
922 cfg
->Write(wxT("hcH"), (long)m_Cfg
.h
);
924 cfg
->Write(wxT("hcFixedFace"), m_FixedFace
);
925 cfg
->Write(wxT("hcNormalFace"), m_NormalFace
);
926 cfg
->Write(wxT("hcBaseFontSize"), (long)m_FontSize
);
931 int cnt
= m_BookmarksNames
.GetCount();
934 cfg
->Write(wxT("hcBookmarksCnt"), (long)cnt
);
935 for (i
= 0; i
< cnt
; i
++)
937 val
.Printf(wxT("hcBookmark_%i"), i
);
938 cfg
->Write(val
, m_BookmarksNames
[i
]);
939 val
.Printf(wxT("hcBookmark_%i_url"), i
);
940 cfg
->Write(val
, m_BookmarksPages
[i
]);
945 m_HtmlWin
->WriteCustomization(cfg
);
947 if (path
!= wxEmptyString
)
948 cfg
->SetPath(oldpath
);
955 static void SetFontsToHtmlWin(wxHtmlWindow
*win
, wxString scalf
, wxString fixf
, int size
)
958 f_sizes
[0] = int(size
* 0.6);
959 f_sizes
[1] = int(size
* 0.8);
961 f_sizes
[3] = int(size
* 1.2);
962 f_sizes
[4] = int(size
* 1.4);
963 f_sizes
[5] = int(size
* 1.6);
964 f_sizes
[6] = int(size
* 1.8);
966 win
->SetFonts(scalf
, fixf
, f_sizes
);
970 class wxHtmlHelpFrameOptionsDialog
: public wxDialog
973 wxComboBox
*NormalFont
, *FixedFont
;
974 wxSpinCtrl
*FontSize
;
975 wxHtmlWindow
*TestWin
;
977 wxHtmlHelpFrameOptionsDialog(wxWindow
*parent
)
978 : wxDialog(parent
, -1, wxString(_("Help Browser Options")))
980 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
981 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2, 3, 2, 5);
983 sizer
->Add(new wxStaticText(this, -1, _("Normal font:")));
984 sizer
->Add(new wxStaticText(this, -1, _("Fixed font:")));
985 sizer
->Add(new wxStaticText(this, -1, _("Font size:")));
987 sizer
->Add(NormalFont
= new wxComboBox(this, -1, wxEmptyString
, wxDefaultPosition
,
989 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
991 sizer
->Add(FixedFont
= new wxComboBox(this, -1, wxEmptyString
, wxDefaultPosition
,
993 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
995 sizer
->Add(FontSize
= new wxSpinCtrl(this, -1));
996 FontSize
->SetRange(2, 100);
998 topsizer
->Add(sizer
, 0, wxLEFT
|wxRIGHT
|wxTOP
, 10);
1000 topsizer
->Add(new wxStaticText(this, -1, _("Preview:")),
1001 0, wxLEFT
| wxTOP
, 10);
1002 topsizer
->Add(TestWin
= new wxHtmlWindow(this, -1, wxDefaultPosition
, wxSize(20, 150),
1003 wxHW_SCROLLBAR_AUTO
| wxSUNKEN_BORDER
),
1004 1, wxEXPAND
| wxLEFT
|wxTOP
|wxRIGHT
, 10);
1006 wxBoxSizer
*sizer2
= new wxBoxSizer(wxHORIZONTAL
);
1008 sizer2
->Add(ok
= new wxButton(this, wxID_OK
, _("OK")), 0, wxALL
, 10);
1010 sizer2
->Add(new wxButton(this, wxID_CANCEL
, _("Cancel")), 0, wxALL
, 10);
1011 topsizer
->Add(sizer2
, 0, wxALIGN_RIGHT
);
1013 SetAutoLayout(TRUE
);
1015 topsizer
->Fit(this);
1020 void UpdateTestWin()
1023 SetFontsToHtmlWin(TestWin
,
1024 NormalFont
->GetStringSelection(),
1025 FixedFont
->GetStringSelection(),
1026 FontSize
->GetValue());
1030 Normal face<br>(and <u>underlined</u>. <i>Italic face.</i> \
1031 <b>Bold face.</b> <b><i>Bold italic face.</i></b><br>\
1032 <font size=-2>font size -2</font><br>\
1033 <font size=-1>font size -1</font><br>\
1034 <font size=+0>font size +0</font><br>\
1035 <font size=+1>font size +1</font><br>\
1036 <font size=+2>font size +2</font><br>\
1037 <font size=+3>font size +3</font><br>\
1038 <font size=+4>font size +4</font><br>\
1040 <p><tt>Fixed size face.<br> <b>bold</b> <i>italic</i> \
1041 <b><i>bold italic <u>underlined</u></i></b><br>\
1042 <font size=-2>font size -2</font><br>\
1043 <font size=-1>font size -1</font><br>\
1044 <font size=+0>font size +0</font><br>\
1045 <font size=+1>font size +1</font><br>\
1046 <font size=+2>font size +2</font><br>\
1047 <font size=+3>font size +3</font><br>\
1048 <font size=+4>font size +4</font></tt>\
1049 </table></body></html>"
1053 void OnUpdate(wxCommandEvent
& WXUNUSED(event
))
1057 void OnUpdateSpin(wxSpinEvent
& WXUNUSED(event
))
1062 DECLARE_EVENT_TABLE()
1063 DECLARE_NO_COPY_CLASS(wxHtmlHelpFrameOptionsDialog
)
1066 BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog
, wxDialog
)
1067 EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate
)
1068 EVT_SPINCTRL(-1, wxHtmlHelpFrameOptionsDialog::OnUpdateSpin
)
1071 void wxHtmlHelpFrame::OptionsDialog()
1073 wxHtmlHelpFrameOptionsDialog
dlg(this);
1076 if (m_NormalFonts
== NULL
)
1078 wxFontEnumerator enu
;
1079 enu
.EnumerateFacenames();
1080 m_NormalFonts
= new wxArrayString
;
1081 *m_NormalFonts
= *enu
.GetFacenames();
1082 m_NormalFonts
->Sort(wxStringSortAscending
);
1084 if (m_FixedFonts
== NULL
)
1086 wxFontEnumerator enu
;
1087 enu
.EnumerateFacenames(wxFONTENCODING_SYSTEM
, TRUE
);
1088 m_FixedFonts
= new wxArrayString
;
1089 *m_FixedFonts
= *enu
.GetFacenames();
1090 m_FixedFonts
->Sort(wxStringSortAscending
);
1093 // VS: We want to show the font that is actually used by wxHtmlWindow.
1094 // If customization dialog wasn't used yet, facenames are empty and
1095 // wxHtmlWindow uses default fonts -- let's find out what they
1096 // are so that we can pass them to the dialog:
1097 if (m_NormalFace
.empty())
1099 wxFont
fnt(m_FontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, FALSE
);
1100 m_NormalFace
= fnt
.GetFaceName();
1102 if (m_FixedFace
.empty())
1104 wxFont
fnt(m_FontSize
, wxMODERN
, wxNORMAL
, wxNORMAL
, FALSE
);
1105 m_FixedFace
= fnt
.GetFaceName();
1108 for (i
= 0; i
< m_NormalFonts
->GetCount(); i
++)
1109 dlg
.NormalFont
->Append((*m_NormalFonts
)[i
]);
1110 for (i
= 0; i
< m_FixedFonts
->GetCount(); i
++)
1111 dlg
.FixedFont
->Append((*m_FixedFonts
)[i
]);
1112 if (!m_NormalFace
.empty())
1113 dlg
.NormalFont
->SetStringSelection(m_NormalFace
);
1115 dlg
.NormalFont
->SetSelection(0);
1116 if (!m_FixedFace
.empty())
1117 dlg
.FixedFont
->SetStringSelection(m_FixedFace
);
1119 dlg
.FixedFont
->SetSelection(0);
1120 dlg
.FontSize
->SetValue(m_FontSize
);
1121 dlg
.UpdateTestWin();
1123 if (dlg
.ShowModal() == wxID_OK
)
1125 m_NormalFace
= dlg
.NormalFont
->GetStringSelection();
1126 m_FixedFace
= dlg
.FixedFont
->GetStringSelection();
1127 m_FontSize
= dlg
.FontSize
->GetValue();
1128 SetFontsToHtmlWin(m_HtmlWin
, m_NormalFace
, m_FixedFace
, m_FontSize
);
1134 void wxHtmlHelpFrame::NotifyPageChanged()
1136 if (m_UpdateContents
&& m_PagesHash
)
1138 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1139 wxHtmlHelpHashData
*ha
;
1141 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage());
1143 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage() + wxT("#") + an
);
1146 bool olduc
= m_UpdateContents
;
1147 m_UpdateContents
= FALSE
;
1148 m_ContentsBox
->SelectItem(ha
->m_Id
);
1149 m_ContentsBox
->EnsureVisible(ha
->m_Id
);
1150 m_UpdateContents
= olduc
;
1162 void wxHtmlHelpFrame::OnActivate(wxActivateEvent
& event
)
1164 // This saves one mouse click when using the
1165 // wxHTML for context sensitive help systems
1167 // NB: wxActivateEvent is a bit broken in wxGTK
1168 // and is sometimes sent when it should not be
1169 if (event
.GetActive() && m_HtmlWin
)
1170 m_HtmlWin
->SetFocus();
1176 void wxHtmlHelpFrame::OnToolbar(wxCommandEvent
& event
)
1178 switch (event
.GetId())
1180 case wxID_HTML_BACK
:
1181 m_HtmlWin
->HistoryBack();
1182 NotifyPageChanged();
1185 case wxID_HTML_FORWARD
:
1186 m_HtmlWin
->HistoryForward();
1187 NotifyPageChanged();
1193 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1194 wxHtmlHelpHashData
*ha
;
1196 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage());
1198 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage() + wxT("#") + an
);
1199 if (ha
&& ha
->m_Index
> 0)
1201 wxHtmlContentsItem
*it
= m_Data
->GetContents() + (ha
->m_Index
- 1);
1202 if (it
->m_Page
[0] != 0)
1204 m_HtmlWin
->LoadPage(it
->GetFullPath());
1205 NotifyPageChanged();
1211 case wxID_HTML_UPNODE
:
1214 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1215 wxHtmlHelpHashData
*ha
;
1217 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage());
1219 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage() + wxT("#") + an
);
1220 if (ha
&& ha
->m_Index
> 0)
1222 int level
= m_Data
->GetContents()[ha
->m_Index
].m_Level
- 1;
1223 wxHtmlContentsItem
*it
;
1224 int ind
= ha
->m_Index
- 1;
1226 it
= m_Data
->GetContents() + ind
;
1227 while (ind
>= 0 && it
->m_Level
!= level
) ind
--, it
--;
1230 if (it
->m_Page
[0] != 0)
1232 m_HtmlWin
->LoadPage(it
->GetFullPath());
1233 NotifyPageChanged();
1240 case wxID_HTML_DOWN
:
1243 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1245 wxHtmlHelpHashData
*ha
;
1247 if (an
.IsEmpty()) adr
= m_HtmlWin
->GetOpenedPage();
1248 else adr
= m_HtmlWin
->GetOpenedPage() + wxT("#") + an
;
1250 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(adr
);
1252 if (ha
&& ha
->m_Index
< m_Data
->GetContentsCnt() - 1)
1254 wxHtmlContentsItem
*it
= m_Data
->GetContents() + (ha
->m_Index
+ 1);
1256 while (it
->GetFullPath() == adr
) it
++;
1258 if (it
->m_Page
[0] != 0)
1260 m_HtmlWin
->LoadPage(it
->GetFullPath());
1261 NotifyPageChanged();
1267 case wxID_HTML_PANEL
:
1269 if (! (m_Splitter
&& m_NavigPan
))
1271 if (m_Splitter
->IsSplit())
1273 m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1274 m_Splitter
->Unsplit(m_NavigPan
);
1275 m_Cfg
.navig_on
= FALSE
;
1279 m_NavigPan
->Show(TRUE
);
1280 m_HtmlWin
->Show(TRUE
);
1281 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
1282 m_Cfg
.navig_on
= TRUE
;
1287 case wxID_HTML_OPTIONS
:
1291 case wxID_HTML_BOOKMARKSADD
:
1296 item
= m_HtmlWin
->GetOpenedPageTitle();
1297 url
= m_HtmlWin
->GetOpenedPage();
1298 if (item
== wxEmptyString
)
1299 item
= url
.AfterLast(wxT('/'));
1300 if (m_BookmarksPages
.Index(url
) == wxNOT_FOUND
)
1302 m_Bookmarks
->Append(item
);
1303 m_BookmarksNames
.Add(item
);
1304 m_BookmarksPages
.Add(url
);
1309 case wxID_HTML_BOOKMARKSREMOVE
:
1314 item
= m_Bookmarks
->GetStringSelection();
1315 pos
= m_BookmarksNames
.Index(item
);
1316 if (pos
!= wxNOT_FOUND
)
1318 m_BookmarksNames
.RemoveAt(pos
);
1319 m_BookmarksPages
.RemoveAt(pos
);
1320 m_Bookmarks
->Delete(m_Bookmarks
->GetSelection());
1325 #if wxUSE_PRINTING_ARCHITECTURE
1326 case wxID_HTML_PRINT
:
1328 if (m_Printer
== NULL
)
1329 m_Printer
= new wxHtmlEasyPrinting(_("Help Printing"), this);
1330 if (!m_HtmlWin
->GetOpenedPage())
1331 wxLogWarning(_("Cannot print empty page."));
1333 m_Printer
->PrintFile(m_HtmlWin
->GetOpenedPage());
1338 case wxID_HTML_OPENFILE
:
1340 wxString s
= wxFileSelector(_("Open HTML document"),
1345 "HTML files (*.htm)|*.htm|HTML files (*.html)|*.html|\
1346 Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
1347 HTML Help Project (*.hhp)|*.hhp|\
1350 wxOPEN
| wxFILE_MUST_EXIST
,
1354 wxString ext
= s
.Right(4).Lower();
1355 if (ext
== _T(".zip") || ext
== _T(".htb") || ext
== _T(".hhp"))
1362 m_HtmlWin
->LoadPage(s
);
1371 void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent
& event
)
1373 wxHtmlHelpTreeItemData
*pg
;
1374 wxHtmlContentsItem
*it
;
1376 pg
= (wxHtmlHelpTreeItemData
*) m_ContentsBox
->GetItemData(event
.GetItem());
1378 if (pg
&& m_UpdateContents
)
1380 it
= m_Data
->GetContents() + (pg
->m_Id
);
1381 m_UpdateContents
= FALSE
;
1382 if (it
->m_Page
[0] != 0)
1383 m_HtmlWin
->LoadPage(it
->GetFullPath());
1384 m_UpdateContents
= TRUE
;
1390 void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent
& WXUNUSED(event
))
1392 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_IndexList
->GetClientData(m_IndexList
->GetSelection());
1393 if (it
->m_Page
[0] != 0)
1394 m_HtmlWin
->LoadPage(it
->GetFullPath());
1395 NotifyPageChanged();
1399 void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent
& event
)
1401 wxString sr
= m_IndexText
->GetLineText(0);
1403 if (sr
== wxEmptyString
)
1410 const wxChar
*cstr
= sr
.c_str();
1415 m_IndexList
->Clear();
1416 int cnt
= m_Data
->GetIndexCnt();
1417 wxHtmlContentsItem
* index
= m_Data
->GetIndex();
1420 for (int i
= 0; i
< cnt
; i
++)
1422 wxStrncpy(mybuff
, index
[i
].m_Name
, 512);
1423 mybuff
[511] = _T('\0');
1424 for (ptr
= mybuff
; *ptr
!= 0; ptr
++)
1425 if (*ptr
>= _T('A') && *ptr
<= _T('Z'))
1426 *ptr
-= (wxChar
)(_T('A') - _T('a'));
1427 if (wxStrstr(mybuff
, cstr
) != NULL
)
1429 m_IndexList
->Append(index
[i
].m_Name
, (char*)(index
+ i
));
1433 if (index
[i
].m_Page
[0] != 0)
1434 m_HtmlWin
->LoadPage(index
[i
].GetFullPath());
1435 NotifyPageChanged();
1442 cnttext
.Printf(_("%i of %i"), displ
, cnt
);
1443 m_IndexCountInfo
->SetLabel(cnttext
);
1445 m_IndexText
->SetSelection(0, sr
.Length());
1446 m_IndexText
->SetFocus();
1450 void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent
& WXUNUSED(event
))
1454 m_IndexList
->Clear();
1455 int cnt
= m_Data
->GetIndexCnt();
1457 wxHtmlContentsItem
* index
= m_Data
->GetIndex();
1459 for (int i
= 0; i
< cnt
; i
++)
1461 m_IndexList
->Append(index
[i
].m_Name
, (char*)(index
+ i
));
1464 if (index
[i
].m_Page
[0] != 0)
1465 m_HtmlWin
->LoadPage(index
[i
].GetFullPath());
1466 NotifyPageChanged();
1472 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1473 m_IndexCountInfo
->SetLabel(cnttext
);
1477 void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent
& WXUNUSED(event
))
1479 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_SearchList
->GetClientData(m_SearchList
->GetSelection());
1482 if (it
->m_Page
[0] != 0)
1483 m_HtmlWin
->LoadPage(it
->GetFullPath());
1484 NotifyPageChanged();
1488 void wxHtmlHelpFrame::OnSearch(wxCommandEvent
& WXUNUSED(event
))
1490 wxString sr
= m_SearchText
->GetLineText(0);
1492 if (sr
!= wxEmptyString
) KeywordSearch(sr
);
1495 void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent
& WXUNUSED(event
))
1497 wxString sr
= m_Bookmarks
->GetStringSelection();
1499 if (sr
!= wxEmptyString
&& sr
!= _("(bookmarks)"))
1501 m_HtmlWin
->LoadPage(m_BookmarksPages
[m_BookmarksNames
.Index(sr
)]);
1502 NotifyPageChanged();
1506 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent
& evt
)
1508 GetSize(&m_Cfg
.w
, &m_Cfg
.h
);
1509 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
1518 if (m_Splitter
&& m_Cfg
.navig_on
) m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1521 WriteCustomization(m_Config
, m_ConfigRoot
);
1523 if (m_helpController
&& m_helpController
->IsKindOf(CLASSINFO(wxHtmlHelpController
)))
1525 ((wxHtmlHelpController
*) m_helpController
)->OnCloseFrame(evt
);
1532 void wxHtmlHelpFrame::OnClose(wxCommandEvent
& event
)
1537 void wxHtmlHelpFrame::OnAbout(wxCommandEvent
& event
)
1539 wxMessageBox(wxT("wxWindows HTML Help Viewer (c) 1998-2003, Vaclav Slavik et al"), wxT("HelpView"),
1540 wxICON_INFORMATION
|wxOK
, this);
1544 BEGIN_EVENT_TABLE(wxHtmlHelpFrame
, wxFrame
)
1545 EVT_ACTIVATE(wxHtmlHelpFrame::OnActivate
)
1546 EVT_TOOL_RANGE(wxID_HTML_PANEL
, wxID_HTML_OPTIONS
, wxHtmlHelpFrame::OnToolbar
)
1547 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE
, wxHtmlHelpFrame::OnToolbar
)
1548 EVT_BUTTON(wxID_HTML_BOOKMARKSADD
, wxHtmlHelpFrame::OnToolbar
)
1549 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL
, wxHtmlHelpFrame::OnContentsSel
)
1550 EVT_LISTBOX(wxID_HTML_INDEXLIST
, wxHtmlHelpFrame::OnIndexSel
)
1551 EVT_LISTBOX(wxID_HTML_SEARCHLIST
, wxHtmlHelpFrame::OnSearchSel
)
1552 EVT_BUTTON(wxID_HTML_SEARCHBUTTON
, wxHtmlHelpFrame::OnSearch
)
1553 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT
, wxHtmlHelpFrame::OnSearch
)
1554 EVT_BUTTON(wxID_HTML_INDEXBUTTON
, wxHtmlHelpFrame::OnIndexFind
)
1555 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT
, wxHtmlHelpFrame::OnIndexFind
)
1556 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL
, wxHtmlHelpFrame::OnIndexAll
)
1557 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST
, wxHtmlHelpFrame::OnBookmarksSel
)
1558 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow
)
1560 EVT_MENU(wxID_CLOSE
, wxHtmlHelpFrame::OnClose
)
1561 EVT_MENU(wxID_ABOUT
, wxHtmlHelpFrame::OnAbout
)
1566 #endif // wxUSE_WXHTML_HELP