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