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