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