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;
287 if (style
& (wxHF_TOOLBAR
| wxHF_FLAT_TOOLBAR
))
289 wxToolBar
*toolBar
= CreateToolBar(wxNO_BORDER
| wxTB_HORIZONTAL
|
291 (style
& wxHF_FLAT_TOOLBAR
? wxTB_FLAT
: 0));
292 toolBar
->SetMargins( 2, 2 );
293 AddToolbarButtons(toolBar
, style
);
296 #endif //wxUSE_TOOLBAR
298 wxSizer
*navigSizer
= NULL
;
300 if (style
& (wxHF_CONTENTS
| wxHF_INDEX
| wxHF_SEARCH
))
302 // traditional help controller; splitter window with html page on the
303 // right and a notebook containing various pages on the left
304 m_Splitter
= new wxSplitterWindow(this);
306 m_HtmlWin
= new wxHtmlHelpHtmlWindow(this, m_Splitter
);
307 m_NavigPan
= new wxPanel(m_Splitter
, wxID_ANY
);
308 m_NavigNotebook
= new wxNotebook(m_NavigPan
, wxID_HTML_NOTEBOOK
,
309 wxDefaultPosition
, wxDefaultSize
);
310 wxNotebookSizer
*nbs
= new wxNotebookSizer(m_NavigNotebook
);
312 navigSizer
= new wxBoxSizer(wxVERTICAL
);
313 navigSizer
->Add(nbs
, 1, wxEXPAND
);
315 m_NavigPan
->SetSizer(navigSizer
);
318 { // only html window, no notebook with index,contents etc
319 m_HtmlWin
= new wxHtmlWindow(this);
322 m_HtmlWin
->SetRelatedFrame(this, m_TitleFormat
);
323 m_HtmlWin
->SetRelatedStatusBar(0);
325 m_HtmlWin
->ReadCustomization(m_Config
, m_ConfigRoot
);
327 // contents tree panel?
328 if ( style
& wxHF_CONTENTS
)
330 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
331 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
333 topsizer
->Add(0, 10);
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,
378 wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
,
381 m_NavigNotebook
->AddPage(dummy
, _("Contents"));
382 m_ContentsPage
= notebook_page
++;
385 // index listbox panel?
386 if ( style
& wxHF_INDEX
)
388 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
389 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
391 dummy
->SetSizer(topsizer
);
393 m_IndexText
= new wxTextCtrl(dummy
, wxID_HTML_INDEXTEXT
, wxEmptyString
,
394 wxDefaultPosition
, wxDefaultSize
,
396 m_IndexButton
= new wxButton(dummy
, wxID_HTML_INDEXBUTTON
, _("Find"));
397 m_IndexButtonAll
= new wxButton(dummy
, wxID_HTML_INDEXBUTTONALL
,
399 m_IndexCountInfo
= new wxStaticText(dummy
, wxID_HTML_COUNTINFO
,
400 wxEmptyString
, wxDefaultPosition
,
402 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
403 m_IndexList
= new wxListBox(dummy
, wxID_HTML_INDEXLIST
,
404 wxDefaultPosition
, wxDefaultSize
,
405 0, NULL
, wxLB_SINGLE
);
408 m_IndexButton
->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
409 m_IndexButtonAll
->SetToolTip(_("Show all items in index"));
410 #endif //wxUSE_TOOLTIPS
412 topsizer
->Add(m_IndexText
, 0, wxEXPAND
| wxALL
, 10);
413 wxSizer
*btsizer
= new wxBoxSizer(wxHORIZONTAL
);
414 btsizer
->Add(m_IndexButton
, 0, wxRIGHT
, 2);
415 btsizer
->Add(m_IndexButtonAll
);
416 topsizer
->Add(btsizer
, 0,
417 wxALIGN_RIGHT
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
418 topsizer
->Add(m_IndexCountInfo
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 2);
419 topsizer
->Add(m_IndexList
, 1, wxEXPAND
| wxALL
, 2);
421 m_NavigNotebook
->AddPage(dummy
, _("Index"));
422 m_IndexPage
= notebook_page
++;
425 // search list panel?
426 if ( style
& wxHF_SEARCH
)
428 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
429 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
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
, wxID_ANY
, _("Case sensitive"));
440 m_SearchWholeWords
= new wxCheckBox(dummy
, wxID_ANY
, _("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
;
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
)
480 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
484 m_NavigPan
->Show(false);
485 m_Splitter
->Initialize(m_HtmlWin
);
489 // Reduce flicker by updating the splitter pane sizes before the
491 wxSizeEvent
sizeEvent(GetSize(), GetId());
492 ProcessEvent(sizeEvent
);
494 m_Splitter
->UpdateSize();
499 wxHtmlHelpFrame::~wxHtmlHelpFrame()
501 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
504 if (m_NormalFonts
) delete m_NormalFonts
;
505 if (m_FixedFonts
) delete m_FixedFonts
;
508 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
511 #if wxUSE_PRINTING_ARCHITECTURE
512 if (m_Printer
) delete m_Printer
;
518 void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar
*toolBar
, int style
)
520 wxBitmap wpanelBitmap
=
521 wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL
, wxART_HELP_BROWSER
);
522 wxBitmap wbackBitmap
=
523 wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_HELP_BROWSER
);
524 wxBitmap wforwardBitmap
=
525 wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_HELP_BROWSER
);
526 wxBitmap wupnodeBitmap
=
527 wxArtProvider::GetBitmap(wxART_GO_TO_PARENT
, wxART_HELP_BROWSER
);
529 wxArtProvider::GetBitmap(wxART_GO_UP
, wxART_HELP_BROWSER
);
530 wxBitmap wdownBitmap
=
531 wxArtProvider::GetBitmap(wxART_GO_DOWN
, wxART_HELP_BROWSER
);
532 wxBitmap wopenBitmap
=
533 wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_HELP_BROWSER
);
534 wxBitmap wprintBitmap
=
535 wxArtProvider::GetBitmap(wxART_PRINT
, wxART_HELP_BROWSER
);
536 wxBitmap woptionsBitmap
=
537 wxArtProvider::GetBitmap(wxART_HELP_SETTINGS
, wxART_HELP_BROWSER
);
539 wxASSERT_MSG( (wpanelBitmap
.Ok() && wbackBitmap
.Ok() &&
540 wforwardBitmap
.Ok() && wupnodeBitmap
.Ok() &&
541 wupBitmap
.Ok() && wdownBitmap
.Ok() &&
542 wopenBitmap
.Ok() && wprintBitmap
.Ok() &&
543 woptionsBitmap
.Ok()),
544 wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
547 toolBar
->AddTool(wxID_HTML_PANEL
, wpanelBitmap
, wxNullBitmap
,
548 false, -1, -1, (wxObject
*) NULL
,
549 _("Show/hide navigation panel"));
551 toolBar
->AddSeparator();
552 toolBar
->AddTool(wxID_HTML_BACK
, wbackBitmap
, wxNullBitmap
,
553 false, -1, -1, (wxObject
*) NULL
,
555 toolBar
->AddTool(wxID_HTML_FORWARD
, wforwardBitmap
, wxNullBitmap
,
556 false, -1, -1, (wxObject
*) NULL
,
558 toolBar
->AddSeparator();
560 toolBar
->AddTool(wxID_HTML_UPNODE
, wupnodeBitmap
, wxNullBitmap
,
561 false, -1, -1, (wxObject
*) NULL
,
562 _("Go one level up in document hierarchy"));
563 toolBar
->AddTool(wxID_HTML_UP
, wupBitmap
, wxNullBitmap
,
564 false, -1, -1, (wxObject
*) NULL
,
566 toolBar
->AddTool(wxID_HTML_DOWN
, wdownBitmap
, wxNullBitmap
,
567 false, -1, -1, (wxObject
*) NULL
,
570 if ((style
& wxHF_PRINT
) || (style
& wxHF_OPEN_FILES
))
571 toolBar
->AddSeparator();
573 if (style
& wxHF_OPEN_FILES
)
574 toolBar
->AddTool(wxID_HTML_OPENFILE
, wopenBitmap
, wxNullBitmap
,
575 false, -1, -1, (wxObject
*) NULL
,
576 _("Open HTML document"));
578 #if wxUSE_PRINTING_ARCHITECTURE
579 if (style
& wxHF_PRINT
)
580 toolBar
->AddTool(wxID_HTML_PRINT
, wprintBitmap
, wxNullBitmap
,
581 false, -1, -1, (wxObject
*) NULL
,
582 _("Print this page"));
585 toolBar
->AddSeparator();
586 toolBar
->AddTool(wxID_HTML_OPTIONS
, woptionsBitmap
, wxNullBitmap
,
587 false, -1, -1, (wxObject
*) NULL
,
588 _("Display options dialog"));
590 #endif //wxUSE_TOOLBAR
593 void wxHtmlHelpFrame::SetTitleFormat(const wxString
& format
)
596 m_HtmlWin
->SetRelatedFrame(this, format
);
597 m_TitleFormat
= format
;
601 bool wxHtmlHelpFrame::Display(const wxString
& x
)
603 wxString url
= m_Data
->FindPageByName(x
);
606 m_HtmlWin
->LoadPage(url
);
614 bool wxHtmlHelpFrame::Display(const int id
)
616 wxString url
= m_Data
->FindPageById(id
);
619 m_HtmlWin
->LoadPage(url
);
629 bool wxHtmlHelpFrame::DisplayContents()
634 if (!m_Splitter
->IsSplit())
638 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
639 m_Cfg
.navig_on
= true;
642 m_NavigNotebook
->SetSelection(0);
644 if (m_Data
->GetBookRecArray().GetCount() > 0)
646 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
647 if (!book
.GetStart().IsEmpty())
648 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
656 bool wxHtmlHelpFrame::DisplayIndex()
661 if (!m_Splitter
->IsSplit())
665 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
668 m_NavigNotebook
->SetSelection(1);
670 if (m_Data
->GetBookRecArray().GetCount() > 0)
672 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
673 if (!book
.GetStart().IsEmpty())
674 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
682 bool wxHtmlHelpFrame::KeywordSearch(const wxString
& keyword
,
683 wxHelpSearchMode mode
)
685 if (mode
== wxHELP_SEARCH_ALL
)
687 if ( !(m_SearchList
&&
688 m_SearchButton
&& m_SearchText
&& m_SearchChoice
) )
691 else if (mode
== wxHELP_SEARCH_INDEX
)
693 if ( !(m_IndexList
&&
694 m_IndexButton
&& m_IndexButtonAll
&& m_IndexText
) )
700 wxString book
= wxEmptyString
;
702 if (!m_Splitter
->IsSplit())
706 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
709 if (mode
== wxHELP_SEARCH_ALL
)
711 m_NavigNotebook
->SetSelection(m_SearchPage
);
712 m_SearchList
->Clear();
713 m_SearchText
->SetValue(keyword
);
714 m_SearchButton
->Disable();
716 if (m_SearchChoice
->GetSelection() != 0)
717 book
= m_SearchChoice
->GetStringSelection();
719 wxHtmlSearchStatus
status(m_Data
, keyword
,
720 m_SearchCaseSensitive
->GetValue(),
721 m_SearchWholeWords
->GetValue(),
724 #if wxUSE_PROGRESSDLG
725 wxProgressDialog
progress(_("Searching..."),
726 _("No matching page found yet"),
727 status
.GetMaxIndex(), this,
728 wxPD_APP_MODAL
| wxPD_CAN_ABORT
| wxPD_AUTO_HIDE
);
732 while (status
.IsActive())
734 curi
= status
.GetCurIndex();
736 #if wxUSE_PROGRESSDLG
737 && !progress
.Update(curi
)
743 foundstr
.Printf(_("Found %i matches"), ++foundcnt
);
744 #if wxUSE_PROGRESSDLG
745 progress
.Update(status
.GetCurIndex(), foundstr
);
747 m_SearchList
->Append(status
.GetName(), status
.GetContentsItem());
751 m_SearchButton
->Enable();
752 m_SearchText
->SetSelection(0, keyword
.Length());
753 m_SearchText
->SetFocus();
755 else if (mode
== wxHELP_SEARCH_INDEX
)
757 m_NavigNotebook
->SetSelection(m_IndexPage
);
758 m_IndexList
->Clear();
759 m_IndexButton
->Disable();
760 m_IndexButtonAll
->Disable();
761 m_IndexText
->SetValue(keyword
);
763 wxCommandEvent dummy
;
764 OnIndexFind(dummy
); // what a hack...
765 m_IndexButton
->Enable();
766 m_IndexButtonAll
->Enable();
767 foundcnt
= m_IndexList
->GetCount();
772 wxHtmlContentsItem
*it
;
776 wxFAIL_MSG( _T("unknown help search mode") );
779 case wxHELP_SEARCH_ALL
:
780 it
= (wxHtmlContentsItem
*) m_SearchList
->GetClientData(0);
783 case wxHELP_SEARCH_INDEX
:
784 it
= (wxHtmlContentsItem
*) m_IndexList
->GetClientData(0);
790 m_HtmlWin
->LoadPage(it
->GetFullPath());
798 void wxHtmlHelpFrame::CreateContents()
805 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
808 m_PagesHash
= new wxHashTable(wxKEY_STRING
, 2 * m_Data
->GetContentsCnt());
810 int cnt
= m_Data
->GetContentsCnt();
813 wxHtmlContentsItem
*it
;
815 const int MAX_ROOTS
= 64;
816 wxTreeItemId roots
[MAX_ROOTS
];
817 // VS: this array holds information about whether we've set item icon at
818 // given level. This is neccessary because m_Data has flat structure
819 // and there's no way of recognizing if some item has subitems or not.
820 // We set the icon later: when we find an item with level=n, we know
821 // that the last item with level=n-1 was folder with subitems, so we
822 // set its icon accordingly
823 bool imaged
[MAX_ROOTS
];
824 m_ContentsBox
->DeleteAllItems();
826 roots
[0] = m_ContentsBox
->AddRoot(_("(Help)"));
829 for (it
= m_Data
->GetContents(), i
= 0; i
< cnt
; i
++, it
++)
832 if (it
->m_Level
== 0)
834 if (m_hfStyle
& wxHF_MERGE_BOOKS
)
835 // VS: we don't want book nodes, books' content should
836 // appear under tree's root. This line will create "fake"
837 // record about book node so that the rest of this look
838 // will believe there really _is_ book node and will
843 roots
[1] = m_ContentsBox
->AppendItem(roots
[0],
844 it
->m_Name
, IMG_Book
, -1,
845 new wxHtmlHelpTreeItemData(i
));
846 m_ContentsBox
->SetItemBold(roots
[1], true);
850 // ...and their contents:
853 roots
[it
->m_Level
+ 1] = m_ContentsBox
->AppendItem(
854 roots
[it
->m_Level
], it
->m_Name
, IMG_Page
,
855 -1, new wxHtmlHelpTreeItemData(i
));
856 imaged
[it
->m_Level
+ 1] = false;
859 m_PagesHash
->Put(it
->GetFullPath(),
860 new wxHtmlHelpHashData(i
, roots
[it
->m_Level
+ 1]));
862 // Set the icon for the node one level up in the hiearachy,
863 // unless already done (see comment above imaged[] declaration)
864 if (!imaged
[it
->m_Level
])
866 int image
= IMG_Folder
;
867 if (m_hfStyle
& wxHF_ICONS_BOOK
)
869 else if (m_hfStyle
& wxHF_ICONS_BOOK_CHAPTER
)
870 image
= (it
->m_Level
== 1) ? IMG_Book
: IMG_Folder
;
871 m_ContentsBox
->SetItemImage(roots
[it
->m_Level
], image
);
872 m_ContentsBox
->SetItemImage(roots
[it
->m_Level
], image
,
873 wxTreeItemIcon_Selected
);
874 imaged
[it
->m_Level
] = true;
880 void wxHtmlHelpFrame::CreateIndex()
885 m_IndexList
->Clear();
887 int cnt
= m_Data
->GetIndexCnt();
890 if (cnt
> INDEX_IS_SMALL
) cnttext
.Printf(_("%i of %i"), 0, cnt
);
891 else cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
892 m_IndexCountInfo
->SetLabel(cnttext
);
893 if (cnt
> INDEX_IS_SMALL
) return;
895 wxHtmlContentsItem
* index
= m_Data
->GetIndex();
897 for (int i
= 0; i
< cnt
; i
++)
898 m_IndexList
->Append(index
[i
].m_Name
, (char*)(index
+ i
));
901 void wxHtmlHelpFrame::CreateSearch()
903 if (! (m_SearchList
&& m_SearchChoice
))
905 m_SearchList
->Clear();
906 m_SearchChoice
->Clear();
907 m_SearchChoice
->Append(_("Search in all books"));
908 const wxHtmlBookRecArray
& bookrec
= m_Data
->GetBookRecArray();
909 int i
, cnt
= bookrec
.GetCount();
910 for (i
= 0; i
< cnt
; i
++)
911 m_SearchChoice
->Append(bookrec
[i
].GetTitle());
912 m_SearchChoice
->SetSelection(0);
916 void wxHtmlHelpFrame::RefreshLists()
923 void wxHtmlHelpFrame::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
928 if (path
!= wxEmptyString
)
930 oldpath
= cfg
->GetPath();
931 cfg
->SetPath(_T("/") + path
);
934 m_Cfg
.navig_on
= cfg
->Read(wxT("hcNavigPanel"), m_Cfg
.navig_on
) != 0;
935 m_Cfg
.sashpos
= cfg
->Read(wxT("hcSashPos"), m_Cfg
.sashpos
);
936 m_Cfg
.x
= cfg
->Read(wxT("hcX"), m_Cfg
.x
);
937 m_Cfg
.y
= cfg
->Read(wxT("hcY"), m_Cfg
.y
);
938 m_Cfg
.w
= cfg
->Read(wxT("hcW"), m_Cfg
.w
);
939 m_Cfg
.h
= cfg
->Read(wxT("hcH"), m_Cfg
.h
);
941 m_FixedFace
= cfg
->Read(wxT("hcFixedFace"), m_FixedFace
);
942 m_NormalFace
= cfg
->Read(wxT("hcNormalFace"), m_NormalFace
);
943 m_FontSize
= cfg
->Read(wxT("hcBaseFontSize"), m_FontSize
);
950 cnt
= cfg
->Read(wxT("hcBookmarksCnt"), 0L);
953 m_BookmarksNames
.Clear();
954 m_BookmarksPages
.Clear();
957 m_Bookmarks
->Clear();
958 m_Bookmarks
->Append(_("(bookmarks)"));
961 for (i
= 0; i
< cnt
; i
++)
963 val
.Printf(wxT("hcBookmark_%i"), i
);
965 m_BookmarksNames
.Add(s
);
966 if (m_Bookmarks
) m_Bookmarks
->Append(s
);
967 val
.Printf(wxT("hcBookmark_%i_url"), i
);
969 m_BookmarksPages
.Add(s
);
975 m_HtmlWin
->ReadCustomization(cfg
);
977 if (path
!= wxEmptyString
)
978 cfg
->SetPath(oldpath
);
981 void wxHtmlHelpFrame::WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
)
986 if (path
!= wxEmptyString
)
988 oldpath
= cfg
->GetPath();
989 cfg
->SetPath(_T("/") + path
);
992 cfg
->Write(wxT("hcNavigPanel"), m_Cfg
.navig_on
);
993 cfg
->Write(wxT("hcSashPos"), (long)m_Cfg
.sashpos
);
996 // Don't write if iconized as this would make the window
997 // disappear next time it is shown!
998 cfg
->Write(wxT("hcX"), (long)m_Cfg
.x
);
999 cfg
->Write(wxT("hcY"), (long)m_Cfg
.y
);
1000 cfg
->Write(wxT("hcW"), (long)m_Cfg
.w
);
1001 cfg
->Write(wxT("hcH"), (long)m_Cfg
.h
);
1003 cfg
->Write(wxT("hcFixedFace"), m_FixedFace
);
1004 cfg
->Write(wxT("hcNormalFace"), m_NormalFace
);
1005 cfg
->Write(wxT("hcBaseFontSize"), (long)m_FontSize
);
1010 int cnt
= m_BookmarksNames
.GetCount();
1013 cfg
->Write(wxT("hcBookmarksCnt"), (long)cnt
);
1014 for (i
= 0; i
< cnt
; i
++)
1016 val
.Printf(wxT("hcBookmark_%i"), i
);
1017 cfg
->Write(val
, m_BookmarksNames
[i
]);
1018 val
.Printf(wxT("hcBookmark_%i_url"), i
);
1019 cfg
->Write(val
, m_BookmarksPages
[i
]);
1024 m_HtmlWin
->WriteCustomization(cfg
);
1026 if (path
!= wxEmptyString
)
1027 cfg
->SetPath(oldpath
);
1034 static void SetFontsToHtmlWin(wxHtmlWindow
*win
, wxString scalf
, wxString fixf
, int size
)
1037 f_sizes
[0] = int(size
* 0.6);
1038 f_sizes
[1] = int(size
* 0.8);
1040 f_sizes
[3] = int(size
* 1.2);
1041 f_sizes
[4] = int(size
* 1.4);
1042 f_sizes
[5] = int(size
* 1.6);
1043 f_sizes
[6] = int(size
* 1.8);
1045 win
->SetFonts(scalf
, fixf
, f_sizes
);
1049 class wxHtmlHelpFrameOptionsDialog
: public wxDialog
1052 wxComboBox
*NormalFont
, *FixedFont
;
1053 wxSpinCtrl
*FontSize
;
1054 wxHtmlWindow
*TestWin
;
1056 wxHtmlHelpFrameOptionsDialog(wxWindow
*parent
)
1057 : wxDialog(parent
, wxID_ANY
, wxString(_("Help Browser Options")))
1059 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
1060 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2, 3, 2, 5);
1062 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Normal font:")));
1063 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Fixed font:")));
1064 sizer
->Add(new wxStaticText(this, wxID_ANY
, _("Font size:")));
1066 sizer
->Add(NormalFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1068 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1070 sizer
->Add(FixedFont
= new wxComboBox(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
,
1072 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1074 sizer
->Add(FontSize
= new wxSpinCtrl(this, wxID_ANY
));
1075 FontSize
->SetRange(2, 100);
1077 topsizer
->Add(sizer
, 0, wxLEFT
|wxRIGHT
|wxTOP
, 10);
1079 topsizer
->Add(new wxStaticText(this, wxID_ANY
, _("Preview:")),
1080 0, wxLEFT
| wxTOP
, 10);
1081 topsizer
->Add(TestWin
= new wxHtmlWindow(this, wxID_ANY
, wxDefaultPosition
, wxSize(20, 150),
1082 wxHW_SCROLLBAR_AUTO
| wxSUNKEN_BORDER
),
1083 1, wxEXPAND
| wxLEFT
|wxTOP
|wxRIGHT
, 10);
1085 wxBoxSizer
*sizer2
= new wxBoxSizer(wxHORIZONTAL
);
1087 sizer2
->Add(ok
= new wxButton(this, wxID_OK
, _("OK")), 0, wxALL
, 10);
1089 sizer2
->Add(new wxButton(this, wxID_CANCEL
, _("Cancel")), 0, wxALL
, 10);
1090 topsizer
->Add(sizer2
, 0, wxALIGN_RIGHT
);
1093 topsizer
->Fit(this);
1098 void UpdateTestWin()
1101 SetFontsToHtmlWin(TestWin
,
1102 NormalFont
->GetStringSelection(),
1103 FixedFont
->GetStringSelection(),
1104 FontSize
->GetValue());
1106 wxString
content(_("font size"));
1108 content
= _T("<font size=-2>") + content
+ _T(" -2</font><br>")
1109 _T("<font size=-1>") + content
+ _T(" -1</font><br>")
1110 _T("<font size=+0>") + content
+ _T(" +0</font><br>")
1111 _T("<font size=+1>") + content
+ _T(" +1</font><br>")
1112 _T("<font size=+2>") + content
+ _T(" +2</font><br>")
1113 _T("<font size=+3>") + content
+ _T(" +3</font><br>")
1114 _T("<font size=+4>") + content
+ _T(" +4</font><br>") ;
1116 content
= wxString( _T("<html><body><table><tr><td>") ) +
1117 _("Normal face<br>and <u>underlined</u>. ") +
1118 _("<i>Italic face.</i> ") +
1119 _("<b>Bold face.</b> ") +
1120 _("<b><i>Bold italic face.</i></b><br>") +
1122 wxString( _T("</td><td><tt>") ) +
1123 _("Fixed size face.<br> <b>bold</b> <i>italic</i> ") +
1124 _("<b><i>bold italic <u>underlined</u></i></b><br>") +
1126 _T("</tt></td></tr></table></body></html>");
1128 TestWin
->SetPage( content
);
1131 void OnUpdate(wxCommandEvent
& WXUNUSED(event
))
1135 void OnUpdateSpin(wxSpinEvent
& WXUNUSED(event
))
1140 DECLARE_EVENT_TABLE()
1141 DECLARE_NO_COPY_CLASS(wxHtmlHelpFrameOptionsDialog
)
1144 BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog
, wxDialog
)
1145 EVT_COMBOBOX(wxID_ANY
, wxHtmlHelpFrameOptionsDialog::OnUpdate
)
1146 EVT_SPINCTRL(wxID_ANY
, wxHtmlHelpFrameOptionsDialog::OnUpdateSpin
)
1149 void wxHtmlHelpFrame::OptionsDialog()
1151 wxHtmlHelpFrameOptionsDialog
dlg(this);
1154 if (m_NormalFonts
== NULL
)
1156 wxFontEnumerator enu
;
1157 enu
.EnumerateFacenames();
1158 m_NormalFonts
= new wxArrayString
;
1159 *m_NormalFonts
= *enu
.GetFacenames();
1160 m_NormalFonts
->Sort(wxStringSortAscending
);
1162 if (m_FixedFonts
== NULL
)
1164 wxFontEnumerator enu
;
1165 enu
.EnumerateFacenames(wxFONTENCODING_SYSTEM
, true /*enum fixed width only*/);
1166 m_FixedFonts
= new wxArrayString
;
1167 *m_FixedFonts
= *enu
.GetFacenames();
1168 m_FixedFonts
->Sort(wxStringSortAscending
);
1171 // VS: We want to show the font that is actually used by wxHtmlWindow.
1172 // If customization dialog wasn't used yet, facenames are empty and
1173 // wxHtmlWindow uses default fonts -- let's find out what they
1174 // are so that we can pass them to the dialog:
1175 if (m_NormalFace
.empty())
1177 wxFont
fnt(m_FontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, false);
1178 m_NormalFace
= fnt
.GetFaceName();
1180 if (m_FixedFace
.empty())
1182 wxFont
fnt(m_FontSize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false);
1183 m_FixedFace
= fnt
.GetFaceName();
1186 for (i
= 0; i
< m_NormalFonts
->GetCount(); i
++)
1187 dlg
.NormalFont
->Append((*m_NormalFonts
)[i
]);
1188 for (i
= 0; i
< m_FixedFonts
->GetCount(); i
++)
1189 dlg
.FixedFont
->Append((*m_FixedFonts
)[i
]);
1190 if (!m_NormalFace
.empty())
1191 dlg
.NormalFont
->SetStringSelection(m_NormalFace
);
1193 dlg
.NormalFont
->SetSelection(0);
1194 if (!m_FixedFace
.empty())
1195 dlg
.FixedFont
->SetStringSelection(m_FixedFace
);
1197 dlg
.FixedFont
->SetSelection(0);
1198 dlg
.FontSize
->SetValue(m_FontSize
);
1199 dlg
.UpdateTestWin();
1201 if (dlg
.ShowModal() == wxID_OK
)
1203 m_NormalFace
= dlg
.NormalFont
->GetStringSelection();
1204 m_FixedFace
= dlg
.FixedFont
->GetStringSelection();
1205 m_FontSize
= dlg
.FontSize
->GetValue();
1206 SetFontsToHtmlWin(m_HtmlWin
, m_NormalFace
, m_FixedFace
, m_FontSize
);
1212 void wxHtmlHelpFrame::NotifyPageChanged()
1214 if (m_UpdateContents
&& m_PagesHash
)
1216 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1217 wxHtmlHelpHashData
*ha
;
1219 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage());
1221 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage() + wxT("#") + an
);
1224 bool olduc
= m_UpdateContents
;
1225 m_UpdateContents
= false;
1226 m_ContentsBox
->SelectItem(ha
->m_Id
);
1227 m_ContentsBox
->EnsureVisible(ha
->m_Id
);
1228 m_UpdateContents
= olduc
;
1240 void wxHtmlHelpFrame::OnActivate(wxActivateEvent
& event
)
1242 // This saves one mouse click when using the
1243 // wxHTML for context sensitive help systems
1245 // NB: wxActivateEvent is a bit broken in wxGTK
1246 // and is sometimes sent when it should not be
1247 if (event
.GetActive() && m_HtmlWin
)
1248 m_HtmlWin
->SetFocus();
1254 void wxHtmlHelpFrame::OnToolbar(wxCommandEvent
& event
)
1256 switch (event
.GetId())
1258 case wxID_HTML_BACK
:
1259 m_HtmlWin
->HistoryBack();
1260 NotifyPageChanged();
1263 case wxID_HTML_FORWARD
:
1264 m_HtmlWin
->HistoryForward();
1265 NotifyPageChanged();
1271 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1272 wxHtmlHelpHashData
*ha
;
1274 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage());
1276 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage() + wxT("#") + an
);
1277 if (ha
&& ha
->m_Index
> 0)
1279 wxHtmlContentsItem
*it
= m_Data
->GetContents() + (ha
->m_Index
- 1);
1280 if (it
->m_Page
[0] != 0)
1282 m_HtmlWin
->LoadPage(it
->GetFullPath());
1283 NotifyPageChanged();
1289 case wxID_HTML_UPNODE
:
1292 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1293 wxHtmlHelpHashData
*ha
;
1295 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage());
1297 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage() + wxT("#") + an
);
1298 if (ha
&& ha
->m_Index
> 0)
1300 int level
= m_Data
->GetContents()[ha
->m_Index
].m_Level
- 1;
1301 wxHtmlContentsItem
*it
;
1302 int ind
= ha
->m_Index
- 1;
1304 it
= m_Data
->GetContents() + ind
;
1305 while (ind
>= 0 && it
->m_Level
!= level
) ind
--, it
--;
1308 if (it
->m_Page
[0] != 0)
1310 m_HtmlWin
->LoadPage(it
->GetFullPath());
1311 NotifyPageChanged();
1318 case wxID_HTML_DOWN
:
1321 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1323 wxHtmlHelpHashData
*ha
;
1325 if (an
.IsEmpty()) adr
= m_HtmlWin
->GetOpenedPage();
1326 else adr
= m_HtmlWin
->GetOpenedPage() + wxT("#") + an
;
1328 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(adr
);
1330 if (ha
&& ha
->m_Index
< m_Data
->GetContentsCnt() - 1)
1332 wxHtmlContentsItem
*it
= m_Data
->GetContents() + (ha
->m_Index
+ 1);
1334 while (it
->GetFullPath() == adr
) it
++;
1336 if (it
->m_Page
[0] != 0)
1338 m_HtmlWin
->LoadPage(it
->GetFullPath());
1339 NotifyPageChanged();
1345 case wxID_HTML_PANEL
:
1347 if (! (m_Splitter
&& m_NavigPan
))
1349 if (m_Splitter
->IsSplit())
1351 m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1352 m_Splitter
->Unsplit(m_NavigPan
);
1353 m_Cfg
.navig_on
= false;
1359 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
1360 m_Cfg
.navig_on
= true;
1365 case wxID_HTML_OPTIONS
:
1369 case wxID_HTML_BOOKMARKSADD
:
1374 item
= m_HtmlWin
->GetOpenedPageTitle();
1375 url
= m_HtmlWin
->GetOpenedPage();
1376 if (item
== wxEmptyString
)
1377 item
= url
.AfterLast(wxT('/'));
1378 if (m_BookmarksPages
.Index(url
) == wxNOT_FOUND
)
1380 m_Bookmarks
->Append(item
);
1381 m_BookmarksNames
.Add(item
);
1382 m_BookmarksPages
.Add(url
);
1387 case wxID_HTML_BOOKMARKSREMOVE
:
1392 item
= m_Bookmarks
->GetStringSelection();
1393 pos
= m_BookmarksNames
.Index(item
);
1394 if (pos
!= wxNOT_FOUND
)
1396 m_BookmarksNames
.RemoveAt(pos
);
1397 m_BookmarksPages
.RemoveAt(pos
);
1398 m_Bookmarks
->Delete(m_Bookmarks
->GetSelection());
1403 #if wxUSE_PRINTING_ARCHITECTURE
1404 case wxID_HTML_PRINT
:
1406 if (m_Printer
== NULL
)
1407 m_Printer
= new wxHtmlEasyPrinting(_("Help Printing"), this);
1408 if (!m_HtmlWin
->GetOpenedPage())
1409 wxLogWarning(_("Cannot print empty page."));
1411 m_Printer
->PrintFile(m_HtmlWin
->GetOpenedPage());
1416 case wxID_HTML_OPENFILE
:
1418 wxString filemask
= wxString(
1419 _("HTML files (*.html;*.htm)|*.html;*.htm|")) +
1420 _("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|") +
1421 _("HTML Help Project (*.hhp)|*.hhp|") +
1423 _("Compressed HTML Help file (*.chm)|*.chm|") +
1425 _("All files (*.*)|*");
1426 wxString s
= wxFileSelector(_("Open HTML document"),
1431 wxOPEN
| wxFILE_MUST_EXIST
,
1435 wxString ext
= s
.Right(4).Lower();
1436 if (ext
== _T(".zip") || ext
== _T(".htb") ||
1438 ext
== _T(".chm") ||
1447 m_HtmlWin
->LoadPage(s
);
1456 void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent
& event
)
1458 wxHtmlHelpTreeItemData
*pg
;
1459 wxHtmlContentsItem
*it
;
1461 pg
= (wxHtmlHelpTreeItemData
*) m_ContentsBox
->GetItemData(event
.GetItem());
1463 if (pg
&& m_UpdateContents
)
1465 it
= m_Data
->GetContents() + (pg
->m_Id
);
1466 m_UpdateContents
= false;
1467 if (it
->m_Page
[0] != 0)
1468 m_HtmlWin
->LoadPage(it
->GetFullPath());
1469 m_UpdateContents
= true;
1475 void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent
& WXUNUSED(event
))
1477 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_IndexList
->GetClientData(m_IndexList
->GetSelection());
1478 if (it
->m_Page
[0] != 0)
1479 m_HtmlWin
->LoadPage(it
->GetFullPath());
1480 NotifyPageChanged();
1484 void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent
& event
)
1486 wxString sr
= m_IndexText
->GetLineText(0);
1488 if (sr
== wxEmptyString
)
1495 const wxChar
*cstr
= sr
.c_str();
1500 m_IndexList
->Clear();
1501 int cnt
= m_Data
->GetIndexCnt();
1502 wxHtmlContentsItem
* index
= m_Data
->GetIndex();
1505 for (int i
= 0; i
< cnt
; i
++)
1507 wxStrncpy(mybuff
, index
[i
].m_Name
, 512);
1508 mybuff
[511] = _T('\0');
1509 for (ptr
= mybuff
; *ptr
!= 0; ptr
++)
1510 if (*ptr
>= _T('A') && *ptr
<= _T('Z'))
1511 *ptr
-= (wxChar
)(_T('A') - _T('a'));
1512 if (wxStrstr(mybuff
, cstr
) != NULL
)
1514 m_IndexList
->Append(index
[i
].m_Name
, (char*)(index
+ i
));
1518 if (index
[i
].m_Page
[0] != 0)
1519 m_HtmlWin
->LoadPage(index
[i
].GetFullPath());
1520 NotifyPageChanged();
1527 cnttext
.Printf(_("%i of %i"), displ
, cnt
);
1528 m_IndexCountInfo
->SetLabel(cnttext
);
1530 m_IndexText
->SetSelection(0, sr
.Length());
1531 m_IndexText
->SetFocus();
1535 void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent
& WXUNUSED(event
))
1539 m_IndexList
->Clear();
1540 int cnt
= m_Data
->GetIndexCnt();
1542 wxHtmlContentsItem
* index
= m_Data
->GetIndex();
1544 for (int i
= 0; i
< cnt
; i
++)
1546 m_IndexList
->Append(index
[i
].m_Name
, (char*)(index
+ i
));
1549 if (index
[i
].m_Page
[0] != 0)
1550 m_HtmlWin
->LoadPage(index
[i
].GetFullPath());
1551 NotifyPageChanged();
1557 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1558 m_IndexCountInfo
->SetLabel(cnttext
);
1562 void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent
& WXUNUSED(event
))
1564 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_SearchList
->GetClientData(m_SearchList
->GetSelection());
1567 if (it
->m_Page
[0] != 0)
1568 m_HtmlWin
->LoadPage(it
->GetFullPath());
1569 NotifyPageChanged();
1573 void wxHtmlHelpFrame::OnSearch(wxCommandEvent
& WXUNUSED(event
))
1575 wxString sr
= m_SearchText
->GetLineText(0);
1578 KeywordSearch(sr
, wxHELP_SEARCH_ALL
);
1581 void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent
& WXUNUSED(event
))
1583 wxString sr
= m_Bookmarks
->GetStringSelection();
1585 if (sr
!= wxEmptyString
&& sr
!= _("(bookmarks)"))
1587 m_HtmlWin
->LoadPage(m_BookmarksPages
[m_BookmarksNames
.Index(sr
)]);
1588 NotifyPageChanged();
1592 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent
& evt
)
1594 GetSize(&m_Cfg
.w
, &m_Cfg
.h
);
1595 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
1604 if (m_Splitter
&& m_Cfg
.navig_on
) m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1607 WriteCustomization(m_Config
, m_ConfigRoot
);
1609 if (m_helpController
&& m_helpController
->IsKindOf(CLASSINFO(wxHtmlHelpController
)))
1611 ((wxHtmlHelpController
*) m_helpController
)->OnCloseFrame(evt
);
1618 void wxHtmlHelpFrame::OnClose(wxCommandEvent
& event
)
1623 void wxHtmlHelpFrame::OnAbout(wxCommandEvent
& event
)
1625 wxMessageBox(wxT("wxWidgets HTML Help Viewer (c) 1998-2003, Vaclav Slavik et al"), wxT("HelpView"),
1626 wxICON_INFORMATION
|wxOK
, this);
1630 BEGIN_EVENT_TABLE(wxHtmlHelpFrame
, wxFrame
)
1631 EVT_ACTIVATE(wxHtmlHelpFrame::OnActivate
)
1632 EVT_TOOL_RANGE(wxID_HTML_PANEL
, wxID_HTML_OPTIONS
, wxHtmlHelpFrame::OnToolbar
)
1633 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE
, wxHtmlHelpFrame::OnToolbar
)
1634 EVT_BUTTON(wxID_HTML_BOOKMARKSADD
, wxHtmlHelpFrame::OnToolbar
)
1635 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL
, wxHtmlHelpFrame::OnContentsSel
)
1636 EVT_LISTBOX(wxID_HTML_INDEXLIST
, wxHtmlHelpFrame::OnIndexSel
)
1637 EVT_LISTBOX(wxID_HTML_SEARCHLIST
, wxHtmlHelpFrame::OnSearchSel
)
1638 EVT_BUTTON(wxID_HTML_SEARCHBUTTON
, wxHtmlHelpFrame::OnSearch
)
1639 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT
, wxHtmlHelpFrame::OnSearch
)
1640 EVT_BUTTON(wxID_HTML_INDEXBUTTON
, wxHtmlHelpFrame::OnIndexFind
)
1641 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT
, wxHtmlHelpFrame::OnIndexFind
)
1642 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL
, wxHtmlHelpFrame::OnIndexAll
)
1643 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST
, wxHtmlHelpFrame::OnBookmarksSel
)
1644 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow
)
1646 EVT_MENU(wxID_CLOSE
, wxHtmlHelpFrame::OnClose
)
1647 EVT_MENU(wxID_ABOUT
, wxHtmlHelpFrame::OnAbout
)
1652 #endif // wxUSE_WXHTML_HELP