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