]> git.saurik.com Git - wxWidgets.git/blame - src/html/helpfrm.cpp
wxSetlocale() doesn't always return NULL
[wxWidgets.git] / src / html / helpfrm.cpp
CommitLineData
8ec2b484
HH
1/////////////////////////////////////////////////////////////////////////////
2// Name: helpfrm.cpp
3// Purpose: wxHtmlHelpFrame
d5bb85a0 4// Notes: Based on htmlhelp.cpp, implementing a monolithic
8ec2b484
HH
5// HTML Help controller class, by Vaclav Slavik
6// Author: Harm van der Heijden and Vaclav Slavik
69941f05 7// RCS-ID: $Id$
8ec2b484
HH
8// Copyright: (c) Harm van der Heijden and Vaclav Slavik
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
69941f05 13#pragma implementation
8ec2b484
HH
14#endif
15
c32bfc10
VS
16// For compilers that support precompilation, includes "wx.h"
17
8ec2b484
HH
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
8ec2b484 27#ifndef WXPRECOMP
3096bd2f 28#include "wx/wx.h"
8ec2b484
HH
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"
2bd5bbc9 40#include "wx/toolbar.h"
83efdf33 41#include "wx/fontenum.h"
8ec2b484
HH
42
43// Bitmaps:
44
45#ifndef __WXMSW__
83efdf33
VS
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"
382e6efe
VS
55#include "bitmaps/wbkadd.xpm"
56#include "bitmaps/wbkdel.xpm"
8ec2b484
HH
57#endif
58
59#include "wx/stream.h"
60
61// number of times that the contents/index creation progress dialog
62// is updated.
d5bb85a0 63#define PROGRESS_STEP 40
8ec2b484
HH
64
65//--------------------------------------------------------------------------
382e6efe 66// wxHtmlHelpTreeItemData (private)
8ec2b484
HH
67//--------------------------------------------------------------------------
68
69class wxHtmlHelpTreeItemData : public wxTreeItemData
70{
71 private:
72 wxString m_Page;
73
74 public:
d5bb85a0 75 wxHtmlHelpTreeItemData(wxHtmlContentsItem *it) : wxTreeItemData()
382e6efe
VS
76 {
77 m_Page = it -> m_Book -> GetBasePath() + it -> m_Page;
78 }
d5bb85a0 79 const wxString& GetPage() { return m_Page; }
8ec2b484
HH
80};
81
382e6efe
VS
82
83
84
8ec2b484
HH
85//---------------------------------------------------------------------------
86// wxHtmlHelpFrame
87//---------------------------------------------------------------------------
88
89IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame)
90
91wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title,
d5bb85a0 92 int style, wxHtmlHelpData* data)
8ec2b484
HH
93{
94 Init(data);
95 Create(parent, id, title, style);
96}
d5bb85a0 97
8ec2b484
HH
98void wxHtmlHelpFrame::Init(wxHtmlHelpData* data)
99{
100 if (data) {
d5bb85a0
VS
101 m_Data = data;
102 m_DataCreated = FALSE;
103 } else {
104 m_Data = new wxHtmlHelpData();
105 m_DataCreated = TRUE;
8ec2b484
HH
106 }
107
68364659 108 m_ContentsImageList = new wxImageList(16, 16);
83efdf33
VS
109 m_ContentsImageList -> Add(wxICON(wbook));
110 m_ContentsImageList -> Add(wxICON(wfolder));
111 m_ContentsImageList -> Add(wxICON(wpage));
112 m_ContentsImageList -> Add(wxICON(whlproot));
8ec2b484
HH
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;
382e6efe 123 m_Bookmarks = NULL;
8ec2b484
HH
124 m_Config = NULL;
125 m_ConfigRoot = wxEmptyString;
126
127 m_Cfg.x = m_Cfg.y = 0;
d5bb85a0
VS
128 m_Cfg.w = 700;
129 m_Cfg.h = 480;
8ec2b484
HH
130 m_Cfg.sashpos = 240;
131 m_Cfg.navig_on = TRUE;
83efdf33
VS
132
133 m_NormalFonts = m_FixedFonts = NULL;
134 m_FontSize = 1;
135 m_NormalFace = m_FixedFace = wxEmptyString;
136 m_NormalItalic = m_FixedItalic = wxSLANT;
8ec2b484
HH
137}
138
d5bb85a0
VS
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
8ec2b484 148bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& title,
d5bb85a0 149 int style)
8ec2b484
HH
150{
151 // Do the config in two steps. We read the HtmlWindow customization after we
152 // create the window.
d5bb85a0
VS
153 if (m_Config)
154 ReadCustomization(m_Config, m_ConfigRoot);
8ec2b484 155
68364659 156 wxFrame::Create(parent, id, _("Help"), wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h));
8ec2b484 157
5c172c17
VS
158 GetPosition(&m_Cfg.x, &m_Cfg.y);
159
83efdf33 160 SetIcon(wxICON(whelp));
9ffdee80 161
8ec2b484
HH
162 int notebook_page = 0;
163
164 CreateStatusBar();
165
166 // toolbar?
167 if (style & wxHF_TOOLBAR) {
83efdf33 168 wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | wxTB_DOCKABLE);
d5bb85a0 169 toolBar -> SetMargins(2, 2);
d5bb85a0 170
83efdf33
VS
171 toolBar -> AddTool(wxID_HTML_PANEL, wxBITMAP(wpanel), wxNullBitmap,
172 FALSE, -1, -1, (wxObject *) NULL,
d5bb85a0 173 _("Show/hide navigation panel"));
d5bb85a0 174 toolBar -> AddSeparator();
83efdf33
VS
175 toolBar -> AddTool(wxID_HTML_BACK, wxBITMAP(wback), wxNullBitmap,
176 FALSE, -1, -1, (wxObject *) NULL,
d5bb85a0 177 _("Go back to the previous HTML page"));
83efdf33
VS
178 toolBar -> AddTool(wxID_HTML_FORWARD, wxBITMAP(wforward), wxNullBitmap,
179 FALSE, -1, -1, (wxObject *) NULL,
d5bb85a0 180 _("Go forward to the next HTML page"));
382e6efe
VS
181 toolBar -> AddSeparator();
182
183 if (style & wxHF_BOOKMARKS) {
184 m_Bookmarks = new wxComboBox(toolBar, wxID_HTML_BOOKMARKSLIST, wxEmptyString,
185 wxDefaultPosition, wxSize(300,200), 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"));
197 }
d5bb85a0 198
83efdf33
VS
199 toolBar -> AddSeparator();
200 toolBar -> AddTool(wxID_HTML_OPTIONS, wxBITMAP(woptions), wxNullBitmap,
201 FALSE, -1, -1, (wxObject *) NULL,
202 _("Display options dialog"));
d5bb85a0 203
83efdf33 204 toolBar -> Realize();
8ec2b484 205 }
d5bb85a0 206
8ec2b484 207 if (style & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH)) {
d5bb85a0
VS
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);
211
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);
8ec2b484
HH
217 }
218
219 m_HtmlWin -> SetRelatedFrame(this, m_TitleFormat);
220 m_HtmlWin -> SetRelatedStatusBar(0);
d5bb85a0
VS
221 if (m_Config)
222 m_HtmlWin -> ReadCustomization(m_Config, m_ConfigRoot);
8ec2b484
HH
223
224 // contents tree panel?
225 if (style & wxHF_CONTENTS) {
d5bb85a0
VS
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++;
8ec2b484
HH
232 }
233
234 // index listbox panel?
235 if (style & wxHF_INDEX) {
d5bb85a0
VS
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++;
8ec2b484
HH
248 }
249
250 // search list panel?
251 if (style & wxHF_SEARCH) {
d5bb85a0
VS
252 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_SEARCHPAGE);
253
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);
259 b1 -> height.AsIs();
260 m_SearchText -> SetConstraints(b1);
261
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);
266 b2 -> width.AsIs();
267 b2 -> height.AsIs();
268 m_SearchButton -> SetConstraints(b2);
269
d5bb85a0
VS
270 wxLayoutConstraints *b4 = new wxLayoutConstraints;
271 m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE, wxDefaultPosition,
272 wxDefaultSize);
273 b4 -> top.Below (m_SearchText, 10);
274 b4 -> left.SameAs (m_SearchButton, wxRight, 10);
275 b4 -> right.SameAs (dummy, wxRight, 10);
276 b4 -> height.AsIs();
277 m_SearchChoice -> SetConstraints(b4);
278
954269e6
VS
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);
286
d5bb85a0
VS
287 dummy -> SetAutoLayout(TRUE);
288 dummy -> Layout();
289 m_NavigPan -> AddPage(dummy, _("Search"));
290 m_SearchPage = notebook_page++;
8ec2b484 291 }
c32bfc10 292 m_HtmlWin -> Show(TRUE);
8ec2b484
HH
293
294 //RefreshLists();
295
296 // showtime
297 if (m_NavigPan && m_Splitter) {
d5bb85a0 298 m_Splitter -> SetMinimumPaneSize(20);
f38374d0
DW
299 if (m_Cfg.navig_on)
300 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
301 else {
302 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
303 m_Splitter -> Unsplit();
304 }
c32bfc10
VS
305 if (m_Cfg.navig_on) {
306 m_NavigPan -> Show(TRUE);
d5bb85a0 307 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
c32bfc10 308 }
68364659 309 else {
c32bfc10
VS
310 m_NavigPan -> Show(FALSE);
311 m_Splitter -> Initialize(m_HtmlWin);
68364659 312 }
8ec2b484 313 }
8ec2b484
HH
314 return TRUE;
315}
316
317wxHtmlHelpFrame::~wxHtmlHelpFrame()
318{
319 delete m_ContentsImageList;
320 if (m_DataCreated)
d5bb85a0 321 delete m_Data;
83efdf33
VS
322 if (m_NormalFonts) delete m_NormalFonts;
323 if (m_FixedFonts) delete m_FixedFonts;
8ec2b484
HH
324}
325
326bool wxHtmlHelpFrame::Display(const wxString& x)
327{
328 wxString url = m_Data->FindPageByName(x);
329 if (! url.IsEmpty()) {
d5bb85a0
VS
330 m_HtmlWin->LoadPage(url);
331 return TRUE;
8ec2b484
HH
332 }
333 return FALSE;
334}
335
336bool wxHtmlHelpFrame::Display(const int id)
337{
338 wxString url = m_Data->FindPageById(id);
339 if (! url.IsEmpty()) {
d5bb85a0
VS
340 m_HtmlWin->LoadPage(url);
341 return TRUE;
8ec2b484
HH
342 }
343 return FALSE;
344}
345
346
347
348bool wxHtmlHelpFrame::DisplayContents()
349{
350 if (! m_ContentsBox)
d5bb85a0 351 return FALSE;
8ec2b484 352 if (!m_Splitter -> IsSplit()) {
d5bb85a0
VS
353 m_NavigPan -> Show(TRUE);
354 m_HtmlWin -> Show(TRUE);
355 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
c32bfc10 356 m_Cfg.navig_on = TRUE;
8ec2b484
HH
357 }
358 m_NavigPan -> SetSelection(0);
359 return TRUE;
360}
361
362
363
364bool wxHtmlHelpFrame::DisplayIndex()
365{
366 if (! m_IndexBox)
d5bb85a0 367 return FALSE;
8ec2b484 368 if (!m_Splitter -> IsSplit()) {
d5bb85a0
VS
369 m_NavigPan -> Show(TRUE);
370 m_HtmlWin -> Show(TRUE);
371 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
8ec2b484
HH
372 }
373 m_NavigPan -> SetSelection(1);
374 return TRUE;
375}
376
377bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword)
378{
379 if (! (m_SearchList && m_SearchButton && m_SearchText && m_SearchChoice))
d5bb85a0 380 return FALSE;
8ec2b484
HH
381
382 int foundcnt = 0;
383 wxString foundstr;
384 wxString book = wxEmptyString;
385
386 if (!m_Splitter -> IsSplit()) {
d5bb85a0
VS
387 m_NavigPan -> Show(TRUE);
388 m_HtmlWin -> Show(TRUE);
389 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
8ec2b484
HH
390 }
391 m_NavigPan -> SetSelection(m_SearchPage);
392 m_SearchList -> Clear();
393 m_SearchText -> SetValue(keyword);
394 m_SearchButton -> Enable(FALSE);
395
396 if (m_SearchChoice->GetSelection() != 0)
d5bb85a0 397 book = m_SearchChoice->GetStringSelection();
8ec2b484
HH
398
399 wxHtmlSearchStatus status(m_Data, keyword, book);
400
d5bb85a0
VS
401 wxProgressDialog progress(_("Searching..."), _("No matching page found yet"),
402 status.GetMaxIndex(), this,
403 wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE);
8ec2b484
HH
404
405 while (status.IsActive()) {
d5bb85a0
VS
406 if (progress.Update(status.GetCurIndex()) == FALSE)
407 break;
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());
412 }
413 wxYield();
8ec2b484
HH
414 }
415
416 m_SearchButton -> Enable(TRUE);
417 m_SearchText -> SetSelection(0, keyword.Length());
418 m_SearchText -> SetFocus();
419 if (foundcnt) {
420 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(0);
421 if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
422 }
423 return (foundcnt > 0);
424}
425
426#define MAX_ROOTS 64
427
428void wxHtmlHelpFrame::CreateContents(bool show_progress)
429{
430 if (! m_ContentsBox)
d5bb85a0 431 return ;
8ec2b484 432
83efdf33 433 wxProgressDialog *progress = NULL;
8ec2b484
HH
434 wxString proginfo;
435
436 m_ContentsBox->Clear();
437
438 int cnt = m_Data->GetContentsCnt();
439 int div = (cnt / PROGRESS_STEP) + 1;
440 int i;
441
83efdf33 442 wxHtmlContentsItem *it;
d5bb85a0
VS
443
444 if (show_progress)
445 progress = new wxProgressDialog(_("Building contents tree..."), wxEmptyString,
446 cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT |
447 wxPD_AUTO_HIDE);
448
8ec2b484
HH
449 wxTreeItemId roots[MAX_ROOTS];
450 bool imaged[MAX_ROOTS];
451
452 m_ContentsBox -> DeleteAllItems();
453 roots[0] = m_ContentsBox -> AddRoot(_("(Help)"));
5c172c17
VS
454 m_ContentsBox -> SetItemImage(roots[0], IMG_RootFolder);
455 m_ContentsBox -> SetItemSelectedImage(roots[0], IMG_RootFolder);
8ec2b484
HH
456 imaged[0] = TRUE;
457
83efdf33 458 for (it = m_Data->GetContents(), i = 0; i < cnt; i++, it++) {
d5bb85a0
VS
459 if (show_progress && ((i % div) == 0)) {
460 proginfo.Printf(_("Added %d/%d items"), i, cnt);
461 if (! progress->Update(i, proginfo))
462 break;
463 wxYield();
464 }
382e6efe 465 roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem(
d5bb85a0
VS
466 roots[it -> m_Level], it -> m_Name, IMG_Page, -1,
467 new wxHtmlHelpTreeItemData(it));
8ec2b484
HH
468
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);
473 imaged[1] = TRUE;
d5bb85a0 474 } else imaged[it -> m_Level + 1] = FALSE;
8ec2b484
HH
475
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;
480 }
481 }
482 if (show_progress)
d5bb85a0 483 delete progress;
8ec2b484
HH
484 m_ContentsBox -> Expand(roots[0]);
485}
486
487
488void wxHtmlHelpFrame::CreateIndex(bool show_progress)
489{
490 if (! m_IndexBox)
d5bb85a0 491 return ;
8ec2b484 492
83efdf33 493 wxProgressDialog *progress = NULL;
8ec2b484
HH
494 wxString proginfo;
495
496 m_IndexBox->Clear();
497
498 int cnt = m_Data->GetIndexCnt();
499 int div = (cnt / PROGRESS_STEP) + 1;
500
501 wxHtmlContentsItem* index = m_Data->GetIndex();
502
d5bb85a0
VS
503 if (show_progress)
504 progress = new wxProgressDialog(_("Building index list..."), wxEmptyString,
505 cnt, this, wxPD_APP_MODAL | wxPD_CAN_ABORT |
506 wxPD_AUTO_HIDE);
8ec2b484 507 for (int i = 0; i < cnt; i++) {
d5bb85a0
VS
508 if (show_progress && ((i % div) == 0)) {
509 proginfo.Printf(_("Added %d/%d items"), i, cnt);
510 if (! progress->Update(i, proginfo))
511 break;
512 wxYield();
513 }
8ec2b484
HH
514 m_IndexBox -> Append(index[i].m_Name, (char*)(index + i));
515 }
516
517 if (show_progress)
d5bb85a0 518 delete progress;
8ec2b484
HH
519}
520
521void wxHtmlHelpFrame::CreateSearch()
522{
523 if (! (m_SearchList && m_SearchChoice))
d5bb85a0 524 return ;
8ec2b484
HH
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();
d5bb85a0
VS
530 for (i = 0; i < cnt; i++)
531 m_SearchChoice->Append(bookrec[i].GetTitle());
8ec2b484
HH
532 m_SearchChoice->SetSelection(0);
533}
534
535
536void wxHtmlHelpFrame::RefreshLists(bool show_progress)
537{
538 CreateContents(show_progress);
539 CreateIndex(show_progress);
540 CreateSearch();
541}
542
543void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path)
544{
545 wxString oldpath;
546 wxString tmp;
547
548 if (path != wxEmptyString) {
549 oldpath = cfg -> GetPath();
550 cfg -> SetPath(path);
551 }
552
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);
8ec2b484 559
83efdf33
VS
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);
565
382e6efe
VS
566 {
567 int i;
568 int cnt;
569 wxString val, s;
570
571 cnt = cfg -> Read("hcBookmarksCnt", 0L);
572 if (cnt != 0) {
573 m_BookmarksNames.Clear();
574 m_BookmarksPages.Clear();
575 if (m_Bookmarks) {
576 m_Bookmarks -> Clear();
577 m_Bookmarks -> Append(_("<bookmarks>"));
578 }
579
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);
588 }
589 }
590 }
591
8ec2b484 592 if (m_HtmlWin)
d5bb85a0 593 m_HtmlWin->ReadCustomization(cfg, path);
8ec2b484
HH
594
595 if (path != wxEmptyString)
596 cfg -> SetPath(oldpath);
597}
598
599void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path)
600{
601 wxString oldpath;
602 wxString tmp;
8ec2b484
HH
603
604 if (path != wxEmptyString) {
605 oldpath = cfg -> GetPath();
606 cfg -> SetPath(path);
607 }
608
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);
83efdf33
VS
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);
382e6efe
VS
620
621 if (m_Bookmarks) {
622 int i;
623 int cnt = m_BookmarksNames.GetCount();
624 wxString val;
625
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]);
632 }
633 }
8ec2b484
HH
634
635 if (m_HtmlWin)
d5bb85a0 636 m_HtmlWin->WriteCustomization(cfg, path);
8ec2b484
HH
637
638 if (path != wxEmptyString)
639 cfg -> SetPath(oldpath);
640}
641
642
83efdf33
VS
643
644
645
646static void SetFontsToHtmlWin(wxHtmlWindow *win, wxString scalf, int scalit, wxString fixf, int fixit, int size)
647{
83efdf33
VS
648 static int f_sizes[3][7] =
649 {
f151e8b5 650 { 8, 9, 12, 14, 16, 19, 22},
83efdf33 651 {10, 12, 14, 16, 19, 24, 32},
83efdf33
VS
652 {14, 16, 18, 24, 32, 38, 45}
653 };
f151e8b5 654
83efdf33
VS
655 win -> SetFonts(scalf, scalit, fixf, fixit, f_sizes[size]);
656}
657
658
659class wxHtmlHelpFrameOptionsDialog : public wxDialog
660{
661 public:
f151e8b5 662 wxComboBox *NormalFont, *FixedFont;
83efdf33
VS
663 wxRadioButton *SFI_i, *SFI_s, *FFI_i, *FFI_s;
664 wxRadioBox *RadioBox;
665 wxHtmlWindow *TestWin;
666
667 wxHtmlHelpFrameOptionsDialog(wxWindow *parent) : wxDialog(parent, -1, wxString(_("Help Browser Options")))
668 {
f151e8b5
VS
669 wxString choices[3] = {_("small"), _("medium"), _("large")};
670 wxString choices2[2] = {_("italic"), _("slant")};
83efdf33
VS
671 wxBoxSizer *topsizer, *sizer, *sizer2, *sizer3;
672
673 topsizer = new wxBoxSizer(wxVERTICAL);
674
675 sizer = new wxBoxSizer(wxHORIZONTAL);
676
677 sizer2 = new wxBoxSizer(wxVERTICAL);
678 sizer2 -> Add(new wxStaticText(this, -1, _("Normal font:")),
679 0, wxLEFT | wxTOP, 10);
382e6efe
VS
680 sizer2 -> Add(NormalFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
681//#ifdef __WXMSW__
682 wxSize(200, 200),
683//#else
684// wxSize(200, -1),
685//#endif // FIXME: temporarily commented by VS to demonstrate the problem
686 0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
83efdf33
VS
687 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
688
689 sizer3 = new wxBoxSizer(wxHORIZONTAL);
690 sizer3 -> Add(SFI_i = new wxRadioButton(this, -1, _("use italic"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP),
691 1, wxEXPAND, 0);
692 sizer3 -> Add(SFI_s = new wxRadioButton(this, -1, _("use slant"), wxDefaultPosition, wxDefaultSize, 0),
693 1, wxEXPAND, 0);
694 sizer2 -> Add(sizer3, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
695
696 sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
697
698 sizer2 = new wxBoxSizer(wxVERTICAL);
699 sizer2 -> Add(new wxStaticText(this, -1, _("Fixed font:")),
700 0, wxLEFT | wxTOP, 10);
382e6efe
VS
701 sizer2 -> Add(FixedFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
702//#ifdef __WXMSW__
703 wxSize(200, 200),
704//#else
705// wxSize(200, -1),
706//#endif // FIXME: temporarily commented by VS to demonstrate the problem
707 0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
83efdf33
VS
708 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
709
710 sizer3 = new wxBoxSizer(wxHORIZONTAL);
711 sizer3 -> Add(FFI_i = new wxRadioButton(this, -1, _("use italic"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP),
712 1, wxEXPAND, 0);
713 sizer3 -> Add(FFI_s = new wxRadioButton(this, -1, _("use slant"), wxDefaultPosition, wxDefaultSize, 0),
714 1, wxEXPAND, 0);
715 sizer2 -> Add(sizer3, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
716
717 sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
718
719 topsizer -> Add(sizer);
720
721 topsizer -> Add(RadioBox = new wxRadioBox(this, -1, _("Font size:"),
722 wxDefaultPosition, wxDefaultSize, 3, choices, 3),
723 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
724
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);
729
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);
734
735 SetAutoLayout(TRUE);
736 SetSizer(topsizer);
737 topsizer -> Fit(this);
738 Centre(wxBOTH);
739 }
740
741
742 void UpdateTestWin()
743 {
744 wxBusyCursor bcur;
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>"
759
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>"
769 "</body></html>"));
770 }
771
772 void OnUpdate(wxCloseEvent& event)
773 {
774 UpdateTestWin();
775 }
776
777 DECLARE_EVENT_TABLE()
778};
779
780BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog, wxDialog)
f151e8b5 781 EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
83efdf33
VS
782 EVT_RADIOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
783 EVT_RADIOBUTTON(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
784END_EVENT_TABLE()
785
786
787void wxHtmlHelpFrame::OptionsDialog()
788{
789 wxHtmlHelpFrameOptionsDialog dlg(this);
790 unsigned i;
791
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();
798 }
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();
805 }
806
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);
820 dlg.UpdateTestWin();
821
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);
829 }
830}
831
832
833
834
835
8ec2b484
HH
836/*
837EVENT HANDLING :
838*/
839
840
841void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event)
842{
843 switch (event.GetId()) {
382e6efe 844
8ec2b484
HH
845 case wxID_HTML_BACK :
846 m_HtmlWin -> HistoryBack();
847 break;
382e6efe 848
8ec2b484
HH
849 case wxID_HTML_FORWARD :
850 m_HtmlWin -> HistoryForward();
851 break;
382e6efe 852
8ec2b484 853 case wxID_HTML_PANEL :
d5bb85a0
VS
854 if (! (m_Splitter && m_NavigPan))
855 return ;
8ec2b484
HH
856 if (m_Splitter -> IsSplit()) {
857 m_Cfg.sashpos = m_Splitter -> GetSashPosition();
858 m_Splitter -> Unsplit(m_NavigPan);
68364659 859 m_Cfg.navig_on = FALSE;
d5bb85a0 860 } else {
8ec2b484
HH
861 m_NavigPan -> Show(TRUE);
862 m_HtmlWin -> Show(TRUE);
863 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
68364659 864 m_Cfg.navig_on = TRUE;
8ec2b484
HH
865 }
866 break;
382e6efe 867
83efdf33
VS
868 case wxID_HTML_OPTIONS :
869 OptionsDialog();
870 break;
382e6efe
VS
871
872 case wxID_HTML_BOOKMARKSADD :
873 {
874 wxString item;
875 wxString url;
876
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);
884 }
885 }
886 break;
887
888 case wxID_HTML_BOOKMARKSREMOVE :
889 {
890 wxString item;
891 int pos;
892
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());
899 }
900 }
901 break;
8ec2b484
HH
902 }
903}
904
905
906
907void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent& event)
908{
909 wxHtmlHelpTreeItemData *pg;
910
911 pg = (wxHtmlHelpTreeItemData*) m_ContentsBox -> GetItemData(event.GetItem());
912 if (pg) m_HtmlWin -> LoadPage(pg -> GetPage());
913}
914
915
916
a4c97004 917void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent& WXUNUSED(event))
8ec2b484 918{
5d4b632b 919 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_IndexBox -> GetClientData(m_IndexBox -> GetSelection());
c32bfc10 920 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
8ec2b484
HH
921}
922
923
924
a4c97004 925void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent& WXUNUSED(event))
8ec2b484
HH
926{
927 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(m_SearchList -> GetSelection());
928 if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
929}
930
a4c97004 931void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event))
8ec2b484
HH
932{
933 wxString sr = m_SearchText -> GetLineText(0);
934
935 if (sr != wxEmptyString) KeywordSearch(sr);
936}
937
382e6efe
VS
938void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event))
939{
940 wxString sr = m_Bookmarks -> GetStringSelection();
941
942 if (sr != wxEmptyString && sr != _("<bookmarks>"))
943 m_HtmlWin -> LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]);
944}
945
8ec2b484
HH
946void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
947{
68364659
VS
948 GetSize(&m_Cfg.w, &m_Cfg.h);
949 GetPosition(&m_Cfg.x, &m_Cfg.y);
5c172c17 950
68364659
VS
951 if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter -> GetSashPosition();
952
d5bb85a0
VS
953 if (m_Config)
954 WriteCustomization(m_Config, m_ConfigRoot);
68364659 955
8ec2b484
HH
956 evt.Skip();
957}
958
959BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame)
382e6efe 960 EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_BOOKMARKSREMOVE, wxHtmlHelpFrame::OnToolbar)
8ec2b484
HH
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)
382e6efe
VS
966 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST, wxHtmlHelpFrame::OnBookmarksSel)
967 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow)
8ec2b484
HH
968END_EVENT_TABLE()
969
970#endif