some != NULL checks
[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/html/helpctrl.h"
33 #include "wx/notebook.h"
34 #include "wx/imaglist.h"
35 #include "wx/treectrl.h"
36 #include "wx/tokenzr.h"
37 #include "wx/wfstream.h"
38 #include "wx/html/htmlwin.h"
39 #include "wx/busyinfo.h"
40 #include "wx/progdlg.h"
41 #include "wx/toolbar.h"
42 #include "wx/fontenum.h"
43 #include "wx/stream.h"
44 #include "wx/filedlg.h"
45
46 // Bitmaps:
47
48 #ifndef __WXMSW__
49 #include "bitmaps/wpanel.xpm"
50 #include "bitmaps/wback.xpm"
51 #include "bitmaps/wforward.xpm"
52 #include "bitmaps/wbook.xpm"
53 #include "bitmaps/woptions.xpm"
54 #include "bitmaps/wfolder.xpm"
55 #include "bitmaps/wpage.xpm"
56 #include "bitmaps/whelp.xpm"
57 #include "bitmaps/whlproot.xpm"
58 #include "bitmaps/wbkadd.xpm"
59 #include "bitmaps/wbkdel.xpm"
60 #include "bitmaps/wup.xpm"
61 #include "bitmaps/wupnode.xpm"
62 #include "bitmaps/wdown.xpm"
63 #include "bitmaps/wopen.xpm"
64 #include "bitmaps/wprint.xpm"
65 #endif
66
67
68 // what is considered "small index"?
69 #define INDEX_IS_SMALL 100
70
71
72 //--------------------------------------------------------------------------
73 // wxHtmlHelpTreeItemData (private)
74 //--------------------------------------------------------------------------
75
76 class wxHtmlHelpTreeItemData : public wxTreeItemData
77 {
78 public:
79 wxHtmlHelpTreeItemData(int id) : wxTreeItemData()
80 { m_Id = id;}
81
82 int m_Id;
83 };
84
85
86 //--------------------------------------------------------------------------
87 // wxHtmlHelpHashData (private)
88 //--------------------------------------------------------------------------
89
90 class wxHtmlHelpHashData : public wxObject
91 {
92 public:
93 wxHtmlHelpHashData(int index, wxTreeItemId id) : wxObject()
94 { m_Index = index; m_Id = id;}
95 ~wxHtmlHelpHashData() {}
96
97 int m_Index;
98 wxTreeItemId m_Id;
99 };
100
101
102 //--------------------------------------------------------------------------
103 // wxHtmlHelpHtmlWindow (private)
104 //--------------------------------------------------------------------------
105
106 class wxHtmlHelpHtmlWindow : public wxHtmlWindow
107 {
108 public:
109 wxHtmlHelpHtmlWindow(wxHtmlHelpFrame *fr, wxWindow *parent) : wxHtmlWindow(parent), m_Frame(fr) {}
110
111 virtual void OnLinkClicked(const wxHtmlLinkInfo& link)
112 {
113 wxHtmlWindow::OnLinkClicked(link);
114 m_Frame -> NotifyPageChanged();
115 }
116
117 private:
118 wxHtmlHelpFrame *m_Frame;
119 };
120
121
122
123 //---------------------------------------------------------------------------
124 // wxHtmlHelpFrame
125 //---------------------------------------------------------------------------
126
127 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame)
128
129 wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title,
130 int style, wxHtmlHelpData* data)
131 {
132 Init(data);
133 Create(parent, id, title, style);
134 }
135
136 void wxHtmlHelpFrame::Init(wxHtmlHelpData* data)
137 {
138 if (data) {
139 m_Data = data;
140 m_DataCreated = FALSE;
141 } else {
142 m_Data = new wxHtmlHelpData();
143 m_DataCreated = TRUE;
144 }
145
146 m_ContentsImageList = new wxImageList(16, 16);
147 m_ContentsImageList -> Add(wxICON(wbook));
148 m_ContentsImageList -> Add(wxICON(wfolder));
149 m_ContentsImageList -> Add(wxICON(wpage));
150 m_ContentsImageList -> Add(wxICON(whlproot));
151
152 m_ContentsBox = NULL;
153 m_IndexList = NULL;
154 m_IndexButton = NULL;
155 m_IndexButtonAll = NULL;
156 m_IndexText = NULL;
157 m_SearchList = NULL;
158 m_SearchButton = NULL;
159 m_SearchText = NULL;
160 m_SearchChoice = NULL;
161 m_IndexCountInfo = NULL;
162 m_Splitter = NULL;
163 m_NavigPan = NULL;
164 m_HtmlWin = NULL;
165 m_Bookmarks = NULL;
166 m_SearchCaseSensitive = NULL;
167 m_SearchWholeWords = NULL;
168
169 m_Config = NULL;
170 m_ConfigRoot = wxEmptyString;
171
172 m_Cfg.x = m_Cfg.y = 0;
173 m_Cfg.w = 700;
174 m_Cfg.h = 480;
175 m_Cfg.sashpos = 240;
176 m_Cfg.navig_on = TRUE;
177
178 m_NormalFonts = m_FixedFonts = NULL;
179 m_NormalFace = m_FixedFace = wxEmptyString;
180 m_FontSize = 1;
181
182 #if wxUSE_PRINTING_ARCHITECTURE
183 m_Printer = NULL;
184 #endif
185
186 m_PagesHash = NULL;
187 m_UpdateContents = TRUE;
188 m_helpController = (wxHelpControllerBase*) NULL;
189 }
190
191 // Create: builds the GUI components.
192 // with the style flag it's possible to toggle the toolbar, contents, index and search
193 // controls.
194 // m_HtmlWin will *always* be created, but it's important to realize that
195 // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
196 // m_SearchButton may be NULL.
197 // moreover, if no contents, index or searchpage is needed, m_Splitter and
198 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
199
200 bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id, const wxString& title,
201 int style)
202 {
203 // Do the config in two steps. We read the HtmlWindow customization after we
204 // create the window.
205 if (m_Config)
206 ReadCustomization(m_Config, m_ConfigRoot);
207
208 wxFrame::Create(parent, id, _("Help"), wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h), wxDEFAULT_FRAME_STYLE, "wxHtmlHelp");
209
210 GetPosition(&m_Cfg.x, &m_Cfg.y);
211
212 SetIcon(wxICON(whelp));
213
214 int notebook_page = 0;
215
216 CreateStatusBar();
217
218 // toolbar?
219 if (style & wxHF_TOOLBAR) {
220 wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | wxTB_DOCKABLE);
221 toolBar->SetMargins( 2, 2 );
222 AddToolbarButtons(toolBar, style);
223 toolBar -> Realize();
224 }
225
226 if (style & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH)) {
227 // traditional help controller; splitter window with html page on the
228 // right and a notebook containing various pages on the left
229 m_Splitter = new wxSplitterWindow(this);
230
231 m_HtmlWin = new wxHtmlHelpHtmlWindow(this, m_Splitter);
232 m_NavigPan = new wxNotebook(m_Splitter, wxID_HTML_NOTEBOOK,
233 wxDefaultPosition, wxDefaultSize);
234 } else { // only html window, no notebook with index,contents etc
235 m_HtmlWin = new wxHtmlWindow(this);
236 }
237
238 m_HtmlWin -> SetRelatedFrame(this, m_TitleFormat);
239 m_HtmlWin -> SetRelatedStatusBar(0);
240 if (m_Config)
241 m_HtmlWin -> ReadCustomization(m_Config, m_ConfigRoot);
242
243 // contents tree panel?
244 if (style & wxHF_CONTENTS) {
245 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_INDEXPAGE);
246
247 if (style & wxHF_BOOKMARKS) {
248 wxLayoutConstraints *b1 = new wxLayoutConstraints;
249 wxBitmapButton *bmpbt = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSREMOVE, wxBITMAP(wbkdel), wxDefaultPosition, wxSize(20,20));
250
251 b1 -> top.SameAs (dummy, wxTop, 10);
252 b1 -> right.SameAs (dummy, wxRight, 10);
253 b1 -> height.AsIs();
254 b1 -> width.AsIs();
255 bmpbt -> SetConstraints(b1);
256
257 wxLayoutConstraints *b2 = new wxLayoutConstraints;
258 wxBitmapButton *bmpbt2 = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSADD, wxBITMAP(wbkadd), wxDefaultPosition, wxSize(20,20));
259
260 b2 -> top.SameAs (dummy, wxTop, 10);
261 b2 -> right.LeftOf (bmpbt, 2);
262 b2 -> height.AsIs();
263 b2 -> width.AsIs();
264 bmpbt2 -> SetConstraints(b2);
265
266 #if wxUSE_TOOLTIPS
267 bmpbt -> SetToolTip(_("Remove current page from bookmarks"));
268 bmpbt2 -> SetToolTip(_("Add current page to bookmarks"));
269 #endif //wxUSE_TOOLTIPS
270
271 wxLayoutConstraints *b3 = new wxLayoutConstraints;
272 m_Bookmarks = new wxComboBox(dummy, wxID_HTML_BOOKMARKSLIST, wxEmptyString,
273 wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY | wxCB_SORT);
274 m_Bookmarks -> Append(_("(bookmarks)"));
275 for (unsigned i = 0; i < m_BookmarksNames.GetCount(); i++)
276 m_Bookmarks -> Append(m_BookmarksNames[i]);
277 m_Bookmarks -> SetSelection(0);
278
279 b3 -> centreY.SameAs (bmpbt2, wxCentreY);
280 b3 -> left.SameAs (dummy, wxLeft, 10);
281 b3 -> right.LeftOf (bmpbt2, 5);
282 b3 -> height.AsIs();
283 m_Bookmarks -> SetConstraints(b3);
284
285
286 wxLayoutConstraints *b4 = new wxLayoutConstraints;
287 m_ContentsBox = new wxTreeCtrl(dummy, wxID_HTML_TREECTRL,
288 wxDefaultPosition, wxDefaultSize,
289 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
290 m_ContentsBox -> SetImageList(m_ContentsImageList);
291
292 b4 -> top.Below (m_Bookmarks, 10);
293 b4 -> left.SameAs (dummy, wxLeft, 0);
294 b4 -> right.SameAs (dummy, wxRight, 0);
295 b4 -> bottom.SameAs (dummy, wxBottom, 0);
296 m_ContentsBox -> SetConstraints(b4);
297
298 dummy -> SetAutoLayout(TRUE);
299 dummy -> Layout();
300
301 m_NavigPan -> AddPage(dummy, _("Contents"));
302 }
303
304 else
305 {
306 m_ContentsBox = new wxTreeCtrl(m_NavigPan, wxID_HTML_TREECTRL,
307 wxDefaultPosition, wxDefaultSize,
308 wxTR_HAS_BUTTONS | wxSUNKEN_BORDER);
309 m_ContentsBox -> SetImageList(m_ContentsImageList);
310 m_NavigPan -> AddPage(m_ContentsBox, _("Contents"));
311 }
312
313 m_ContentsPage = notebook_page++;
314 }
315
316 // index listbox panel?
317 if (style & wxHF_INDEX) {
318 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_INDEXPAGE);
319
320 wxLayoutConstraints *b1 = new wxLayoutConstraints;
321 m_IndexText = new wxTextCtrl(dummy, wxID_HTML_INDEXTEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
322 b1 -> top.SameAs (dummy, wxTop, 10);
323 b1 -> left.SameAs (dummy, wxLeft, 10);
324 b1 -> right.SameAs (dummy, wxRight, 10);
325 b1 -> height.AsIs();
326 m_IndexText -> SetConstraints(b1);
327
328 wxLayoutConstraints *b4 = new wxLayoutConstraints;
329 m_IndexButtonAll = new wxButton(dummy, wxID_HTML_INDEXBUTTONALL, _("Show all"));
330
331 b4 -> top.Below (m_IndexText, 10);
332 b4 -> right.SameAs (dummy, wxRight, 10);
333 b4 -> width.AsIs();
334 b4 -> height.AsIs();
335 m_IndexButtonAll -> SetConstraints(b4);
336
337 wxLayoutConstraints *b2 = new wxLayoutConstraints;
338 m_IndexButton = new wxButton(dummy, wxID_HTML_INDEXBUTTON, _("Find"));
339 b2 -> top.Below (m_IndexText, 10);
340 b2 -> right.LeftOf (m_IndexButtonAll, 10);
341 b2 -> width.AsIs();
342 b2 -> height.AsIs();
343 m_IndexButton -> SetConstraints(b2);
344
345 wxLayoutConstraints *b5 = new wxLayoutConstraints;
346 m_IndexCountInfo = new wxStaticText(dummy, wxID_HTML_COUNTINFO, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT | wxST_NO_AUTORESIZE);
347
348 b5 -> top.Below (m_IndexButton, 5);
349 b5 -> right.SameAs (dummy, wxRight, 10);
350 b5 -> left.SameAs (dummy, wxLeft, 10);
351 b5 -> height.AsIs();
352 m_IndexCountInfo -> SetConstraints(b5);
353
354 wxLayoutConstraints *b3 = new wxLayoutConstraints;
355 m_IndexList = new wxListBox(dummy, wxID_HTML_INDEXLIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE);
356 b3 -> top.Below (m_IndexCountInfo, 5);
357 b3 -> left.SameAs (dummy, wxLeft, 0);
358 b3 -> right.SameAs (dummy, wxRight, 0);
359 b3 -> bottom.SameAs (dummy, wxBottom, 0);
360 m_IndexList -> SetConstraints(b3);
361
362 #if wxUSE_TOOLTIPS
363 m_IndexButtonAll -> SetToolTip(_("Show all items in index"));
364 m_IndexButton -> SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
365 #endif //wxUSE_TOOLTIPS
366
367 dummy -> SetAutoLayout(TRUE);
368 dummy -> Layout();
369
370 m_NavigPan -> AddPage(dummy, _("Index"));
371 m_IndexPage = notebook_page++;
372 }
373
374 // search list panel?
375 if (style & wxHF_SEARCH) {
376 wxWindow *dummy = new wxPanel(m_NavigPan, wxID_HTML_SEARCHPAGE);
377
378 wxLayoutConstraints *b1 = new wxLayoutConstraints;
379 m_SearchText = new wxTextCtrl(dummy, wxID_HTML_SEARCHTEXT, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
380 b1 -> top.SameAs (dummy, wxTop, 10);
381 b1 -> left.SameAs (dummy, wxLeft, 10);
382 b1 -> right.SameAs (dummy, wxRight, 10);
383 b1 -> height.AsIs();
384 m_SearchText -> SetConstraints(b1);
385
386 wxLayoutConstraints *b4 = new wxLayoutConstraints;
387 m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE, wxDefaultPosition,
388 wxDefaultSize);
389 b4 -> top.Below (m_SearchText, 10);
390 b4 -> left.SameAs (dummy, wxLeft, 10);
391 b4 -> right.SameAs (dummy, wxRight, 10);
392 b4 -> height.AsIs();
393 m_SearchChoice -> SetConstraints(b4);
394
395 wxLayoutConstraints *b5 = new wxLayoutConstraints;
396 m_SearchCaseSensitive = new wxCheckBox(dummy, -1, _("Case sensitive"));
397 b5 -> top.Below (m_SearchChoice, 10);
398 b5 -> left.SameAs (dummy, wxLeft, 10);
399 b5 -> width.AsIs();
400 b5 -> height.AsIs ();
401 m_SearchCaseSensitive -> SetConstraints(b5);
402
403 wxLayoutConstraints *b6 = new wxLayoutConstraints;
404 m_SearchWholeWords = new wxCheckBox(dummy, -1, _("Whole words only"));
405 b6 -> top.Below (m_SearchCaseSensitive, 0);
406 b6 -> left.SameAs (dummy, wxLeft, 10);
407 b6 -> width.AsIs();
408 b6 -> height.AsIs ();
409 m_SearchWholeWords -> SetConstraints(b6);
410
411 wxLayoutConstraints *b2 = new wxLayoutConstraints;
412 m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search"));
413 #if wxUSE_TOOLTIPS
414 m_SearchButton -> SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
415 #endif //wxUSE_TOOLTIPS
416 b2 -> top.Below (m_SearchWholeWords, 0);
417 b2 -> right.SameAs (dummy, wxRight, 10);
418 b2 -> width.AsIs();
419 b2 -> height.AsIs();
420 m_SearchButton -> SetConstraints(b2);
421
422 wxLayoutConstraints *b3 = new wxLayoutConstraints;
423 m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE);
424 b3 -> top.Below (m_SearchButton, 10);
425 b3 -> left.SameAs (dummy, wxLeft, 0);
426 b3 -> right.SameAs (dummy, wxRight, 0);
427 b3 -> bottom.SameAs (dummy, wxBottom, 0);
428 m_SearchList -> SetConstraints(b3);
429
430 dummy -> SetAutoLayout(TRUE);
431 dummy -> Layout();
432 m_NavigPan -> AddPage(dummy, _("Search"));
433 m_SearchPage = notebook_page++;
434 }
435 m_HtmlWin -> Show(TRUE);
436
437 RefreshLists();
438
439 // showtime
440 if (m_NavigPan && m_Splitter) {
441 m_Splitter -> SetMinimumPaneSize(20);
442 if (m_Cfg.navig_on)
443 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
444 else {
445 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
446 m_Splitter -> Unsplit();
447 }
448 if (m_Cfg.navig_on) {
449 m_NavigPan -> Show(TRUE);
450 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
451 }
452 else {
453 m_NavigPan -> Show(FALSE);
454 m_Splitter -> Initialize(m_HtmlWin);
455 }
456 }
457 return TRUE;
458 }
459
460 wxHtmlHelpFrame::~wxHtmlHelpFrame()
461 {
462 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
463 delete m_ContentsImageList;
464 if (m_DataCreated)
465 delete m_Data;
466 if (m_NormalFonts) delete m_NormalFonts;
467 if (m_FixedFonts) delete m_FixedFonts;
468 if (m_PagesHash) delete m_PagesHash;
469 }
470
471
472 void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar *toolBar, int style)
473 {
474 toolBar -> AddTool(wxID_HTML_PANEL, wxBITMAP(wpanel), wxNullBitmap,
475 FALSE, -1, -1, (wxObject *) NULL,
476 _("Show/hide navigation panel"));
477
478 toolBar -> AddSeparator();
479 toolBar -> AddTool(wxID_HTML_BACK, wxBITMAP(wback), wxNullBitmap,
480 FALSE, -1, -1, (wxObject *) NULL,
481 _("Go back"));
482 toolBar -> AddTool(wxID_HTML_FORWARD, wxBITMAP(wforward), wxNullBitmap,
483 FALSE, -1, -1, (wxObject *) NULL,
484 _("Go forward"));
485 toolBar -> AddSeparator();
486
487 toolBar -> AddTool(wxID_HTML_UPNODE, wxBITMAP(wupnode), wxNullBitmap,
488 FALSE, -1, -1, (wxObject *) NULL,
489 _("Go one level up in document hierarchy"));
490 toolBar -> AddTool(wxID_HTML_UP, wxBITMAP(wup), wxNullBitmap,
491 FALSE, -1, -1, (wxObject *) NULL,
492 _("Previous page"));
493 toolBar -> AddTool(wxID_HTML_DOWN, wxBITMAP(wdown), wxNullBitmap,
494 FALSE, -1, -1, (wxObject *) NULL,
495 _("Next page"));
496
497 if ((style & wxHF_PRINT) || (style & wxHF_OPENFILES))
498 toolBar -> AddSeparator();
499
500 if (style & wxHF_OPENFILES)
501 toolBar -> AddTool(wxID_HTML_OPENFILE, wxBITMAP(wopen), wxNullBitmap,
502 FALSE, -1, -1, (wxObject *) NULL,
503 _("Open HTML document"));
504
505 #if wxUSE_PRINTING_ARCHITECTURE
506 if (style & wxHF_PRINT)
507 toolBar -> AddTool(wxID_HTML_PRINT, wxBITMAP(wprint), wxNullBitmap,
508 FALSE, -1, -1, (wxObject *) NULL,
509 _("Print this page"));
510 #endif
511
512 toolBar -> AddSeparator();
513 toolBar -> AddTool(wxID_HTML_OPTIONS, wxBITMAP(woptions), wxNullBitmap,
514 FALSE, -1, -1, (wxObject *) NULL,
515 _("Display options dialog"));
516 }
517
518
519 void wxHtmlHelpFrame::SetTitleFormat(const wxString& format)
520 {
521 if (m_HtmlWin)
522 m_HtmlWin->SetRelatedFrame(this, format);
523 m_TitleFormat = format;
524 }
525
526
527 bool wxHtmlHelpFrame::Display(const wxString& x)
528 {
529 wxString url = m_Data->FindPageByName(x);
530 if (! url.IsEmpty()) {
531 m_HtmlWin->LoadPage(url);
532 NotifyPageChanged();
533 return TRUE;
534 }
535 return FALSE;
536 }
537
538 bool wxHtmlHelpFrame::Display(const int id)
539 {
540 wxString url = m_Data->FindPageById(id);
541 if (! url.IsEmpty()) {
542 m_HtmlWin->LoadPage(url);
543 NotifyPageChanged();
544 return TRUE;
545 }
546 return FALSE;
547 }
548
549
550
551 bool wxHtmlHelpFrame::DisplayContents()
552 {
553 if (! m_ContentsBox)
554 return FALSE;
555 if (!m_Splitter -> IsSplit()) {
556 m_NavigPan -> Show(TRUE);
557 m_HtmlWin -> Show(TRUE);
558 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
559 m_Cfg.navig_on = TRUE;
560 }
561 m_NavigPan -> SetSelection(0);
562 return TRUE;
563 }
564
565
566
567 bool wxHtmlHelpFrame::DisplayIndex()
568 {
569 if (! m_IndexList)
570 return FALSE;
571 if (!m_Splitter -> IsSplit()) {
572 m_NavigPan -> Show(TRUE);
573 m_HtmlWin -> Show(TRUE);
574 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
575 }
576 m_NavigPan -> SetSelection(1);
577 return TRUE;
578 }
579
580
581
582 bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword)
583 {
584 if (! (m_SearchList && m_SearchButton && m_SearchText && m_SearchChoice))
585 return FALSE;
586
587 int foundcnt = 0, curi;
588 wxString foundstr;
589 wxString book = wxEmptyString;
590
591 if (!m_Splitter -> IsSplit()) {
592 m_NavigPan -> Show(TRUE);
593 m_HtmlWin -> Show(TRUE);
594 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
595 }
596 m_NavigPan -> SetSelection(m_SearchPage);
597 m_SearchList -> Clear();
598 m_SearchText -> SetValue(keyword);
599 m_SearchButton -> Enable(FALSE);
600
601 if (m_SearchChoice->GetSelection() != 0)
602 book = m_SearchChoice->GetStringSelection();
603
604 wxHtmlSearchStatus status(m_Data, keyword,
605 m_SearchCaseSensitive -> GetValue(), m_SearchWholeWords -> GetValue(),
606 book);
607
608 wxProgressDialog progress(_("Searching..."), _("No matching page found yet"),
609 status.GetMaxIndex(), this,
610 wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE);
611
612 while (status.IsActive()) {
613 curi = status.GetCurIndex();
614 if (curi % 32 == 0 && progress.Update(curi) == FALSE)
615 break;
616 if (status.Search()) {
617 foundstr.Printf(_("Found %i matches"), ++foundcnt);
618 progress.Update(status.GetCurIndex(), foundstr);
619 m_SearchList -> Append(status.GetName(), status.GetContentsItem());
620 }
621 }
622
623 m_SearchButton -> Enable(TRUE);
624 m_SearchText -> SetSelection(0, keyword.Length());
625 m_SearchText -> SetFocus();
626 if (foundcnt) {
627 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(0);
628 if (it)
629 {
630 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
631 NotifyPageChanged();
632 }
633 }
634 return (foundcnt > 0);
635 }
636
637 #define MAX_ROOTS 64
638
639 void wxHtmlHelpFrame::CreateContents()
640 {
641 if (! m_ContentsBox)
642 return ;
643
644 m_ContentsBox->Clear();
645
646 if (m_PagesHash) delete m_PagesHash;
647 m_PagesHash = new wxHashTable(wxKEY_STRING, 2 * m_Data -> GetContentsCnt());
648 m_PagesHash -> DeleteContents(TRUE);
649
650 int cnt = m_Data->GetContentsCnt();
651 int i;
652
653 wxHtmlContentsItem *it;
654
655 wxTreeItemId roots[MAX_ROOTS];
656 bool imaged[MAX_ROOTS];
657
658 m_ContentsBox -> DeleteAllItems();
659 roots[0] = m_ContentsBox -> AddRoot(_("(Help)"));
660 m_ContentsBox -> SetItemImage(roots[0], IMG_RootFolder);
661 m_ContentsBox -> SetItemSelectedImage(roots[0], IMG_RootFolder);
662 imaged[0] = TRUE;
663
664 for (it = m_Data->GetContents(), i = 0; i < cnt; i++, it++) {
665 roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem(
666 roots[it -> m_Level], it -> m_Name, IMG_Page, -1,
667 new wxHtmlHelpTreeItemData(i));
668 m_PagesHash -> Put(it -> m_Book -> GetBasePath() + it -> m_Page,
669 new wxHtmlHelpHashData(i, roots[it -> m_Level + 1]));
670
671 if (it -> m_Level == 0) {
672 m_ContentsBox -> SetItemBold(roots[1], TRUE);
673 m_ContentsBox -> SetItemImage(roots[1], IMG_Book);
674 m_ContentsBox -> SetItemSelectedImage(roots[1], IMG_Book);
675 imaged[1] = TRUE;
676 } else imaged[it -> m_Level + 1] = FALSE;
677
678 if (!imaged[it -> m_Level]) {
679 m_ContentsBox -> SetItemImage(roots[it -> m_Level], IMG_Folder);
680 m_ContentsBox -> SetItemSelectedImage(roots[it -> m_Level], IMG_Folder);
681 imaged[it -> m_Level] = TRUE;
682 }
683 }
684 m_ContentsBox -> Expand(roots[0]);
685 }
686
687
688 void wxHtmlHelpFrame::CreateIndex()
689 {
690 if (! m_IndexList)
691 return ;
692
693 m_IndexList->Clear();
694
695 int cnt = m_Data->GetIndexCnt();
696
697 wxString cnttext;
698 if (cnt > INDEX_IS_SMALL) cnttext.Printf(_("%i of %i"), 0, cnt);
699 else cnttext.Printf(_("%i of %i"), cnt, cnt);
700 m_IndexCountInfo -> SetLabel(cnttext);
701 if (cnt > INDEX_IS_SMALL) return;
702
703 wxHtmlContentsItem* index = m_Data->GetIndex();
704
705 for (int i = 0; i < cnt; i++)
706 m_IndexList -> Append(index[i].m_Name, (char*)(index + i));
707 }
708
709 void wxHtmlHelpFrame::CreateSearch()
710 {
711 if (! (m_SearchList && m_SearchChoice))
712 return ;
713 m_SearchList -> Clear();
714 m_SearchChoice -> Clear();
715 m_SearchChoice -> Append(_("Search in all books"));
716 const wxHtmlBookRecArray& bookrec = m_Data->GetBookRecArray();
717 int i, cnt = bookrec.GetCount();
718 for (i = 0; i < cnt; i++)
719 m_SearchChoice->Append(bookrec[i].GetTitle());
720 m_SearchChoice->SetSelection(0);
721 }
722
723
724 void wxHtmlHelpFrame::RefreshLists()
725 {
726 CreateContents();
727 CreateIndex();
728 CreateSearch();
729 }
730
731 void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path)
732 {
733 wxString oldpath;
734 wxString tmp;
735
736 if (path != wxEmptyString) {
737 oldpath = cfg -> GetPath();
738 cfg -> SetPath(_T("/") + path);
739 }
740
741 m_Cfg.navig_on = cfg -> Read(wxT("hcNavigPanel"), m_Cfg.navig_on) != 0;
742 m_Cfg.sashpos = cfg -> Read(wxT("hcSashPos"), m_Cfg.sashpos);
743 m_Cfg.x = cfg -> Read(wxT("hcX"), m_Cfg.x);
744 m_Cfg.y = cfg -> Read(wxT("hcY"), m_Cfg.y);
745 m_Cfg.w = cfg -> Read(wxT("hcW"), m_Cfg.w);
746 m_Cfg.h = cfg -> Read(wxT("hcH"), m_Cfg.h);
747
748 m_FixedFace = cfg -> Read(wxT("hcFixedFace"), m_FixedFace);
749 m_NormalFace = cfg -> Read(wxT("hcNormalFace"), m_NormalFace);
750 m_FontSize = cfg -> Read(wxT("hcFontSize"), m_FontSize);
751
752 {
753 int i;
754 int cnt;
755 wxString val, s;
756
757 cnt = cfg -> Read(wxT("hcBookmarksCnt"), 0L);
758 if (cnt != 0) {
759 m_BookmarksNames.Clear();
760 m_BookmarksPages.Clear();
761 if (m_Bookmarks) {
762 m_Bookmarks -> Clear();
763 m_Bookmarks -> Append(_("(bookmarks)"));
764 }
765
766 for (i = 0; i < cnt; i++) {
767 val.Printf(wxT("hcBookmark_%i"), i);
768 s = cfg -> Read(val);
769 m_BookmarksNames.Add(s);
770 if (m_Bookmarks) m_Bookmarks -> Append(s);
771 val.Printf(wxT("hcBookmark_%i_url"), i);
772 s = cfg -> Read(val);
773 m_BookmarksPages.Add(s);
774 }
775 }
776 }
777
778 if (m_HtmlWin)
779 m_HtmlWin->ReadCustomization(cfg);
780
781 if (path != wxEmptyString)
782 cfg -> SetPath(oldpath);
783 }
784
785 void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path)
786 {
787 wxString oldpath;
788 wxString tmp;
789
790 if (path != wxEmptyString) {
791 oldpath = cfg -> GetPath();
792 cfg -> SetPath(_T("/") + path);
793 }
794
795 cfg -> Write(wxT("hcNavigPanel"), m_Cfg.navig_on);
796 cfg -> Write(wxT("hcSashPos"), (long)m_Cfg.sashpos);
797 cfg -> Write(wxT("hcX"), (long)m_Cfg.x);
798 cfg -> Write(wxT("hcY"), (long)m_Cfg.y);
799 cfg -> Write(wxT("hcW"), (long)m_Cfg.w);
800 cfg -> Write(wxT("hcH"), (long)m_Cfg.h);
801 cfg -> Write(wxT("hcFixedFace"), m_FixedFace);
802 cfg -> Write(wxT("hcNormalFace"), m_NormalFace);
803 cfg -> Write(wxT("hcFontSize"), (long)m_FontSize);
804
805 if (m_Bookmarks) {
806 int i;
807 int cnt = m_BookmarksNames.GetCount();
808 wxString val;
809
810 cfg -> Write(wxT("hcBookmarksCnt"), (long)cnt);
811 for (i = 0; i < cnt; i++) {
812 val.Printf(wxT("hcBookmark_%i"), i);
813 cfg -> Write(val, m_BookmarksNames[i]);
814 val.Printf(wxT("hcBookmark_%i_url"), i);
815 cfg -> Write(val, m_BookmarksPages[i]);
816 }
817 }
818
819 if (m_HtmlWin)
820 m_HtmlWin->WriteCustomization(cfg);
821
822 if (path != wxEmptyString)
823 cfg -> SetPath(oldpath);
824 }
825
826
827
828
829
830 static void SetFontsToHtmlWin(wxHtmlWindow *win, wxString scalf, wxString fixf, int size)
831 {
832 static int f_sizes[5][7] =
833 {
834 { 6, 7, 9, 12, 14, 16, 19},
835 { 8, 9, 12, 14, 16, 19, 22},
836 {10, 12, 14, 16, 19, 24, 32},
837 {14, 16, 18, 24, 32, 38, 45},
838 {16, 20, 24, 32, 38, 45, 50}
839 };
840
841 win -> SetFonts(scalf, fixf, f_sizes[size]);
842 }
843
844
845 class wxHtmlHelpFrameOptionsDialog : public wxDialog
846 {
847 public:
848 wxComboBox *NormalFont, *FixedFont;
849 wxRadioBox *RadioBox;
850 wxHtmlWindow *TestWin;
851
852 wxHtmlHelpFrameOptionsDialog(wxWindow *parent) : wxDialog(parent, -1, wxString(_("Help Browser Options")))
853 {
854 wxString choices[5] = {_("very small"), _("small"), _("medium"), _("large"), _("very large")};
855 wxBoxSizer *topsizer, *sizer, *sizer2;
856
857 topsizer = new wxBoxSizer(wxVERTICAL);
858
859 sizer = new wxBoxSizer(wxHORIZONTAL);
860
861 sizer2 = new wxStaticBoxSizer( new wxStaticBox(this, -1, _("Normal font:")), wxVERTICAL);
862 sizer2 -> Add(NormalFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
863 wxSize(200, 200),
864 0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
865 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
866
867 sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10);
868
869 sizer2 = new wxStaticBoxSizer( new wxStaticBox(this, -1, _("Fixed font:")), wxVERTICAL);
870 sizer2 -> Add(FixedFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
871 wxSize(200, 200),
872 0, NULL, wxCB_DROPDOWN | wxCB_READONLY),
873 1, wxEXPAND | wxLEFT | wxRIGHT, 10);
874
875 sizer -> Add(sizer2, 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10);
876
877 topsizer -> Add(sizer);
878
879 topsizer -> Add(RadioBox = new wxRadioBox(this, -1, _("Font size:"),
880 wxDefaultPosition, wxDefaultSize, 5, choices, 5),
881 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10);
882
883 topsizer -> Add(new wxStaticText(this, -1, _("Preview:")),
884 0, wxLEFT | wxTOP, 10);
885 topsizer -> Add(TestWin = new wxHtmlWindow(this, -1, wxDefaultPosition, wxSize(-1, 150)),
886 1, wxEXPAND | wxLEFT|wxTOP|wxRIGHT, 10);
887
888 sizer = new wxBoxSizer(wxHORIZONTAL);
889 sizer -> Add(new wxButton(this, wxID_OK, _("OK")), 0, wxALL, 10);
890 sizer -> Add(new wxButton(this, wxID_CANCEL, _("Cancel")), 0, wxALL, 10);
891 topsizer -> Add(sizer, 0, wxALIGN_RIGHT);
892
893 SetAutoLayout(TRUE);
894 SetSizer(topsizer);
895 topsizer -> Fit(this);
896 Centre(wxBOTH);
897 }
898
899
900 void UpdateTestWin()
901 {
902 wxBusyCursor bcur;
903 SetFontsToHtmlWin(TestWin,
904 NormalFont -> GetStringSelection(),
905 FixedFont -> GetStringSelection(),
906 RadioBox -> GetSelection());
907 TestWin -> SetPage(_("<html><body>"
908 "Normal face<br>(and <u>underlined</u>. <i>Italic face.</i> "
909 "<b>Bold face.</b> <b><i>Bold italic face.</i></b><br>"
910 "<font size=-2>font size -2</font><br>"
911 "<font size=-1>font size -1</font><br>"
912 "<font size=+0>font size +0</font><br>"
913 "<font size=+1>font size +1</font><br>"
914 "<font size=+2>font size +2</font><br>"
915 "<font size=+3>font size +3</font><br>"
916 "<font size=+4>font size +4</font><br>"
917
918 "<p><tt>Fixed size face.<br> <b>bold</b> <i>italic</i> "
919 "<b><i>bold italic <u>underlined</u></i></b><br>"
920 "<font size=-2>font size -2</font><br>"
921 "<font size=-1>font size -1</font><br>"
922 "<font size=+0>font size +0</font><br>"
923 "<font size=+1>font size +1</font><br>"
924 "<font size=+2>font size +2</font><br>"
925 "<font size=+3>font size +3</font><br>"
926 "<font size=+4>font size +4</font></tt>"
927 "</body></html>"));
928 }
929
930 void OnUpdate(wxCommandEvent& event)
931 {
932 UpdateTestWin();
933 }
934
935 DECLARE_EVENT_TABLE()
936 };
937
938 BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog, wxDialog)
939 EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
940 EVT_RADIOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
941 END_EVENT_TABLE()
942
943
944 void wxHtmlHelpFrame::OptionsDialog()
945 {
946 wxHtmlHelpFrameOptionsDialog dlg(this);
947 unsigned i;
948
949 if (m_NormalFonts == NULL) {
950 wxFontEnumerator enu;
951 enu.EnumerateFacenames();
952 m_NormalFonts = new wxArrayString;
953 *m_NormalFonts = *enu.GetFacenames();
954 m_NormalFonts -> Sort();
955 }
956 if (m_FixedFonts == NULL) {
957 wxFontEnumerator enu;
958 enu.EnumerateFacenames(wxFONTENCODING_SYSTEM, TRUE);
959 m_FixedFonts = new wxArrayString;
960 *m_FixedFonts = *enu.GetFacenames();
961 m_FixedFonts -> Sort();
962 }
963
964 for (i = 0; i < m_NormalFonts -> GetCount(); i++)
965 dlg.NormalFont -> Append((*m_NormalFonts)[i]);
966 for (i = 0; i < m_FixedFonts -> GetCount(); i++)
967 dlg.FixedFont -> Append((*m_FixedFonts)[i]);
968 if (!m_NormalFace.IsEmpty()) dlg.NormalFont -> SetStringSelection(m_NormalFace);
969 else dlg.NormalFont -> SetSelection(0);
970 if (!m_FixedFace.IsEmpty()) dlg.FixedFont -> SetStringSelection(m_FixedFace);
971 else dlg.FixedFont -> SetSelection(0);
972 dlg.RadioBox -> SetSelection(m_FontSize);
973 dlg.UpdateTestWin();
974
975 if (dlg.ShowModal() == wxID_OK) {
976 m_NormalFace = dlg.NormalFont -> GetStringSelection();
977 m_FixedFace = dlg.FixedFont -> GetStringSelection();
978 m_FontSize = dlg.RadioBox -> GetSelection();
979 SetFontsToHtmlWin(m_HtmlWin, m_NormalFace, m_FixedFace, m_FontSize);
980 }
981 }
982
983
984
985 void wxHtmlHelpFrame::NotifyPageChanged()
986 {
987 if (m_UpdateContents && m_PagesHash)
988 {
989 wxString an = m_HtmlWin -> GetOpenedAnchor();
990 wxHtmlHelpHashData *ha;
991 if (an.IsEmpty())
992 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage());
993 else
994 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage() + wxT("#") + an);
995 if (ha)
996 {
997 bool olduc = m_UpdateContents;
998 m_UpdateContents = FALSE;
999 m_ContentsBox -> SelectItem(ha -> m_Id);
1000 m_ContentsBox -> EnsureVisible(ha -> m_Id);
1001 m_UpdateContents = olduc;
1002 }
1003 }
1004 }
1005
1006
1007
1008 /*
1009 EVENT HANDLING :
1010 */
1011
1012
1013 void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event)
1014 {
1015 switch (event.GetId()) {
1016
1017 case wxID_HTML_BACK :
1018 m_HtmlWin -> HistoryBack();
1019 NotifyPageChanged();
1020 break;
1021
1022 case wxID_HTML_FORWARD :
1023 m_HtmlWin -> HistoryForward();
1024 NotifyPageChanged();
1025 break;
1026
1027 case wxID_HTML_UP :
1028 if (m_PagesHash)
1029 {
1030 wxString an = m_HtmlWin -> GetOpenedAnchor();
1031 wxHtmlHelpHashData *ha;
1032 if (an.IsEmpty())
1033 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage());
1034 else
1035 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage() + wxT("#") + an);
1036 if (ha && ha -> m_Index > 0)
1037 {
1038 wxHtmlContentsItem *it = m_Data -> GetContents() + (ha -> m_Index - 1);
1039 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1040 NotifyPageChanged();
1041 }
1042 }
1043 break;
1044
1045 case wxID_HTML_UPNODE :
1046 if (m_PagesHash)
1047 {
1048 wxString an = m_HtmlWin -> GetOpenedAnchor();
1049 wxHtmlHelpHashData *ha;
1050 if (an.IsEmpty())
1051 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage());
1052 else
1053 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(m_HtmlWin -> GetOpenedPage() + wxT("#") + an);
1054 if (ha && ha -> m_Index > 0)
1055 {
1056 int level = m_Data -> GetContents()[ha -> m_Index].m_Level - 1;
1057 wxHtmlContentsItem *it;
1058 int ind = ha -> m_Index - 1;
1059
1060 it = m_Data -> GetContents() + ind;
1061 while (ind >= 0 && it -> m_Level != level) ind--, it--;
1062 if (ind >= 0)
1063 {
1064 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1065 NotifyPageChanged();
1066 }
1067 }
1068 }
1069 break;
1070
1071 case wxID_HTML_DOWN :
1072 if (m_PagesHash)
1073 {
1074 wxString an = m_HtmlWin -> GetOpenedAnchor();
1075 wxString adr;
1076 wxHtmlHelpHashData *ha;
1077
1078 if (an.IsEmpty()) adr = m_HtmlWin -> GetOpenedPage();
1079 else adr = m_HtmlWin -> GetOpenedPage() + wxT("#") + an;
1080
1081 ha = (wxHtmlHelpHashData*) m_PagesHash -> Get(adr);
1082
1083 if (ha && ha -> m_Index < m_Data -> GetContentsCnt() - 1)
1084 {
1085 wxHtmlContentsItem *it = m_Data -> GetContents() + (ha -> m_Index + 1);
1086
1087 while (it -> m_Book -> GetBasePath() + it -> m_Page == adr) it++;
1088 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1089 NotifyPageChanged();
1090 }
1091 }
1092 break;
1093
1094 case wxID_HTML_PANEL :
1095 {
1096 if (! (m_Splitter && m_NavigPan))
1097 return ;
1098 if (m_Splitter -> IsSplit()) {
1099 m_Cfg.sashpos = m_Splitter -> GetSashPosition();
1100 m_Splitter -> Unsplit(m_NavigPan);
1101 m_Cfg.navig_on = FALSE;
1102 } else {
1103 m_NavigPan -> Show(TRUE);
1104 m_HtmlWin -> Show(TRUE);
1105 m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
1106 m_Cfg.navig_on = TRUE;
1107 }
1108 }
1109 break;
1110
1111 case wxID_HTML_OPTIONS :
1112 OptionsDialog();
1113 break;
1114
1115 case wxID_HTML_BOOKMARKSADD :
1116 {
1117 wxString item;
1118 wxString url;
1119
1120 item = m_HtmlWin -> GetOpenedPageTitle();
1121 url = m_HtmlWin -> GetOpenedPage();
1122 if (item == wxEmptyString) item = url.AfterLast(wxT('/'));
1123 if (m_BookmarksPages.Index(url) == wxNOT_FOUND) {
1124 m_Bookmarks -> Append(item);
1125 m_BookmarksNames.Add(item);
1126 m_BookmarksPages.Add(url);
1127 }
1128 }
1129 break;
1130
1131 case wxID_HTML_BOOKMARKSREMOVE :
1132 {
1133 wxString item;
1134 int pos;
1135
1136 item = m_Bookmarks -> GetStringSelection();
1137 pos = m_BookmarksNames.Index(item);
1138 if (pos != wxNOT_FOUND) {
1139 m_BookmarksNames.Remove(pos);
1140 m_BookmarksPages.Remove(pos);
1141 m_Bookmarks -> Delete(m_Bookmarks -> GetSelection());
1142 }
1143 }
1144 break;
1145
1146 #if wxUSE_PRINTING_ARCHITECTURE
1147 case wxID_HTML_PRINT :
1148 {
1149 if (m_Printer == NULL)
1150 m_Printer = new wxHtmlEasyPrinting(_("Help Printing"), this);
1151 if (!m_HtmlWin -> GetOpenedPage())
1152 wxLogWarning(_("Cannot print empty page."));
1153 else
1154 m_Printer -> PrintFile(m_HtmlWin -> GetOpenedPage());
1155 }
1156 break;
1157 #endif
1158
1159 case wxID_HTML_OPENFILE :
1160 {
1161 wxString s = wxFileSelector(_("Open HTML document"), wxEmptyString, wxEmptyString, wxEmptyString,
1162 wxT("HTML files (*.htm)|*.htm|HTML files (*.html)|*.html|"
1163 "Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|"
1164 "HTML Help Project (*.hhp)|*.hhp|"
1165 "All files (*.*)|*"),
1166 wxOPEN | wxFILE_MUST_EXIST, this);
1167 if (!s.IsEmpty())
1168 {
1169 wxString ext = s.Right(4).Lower();
1170 if (ext == _T(".zip") || ext == _T(".htb") || ext == _T(".hhp"))
1171 {
1172 wxBusyCursor bcur;
1173 m_Data -> AddBook(s);
1174 RefreshLists();
1175 }
1176 else
1177 m_HtmlWin -> LoadPage(s);
1178 }
1179 }
1180 break;
1181 }
1182 }
1183
1184
1185
1186 void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent& event)
1187 {
1188 wxHtmlHelpTreeItemData *pg;
1189 wxHtmlContentsItem *it;
1190
1191 pg = (wxHtmlHelpTreeItemData*) m_ContentsBox -> GetItemData(event.GetItem());
1192
1193 if (pg && m_UpdateContents)
1194 {
1195 it = m_Data -> GetContents() + (pg -> m_Id);
1196 m_UpdateContents = FALSE;
1197 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1198 m_UpdateContents = TRUE;
1199 }
1200 }
1201
1202
1203
1204 void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent& WXUNUSED(event))
1205 {
1206 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_IndexList -> GetClientData(m_IndexList -> GetSelection());
1207 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1208 NotifyPageChanged();
1209 }
1210
1211
1212 void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent& event)
1213 {
1214 wxString sr = m_IndexText -> GetLineText(0);
1215 sr.MakeLower();
1216 if (sr == wxEmptyString)
1217 OnIndexAll(event);
1218
1219 else {
1220 wxBusyCursor bcur;
1221 const wxChar *cstr = sr.c_str();
1222 wxChar mybuff[512], *ptr;
1223 bool first = TRUE;
1224
1225 m_IndexList->Clear();
1226 int cnt = m_Data->GetIndexCnt();
1227 wxHtmlContentsItem* index = m_Data->GetIndex();
1228
1229 int displ = 0;
1230 for (int i = 0; i < cnt; i++)
1231 {
1232 wxStrncpy(mybuff, index[i].m_Name, 512);
1233 mybuff[511] = 0;
1234 for (ptr = mybuff; *ptr != 0; ptr++)
1235 if (*ptr >= 'A' && *ptr <= 'Z') *ptr -= 'A' - 'a';
1236 if (wxStrstr(mybuff, cstr) != NULL) {
1237 m_IndexList -> Append(index[i].m_Name, (char*)(index + i));
1238 displ++;
1239 if (first) {
1240 m_HtmlWin -> LoadPage(index[i].m_Book -> GetBasePath() + index[i].m_Page);
1241 NotifyPageChanged();
1242 first = FALSE;
1243 }
1244 }
1245 }
1246
1247 wxString cnttext;
1248 cnttext.Printf(_("%i of %i"), displ, cnt);
1249 m_IndexCountInfo -> SetLabel(cnttext);
1250
1251 m_IndexText -> SetSelection(0, sr.Length());
1252 m_IndexText -> SetFocus();
1253 }
1254 }
1255
1256 void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent& WXUNUSED(event))
1257 {
1258 wxBusyCursor bcur;
1259
1260 m_IndexList->Clear();
1261 int cnt = m_Data->GetIndexCnt();
1262 bool first = TRUE;
1263 wxHtmlContentsItem* index = m_Data->GetIndex();
1264
1265 for (int i = 0; i < cnt; i++) {
1266 m_IndexList -> Append(index[i].m_Name, (char*)(index + i));
1267 if (first) {
1268 m_HtmlWin -> LoadPage(index[i].m_Book -> GetBasePath() + index[i].m_Page);
1269 NotifyPageChanged();
1270 first = FALSE;
1271 }
1272 }
1273
1274 wxString cnttext;
1275 cnttext.Printf(_("%i of %i"), cnt, cnt);
1276 m_IndexCountInfo -> SetLabel(cnttext);
1277 }
1278
1279
1280 void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent& WXUNUSED(event))
1281 {
1282 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList -> GetClientData(m_SearchList -> GetSelection());
1283 if (it)
1284 {
1285 m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page);
1286 NotifyPageChanged();
1287 }
1288 }
1289
1290 void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event))
1291 {
1292 wxString sr = m_SearchText -> GetLineText(0);
1293
1294 if (sr != wxEmptyString) KeywordSearch(sr);
1295 }
1296
1297 void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event))
1298 {
1299 wxString sr = m_Bookmarks -> GetStringSelection();
1300
1301 if (sr != wxEmptyString && sr != _("(bookmarks)"))
1302 {
1303 m_HtmlWin -> LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]);
1304 NotifyPageChanged();
1305 }
1306 }
1307
1308 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
1309 {
1310 GetSize(&m_Cfg.w, &m_Cfg.h);
1311 GetPosition(&m_Cfg.x, &m_Cfg.y);
1312
1313 if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter -> GetSashPosition();
1314
1315 if (m_Config)
1316 WriteCustomization(m_Config, m_ConfigRoot);
1317
1318 if (m_helpController && m_helpController->IsKindOf(CLASSINFO(wxHtmlHelpController)))
1319 {
1320 ((wxHtmlHelpController*) m_helpController)->OnCloseFrame(evt);
1321 }
1322
1323 evt.Skip();
1324 }
1325
1326 BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame)
1327 EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_OPTIONS, wxHtmlHelpFrame::OnToolbar)
1328 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE, wxHtmlHelpFrame::OnToolbar)
1329 EVT_BUTTON(wxID_HTML_BOOKMARKSADD, wxHtmlHelpFrame::OnToolbar)
1330 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpFrame::OnContentsSel)
1331 EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel)
1332 EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel)
1333 EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch)
1334 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpFrame::OnSearch)
1335 EVT_BUTTON(wxID_HTML_INDEXBUTTON, wxHtmlHelpFrame::OnIndexFind)
1336 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT, wxHtmlHelpFrame::OnIndexFind)
1337 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL, wxHtmlHelpFrame::OnIndexAll)
1338 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST, wxHtmlHelpFrame::OnBookmarksSel)
1339 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow)
1340 END_EVENT_TABLE()
1341
1342 #endif