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
, -1);
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
->SetAutoLayout(TRUE
);
316 m_NavigPan
->SetSizer(navigSizer
);
319 { // only html window, no notebook with index,contents etc
320 m_HtmlWin
= new wxHtmlWindow(this);
323 m_HtmlWin
->SetRelatedFrame(this, m_TitleFormat
);
324 m_HtmlWin
->SetRelatedStatusBar(0);
326 m_HtmlWin
->ReadCustomization(m_Config
, m_ConfigRoot
);
328 // contents tree panel?
329 if ( style
& wxHF_CONTENTS
)
331 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
332 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
334 topsizer
->Add(0, 10);
336 dummy
->SetAutoLayout(TRUE
);
337 dummy
->SetSizer(topsizer
);
339 if ( style
& wxHF_BOOKMARKS
)
341 m_Bookmarks
= new wxComboBox(dummy
, wxID_HTML_BOOKMARKSLIST
,
343 wxDefaultPosition
, wxDefaultSize
,
344 0, NULL
, wxCB_READONLY
| wxCB_SORT
);
345 m_Bookmarks
->Append(_("(bookmarks)"));
346 for (unsigned i
= 0; i
< m_BookmarksNames
.GetCount(); i
++)
347 m_Bookmarks
->Append(m_BookmarksNames
[i
]);
348 m_Bookmarks
->SetSelection(0);
350 wxBitmapButton
*bmpbt1
, *bmpbt2
;
351 bmpbt1
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSADD
,
352 wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK
,
353 wxART_HELP_BROWSER
));
354 bmpbt2
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSREMOVE
,
355 wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK
,
356 wxART_HELP_BROWSER
));
358 bmpbt1
->SetToolTip(_("Add current page to bookmarks"));
359 bmpbt2
->SetToolTip(_("Remove current page from bookmarks"));
360 #endif // wxUSE_TOOLTIPS
362 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
364 sizer
->Add(m_Bookmarks
, 1, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 5);
365 sizer
->Add(bmpbt1
, 0, wxALIGN_CENTRE_VERTICAL
| wxRIGHT
, 2);
366 sizer
->Add(bmpbt2
, 0, wxALIGN_CENTRE_VERTICAL
, 0);
368 topsizer
->Add(sizer
, 0, wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
, 10);
371 m_ContentsBox
= new wxTreeCtrl(dummy
, wxID_HTML_TREECTRL
,
372 wxDefaultPosition
, wxDefaultSize
,
374 wxTR_HAS_BUTTONS
| wxTR_HIDE_ROOT
|
377 m_ContentsBox
->AssignImageList(ContentsImageList
);
379 topsizer
->Add(m_ContentsBox
, 1,
380 wxEXPAND
| wxLEFT
| wxBOTTOM
| wxRIGHT
| wxADJUST_MINSIZE
,
383 m_NavigNotebook
->AddPage(dummy
, _("Contents"));
384 m_ContentsPage
= notebook_page
++;
387 // index listbox panel?
388 if ( style
& wxHF_INDEX
)
390 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
391 wxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
393 dummy
->SetAutoLayout(TRUE
);
394 dummy
->SetSizer(topsizer
);
396 m_IndexText
= new wxTextCtrl(dummy
, wxID_HTML_INDEXTEXT
, wxEmptyString
,
397 wxDefaultPosition
, wxDefaultSize
,
399 m_IndexButton
= new wxButton(dummy
, wxID_HTML_INDEXBUTTON
, _("Find"));
400 m_IndexButtonAll
= new wxButton(dummy
, wxID_HTML_INDEXBUTTONALL
,
402 m_IndexCountInfo
= new wxStaticText(dummy
, wxID_HTML_COUNTINFO
,
403 wxEmptyString
, wxDefaultPosition
,
405 wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
406 m_IndexList
= new wxListBox(dummy
, wxID_HTML_INDEXLIST
,
407 wxDefaultPosition
, wxDefaultSize
,
408 0, NULL
, wxLB_SINGLE
);
411 m_IndexButton
->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
412 m_IndexButtonAll
->SetToolTip(_("Show all items in index"));
413 #endif //wxUSE_TOOLTIPS
415 topsizer
->Add(m_IndexText
, 0, wxEXPAND
| wxALL
, 10);
416 wxSizer
*btsizer
= new wxBoxSizer(wxHORIZONTAL
);
417 btsizer
->Add(m_IndexButton
, 0, wxRIGHT
, 2);
418 btsizer
->Add(m_IndexButtonAll
);
419 topsizer
->Add(btsizer
, 0,
420 wxALIGN_RIGHT
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
421 topsizer
->Add(m_IndexCountInfo
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 2);
422 topsizer
->Add(m_IndexList
, 1, wxEXPAND
| wxALL
| wxADJUST_MINSIZE
, 2);
424 m_NavigNotebook
->AddPage(dummy
, _("Index"));
425 m_IndexPage
= notebook_page
++;
428 // search list panel?
429 if ( style
& wxHF_SEARCH
)
431 wxWindow
*dummy
= new wxPanel(m_NavigNotebook
, wxID_HTML_INDEXPAGE
);
432 wxSizer
*sizer
= new wxBoxSizer(wxVERTICAL
);
434 dummy
->SetAutoLayout(TRUE
);
435 dummy
->SetSizer(sizer
);
437 m_SearchText
= new wxTextCtrl(dummy
, wxID_HTML_SEARCHTEXT
,
439 wxDefaultPosition
, wxDefaultSize
,
441 m_SearchChoice
= new wxChoice(dummy
, wxID_HTML_SEARCHCHOICE
,
442 wxDefaultPosition
, wxDefaultSize
);
443 m_SearchCaseSensitive
= new wxCheckBox(dummy
, -1, _("Case sensitive"));
444 m_SearchWholeWords
= new wxCheckBox(dummy
, -1, _("Whole words only"));
445 m_SearchButton
= new wxButton(dummy
, wxID_HTML_SEARCHBUTTON
, _("Search"));
447 m_SearchButton
->SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
448 #endif //wxUSE_TOOLTIPS
449 m_SearchList
= new wxListBox(dummy
, wxID_HTML_SEARCHLIST
,
450 wxDefaultPosition
, wxDefaultSize
,
451 0, NULL
, wxLB_SINGLE
);
453 sizer
->Add(m_SearchText
, 0, wxEXPAND
| wxALL
, 10);
454 sizer
->Add(m_SearchChoice
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
455 sizer
->Add(m_SearchCaseSensitive
, 0, wxLEFT
| wxRIGHT
, 10);
456 sizer
->Add(m_SearchWholeWords
, 0, wxLEFT
| wxRIGHT
, 10);
457 sizer
->Add(m_SearchButton
, 0, wxALL
| wxALIGN_RIGHT
, 8);
458 sizer
->Add(m_SearchList
, 1, wxALL
| wxEXPAND
| wxADJUST_MINSIZE
, 2);
460 m_NavigNotebook
->AddPage(dummy
, _("Search"));
461 m_SearchPage
= notebook_page
;
464 m_HtmlWin
->Show(TRUE
);
470 navigSizer
->SetSizeHints(m_NavigPan
);
471 m_NavigPan
->Layout();
475 if ( m_NavigPan
&& m_Splitter
)
477 m_Splitter
->SetMinimumPaneSize(20);
478 if ( m_Cfg
.navig_on
)
479 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
481 if ( m_Cfg
.navig_on
)
483 m_NavigPan
->Show(TRUE
);
484 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
488 m_NavigPan
->Show(FALSE
);
489 m_Splitter
->Initialize(m_HtmlWin
);
496 wxHtmlHelpFrame::~wxHtmlHelpFrame()
498 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
501 if (m_NormalFonts
) delete m_NormalFonts
;
502 if (m_FixedFonts
) delete m_FixedFonts
;
505 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
508 #if wxUSE_PRINTING_ARCHITECTURE
509 if (m_Printer
) delete m_Printer
;
515 void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar
*toolBar
, int style
)
517 wxBitmap wpanelBitmap
=
518 wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL
, wxART_HELP_BROWSER
);
519 wxBitmap wbackBitmap
=
520 wxArtProvider::GetBitmap(wxART_GO_BACK
, wxART_HELP_BROWSER
);
521 wxBitmap wforwardBitmap
=
522 wxArtProvider::GetBitmap(wxART_GO_FORWARD
, wxART_HELP_BROWSER
);
523 wxBitmap wupnodeBitmap
=
524 wxArtProvider::GetBitmap(wxART_GO_TO_PARENT
, wxART_HELP_BROWSER
);
526 wxArtProvider::GetBitmap(wxART_GO_UP
, wxART_HELP_BROWSER
);
527 wxBitmap wdownBitmap
=
528 wxArtProvider::GetBitmap(wxART_GO_DOWN
, wxART_HELP_BROWSER
);
529 wxBitmap wopenBitmap
=
530 wxArtProvider::GetBitmap(wxART_FILE_OPEN
, wxART_HELP_BROWSER
);
531 wxBitmap wprintBitmap
=
532 wxArtProvider::GetBitmap(wxART_PRINT
, wxART_HELP_BROWSER
);
533 wxBitmap woptionsBitmap
=
534 wxArtProvider::GetBitmap(wxART_HELP_SETTINGS
, wxART_HELP_BROWSER
);
536 wxASSERT_MSG( (wpanelBitmap
.Ok() && wbackBitmap
.Ok() &&
537 wforwardBitmap
.Ok() && wupnodeBitmap
.Ok() &&
538 wupBitmap
.Ok() && wdownBitmap
.Ok() &&
539 wopenBitmap
.Ok() && wprintBitmap
.Ok() &&
540 woptionsBitmap
.Ok()),
541 wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
544 toolBar
->AddTool(wxID_HTML_PANEL
, wpanelBitmap
, wxNullBitmap
,
545 FALSE
, -1, -1, (wxObject
*) NULL
,
546 _("Show/hide navigation panel"));
548 toolBar
->AddSeparator();
549 toolBar
->AddTool(wxID_HTML_BACK
, wbackBitmap
, wxNullBitmap
,
550 FALSE
, -1, -1, (wxObject
*) NULL
,
552 toolBar
->AddTool(wxID_HTML_FORWARD
, wforwardBitmap
, wxNullBitmap
,
553 FALSE
, -1, -1, (wxObject
*) NULL
,
555 toolBar
->AddSeparator();
557 toolBar
->AddTool(wxID_HTML_UPNODE
, wupnodeBitmap
, wxNullBitmap
,
558 FALSE
, -1, -1, (wxObject
*) NULL
,
559 _("Go one level up in document hierarchy"));
560 toolBar
->AddTool(wxID_HTML_UP
, wupBitmap
, wxNullBitmap
,
561 FALSE
, -1, -1, (wxObject
*) NULL
,
563 toolBar
->AddTool(wxID_HTML_DOWN
, wdownBitmap
, wxNullBitmap
,
564 FALSE
, -1, -1, (wxObject
*) NULL
,
567 if ((style
& wxHF_PRINT
) || (style
& wxHF_OPEN_FILES
))
568 toolBar
->AddSeparator();
570 if (style
& wxHF_OPEN_FILES
)
571 toolBar
->AddTool(wxID_HTML_OPENFILE
, wopenBitmap
, wxNullBitmap
,
572 FALSE
, -1, -1, (wxObject
*) NULL
,
573 _("Open HTML document"));
575 #if wxUSE_PRINTING_ARCHITECTURE
576 if (style
& wxHF_PRINT
)
577 toolBar
->AddTool(wxID_HTML_PRINT
, wprintBitmap
, wxNullBitmap
,
578 FALSE
, -1, -1, (wxObject
*) NULL
,
579 _("Print this page"));
582 toolBar
->AddSeparator();
583 toolBar
->AddTool(wxID_HTML_OPTIONS
, woptionsBitmap
, wxNullBitmap
,
584 FALSE
, -1, -1, (wxObject
*) NULL
,
585 _("Display options dialog"));
587 #endif //wxUSE_TOOLBAR
590 void wxHtmlHelpFrame::SetTitleFormat(const wxString
& format
)
593 m_HtmlWin
->SetRelatedFrame(this, format
);
594 m_TitleFormat
= format
;
598 bool wxHtmlHelpFrame::Display(const wxString
& x
)
600 wxString url
= m_Data
->FindPageByName(x
);
603 m_HtmlWin
->LoadPage(url
);
610 bool wxHtmlHelpFrame::Display(const int id
)
612 wxString url
= m_Data
->FindPageById(id
);
615 m_HtmlWin
->LoadPage(url
);
624 bool wxHtmlHelpFrame::DisplayContents()
628 if (!m_Splitter
->IsSplit())
630 m_NavigPan
->Show(TRUE
);
631 m_HtmlWin
->Show(TRUE
);
632 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
633 m_Cfg
.navig_on
= TRUE
;
635 m_NavigNotebook
->SetSelection(0);
636 if (m_Data
->GetBookRecArray().GetCount() > 0)
638 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
639 if (!book
.GetStart().IsEmpty())
640 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
647 bool wxHtmlHelpFrame::DisplayIndex()
651 if (!m_Splitter
->IsSplit())
653 m_NavigPan
->Show(TRUE
);
654 m_HtmlWin
->Show(TRUE
);
655 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
657 m_NavigNotebook
->SetSelection(1);
658 if (m_Data
->GetBookRecArray().GetCount() > 0)
660 wxHtmlBookRecord
& book
= m_Data
->GetBookRecArray()[0];
661 if (!book
.GetStart().IsEmpty())
662 m_HtmlWin
->LoadPage(book
.GetFullPath(book
.GetStart()));
669 bool wxHtmlHelpFrame::KeywordSearch(const wxString
& keyword
,
670 wxHelpSearchMode mode
)
672 if (mode
== wxHELP_SEARCH_ALL
)
674 if ( !(m_SearchList
&&
675 m_SearchButton
&& m_SearchText
&& m_SearchChoice
) )
678 else if (mode
== wxHELP_SEARCH_INDEX
)
680 if ( !(m_IndexList
&&
681 m_IndexButton
&& m_IndexButtonAll
&& m_IndexText
) )
687 wxString book
= wxEmptyString
;
689 if (!m_Splitter
->IsSplit())
691 m_NavigPan
->Show(TRUE
);
692 m_HtmlWin
->Show(TRUE
);
693 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
696 if (mode
== wxHELP_SEARCH_ALL
)
698 m_NavigNotebook
->SetSelection(m_SearchPage
);
699 m_SearchList
->Clear();
700 m_SearchText
->SetValue(keyword
);
701 m_SearchButton
->Enable(false);
703 if (m_SearchChoice
->GetSelection() != 0)
704 book
= m_SearchChoice
->GetStringSelection();
706 wxHtmlSearchStatus
status(m_Data
, keyword
,
707 m_SearchCaseSensitive
->GetValue(),
708 m_SearchWholeWords
->GetValue(),
711 wxProgressDialog
progress(_("Searching..."),
712 _("No matching page found yet"),
713 status
.GetMaxIndex(), this,
714 wxPD_APP_MODAL
| wxPD_CAN_ABORT
| wxPD_AUTO_HIDE
);
717 while (status
.IsActive())
719 curi
= status
.GetCurIndex();
720 if (curi
% 32 == 0 && progress
.Update(curi
) == FALSE
)
724 foundstr
.Printf(_("Found %i matches"), ++foundcnt
);
725 progress
.Update(status
.GetCurIndex(), foundstr
);
726 m_SearchList
->Append(status
.GetName(), status
.GetContentsItem());
730 m_SearchButton
->Enable(TRUE
);
731 m_SearchText
->SetSelection(0, keyword
.Length());
732 m_SearchText
->SetFocus();
734 else if (mode
== wxHELP_SEARCH_INDEX
)
736 m_NavigNotebook
->SetSelection(m_IndexPage
);
737 m_IndexList
->Clear();
738 m_IndexButton
->Enable(false);
739 m_IndexButtonAll
->Enable(false);
740 m_IndexText
->SetValue(keyword
);
742 wxCommandEvent dummy
;
743 OnIndexFind(dummy
); // what a hack...
744 m_IndexButton
->Enable(true);
745 m_IndexButtonAll
->Enable(true);
746 foundcnt
= m_IndexList
->GetCount();
751 wxHtmlContentsItem
*it
;
755 wxFAIL_MSG( _T("unknown help search mode") );
758 case wxHELP_SEARCH_ALL
:
759 it
= (wxHtmlContentsItem
*) m_SearchList
->GetClientData(0);
762 case wxHELP_SEARCH_INDEX
:
763 it
= (wxHtmlContentsItem
*) m_IndexList
->GetClientData(0);
769 m_HtmlWin
->LoadPage(it
->GetFullPath());
777 void wxHtmlHelpFrame::CreateContents()
784 WX_CLEAR_HASH_TABLE(*m_PagesHash
);
787 m_PagesHash
= new wxHashTable(wxKEY_STRING
, 2 * m_Data
->GetContentsCnt());
789 int cnt
= m_Data
->GetContentsCnt();
792 wxHtmlContentsItem
*it
;
794 const int MAX_ROOTS
= 64;
795 wxTreeItemId roots
[MAX_ROOTS
];
796 // VS: this array holds information about whether we've set item icon at
797 // given level. This is neccessary because m_Data has flat structure
798 // and there's no way of recognizing if some item has subitems or not.
799 // We set the icon later: when we find an item with level=n, we know
800 // that the last item with level=n-1 was folder with subitems, so we
801 // set its icon accordingly
802 bool imaged
[MAX_ROOTS
];
803 m_ContentsBox
->DeleteAllItems();
805 roots
[0] = m_ContentsBox
->AddRoot(_("(Help)"));
808 for (it
= m_Data
->GetContents(), i
= 0; i
< cnt
; i
++, it
++)
811 if (it
->m_Level
== 0)
813 if (m_hfStyle
& wxHF_MERGE_BOOKS
)
814 // VS: we don't want book nodes, books' content should
815 // appear under tree's root. This line will create "fake"
816 // record about book node so that the rest of this look
817 // will believe there really _is_ book node and will
822 roots
[1] = m_ContentsBox
->AppendItem(roots
[0],
823 it
->m_Name
, IMG_Book
, -1,
824 new wxHtmlHelpTreeItemData(i
));
825 m_ContentsBox
->SetItemBold(roots
[1], TRUE
);
829 // ...and their contents:
832 roots
[it
->m_Level
+ 1] = m_ContentsBox
->AppendItem(
833 roots
[it
->m_Level
], it
->m_Name
, IMG_Page
,
834 -1, new wxHtmlHelpTreeItemData(i
));
835 imaged
[it
->m_Level
+ 1] = FALSE
;
838 m_PagesHash
->Put(it
->GetFullPath(),
839 new wxHtmlHelpHashData(i
, roots
[it
->m_Level
+ 1]));
841 // Set the icon for the node one level up in the hiearachy,
842 // unless already done (see comment above imaged[] declaration)
843 if (!imaged
[it
->m_Level
])
845 int image
= IMG_Folder
;
846 if (m_hfStyle
& wxHF_ICONS_BOOK
)
848 else if (m_hfStyle
& wxHF_ICONS_BOOK_CHAPTER
)
849 image
= (it
->m_Level
== 1) ? IMG_Book
: IMG_Folder
;
850 m_ContentsBox
->SetItemImage(roots
[it
->m_Level
], image
);
851 m_ContentsBox
->SetItemImage(roots
[it
->m_Level
], image
,
852 wxTreeItemIcon_Selected
);
853 imaged
[it
->m_Level
] = TRUE
;
859 void wxHtmlHelpFrame::CreateIndex()
864 m_IndexList
->Clear();
866 int cnt
= m_Data
->GetIndexCnt();
869 if (cnt
> INDEX_IS_SMALL
) cnttext
.Printf(_("%i of %i"), 0, cnt
);
870 else cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
871 m_IndexCountInfo
->SetLabel(cnttext
);
872 if (cnt
> INDEX_IS_SMALL
) return;
874 wxHtmlContentsItem
* index
= m_Data
->GetIndex();
876 for (int i
= 0; i
< cnt
; i
++)
877 m_IndexList
->Append(index
[i
].m_Name
, (char*)(index
+ i
));
880 void wxHtmlHelpFrame::CreateSearch()
882 if (! (m_SearchList
&& m_SearchChoice
))
884 m_SearchList
->Clear();
885 m_SearchChoice
->Clear();
886 m_SearchChoice
->Append(_("Search in all books"));
887 const wxHtmlBookRecArray
& bookrec
= m_Data
->GetBookRecArray();
888 int i
, cnt
= bookrec
.GetCount();
889 for (i
= 0; i
< cnt
; i
++)
890 m_SearchChoice
->Append(bookrec
[i
].GetTitle());
891 m_SearchChoice
->SetSelection(0);
895 void wxHtmlHelpFrame::RefreshLists()
902 void wxHtmlHelpFrame::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
907 if (path
!= wxEmptyString
)
909 oldpath
= cfg
->GetPath();
910 cfg
->SetPath(_T("/") + path
);
913 m_Cfg
.navig_on
= cfg
->Read(wxT("hcNavigPanel"), m_Cfg
.navig_on
) != 0;
914 m_Cfg
.sashpos
= cfg
->Read(wxT("hcSashPos"), m_Cfg
.sashpos
);
915 m_Cfg
.x
= cfg
->Read(wxT("hcX"), m_Cfg
.x
);
916 m_Cfg
.y
= cfg
->Read(wxT("hcY"), m_Cfg
.y
);
917 m_Cfg
.w
= cfg
->Read(wxT("hcW"), m_Cfg
.w
);
918 m_Cfg
.h
= cfg
->Read(wxT("hcH"), m_Cfg
.h
);
920 m_FixedFace
= cfg
->Read(wxT("hcFixedFace"), m_FixedFace
);
921 m_NormalFace
= cfg
->Read(wxT("hcNormalFace"), m_NormalFace
);
922 m_FontSize
= cfg
->Read(wxT("hcBaseFontSize"), m_FontSize
);
929 cnt
= cfg
->Read(wxT("hcBookmarksCnt"), 0L);
932 m_BookmarksNames
.Clear();
933 m_BookmarksPages
.Clear();
936 m_Bookmarks
->Clear();
937 m_Bookmarks
->Append(_("(bookmarks)"));
940 for (i
= 0; i
< cnt
; i
++)
942 val
.Printf(wxT("hcBookmark_%i"), i
);
944 m_BookmarksNames
.Add(s
);
945 if (m_Bookmarks
) m_Bookmarks
->Append(s
);
946 val
.Printf(wxT("hcBookmark_%i_url"), i
);
948 m_BookmarksPages
.Add(s
);
954 m_HtmlWin
->ReadCustomization(cfg
);
956 if (path
!= wxEmptyString
)
957 cfg
->SetPath(oldpath
);
960 void wxHtmlHelpFrame::WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
)
965 if (path
!= wxEmptyString
)
967 oldpath
= cfg
->GetPath();
968 cfg
->SetPath(_T("/") + path
);
971 cfg
->Write(wxT("hcNavigPanel"), m_Cfg
.navig_on
);
972 cfg
->Write(wxT("hcSashPos"), (long)m_Cfg
.sashpos
);
975 // Don't write if iconized as this would make the window
976 // disappear next time it is shown!
977 cfg
->Write(wxT("hcX"), (long)m_Cfg
.x
);
978 cfg
->Write(wxT("hcY"), (long)m_Cfg
.y
);
979 cfg
->Write(wxT("hcW"), (long)m_Cfg
.w
);
980 cfg
->Write(wxT("hcH"), (long)m_Cfg
.h
);
982 cfg
->Write(wxT("hcFixedFace"), m_FixedFace
);
983 cfg
->Write(wxT("hcNormalFace"), m_NormalFace
);
984 cfg
->Write(wxT("hcBaseFontSize"), (long)m_FontSize
);
989 int cnt
= m_BookmarksNames
.GetCount();
992 cfg
->Write(wxT("hcBookmarksCnt"), (long)cnt
);
993 for (i
= 0; i
< cnt
; i
++)
995 val
.Printf(wxT("hcBookmark_%i"), i
);
996 cfg
->Write(val
, m_BookmarksNames
[i
]);
997 val
.Printf(wxT("hcBookmark_%i_url"), i
);
998 cfg
->Write(val
, m_BookmarksPages
[i
]);
1003 m_HtmlWin
->WriteCustomization(cfg
);
1005 if (path
!= wxEmptyString
)
1006 cfg
->SetPath(oldpath
);
1013 static void SetFontsToHtmlWin(wxHtmlWindow
*win
, wxString scalf
, wxString fixf
, int size
)
1016 f_sizes
[0] = int(size
* 0.6);
1017 f_sizes
[1] = int(size
* 0.8);
1019 f_sizes
[3] = int(size
* 1.2);
1020 f_sizes
[4] = int(size
* 1.4);
1021 f_sizes
[5] = int(size
* 1.6);
1022 f_sizes
[6] = int(size
* 1.8);
1024 win
->SetFonts(scalf
, fixf
, f_sizes
);
1028 class wxHtmlHelpFrameOptionsDialog
: public wxDialog
1031 wxComboBox
*NormalFont
, *FixedFont
;
1032 wxSpinCtrl
*FontSize
;
1033 wxHtmlWindow
*TestWin
;
1035 wxHtmlHelpFrameOptionsDialog(wxWindow
*parent
)
1036 : wxDialog(parent
, -1, wxString(_("Help Browser Options")))
1038 wxBoxSizer
*topsizer
= new wxBoxSizer(wxVERTICAL
);
1039 wxFlexGridSizer
*sizer
= new wxFlexGridSizer(2, 3, 2, 5);
1041 sizer
->Add(new wxStaticText(this, -1, _("Normal font:")));
1042 sizer
->Add(new wxStaticText(this, -1, _("Fixed font:")));
1043 sizer
->Add(new wxStaticText(this, -1, _("Font size:")));
1045 sizer
->Add(NormalFont
= new wxComboBox(this, -1, wxEmptyString
, wxDefaultPosition
,
1047 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1049 sizer
->Add(FixedFont
= new wxComboBox(this, -1, wxEmptyString
, wxDefaultPosition
,
1051 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
));
1053 sizer
->Add(FontSize
= new wxSpinCtrl(this, -1));
1054 FontSize
->SetRange(2, 100);
1056 topsizer
->Add(sizer
, 0, wxLEFT
|wxRIGHT
|wxTOP
, 10);
1058 topsizer
->Add(new wxStaticText(this, -1, _("Preview:")),
1059 0, wxLEFT
| wxTOP
, 10);
1060 topsizer
->Add(TestWin
= new wxHtmlWindow(this, -1, wxDefaultPosition
, wxSize(20, 150),
1061 wxHW_SCROLLBAR_AUTO
| wxSUNKEN_BORDER
),
1062 1, wxEXPAND
| wxLEFT
|wxTOP
|wxRIGHT
, 10);
1064 wxBoxSizer
*sizer2
= new wxBoxSizer(wxHORIZONTAL
);
1066 sizer2
->Add(ok
= new wxButton(this, wxID_OK
, _("OK")), 0, wxALL
, 10);
1068 sizer2
->Add(new wxButton(this, wxID_CANCEL
, _("Cancel")), 0, wxALL
, 10);
1069 topsizer
->Add(sizer2
, 0, wxALIGN_RIGHT
);
1071 SetAutoLayout(TRUE
);
1073 topsizer
->Fit(this);
1078 void UpdateTestWin()
1081 SetFontsToHtmlWin(TestWin
,
1082 NormalFont
->GetStringSelection(),
1083 FixedFont
->GetStringSelection(),
1084 FontSize
->GetValue());
1086 wxString
content(_("font size"));
1088 content
= _T("<font size=-2>") + content
+ _T(" -2</font><br>")
1089 _T("<font size=-1>") + content
+ _T(" -1</font><br>")
1090 _T("<font size=+0>") + content
+ _T(" +0</font><br>")
1091 _T("<font size=+1>") + content
+ _T(" +1</font><br>")
1092 _T("<font size=+2>") + content
+ _T(" +2</font><br>")
1093 _T("<font size=+3>") + content
+ _T(" +3</font><br>")
1094 _T("<font size=+4>") + content
+ _T(" +4</font><br>") ;
1096 content
= wxString( _T("<html><body><table><tr><td>") ) +
1097 _("Normal face<br>and <u>underlined</u>. ") +
1098 _("<i>Italic face.</i> ") +
1099 _("<b>Bold face.</b> ") +
1100 _("<b><i>Bold italic face.</i></b><br>") +
1102 wxString( _T("</td><td><tt>") ) +
1103 _("Fixed size face.<br> <b>bold</b> <i>italic</i> ") +
1104 _("<b><i>bold italic <u>underlined</u></i></b><br>") +
1106 _T("</tt></td></tr></table></body></html>");
1108 TestWin
->SetPage( content
);
1111 void OnUpdate(wxCommandEvent
& WXUNUSED(event
))
1115 void OnUpdateSpin(wxSpinEvent
& WXUNUSED(event
))
1120 DECLARE_EVENT_TABLE()
1121 DECLARE_NO_COPY_CLASS(wxHtmlHelpFrameOptionsDialog
)
1124 BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog
, wxDialog
)
1125 EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate
)
1126 EVT_SPINCTRL(-1, wxHtmlHelpFrameOptionsDialog::OnUpdateSpin
)
1129 void wxHtmlHelpFrame::OptionsDialog()
1131 wxHtmlHelpFrameOptionsDialog
dlg(this);
1134 if (m_NormalFonts
== NULL
)
1136 wxFontEnumerator enu
;
1137 enu
.EnumerateFacenames();
1138 m_NormalFonts
= new wxArrayString
;
1139 *m_NormalFonts
= *enu
.GetFacenames();
1140 m_NormalFonts
->Sort(wxStringSortAscending
);
1142 if (m_FixedFonts
== NULL
)
1144 wxFontEnumerator enu
;
1145 enu
.EnumerateFacenames(wxFONTENCODING_SYSTEM
, TRUE
);
1146 m_FixedFonts
= new wxArrayString
;
1147 *m_FixedFonts
= *enu
.GetFacenames();
1148 m_FixedFonts
->Sort(wxStringSortAscending
);
1151 // VS: We want to show the font that is actually used by wxHtmlWindow.
1152 // If customization dialog wasn't used yet, facenames are empty and
1153 // wxHtmlWindow uses default fonts -- let's find out what they
1154 // are so that we can pass them to the dialog:
1155 if (m_NormalFace
.empty())
1157 wxFont
fnt(m_FontSize
, wxSWISS
, wxNORMAL
, wxNORMAL
, FALSE
);
1158 m_NormalFace
= fnt
.GetFaceName();
1160 if (m_FixedFace
.empty())
1162 wxFont
fnt(m_FontSize
, wxMODERN
, wxNORMAL
, wxNORMAL
, FALSE
);
1163 m_FixedFace
= fnt
.GetFaceName();
1166 for (i
= 0; i
< m_NormalFonts
->GetCount(); i
++)
1167 dlg
.NormalFont
->Append((*m_NormalFonts
)[i
]);
1168 for (i
= 0; i
< m_FixedFonts
->GetCount(); i
++)
1169 dlg
.FixedFont
->Append((*m_FixedFonts
)[i
]);
1170 if (!m_NormalFace
.empty())
1171 dlg
.NormalFont
->SetStringSelection(m_NormalFace
);
1173 dlg
.NormalFont
->SetSelection(0);
1174 if (!m_FixedFace
.empty())
1175 dlg
.FixedFont
->SetStringSelection(m_FixedFace
);
1177 dlg
.FixedFont
->SetSelection(0);
1178 dlg
.FontSize
->SetValue(m_FontSize
);
1179 dlg
.UpdateTestWin();
1181 if (dlg
.ShowModal() == wxID_OK
)
1183 m_NormalFace
= dlg
.NormalFont
->GetStringSelection();
1184 m_FixedFace
= dlg
.FixedFont
->GetStringSelection();
1185 m_FontSize
= dlg
.FontSize
->GetValue();
1186 SetFontsToHtmlWin(m_HtmlWin
, m_NormalFace
, m_FixedFace
, m_FontSize
);
1192 void wxHtmlHelpFrame::NotifyPageChanged()
1194 if (m_UpdateContents
&& m_PagesHash
)
1196 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1197 wxHtmlHelpHashData
*ha
;
1199 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage());
1201 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage() + wxT("#") + an
);
1204 bool olduc
= m_UpdateContents
;
1205 m_UpdateContents
= FALSE
;
1206 m_ContentsBox
->SelectItem(ha
->m_Id
);
1207 m_ContentsBox
->EnsureVisible(ha
->m_Id
);
1208 m_UpdateContents
= olduc
;
1220 void wxHtmlHelpFrame::OnActivate(wxActivateEvent
& event
)
1222 // This saves one mouse click when using the
1223 // wxHTML for context sensitive help systems
1225 // NB: wxActivateEvent is a bit broken in wxGTK
1226 // and is sometimes sent when it should not be
1227 if (event
.GetActive() && m_HtmlWin
)
1228 m_HtmlWin
->SetFocus();
1234 void wxHtmlHelpFrame::OnToolbar(wxCommandEvent
& event
)
1236 switch (event
.GetId())
1238 case wxID_HTML_BACK
:
1239 m_HtmlWin
->HistoryBack();
1240 NotifyPageChanged();
1243 case wxID_HTML_FORWARD
:
1244 m_HtmlWin
->HistoryForward();
1245 NotifyPageChanged();
1251 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1252 wxHtmlHelpHashData
*ha
;
1254 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage());
1256 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage() + wxT("#") + an
);
1257 if (ha
&& ha
->m_Index
> 0)
1259 wxHtmlContentsItem
*it
= m_Data
->GetContents() + (ha
->m_Index
- 1);
1260 if (it
->m_Page
[0] != 0)
1262 m_HtmlWin
->LoadPage(it
->GetFullPath());
1263 NotifyPageChanged();
1269 case wxID_HTML_UPNODE
:
1272 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1273 wxHtmlHelpHashData
*ha
;
1275 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage());
1277 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(m_HtmlWin
->GetOpenedPage() + wxT("#") + an
);
1278 if (ha
&& ha
->m_Index
> 0)
1280 int level
= m_Data
->GetContents()[ha
->m_Index
].m_Level
- 1;
1281 wxHtmlContentsItem
*it
;
1282 int ind
= ha
->m_Index
- 1;
1284 it
= m_Data
->GetContents() + ind
;
1285 while (ind
>= 0 && it
->m_Level
!= level
) ind
--, it
--;
1288 if (it
->m_Page
[0] != 0)
1290 m_HtmlWin
->LoadPage(it
->GetFullPath());
1291 NotifyPageChanged();
1298 case wxID_HTML_DOWN
:
1301 wxString an
= m_HtmlWin
->GetOpenedAnchor();
1303 wxHtmlHelpHashData
*ha
;
1305 if (an
.IsEmpty()) adr
= m_HtmlWin
->GetOpenedPage();
1306 else adr
= m_HtmlWin
->GetOpenedPage() + wxT("#") + an
;
1308 ha
= (wxHtmlHelpHashData
*) m_PagesHash
->Get(adr
);
1310 if (ha
&& ha
->m_Index
< m_Data
->GetContentsCnt() - 1)
1312 wxHtmlContentsItem
*it
= m_Data
->GetContents() + (ha
->m_Index
+ 1);
1314 while (it
->GetFullPath() == adr
) it
++;
1316 if (it
->m_Page
[0] != 0)
1318 m_HtmlWin
->LoadPage(it
->GetFullPath());
1319 NotifyPageChanged();
1325 case wxID_HTML_PANEL
:
1327 if (! (m_Splitter
&& m_NavigPan
))
1329 if (m_Splitter
->IsSplit())
1331 m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1332 m_Splitter
->Unsplit(m_NavigPan
);
1333 m_Cfg
.navig_on
= FALSE
;
1337 m_NavigPan
->Show(TRUE
);
1338 m_HtmlWin
->Show(TRUE
);
1339 m_Splitter
->SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
1340 m_Cfg
.navig_on
= TRUE
;
1345 case wxID_HTML_OPTIONS
:
1349 case wxID_HTML_BOOKMARKSADD
:
1354 item
= m_HtmlWin
->GetOpenedPageTitle();
1355 url
= m_HtmlWin
->GetOpenedPage();
1356 if (item
== wxEmptyString
)
1357 item
= url
.AfterLast(wxT('/'));
1358 if (m_BookmarksPages
.Index(url
) == wxNOT_FOUND
)
1360 m_Bookmarks
->Append(item
);
1361 m_BookmarksNames
.Add(item
);
1362 m_BookmarksPages
.Add(url
);
1367 case wxID_HTML_BOOKMARKSREMOVE
:
1372 item
= m_Bookmarks
->GetStringSelection();
1373 pos
= m_BookmarksNames
.Index(item
);
1374 if (pos
!= wxNOT_FOUND
)
1376 m_BookmarksNames
.RemoveAt(pos
);
1377 m_BookmarksPages
.RemoveAt(pos
);
1378 m_Bookmarks
->Delete(m_Bookmarks
->GetSelection());
1383 #if wxUSE_PRINTING_ARCHITECTURE
1384 case wxID_HTML_PRINT
:
1386 if (m_Printer
== NULL
)
1387 m_Printer
= new wxHtmlEasyPrinting(_("Help Printing"), this);
1388 if (!m_HtmlWin
->GetOpenedPage())
1389 wxLogWarning(_("Cannot print empty page."));
1391 m_Printer
->PrintFile(m_HtmlWin
->GetOpenedPage());
1396 case wxID_HTML_OPENFILE
:
1398 wxString filemask
= wxString(
1399 _("HTML files (*.html;*.htm)|*.html;*.htm|")) +
1400 _("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|") +
1401 _("HTML Help Project (*.hhp)|*.hhp|") +
1403 _("Compressed HTML Help file (*.chm)|*.chm|") +
1405 _("All files (*.*)|*");
1406 wxString s
= wxFileSelector(_("Open HTML document"),
1411 wxOPEN
| wxFILE_MUST_EXIST
,
1415 wxString ext
= s
.Right(4).Lower();
1416 if (ext
== _T(".zip") || ext
== _T(".htb") ||
1418 ext
== _T(".chm") ||
1427 m_HtmlWin
->LoadPage(s
);
1436 void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent
& event
)
1438 wxHtmlHelpTreeItemData
*pg
;
1439 wxHtmlContentsItem
*it
;
1441 pg
= (wxHtmlHelpTreeItemData
*) m_ContentsBox
->GetItemData(event
.GetItem());
1443 if (pg
&& m_UpdateContents
)
1445 it
= m_Data
->GetContents() + (pg
->m_Id
);
1446 m_UpdateContents
= FALSE
;
1447 if (it
->m_Page
[0] != 0)
1448 m_HtmlWin
->LoadPage(it
->GetFullPath());
1449 m_UpdateContents
= TRUE
;
1455 void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent
& WXUNUSED(event
))
1457 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_IndexList
->GetClientData(m_IndexList
->GetSelection());
1458 if (it
->m_Page
[0] != 0)
1459 m_HtmlWin
->LoadPage(it
->GetFullPath());
1460 NotifyPageChanged();
1464 void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent
& event
)
1466 wxString sr
= m_IndexText
->GetLineText(0);
1468 if (sr
== wxEmptyString
)
1475 const wxChar
*cstr
= sr
.c_str();
1480 m_IndexList
->Clear();
1481 int cnt
= m_Data
->GetIndexCnt();
1482 wxHtmlContentsItem
* index
= m_Data
->GetIndex();
1485 for (int i
= 0; i
< cnt
; i
++)
1487 wxStrncpy(mybuff
, index
[i
].m_Name
, 512);
1488 mybuff
[511] = _T('\0');
1489 for (ptr
= mybuff
; *ptr
!= 0; ptr
++)
1490 if (*ptr
>= _T('A') && *ptr
<= _T('Z'))
1491 *ptr
-= (wxChar
)(_T('A') - _T('a'));
1492 if (wxStrstr(mybuff
, cstr
) != NULL
)
1494 m_IndexList
->Append(index
[i
].m_Name
, (char*)(index
+ i
));
1498 if (index
[i
].m_Page
[0] != 0)
1499 m_HtmlWin
->LoadPage(index
[i
].GetFullPath());
1500 NotifyPageChanged();
1507 cnttext
.Printf(_("%i of %i"), displ
, cnt
);
1508 m_IndexCountInfo
->SetLabel(cnttext
);
1510 m_IndexText
->SetSelection(0, sr
.Length());
1511 m_IndexText
->SetFocus();
1515 void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent
& WXUNUSED(event
))
1519 m_IndexList
->Clear();
1520 int cnt
= m_Data
->GetIndexCnt();
1522 wxHtmlContentsItem
* index
= m_Data
->GetIndex();
1524 for (int i
= 0; i
< cnt
; i
++)
1526 m_IndexList
->Append(index
[i
].m_Name
, (char*)(index
+ i
));
1529 if (index
[i
].m_Page
[0] != 0)
1530 m_HtmlWin
->LoadPage(index
[i
].GetFullPath());
1531 NotifyPageChanged();
1537 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1538 m_IndexCountInfo
->SetLabel(cnttext
);
1542 void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent
& WXUNUSED(event
))
1544 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_SearchList
->GetClientData(m_SearchList
->GetSelection());
1547 if (it
->m_Page
[0] != 0)
1548 m_HtmlWin
->LoadPage(it
->GetFullPath());
1549 NotifyPageChanged();
1553 void wxHtmlHelpFrame::OnSearch(wxCommandEvent
& WXUNUSED(event
))
1555 wxString sr
= m_SearchText
->GetLineText(0);
1558 KeywordSearch(sr
, wxHELP_SEARCH_ALL
);
1561 void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent
& WXUNUSED(event
))
1563 wxString sr
= m_Bookmarks
->GetStringSelection();
1565 if (sr
!= wxEmptyString
&& sr
!= _("(bookmarks)"))
1567 m_HtmlWin
->LoadPage(m_BookmarksPages
[m_BookmarksNames
.Index(sr
)]);
1568 NotifyPageChanged();
1572 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent
& evt
)
1574 GetSize(&m_Cfg
.w
, &m_Cfg
.h
);
1575 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
1584 if (m_Splitter
&& m_Cfg
.navig_on
) m_Cfg
.sashpos
= m_Splitter
->GetSashPosition();
1587 WriteCustomization(m_Config
, m_ConfigRoot
);
1589 if (m_helpController
&& m_helpController
->IsKindOf(CLASSINFO(wxHtmlHelpController
)))
1591 ((wxHtmlHelpController
*) m_helpController
)->OnCloseFrame(evt
);
1598 void wxHtmlHelpFrame::OnClose(wxCommandEvent
& event
)
1603 void wxHtmlHelpFrame::OnAbout(wxCommandEvent
& event
)
1605 wxMessageBox(wxT("wxWindows HTML Help Viewer (c) 1998-2003, Vaclav Slavik et al"), wxT("HelpView"),
1606 wxICON_INFORMATION
|wxOK
, this);
1610 BEGIN_EVENT_TABLE(wxHtmlHelpFrame
, wxFrame
)
1611 EVT_ACTIVATE(wxHtmlHelpFrame::OnActivate
)
1612 EVT_TOOL_RANGE(wxID_HTML_PANEL
, wxID_HTML_OPTIONS
, wxHtmlHelpFrame::OnToolbar
)
1613 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE
, wxHtmlHelpFrame::OnToolbar
)
1614 EVT_BUTTON(wxID_HTML_BOOKMARKSADD
, wxHtmlHelpFrame::OnToolbar
)
1615 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL
, wxHtmlHelpFrame::OnContentsSel
)
1616 EVT_LISTBOX(wxID_HTML_INDEXLIST
, wxHtmlHelpFrame::OnIndexSel
)
1617 EVT_LISTBOX(wxID_HTML_SEARCHLIST
, wxHtmlHelpFrame::OnSearchSel
)
1618 EVT_BUTTON(wxID_HTML_SEARCHBUTTON
, wxHtmlHelpFrame::OnSearch
)
1619 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT
, wxHtmlHelpFrame::OnSearch
)
1620 EVT_BUTTON(wxID_HTML_INDEXBUTTON
, wxHtmlHelpFrame::OnIndexFind
)
1621 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT
, wxHtmlHelpFrame::OnIndexFind
)
1622 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL
, wxHtmlHelpFrame::OnIndexAll
)
1623 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST
, wxHtmlHelpFrame::OnBookmarksSel
)
1624 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow
)
1626 EVT_MENU(wxID_CLOSE
, wxHtmlHelpFrame::OnClose
)
1627 EVT_MENU(wxID_ABOUT
, wxHtmlHelpFrame::OnAbout
)
1632 #endif // wxUSE_WXHTML_HELP