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