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 //--------------------------------------------------------------------------
66 // wxHtmlHelpTreeItemData (private)
67 //--------------------------------------------------------------------------
69 class wxHtmlHelpTreeItemData
: public wxTreeItemData
75 wxHtmlHelpTreeItemData(wxHtmlContentsItem
*it
) : wxTreeItemData()
77 m_Page
= it
-> m_Book
-> GetBasePath() + it
-> m_Page
;
79 const wxString
& GetPage() { return m_Page
; }
85 //---------------------------------------------------------------------------
87 //---------------------------------------------------------------------------
89 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame
, wxFrame
)
91 wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow
* parent
, wxWindowID id
, const wxString
& title
,
92 int style
, wxHtmlHelpData
* data
)
95 Create(parent
, id
, title
, style
);
98 void wxHtmlHelpFrame::Init(wxHtmlHelpData
* data
)
102 m_DataCreated
= FALSE
;
104 m_Data
= new wxHtmlHelpData();
105 m_DataCreated
= TRUE
;
108 m_ContentsImageList
= new wxImageList(16, 16);
109 m_ContentsImageList
-> Add(wxICON(wbook
));
110 m_ContentsImageList
-> Add(wxICON(wfolder
));
111 m_ContentsImageList
-> Add(wxICON(wpage
));
112 m_ContentsImageList
-> Add(wxICON(whlproot
));
114 m_ContentsBox
= NULL
;
117 m_SearchButton
= NULL
;
119 m_SearchChoice
= NULL
;
125 m_ConfigRoot
= wxEmptyString
;
127 m_Cfg
.x
= m_Cfg
.y
= 0;
131 m_Cfg
.navig_on
= TRUE
;
133 m_NormalFonts
= m_FixedFonts
= NULL
;
135 m_NormalFace
= m_FixedFace
= wxEmptyString
;
136 m_NormalItalic
= m_FixedItalic
= wxSLANT
;
139 // Create: builds the GUI components.
140 // with the style flag it's possible to toggle the toolbar, contents, index and search
142 // m_HtmlWin will *always* be created, but it's important to realize that
143 // m_ContentsBox, m_IndexBox, m_SearchList, m_SearchButton, m_SearchText and
144 // m_SearchButton may be NULL.
145 // moreover, if no contents, index or searchpage is needed, m_Splitter and
146 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
148 bool wxHtmlHelpFrame::Create(wxWindow
* parent
, wxWindowID id
, const wxString
& title
,
151 // Do the config in two steps. We read the HtmlWindow customization after we
152 // create the window.
154 ReadCustomization(m_Config
, m_ConfigRoot
);
156 wxFrame::Create(parent
, id
, _("Help"), wxPoint(m_Cfg
.x
, m_Cfg
.y
), wxSize(m_Cfg
.w
, m_Cfg
.h
));
158 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
160 SetIcon(wxICON(whelp
));
162 int notebook_page
= 0;
167 if (style
& wxHF_TOOLBAR
) {
168 wxToolBar
*toolBar
= CreateToolBar(wxNO_BORDER
| wxTB_HORIZONTAL
| wxTB_DOCKABLE
);
169 toolBar
->SetMargins( 2, 2 );
171 toolBar
-> AddTool(wxID_HTML_PANEL
, wxBITMAP(wpanel
), wxNullBitmap
,
172 FALSE
, -1, -1, (wxObject
*) NULL
,
173 _("Show/hide navigation panel"));
174 toolBar
-> AddSeparator();
175 toolBar
-> AddTool(wxID_HTML_BACK
, wxBITMAP(wback
), wxNullBitmap
,
176 FALSE
, -1, -1, (wxObject
*) NULL
,
177 _("Go back to the previous HTML page"));
178 toolBar
-> AddTool(wxID_HTML_FORWARD
, wxBITMAP(wforward
), wxNullBitmap
,
179 FALSE
, -1, -1, (wxObject
*) NULL
,
180 _("Go forward to the next HTML page"));
181 toolBar
-> AddSeparator();
183 if (style
& wxHF_BOOKMARKS
) {
184 m_Bookmarks
= new wxComboBox(toolBar
, wxID_HTML_BOOKMARKSLIST
, wxEmptyString
,
185 wxDefaultPosition
, wxSize(300,-1), 0, NULL
, wxCB_READONLY
| wxCB_SORT
);
186 m_Bookmarks
-> Append(_("<bookmarks>"));
187 for (unsigned i
= 0; i
< m_BookmarksNames
.GetCount(); i
++)
188 m_Bookmarks
-> Append(m_BookmarksNames
[i
]);
189 m_Bookmarks
-> SetSelection(0);
190 toolBar
-> AddControl(m_Bookmarks
);
192 toolBar
-> AddSeparator();
194 toolBar
-> AddTool(wxID_HTML_BOOKMARKSADD
, wxBITMAP(wbkadd
), wxNullBitmap
,
195 FALSE
, -1, -1, (wxObject
*) NULL
,
196 _("Add current page to bookmarks"));
197 toolBar
-> AddTool(wxID_HTML_BOOKMARKSREMOVE
, wxBITMAP(wbkdel
), wxNullBitmap
,
198 FALSE
, -1, -1, (wxObject
*) NULL
,
199 _("Remove current page from bookmarks"));
202 toolBar
-> AddSeparator();
203 toolBar
-> AddTool(wxID_HTML_OPTIONS
, wxBITMAP(woptions
), wxNullBitmap
,
204 FALSE
, -1, -1, (wxObject
*) NULL
,
205 _("Display options dialog"));
207 toolBar
-> Realize();
210 if (style
& (wxHF_CONTENTS
| wxHF_INDEX
| wxHF_SEARCH
)) {
211 // traditional help controller; splitter window with html page on the
212 // right and a notebook containing various pages on the left
213 m_Splitter
= new wxSplitterWindow(this);
215 m_HtmlWin
= new wxHtmlWindow(m_Splitter
);
216 m_NavigPan
= new wxNotebook(m_Splitter
, wxID_HTML_NOTEBOOK
,
217 wxDefaultPosition
, wxDefaultSize
);
218 } else { // only html window, no notebook with index,contents etc
219 m_HtmlWin
= new wxHtmlWindow(this);
222 m_HtmlWin
-> SetRelatedFrame(this, m_TitleFormat
);
223 m_HtmlWin
-> SetRelatedStatusBar(0);
225 m_HtmlWin
-> ReadCustomization(m_Config
, m_ConfigRoot
);
227 // contents tree panel?
228 if (style
& wxHF_CONTENTS
) {
229 m_ContentsBox
= new wxTreeCtrl(m_NavigPan
, wxID_HTML_TREECTRL
,
230 wxDefaultPosition
, wxDefaultSize
,
231 wxTR_HAS_BUTTONS
| wxSUNKEN_BORDER
);
232 m_ContentsBox
-> SetImageList(m_ContentsImageList
);
233 m_NavigPan
-> AddPage(m_ContentsBox
, _("Contents"));
234 m_ContentsPage
= notebook_page
++;
237 // index listbox panel?
238 if (style
& wxHF_INDEX
) {
239 wxWindow
*dummy
= new wxPanel(m_NavigPan
, wxID_HTML_INDEXPAGE
);
240 wxLayoutConstraints
*b1
= new wxLayoutConstraints
;
241 b1
-> top
.SameAs (dummy
, wxTop
, 0);
242 b1
-> left
.SameAs (dummy
, wxLeft
, 0);
243 b1
-> width
.PercentOf (dummy
, wxWidth
, 100);
244 b1
-> bottom
.SameAs (dummy
, wxBottom
, 0);
245 m_IndexBox
= new wxListBox(dummy
, wxID_HTML_INDEXLIST
, wxDefaultPosition
,
246 wxDefaultSize
, 0, NULL
, wxLB_SINGLE
| wxLB_ALWAYS_SB
);
247 m_IndexBox
-> SetConstraints(b1
);
248 dummy
-> SetAutoLayout(TRUE
);
249 m_NavigPan
-> AddPage(dummy
, _("Index"));
250 m_IndexPage
= notebook_page
++;
253 // search list panel?
254 if (style
& wxHF_SEARCH
) {
255 wxWindow
*dummy
= new wxPanel(m_NavigPan
, wxID_HTML_SEARCHPAGE
);
257 wxLayoutConstraints
*b1
= new wxLayoutConstraints
;
258 m_SearchText
= new wxTextCtrl(dummy
, wxID_HTML_SEARCHTEXT
);
259 b1
-> top
.SameAs (dummy
, wxTop
, 10);
260 b1
-> left
.SameAs (dummy
, wxLeft
, 10);
261 b1
-> right
.SameAs (dummy
, wxRight
, 10);
263 m_SearchText
-> SetConstraints(b1
);
265 wxLayoutConstraints
*b2
= new wxLayoutConstraints
;
266 m_SearchButton
= new wxButton(dummy
, wxID_HTML_SEARCHBUTTON
, _("Search"));
267 b2
-> top
.Below (m_SearchText
, 10);
268 b2
-> left
.SameAs (dummy
, wxLeft
, 10);
271 m_SearchButton
-> SetConstraints(b2
);
273 wxLayoutConstraints
*b4
= new wxLayoutConstraints
;
274 m_SearchChoice
= new wxChoice(dummy
, wxID_HTML_SEARCHCHOICE
, wxDefaultPosition
,
276 b4
-> top
.Below (m_SearchText
, 10);
277 b4
-> left
.SameAs (m_SearchButton
, wxRight
, 10);
278 b4
-> right
.SameAs (dummy
, wxRight
, 10);
280 m_SearchChoice
-> SetConstraints(b4
);
282 wxLayoutConstraints
*b3
= new wxLayoutConstraints
;
283 m_SearchList
= new wxListBox(dummy
, wxID_HTML_SEARCHLIST
, wxDefaultPosition
, wxDefaultSize
, 0);
284 b3
-> top
.Below (m_SearchButton
, 10);
285 b3
-> left
.SameAs (dummy
, wxLeft
, 0);
286 b3
-> right
.SameAs (dummy
, wxRight
, 0);
287 b3
-> bottom
.SameAs (dummy
, wxBottom
, 0);
288 m_SearchList
-> SetConstraints(b3
);
290 dummy
-> SetAutoLayout(TRUE
);
292 m_NavigPan
-> AddPage(dummy
, _("Search"));
293 m_SearchPage
= notebook_page
++;
295 m_HtmlWin
-> Show(TRUE
);
300 if (m_NavigPan
&& m_Splitter
) {
301 m_Splitter
-> SetMinimumPaneSize(20);
303 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
305 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
306 m_Splitter
-> Unsplit();
308 if (m_Cfg
.navig_on
) {
309 m_NavigPan
-> Show(TRUE
);
310 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
313 m_NavigPan
-> Show(FALSE
);
314 m_Splitter
-> Initialize(m_HtmlWin
);
320 wxHtmlHelpFrame::~wxHtmlHelpFrame()
322 delete m_ContentsImageList
;
325 if (m_NormalFonts
) delete m_NormalFonts
;
326 if (m_FixedFonts
) delete m_FixedFonts
;
329 bool wxHtmlHelpFrame::Display(const wxString
& x
)
331 wxString url
= m_Data
->FindPageByName(x
);
332 if (! url
.IsEmpty()) {
333 m_HtmlWin
->LoadPage(url
);
339 bool wxHtmlHelpFrame::Display(const int id
)
341 wxString url
= m_Data
->FindPageById(id
);
342 if (! url
.IsEmpty()) {
343 m_HtmlWin
->LoadPage(url
);
351 bool wxHtmlHelpFrame::DisplayContents()
355 if (!m_Splitter
-> IsSplit()) {
356 m_NavigPan
-> Show(TRUE
);
357 m_HtmlWin
-> Show(TRUE
);
358 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
359 m_Cfg
.navig_on
= TRUE
;
361 m_NavigPan
-> SetSelection(0);
367 bool wxHtmlHelpFrame::DisplayIndex()
371 if (!m_Splitter
-> IsSplit()) {
372 m_NavigPan
-> Show(TRUE
);
373 m_HtmlWin
-> Show(TRUE
);
374 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
376 m_NavigPan
-> SetSelection(1);
380 bool wxHtmlHelpFrame::KeywordSearch(const wxString
& keyword
)
382 if (! (m_SearchList
&& m_SearchButton
&& m_SearchText
&& m_SearchChoice
))
387 wxString book
= wxEmptyString
;
389 if (!m_Splitter
-> IsSplit()) {
390 m_NavigPan
-> Show(TRUE
);
391 m_HtmlWin
-> Show(TRUE
);
392 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
394 m_NavigPan
-> SetSelection(m_SearchPage
);
395 m_SearchList
-> Clear();
396 m_SearchText
-> SetValue(keyword
);
397 m_SearchButton
-> Enable(FALSE
);
399 if (m_SearchChoice
->GetSelection() != 0)
400 book
= m_SearchChoice
->GetStringSelection();
402 wxHtmlSearchStatus
status(m_Data
, keyword
, book
);
404 wxProgressDialog
progress(_("Searching..."), _("No matching page found yet"),
405 status
.GetMaxIndex(), this,
406 wxPD_APP_MODAL
| wxPD_CAN_ABORT
| wxPD_AUTO_HIDE
);
408 while (status
.IsActive()) {
409 if (progress
.Update(status
.GetCurIndex()) == FALSE
)
411 if (status
.Search()) {
412 foundstr
.Printf(_("Found %i matches"), ++foundcnt
);
413 progress
.Update(status
.GetCurIndex(), foundstr
);
414 m_SearchList
-> Append(status
.GetName(), status
.GetContentsItem());
419 m_SearchButton
-> Enable(TRUE
);
420 m_SearchText
-> SetSelection(0, keyword
.Length());
421 m_SearchText
-> SetFocus();
423 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_SearchList
-> GetClientData(0);
424 if (it
) m_HtmlWin
-> LoadPage(it
-> m_Book
-> GetBasePath() + it
-> m_Page
);
426 return (foundcnt
> 0);
431 void wxHtmlHelpFrame::CreateContents(bool show_progress
)
436 wxProgressDialog
*progress
= NULL
;
439 m_ContentsBox
->Clear();
441 int cnt
= m_Data
->GetContentsCnt();
442 int div
= (cnt
/ PROGRESS_STEP
) + 1;
445 wxHtmlContentsItem
*it
;
448 progress
= new wxProgressDialog(_("Building contents tree..."), wxEmptyString
,
449 cnt
, this, wxPD_APP_MODAL
| wxPD_CAN_ABORT
|
452 wxTreeItemId roots
[MAX_ROOTS
];
453 bool imaged
[MAX_ROOTS
];
455 m_ContentsBox
-> DeleteAllItems();
456 roots
[0] = m_ContentsBox
-> AddRoot(_("(Help)"));
457 m_ContentsBox
-> SetItemImage(roots
[0], IMG_RootFolder
);
458 m_ContentsBox
-> SetItemSelectedImage(roots
[0], IMG_RootFolder
);
461 for (it
= m_Data
->GetContents(), i
= 0; i
< cnt
; i
++, it
++) {
462 if (show_progress
&& ((i
% div
) == 0)) {
463 proginfo
.Printf(_("Added %d/%d items"), i
, cnt
);
464 if (! progress
->Update(i
, proginfo
))
468 roots
[it
-> m_Level
+ 1] = m_ContentsBox
-> AppendItem(
469 roots
[it
-> m_Level
], it
-> m_Name
, IMG_Page
, -1,
470 new wxHtmlHelpTreeItemData(it
));
472 if (it
-> m_Level
== 0) {
473 m_ContentsBox
-> SetItemBold(roots
[1], TRUE
);
474 m_ContentsBox
-> SetItemImage(roots
[1], IMG_Book
);
475 m_ContentsBox
-> SetItemSelectedImage(roots
[1], IMG_Book
);
477 } else imaged
[it
-> m_Level
+ 1] = FALSE
;
479 if (!imaged
[it
-> m_Level
]) {
480 m_ContentsBox
-> SetItemImage(roots
[it
-> m_Level
], IMG_Folder
);
481 m_ContentsBox
-> SetItemSelectedImage(roots
[it
-> m_Level
], IMG_Folder
);
482 imaged
[it
-> m_Level
] = TRUE
;
487 m_ContentsBox
-> Expand(roots
[0]);
491 void wxHtmlHelpFrame::CreateIndex(bool show_progress
)
496 wxProgressDialog
*progress
= NULL
;
501 int cnt
= m_Data
->GetIndexCnt();
502 int div
= (cnt
/ PROGRESS_STEP
) + 1;
504 wxHtmlContentsItem
* index
= m_Data
->GetIndex();
507 progress
= new wxProgressDialog(_("Building index list..."), wxEmptyString
,
508 cnt
, this, wxPD_APP_MODAL
| wxPD_CAN_ABORT
|
510 for (int i
= 0; i
< cnt
; i
++) {
511 if (show_progress
&& ((i
% div
) == 0)) {
512 proginfo
.Printf(_("Added %d/%d items"), i
, cnt
);
513 if (! progress
->Update(i
, proginfo
))
517 m_IndexBox
-> Append(index
[i
].m_Name
, (char*)(index
+ i
));
524 void wxHtmlHelpFrame::CreateSearch()
526 if (! (m_SearchList
&& m_SearchChoice
))
528 m_SearchList
-> Clear();
529 m_SearchChoice
-> Clear();
530 m_SearchChoice
-> Append(_("all books"));
531 const wxHtmlBookRecArray
& bookrec
= m_Data
->GetBookRecArray();
532 int i
, cnt
= bookrec
.GetCount();
533 for (i
= 0; i
< cnt
; i
++)
534 m_SearchChoice
->Append(bookrec
[i
].GetTitle());
535 m_SearchChoice
->SetSelection(0);
539 void wxHtmlHelpFrame::RefreshLists(bool show_progress
)
541 CreateContents(show_progress
);
542 CreateIndex(show_progress
);
546 void wxHtmlHelpFrame::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
551 if (path
!= wxEmptyString
) {
552 oldpath
= cfg
-> GetPath();
553 cfg
-> SetPath(path
);
556 m_Cfg
.navig_on
= cfg
-> Read("hcNavigPanel", m_Cfg
.navig_on
) != 0;
557 m_Cfg
.sashpos
= cfg
-> Read("hcSashPos", m_Cfg
.sashpos
);
558 m_Cfg
.x
= cfg
-> Read("hcX", m_Cfg
.x
);
559 m_Cfg
.y
= cfg
-> Read("hcY", m_Cfg
.y
);
560 m_Cfg
.w
= cfg
-> Read("hcW", m_Cfg
.w
);
561 m_Cfg
.h
= cfg
-> Read("hcH", m_Cfg
.h
);
563 m_FixedFace
= cfg
-> Read("hcFixedFace", m_FixedFace
);
564 m_NormalFace
= cfg
-> Read("hcNormalFace", m_NormalFace
);
565 m_FontSize
= cfg
-> Read("hcFontSize", m_FontSize
);
566 m_NormalItalic
= cfg
-> Read("hcNormalItalic", m_NormalItalic
);
567 m_FixedItalic
= cfg
-> Read("hcFixedItalic", m_FixedItalic
);
574 cnt
= cfg
-> Read("hcBookmarksCnt", 0L);
576 m_BookmarksNames
.Clear();
577 m_BookmarksPages
.Clear();
579 m_Bookmarks
-> Clear();
580 m_Bookmarks
-> Append(_("<bookmarks>"));
583 for (i
= 0; i
< cnt
; i
++) {
584 val
.Printf("hcBookmark_%i", i
);
585 s
= cfg
-> Read(val
);
586 m_BookmarksNames
.Add(s
);
587 if (m_Bookmarks
) m_Bookmarks
-> Append(s
);
588 val
.Printf("hcBookmark_%i_url", i
);
589 s
= cfg
-> Read(val
);
590 m_BookmarksPages
.Add(s
);
596 m_HtmlWin
->ReadCustomization(cfg
, path
);
598 if (path
!= wxEmptyString
)
599 cfg
-> SetPath(oldpath
);
602 void wxHtmlHelpFrame::WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
)
607 if (path
!= wxEmptyString
) {
608 oldpath
= cfg
-> GetPath();
609 cfg
-> SetPath(path
);
612 cfg
-> Write("hcNavigPanel", m_Cfg
.navig_on
);
613 cfg
-> Write("hcSashPos", (long)m_Cfg
.sashpos
);
614 cfg
-> Write("hcX", (long)m_Cfg
.x
);
615 cfg
-> Write("hcY", (long)m_Cfg
.y
);
616 cfg
-> Write("hcW", (long)m_Cfg
.w
);
617 cfg
-> Write("hcH", (long)m_Cfg
.h
);
618 cfg
-> Write("hcFixedFace", m_FixedFace
);
619 cfg
-> Write("hcNormalFace", m_NormalFace
);
620 cfg
-> Write("hcFontSize", (long)m_FontSize
);
621 cfg
-> Write("hcNormalItalic", (long)m_NormalItalic
);
622 cfg
-> Write("hcFixedItalic", (long)m_FixedItalic
);
626 int cnt
= m_BookmarksNames
.GetCount();
629 cfg
-> Write("hcBookmarksCnt", (long)cnt
);
630 for (i
= 0; i
< cnt
; i
++) {
631 val
.Printf("hcBookmark_%i", i
);
632 cfg
-> Write(val
, m_BookmarksNames
[i
]);
633 val
.Printf("hcBookmark_%i_url", i
);
634 cfg
-> Write(val
, m_BookmarksPages
[i
]);
639 m_HtmlWin
->WriteCustomization(cfg
, path
);
641 if (path
!= wxEmptyString
)
642 cfg
-> SetPath(oldpath
);
649 static void SetFontsToHtmlWin(wxHtmlWindow
*win
, wxString scalf
, int scalit
, wxString fixf
, int fixit
, int size
)
651 static int f_sizes
[3][7] =
653 { 8, 9, 12, 14, 16, 19, 22},
654 {10, 12, 14, 16, 19, 24, 32},
655 {14, 16, 18, 24, 32, 38, 45}
658 win
-> SetFonts(scalf
, scalit
, fixf
, fixit
, f_sizes
[size
]);
662 class wxHtmlHelpFrameOptionsDialog
: public wxDialog
665 wxComboBox
*NormalFont
, *FixedFont
;
666 wxRadioButton
*SFI_i
, *SFI_s
, *FFI_i
, *FFI_s
;
667 wxRadioBox
*RadioBox
;
668 wxHtmlWindow
*TestWin
;
670 wxHtmlHelpFrameOptionsDialog(wxWindow
*parent
) : wxDialog(parent
, -1, wxString(_("Help Browser Options")))
672 wxString choices
[3] = {_("small"), _("medium"), _("large")};
673 wxString choices2
[2] = {_("italic"), _("slant")};
674 wxBoxSizer
*topsizer
, *sizer
, *sizer2
, *sizer3
;
676 topsizer
= new wxBoxSizer(wxVERTICAL
);
678 sizer
= new wxBoxSizer(wxHORIZONTAL
);
680 sizer2
= new wxBoxSizer(wxVERTICAL
);
681 sizer2
-> Add(new wxStaticText(this, -1, _("Normal font:")),
682 0, wxLEFT
| wxTOP
, 10);
683 sizer2
-> Add(NormalFont
= new wxComboBox(this, -1, wxEmptyString
, wxDefaultPosition
,
685 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
),
686 1, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
688 sizer3
= new wxBoxSizer(wxHORIZONTAL
);
689 sizer3
-> Add(SFI_i
= new wxRadioButton(this, -1, _("use italic"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
),
691 sizer3
-> Add(SFI_s
= new wxRadioButton(this, -1, _("use slant"), wxDefaultPosition
, wxDefaultSize
, 0),
693 sizer2
-> Add(sizer3
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
695 sizer
-> Add(sizer2
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
697 sizer2
= new wxBoxSizer(wxVERTICAL
);
698 sizer2
-> Add(new wxStaticText(this, -1, _("Fixed font:")),
699 0, wxLEFT
| wxTOP
, 10);
700 sizer2
-> Add(FixedFont
= new wxComboBox(this, -1, wxEmptyString
, wxDefaultPosition
,
702 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
),
703 1, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
705 sizer3
= new wxBoxSizer(wxHORIZONTAL
);
706 sizer3
-> Add(FFI_i
= new wxRadioButton(this, -1, _("use italic"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
),
708 sizer3
-> Add(FFI_s
= new wxRadioButton(this, -1, _("use slant"), wxDefaultPosition
, wxDefaultSize
, 0),
710 sizer2
-> Add(sizer3
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
712 sizer
-> Add(sizer2
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
714 topsizer
-> Add(sizer
);
716 topsizer
-> Add(RadioBox
= new wxRadioBox(this, -1, _("Font size:"),
717 wxDefaultPosition
, wxDefaultSize
, 3, choices
, 3),
718 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
720 topsizer
-> Add(new wxStaticText(this, -1, _("Preview:")),
721 0, wxLEFT
| wxTOP
, 10);
722 topsizer
-> Add(TestWin
= new wxHtmlWindow(this, -1, wxDefaultPosition
, wxSize(-1, 150)),
723 1, wxEXPAND
| wxLEFT
| wxTOP
, 10);
725 sizer
= new wxBoxSizer(wxHORIZONTAL
);
726 sizer
-> Add(new wxButton(this, wxID_OK
, _("OK")), 0, wxALL
, 10);
727 sizer
-> Add(new wxButton(this, wxID_CANCEL
, _("Cancel")), 0, wxALL
, 10);
728 topsizer
-> Add(sizer
, 0, wxALIGN_RIGHT
);
732 topsizer
-> Fit(this);
740 SetFontsToHtmlWin(TestWin
,
741 NormalFont
-> GetStringSelection(), SFI_i
-> GetValue() ? wxITALIC
: wxSLANT
,
742 FixedFont
-> GetStringSelection(), FFI_i
-> GetValue() ? wxITALIC
: wxSLANT
,
743 RadioBox
-> GetSelection());
744 TestWin
-> SetPage(_("<html><body>"
745 "Normal face<br>(and <u>underlined</u>. <i>Italic face.</i> "
746 "<b>Bold face.</b> <b><i>Bold italic face.</i></b><br>"
747 "<font size=-2>font size -2</font><br>"
748 "<font size=-1>font size -1</font><br>"
749 "<font size=+0>font size +0</font><br>"
750 "<font size=+1>font size +1</font><br>"
751 "<font size=+2>font size +2</font><br>"
752 "<font size=+3>font size +3</font><br>"
753 "<font size=+4>font size +4</font><br>"
755 "<p><tt>Fixed size face.<br> <b>bold</b> <i>italic</i> "
756 "<b><i>bold italic <u>underlined</u></i></b></tt><br>"
757 "<font size=-2>font size -2</font><br>"
758 "<font size=-1>font size -1</font><br>"
759 "<font size=+0>font size +0</font><br>"
760 "<font size=+1>font size +1</font><br>"
761 "<font size=+2>font size +2</font><br>"
762 "<font size=+3>font size +3</font><br>"
763 "<font size=+4>font size +4</font>"
767 void OnUpdate(wxCloseEvent
& event
)
772 DECLARE_EVENT_TABLE()
775 BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog
, wxDialog
)
776 EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate
)
777 EVT_RADIOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate
)
778 EVT_RADIOBUTTON(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate
)
782 void wxHtmlHelpFrame::OptionsDialog()
784 wxHtmlHelpFrameOptionsDialog
dlg(this);
787 if (m_NormalFonts
== NULL
) {
788 wxFontEnumerator enu
;
789 enu
.EnumerateFacenames();
790 m_NormalFonts
= new wxArrayString
;
791 *m_NormalFonts
= *enu
.GetFacenames();
792 m_NormalFonts
-> Sort();
794 if (m_FixedFonts
== NULL
) {
795 wxFontEnumerator enu
;
796 enu
.EnumerateFacenames(wxFONTENCODING_SYSTEM
, TRUE
);
797 m_FixedFonts
= new wxArrayString
;
798 *m_FixedFonts
= *enu
.GetFacenames();
799 m_FixedFonts
-> Sort();
802 for (i
= 0; i
< m_NormalFonts
-> GetCount(); i
++)
803 dlg
.NormalFont
-> Append((*m_NormalFonts
)[i
]);
804 for (i
= 0; i
< m_FixedFonts
-> GetCount(); i
++)
805 dlg
.FixedFont
-> Append((*m_FixedFonts
)[i
]);
806 if (!m_NormalFace
.IsEmpty()) dlg
.NormalFont
-> SetStringSelection(m_NormalFace
);
807 else dlg
.NormalFont
-> SetSelection(0);
808 if (!m_FixedFace
.IsEmpty()) dlg
.FixedFont
-> SetStringSelection(m_FixedFace
);
809 else dlg
.FixedFont
-> SetSelection(0);
810 dlg
.RadioBox
-> SetSelection(m_FontSize
);
811 dlg
.SFI_i
-> SetValue(m_NormalItalic
== wxITALIC
);
812 dlg
.SFI_s
-> SetValue(m_NormalItalic
== wxSLANT
);
813 dlg
.FFI_i
-> SetValue(m_FixedItalic
== wxITALIC
);
814 dlg
.FFI_s
-> SetValue(m_FixedItalic
== wxSLANT
);
817 if (dlg
.ShowModal() == wxID_OK
) {
818 m_NormalFace
= dlg
.NormalFont
-> GetStringSelection();
819 m_FixedFace
= dlg
.FixedFont
-> GetStringSelection();
820 m_FontSize
= dlg
.RadioBox
-> GetSelection();
821 m_NormalItalic
= dlg
.SFI_i
-> GetValue() ? wxITALIC
: wxSLANT
;
822 m_FixedItalic
= dlg
.FFI_i
-> GetValue() ? wxITALIC
: wxSLANT
;
823 SetFontsToHtmlWin(m_HtmlWin
, m_NormalFace
, m_NormalItalic
, m_FixedFace
, m_FixedItalic
, m_FontSize
);
836 void wxHtmlHelpFrame::OnToolbar(wxCommandEvent
& event
)
838 switch (event
.GetId()) {
840 case wxID_HTML_BACK
:
841 m_HtmlWin
-> HistoryBack();
844 case wxID_HTML_FORWARD
:
845 m_HtmlWin
-> HistoryForward();
848 case wxID_HTML_PANEL
:
849 if (! (m_Splitter
&& m_NavigPan
))
851 if (m_Splitter
-> IsSplit()) {
852 m_Cfg
.sashpos
= m_Splitter
-> GetSashPosition();
853 m_Splitter
-> Unsplit(m_NavigPan
);
854 m_Cfg
.navig_on
= FALSE
;
856 m_NavigPan
-> Show(TRUE
);
857 m_HtmlWin
-> Show(TRUE
);
858 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
859 m_Cfg
.navig_on
= TRUE
;
863 case wxID_HTML_OPTIONS
:
867 case wxID_HTML_BOOKMARKSADD
:
872 item
= m_HtmlWin
-> GetOpenedPageTitle();
873 url
= m_HtmlWin
-> GetOpenedPage();
874 if (item
== wxEmptyString
) item
= url
.AfterLast(wxT('/'));
875 if (m_BookmarksPages
.Index(url
) == wxNOT_FOUND
) {
876 m_Bookmarks
-> Append(item
);
877 m_BookmarksNames
.Add(item
);
878 m_BookmarksPages
.Add(url
);
883 case wxID_HTML_BOOKMARKSREMOVE
:
888 item
= m_Bookmarks
-> GetStringSelection();
889 pos
= m_BookmarksNames
.Index(item
);
890 if (pos
!= wxNOT_FOUND
) {
891 m_BookmarksNames
.Remove(pos
);
892 m_BookmarksPages
.Remove(pos
);
893 m_Bookmarks
-> Delete(m_Bookmarks
-> GetSelection());
902 void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent
& event
)
904 wxHtmlHelpTreeItemData
*pg
;
906 pg
= (wxHtmlHelpTreeItemData
*) m_ContentsBox
-> GetItemData(event
.GetItem());
907 if (pg
) m_HtmlWin
-> LoadPage(pg
-> GetPage());
912 void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent
& WXUNUSED(event
))
914 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_IndexBox
-> GetClientData(m_IndexBox
-> GetSelection());
915 m_HtmlWin
-> LoadPage(it
-> m_Book
-> GetBasePath() + it
-> m_Page
);
920 void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent
& WXUNUSED(event
))
922 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_SearchList
-> GetClientData(m_SearchList
-> GetSelection());
923 if (it
) m_HtmlWin
-> LoadPage(it
-> m_Book
-> GetBasePath() + it
-> m_Page
);
926 void wxHtmlHelpFrame::OnSearch(wxCommandEvent
& WXUNUSED(event
))
928 wxString sr
= m_SearchText
-> GetLineText(0);
930 if (sr
!= wxEmptyString
) KeywordSearch(sr
);
933 void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent
& WXUNUSED(event
))
935 wxString sr
= m_Bookmarks
-> GetStringSelection();
937 if (sr
!= wxEmptyString
&& sr
!= _("<bookmarks>"))
938 m_HtmlWin
-> LoadPage(m_BookmarksPages
[m_BookmarksNames
.Index(sr
)]);
941 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent
& evt
)
943 GetSize(&m_Cfg
.w
, &m_Cfg
.h
);
944 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
946 if (m_Splitter
&& m_Cfg
.navig_on
) m_Cfg
.sashpos
= m_Splitter
-> GetSashPosition();
949 WriteCustomization(m_Config
, m_ConfigRoot
);
954 BEGIN_EVENT_TABLE(wxHtmlHelpFrame
, wxFrame
)
955 EVT_TOOL_RANGE(wxID_HTML_PANEL
, wxID_HTML_BOOKMARKSREMOVE
, wxHtmlHelpFrame::OnToolbar
)
956 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL
, wxHtmlHelpFrame::OnContentsSel
)
957 EVT_LISTBOX(wxID_HTML_INDEXLIST
, wxHtmlHelpFrame::OnIndexSel
)
958 EVT_LISTBOX(wxID_HTML_SEARCHLIST
, wxHtmlHelpFrame::OnSearchSel
)
959 EVT_BUTTON(wxID_HTML_SEARCHBUTTON
, wxHtmlHelpFrame::OnSearch
)
960 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT
, wxHtmlHelpFrame::OnSearch
)
961 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST
, wxHtmlHelpFrame::OnBookmarksSel
)
962 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow
)