ReDOS-ified project files
[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 "helpfrm.h"
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 #if wxUSE_WXHTML_HELP
25
26 #ifndef WXPRECOMP
27 #include "wx/intl.h"
28 #include "wx/log.h"
29
30 #include "wx/object.h"
31 #include "wx/sizer.h"
32
33 #include "wx/bmpbuttn.h"
34 #include "wx/statbox.h"
35 #include "wx/radiobox.h"
36 #endif // WXPRECOMP
37
38 #include "wx/html/helpfrm.h"
39 #include "wx/html/helpctrl.h"
40 #include "wx/textctrl.h"
41 #include "wx/notebook.h"
42 #include "wx/imaglist.h"
43 #include "wx/treectrl.h"
44 #include "wx/tokenzr.h"
45 #include "wx/wfstream.h"
46 #include "wx/html/htmlwin.h"
47 #include "wx/busyinfo.h"
48 #include "wx/progdlg.h"
49 #include "wx/toolbar.h"
50 #include "wx/fontenum.h"
51 #include "wx/stream.h"
52 #include "wx/filedlg.h"
53 #include "wx/artprov.h"
54 #include "wx/spinctrl.h"
55
56 // what is considered "small index"?
57 #define INDEX_IS_SMALL 100
58
59 /* Motif defines this as a macro */
60 #ifdef Below
61 #undef Below
62 #endif
63
64 //--------------------------------------------------------------------------
65 // wxHtmlHelpTreeItemData (private)
66 //--------------------------------------------------------------------------
67
68 class wxHtmlHelpTreeItemData : public wxTreeItemData
69 {
70 public:
71 #if defined(__VISAGECPP__)
72 // VA needs a default ctor for some reason....
73 wxHtmlHelpTreeItemData() : wxTreeItemData()
74 { m_Id = 0; }
75 #endif
76 wxHtmlHelpTreeItemData(int id) : wxTreeItemData()
77 { m_Id = id;}
78
79 int m_Id;
80 };
81
82
83 //--------------------------------------------------------------------------
84 // wxHtmlHelpHashData (private)
85 //--------------------------------------------------------------------------
86
87 class wxHtmlHelpHashData : public wxObject
88 {
89 public:
90 wxHtmlHelpHashData(int index, wxTreeItemId id) : wxObject()
91 { m_Index = index; m_Id = id;}
92 ~wxHtmlHelpHashData() {}
93
94 int m_Index;
95 wxTreeItemId m_Id;
96 };
97
98
99 //--------------------------------------------------------------------------
100 // wxHtmlHelpHtmlWindow (private)
101 //--------------------------------------------------------------------------
102
103 class wxHtmlHelpHtmlWindow : public wxHtmlWindow
104 {
105 public:
106 wxHtmlHelpHtmlWindow(wxHtmlHelpFrame *fr, wxWindow *parent) : wxHtmlWindow(parent), m_Frame(fr) {}
107
108 virtual void OnLinkClicked(const wxHtmlLinkInfo& link)
109 {
110 wxHtmlWindow::OnLinkClicked(link);
111 m_Frame->NotifyPageChanged();
112 }
113
114 private:
115 wxHtmlHelpFrame *m_Frame;
116
117 DECLARE_NO_COPY_CLASS(wxHtmlHelpHtmlWindow)
118 };
119
120
121
122 //---------------------------------------------------------------------------
123 // wxHtmlHelpFrame
124 //---------------------------------------------------------------------------
125
126 // Command IDs :
127 enum
128 {
129 //wxID_HTML_HELPFRAME = wxID_HIGHEST + 1,
130 wxID_HTML_PANEL = wxID_HIGHEST + 2,
131 wxID_HTML_BACK,
132 wxID_HTML_FORWARD,
133 wxID_HTML_UPNODE,
134 wxID_HTML_UP,
135 wxID_HTML_DOWN,
136 wxID_HTML_PRINT,
137 wxID_HTML_OPENFILE,
138 wxID_HTML_OPTIONS,
139 wxID_HTML_BOOKMARKSLIST,
140 wxID_HTML_BOOKMARKSADD,
141 wxID_HTML_BOOKMARKSREMOVE,
142 wxID_HTML_TREECTRL,
143 wxID_HTML_INDEXPAGE,
144 wxID_HTML_INDEXLIST,
145 wxID_HTML_INDEXTEXT,
146 wxID_HTML_INDEXBUTTON,
147 wxID_HTML_INDEXBUTTONALL,
148 wxID_HTML_NOTEBOOK,
149 wxID_HTML_SEARCHPAGE,
150 wxID_HTML_SEARCHTEXT,
151 wxID_HTML_SEARCHLIST,
152 wxID_HTML_SEARCHBUTTON,
153 wxID_HTML_SEARCHCHOICE,
154 wxID_HTML_COUNTINFO
155 };
156
157
158 IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpFrame, wxFrame)
159
160 wxHtmlHelpFrame::wxHtmlHelpFrame(wxWindow* parent, wxWindowID id, const wxString& title,
161 int style, wxHtmlHelpData* data)
162 {
163 Init(data);
164 Create(parent, id, title, style);
165 }
166
167 void wxHtmlHelpFrame::Init(wxHtmlHelpData* data)
168 {
169 if (data)
170 {
171 m_Data = data;
172 m_DataCreated = FALSE;
173 } else
174 {
175 m_Data = new wxHtmlHelpData();
176 m_DataCreated = TRUE;
177 }
178
179 m_ContentsBox = NULL;
180 m_IndexList = NULL;
181 m_IndexButton = NULL;
182 m_IndexButtonAll = NULL;
183 m_IndexText = NULL;
184 m_SearchList = NULL;
185 m_SearchButton = NULL;
186 m_SearchText = NULL;
187 m_SearchChoice = NULL;
188 m_IndexCountInfo = NULL;
189 m_Splitter = NULL;
190 m_NavigPan = NULL;
191 m_NavigNotebook = NULL;
192 m_HtmlWin = NULL;
193 m_Bookmarks = NULL;
194 m_SearchCaseSensitive = NULL;
195 m_SearchWholeWords = NULL;
196
197 m_Config = NULL;
198 m_ConfigRoot = wxEmptyString;
199
200 m_Cfg.x = m_Cfg.y = 0;
201 m_Cfg.w = 700;
202 m_Cfg.h = 480;
203 m_Cfg.sashpos = 240;
204 m_Cfg.navig_on = TRUE;
205
206 m_NormalFonts = m_FixedFonts = NULL;
207 m_NormalFace = m_FixedFace = wxEmptyString;
208 #ifdef __WXMSW__
209 m_FontSize = 10;
210 #else
211 m_FontSize = 14;
212 #endif
213
214 #if wxUSE_PRINTING_ARCHITECTURE
215 m_Printer = NULL;
216 #endif
217
218 m_PagesHash = NULL;
219 m_UpdateContents = TRUE;
220 m_helpController = (wxHelpControllerBase*) NULL;
221 }
222
223 // Create: builds the GUI components.
224 // with the style flag it's possible to toggle the toolbar, contents, index and search
225 // controls.
226 // m_HtmlWin will *always* be created, but it's important to realize that
227 // m_ContentsBox, m_IndexList, m_SearchList, m_SearchButton, m_SearchText and
228 // m_SearchButton may be NULL.
229 // moreover, if no contents, index or searchpage is needed, m_Splitter and
230 // m_NavigPan will be NULL too (with m_HtmlWin directly connected to the frame)
231
232 bool wxHtmlHelpFrame::Create(wxWindow* parent, wxWindowID id,
233 const wxString& WXUNUSED(title), int style)
234 {
235 m_hfStyle = style;
236
237 wxImageList *ContentsImageList = new wxImageList(16, 16);
238 ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_BOOK, wxART_HELP_BROWSER));
239 ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_FOLDER, wxART_HELP_BROWSER));
240 ContentsImageList->Add(wxArtProvider::GetIcon(wxART_HELP_PAGE, wxART_HELP_BROWSER));
241
242 // Do the config in two steps. We read the HtmlWindow customization after we
243 // create the window.
244 if (m_Config)
245 ReadCustomization(m_Config, m_ConfigRoot);
246
247 wxFrame::Create(parent, id, _("Help"),
248 wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h),
249 wxDEFAULT_FRAME_STYLE, wxT("wxHtmlHelp"));
250
251 GetPosition(&m_Cfg.x, &m_Cfg.y);
252
253 SetIcon(wxArtProvider::GetIcon(wxART_HELP, wxART_HELP_BROWSER));
254
255 // On the Mac, each modeless frame must have a menubar.
256 // TODO: add more menu items, and perhaps add a style to show
257 // the menubar: compulsory on the Mac, optional elsewhere.
258 #ifdef __WXMAC__
259 wxMenuBar* menuBar = new wxMenuBar;
260
261 wxMenu* fileMenu = new wxMenu;
262 fileMenu->Append(wxID_HTML_OPENFILE, _("&Open..."));
263 fileMenu->Append(wxID_ABOUT, _("&About..."));
264 fileMenu->AppendSeparator();
265 fileMenu->Append(wxID_CLOSE, _("&Close"));
266
267 // wxMenu* helpMenu = new wxMenu;
268 // helpMenu->Append(wxID_ABOUT, _("&About..."));
269
270 menuBar->Append(fileMenu);
271 SetMenuBar(menuBar);
272 #endif
273
274 int notebook_page = 0;
275
276 CreateStatusBar();
277
278 // toolbar?
279 if (style & (wxHF_TOOLBAR | wxHF_FLAT_TOOLBAR))
280 {
281 wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL |
282 wxTB_DOCKABLE |
283 (style & wxHF_FLAT_TOOLBAR ? wxTB_FLAT : 0));
284 toolBar->SetMargins( 2, 2 );
285 AddToolbarButtons(toolBar, style);
286 toolBar->Realize();
287 }
288
289 wxSizer *navigSizer = NULL;
290
291 if (style & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH))
292 {
293 // traditional help controller; splitter window with html page on the
294 // right and a notebook containing various pages on the left
295 m_Splitter = new wxSplitterWindow(this);
296
297 m_HtmlWin = new wxHtmlHelpHtmlWindow(this, m_Splitter);
298 m_NavigPan = new wxPanel(m_Splitter, -1);
299 m_NavigNotebook = new wxNotebook(m_NavigPan, wxID_HTML_NOTEBOOK,
300 wxDefaultPosition, wxDefaultSize);
301 wxNotebookSizer *nbs = new wxNotebookSizer(m_NavigNotebook);
302
303 navigSizer = new wxBoxSizer(wxVERTICAL);
304 navigSizer->Add(nbs, 1, wxEXPAND);
305
306 m_NavigPan->SetAutoLayout(TRUE);
307 m_NavigPan->SetSizer(navigSizer);
308 }
309 else
310 { // only html window, no notebook with index,contents etc
311 m_HtmlWin = new wxHtmlWindow(this);
312 }
313
314 m_HtmlWin->SetRelatedFrame(this, m_TitleFormat);
315 m_HtmlWin->SetRelatedStatusBar(0);
316 if ( m_Config )
317 m_HtmlWin->ReadCustomization(m_Config, m_ConfigRoot);
318
319 // contents tree panel?
320 if ( style & wxHF_CONTENTS )
321 {
322 wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE);
323 wxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
324
325 topsizer->Add(0, 10);
326
327 dummy->SetAutoLayout(TRUE);
328 dummy->SetSizer(topsizer);
329
330 if ( style & wxHF_BOOKMARKS )
331 {
332 m_Bookmarks = new wxComboBox(dummy, wxID_HTML_BOOKMARKSLIST,
333 wxEmptyString,
334 wxDefaultPosition, wxDefaultSize,
335 0, NULL, wxCB_READONLY | wxCB_SORT);
336 m_Bookmarks->Append(_("(bookmarks)"));
337 for (unsigned i = 0; i < m_BookmarksNames.GetCount(); i++)
338 m_Bookmarks->Append(m_BookmarksNames[i]);
339 m_Bookmarks->SetSelection(0);
340
341 wxBitmapButton *bmpbt1, *bmpbt2;
342 bmpbt1 = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSADD,
343 wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK,
344 wxART_HELP_BROWSER));
345 bmpbt2 = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSREMOVE,
346 wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK,
347 wxART_HELP_BROWSER));
348 #if wxUSE_TOOLTIPS
349 bmpbt1->SetToolTip(_("Add current page to bookmarks"));
350 bmpbt2->SetToolTip(_("Remove current page from bookmarks"));
351 #endif // wxUSE_TOOLTIPS
352
353 wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
354
355 sizer->Add(m_Bookmarks, 1, wxALIGN_CENTRE_VERTICAL | wxRIGHT, 5);
356 sizer->Add(bmpbt1, 0, wxALIGN_CENTRE_VERTICAL | wxRIGHT, 2);
357 sizer->Add(bmpbt2, 0, wxALIGN_CENTRE_VERTICAL, 0);
358
359 topsizer->Add(sizer, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, 10);
360 }
361
362 m_ContentsBox = new wxTreeCtrl(dummy, wxID_HTML_TREECTRL,
363 wxDefaultPosition, wxDefaultSize,
364 wxSUNKEN_BORDER |
365 wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT |
366 wxTR_LINES_AT_ROOT);
367
368 m_ContentsBox->AssignImageList(ContentsImageList);
369
370 topsizer->Add(m_ContentsBox, 1, wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, 2);
371
372 m_NavigNotebook->AddPage(dummy, _("Contents"));
373 m_ContentsPage = notebook_page++;
374 }
375
376 // index listbox panel?
377 if ( style & wxHF_INDEX )
378 {
379 wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE);
380 wxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
381
382 dummy->SetAutoLayout(TRUE);
383 dummy->SetSizer(topsizer);
384
385 m_IndexText = new wxTextCtrl(dummy, wxID_HTML_INDEXTEXT, wxEmptyString,
386 wxDefaultPosition, wxDefaultSize,
387 wxTE_PROCESS_ENTER);
388 m_IndexButton = new wxButton(dummy, wxID_HTML_INDEXBUTTON, _("Find"));
389 m_IndexButtonAll = new wxButton(dummy, wxID_HTML_INDEXBUTTONALL,
390 _("Show all"));
391 m_IndexCountInfo = new wxStaticText(dummy, wxID_HTML_COUNTINFO,
392 wxEmptyString, wxDefaultPosition,
393 wxDefaultSize,
394 wxALIGN_RIGHT | wxST_NO_AUTORESIZE);
395 m_IndexList = new wxListBox(dummy, wxID_HTML_INDEXLIST,
396 wxDefaultPosition, wxDefaultSize,
397 0, NULL, wxLB_SINGLE);
398
399 #if wxUSE_TOOLTIPS
400 m_IndexButton->SetToolTip(_("Display all index items that contain given substring. Search is case insensitive."));
401 m_IndexButtonAll->SetToolTip(_("Show all items in index"));
402 #endif //wxUSE_TOOLTIPS
403
404 topsizer->Add(m_IndexText, 0, wxEXPAND | wxALL, 10);
405 wxSizer *btsizer = new wxBoxSizer(wxHORIZONTAL);
406 btsizer->Add(m_IndexButton, 0, wxRIGHT, 2);
407 btsizer->Add(m_IndexButtonAll);
408 topsizer->Add(btsizer, 0,
409 wxALIGN_RIGHT | wxLEFT | wxRIGHT | wxBOTTOM, 10);
410 topsizer->Add(m_IndexCountInfo, 0, wxEXPAND | wxLEFT | wxRIGHT, 2);
411 topsizer->Add(m_IndexList, 1, wxEXPAND | wxALL, 2);
412
413 m_NavigNotebook->AddPage(dummy, _("Index"));
414 m_IndexPage = notebook_page++;
415 }
416
417 // search list panel?
418 if ( style & wxHF_SEARCH )
419 {
420 wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE);
421 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
422
423 dummy->SetAutoLayout(TRUE);
424 dummy->SetSizer(sizer);
425
426 m_SearchText = new wxTextCtrl(dummy, wxID_HTML_SEARCHTEXT,
427 wxEmptyString,
428 wxDefaultPosition, wxDefaultSize,
429 wxTE_PROCESS_ENTER);
430 m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE,
431 wxDefaultPosition, wxDefaultSize);
432 m_SearchCaseSensitive = new wxCheckBox(dummy, -1, _("Case sensitive"));
433 m_SearchWholeWords = new wxCheckBox(dummy, -1, _("Whole words only"));
434 m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search"));
435 #if wxUSE_TOOLTIPS
436 m_SearchButton->SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above"));
437 #endif //wxUSE_TOOLTIPS
438 m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST,
439 wxDefaultPosition, wxDefaultSize,
440 0, NULL, wxLB_SINGLE);
441
442 sizer->Add(m_SearchText, 0, wxEXPAND | wxALL, 10);
443 sizer->Add(m_SearchChoice, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
444 sizer->Add(m_SearchCaseSensitive, 0, wxLEFT | wxRIGHT, 10);
445 sizer->Add(m_SearchWholeWords, 0, wxLEFT | wxRIGHT, 10);
446 sizer->Add(m_SearchButton, 0, wxALL | wxALIGN_RIGHT, 8);
447 sizer->Add(m_SearchList, 1, wxALL | wxEXPAND, 2);
448
449 m_NavigNotebook->AddPage(dummy, _("Search"));
450 m_SearchPage = notebook_page++;
451 }
452
453 m_HtmlWin->Show(TRUE);
454
455 RefreshLists();
456
457 if ( navigSizer )
458 {
459 navigSizer->SetSizeHints(m_NavigPan);
460 m_NavigPan->Layout();
461 }
462
463 // showtime
464 if ( m_NavigPan && m_Splitter )
465 {
466 m_Splitter->SetMinimumPaneSize(20);
467 if ( m_Cfg.navig_on )
468 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
469
470 if ( m_Cfg.navig_on )
471 {
472 m_NavigPan->Show(TRUE);
473 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
474 }
475 else
476 {
477 m_NavigPan->Show(FALSE);
478 m_Splitter->Initialize(m_HtmlWin);
479 }
480 }
481
482 return TRUE;
483 }
484
485 wxHtmlHelpFrame::~wxHtmlHelpFrame()
486 {
487 // PopEventHandler(); // wxhtmlhelpcontroller (not any more!)
488 if (m_DataCreated)
489 delete m_Data;
490 if (m_NormalFonts) delete m_NormalFonts;
491 if (m_FixedFonts) delete m_FixedFonts;
492 if (m_PagesHash) delete m_PagesHash;
493 }
494
495
496 void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar *toolBar, int style)
497 {
498 wxBitmap wpanelBitmap =
499 wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL, wxART_HELP_BROWSER);
500 wxBitmap wbackBitmap =
501 wxArtProvider::GetBitmap(wxART_GO_BACK, wxART_HELP_BROWSER);
502 wxBitmap wforwardBitmap =
503 wxArtProvider::GetBitmap(wxART_GO_FORWARD, wxART_HELP_BROWSER);
504 wxBitmap wupnodeBitmap =
505 wxArtProvider::GetBitmap(wxART_GO_TO_PARENT, wxART_HELP_BROWSER);
506 wxBitmap wupBitmap =
507 wxArtProvider::GetBitmap(wxART_GO_UP, wxART_HELP_BROWSER);
508 wxBitmap wdownBitmap =
509 wxArtProvider::GetBitmap(wxART_GO_DOWN, wxART_HELP_BROWSER);
510 wxBitmap wopenBitmap =
511 wxArtProvider::GetBitmap(wxART_FILE_OPEN, wxART_HELP_BROWSER);
512 wxBitmap wprintBitmap =
513 wxArtProvider::GetBitmap(wxART_PRINT, wxART_HELP_BROWSER);
514 wxBitmap woptionsBitmap =
515 wxArtProvider::GetBitmap(wxART_HELP_SETTINGS, wxART_HELP_BROWSER);
516
517 wxASSERT_MSG( (wpanelBitmap.Ok() && wbackBitmap.Ok() &&
518 wforwardBitmap.Ok() && wupnodeBitmap.Ok() &&
519 wupBitmap.Ok() && wdownBitmap.Ok() &&
520 wopenBitmap.Ok() && wprintBitmap.Ok() &&
521 woptionsBitmap.Ok()),
522 wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ;
523
524
525 toolBar->AddTool(wxID_HTML_PANEL, wpanelBitmap, wxNullBitmap,
526 FALSE, -1, -1, (wxObject *) NULL,
527 _("Show/hide navigation panel"));
528
529 toolBar->AddSeparator();
530 toolBar->AddTool(wxID_HTML_BACK, wbackBitmap, wxNullBitmap,
531 FALSE, -1, -1, (wxObject *) NULL,
532 _("Go back"));
533 toolBar->AddTool(wxID_HTML_FORWARD, wforwardBitmap, wxNullBitmap,
534 FALSE, -1, -1, (wxObject *) NULL,
535 _("Go forward"));
536 toolBar->AddSeparator();
537
538 toolBar->AddTool(wxID_HTML_UPNODE, wupnodeBitmap, wxNullBitmap,
539 FALSE, -1, -1, (wxObject *) NULL,
540 _("Go one level up in document hierarchy"));
541 toolBar->AddTool(wxID_HTML_UP, wupBitmap, wxNullBitmap,
542 FALSE, -1, -1, (wxObject *) NULL,
543 _("Previous page"));
544 toolBar->AddTool(wxID_HTML_DOWN, wdownBitmap, wxNullBitmap,
545 FALSE, -1, -1, (wxObject *) NULL,
546 _("Next page"));
547
548 if ((style & wxHF_PRINT) || (style & wxHF_OPEN_FILES))
549 toolBar->AddSeparator();
550
551 if (style & wxHF_OPEN_FILES)
552 toolBar->AddTool(wxID_HTML_OPENFILE, wopenBitmap, wxNullBitmap,
553 FALSE, -1, -1, (wxObject *) NULL,
554 _("Open HTML document"));
555
556 #if wxUSE_PRINTING_ARCHITECTURE
557 if (style & wxHF_PRINT)
558 toolBar->AddTool(wxID_HTML_PRINT, wprintBitmap, wxNullBitmap,
559 FALSE, -1, -1, (wxObject *) NULL,
560 _("Print this page"));
561 #endif
562
563 toolBar->AddSeparator();
564 toolBar->AddTool(wxID_HTML_OPTIONS, woptionsBitmap, wxNullBitmap,
565 FALSE, -1, -1, (wxObject *) NULL,
566 _("Display options dialog"));
567 }
568
569
570 void wxHtmlHelpFrame::SetTitleFormat(const wxString& format)
571 {
572 if (m_HtmlWin)
573 m_HtmlWin->SetRelatedFrame(this, format);
574 m_TitleFormat = format;
575 }
576
577
578 bool wxHtmlHelpFrame::Display(const wxString& x)
579 {
580 wxString url = m_Data->FindPageByName(x);
581 if (!url.IsEmpty())
582 {
583 m_HtmlWin->LoadPage(url);
584 NotifyPageChanged();
585 return TRUE;
586 }
587 return FALSE;
588 }
589
590 bool wxHtmlHelpFrame::Display(const int id)
591 {
592 wxString url = m_Data->FindPageById(id);
593 if (!url.IsEmpty())
594 {
595 m_HtmlWin->LoadPage(url);
596 NotifyPageChanged();
597 return TRUE;
598 }
599 return FALSE;
600 }
601
602
603
604 bool wxHtmlHelpFrame::DisplayContents()
605 {
606 if (! m_ContentsBox)
607 return FALSE;
608 if (!m_Splitter->IsSplit())
609 {
610 m_NavigPan->Show(TRUE);
611 m_HtmlWin->Show(TRUE);
612 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
613 m_Cfg.navig_on = TRUE;
614 }
615 m_NavigNotebook->SetSelection(0);
616 if (m_Data->GetBookRecArray().GetCount() > 0)
617 {
618 wxHtmlBookRecord& book = m_Data->GetBookRecArray()[0];
619 if (!book.GetStart().IsEmpty())
620 m_HtmlWin->LoadPage(book.GetFullPath(book.GetStart()));
621 }
622 return TRUE;
623 }
624
625
626
627 bool wxHtmlHelpFrame::DisplayIndex()
628 {
629 if (! m_IndexList)
630 return FALSE;
631 if (!m_Splitter->IsSplit())
632 {
633 m_NavigPan->Show(TRUE);
634 m_HtmlWin->Show(TRUE);
635 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
636 }
637 m_NavigNotebook->SetSelection(1);
638 if (m_Data->GetBookRecArray().GetCount() > 0)
639 {
640 wxHtmlBookRecord& book = m_Data->GetBookRecArray()[0];
641 if (!book.GetStart().IsEmpty())
642 m_HtmlWin->LoadPage(book.GetFullPath(book.GetStart()));
643 }
644 return TRUE;
645 }
646
647
648
649 bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword)
650 {
651 if (! (m_SearchList && m_SearchButton && m_SearchText && m_SearchChoice))
652 return FALSE;
653
654 int foundcnt = 0, curi;
655 wxString foundstr;
656 wxString book = wxEmptyString;
657
658 if (!m_Splitter->IsSplit())
659 {
660 m_NavigPan->Show(TRUE);
661 m_HtmlWin->Show(TRUE);
662 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
663 }
664 m_NavigNotebook->SetSelection(m_SearchPage);
665 m_SearchList->Clear();
666 m_SearchText->SetValue(keyword);
667 m_SearchButton->Enable(FALSE);
668
669 if (m_SearchChoice->GetSelection() != 0)
670 book = m_SearchChoice->GetStringSelection();
671
672 wxHtmlSearchStatus status(m_Data, keyword,
673 m_SearchCaseSensitive->GetValue(), m_SearchWholeWords->GetValue(),
674 book);
675
676 wxProgressDialog progress(_("Searching..."), _("No matching page found yet"),
677 status.GetMaxIndex(), this,
678 wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE);
679
680 while (status.IsActive())
681 {
682 curi = status.GetCurIndex();
683 if (curi % 32 == 0 && progress.Update(curi) == FALSE)
684 break;
685 if (status.Search())
686 {
687 foundstr.Printf(_("Found %i matches"), ++foundcnt);
688 progress.Update(status.GetCurIndex(), foundstr);
689 m_SearchList->Append(status.GetName(), status.GetContentsItem());
690 }
691 }
692
693 m_SearchButton->Enable(TRUE);
694 m_SearchText->SetSelection(0, keyword.Length());
695 m_SearchText->SetFocus();
696 if (foundcnt)
697 {
698 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList->GetClientData(0);
699 if (it)
700 {
701 m_HtmlWin->LoadPage(it->GetFullPath());
702 NotifyPageChanged();
703 }
704 }
705 return (foundcnt > 0);
706 }
707
708 void wxHtmlHelpFrame::CreateContents()
709 {
710 if (! m_ContentsBox)
711 return ;
712
713 m_ContentsBox->Clear();
714
715 if (m_PagesHash) delete m_PagesHash;
716 m_PagesHash = new wxHashTable(wxKEY_STRING, 2 * m_Data->GetContentsCnt());
717 m_PagesHash->DeleteContents(TRUE);
718
719 int cnt = m_Data->GetContentsCnt();
720 int i;
721
722 wxHtmlContentsItem *it;
723
724 const int MAX_ROOTS = 64;
725 wxTreeItemId roots[MAX_ROOTS];
726 // VS: this array holds information about whether we've set item icon at
727 // given level. This is neccessary because m_Data has flat structure
728 // and there's no way of recognizing if some item has subitems or not.
729 // We set the icon later: when we find an item with level=n, we know
730 // that the last item with level=n-1 was folder with subitems, so we
731 // set its icon accordingly
732 bool imaged[MAX_ROOTS];
733 m_ContentsBox->DeleteAllItems();
734
735 roots[0] = m_ContentsBox->AddRoot(_("(Help)"));
736 imaged[0] = TRUE;
737
738 for (it = m_Data->GetContents(), i = 0; i < cnt; i++, it++)
739 {
740 // Handle books:
741 if (it->m_Level == 0)
742 {
743 if (m_hfStyle & wxHF_MERGE_BOOKS)
744 // VS: we don't want book nodes, books' content should
745 // appear under tree's root. This line will create "fake"
746 // record about book node so that the rest of this look
747 // will believe there really _is_ book node and will
748 // behave correctly.
749 roots[1] = roots[0];
750 else
751 {
752 roots[1] = m_ContentsBox->AppendItem(roots[0],
753 it->m_Name, IMG_Book, -1,
754 new wxHtmlHelpTreeItemData(i));
755 m_ContentsBox->SetItemBold(roots[1], TRUE);
756 }
757 imaged[1] = TRUE;
758 }
759 // ...and their contents:
760 else
761 {
762 roots[it->m_Level + 1] = m_ContentsBox->AppendItem(
763 roots[it->m_Level], it->m_Name, IMG_Page,
764 -1, new wxHtmlHelpTreeItemData(i));
765 imaged[it->m_Level + 1] = FALSE;
766 }
767
768 m_PagesHash->Put(it->GetFullPath(),
769 new wxHtmlHelpHashData(i, roots[it->m_Level + 1]));
770
771 // Set the icon for the node one level up in the hiearachy,
772 // unless already done (see comment above imaged[] declaration)
773 if (!imaged[it->m_Level])
774 {
775 int image = IMG_Folder;
776 if (m_hfStyle & wxHF_ICONS_BOOK)
777 image = IMG_Book;
778 else if (m_hfStyle & wxHF_ICONS_BOOK_CHAPTER)
779 image = (it->m_Level == 1) ? IMG_Book : IMG_Folder;
780 m_ContentsBox->SetItemImage(roots[it->m_Level], image);
781 m_ContentsBox->SetItemSelectedImage(roots[it->m_Level], image);
782 imaged[it->m_Level] = TRUE;
783 }
784 }
785 }
786
787
788 void wxHtmlHelpFrame::CreateIndex()
789 {
790 if (! m_IndexList)
791 return ;
792
793 m_IndexList->Clear();
794
795 int cnt = m_Data->GetIndexCnt();
796
797 wxString cnttext;
798 if (cnt > INDEX_IS_SMALL) cnttext.Printf(_("%i of %i"), 0, cnt);
799 else cnttext.Printf(_("%i of %i"), cnt, cnt);
800 m_IndexCountInfo->SetLabel(cnttext);
801 if (cnt > INDEX_IS_SMALL) return;
802
803 wxHtmlContentsItem* index = m_Data->GetIndex();
804
805 for (int i = 0; i < cnt; i++)
806 m_IndexList->Append(index[i].m_Name, (char*)(index + i));
807 }
808
809 void wxHtmlHelpFrame::CreateSearch()
810 {
811 if (! (m_SearchList && m_SearchChoice))
812 return ;
813 m_SearchList->Clear();
814 m_SearchChoice->Clear();
815 m_SearchChoice->Append(_("Search in all books"));
816 const wxHtmlBookRecArray& bookrec = m_Data->GetBookRecArray();
817 int i, cnt = bookrec.GetCount();
818 for (i = 0; i < cnt; i++)
819 m_SearchChoice->Append(bookrec[i].GetTitle());
820 m_SearchChoice->SetSelection(0);
821 }
822
823
824 void wxHtmlHelpFrame::RefreshLists()
825 {
826 CreateContents();
827 CreateIndex();
828 CreateSearch();
829 }
830
831 void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path)
832 {
833 wxString oldpath;
834 wxString tmp;
835
836 if (path != wxEmptyString)
837 {
838 oldpath = cfg->GetPath();
839 cfg->SetPath(_T("/") + path);
840 }
841
842 m_Cfg.navig_on = cfg->Read(wxT("hcNavigPanel"), m_Cfg.navig_on) != 0;
843 m_Cfg.sashpos = cfg->Read(wxT("hcSashPos"), m_Cfg.sashpos);
844 m_Cfg.x = cfg->Read(wxT("hcX"), m_Cfg.x);
845 m_Cfg.y = cfg->Read(wxT("hcY"), m_Cfg.y);
846 m_Cfg.w = cfg->Read(wxT("hcW"), m_Cfg.w);
847 m_Cfg.h = cfg->Read(wxT("hcH"), m_Cfg.h);
848
849 m_FixedFace = cfg->Read(wxT("hcFixedFace"), m_FixedFace);
850 m_NormalFace = cfg->Read(wxT("hcNormalFace"), m_NormalFace);
851 m_FontSize = cfg->Read(wxT("hcBaseFontSize"), m_FontSize);
852
853 {
854 int i;
855 int cnt;
856 wxString val, s;
857
858 cnt = cfg->Read(wxT("hcBookmarksCnt"), 0L);
859 if (cnt != 0)
860 {
861 m_BookmarksNames.Clear();
862 m_BookmarksPages.Clear();
863 if (m_Bookmarks)
864 {
865 m_Bookmarks->Clear();
866 m_Bookmarks->Append(_("(bookmarks)"));
867 }
868
869 for (i = 0; i < cnt; i++)
870 {
871 val.Printf(wxT("hcBookmark_%i"), i);
872 s = cfg->Read(val);
873 m_BookmarksNames.Add(s);
874 if (m_Bookmarks) m_Bookmarks->Append(s);
875 val.Printf(wxT("hcBookmark_%i_url"), i);
876 s = cfg->Read(val);
877 m_BookmarksPages.Add(s);
878 }
879 }
880 }
881
882 if (m_HtmlWin)
883 m_HtmlWin->ReadCustomization(cfg);
884
885 if (path != wxEmptyString)
886 cfg->SetPath(oldpath);
887 }
888
889 void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path)
890 {
891 wxString oldpath;
892 wxString tmp;
893
894 if (path != wxEmptyString)
895 {
896 oldpath = cfg->GetPath();
897 cfg->SetPath(_T("/") + path);
898 }
899
900 cfg->Write(wxT("hcNavigPanel"), m_Cfg.navig_on);
901 cfg->Write(wxT("hcSashPos"), (long)m_Cfg.sashpos);
902 if ( !IsIconized() )
903 {
904 // Don't write if iconized as this would make the window
905 // disappear next time it is shown!
906 cfg->Write(wxT("hcX"), (long)m_Cfg.x);
907 cfg->Write(wxT("hcY"), (long)m_Cfg.y);
908 cfg->Write(wxT("hcW"), (long)m_Cfg.w);
909 cfg->Write(wxT("hcH"), (long)m_Cfg.h);
910 }
911 cfg->Write(wxT("hcFixedFace"), m_FixedFace);
912 cfg->Write(wxT("hcNormalFace"), m_NormalFace);
913 cfg->Write(wxT("hcBaseFontSize"), (long)m_FontSize);
914
915 if (m_Bookmarks)
916 {
917 int i;
918 int cnt = m_BookmarksNames.GetCount();
919 wxString val;
920
921 cfg->Write(wxT("hcBookmarksCnt"), (long)cnt);
922 for (i = 0; i < cnt; i++)
923 {
924 val.Printf(wxT("hcBookmark_%i"), i);
925 cfg->Write(val, m_BookmarksNames[i]);
926 val.Printf(wxT("hcBookmark_%i_url"), i);
927 cfg->Write(val, m_BookmarksPages[i]);
928 }
929 }
930
931 if (m_HtmlWin)
932 m_HtmlWin->WriteCustomization(cfg);
933
934 if (path != wxEmptyString)
935 cfg->SetPath(oldpath);
936 }
937
938
939
940
941
942 static void SetFontsToHtmlWin(wxHtmlWindow *win, wxString scalf, wxString fixf, int size)
943 {
944 int f_sizes[7];
945 f_sizes[0] = int(size * 0.6);
946 f_sizes[1] = int(size * 0.8);
947 f_sizes[2] = size;
948 f_sizes[3] = int(size * 1.2);
949 f_sizes[4] = int(size * 1.4);
950 f_sizes[5] = int(size * 1.6);
951 f_sizes[6] = int(size * 1.8);
952
953 win->SetFonts(scalf, fixf, f_sizes);
954 }
955
956
957 class wxHtmlHelpFrameOptionsDialog : public wxDialog
958 {
959 public:
960 wxComboBox *NormalFont, *FixedFont;
961 wxSpinCtrl *FontSize;
962 wxHtmlWindow *TestWin;
963
964 wxHtmlHelpFrameOptionsDialog(wxWindow *parent)
965 : wxDialog(parent, -1, wxString(_("Help Browser Options")))
966 {
967 wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
968 wxFlexGridSizer *sizer = new wxFlexGridSizer(2, 3, 2, 5);
969
970 sizer->Add(new wxStaticText(this, -1, _("Normal font:")));
971 sizer->Add(new wxStaticText(this, -1, _("Fixed font:")));
972 sizer->Add(new wxStaticText(this, -1, _("Font size:")));
973
974 sizer->Add(NormalFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
975 wxSize(200, 200),
976 0, NULL, wxCB_DROPDOWN | wxCB_READONLY));
977
978 sizer->Add(FixedFont = new wxComboBox(this, -1, wxEmptyString, wxDefaultPosition,
979 wxSize(200, 200),
980 0, NULL, wxCB_DROPDOWN | wxCB_READONLY));
981
982 sizer->Add(FontSize = new wxSpinCtrl(this, -1));
983 FontSize->SetRange(2, 100);
984
985 topsizer->Add(sizer, 0, wxLEFT|wxRIGHT|wxTOP, 10);
986
987 topsizer->Add(new wxStaticText(this, -1, _("Preview:")),
988 0, wxLEFT | wxTOP, 10);
989 topsizer->Add(TestWin = new wxHtmlWindow(this, -1, wxDefaultPosition, wxSize(20, 150),
990 wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER),
991 1, wxEXPAND | wxLEFT|wxTOP|wxRIGHT, 10);
992
993 wxBoxSizer *sizer2 = new wxBoxSizer(wxHORIZONTAL);
994 wxButton *ok;
995 sizer2->Add(ok = new wxButton(this, wxID_OK, _("OK")), 0, wxALL, 10);
996 ok->SetDefault();
997 sizer2->Add(new wxButton(this, wxID_CANCEL, _("Cancel")), 0, wxALL, 10);
998 topsizer->Add(sizer2, 0, wxALIGN_RIGHT);
999
1000 SetAutoLayout(TRUE);
1001 SetSizer(topsizer);
1002 topsizer->Fit(this);
1003 Centre(wxBOTH);
1004 }
1005
1006
1007 void UpdateTestWin()
1008 {
1009 wxBusyCursor bcur;
1010 SetFontsToHtmlWin(TestWin,
1011 NormalFont->GetStringSelection(),
1012 FixedFont->GetStringSelection(),
1013 FontSize->GetValue());
1014 TestWin->SetPage(_(
1015 "<html><body>\
1016 <table><tr><td>\
1017 Normal face<br>(and <u>underlined</u>. <i>Italic face.</i> \
1018 <b>Bold face.</b> <b><i>Bold italic face.</i></b><br>\
1019 <font size=-2>font size -2</font><br>\
1020 <font size=-1>font size -1</font><br>\
1021 <font size=+0>font size +0</font><br>\
1022 <font size=+1>font size +1</font><br>\
1023 <font size=+2>font size +2</font><br>\
1024 <font size=+3>font size +3</font><br>\
1025 <font size=+4>font size +4</font><br>\
1026 <td>\
1027 <p><tt>Fixed size face.<br> <b>bold</b> <i>italic</i> \
1028 <b><i>bold italic <u>underlined</u></i></b><br>\
1029 <font size=-2>font size -2</font><br>\
1030 <font size=-1>font size -1</font><br>\
1031 <font size=+0>font size +0</font><br>\
1032 <font size=+1>font size +1</font><br>\
1033 <font size=+2>font size +2</font><br>\
1034 <font size=+3>font size +3</font><br>\
1035 <font size=+4>font size +4</font></tt>\
1036 </table></body></html>"
1037 ));
1038 }
1039
1040 void OnUpdate(wxCommandEvent& WXUNUSED(event))
1041 {
1042 UpdateTestWin();
1043 }
1044 void OnUpdateSpin(wxSpinEvent& WXUNUSED(event))
1045 {
1046 UpdateTestWin();
1047 }
1048
1049 DECLARE_EVENT_TABLE()
1050 DECLARE_NO_COPY_CLASS(wxHtmlHelpFrameOptionsDialog)
1051 };
1052
1053 BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog, wxDialog)
1054 EVT_COMBOBOX(-1, wxHtmlHelpFrameOptionsDialog::OnUpdate)
1055 EVT_SPINCTRL(-1, wxHtmlHelpFrameOptionsDialog::OnUpdateSpin)
1056 END_EVENT_TABLE()
1057
1058
1059 void wxHtmlHelpFrame::OptionsDialog()
1060 {
1061 wxHtmlHelpFrameOptionsDialog dlg(this);
1062 unsigned i;
1063
1064 if (m_NormalFonts == NULL)
1065 {
1066 wxFontEnumerator enu;
1067 enu.EnumerateFacenames();
1068 m_NormalFonts = new wxArrayString;
1069 *m_NormalFonts = *enu.GetFacenames();
1070 m_NormalFonts->Sort();
1071 }
1072 if (m_FixedFonts == NULL)
1073 {
1074 wxFontEnumerator enu;
1075 enu.EnumerateFacenames(wxFONTENCODING_SYSTEM, TRUE);
1076 m_FixedFonts = new wxArrayString;
1077 *m_FixedFonts = *enu.GetFacenames();
1078 m_FixedFonts->Sort();
1079 }
1080
1081 // VS: We want to show the font that is actually used by wxHtmlWindow.
1082 // If customization dialog wasn't used yet, facenames are empty and
1083 // wxHtmlWindow uses default fonts -- let's find out what they
1084 // are so that we can pass them to the dialog:
1085 if (m_NormalFace.empty())
1086 {
1087 wxFont fnt(m_FontSize, wxSWISS, wxNORMAL, wxNORMAL, FALSE);
1088 m_NormalFace = fnt.GetFaceName();
1089 }
1090 if (m_FixedFace.empty())
1091 {
1092 wxFont fnt(m_FontSize, wxMODERN, wxNORMAL, wxNORMAL, FALSE);
1093 m_FixedFace = fnt.GetFaceName();
1094 }
1095
1096 for (i = 0; i < m_NormalFonts->GetCount(); i++)
1097 dlg.NormalFont->Append((*m_NormalFonts)[i]);
1098 for (i = 0; i < m_FixedFonts->GetCount(); i++)
1099 dlg.FixedFont->Append((*m_FixedFonts)[i]);
1100 if (!m_NormalFace.empty())
1101 dlg.NormalFont->SetStringSelection(m_NormalFace);
1102 else
1103 dlg.NormalFont->SetSelection(0);
1104 if (!m_FixedFace.empty())
1105 dlg.FixedFont->SetStringSelection(m_FixedFace);
1106 else
1107 dlg.FixedFont->SetSelection(0);
1108 dlg.FontSize->SetValue(m_FontSize);
1109 dlg.UpdateTestWin();
1110
1111 if (dlg.ShowModal() == wxID_OK)
1112 {
1113 m_NormalFace = dlg.NormalFont->GetStringSelection();
1114 m_FixedFace = dlg.FixedFont->GetStringSelection();
1115 m_FontSize = dlg.FontSize->GetValue();
1116 SetFontsToHtmlWin(m_HtmlWin, m_NormalFace, m_FixedFace, m_FontSize);
1117 }
1118 }
1119
1120
1121
1122 void wxHtmlHelpFrame::NotifyPageChanged()
1123 {
1124 if (m_UpdateContents && m_PagesHash)
1125 {
1126 wxString an = m_HtmlWin->GetOpenedAnchor();
1127 wxHtmlHelpHashData *ha;
1128 if (an.IsEmpty())
1129 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage());
1130 else
1131 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage() + wxT("#") + an);
1132 if (ha)
1133 {
1134 bool olduc = m_UpdateContents;
1135 m_UpdateContents = FALSE;
1136 m_ContentsBox->SelectItem(ha->m_Id);
1137 m_ContentsBox->EnsureVisible(ha->m_Id);
1138 m_UpdateContents = olduc;
1139 }
1140 }
1141 }
1142
1143
1144
1145 /*
1146 EVENT HANDLING :
1147 */
1148
1149
1150 void wxHtmlHelpFrame::OnActivate(wxActivateEvent& event)
1151 {
1152 // This saves one mouse click when using the
1153 // wxHTML for context sensitive help systems
1154 #ifndef __WXGTK__
1155 // NB: wxActivateEvent is a bit broken in wxGTK
1156 // and is sometimes sent when it should not be
1157 if (event.GetActive() && m_HtmlWin)
1158 m_HtmlWin->SetFocus();
1159 #endif
1160
1161 event.Skip();
1162 }
1163
1164 void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event)
1165 {
1166 switch (event.GetId())
1167 {
1168 case wxID_HTML_BACK :
1169 m_HtmlWin->HistoryBack();
1170 NotifyPageChanged();
1171 break;
1172
1173 case wxID_HTML_FORWARD :
1174 m_HtmlWin->HistoryForward();
1175 NotifyPageChanged();
1176 break;
1177
1178 case wxID_HTML_UP :
1179 if (m_PagesHash)
1180 {
1181 wxString an = m_HtmlWin->GetOpenedAnchor();
1182 wxHtmlHelpHashData *ha;
1183 if (an.IsEmpty())
1184 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage());
1185 else
1186 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage() + wxT("#") + an);
1187 if (ha && ha->m_Index > 0)
1188 {
1189 wxHtmlContentsItem *it = m_Data->GetContents() + (ha->m_Index - 1);
1190 if (it->m_Page[0] != 0)
1191 {
1192 m_HtmlWin->LoadPage(it->GetFullPath());
1193 NotifyPageChanged();
1194 }
1195 }
1196 }
1197 break;
1198
1199 case wxID_HTML_UPNODE :
1200 if (m_PagesHash)
1201 {
1202 wxString an = m_HtmlWin->GetOpenedAnchor();
1203 wxHtmlHelpHashData *ha;
1204 if (an.IsEmpty())
1205 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage());
1206 else
1207 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage() + wxT("#") + an);
1208 if (ha && ha->m_Index > 0)
1209 {
1210 int level = m_Data->GetContents()[ha->m_Index].m_Level - 1;
1211 wxHtmlContentsItem *it;
1212 int ind = ha->m_Index - 1;
1213
1214 it = m_Data->GetContents() + ind;
1215 while (ind >= 0 && it->m_Level != level) ind--, it--;
1216 if (ind >= 0)
1217 {
1218 if (it->m_Page[0] != 0)
1219 {
1220 m_HtmlWin->LoadPage(it->GetFullPath());
1221 NotifyPageChanged();
1222 }
1223 }
1224 }
1225 }
1226 break;
1227
1228 case wxID_HTML_DOWN :
1229 if (m_PagesHash)
1230 {
1231 wxString an = m_HtmlWin->GetOpenedAnchor();
1232 wxString adr;
1233 wxHtmlHelpHashData *ha;
1234
1235 if (an.IsEmpty()) adr = m_HtmlWin->GetOpenedPage();
1236 else adr = m_HtmlWin->GetOpenedPage() + wxT("#") + an;
1237
1238 ha = (wxHtmlHelpHashData*) m_PagesHash->Get(adr);
1239
1240 if (ha && ha->m_Index < m_Data->GetContentsCnt() - 1)
1241 {
1242 wxHtmlContentsItem *it = m_Data->GetContents() + (ha->m_Index + 1);
1243
1244 while (it->GetFullPath() == adr) it++;
1245
1246 if (it->m_Page[0] != 0)
1247 {
1248 m_HtmlWin->LoadPage(it->GetFullPath());
1249 NotifyPageChanged();
1250 }
1251 }
1252 }
1253 break;
1254
1255 case wxID_HTML_PANEL :
1256 {
1257 if (! (m_Splitter && m_NavigPan))
1258 return ;
1259 if (m_Splitter->IsSplit())
1260 {
1261 m_Cfg.sashpos = m_Splitter->GetSashPosition();
1262 m_Splitter->Unsplit(m_NavigPan);
1263 m_Cfg.navig_on = FALSE;
1264 }
1265 else
1266 {
1267 m_NavigPan->Show(TRUE);
1268 m_HtmlWin->Show(TRUE);
1269 m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos);
1270 m_Cfg.navig_on = TRUE;
1271 }
1272 }
1273 break;
1274
1275 case wxID_HTML_OPTIONS :
1276 OptionsDialog();
1277 break;
1278
1279 case wxID_HTML_BOOKMARKSADD :
1280 {
1281 wxString item;
1282 wxString url;
1283
1284 item = m_HtmlWin->GetOpenedPageTitle();
1285 url = m_HtmlWin->GetOpenedPage();
1286 if (item == wxEmptyString)
1287 item = url.AfterLast(wxT('/'));
1288 if (m_BookmarksPages.Index(url) == wxNOT_FOUND)
1289 {
1290 m_Bookmarks->Append(item);
1291 m_BookmarksNames.Add(item);
1292 m_BookmarksPages.Add(url);
1293 }
1294 }
1295 break;
1296
1297 case wxID_HTML_BOOKMARKSREMOVE :
1298 {
1299 wxString item;
1300 int pos;
1301
1302 item = m_Bookmarks->GetStringSelection();
1303 pos = m_BookmarksNames.Index(item);
1304 if (pos != wxNOT_FOUND)
1305 {
1306 m_BookmarksNames.Remove(pos);
1307 m_BookmarksPages.Remove(pos);
1308 m_Bookmarks->Delete(m_Bookmarks->GetSelection());
1309 }
1310 }
1311 break;
1312
1313 #if wxUSE_PRINTING_ARCHITECTURE
1314 case wxID_HTML_PRINT :
1315 {
1316 if (m_Printer == NULL)
1317 m_Printer = new wxHtmlEasyPrinting(_("Help Printing"), this);
1318 if (!m_HtmlWin->GetOpenedPage())
1319 wxLogWarning(_("Cannot print empty page."));
1320 else
1321 m_Printer->PrintFile(m_HtmlWin->GetOpenedPage());
1322 }
1323 break;
1324 #endif
1325
1326 case wxID_HTML_OPENFILE :
1327 {
1328 wxString s = wxFileSelector(_("Open HTML document"),
1329 wxEmptyString,
1330 wxEmptyString,
1331 wxEmptyString,
1332 _(
1333 "HTML files (*.htm)|*.htm|HTML files (*.html)|*.html|\
1334 Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|\
1335 HTML Help Project (*.hhp)|*.hhp|\
1336 All files (*.*)|*"
1337 ),
1338 wxOPEN | wxFILE_MUST_EXIST,
1339 this);
1340 if (!s.IsEmpty())
1341 {
1342 wxString ext = s.Right(4).Lower();
1343 if (ext == _T(".zip") || ext == _T(".htb") || ext == _T(".hhp"))
1344 {
1345 wxBusyCursor bcur;
1346 m_Data->AddBook(s);
1347 RefreshLists();
1348 }
1349 else
1350 m_HtmlWin->LoadPage(s);
1351 }
1352 }
1353 break;
1354 }
1355 }
1356
1357
1358
1359 void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent& event)
1360 {
1361 wxHtmlHelpTreeItemData *pg;
1362 wxHtmlContentsItem *it;
1363
1364 pg = (wxHtmlHelpTreeItemData*) m_ContentsBox->GetItemData(event.GetItem());
1365
1366 if (pg && m_UpdateContents)
1367 {
1368 it = m_Data->GetContents() + (pg->m_Id);
1369 m_UpdateContents = FALSE;
1370 if (it->m_Page[0] != 0)
1371 m_HtmlWin->LoadPage(it->GetFullPath());
1372 m_UpdateContents = TRUE;
1373 }
1374 }
1375
1376
1377
1378 void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent& WXUNUSED(event))
1379 {
1380 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_IndexList->GetClientData(m_IndexList->GetSelection());
1381 if (it->m_Page[0] != 0)
1382 m_HtmlWin->LoadPage(it->GetFullPath());
1383 NotifyPageChanged();
1384 }
1385
1386
1387 void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent& event)
1388 {
1389 wxString sr = m_IndexText->GetLineText(0);
1390 sr.MakeLower();
1391 if (sr == wxEmptyString)
1392 {
1393 OnIndexAll(event);
1394 }
1395 else
1396 {
1397 wxBusyCursor bcur;
1398 const wxChar *cstr = sr.c_str();
1399 wxChar mybuff[512];
1400 wxChar *ptr;
1401 bool first = TRUE;
1402
1403 m_IndexList->Clear();
1404 int cnt = m_Data->GetIndexCnt();
1405 wxHtmlContentsItem* index = m_Data->GetIndex();
1406
1407 int displ = 0;
1408 for (int i = 0; i < cnt; i++)
1409 {
1410 wxStrncpy(mybuff, index[i].m_Name, 512);
1411 mybuff[511] = _T('\0');
1412 for (ptr = mybuff; *ptr != 0; ptr++)
1413 if (*ptr >= _T('A') && *ptr <= _T('Z'))
1414 *ptr -= (wxChar)(_T('A') - _T('a'));
1415 if (wxStrstr(mybuff, cstr) != NULL)
1416 {
1417 m_IndexList->Append(index[i].m_Name, (char*)(index + i));
1418 displ++;
1419 if (first)
1420 {
1421 if (index[i].m_Page[0] != 0)
1422 m_HtmlWin->LoadPage(index[i].GetFullPath());
1423 NotifyPageChanged();
1424 first = FALSE;
1425 }
1426 }
1427 }
1428
1429 wxString cnttext;
1430 cnttext.Printf(_("%i of %i"), displ, cnt);
1431 m_IndexCountInfo->SetLabel(cnttext);
1432
1433 m_IndexText->SetSelection(0, sr.Length());
1434 m_IndexText->SetFocus();
1435 }
1436 }
1437
1438 void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent& WXUNUSED(event))
1439 {
1440 wxBusyCursor bcur;
1441
1442 m_IndexList->Clear();
1443 int cnt = m_Data->GetIndexCnt();
1444 bool first = TRUE;
1445 wxHtmlContentsItem* index = m_Data->GetIndex();
1446
1447 for (int i = 0; i < cnt; i++)
1448 {
1449 m_IndexList->Append(index[i].m_Name, (char*)(index + i));
1450 if (first)
1451 {
1452 if (index[i].m_Page[0] != 0)
1453 m_HtmlWin->LoadPage(index[i].GetFullPath());
1454 NotifyPageChanged();
1455 first = FALSE;
1456 }
1457 }
1458
1459 wxString cnttext;
1460 cnttext.Printf(_("%i of %i"), cnt, cnt);
1461 m_IndexCountInfo->SetLabel(cnttext);
1462 }
1463
1464
1465 void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent& WXUNUSED(event))
1466 {
1467 wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList->GetClientData(m_SearchList->GetSelection());
1468 if (it)
1469 {
1470 if (it->m_Page[0] != 0)
1471 m_HtmlWin->LoadPage(it->GetFullPath());
1472 NotifyPageChanged();
1473 }
1474 }
1475
1476 void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event))
1477 {
1478 wxString sr = m_SearchText->GetLineText(0);
1479
1480 if (sr != wxEmptyString) KeywordSearch(sr);
1481 }
1482
1483 void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event))
1484 {
1485 wxString sr = m_Bookmarks->GetStringSelection();
1486
1487 if (sr != wxEmptyString && sr != _("(bookmarks)"))
1488 {
1489 m_HtmlWin->LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]);
1490 NotifyPageChanged();
1491 }
1492 }
1493
1494 void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt)
1495 {
1496 GetSize(&m_Cfg.w, &m_Cfg.h);
1497 GetPosition(&m_Cfg.x, &m_Cfg.y);
1498
1499 #ifdef __WXGTK__
1500 if (IsGrabbed())
1501 {
1502 RemoveGrab();
1503 }
1504 #endif
1505
1506 if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter->GetSashPosition();
1507
1508 if (m_Config)
1509 WriteCustomization(m_Config, m_ConfigRoot);
1510
1511 if (m_helpController && m_helpController->IsKindOf(CLASSINFO(wxHtmlHelpController)))
1512 {
1513 ((wxHtmlHelpController*) m_helpController)->OnCloseFrame(evt);
1514 }
1515
1516 evt.Skip();
1517 }
1518
1519 #ifdef __WXMAC__
1520 void wxHtmlHelpFrame::OnQuit(wxCommandEvent& event)
1521 {
1522 Close(TRUE);
1523 }
1524
1525 void wxHtmlHelpFrame::OnAbout(wxCommandEvent& event)
1526 {
1527 wxMessageBox(wxT("wxWindows HTML Help Viewer (c) 1998-2003, Vaclav Slavik et al"), wxT("HelpView"),
1528 wxICON_INFORMATION|wxOK, this);
1529 }
1530 #endif
1531
1532 BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame)
1533 EVT_ACTIVATE(wxHtmlHelpFrame::OnActivate)
1534 EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_OPTIONS, wxHtmlHelpFrame::OnToolbar)
1535 EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE, wxHtmlHelpFrame::OnToolbar)
1536 EVT_BUTTON(wxID_HTML_BOOKMARKSADD, wxHtmlHelpFrame::OnToolbar)
1537 EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpFrame::OnContentsSel)
1538 EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel)
1539 EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel)
1540 EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch)
1541 EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpFrame::OnSearch)
1542 EVT_BUTTON(wxID_HTML_INDEXBUTTON, wxHtmlHelpFrame::OnIndexFind)
1543 EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT, wxHtmlHelpFrame::OnIndexFind)
1544 EVT_BUTTON(wxID_HTML_INDEXBUTTONALL, wxHtmlHelpFrame::OnIndexAll)
1545 EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST, wxHtmlHelpFrame::OnBookmarksSel)
1546 EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow)
1547 #ifdef __WXMAC__
1548 EVT_MENU(wxID_CLOSE, wxHtmlHelpFrame::OnQuit)
1549 EVT_MENU(wxID_ABOUT, wxHtmlHelpFrame::OnAbout)
1550 #endif
1551
1552 END_EVENT_TABLE()
1553
1554 #endif // wxUSE_WXHTML_HELP
1555