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