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