]> git.saurik.com Git - wxWidgets.git/blob - src/html/helpfrm.cpp
removed platform specific #ifdefs around wxComboBox
[wxWidgets.git] / src / html / helpfrm.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: helpfrm.cpp
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
7 // RCS-ID: $Id$
8 // Copyright: (c) Harm van der Heijden and Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h"
17
18 #include "wx/wxprec.h"
19
20 #ifdef __BORLANDC__
21 #pragma hdrstop
22 #endif
23
24 #include "wx/defs.h"
25
26 #if wxUSE_HTML
27 #ifndef WXPRECOMP
28 #include "wx/wx.h"
29 #endif
30
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"
42
43 // Bitmaps:
44
45 #ifndef __WXMSW__
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"
57 #endif
58
59 #include "wx/stream.h"
60
61 // number of times that the contents/index creation progress dialog
62 // is updated.
63 #define PROGRESS_STEP 40
64
65 //--------------------------------------------------------------------------
66 // wxHtmlHelpTreeItemData (private)
67 //--------------------------------------------------------------------------
68
69 class wxHtmlHelpTreeItemData : public wxTreeItemData
70 {
71 private:
72 wxString m_Page;
73
74 public:
75 wxHtmlHelpTreeItemData(wxHtmlContentsItem *it) : wxTreeItemData()
76 {
77 m_Page = it -> m_Book -> GetBasePath() + it -> m_Page;
78 }
79 const wxString& GetPage() { return m_Page; }
80 };
81
82
83
84
85 //---------------------------------------------------------------------------
86 // wxHtmlHelpFrame
87 //---------------------------------------------------------------------------
88
89 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame)
90
91 wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title,
92 int style, wxHtmlHelpData* data)
93 {
94 Init(data);
95 Create(parent, id, title, style);
96 }
97
98 void wxHtmlHelpFrame::Init(wxHtmlHelpData* data)
99 {
100 if (data) {
101 m_Data = data;
102 m_DataCreated = FALSE;
103 } else {
104 m_Data = new wxHtmlHelpData();
105 m_DataCreated = TRUE;
106 }
107
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));
113
114 m_ContentsBox = NULL;
115 m_IndexBox = NULL;
116 m_SearchList = NULL;
117 m_SearchButton = NULL;
118 m_SearchText = NULL;
119 m_SearchChoice = NULL;
120 m_Splitter = NULL;
121 m_NavigPan = NULL;
122 m_HtmlWin = NULL;
123 m_Bookmarks = NULL;
124 m_Config = NULL;
125 m_ConfigRoot = wxEmptyString;
126
127 m_Cfg.x = m_Cfg.y = 0;
128 m_Cfg.w = 700;
129 m_Cfg.h = 480;
130 m_Cfg.sashpos = 240;
131 m_Cfg.navig_on = TRUE;
132
133 m_NormalFonts = m_FixedFonts = NULL;
134 m_FontSize = 1;
135 m_NormalFace = m_FixedFace = wxEmptyString;
136 m_NormalItalic = m_FixedItalic = wxSLANT;
137 }
138
139 // Create: builds the GUI components.
140 // with the style flag it's possible to toggle the toolbar, contents, index and search
141 // controls.
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)
147
148 bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& title,
149 int style)
150 {
151 // Do the config in two steps. We read the HtmlWindow customization after we
152 // create the window.
153 if (m_Config)
154 ReadCustomization(m_Config, m_ConfigRoot);
155
156 wxFrame::Create(parent, id, _("Help"), wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h));
157
158 GetPosition(&m_Cfg.x, &m_Cfg.y);
159
160 SetIcon(wxICON(whelp));
161
162 int notebook_page = 0;
163
164 CreateStatusBar();
165
166 // toolbar?
167 if (style & wxHF_TOOLBAR) {
168 wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | wxTB_DOCKABLE);
169 toolBar->SetMargins( 2, 2 );
170
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();
182
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 #ifdef __WXGTK__
192 toolBar -> AddSeparator();
193 #endif
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"));
200 }
201
202 toolBar -> AddSeparator();
203 toolBar -> AddTool(wxID_HTML_OPTIONS, wxBITMAP(woptions), wxNullBitmap,
204 FALSE, -1, -1, (wxObject *) NULL,
205 _("Display options dialog"));
206
207 toolBar -> Realize();
208 }
209
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);
214
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);
220 }
221
222 m_HtmlWin -> SetRelatedFrame(this, m_TitleFormat);
223 m_HtmlWin -> SetRelatedStatusBar(0);
224 if (m_Config)
225 m_HtmlWin -> ReadCustomization(m_Config, m_ConfigRoot);
226
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++;
235 }
236
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++;
251 }
252
253 // search list panel?
254 if (style & wxHF_SEARCH) {
255 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_SEARCHPAGE);
256
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);
262 b1 -> height.AsIs();
263 m_SearchText -> SetConstraints(b1);
264
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);
269 b2 -> width.AsIs();
270 b2 -> height.AsIs();
271 m_SearchButton -> SetConstraints(b2);
272
273 wxLayoutConstraints *b4 = new wxLayoutConstraints;
274 m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE, wxDefaultPosition,
275 wxDefaultSize);
276 b4 -> top.Below (m_SearchText, 10);
277 b4 -> left.SameAs (m_SearchButton, wxRight, 10);
278 b4 -> right.SameAs (dummy, wxRight, 10);
279 b4 -> height.AsIs();
280 m_SearchChoice -> SetConstraints(b4);
281
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);
289
290 dummy -> SetAutoLayout(TRUE);
291 dummy -> Layout();
292 m_NavigPan -> AddPage(dummy, _("Search"));
293 m_SearchPage = notebook_page++;
294 }
295 m_HtmlWin -> Show(TRUE);
296
297 //RefreshLists();
298
299 // showtime
300 if (m_NavigPan && m_Splitter) {
301 m_Splitter -> SetMinimumPaneSize(20);
302 if (m_Cfg.navig_on)
303 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
304 else {
305 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
306 m_Splitter -> Unsplit();
307 }
308 if (m_Cfg.navig_on) {
309 m_NavigPan -> Show(TRUE);
310 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
311 }
312 else {
313 m_NavigPan -> Show(FALSE);
314 m_Splitter -> Initialize(m_HtmlWin);
315 }
316 }
317 return TRUE;
318 }
319
320 wxHtmlHelpFrame::~wxHtmlHelpFrame()
321 {
322 delete m_ContentsImageList;
323 if (m_DataCreated)
324 delete m_Data;
325 if (m_NormalFonts) delete m_NormalFonts;
326 if (m_FixedFonts) delete m_FixedFonts;
327 }
328
329 bool wxHtmlHelpFrame::Display(const wxString& x)
330 {
331 wxString url = m_Data->FindPageByName(x);
332 if (! url.IsEmpty()) {
333 m_HtmlWin->LoadPage(url);
334 return TRUE;
335 }
336 return FALSE;
337 }
338
339 bool wxHtmlHelpFrame::Display(const int id)
340 {
341 wxString url = m_Data->FindPageById(id);
342 if (! url.IsEmpty()) {
343 m_HtmlWin->LoadPage(url);
344 return TRUE;
345 }
346 return FALSE;
347 }
348
349
350
351 bool wxHtmlHelpFrame::DisplayContents()
352 {
353 if (! m_ContentsBox)
354 return FALSE;
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;
360 }
361 m_NavigPan -> SetSelection(0);
362 return TRUE;
363 }
364
365
366
367 bool wxHtmlHelpFrame::DisplayIndex()
368 {
369 if (! m_IndexBox)
370 return FALSE;
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);
375 }
376 m_NavigPan -> SetSelection(1);
377 return TRUE;
378 }
379
380 bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword)
381 {
382 if (! (m_SearchList && m_SearchButton && m_SearchText && m_SearchChoice))
383 return FALSE;
384
385 int foundcnt = 0;
386 wxString foundstr;
387 wxString book = wxEmptyString;
388
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);
393 }
394 m_NavigPan -> SetSelection(m_SearchPage);
395 m_SearchList -> Clear();
396 m_SearchText -> SetValue(keyword);
397 m_SearchButton -> Enable(FALSE);
398
399 if (m_SearchChoice->GetSelection() != 0)
400 book = m_SearchChoice->GetStringSelection();
401
402 wxHtmlSearchStatus status(m_Data, keyword, book);
403
404 wxProgressDialog progress(_("Searching..."), _("No matching page found yet"),
405 status.GetMaxIndex(), this,
406 wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE);
407
408 while (status.IsActive()) {
409 if (progress.Update(status.GetCurIndex()) == FALSE)
410 break;
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());
415 }
416 wxYield();
417 }
418
419 m_SearchButton -> Enable(TRUE);
420 m_SearchText -> SetSelection(0, keyword.Length());
421 m_SearchText -> SetFocus();
422 if (foundcnt) {
423 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(0);
424 if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
425 }
426 return (foundcnt > 0);
427 }
428
429 #define MAX_ROOTS 64
430
431 void wxHtmlHelpFrame::CreateContents(bool show_progress)
432 {
433 if (! m_ContentsBox)
434 return ;
435
436 wxProgressDialog *progress = NULL;
437 wxString proginfo;
438
439 m_ContentsBox->Clear();
440
441 int cnt = m_Data->GetContentsCnt();
442 int div = (cnt / PROGRESS_STEP) + 1;
443 int i;
444
445 wxHtmlContentsItem *it;
446
447 if (show_progress)
448 progress = new wxProgressDialog(_("Building contents tree..."), wxEmptyString,
449 cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT |
450 wxPD_AUTO_HIDE);
451
452 wxTreeItemId roots[MAX_ROOTS];
453 bool imaged[MAX_ROOTS];
454
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);
459 imaged[0] = TRUE;
460
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))
465 break;
466 wxYield();
467 }
468 roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem(
469 roots[it -> m_Level], it -> m_Name, IMG_Page, -1,
470 new wxHtmlHelpTreeItemData(it));
471
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);
476 imaged[1] = TRUE;
477 } else imaged[it -> m_Level + 1] = FALSE;
478
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;
483 }
484 }
485 if (show_progress)
486 delete progress;
487 m_ContentsBox -> Expand(roots[0]);
488 }
489
490
491 void wxHtmlHelpFrame::CreateIndex(bool show_progress)
492 {
493 if (! m_IndexBox)
494 return ;
495
496 wxProgressDialog *progress = NULL;
497 wxString proginfo;
498
499 m_IndexBox->Clear();
500
501 int cnt = m_Data->GetIndexCnt();
502 int div = (cnt / PROGRESS_STEP) + 1;
503
504 wxHtmlContentsItem* index = m_Data->GetIndex();
505
506 if (show_progress)
507 progress = new wxProgressDialog(_("Building index list..."), wxEmptyString,
508 cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT |
509 wxPD_AUTO_HIDE);
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))
514 break;
515 wxYield();
516 }
517 m_IndexBox -> Append(index[i].m_Name, (char*)(index + i));
518 }
519
520 if (show_progress)
521 delete progress;
522 }
523
524 void wxHtmlHelpFrame::CreateSearch()
525 {
526 if (! (m_SearchList && m_SearchChoice))
527 return ;
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);
536 }
537
538
539 void wxHtmlHelpFrame::RefreshLists(bool show_progress)
540 {
541 CreateContents(show_progress);
542 CreateIndex(show_progress);
543 CreateSearch();
544 }
545
546 void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path)
547 {
548 wxString oldpath;
549 wxString tmp;
550
551 if (path != wxEmptyString) {
552 oldpath = cfg -> GetPath();
553 cfg -> SetPath(path);
554 }
555
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);
562
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);
568
569 {
570 int i;
571 int cnt;
572 wxString val, s;
573
574 cnt = cfg -> Read("hcBookmarksCnt", 0L);
575 if (cnt != 0) {
576 m_BookmarksNames.Clear();
577 m_BookmarksPages.Clear();
578 if (m_Bookmarks) {
579 m_Bookmarks -> Clear();
580 m_Bookmarks -> Append(_("<bookmarks>"));
581 }
582
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);
591 }
592 }
593 }
594
595 if (m_HtmlWin)
596 m_HtmlWin->ReadCustomization(cfg, path);
597
598 if (path != wxEmptyString)
599 cfg -> SetPath(oldpath);
600 }
601
602 void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path)
603 {
604 wxString oldpath;
605 wxString tmp;
606
607 if (path != wxEmptyString) {
608 oldpath = cfg -> GetPath();
609 cfg -> SetPath(path);
610 }
611
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);
623
624 if (m_Bookmarks) {
625 int i;
626 int cnt = m_BookmarksNames.GetCount();
627 wxString val;
628
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]);
635 }
636 }
637
638 if (m_HtmlWin)
639 m_HtmlWin->WriteCustomization(cfg, path);
640
641 if (path != wxEmptyString)
642 cfg -> SetPath(oldpath);
643 }
644
645
646
647
648
649 static void SetFontsToHtmlWin(wxHtmlWindow *win, wxString scalf, int scalit, wxString fixf, int fixit, int size)
650 {
651 static int f_sizes[3][7] =
652 {
653 { 8, 9, 12, 14, 16, 19, 22},
654 {10, 12, 14, 16, 19, 24, 32},
655 {14, 16, 18, 24, 32, 38, 45}
656 };
657
658 win -> SetFonts(scalf, scalit, fixf, fixit, f_sizes[size]);
659 }
660
661
662 class wxHtmlHelpFrameOptionsDialog : public wxDialog
663 {
664 public:
665 wxComboBox *NormalFont, *FixedFont;
666 wxRadioButton *SFI_i, *SFI_s, *FFI_i, *FFI_s;
667 wxRadioBox *RadioBox;
668 wxHtmlWindow *TestWin;
669
670 wxHtmlHelpFrameOptionsDialog(wxWindow *parent) : wxDialog(parent, -1, wxString(_("Help Browser Options")))
671 {
672 wxString choices[3] = {_("small"), _("medium"), _("large")};
673 wxString choices2[2] = {_("italic"), _("slant")};
674 wxBoxSizer *topsizer, *sizer, *sizer2, *sizer3;
675
676 topsizer = new wxBoxSizer(wxVERTICAL);
677
678 sizer = new wxBoxSizer(wxHORIZONTAL);
679
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,
684 wxSize(200, 200),
685 0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
686 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
687
688 sizer3 = new wxBoxSizer(wxHORIZONTAL);
689 sizer3 -> Add(SFI_i = new wxRadioButton(this, -1, _("use italic"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP),
690 1, wxEXPAND, 0);
691 sizer3 -> Add(SFI_s = new wxRadioButton(this, -1, _("use slant"), wxDefaultPosition, wxDefaultSize, 0),
692 1, wxEXPAND, 0);
693 sizer2 -> Add(sizer3, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
694
695 sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
696
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,
701 wxSize(200, 200),
702 0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
703 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
704
705 sizer3 = new wxBoxSizer(wxHORIZONTAL);
706 sizer3 -> Add(FFI_i = new wxRadioButton(this, -1, _("use italic"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP),
707 1, wxEXPAND, 0);
708 sizer3 -> Add(FFI_s = new wxRadioButton(this, -1, _("use slant"), wxDefaultPosition, wxDefaultSize, 0),
709 1, wxEXPAND, 0);
710 sizer2 -> Add(sizer3, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
711
712 sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
713
714 topsizer -> Add(sizer);
715
716 topsizer -> Add(RadioBox = new wxRadioBox(this, -1, _("Font size:"),
717 wxDefaultPosition, wxDefaultSize, 3, choices, 3),
718 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
719
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);
724
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);
729
730 SetAutoLayout(TRUE);
731 SetSizer(topsizer);
732 topsizer -> Fit(this);
733 Centre(wxBOTH);
734 }
735
736
737 void UpdateTestWin()
738 {
739 wxBusyCursor bcur;
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>"
754
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>"
764 "</body></html>"));
765 }
766
767 void OnUpdate(wxCloseEvent& event)
768 {
769 UpdateTestWin();
770 }
771
772 DECLARE_EVENT_TABLE()
773 };
774
775 BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog, wxDialog)
776 EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
777 EVT_RADIOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
778 EVT_RADIOBUTTON(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
779 END_EVENT_TABLE()
780
781
782 void wxHtmlHelpFrame::OptionsDialog()
783 {
784 wxHtmlHelpFrameOptionsDialog dlg(this);
785 unsigned i;
786
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();
793 }
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();
800 }
801
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);
815 dlg.UpdateTestWin();
816
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);
824 }
825 }
826
827
828
829
830
831 /*
832 EVENT HANDLING :
833 */
834
835
836 void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event)
837 {
838 switch (event.GetId()) {
839
840 case wxID_HTML_BACK :
841 m_HtmlWin -> HistoryBack();
842 break;
843
844 case wxID_HTML_FORWARD :
845 m_HtmlWin -> HistoryForward();
846 break;
847
848 case wxID_HTML_PANEL :
849 if (! (m_Splitter && m_NavigPan))
850 return ;
851 if (m_Splitter -> IsSplit()) {
852 m_Cfg.sashpos = m_Splitter -> GetSashPosition();
853 m_Splitter -> Unsplit(m_NavigPan);
854 m_Cfg.navig_on = FALSE;
855 } else {
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;
860 }
861 break;
862
863 case wxID_HTML_OPTIONS :
864 OptionsDialog();
865 break;
866
867 case wxID_HTML_BOOKMARKSADD :
868 {
869 wxString item;
870 wxString url;
871
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);
879 }
880 }
881 break;
882
883 case wxID_HTML_BOOKMARKSREMOVE :
884 {
885 wxString item;
886 int pos;
887
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());
894 }
895 }
896 break;
897 }
898 }
899
900
901
902 void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent& event)
903 {
904 wxHtmlHelpTreeItemData *pg;
905
906 pg = (wxHtmlHelpTreeItemData*) m_ContentsBox -> GetItemData(event.GetItem());
907 if (pg) m_HtmlWin -> LoadPage(pg -> GetPage());
908 }
909
910
911
912 void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent& WXUNUSED(event))
913 {
914 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_IndexBox -> GetClientData(m_IndexBox -> GetSelection());
915 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
916 }
917
918
919
920 void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent& WXUNUSED(event))
921 {
922 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(m_SearchList -> GetSelection());
923 if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
924 }
925
926 void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event))
927 {
928 wxString sr = m_SearchText -> GetLineText(0);
929
930 if (sr != wxEmptyString) KeywordSearch(sr);
931 }
932
933 void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event))
934 {
935 wxString sr = m_Bookmarks -> GetStringSelection();
936
937 if (sr != wxEmptyString && sr != _("<bookmarks>"))
938 m_HtmlWin -> LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]);
939 }
940
941 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
942 {
943 GetSize(&m_Cfg.w, &m_Cfg.h);
944 GetPosition(&m_Cfg.x, &m_Cfg.y);
945
946 if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter -> GetSashPosition();
947
948 if (m_Config)
949 WriteCustomization(m_Config, m_ConfigRoot);
950
951 evt.Skip();
952 }
953
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)
963 END_EVENT_TABLE()
964
965 #endif