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