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
);
191 toolBar
-> AddTool(wxID_HTML_BOOKMARKSADD
, wxBITMAP(wbkadd
), wxNullBitmap
,
192 FALSE
, -1, -1, (wxObject
*) NULL
,
193 _("Add current page to bookmarks"));
194 toolBar
-> AddTool(wxID_HTML_BOOKMARKSREMOVE
, wxBITMAP(wbkdel
), wxNullBitmap
,
195 FALSE
, -1, -1, (wxObject
*) NULL
,
196 _("Remove current page from bookmarks"));
199 toolBar
-> AddSeparator();
200 toolBar
-> AddTool(wxID_HTML_OPTIONS
, wxBITMAP(woptions
), wxNullBitmap
,
201 FALSE
, -1, -1, (wxObject
*) NULL
,
202 _("Display options dialog"));
204 toolBar
-> Realize();
207 if (style
& (wxHF_CONTENTS
| wxHF_INDEX
| wxHF_SEARCH
)) {
208 // traditional help controller; splitter window with html page on the
209 // right and a notebook containing various pages on the left
210 m_Splitter
= new wxSplitterWindow(this);
212 m_HtmlWin
= new wxHtmlWindow(m_Splitter
);
213 m_NavigPan
= new wxNotebook(m_Splitter
, wxID_HTML_NOTEBOOK
,
214 wxDefaultPosition
, wxDefaultSize
);
215 } else { // only html window, no notebook with index,contents etc
216 m_HtmlWin
= new wxHtmlWindow(this);
219 m_HtmlWin
-> SetRelatedFrame(this, m_TitleFormat
);
220 m_HtmlWin
-> SetRelatedStatusBar(0);
222 m_HtmlWin
-> ReadCustomization(m_Config
, m_ConfigRoot
);
224 // contents tree panel?
225 if (style
& wxHF_CONTENTS
) {
226 m_ContentsBox
= new wxTreeCtrl(m_NavigPan
, wxID_HTML_TREECTRL
,
227 wxDefaultPosition
, wxDefaultSize
,
228 wxTR_HAS_BUTTONS
| wxSUNKEN_BORDER
);
229 m_ContentsBox
-> SetImageList(m_ContentsImageList
);
230 m_NavigPan
-> AddPage(m_ContentsBox
, _("Contents"));
231 m_ContentsPage
= notebook_page
++;
234 // index listbox panel?
235 if (style
& wxHF_INDEX
) {
236 wxWindow
*dummy
= new wxPanel(m_NavigPan
, wxID_HTML_INDEXPAGE
);
237 wxLayoutConstraints
*b1
= new wxLayoutConstraints
;
238 b1
-> top
.SameAs (dummy
, wxTop
, 0);
239 b1
-> left
.SameAs (dummy
, wxLeft
, 0);
240 b1
-> width
.PercentOf (dummy
, wxWidth
, 100);
241 b1
-> bottom
.SameAs (dummy
, wxBottom
, 0);
242 m_IndexBox
= new wxListBox(dummy
, wxID_HTML_INDEXLIST
, wxDefaultPosition
,
243 wxDefaultSize
, 0, NULL
, wxLB_SINGLE
| wxLB_ALWAYS_SB
);
244 m_IndexBox
-> SetConstraints(b1
);
245 dummy
-> SetAutoLayout(TRUE
);
246 m_NavigPan
-> AddPage(dummy
, _("Index"));
247 m_IndexPage
= notebook_page
++;
250 // search list panel?
251 if (style
& wxHF_SEARCH
) {
252 wxWindow
*dummy
= new wxPanel(m_NavigPan
, wxID_HTML_SEARCHPAGE
);
254 wxLayoutConstraints
*b1
= new wxLayoutConstraints
;
255 m_SearchText
= new wxTextCtrl(dummy
, wxID_HTML_SEARCHTEXT
);
256 b1
-> top
.SameAs (dummy
, wxTop
, 10);
257 b1
-> left
.SameAs (dummy
, wxLeft
, 10);
258 b1
-> right
.SameAs (dummy
, wxRight
, 10);
260 m_SearchText
-> SetConstraints(b1
);
262 wxLayoutConstraints
*b2
= new wxLayoutConstraints
;
263 m_SearchButton
= new wxButton(dummy
, wxID_HTML_SEARCHBUTTON
, _("Search"));
264 b2
-> top
.Below (m_SearchText
, 10);
265 b2
-> left
.SameAs (dummy
, wxLeft
, 10);
268 m_SearchButton
-> SetConstraints(b2
);
270 wxLayoutConstraints
*b4
= new wxLayoutConstraints
;
271 m_SearchChoice
= new wxChoice(dummy
, wxID_HTML_SEARCHCHOICE
, wxDefaultPosition
,
273 b4
-> top
.Below (m_SearchText
, 10);
274 b4
-> left
.SameAs (m_SearchButton
, wxRight
, 10);
275 b4
-> right
.SameAs (dummy
, wxRight
, 10);
277 m_SearchChoice
-> SetConstraints(b4
);
279 wxLayoutConstraints
*b3
= new wxLayoutConstraints
;
280 m_SearchList
= new wxListBox(dummy
, wxID_HTML_SEARCHLIST
, wxDefaultPosition
, wxDefaultSize
, 0);
281 b3
-> top
.Below (m_SearchButton
, 10);
282 b3
-> left
.SameAs (dummy
, wxLeft
, 0);
283 b3
-> right
.SameAs (dummy
, wxRight
, 0);
284 b3
-> bottom
.SameAs (dummy
, wxBottom
, 0);
285 m_SearchList
-> SetConstraints(b3
);
287 dummy
-> SetAutoLayout(TRUE
);
289 m_NavigPan
-> AddPage(dummy
, _("Search"));
290 m_SearchPage
= notebook_page
++;
292 m_HtmlWin
-> Show(TRUE
);
297 if (m_NavigPan
&& m_Splitter
) {
298 m_Splitter
-> SetMinimumPaneSize(20);
300 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
302 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
303 m_Splitter
-> Unsplit();
305 if (m_Cfg
.navig_on
) {
306 m_NavigPan
-> Show(TRUE
);
307 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
310 m_NavigPan
-> Show(FALSE
);
311 m_Splitter
-> Initialize(m_HtmlWin
);
317 wxHtmlHelpFrame::~wxHtmlHelpFrame()
319 delete m_ContentsImageList
;
322 if (m_NormalFonts
) delete m_NormalFonts
;
323 if (m_FixedFonts
) delete m_FixedFonts
;
326 bool wxHtmlHelpFrame::Display(const wxString
& x
)
328 wxString url
= m_Data
->FindPageByName(x
);
329 if (! url
.IsEmpty()) {
330 m_HtmlWin
->LoadPage(url
);
336 bool wxHtmlHelpFrame::Display(const int id
)
338 wxString url
= m_Data
->FindPageById(id
);
339 if (! url
.IsEmpty()) {
340 m_HtmlWin
->LoadPage(url
);
348 bool wxHtmlHelpFrame::DisplayContents()
352 if (!m_Splitter
-> IsSplit()) {
353 m_NavigPan
-> Show(TRUE
);
354 m_HtmlWin
-> Show(TRUE
);
355 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
356 m_Cfg
.navig_on
= TRUE
;
358 m_NavigPan
-> SetSelection(0);
364 bool wxHtmlHelpFrame::DisplayIndex()
368 if (!m_Splitter
-> IsSplit()) {
369 m_NavigPan
-> Show(TRUE
);
370 m_HtmlWin
-> Show(TRUE
);
371 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
373 m_NavigPan
-> SetSelection(1);
377 bool wxHtmlHelpFrame::KeywordSearch(const wxString
& keyword
)
379 if (! (m_SearchList
&& m_SearchButton
&& m_SearchText
&& m_SearchChoice
))
384 wxString book
= wxEmptyString
;
386 if (!m_Splitter
-> IsSplit()) {
387 m_NavigPan
-> Show(TRUE
);
388 m_HtmlWin
-> Show(TRUE
);
389 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
391 m_NavigPan
-> SetSelection(m_SearchPage
);
392 m_SearchList
-> Clear();
393 m_SearchText
-> SetValue(keyword
);
394 m_SearchButton
-> Enable(FALSE
);
396 if (m_SearchChoice
->GetSelection() != 0)
397 book
= m_SearchChoice
->GetStringSelection();
399 wxHtmlSearchStatus
status(m_Data
, keyword
, book
);
401 wxProgressDialog
progress(_("Searching..."), _("No matching page found yet"),
402 status
.GetMaxIndex(), this,
403 wxPD_APP_MODAL
| wxPD_CAN_ABORT
| wxPD_AUTO_HIDE
);
405 while (status
.IsActive()) {
406 if (progress
.Update(status
.GetCurIndex()) == FALSE
)
408 if (status
.Search()) {
409 foundstr
.Printf(_("Found %i matches"), ++foundcnt
);
410 progress
.Update(status
.GetCurIndex(), foundstr
);
411 m_SearchList
-> Append(status
.GetName(), status
.GetContentsItem());
416 m_SearchButton
-> Enable(TRUE
);
417 m_SearchText
-> SetSelection(0, keyword
.Length());
418 m_SearchText
-> SetFocus();
420 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_SearchList
-> GetClientData(0);
421 if (it
) m_HtmlWin
-> LoadPage(it
-> m_Book
-> GetBasePath() + it
-> m_Page
);
423 return (foundcnt
> 0);
428 void wxHtmlHelpFrame::CreateContents(bool show_progress
)
433 wxProgressDialog
*progress
= NULL
;
436 m_ContentsBox
->Clear();
438 int cnt
= m_Data
->GetContentsCnt();
439 int div
= (cnt
/ PROGRESS_STEP
) + 1;
442 wxHtmlContentsItem
*it
;
445 progress
= new wxProgressDialog(_("Building contents tree..."), wxEmptyString
,
446 cnt
, this, wxPD_APP_MODAL
| wxPD_CAN_ABORT
|
449 wxTreeItemId roots
[MAX_ROOTS
];
450 bool imaged
[MAX_ROOTS
];
452 m_ContentsBox
-> DeleteAllItems();
453 roots
[0] = m_ContentsBox
-> AddRoot(_("(Help)"));
454 m_ContentsBox
-> SetItemImage(roots
[0], IMG_RootFolder
);
455 m_ContentsBox
-> SetItemSelectedImage(roots
[0], IMG_RootFolder
);
458 for (it
= m_Data
->GetContents(), i
= 0; i
< cnt
; i
++, it
++) {
459 if (show_progress
&& ((i
% div
) == 0)) {
460 proginfo
.Printf(_("Added %d/%d items"), i
, cnt
);
461 if (! progress
->Update(i
, proginfo
))
465 roots
[it
-> m_Level
+ 1] = m_ContentsBox
-> AppendItem(
466 roots
[it
-> m_Level
], it
-> m_Name
, IMG_Page
, -1,
467 new wxHtmlHelpTreeItemData(it
));
469 if (it
-> m_Level
== 0) {
470 m_ContentsBox
-> SetItemBold(roots
[1], TRUE
);
471 m_ContentsBox
-> SetItemImage(roots
[1], IMG_Book
);
472 m_ContentsBox
-> SetItemSelectedImage(roots
[1], IMG_Book
);
474 } else imaged
[it
-> m_Level
+ 1] = FALSE
;
476 if (!imaged
[it
-> m_Level
]) {
477 m_ContentsBox
-> SetItemImage(roots
[it
-> m_Level
], IMG_Folder
);
478 m_ContentsBox
-> SetItemSelectedImage(roots
[it
-> m_Level
], IMG_Folder
);
479 imaged
[it
-> m_Level
] = TRUE
;
484 m_ContentsBox
-> Expand(roots
[0]);
488 void wxHtmlHelpFrame::CreateIndex(bool show_progress
)
493 wxProgressDialog
*progress
= NULL
;
498 int cnt
= m_Data
->GetIndexCnt();
499 int div
= (cnt
/ PROGRESS_STEP
) + 1;
501 wxHtmlContentsItem
* index
= m_Data
->GetIndex();
504 progress
= new wxProgressDialog(_("Building index list..."), wxEmptyString
,
505 cnt
, this, wxPD_APP_MODAL
| wxPD_CAN_ABORT
|
507 for (int i
= 0; i
< cnt
; i
++) {
508 if (show_progress
&& ((i
% div
) == 0)) {
509 proginfo
.Printf(_("Added %d/%d items"), i
, cnt
);
510 if (! progress
->Update(i
, proginfo
))
514 m_IndexBox
-> Append(index
[i
].m_Name
, (char*)(index
+ i
));
521 void wxHtmlHelpFrame::CreateSearch()
523 if (! (m_SearchList
&& m_SearchChoice
))
525 m_SearchList
-> Clear();
526 m_SearchChoice
-> Clear();
527 m_SearchChoice
-> Append(_("all books"));
528 const wxHtmlBookRecArray
& bookrec
= m_Data
->GetBookRecArray();
529 int i
, cnt
= bookrec
.GetCount();
530 for (i
= 0; i
< cnt
; i
++)
531 m_SearchChoice
->Append(bookrec
[i
].GetTitle());
532 m_SearchChoice
->SetSelection(0);
536 void wxHtmlHelpFrame::RefreshLists(bool show_progress
)
538 CreateContents(show_progress
);
539 CreateIndex(show_progress
);
543 void wxHtmlHelpFrame::ReadCustomization(wxConfigBase
*cfg
, const wxString
& path
)
548 if (path
!= wxEmptyString
) {
549 oldpath
= cfg
-> GetPath();
550 cfg
-> SetPath(path
);
553 m_Cfg
.navig_on
= cfg
-> Read("hcNavigPanel", m_Cfg
.navig_on
) != 0;
554 m_Cfg
.sashpos
= cfg
-> Read("hcSashPos", m_Cfg
.sashpos
);
555 m_Cfg
.x
= cfg
-> Read("hcX", m_Cfg
.x
);
556 m_Cfg
.y
= cfg
-> Read("hcY", m_Cfg
.y
);
557 m_Cfg
.w
= cfg
-> Read("hcW", m_Cfg
.w
);
558 m_Cfg
.h
= cfg
-> Read("hcH", m_Cfg
.h
);
560 m_FixedFace
= cfg
-> Read("hcFixedFace", m_FixedFace
);
561 m_NormalFace
= cfg
-> Read("hcNormalFace", m_NormalFace
);
562 m_FontSize
= cfg
-> Read("hcFontSize", m_FontSize
);
563 m_NormalItalic
= cfg
-> Read("hcNormalItalic", m_NormalItalic
);
564 m_FixedItalic
= cfg
-> Read("hcFixedItalic", m_FixedItalic
);
571 cnt
= cfg
-> Read("hcBookmarksCnt", 0L);
573 m_BookmarksNames
.Clear();
574 m_BookmarksPages
.Clear();
576 m_Bookmarks
-> Clear();
577 m_Bookmarks
-> Append(_("<bookmarks>"));
580 for (i
= 0; i
< cnt
; i
++) {
581 val
.Printf("hcBookmark_%i", i
);
582 s
= cfg
-> Read(val
);
583 m_BookmarksNames
.Add(s
);
584 if (m_Bookmarks
) m_Bookmarks
-> Append(s
);
585 val
.Printf("hcBookmark_%i_url", i
);
586 s
= cfg
-> Read(val
);
587 m_BookmarksPages
.Add(s
);
593 m_HtmlWin
->ReadCustomization(cfg
, path
);
595 if (path
!= wxEmptyString
)
596 cfg
-> SetPath(oldpath
);
599 void wxHtmlHelpFrame::WriteCustomization(wxConfigBase
*cfg
, const wxString
& path
)
604 if (path
!= wxEmptyString
) {
605 oldpath
= cfg
-> GetPath();
606 cfg
-> SetPath(path
);
609 cfg
-> Write("hcNavigPanel", m_Cfg
.navig_on
);
610 cfg
-> Write("hcSashPos", (long)m_Cfg
.sashpos
);
611 cfg
-> Write("hcX", (long)m_Cfg
.x
);
612 cfg
-> Write("hcY", (long)m_Cfg
.y
);
613 cfg
-> Write("hcW", (long)m_Cfg
.w
);
614 cfg
-> Write("hcH", (long)m_Cfg
.h
);
615 cfg
-> Write("hcFixedFace", m_FixedFace
);
616 cfg
-> Write("hcNormalFace", m_NormalFace
);
617 cfg
-> Write("hcFontSize", (long)m_FontSize
);
618 cfg
-> Write("hcNormalItalic", (long)m_NormalItalic
);
619 cfg
-> Write("hcFixedItalic", (long)m_FixedItalic
);
623 int cnt
= m_BookmarksNames
.GetCount();
626 cfg
-> Write("hcBookmarksCnt", (long)cnt
);
627 for (i
= 0; i
< cnt
; i
++) {
628 val
.Printf("hcBookmark_%i", i
);
629 cfg
-> Write(val
, m_BookmarksNames
[i
]);
630 val
.Printf("hcBookmark_%i_url", i
);
631 cfg
-> Write(val
, m_BookmarksPages
[i
]);
636 m_HtmlWin
->WriteCustomization(cfg
, path
);
638 if (path
!= wxEmptyString
)
639 cfg
-> SetPath(oldpath
);
646 static void SetFontsToHtmlWin(wxHtmlWindow
*win
, wxString scalf
, int scalit
, wxString fixf
, int fixit
, int size
)
648 static int f_sizes
[3][7] =
650 { 8, 9, 12, 14, 16, 19, 22},
651 {10, 12, 14, 16, 19, 24, 32},
652 {14, 16, 18, 24, 32, 38, 45}
655 win
-> SetFonts(scalf
, scalit
, fixf
, fixit
, f_sizes
[size
]);
659 class wxHtmlHelpFrameOptionsDialog
: public wxDialog
662 wxComboBox
*NormalFont
, *FixedFont
;
663 wxRadioButton
*SFI_i
, *SFI_s
, *FFI_i
, *FFI_s
;
664 wxRadioBox
*RadioBox
;
665 wxHtmlWindow
*TestWin
;
667 wxHtmlHelpFrameOptionsDialog(wxWindow
*parent
) : wxDialog(parent
, -1, wxString(_("Help Browser Options")))
669 wxString choices
[3] = {_("small"), _("medium"), _("large")};
670 wxString choices2
[2] = {_("italic"), _("slant")};
671 wxBoxSizer
*topsizer
, *sizer
, *sizer2
, *sizer3
;
673 topsizer
= new wxBoxSizer(wxVERTICAL
);
675 sizer
= new wxBoxSizer(wxHORIZONTAL
);
677 sizer2
= new wxBoxSizer(wxVERTICAL
);
678 sizer2
-> Add(new wxStaticText(this, -1, _("Normal font:")),
679 0, wxLEFT
| wxTOP
, 10);
680 sizer2
-> Add(NormalFont
= new wxComboBox(this, -1, wxEmptyString
, wxDefaultPosition
,
685 //#endif // FIXME: temporarily commented by VS to demonstrate the problem
686 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
),
687 1, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
689 sizer3
= new wxBoxSizer(wxHORIZONTAL
);
690 sizer3
-> Add(SFI_i
= new wxRadioButton(this, -1, _("use italic"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
),
692 sizer3
-> Add(SFI_s
= new wxRadioButton(this, -1, _("use slant"), wxDefaultPosition
, wxDefaultSize
, 0),
694 sizer2
-> Add(sizer3
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
696 sizer
-> Add(sizer2
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
698 sizer2
= new wxBoxSizer(wxVERTICAL
);
699 sizer2
-> Add(new wxStaticText(this, -1, _("Fixed font:")),
700 0, wxLEFT
| wxTOP
, 10);
701 sizer2
-> Add(FixedFont
= new wxComboBox(this, -1, wxEmptyString
, wxDefaultPosition
,
706 //#endif // FIXME: temporarily commented by VS to demonstrate the problem
707 0, NULL
, wxCB_DROPDOWN
| wxCB_READONLY
),
708 1, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
710 sizer3
= new wxBoxSizer(wxHORIZONTAL
);
711 sizer3
-> Add(FFI_i
= new wxRadioButton(this, -1, _("use italic"), wxDefaultPosition
, wxDefaultSize
, wxRB_GROUP
),
713 sizer3
-> Add(FFI_s
= new wxRadioButton(this, -1, _("use slant"), wxDefaultPosition
, wxDefaultSize
, 0),
715 sizer2
-> Add(sizer3
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
717 sizer
-> Add(sizer2
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
719 topsizer
-> Add(sizer
);
721 topsizer
-> Add(RadioBox
= new wxRadioBox(this, -1, _("Font size:"),
722 wxDefaultPosition
, wxDefaultSize
, 3, choices
, 3),
723 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
725 topsizer
-> Add(new wxStaticText(this, -1, _("Preview:")),
726 0, wxLEFT
| wxTOP
, 10);
727 topsizer
-> Add(TestWin
= new wxHtmlWindow(this, -1, wxDefaultPosition
, wxSize(-1, 150)),
728 1, wxEXPAND
| wxLEFT
| wxTOP
, 10);
730 sizer
= new wxBoxSizer(wxHORIZONTAL
);
731 sizer
-> Add(new wxButton(this, wxID_OK
, _("OK")), 0, wxALL
, 10);
732 sizer
-> Add(new wxButton(this, wxID_CANCEL
, _("Cancel")), 0, wxALL
, 10);
733 topsizer
-> Add(sizer
, 0, wxALIGN_RIGHT
);
737 topsizer
-> Fit(this);
745 SetFontsToHtmlWin(TestWin
,
746 NormalFont
-> GetStringSelection(), SFI_i
-> GetValue() ? wxITALIC
: wxSLANT
,
747 FixedFont
-> GetStringSelection(), FFI_i
-> GetValue() ? wxITALIC
: wxSLANT
,
748 RadioBox
-> GetSelection());
749 TestWin
-> SetPage(_("<html><body>"
750 "Normal face<br>(and <u>underlined</u>. <i>Italic face.</i> "
751 "<b>Bold face.</b> <b><i>Bold italic face.</i></b><br>"
752 "<font size=-2>font size -2</font><br>"
753 "<font size=-1>font size -1</font><br>"
754 "<font size=+0>font size +0</font><br>"
755 "<font size=+1>font size +1</font><br>"
756 "<font size=+2>font size +2</font><br>"
757 "<font size=+3>font size +3</font><br>"
758 "<font size=+4>font size +4</font><br>"
760 "<p><tt>Fixed size face.<br> <b>bold</b> <i>italic</i> "
761 "<b><i>bold italic <u>underlined</u></i></b></tt><br>"
762 "<font size=-2>font size -2</font><br>"
763 "<font size=-1>font size -1</font><br>"
764 "<font size=+0>font size +0</font><br>"
765 "<font size=+1>font size +1</font><br>"
766 "<font size=+2>font size +2</font><br>"
767 "<font size=+3>font size +3</font><br>"
768 "<font size=+4>font size +4</font>"
772 void OnUpdate(wxCloseEvent
& event
)
777 DECLARE_EVENT_TABLE()
780 BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog
, wxDialog
)
781 EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate
)
782 EVT_RADIOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate
)
783 EVT_RADIOBUTTON(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate
)
787 void wxHtmlHelpFrame::OptionsDialog()
789 wxHtmlHelpFrameOptionsDialog
dlg(this);
792 if (m_NormalFonts
== NULL
) {
793 wxFontEnumerator enu
;
794 enu
.EnumerateFacenames();
795 m_NormalFonts
= new wxArrayString
;
796 *m_NormalFonts
= *enu
.GetFacenames();
797 m_NormalFonts
-> Sort();
799 if (m_FixedFonts
== NULL
) {
800 wxFontEnumerator enu
;
801 enu
.EnumerateFacenames(wxFONTENCODING_SYSTEM
, TRUE
);
802 m_FixedFonts
= new wxArrayString
;
803 *m_FixedFonts
= *enu
.GetFacenames();
804 m_FixedFonts
-> Sort();
807 for (i
= 0; i
< m_NormalFonts
-> GetCount(); i
++)
808 dlg
.NormalFont
-> Append((*m_NormalFonts
)[i
]);
809 for (i
= 0; i
< m_FixedFonts
-> GetCount(); i
++)
810 dlg
.FixedFont
-> Append((*m_FixedFonts
)[i
]);
811 if (!m_NormalFace
.IsEmpty()) dlg
.NormalFont
-> SetStringSelection(m_NormalFace
);
812 else dlg
.NormalFont
-> SetSelection(0);
813 if (!m_FixedFace
.IsEmpty()) dlg
.FixedFont
-> SetStringSelection(m_FixedFace
);
814 else dlg
.FixedFont
-> SetSelection(0);
815 dlg
.RadioBox
-> SetSelection(m_FontSize
);
816 dlg
.SFI_i
-> SetValue(m_NormalItalic
== wxITALIC
);
817 dlg
.SFI_s
-> SetValue(m_NormalItalic
== wxSLANT
);
818 dlg
.FFI_i
-> SetValue(m_FixedItalic
== wxITALIC
);
819 dlg
.FFI_s
-> SetValue(m_FixedItalic
== wxSLANT
);
822 if (dlg
.ShowModal() == wxID_OK
) {
823 m_NormalFace
= dlg
.NormalFont
-> GetStringSelection();
824 m_FixedFace
= dlg
.FixedFont
-> GetStringSelection();
825 m_FontSize
= dlg
.RadioBox
-> GetSelection();
826 m_NormalItalic
= dlg
.SFI_i
-> GetValue() ? wxITALIC
: wxSLANT
;
827 m_FixedItalic
= dlg
.FFI_i
-> GetValue() ? wxITALIC
: wxSLANT
;
828 SetFontsToHtmlWin(m_HtmlWin
, m_NormalFace
, m_NormalItalic
, m_FixedFace
, m_FixedItalic
, m_FontSize
);
841 void wxHtmlHelpFrame::OnToolbar(wxCommandEvent
& event
)
843 switch (event
.GetId()) {
845 case wxID_HTML_BACK
:
846 m_HtmlWin
-> HistoryBack();
849 case wxID_HTML_FORWARD
:
850 m_HtmlWin
-> HistoryForward();
853 case wxID_HTML_PANEL
:
854 if (! (m_Splitter
&& m_NavigPan
))
856 if (m_Splitter
-> IsSplit()) {
857 m_Cfg
.sashpos
= m_Splitter
-> GetSashPosition();
858 m_Splitter
-> Unsplit(m_NavigPan
);
859 m_Cfg
.navig_on
= FALSE
;
861 m_NavigPan
-> Show(TRUE
);
862 m_HtmlWin
-> Show(TRUE
);
863 m_Splitter
-> SplitVertically(m_NavigPan
, m_HtmlWin
, m_Cfg
.sashpos
);
864 m_Cfg
.navig_on
= TRUE
;
868 case wxID_HTML_OPTIONS
:
872 case wxID_HTML_BOOKMARKSADD
:
877 item
= m_HtmlWin
-> GetOpenedPageTitle();
878 url
= m_HtmlWin
-> GetOpenedPage();
879 if (item
== wxEmptyString
) item
= url
.AfterLast(wxT('/'));
880 if (m_BookmarksPages
.Index(url
) == wxNOT_FOUND
) {
881 m_Bookmarks
-> Append(item
);
882 m_BookmarksNames
.Add(item
);
883 m_BookmarksPages
.Add(url
);
888 case wxID_HTML_BOOKMARKSREMOVE
:
893 item
= m_Bookmarks
-> GetStringSelection();
894 pos
= m_BookmarksNames
.Index(item
);
895 if (pos
!= wxNOT_FOUND
) {
896 m_BookmarksNames
.Remove(pos
);
897 m_BookmarksPages
.Remove(pos
);
898 m_Bookmarks
-> Delete(m_Bookmarks
-> GetSelection());
907 void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent
& event
)
909 wxHtmlHelpTreeItemData
*pg
;
911 pg
= (wxHtmlHelpTreeItemData
*) m_ContentsBox
-> GetItemData(event
.GetItem());
912 if (pg
) m_HtmlWin
-> LoadPage(pg
-> GetPage());
917 void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent
& WXUNUSED(event
))
919 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_IndexBox
-> GetClientData(m_IndexBox
-> GetSelection());
920 m_HtmlWin
-> LoadPage(it
-> m_Book
-> GetBasePath() + it
-> m_Page
);
925 void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent
& WXUNUSED(event
))
927 wxHtmlContentsItem
*it
= (wxHtmlContentsItem
*) m_SearchList
-> GetClientData(m_SearchList
-> GetSelection());
928 if (it
) m_HtmlWin
-> LoadPage(it
-> m_Book
-> GetBasePath() + it
-> m_Page
);
931 void wxHtmlHelpFrame::OnSearch(wxCommandEvent
& WXUNUSED(event
))
933 wxString sr
= m_SearchText
-> GetLineText(0);
935 if (sr
!= wxEmptyString
) KeywordSearch(sr
);
938 void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent
& WXUNUSED(event
))
940 wxString sr
= m_Bookmarks
-> GetStringSelection();
942 if (sr
!= wxEmptyString
&& sr
!= _("<bookmarks>"))
943 m_HtmlWin
-> LoadPage(m_BookmarksPages
[m_BookmarksNames
.Index(sr
)]);
946 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent
& evt
)
948 GetSize(&m_Cfg
.w
, &m_Cfg
.h
);
949 GetPosition(&m_Cfg
.x
, &m_Cfg
.y
);
951 if (m_Splitter
&& m_Cfg
.navig_on
) m_Cfg
.sashpos
= m_Splitter
-> GetSashPosition();
954 WriteCustomization(m_Config
, m_ConfigRoot
);
959 BEGIN_EVENT_TABLE(wxHtmlHelpFrame
, wxFrame
)
960 EVT_TOOL_RANGE(wxID_HTML_PANEL
, wxID_HTML_BOOKMARKSREMOVE
, wxHtmlHelpFrame::OnToolbar
)
961 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL
, wxHtmlHelpFrame::OnContentsSel
)
962 EVT_LISTBOX(wxID_HTML_INDEXLIST
, wxHtmlHelpFrame::OnIndexSel
)
963 EVT_LISTBOX(wxID_HTML_SEARCHLIST
, wxHtmlHelpFrame::OnSearchSel
)
964 EVT_BUTTON(wxID_HTML_SEARCHBUTTON
, wxHtmlHelpFrame::OnSearch
)
965 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT
, wxHtmlHelpFrame::OnSearch
)
966 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST
, wxHtmlHelpFrame::OnBookmarksSel
)
967 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow
)