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