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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx.h"
18 #include "wx/wxprec.h"
31 #include "wx/html/helpfrm.h"
32 #include "wx/notebook.h"
33 #include "wx/imaglist.h"
34 #include "wx/treectrl.h"
35 #include "wx/tokenzr.h"
36 #include "wx/wfstream.h"
37 #include "wx/html/htmlwin.h"
38 #include "wx/busyinfo.h"
39 #include "wx/progdlg.h"
40 #include "wx/toolbar.h"
41 #include "wx/fontenum.h"
46 #include "bitmaps/wpanel.xpm"
47 #include "bitmaps/wback.xpm"
48 #include "bitmaps/wforward.xpm"
49 #include "bitmaps/wbook.xpm"
50 #include "bitmaps/woptions.xpm"
51 #include "bitmaps/wfolder.xpm"
52 #include "bitmaps/wpage.xpm"
53 #include "bitmaps/whelp.xpm"
54 #include "bitmaps/whlproot.xpm"
55 #include "bitmaps/wbkadd.xpm"
56 #include "bitmaps/wbkdel.xpm"
59 #include "wx/stream.h"
61 // number of times that the contents/index creation progress dialog
63 #define PROGRESS_STEP 40
65 // what is considered "small index"?
66 #define INDEX_IS_SMALL 100
69 //--------------------------------------------------------------------------
70 // wxHtmlHelpTreeItemData (private)
71 //--------------------------------------------------------------------------
73 class wxHtmlHelpTreeItemData
: public wxTreeItemData
79 wxHtmlHelpTreeItemData(wxHtmlContentsItem
*it
) : wxTreeItemData()
81 m_Page
= it
-> m_Book
-> GetBasePath() + it
-> m_Page
;
83 const wxString
& GetPage() { return m_Page
; }
89 //---------------------------------------------------------------------------
91 //---------------------------------------------------------------------------
93 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame
, wxFrame
)
95 wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow
* parent
, wxWindowID id
, const wxString
& title
,
96 int style
, wxHtmlHelpData
* data
)
99 Create(parent
, id
, title
, style
);
102 void wxHtmlHelpFrame::Init(wxHtmlHelpData
* data
)
106 m_DataCreated
= FALSE
;
108 m_Data
= new wxHtmlHelpData();
109 m_DataCreated
= TRUE
;
112 m_ContentsImageList
= new wxImageList(16, 16);
113 m_ContentsImageList
-> Add(wxICON(wbook
));
114 m_ContentsImageList
-> Add(wxICON(wfolder
));
115 m_ContentsImageList
-> Add(wxICON(wpage
));
116 m_ContentsImageList
-> Add(wxICON(whlproot
));
118 m_ContentsBox
= NULL
;
120 m_IndexButton
= NULL
;
121 m_IndexButtonAll
= NULL
;
124 m_SearchButton
= NULL
;
126 m_SearchChoice
= NULL
;
127 m_IndexCountInfo
= NULL
;
132 m_SearchCaseSensitive
= NULL
;
133 m_SearchWholeWords
= NULL
;
136 m_ConfigRoot
= wxEmptyString
;
138 m_Cfg
.x
= m_Cfg
.y
= 0;
142 m_Cfg
.navig_on
= TRUE
;
144 m_NormalFonts
= m_FixedFonts
= NULL
;
146 m_NormalFace
= m_FixedFace
= wxEmptyString
;
149 // Create: builds the GUI components.
150 // with the style flag it's possible to toggle the toolbar, contents, index and search
152 // m_HtmlWin will *always* be created, but it's important to realize that
153 // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
154 // m_SearchButton may be NULL.
155 // moreover, if no contents, index or searchpage is needed, m_Splitter and
156 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
158 bool wxHtmlHelpFrame::Create(wxWindow
* parent
, wxWindowID id
, const wxString
& title
,
161 // Do the config in two steps. We read the HtmlWindow customization after we
162 // create the window.
164 ReadCustomization(m_Config
, m_ConfigRoot
);
166 wxFrame::Create(parent
, id
, _("Help"), wxPoint(m_Cfg
.x
, m_Cfg
.y
), wxSize(m_Cfg
.w
, m_Cfg
.h
), wxDEFAULT_FRAME_STYLE
, "wxHtmlHelp");
168 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
170 SetIcon(wxICON(whelp
));
172 int notebook_page
= 0;
177 if (style
& wxHF_TOOLBAR
) {
178 wxToolBar
*toolBar
= CreateToolBar(wxNO_BORDER
| wxTB_HORIZONTAL
| wxTB_DOCKABLE
);
179 toolBar
->SetMargins( 2, 2 );
180 AddToolbarButtons(toolBar
, style
);
181 toolBar
-> Realize();
184 if (style
& (wxHF_CONTENTS
| wxHF_INDEX
| wxHF_SEARCH
)) {
185 // traditional help controller; splitter window with html page on the
186 // right and a notebook containing various pages on the left
187 m_Splitter
= new wxSplitterWindow(this);
189 m_HtmlWin
= new wxHtmlWindow(m_Splitter
);
190 m_NavigPan
= new wxNotebook(m_Splitter
, wxID_HTML_NOTEBOOK
,
191 wxDefaultPosition
, wxDefaultSize
);
192 } else { // only html window, no notebook with index,contents etc
193 m_HtmlWin
= new wxHtmlWindow(this);
196 m_HtmlWin
-> SetRelatedFrame(this, m_TitleFormat
);
197 m_HtmlWin
-> SetRelatedStatusBar(0);
199 m_HtmlWin
-> ReadCustomization(m_Config
, m_ConfigRoot
);
201 // contents tree panel?
202 if (style
& wxHF_CONTENTS
) {
203 wxWindow
*dummy
= new wxPanel(m_NavigPan
, wxID_HTML_INDEXPAGE
);
205 if (style
& wxHF_BOOKMARKS
) {
206 wxLayoutConstraints
*b1
= new wxLayoutConstraints
;
207 wxBitmapButton
*bmpbt
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSREMOVE
, wxBITMAP(wbkdel
), wxDefaultPosition
, wxSize(20,20));
209 b1
-> top
.SameAs (dummy
, wxTop
, 10);
210 b1
-> right
.SameAs (dummy
, wxRight
, 10);
213 bmpbt
-> SetConstraints(b1
);
215 wxLayoutConstraints
*b2
= new wxLayoutConstraints
;
216 wxBitmapButton
*bmpbt2
= new wxBitmapButton(dummy
, wxID_HTML_BOOKMARKSADD
, wxBITMAP(wbkadd
), wxDefaultPosition
, wxSize(20,20));
218 b2
-> top
.SameAs (dummy
, wxTop
, 10);
219 b2
-> right
.LeftOf (bmpbt
, 2);
222 bmpbt2
-> SetConstraints(b2
);
225 bmpbt
-> SetToolTip(_("Remove current page from bookmarks"));
226 bmpbt2
-> SetToolTip(_("Add current page to bookmarks"));
227 #endif //wxUSE_TOOLTIPS
229 wxLayoutConstraints
*b3
= new wxLayoutConstraints
;
230 m_Bookmarks
= new wxComboBox(dummy
, wxID_HTML_BOOKMARKSLIST
, wxEmptyString
,
231 wxDefaultPosition
, wxDefaultSize
, 0, NULL
, wxCB_READONLY
| wxCB_SORT
);
232 m_Bookmarks
-> Append(_("(bookmarks)"));
233 for (unsigned i
= 0; i
< m_BookmarksNames
.GetCount(); i
++)
234 m_Bookmarks
-> Append(m_BookmarksNames
[i
]);
235 m_Bookmarks
-> SetSelection(0);
237 b3
-> centreY
.SameAs (bmpbt2
, wxCentreY
);
238 b3
-> left
.SameAs (dummy
, wxLeft
, 10);
239 b3
-> right
.LeftOf (bmpbt2
, 5);
241 m_Bookmarks
-> SetConstraints(b3
);
244 wxLayoutConstraints
*b4
= new wxLayoutConstraints
;
245 m_ContentsBox
= new wxTreeCtrl(dummy
, wxID_HTML_TREECTRL
,
246 wxDefaultPosition
, wxDefaultSize
,
247 wxTR_HAS_BUTTONS
| wxSUNKEN_BORDER
);
248 m_ContentsBox
-> SetImageList(m_ContentsImageList
);
250 b4
-> top
.Below (m_Bookmarks
, 10);
251 b4
-> left
.SameAs (dummy
, wxLeft
, 0);
252 b4
-> right
.SameAs (dummy
, wxRight
, 0);
253 b4
-> bottom
.SameAs (dummy
, wxBottom
, 0);
254 m_ContentsBox
-> SetConstraints(b4
);
256 dummy
-> SetAutoLayout(TRUE
);
259 m_NavigPan
-> AddPage(dummy
, _("Contents"));
264 m_ContentsBox
= new wxTreeCtrl(m_NavigPan
, wxID_HTML_TREECTRL
,
265 wxDefaultPosition
, wxDefaultSize
,
266 wxTR_HAS_BUTTONS
| wxSUNKEN_BORDER
);
267 m_ContentsBox
-> SetImageList(m_ContentsImageList
);
268 m_NavigPan
-> AddPage(m_ContentsBox
, _("Contents"));
271 m_ContentsPage
= notebook_page
++;
274 // index listbox panel?
275 if (style
& wxHF_INDEX
) {
276 wxWindow
*dummy
= new wxPanel(m_NavigPan
, wxID_HTML_INDEXPAGE
);
278 wxLayoutConstraints
*b1
= new wxLayoutConstraints
;
279 m_IndexText
= new wxTextCtrl(dummy
, wxID_HTML_INDEXTEXT
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxTE_PROCESS_ENTER
);
280 b1
-> top
.SameAs (dummy
, wxTop
, 10);
281 b1
-> left
.SameAs (dummy
, wxLeft
, 10);
282 b1
-> right
.SameAs (dummy
, wxRight
, 10);
284 m_IndexText
-> SetConstraints(b1
);
286 wxLayoutConstraints
*b4
= new wxLayoutConstraints
;
287 m_IndexButtonAll
= new wxButton(dummy
, wxID_HTML_INDEXBUTTONALL
, _("Show all"));
289 b4
-> top
.Below (m_IndexText
, 10);
290 b4
-> right
.SameAs (dummy
, wxRight
, 10);
293 m_IndexButtonAll
-> SetConstraints(b4
);
295 wxLayoutConstraints
*b2
= new wxLayoutConstraints
;
296 m_IndexButton
= new wxButton(dummy
, wxID_HTML_INDEXBUTTON
, _("Find"));
297 b2
-> top
.Below (m_IndexText
, 10);
298 b2
-> right
.LeftOf (m_IndexButtonAll
, 10);
301 m_IndexButton
-> SetConstraints(b2
);
303 wxLayoutConstraints
*b5
= new wxLayoutConstraints
;
304 m_IndexCountInfo
= new wxStaticText(dummy
, wxID_HTML_COUNTINFO
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxALIGN_RIGHT
| wxST_NO_AUTORESIZE
);
306 b5
-> top
.Below (m_IndexButton
, 5);
307 b5
-> right
.SameAs (dummy
, wxRight
, 10);
308 b5
-> left
.SameAs (dummy
, wxLeft
, 10);
310 m_IndexCountInfo
-> SetConstraints(b5
);
312 wxLayoutConstraints
*b3
= new wxLayoutConstraints
;
313 m_IndexList
= new wxListBox(dummy
, wxID_HTML_INDEXLIST
, wxDefaultPosition
, wxDefaultSize
, 0, NULL
, wxLB_SINGLE
| wxLB_ALWAYS_SB
);
314 b3
-> top
.Below (m_IndexCountInfo
, 5);
315 b3
-> left
.SameAs (dummy
, wxLeft
, 0);
316 b3
-> right
.SameAs (dummy
, wxRight
, 0);
317 b3
-> bottom
.SameAs (dummy
, wxBottom
, 0);
318 m_IndexList
-> SetConstraints(b3
);
321 m_IndexButtonAll
-> SetToolTip(_("Show all items in index"));
322 m_IndexButton
-> SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
323 #endif //wxUSE_TOOLTIPS
325 dummy
-> SetAutoLayout(TRUE
);
328 m_NavigPan
-> AddPage(dummy
, _("Index"));
329 m_IndexPage
= notebook_page
++;
332 // search list panel?
333 if (style
& wxHF_SEARCH
) {
334 wxWindow
*dummy
= new wxPanel(m_NavigPan
, wxID_HTML_SEARCHPAGE
);
336 wxLayoutConstraints
*b1
= new wxLayoutConstraints
;
337 m_SearchText
= new wxTextCtrl(dummy
, wxID_HTML_SEARCHTEXT
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
, wxTE_PROCESS_ENTER
);
338 b1
-> top
.SameAs (dummy
, wxTop
, 10);
339 b1
-> left
.SameAs (dummy
, wxLeft
, 10);
340 b1
-> right
.SameAs (dummy
, wxRight
, 10);
342 m_SearchText
-> SetConstraints(b1
);
344 wxLayoutConstraints
*b4
= new wxLayoutConstraints
;
345 m_SearchChoice
= new wxChoice(dummy
, wxID_HTML_SEARCHCHOICE
, wxDefaultPosition
,
347 b4
-> top
.Below (m_SearchText
, 10);
348 b4
-> left
.SameAs (dummy
, wxLeft
, 10);
349 b4
-> right
.SameAs (dummy
, wxRight
, 10);
351 m_SearchChoice
-> SetConstraints(b4
);
353 wxLayoutConstraints
*b5
= new wxLayoutConstraints
;
354 m_SearchCaseSensitive
= new wxCheckBox(dummy
, -1, _("Case sensitive"));
355 b5
-> top
.Below (m_SearchChoice
, 10);
356 b5
-> left
.SameAs (dummy
, wxLeft
, 10);
358 b5
-> height
.AsIs ();
359 m_SearchCaseSensitive
-> SetConstraints(b5
);
361 wxLayoutConstraints
*b6
= new wxLayoutConstraints
;
362 m_SearchWholeWords
= new wxCheckBox(dummy
, -1, _("Whole words only"));
363 b6
-> top
.Below (m_SearchCaseSensitive
, 0);
364 b6
-> left
.SameAs (dummy
, wxLeft
, 10);
366 b6
-> height
.AsIs ();
367 m_SearchWholeWords
-> SetConstraints(b6
);
369 wxLayoutConstraints
*b2
= new wxLayoutConstraints
;
370 m_SearchButton
= new wxButton(dummy
, wxID_HTML_SEARCHBUTTON
, _("Search"));
372 m_SearchButton
-> SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
373 #endif //wxUSE_TOOLTIPS
374 b2
-> top
.Below (m_SearchWholeWords
, 0);
375 b2
-> right
.SameAs (dummy
, wxRight
, 10);
378 m_SearchButton
-> SetConstraints(b2
);
380 wxLayoutConstraints
*b3
= new wxLayoutConstraints
;
381 m_SearchList
= new wxListBox(dummy
, wxID_HTML_SEARCHLIST
, wxDefaultPosition
, wxDefaultSize
, 0, NULL
, wxLB_SINGLE
| wxLB_ALWAYS_SB
);
382 b3
-> top
.Below (m_SearchButton
, 10);
383 b3
-> left
.SameAs (dummy
, wxLeft
, 0);
384 b3
-> right
.SameAs (dummy
, wxRight
, 0);
385 b3
-> bottom
.SameAs (dummy
, wxBottom
, 0);
386 m_SearchList
-> SetConstraints(b3
);
388 dummy
-> SetAutoLayout(TRUE
);
390 m_NavigPan
-> AddPage(dummy
, _("Search"));
391 m_SearchPage
= notebook_page
++;
393 m_HtmlWin
-> Show(TRUE
);
398 if (m_NavigPan
&& m_Splitter
) {
399 m_Splitter
-> SetMinimumPaneSize(20);
401 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
403 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
404 m_Splitter
-> Unsplit();
406 if (m_Cfg
.navig_on
) {
407 m_NavigPan
-> Show(TRUE
);
408 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
411 m_NavigPan
-> Show(FALSE
);
412 m_Splitter
-> Initialize(m_HtmlWin
);
418 wxHtmlHelpFrame::~wxHtmlHelpFrame()
420 PopEventHandler(); // wxhtmlhelpcontroller
421 delete m_ContentsImageList
;
424 if (m_NormalFonts
) delete m_NormalFonts
;
425 if (m_FixedFonts
) delete m_FixedFonts
;
429 void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar
*toolBar
, int style
)
431 toolBar
-> AddTool(wxID_HTML_PANEL
, wxBITMAP(wpanel
), wxNullBitmap
,
432 FALSE
, -1, -1, (wxObject
*) NULL
,
433 _("Show/hide navigation panel"));
434 toolBar
-> AddSeparator();
435 toolBar
-> AddTool(wxID_HTML_BACK
, wxBITMAP(wback
), wxNullBitmap
,
436 FALSE
, -1, -1, (wxObject
*) NULL
,
437 _("Go back to the previous HTML page"));
438 toolBar
-> AddTool(wxID_HTML_FORWARD
, wxBITMAP(wforward
), wxNullBitmap
,
439 FALSE
, -1, -1, (wxObject
*) NULL
,
440 _("Go forward to the next HTML page"));
441 toolBar
-> AddSeparator();
443 toolBar
-> AddSeparator();
444 toolBar
-> AddTool(wxID_HTML_OPTIONS
, wxBITMAP(woptions
), wxNullBitmap
,
445 FALSE
, -1, -1, (wxObject
*) NULL
,
446 _("Display options dialog"));
451 bool wxHtmlHelpFrame::Display(const wxString
& x
)
453 wxString url
= m_Data
->FindPageByName(x
);
454 if (! url
.IsEmpty()) {
455 m_HtmlWin
->LoadPage(url
);
461 bool wxHtmlHelpFrame::Display(const int id
)
463 wxString url
= m_Data
->FindPageById(id
);
464 if (! url
.IsEmpty()) {
465 m_HtmlWin
->LoadPage(url
);
473 bool wxHtmlHelpFrame::DisplayContents()
477 if (!m_Splitter
-> IsSplit()) {
478 m_NavigPan
-> Show(TRUE
);
479 m_HtmlWin
-> Show(TRUE
);
480 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
481 m_Cfg
.navig_on
= TRUE
;
483 m_NavigPan
-> SetSelection(0);
489 bool wxHtmlHelpFrame::DisplayIndex()
493 if (!m_Splitter
-> IsSplit()) {
494 m_NavigPan
-> Show(TRUE
);
495 m_HtmlWin
-> Show(TRUE
);
496 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
498 m_NavigPan
-> SetSelection(1);
504 bool wxHtmlHelpFrame::KeywordSearch(const wxString
& keyword
)
506 if (! (m_SearchList
&& m_SearchButton
&& m_SearchText
&& m_SearchChoice
))
509 int foundcnt
= 0, curi
;
511 wxString book
= wxEmptyString
;
513 if (!m_Splitter
-> IsSplit()) {
514 m_NavigPan
-> Show(TRUE
);
515 m_HtmlWin
-> Show(TRUE
);
516 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
518 m_NavigPan
-> SetSelection(m_SearchPage
);
519 m_SearchList
-> Clear();
520 m_SearchText
-> SetValue(keyword
);
521 m_SearchButton
-> Enable(FALSE
);
523 if (m_SearchChoice
->GetSelection() != 0)
524 book
= m_SearchChoice
->GetStringSelection();
526 wxHtmlSearchStatus
status(m_Data
, keyword
,
527 m_SearchCaseSensitive
-> GetValue(), m_SearchWholeWords
-> GetValue(),
530 wxProgressDialog
progress(_("Searching..."), _("No matching page found yet"),
531 status
.GetMaxIndex(), this,
532 wxPD_APP_MODAL
| wxPD_CAN_ABORT
| wxPD_AUTO_HIDE
| wxGA_SMOOTH
);
534 while (status
.IsActive()) {
535 curi
= status
.GetCurIndex();
536 if (curi
% 32 == 0 && progress
.Update(curi
) == FALSE
)
538 if (status
.Search()) {
539 foundstr
.Printf(_("Found %i matches"), ++foundcnt
);
540 progress
.Update(status
.GetCurIndex(), foundstr
);
541 m_SearchList
-> Append(status
.GetName(), status
.GetContentsItem());
545 m_SearchButton
-> Enable(TRUE
);
546 m_SearchText
-> SetSelection(0, keyword
.Length());
547 m_SearchText
-> SetFocus();
549 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_SearchList
-> GetClientData(0);
550 if (it
) m_HtmlWin
-> LoadPage(it
-> m_Book
-> GetBasePath() + it
-> m_Page
);
552 return (foundcnt
> 0);
557 void wxHtmlHelpFrame::CreateContents()
562 m_ContentsBox
->Clear();
564 int cnt
= m_Data
->GetContentsCnt();
567 wxHtmlContentsItem
*it
;
569 wxTreeItemId roots
[MAX_ROOTS
];
570 bool imaged
[MAX_ROOTS
];
572 m_ContentsBox
-> DeleteAllItems();
573 roots
[0] = m_ContentsBox
-> AddRoot(_("(Help)"));
574 m_ContentsBox
-> SetItemImage(roots
[0], IMG_RootFolder
);
575 m_ContentsBox
-> SetItemSelectedImage(roots
[0], IMG_RootFolder
);
578 for (it
= m_Data
->GetContents(), i
= 0; i
< cnt
; i
++, it
++) {
579 roots
[it
-> m_Level
+ 1] = m_ContentsBox
-> AppendItem(
580 roots
[it
-> m_Level
], it
-> m_Name
, IMG_Page
, -1,
581 new wxHtmlHelpTreeItemData(it
));
583 if (it
-> m_Level
== 0) {
584 m_ContentsBox
-> SetItemBold(roots
[1], TRUE
);
585 m_ContentsBox
-> SetItemImage(roots
[1], IMG_Book
);
586 m_ContentsBox
-> SetItemSelectedImage(roots
[1], IMG_Book
);
588 } else imaged
[it
-> m_Level
+ 1] = FALSE
;
590 if (!imaged
[it
-> m_Level
]) {
591 m_ContentsBox
-> SetItemImage(roots
[it
-> m_Level
], IMG_Folder
);
592 m_ContentsBox
-> SetItemSelectedImage(roots
[it
-> m_Level
], IMG_Folder
);
593 imaged
[it
-> m_Level
] = TRUE
;
596 m_ContentsBox
-> Expand(roots
[0]);
600 void wxHtmlHelpFrame::CreateIndex()
605 m_IndexList
->Clear();
607 int cnt
= m_Data
->GetIndexCnt();
610 if (cnt
> INDEX_IS_SMALL
) cnttext
.Printf(_("%i of %i"), 0, cnt
);
611 else cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
612 m_IndexCountInfo
-> SetLabel(cnttext
);
613 if (cnt
> INDEX_IS_SMALL
) return;
615 wxHtmlContentsItem
* index
= m_Data
->GetIndex();
617 for (int i
= 0; i
< cnt
; i
++)
618 m_IndexList
-> Append(index
[i
].m_Name
, (char*)(index
+ i
));
621 void wxHtmlHelpFrame::CreateSearch()
623 if (! (m_SearchList
&& m_SearchChoice
))
625 m_SearchList
-> Clear();
626 m_SearchChoice
-> Clear();
627 m_SearchChoice
-> Append(_("Search in all books"));
628 const wxHtmlBookRecArray
& bookrec
= m_Data
->GetBookRecArray();
629 int i
, cnt
= bookrec
.GetCount();
630 for (i
= 0; i
< cnt
; i
++)
631 m_SearchChoice
->Append(bookrec
[i
].GetTitle());
632 m_SearchChoice
->SetSelection(0);
636 void wxHtmlHelpFrame::RefreshLists()
643 void wxHtmlHelpFrame::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
648 if (path
!= wxEmptyString
) {
649 oldpath
= cfg
-> GetPath();
650 cfg
-> SetPath(_T("/") + path
);
653 m_Cfg
.navig_on
= cfg
-> Read("hcNavigPanel", m_Cfg
.navig_on
) != 0;
654 m_Cfg
.sashpos
= cfg
-> Read("hcSashPos", m_Cfg
.sashpos
);
655 m_Cfg
.x
= cfg
-> Read("hcX", m_Cfg
.x
);
656 m_Cfg
.y
= cfg
-> Read("hcY", m_Cfg
.y
);
657 m_Cfg
.w
= cfg
-> Read("hcW", m_Cfg
.w
);
658 m_Cfg
.h
= cfg
-> Read("hcH", m_Cfg
.h
);
660 m_FixedFace
= cfg
-> Read("hcFixedFace", m_FixedFace
);
661 m_NormalFace
= cfg
-> Read("hcNormalFace", m_NormalFace
);
662 m_FontSize
= cfg
-> Read("hcFontSize", m_FontSize
);
669 cnt
= cfg
-> Read("hcBookmarksCnt", 0L);
671 m_BookmarksNames
.Clear();
672 m_BookmarksPages
.Clear();
674 m_Bookmarks
-> Clear();
675 m_Bookmarks
-> Append(_("(bookmarks)"));
678 for (i
= 0; i
< cnt
; i
++) {
679 val
.Printf(wxT("hcBookmark_%i"), i
);
680 s
= cfg
-> Read(val
);
681 m_BookmarksNames
.Add(s
);
682 if (m_Bookmarks
) m_Bookmarks
-> Append(s
);
683 val
.Printf(wxT("hcBookmark_%i_url"), i
);
684 s
= cfg
-> Read(val
);
685 m_BookmarksPages
.Add(s
);
691 m_HtmlWin
->ReadCustomization(cfg
);
693 if (path
!= wxEmptyString
)
694 cfg
-> SetPath(oldpath
);
697 void wxHtmlHelpFrame::WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
)
702 if (path
!= wxEmptyString
) {
703 oldpath
= cfg
-> GetPath();
704 cfg
-> SetPath(_T("/") + path
);
707 cfg
-> Write("hcNavigPanel", m_Cfg
.navig_on
);
708 cfg
-> Write("hcSashPos", (long)m_Cfg
.sashpos
);
709 cfg
-> Write("hcX", (long)m_Cfg
.x
);
710 cfg
-> Write("hcY", (long)m_Cfg
.y
);
711 cfg
-> Write("hcW", (long)m_Cfg
.w
);
712 cfg
-> Write("hcH", (long)m_Cfg
.h
);
713 cfg
-> Write("hcFixedFace", m_FixedFace
);
714 cfg
-> Write("hcNormalFace", m_NormalFace
);
715 cfg
-> Write("hcFontSize", (long)m_FontSize
);
719 int cnt
= m_BookmarksNames
.GetCount();
722 cfg
-> Write("hcBookmarksCnt", (long)cnt
);
723 for (i
= 0; i
< cnt
; i
++) {
724 val
.Printf(wxT("hcBookmark_%i"), i
);
725 cfg
-> Write(val
, m_BookmarksNames
[i
]);
726 val
.Printf(wxT("hcBookmark_%i_url"), i
);
727 cfg
-> Write(val
, m_BookmarksPages
[i
]);
732 m_HtmlWin
->WriteCustomization(cfg
);
734 if (path
!= wxEmptyString
)
735 cfg
-> SetPath(oldpath
);
742 static void SetFontsToHtmlWin(wxHtmlWindow
*win
, wxString scalf
, wxString fixf
, int size
)
744 static int f_sizes
[3][7] =
746 { 8, 9, 12, 14, 16, 19, 22},
747 {10, 12, 14, 16, 19, 24, 32},
748 {14, 16, 18, 24, 32, 38, 45}
751 win
-> SetFonts(scalf
, fixf
, f_sizes
[size
]);
755 class wxHtmlHelpFrameOptionsDialog
: public wxDialog
758 wxComboBox
*NormalFont
, *FixedFont
;
759 wxRadioBox
*RadioBox
;
760 wxHtmlWindow
*TestWin
;
762 wxHtmlHelpFrameOptionsDialog(wxWindow
*parent
) : wxDialog(parent
, -1, wxString(_("Help Browser Options")))
764 wxString choices
[3] = {_("small"), _("medium"), _("large")};
765 wxBoxSizer
*topsizer
, *sizer
, *sizer2
;
767 topsizer
= new wxBoxSizer(wxVERTICAL
);
769 sizer
= new wxBoxSizer(wxHORIZONTAL
);
771 sizer2
= new wxStaticBoxSizer( new wxStaticBox(this, -1, _("Normal font:")), wxVERTICAL
);
772 sizer2
-> Add(NormalFont
= new wxComboBox(this, -1, wxEmptyString
, wxDefaultPosition
,
774 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
),
775 1, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
777 sizer
-> Add(sizer2
, 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10);
779 sizer2
= new wxStaticBoxSizer( new wxStaticBox(this, -1, _("Fixed font:")), wxVERTICAL
);
780 sizer2
-> Add(FixedFont
= new wxComboBox(this, -1, wxEmptyString
, wxDefaultPosition
,
782 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
),
783 1, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
785 sizer
-> Add(sizer2
, 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10);
787 topsizer
-> Add(sizer
);
789 topsizer
-> Add(RadioBox
= new wxRadioBox(this, -1, _("Font size:"),
790 wxDefaultPosition
, wxDefaultSize
, 3, choices
, 3),
791 0, wxEXPAND
| wxLEFT
|wxRIGHT
|wxTOP
, 10);
793 topsizer
-> Add(new wxStaticText(this, -1, _("Preview:")),
794 0, wxLEFT
| wxTOP
, 10);
795 topsizer
-> Add(TestWin
= new wxHtmlWindow(this, -1, wxDefaultPosition
, wxSize(-1, 150)),
796 1, wxEXPAND
| wxLEFT
|wxTOP
|wxRIGHT
, 10);
798 sizer
= new wxBoxSizer(wxHORIZONTAL
);
799 sizer
-> Add(new wxButton(this, wxID_OK
, _("OK")), 0, wxALL
, 10);
800 sizer
-> Add(new wxButton(this, wxID_CANCEL
, _("Cancel")), 0, wxALL
, 10);
801 topsizer
-> Add(sizer
, 0, wxALIGN_RIGHT
);
805 topsizer
-> Fit(this);
813 SetFontsToHtmlWin(TestWin
,
814 NormalFont
-> GetStringSelection(),
815 FixedFont
-> GetStringSelection(),
816 RadioBox
-> GetSelection());
817 TestWin
-> SetPage(_("<html><body>"
818 "Normal face<br>(and <u>underlined</u>. <i>Italic face.</i> "
819 "<b>Bold face.</b> <b><i>Bold italic face.</i></b><br>"
820 "<font size=-2>font size -2</font><br>"
821 "<font size=-1>font size -1</font><br>"
822 "<font size=+0>font size +0</font><br>"
823 "<font size=+1>font size +1</font><br>"
824 "<font size=+2>font size +2</font><br>"
825 "<font size=+3>font size +3</font><br>"
826 "<font size=+4>font size +4</font><br>"
828 "<p><tt>Fixed size face.<br> <b>bold</b> <i>italic</i> "
829 "<b><i>bold italic <u>underlined</u></i></b><br>"
830 "<font size=-2>font size -2</font><br>"
831 "<font size=-1>font size -1</font><br>"
832 "<font size=+0>font size +0</font><br>"
833 "<font size=+1>font size +1</font><br>"
834 "<font size=+2>font size +2</font><br>"
835 "<font size=+3>font size +3</font><br>"
836 "<font size=+4>font size +4</font></tt>"
840 void OnUpdate(wxCloseEvent
& event
)
845 DECLARE_EVENT_TABLE()
848 BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog
, wxDialog
)
849 EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate
)
850 EVT_RADIOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate
)
854 void wxHtmlHelpFrame::OptionsDialog()
856 wxHtmlHelpFrameOptionsDialog
dlg(this);
859 if (m_NormalFonts
== NULL
) {
860 wxFontEnumerator enu
;
861 enu
.EnumerateFacenames();
862 m_NormalFonts
= new wxArrayString
;
863 *m_NormalFonts
= *enu
.GetFacenames();
864 m_NormalFonts
-> Sort();
866 if (m_FixedFonts
== NULL
) {
867 wxFontEnumerator enu
;
868 enu
.EnumerateFacenames(wxFONTENCODING_SYSTEM
, TRUE
);
869 m_FixedFonts
= new wxArrayString
;
870 *m_FixedFonts
= *enu
.GetFacenames();
871 m_FixedFonts
-> Sort();
874 for (i
= 0; i
< m_NormalFonts
-> GetCount(); i
++)
875 dlg
.NormalFont
-> Append((*m_NormalFonts
)[i
]);
876 for (i
= 0; i
< m_FixedFonts
-> GetCount(); i
++)
877 dlg
.FixedFont
-> Append((*m_FixedFonts
)[i
]);
878 if (!m_NormalFace
.IsEmpty()) dlg
.NormalFont
-> SetStringSelection(m_NormalFace
);
879 else dlg
.NormalFont
-> SetSelection(0);
880 if (!m_FixedFace
.IsEmpty()) dlg
.FixedFont
-> SetStringSelection(m_FixedFace
);
881 else dlg
.FixedFont
-> SetSelection(0);
882 dlg
.RadioBox
-> SetSelection(m_FontSize
);
885 if (dlg
.ShowModal() == wxID_OK
) {
886 m_NormalFace
= dlg
.NormalFont
-> GetStringSelection();
887 m_FixedFace
= dlg
.FixedFont
-> GetStringSelection();
888 m_FontSize
= dlg
.RadioBox
-> GetSelection();
889 SetFontsToHtmlWin(m_HtmlWin
, m_NormalFace
, m_FixedFace
, m_FontSize
);
902 void wxHtmlHelpFrame::OnToolbar(wxCommandEvent
& event
)
904 switch (event
.GetId()) {
906 case wxID_HTML_BACK
:
907 m_HtmlWin
-> HistoryBack();
910 case wxID_HTML_FORWARD
:
911 m_HtmlWin
-> HistoryForward();
914 case wxID_HTML_PANEL
:
915 if (! (m_Splitter
&& m_NavigPan
))
917 if (m_Splitter
-> IsSplit()) {
918 m_Cfg
.sashpos
= m_Splitter
-> GetSashPosition();
919 m_Splitter
-> Unsplit(m_NavigPan
);
920 m_Cfg
.navig_on
= FALSE
;
922 m_NavigPan
-> Show(TRUE
);
923 m_HtmlWin
-> Show(TRUE
);
924 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
925 m_Cfg
.navig_on
= TRUE
;
929 case wxID_HTML_OPTIONS
:
933 case wxID_HTML_BOOKMARKSADD
:
938 item
= m_HtmlWin
-> GetOpenedPageTitle();
939 url
= m_HtmlWin
-> GetOpenedPage();
940 if (item
== wxEmptyString
) item
= url
.AfterLast(wxT('/'));
941 if (m_BookmarksPages
.Index(url
) == wxNOT_FOUND
) {
942 m_Bookmarks
-> Append(item
);
943 m_BookmarksNames
.Add(item
);
944 m_BookmarksPages
.Add(url
);
949 case wxID_HTML_BOOKMARKSREMOVE
:
954 item
= m_Bookmarks
-> GetStringSelection();
955 pos
= m_BookmarksNames
.Index(item
);
956 if (pos
!= wxNOT_FOUND
) {
957 m_BookmarksNames
.Remove(pos
);
958 m_BookmarksPages
.Remove(pos
);
959 m_Bookmarks
-> Delete(m_Bookmarks
-> GetSelection());
968 void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent
& event
)
970 wxHtmlHelpTreeItemData
*pg
;
972 pg
= (wxHtmlHelpTreeItemData
*) m_ContentsBox
-> GetItemData(event
.GetItem());
973 if (pg
) m_HtmlWin
-> LoadPage(pg
-> GetPage());
978 void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent
& WXUNUSED(event
))
980 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_IndexList
-> GetClientData(m_IndexList
-> GetSelection());
981 m_HtmlWin
-> LoadPage(it
-> m_Book
-> GetBasePath() + it
-> m_Page
);
985 void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent
& event
)
987 wxString sr
= m_IndexText
-> GetLineText(0);
989 if (sr
== wxEmptyString
)
994 const wxChar
*cstr
= sr
.c_str();
995 wxChar mybuff
[512], *ptr
;
998 m_IndexList
->Clear();
999 int cnt
= m_Data
->GetIndexCnt();
1000 wxHtmlContentsItem
* index
= m_Data
->GetIndex();
1003 for (int i
= 0; i
< cnt
; i
++)
1005 wxStrncpy(mybuff
, index
[i
].m_Name
, 512);
1007 for (ptr
= mybuff
; *ptr
!= 0; ptr
++)
1008 if (*ptr
>= 'A' && *ptr
<= 'Z') *ptr
-= 'A' - 'a';
1009 if (wxStrstr(mybuff
, cstr
) != NULL
) {
1010 m_IndexList
-> Append(index
[i
].m_Name
, (char*)(index
+ i
));
1013 m_HtmlWin
-> LoadPage(index
[i
].m_Book
-> GetBasePath() + index
[i
].m_Page
);
1020 cnttext
.Printf(_("%i of %i"), displ
, cnt
);
1021 m_IndexCountInfo
-> SetLabel(cnttext
);
1023 m_IndexText
-> SetSelection(0, sr
.Length());
1024 m_IndexText
-> SetFocus();
1028 void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent
& WXUNUSED(event
))
1032 m_IndexList
->Clear();
1033 int cnt
= m_Data
->GetIndexCnt();
1035 wxHtmlContentsItem
* index
= m_Data
->GetIndex();
1037 for (int i
= 0; i
< cnt
; i
++) {
1038 m_IndexList
-> Append(index
[i
].m_Name
, (char*)(index
+ i
));
1040 m_HtmlWin
-> LoadPage(index
[i
].m_Book
-> GetBasePath() + index
[i
].m_Page
);
1046 cnttext
.Printf(_("%i of %i"), cnt
, cnt
);
1047 m_IndexCountInfo
-> SetLabel(cnttext
);
1051 void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent
& WXUNUSED(event
))
1053 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_SearchList
-> GetClientData(m_SearchList
-> GetSelection());
1054 if (it
) m_HtmlWin
-> LoadPage(it
-> m_Book
-> GetBasePath() + it
-> m_Page
);
1057 void wxHtmlHelpFrame::OnSearch(wxCommandEvent
& WXUNUSED(event
))
1059 wxString sr
= m_SearchText
-> GetLineText(0);
1061 if (sr
!= wxEmptyString
) KeywordSearch(sr
);
1064 void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent
& WXUNUSED(event
))
1066 wxString sr
= m_Bookmarks
-> GetStringSelection();
1068 if (sr
!= wxEmptyString
&& sr
!= _("(bookmarks)"))
1069 m_HtmlWin
-> LoadPage(m_BookmarksPages
[m_BookmarksNames
.Index(sr
)]);
1072 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent
& evt
)
1074 GetSize(&m_Cfg
.w
, &m_Cfg
.h
);
1075 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
1077 if (m_Splitter
&& m_Cfg
.navig_on
) m_Cfg
.sashpos
= m_Splitter
-> GetSashPosition();
1080 WriteCustomization(m_Config
, m_ConfigRoot
);
1085 BEGIN_EVENT_TABLE(wxHtmlHelpFrame
, wxFrame
)
1086 EVT_TOOL_RANGE(wxID_HTML_PANEL
, wxID_HTML_OPTIONS
, wxHtmlHelpFrame::OnToolbar
)
1087 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE
, wxHtmlHelpFrame::OnToolbar
)
1088 EVT_BUTTON(wxID_HTML_BOOKMARKSADD
, wxHtmlHelpFrame::OnToolbar
)
1089 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL
, wxHtmlHelpFrame::OnContentsSel
)
1090 EVT_LISTBOX(wxID_HTML_INDEXLIST
, wxHtmlHelpFrame::OnIndexSel
)
1091 EVT_LISTBOX(wxID_HTML_SEARCHLIST
, wxHtmlHelpFrame::OnSearchSel
)
1092 EVT_BUTTON(wxID_HTML_SEARCHBUTTON
, wxHtmlHelpFrame::OnSearch
)
1093 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT
, wxHtmlHelpFrame::OnSearch
)
1094 EVT_BUTTON(wxID_HTML_INDEXBUTTON
, wxHtmlHelpFrame::OnIndexFind
)
1095 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT
, wxHtmlHelpFrame::OnIndexFind
)
1096 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL
, wxHtmlHelpFrame::OnIndexAll
)
1097 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST
, wxHtmlHelpFrame::OnBookmarksSel
)
1098 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow
)