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