]>
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 | 8 | // Copyright: (c) Harm van der Heijden and Vaclav Slavik |
65571936 | 9 | // Licence: wxWindows licence |
8ec2b484 HH |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
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 | 178 | m_Data = data; |
dabbc6a5 | 179 | m_DataCreated = false; |
da4cc40c | 180 | } else |
4f9297b0 | 181 | { |
d5bb85a0 | 182 | m_Data = new wxHtmlHelpData(); |
dabbc6a5 | 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 | 210 | m_Cfg.sashpos = 240; |
dabbc6a5 | 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; | |
dabbc6a5 | 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 | |
dabbc6a5 DS |
254 | wxFrame::Create(parent, id, _("Help"), |
255 | wxPoint(m_Cfg.x, m_Cfg.y), wxSize(m_Cfg.w, m_Cfg.h), | |
5229b11d | 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 | |
c3eeb758 RD |
276 | menuBar->Append(fileMenu,_("&File")); |
277 | menuBar->Append(helpMenu,_("&Help")); | |
d9b21c9f JS |
278 | SetMenuBar(menuBar); |
279 | #endif | |
280 | ||
8ec2b484 HH |
281 | int notebook_page = 0; |
282 | ||
283 | CreateStatusBar(); | |
284 | ||
ee2f6a93 | 285 | #if wxUSE_TOOLBAR |
8ec2b484 | 286 | // toolbar? |
576507e2 | 287 | if (style & (wxHF_TOOLBAR | wxHF_FLAT_TOOLBAR)) |
4f9297b0 | 288 | { |
f6bcfd97 BP |
289 | wxToolBar *toolBar = CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL | |
290 | wxTB_DOCKABLE | | |
576507e2 | 291 | (style & wxHF_FLAT_TOOLBAR ? wxTB_FLAT : 0)); |
00655497 | 292 | toolBar->SetMargins( 2, 2 ); |
b854b7b8 | 293 | AddToolbarButtons(toolBar, style); |
4f9297b0 | 294 | toolBar->Realize(); |
8ec2b484 | 295 | } |
ee2f6a93 | 296 | #endif //wxUSE_TOOLBAR |
d5bb85a0 | 297 | |
5229b11d VS |
298 | wxSizer *navigSizer = NULL; |
299 | ||
da4cc40c | 300 | if (style & (wxHF_CONTENTS | wxHF_INDEX | wxHF_SEARCH)) |
4f9297b0 | 301 | { |
d5bb85a0 VS |
302 | // traditional help controller; splitter window with html page on the |
303 | // right and a notebook containing various pages on the left | |
304 | m_Splitter = new wxSplitterWindow(this); | |
305 | ||
0646614d | 306 | m_HtmlWin = new wxHtmlHelpHtmlWindow(this, m_Splitter); |
dabbc6a5 | 307 | m_NavigPan = new wxPanel(m_Splitter, wxID_ANY); |
5229b11d VS |
308 | m_NavigNotebook = new wxNotebook(m_NavigPan, wxID_HTML_NOTEBOOK, |
309 | wxDefaultPosition, wxDefaultSize); | |
dabbc6a5 | 310 | |
5229b11d | 311 | navigSizer = new wxBoxSizer(wxVERTICAL); |
adbf2d73 | 312 | navigSizer->Add(m_NavigNotebook, 1, wxEXPAND); |
5229b11d | 313 | |
5229b11d | 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); | |
dabbc6a5 | 331 | |
5229b11d | 332 | topsizer->Add(0, 10); |
dabbc6a5 | 333 | |
5229b11d VS |
334 | dummy->SetSizer(topsizer); |
335 | ||
5229b11d | 336 | if ( style & wxHF_BOOKMARKS ) |
3379ed37 | 337 | { |
dabbc6a5 | 338 | m_Bookmarks = new wxComboBox(dummy, wxID_HTML_BOOKMARKSLIST, |
5229b11d | 339 | wxEmptyString, |
dabbc6a5 | 340 | wxDefaultPosition, wxDefaultSize, |
5229b11d | 341 | 0, NULL, wxCB_READONLY | wxCB_SORT); |
4f9297b0 | 342 | m_Bookmarks->Append(_("(bookmarks)")); |
ae80f837 | 343 | for (unsigned i = 0; i < m_BookmarksNames.GetCount(); i++) |
4f9297b0 VS |
344 | m_Bookmarks->Append(m_BookmarksNames[i]); |
345 | m_Bookmarks->SetSelection(0); | |
ae80f837 | 346 | |
5229b11d | 347 | wxBitmapButton *bmpbt1, *bmpbt2; |
dabbc6a5 DS |
348 | bmpbt1 = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSADD, |
349 | wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK, | |
f435c1f0 | 350 | wxART_HELP_BROWSER)); |
dabbc6a5 DS |
351 | bmpbt2 = new wxBitmapButton(dummy, wxID_HTML_BOOKMARKSREMOVE, |
352 | wxArtProvider::GetBitmap(wxART_DEL_BOOKMARK, | |
f435c1f0 | 353 | wxART_HELP_BROWSER)); |
5229b11d VS |
354 | #if wxUSE_TOOLTIPS |
355 | bmpbt1->SetToolTip(_("Add current page to bookmarks")); | |
356 | bmpbt2->SetToolTip(_("Remove current page from bookmarks")); | |
357 | #endif // wxUSE_TOOLTIPS | |
358 | ||
359 | wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL); | |
dabbc6a5 | 360 | |
f435c1f0 VS |
361 | sizer->Add(m_Bookmarks, 1, wxALIGN_CENTRE_VERTICAL | wxRIGHT, 5); |
362 | sizer->Add(bmpbt1, 0, wxALIGN_CENTRE_VERTICAL | wxRIGHT, 2); | |
363 | sizer->Add(bmpbt2, 0, wxALIGN_CENTRE_VERTICAL, 0); | |
dabbc6a5 | 364 | |
5229b11d | 365 | topsizer->Add(sizer, 0, wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, 10); |
ae80f837 VS |
366 | } |
367 | ||
5229b11d VS |
368 | m_ContentsBox = new wxTreeCtrl(dummy, wxID_HTML_TREECTRL, |
369 | wxDefaultPosition, wxDefaultSize, | |
dabbc6a5 | 370 | wxSUNKEN_BORDER | |
e0952648 VS |
371 | wxTR_HAS_BUTTONS | wxTR_HIDE_ROOT | |
372 | wxTR_LINES_AT_ROOT); | |
373 | ||
5229b11d | 374 | m_ContentsBox->AssignImageList(ContentsImageList); |
dabbc6a5 | 375 | |
d49520c3 | 376 | topsizer->Add(m_ContentsBox, 1, |
395a82b1 | 377 | wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, |
d49520c3 | 378 | 2); |
ae80f837 | 379 | |
5229b11d | 380 | m_NavigNotebook->AddPage(dummy, _("Contents")); |
d5bb85a0 | 381 | m_ContentsPage = notebook_page++; |
8ec2b484 HH |
382 | } |
383 | ||
384 | // index listbox panel? | |
5229b11d | 385 | if ( style & wxHF_INDEX ) |
4f9297b0 | 386 | { |
dabbc6a5 | 387 | wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE); |
5229b11d VS |
388 | wxSizer *topsizer = new wxBoxSizer(wxVERTICAL); |
389 | ||
5229b11d VS |
390 | dummy->SetSizer(topsizer); |
391 | ||
dabbc6a5 DS |
392 | m_IndexText = new wxTextCtrl(dummy, wxID_HTML_INDEXTEXT, wxEmptyString, |
393 | wxDefaultPosition, wxDefaultSize, | |
5229b11d | 394 | wxTE_PROCESS_ENTER); |
f0b6a33f | 395 | m_IndexButton = new wxButton(dummy, wxID_HTML_INDEXBUTTON, _("Find")); |
dabbc6a5 | 396 | m_IndexButtonAll = new wxButton(dummy, wxID_HTML_INDEXBUTTONALL, |
5229b11d | 397 | _("Show all")); |
dabbc6a5 | 398 | m_IndexCountInfo = new wxStaticText(dummy, wxID_HTML_COUNTINFO, |
5229b11d | 399 | wxEmptyString, wxDefaultPosition, |
dabbc6a5 | 400 | wxDefaultSize, |
5229b11d | 401 | wxALIGN_RIGHT | wxST_NO_AUTORESIZE); |
dabbc6a5 DS |
402 | m_IndexList = new wxListBox(dummy, wxID_HTML_INDEXLIST, |
403 | wxDefaultPosition, wxDefaultSize, | |
5229b11d | 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); | |
dabbc6a5 | 415 | topsizer->Add(btsizer, 0, |
5229b11d VS |
416 | wxALIGN_RIGHT | wxLEFT | wxRIGHT | wxBOTTOM, 10); |
417 | topsizer->Add(m_IndexCountInfo, 0, wxEXPAND | wxLEFT | wxRIGHT, 2); | |
395a82b1 | 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 | { |
dabbc6a5 | 427 | wxWindow *dummy = new wxPanel(m_NavigNotebook, wxID_HTML_INDEXPAGE); |
5229b11d | 428 | wxSizer *sizer = new wxBoxSizer(wxVERTICAL); |
c4971147 | 429 | |
5229b11d VS |
430 | dummy->SetSizer(sizer); |
431 | ||
dabbc6a5 DS |
432 | m_SearchText = new wxTextCtrl(dummy, wxID_HTML_SEARCHTEXT, |
433 | wxEmptyString, | |
434 | wxDefaultPosition, wxDefaultSize, | |
5229b11d | 435 | wxTE_PROCESS_ENTER); |
dabbc6a5 | 436 | m_SearchChoice = new wxChoice(dummy, wxID_HTML_SEARCHCHOICE, |
5229b11d | 437 | wxDefaultPosition, wxDefaultSize); |
dabbc6a5 DS |
438 | m_SearchCaseSensitive = new wxCheckBox(dummy, wxID_ANY, _("Case sensitive")); |
439 | m_SearchWholeWords = new wxCheckBox(dummy, wxID_ANY, _("Whole words only")); | |
ae80f837 VS |
440 | m_SearchButton = new wxButton(dummy, wxID_HTML_SEARCHBUTTON, _("Search")); |
441 | #if wxUSE_TOOLTIPS | |
4f9297b0 | 442 | m_SearchButton->SetToolTip(_("Search contents of help book(s) for all occurences of the text you typed above")); |
ae80f837 | 443 | #endif //wxUSE_TOOLTIPS |
dabbc6a5 DS |
444 | m_SearchList = new wxListBox(dummy, wxID_HTML_SEARCHLIST, |
445 | wxDefaultPosition, wxDefaultSize, | |
5229b11d | 446 | 0, NULL, wxLB_SINGLE); |
dabbc6a5 | 447 | |
5229b11d VS |
448 | sizer->Add(m_SearchText, 0, wxEXPAND | wxALL, 10); |
449 | sizer->Add(m_SearchChoice, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10); | |
450 | sizer->Add(m_SearchCaseSensitive, 0, wxLEFT | wxRIGHT, 10); | |
451 | sizer->Add(m_SearchWholeWords, 0, wxLEFT | wxRIGHT, 10); | |
452 | sizer->Add(m_SearchButton, 0, wxALL | wxALIGN_RIGHT, 8); | |
395a82b1 | 453 | sizer->Add(m_SearchList, 1, wxALL | wxEXPAND, 2); |
5229b11d VS |
454 | |
455 | m_NavigNotebook->AddPage(dummy, _("Search")); | |
999836aa | 456 | m_SearchPage = notebook_page; |
8ec2b484 | 457 | } |
5229b11d | 458 | |
dabbc6a5 | 459 | m_HtmlWin->Show(); |
f6bcfd97 | 460 | |
b5a7b000 | 461 | RefreshLists(); |
8ec2b484 | 462 | |
5229b11d VS |
463 | if ( navigSizer ) |
464 | { | |
d49520c3 | 465 | navigSizer->SetSizeHints(m_NavigPan); |
5229b11d VS |
466 | m_NavigPan->Layout(); |
467 | } | |
468 | ||
8ec2b484 | 469 | // showtime |
5229b11d | 470 | if ( m_NavigPan && m_Splitter ) |
4f9297b0 VS |
471 | { |
472 | m_Splitter->SetMinimumPaneSize(20); | |
5229b11d | 473 | if ( m_Cfg.navig_on ) |
4f9297b0 | 474 | m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); |
4f9297b0 | 475 | |
5229b11d | 476 | if ( m_Cfg.navig_on ) |
3379ed37 | 477 | { |
dabbc6a5 | 478 | m_NavigPan->Show(); |
4f9297b0 | 479 | m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); |
c32bfc10 | 480 | } |
da4cc40c | 481 | else |
3379ed37 | 482 | { |
dabbc6a5 | 483 | m_NavigPan->Show(false); |
4f9297b0 | 484 | m_Splitter->Initialize(m_HtmlWin); |
68364659 | 485 | } |
8ec2b484 | 486 | } |
dabbc6a5 | 487 | |
7e521b01 JS |
488 | // Reduce flicker by updating the splitter pane sizes before the |
489 | // frame is shown | |
490 | wxSizeEvent sizeEvent(GetSize(), GetId()); | |
491 | ProcessEvent(sizeEvent); | |
dabbc6a5 | 492 | |
7e521b01 | 493 | m_Splitter->UpdateSize(); |
dabbc6a5 DS |
494 | |
495 | return true; | |
8ec2b484 HH |
496 | } |
497 | ||
498 | wxHtmlHelpFrame::~wxHtmlHelpFrame() | |
499 | { | |
b4414c1f | 500 | // PopEventHandler(); // wxhtmlhelpcontroller (not any more!) |
8ec2b484 | 501 | if (m_DataCreated) |
d5bb85a0 | 502 | delete m_Data; |
83efdf33 VS |
503 | if (m_NormalFonts) delete m_NormalFonts; |
504 | if (m_FixedFonts) delete m_FixedFonts; | |
dabbc6a5 | 505 | if (m_PagesHash) |
ba8c1601 MB |
506 | { |
507 | WX_CLEAR_HASH_TABLE(*m_PagesHash); | |
508 | delete m_PagesHash; | |
509 | } | |
6c24d95c VS |
510 | #if wxUSE_PRINTING_ARCHITECTURE |
511 | if (m_Printer) delete m_Printer; | |
512 | #endif | |
8ec2b484 HH |
513 | } |
514 | ||
b854b7b8 | 515 | |
ee2f6a93 | 516 | #if wxUSE_TOOLBAR |
b854b7b8 VS |
517 | void wxHtmlHelpFrame::AddToolbarButtons(wxToolBar *toolBar, int style) |
518 | { | |
dabbc6a5 | 519 | wxBitmap wpanelBitmap = |
f435c1f0 | 520 | wxArtProvider::GetBitmap(wxART_HELP_SIDE_PANEL, wxART_HELP_BROWSER); |
dabbc6a5 | 521 | wxBitmap wbackBitmap = |
f435c1f0 | 522 | wxArtProvider::GetBitmap(wxART_GO_BACK, wxART_HELP_BROWSER); |
dabbc6a5 | 523 | wxBitmap wforwardBitmap = |
f435c1f0 | 524 | wxArtProvider::GetBitmap(wxART_GO_FORWARD, wxART_HELP_BROWSER); |
dabbc6a5 | 525 | wxBitmap wupnodeBitmap = |
f435c1f0 | 526 | wxArtProvider::GetBitmap(wxART_GO_TO_PARENT, wxART_HELP_BROWSER); |
dabbc6a5 | 527 | wxBitmap wupBitmap = |
f435c1f0 | 528 | wxArtProvider::GetBitmap(wxART_GO_UP, wxART_HELP_BROWSER); |
dabbc6a5 | 529 | wxBitmap wdownBitmap = |
f435c1f0 | 530 | wxArtProvider::GetBitmap(wxART_GO_DOWN, wxART_HELP_BROWSER); |
dabbc6a5 | 531 | wxBitmap wopenBitmap = |
f435c1f0 | 532 | wxArtProvider::GetBitmap(wxART_FILE_OPEN, wxART_HELP_BROWSER); |
dabbc6a5 | 533 | wxBitmap wprintBitmap = |
f435c1f0 | 534 | wxArtProvider::GetBitmap(wxART_PRINT, wxART_HELP_BROWSER); |
dabbc6a5 | 535 | wxBitmap woptionsBitmap = |
f435c1f0 | 536 | wxArtProvider::GetBitmap(wxART_HELP_SETTINGS, wxART_HELP_BROWSER); |
f6bcfd97 BP |
537 | |
538 | wxASSERT_MSG( (wpanelBitmap.Ok() && wbackBitmap.Ok() && | |
539 | wforwardBitmap.Ok() && wupnodeBitmap.Ok() && | |
540 | wupBitmap.Ok() && wdownBitmap.Ok() && | |
541 | wopenBitmap.Ok() && wprintBitmap.Ok() && | |
542 | woptionsBitmap.Ok()), | |
543 | wxT("One or more HTML help frame toolbar bitmap could not be loaded.")) ; | |
544 | ||
545 | ||
4f9297b0 | 546 | toolBar->AddTool(wxID_HTML_PANEL, wpanelBitmap, wxNullBitmap, |
dabbc6a5 | 547 | false, -1, -1, (wxObject *) NULL, |
b854b7b8 | 548 | _("Show/hide navigation panel")); |
0646614d | 549 | |
4f9297b0 VS |
550 | toolBar->AddSeparator(); |
551 | toolBar->AddTool(wxID_HTML_BACK, wbackBitmap, wxNullBitmap, | |
dabbc6a5 | 552 | false, -1, -1, (wxObject *) NULL, |
0646614d | 553 | _("Go back")); |
4f9297b0 | 554 | toolBar->AddTool(wxID_HTML_FORWARD, wforwardBitmap, wxNullBitmap, |
dabbc6a5 | 555 | false, -1, -1, (wxObject *) NULL, |
0646614d | 556 | _("Go forward")); |
4f9297b0 | 557 | toolBar->AddSeparator(); |
b854b7b8 | 558 | |
4f9297b0 | 559 | toolBar->AddTool(wxID_HTML_UPNODE, wupnodeBitmap, wxNullBitmap, |
dabbc6a5 | 560 | false, -1, -1, (wxObject *) NULL, |
0646614d | 561 | _("Go one level up in document hierarchy")); |
4f9297b0 | 562 | toolBar->AddTool(wxID_HTML_UP, wupBitmap, wxNullBitmap, |
dabbc6a5 | 563 | false, -1, -1, (wxObject *) NULL, |
0646614d | 564 | _("Previous page")); |
4f9297b0 | 565 | toolBar->AddTool(wxID_HTML_DOWN, wdownBitmap, wxNullBitmap, |
dabbc6a5 | 566 | false, -1, -1, (wxObject *) NULL, |
0646614d VS |
567 | _("Next page")); |
568 | ||
576507e2 | 569 | if ((style & wxHF_PRINT) || (style & wxHF_OPEN_FILES)) |
4f9297b0 | 570 | toolBar->AddSeparator(); |
f6bcfd97 | 571 | |
576507e2 | 572 | if (style & wxHF_OPEN_FILES) |
4f9297b0 | 573 | toolBar->AddTool(wxID_HTML_OPENFILE, wopenBitmap, wxNullBitmap, |
dabbc6a5 | 574 | false, -1, -1, (wxObject *) NULL, |
0646614d VS |
575 | _("Open HTML document")); |
576 | ||
577 | #if wxUSE_PRINTING_ARCHITECTURE | |
578 | if (style & wxHF_PRINT) | |
4f9297b0 | 579 | toolBar->AddTool(wxID_HTML_PRINT, wprintBitmap, wxNullBitmap, |
dabbc6a5 | 580 | false, -1, -1, (wxObject *) NULL, |
0646614d VS |
581 | _("Print this page")); |
582 | #endif | |
583 | ||
4f9297b0 VS |
584 | toolBar->AddSeparator(); |
585 | toolBar->AddTool(wxID_HTML_OPTIONS, woptionsBitmap, wxNullBitmap, | |
dabbc6a5 | 586 | false, -1, -1, (wxObject *) NULL, |
b854b7b8 VS |
587 | _("Display options dialog")); |
588 | } | |
ee2f6a93 | 589 | #endif //wxUSE_TOOLBAR |
b854b7b8 VS |
590 | |
591 | ||
721ab905 VS |
592 | void wxHtmlHelpFrame::SetTitleFormat(const wxString& format) |
593 | { | |
594 | if (m_HtmlWin) | |
595 | m_HtmlWin->SetRelatedFrame(this, format); | |
596 | m_TitleFormat = format; | |
597 | } | |
598 | ||
b854b7b8 | 599 | |
8ec2b484 HH |
600 | bool wxHtmlHelpFrame::Display(const wxString& x) |
601 | { | |
602 | wxString url = m_Data->FindPageByName(x); | |
da4cc40c | 603 | if (!url.IsEmpty()) |
4f9297b0 | 604 | { |
d5bb85a0 | 605 | m_HtmlWin->LoadPage(url); |
0646614d | 606 | NotifyPageChanged(); |
dabbc6a5 | 607 | return true; |
8ec2b484 | 608 | } |
dabbc6a5 DS |
609 | |
610 | return false; | |
8ec2b484 HH |
611 | } |
612 | ||
613 | bool wxHtmlHelpFrame::Display(const int id) | |
614 | { | |
615 | wxString url = m_Data->FindPageById(id); | |
da4cc40c | 616 | if (!url.IsEmpty()) |
4f9297b0 | 617 | { |
d5bb85a0 | 618 | m_HtmlWin->LoadPage(url); |
0646614d | 619 | NotifyPageChanged(); |
dabbc6a5 | 620 | return true; |
8ec2b484 | 621 | } |
dabbc6a5 DS |
622 | |
623 | return false; | |
8ec2b484 HH |
624 | } |
625 | ||
626 | ||
627 | ||
628 | bool wxHtmlHelpFrame::DisplayContents() | |
629 | { | |
630 | if (! m_ContentsBox) | |
dabbc6a5 DS |
631 | return false; |
632 | ||
da4cc40c | 633 | if (!m_Splitter->IsSplit()) |
4f9297b0 | 634 | { |
dabbc6a5 DS |
635 | m_NavigPan->Show(); |
636 | m_HtmlWin->Show(); | |
4f9297b0 | 637 | m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); |
dabbc6a5 | 638 | m_Cfg.navig_on = true; |
8ec2b484 | 639 | } |
dabbc6a5 | 640 | |
5229b11d | 641 | m_NavigNotebook->SetSelection(0); |
dabbc6a5 | 642 | |
71d04f7f JS |
643 | if (m_Data->GetBookRecArray().GetCount() > 0) |
644 | { | |
645 | wxHtmlBookRecord& book = m_Data->GetBookRecArray()[0]; | |
646 | if (!book.GetStart().IsEmpty()) | |
468ae730 | 647 | m_HtmlWin->LoadPage(book.GetFullPath(book.GetStart())); |
71d04f7f | 648 | } |
dabbc6a5 DS |
649 | |
650 | return true; | |
8ec2b484 HH |
651 | } |
652 | ||
653 | ||
654 | ||
655 | bool wxHtmlHelpFrame::DisplayIndex() | |
656 | { | |
f0b6a33f | 657 | if (! m_IndexList) |
dabbc6a5 DS |
658 | return false; |
659 | ||
da4cc40c | 660 | if (!m_Splitter->IsSplit()) |
4f9297b0 | 661 | { |
dabbc6a5 DS |
662 | m_NavigPan->Show(); |
663 | m_HtmlWin->Show(); | |
4f9297b0 | 664 | m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); |
8ec2b484 | 665 | } |
dabbc6a5 | 666 | |
5229b11d | 667 | m_NavigNotebook->SetSelection(1); |
dabbc6a5 | 668 | |
71d04f7f JS |
669 | if (m_Data->GetBookRecArray().GetCount() > 0) |
670 | { | |
671 | wxHtmlBookRecord& book = m_Data->GetBookRecArray()[0]; | |
672 | if (!book.GetStart().IsEmpty()) | |
468ae730 | 673 | m_HtmlWin->LoadPage(book.GetFullPath(book.GetStart())); |
71d04f7f | 674 | } |
dabbc6a5 DS |
675 | |
676 | return true; | |
8ec2b484 HH |
677 | } |
678 | ||
b854b7b8 VS |
679 | |
680 | ||
69b5cec2 VS |
681 | bool wxHtmlHelpFrame::KeywordSearch(const wxString& keyword, |
682 | wxHelpSearchMode mode) | |
8ec2b484 | 683 | { |
69b5cec2 VS |
684 | if (mode == wxHELP_SEARCH_ALL) |
685 | { | |
686 | if ( !(m_SearchList && | |
687 | m_SearchButton && m_SearchText && m_SearchChoice) ) | |
688 | return false; | |
689 | } | |
690 | else if (mode == wxHELP_SEARCH_INDEX) | |
691 | { | |
692 | if ( !(m_IndexList && | |
693 | m_IndexButton && m_IndexButtonAll && m_IndexText) ) | |
694 | return false; | |
695 | } | |
8ec2b484 | 696 | |
69b5cec2 | 697 | int foundcnt = 0; |
8ec2b484 HH |
698 | wxString foundstr; |
699 | wxString book = wxEmptyString; | |
700 | ||
da4cc40c | 701 | if (!m_Splitter->IsSplit()) |
4f9297b0 | 702 | { |
dabbc6a5 DS |
703 | m_NavigPan->Show(); |
704 | m_HtmlWin->Show(); | |
4f9297b0 | 705 | m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); |
8ec2b484 | 706 | } |
8ec2b484 | 707 | |
69b5cec2 | 708 | if (mode == wxHELP_SEARCH_ALL) |
4f9297b0 | 709 | { |
69b5cec2 VS |
710 | m_NavigNotebook->SetSelection(m_SearchPage); |
711 | m_SearchList->Clear(); | |
712 | m_SearchText->SetValue(keyword); | |
dabbc6a5 | 713 | m_SearchButton->Disable(); |
69b5cec2 VS |
714 | |
715 | if (m_SearchChoice->GetSelection() != 0) | |
716 | book = m_SearchChoice->GetStringSelection(); | |
717 | ||
718 | wxHtmlSearchStatus status(m_Data, keyword, | |
719 | m_SearchCaseSensitive->GetValue(), | |
720 | m_SearchWholeWords->GetValue(), | |
721 | book); | |
722 | ||
3511e024 | 723 | #if wxUSE_PROGRESSDLG |
69b5cec2 VS |
724 | wxProgressDialog progress(_("Searching..."), |
725 | _("No matching page found yet"), | |
726 | status.GetMaxIndex(), this, | |
727 | wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_AUTO_HIDE); | |
3511e024 | 728 | #endif |
69b5cec2 VS |
729 | |
730 | int curi; | |
731 | while (status.IsActive()) | |
3379ed37 | 732 | { |
69b5cec2 | 733 | curi = status.GetCurIndex(); |
dabbc6a5 | 734 | if (curi % 32 == 0 |
3511e024 | 735 | #if wxUSE_PROGRESSDLG |
dabbc6a5 | 736 | && !progress.Update(curi) |
3511e024 WS |
737 | #endif |
738 | ) | |
69b5cec2 VS |
739 | break; |
740 | if (status.Search()) | |
741 | { | |
742 | foundstr.Printf(_("Found %i matches"), ++foundcnt); | |
3511e024 | 743 | #if wxUSE_PROGRESSDLG |
69b5cec2 | 744 | progress.Update(status.GetCurIndex(), foundstr); |
3511e024 | 745 | #endif |
69b5cec2 VS |
746 | m_SearchList->Append(status.GetName(), status.GetContentsItem()); |
747 | } | |
d5bb85a0 | 748 | } |
69b5cec2 | 749 | |
dabbc6a5 | 750 | m_SearchButton->Enable(); |
69b5cec2 VS |
751 | m_SearchText->SetSelection(0, keyword.Length()); |
752 | m_SearchText->SetFocus(); | |
753 | } | |
754 | else if (mode == wxHELP_SEARCH_INDEX) | |
755 | { | |
756 | m_NavigNotebook->SetSelection(m_IndexPage); | |
757 | m_IndexList->Clear(); | |
dabbc6a5 DS |
758 | m_IndexButton->Disable(); |
759 | m_IndexButtonAll->Disable(); | |
69b5cec2 VS |
760 | m_IndexText->SetValue(keyword); |
761 | ||
762 | wxCommandEvent dummy; | |
763 | OnIndexFind(dummy); // what a hack... | |
dabbc6a5 DS |
764 | m_IndexButton->Enable(); |
765 | m_IndexButtonAll->Enable(); | |
69b5cec2 | 766 | foundcnt = m_IndexList->GetCount(); |
8ec2b484 HH |
767 | } |
768 | ||
da4cc40c | 769 | if (foundcnt) |
4f9297b0 | 770 | { |
69b5cec2 | 771 | wxHtmlContentsItem *it; |
75d07c0a | 772 | switch ( mode ) |
69b5cec2 | 773 | { |
75d07c0a VZ |
774 | default: |
775 | wxFAIL_MSG( _T("unknown help search mode") ); | |
776 | // fall back | |
777 | ||
778 | case wxHELP_SEARCH_ALL: | |
779 | it = (wxHtmlContentsItem*) m_SearchList->GetClientData(0); | |
780 | break; | |
781 | ||
782 | case wxHELP_SEARCH_INDEX: | |
783 | it = (wxHtmlContentsItem*) m_IndexList->GetClientData(0); | |
784 | break; | |
69b5cec2 | 785 | } |
75d07c0a | 786 | |
f6bcfd97 | 787 | if (it) |
0646614d | 788 | { |
468ae730 | 789 | m_HtmlWin->LoadPage(it->GetFullPath()); |
0646614d VS |
790 | NotifyPageChanged(); |
791 | } | |
8ec2b484 | 792 | } |
75d07c0a VZ |
793 | |
794 | return foundcnt > 0; | |
8ec2b484 HH |
795 | } |
796 | ||
b5a7b000 | 797 | void wxHtmlHelpFrame::CreateContents() |
8ec2b484 HH |
798 | { |
799 | if (! m_ContentsBox) | |
d5bb85a0 | 800 | return ; |
8ec2b484 | 801 | |
ba8c1601 MB |
802 | if (m_PagesHash) |
803 | { | |
804 | WX_CLEAR_HASH_TABLE(*m_PagesHash); | |
805 | delete m_PagesHash; | |
806 | } | |
4f9297b0 | 807 | m_PagesHash = new wxHashTable(wxKEY_STRING, 2 * m_Data->GetContentsCnt()); |
8ec2b484 HH |
808 | |
809 | int cnt = m_Data->GetContentsCnt(); | |
8ec2b484 HH |
810 | int i; |
811 | ||
83efdf33 | 812 | wxHtmlContentsItem *it; |
d5bb85a0 | 813 | |
576507e2 | 814 | const int MAX_ROOTS = 64; |
8ec2b484 | 815 | wxTreeItemId roots[MAX_ROOTS]; |
576507e2 VS |
816 | // VS: this array holds information about whether we've set item icon at |
817 | // given level. This is neccessary because m_Data has flat structure | |
818 | // and there's no way of recognizing if some item has subitems or not. | |
819 | // We set the icon later: when we find an item with level=n, we know | |
820 | // that the last item with level=n-1 was folder with subitems, so we | |
821 | // set its icon accordingly | |
3379ed37 | 822 | bool imaged[MAX_ROOTS]; |
4f9297b0 | 823 | m_ContentsBox->DeleteAllItems(); |
dabbc6a5 | 824 | |
e0952648 | 825 | roots[0] = m_ContentsBox->AddRoot(_("(Help)")); |
dabbc6a5 | 826 | imaged[0] = true; |
8ec2b484 | 827 | |
da4cc40c | 828 | for (it = m_Data->GetContents(), i = 0; i < cnt; i++, it++) |
4f9297b0 | 829 | { |
576507e2 | 830 | // Handle books: |
da4cc40c | 831 | if (it->m_Level == 0) |
576507e2 | 832 | { |
e0952648 VS |
833 | if (m_hfStyle & wxHF_MERGE_BOOKS) |
834 | // VS: we don't want book nodes, books' content should | |
835 | // appear under tree's root. This line will create "fake" | |
836 | // record about book node so that the rest of this look | |
837 | // will believe there really _is_ book node and will | |
838 | // behave correctly. | |
839 | roots[1] = roots[0]; | |
840 | else | |
576507e2 | 841 | { |
e0952648 | 842 | roots[1] = m_ContentsBox->AppendItem(roots[0], |
0c55409f | 843 | it->m_Name, IMG_Book, -1, |
576507e2 | 844 | new wxHtmlHelpTreeItemData(i)); |
dabbc6a5 | 845 | m_ContentsBox->SetItemBold(roots[1], true); |
576507e2 | 846 | } |
dabbc6a5 | 847 | imaged[1] = true; |
4f9297b0 | 848 | } |
576507e2 | 849 | // ...and their contents: |
3379ed37 | 850 | else |
576507e2 VS |
851 | { |
852 | roots[it->m_Level + 1] = m_ContentsBox->AppendItem( | |
3379ed37 | 853 | roots[it->m_Level], it->m_Name, IMG_Page, |
576507e2 | 854 | -1, new wxHtmlHelpTreeItemData(i)); |
dabbc6a5 | 855 | imaged[it->m_Level + 1] = false; |
576507e2 | 856 | } |
4f9297b0 | 857 | |
576507e2 VS |
858 | m_PagesHash->Put(it->GetFullPath(), |
859 | new wxHtmlHelpHashData(i, roots[it->m_Level + 1])); | |
860 | ||
861 | // Set the icon for the node one level up in the hiearachy, | |
862 | // unless already done (see comment above imaged[] declaration) | |
da4cc40c | 863 | if (!imaged[it->m_Level]) |
3379ed37 | 864 | { |
576507e2 VS |
865 | int image = IMG_Folder; |
866 | if (m_hfStyle & wxHF_ICONS_BOOK) | |
867 | image = IMG_Book; | |
868 | else if (m_hfStyle & wxHF_ICONS_BOOK_CHAPTER) | |
869 | image = (it->m_Level == 1) ? IMG_Book : IMG_Folder; | |
870 | m_ContentsBox->SetItemImage(roots[it->m_Level], image); | |
b5f6b52a MB |
871 | m_ContentsBox->SetItemImage(roots[it->m_Level], image, |
872 | wxTreeItemIcon_Selected); | |
dabbc6a5 | 873 | imaged[it->m_Level] = true; |
8ec2b484 HH |
874 | } |
875 | } | |
8ec2b484 HH |
876 | } |
877 | ||
878 | ||
b5a7b000 | 879 | void wxHtmlHelpFrame::CreateIndex() |
8ec2b484 | 880 | { |
f0b6a33f | 881 | if (! m_IndexList) |
d5bb85a0 | 882 | return ; |
8ec2b484 | 883 | |
f0b6a33f | 884 | m_IndexList->Clear(); |
8ec2b484 HH |
885 | |
886 | int cnt = m_Data->GetIndexCnt(); | |
f6bcfd97 | 887 | |
240c2873 VS |
888 | wxString cnttext; |
889 | if (cnt > INDEX_IS_SMALL) cnttext.Printf(_("%i of %i"), 0, cnt); | |
890 | else cnttext.Printf(_("%i of %i"), cnt, cnt); | |
4f9297b0 | 891 | m_IndexCountInfo->SetLabel(cnttext); |
f0b6a33f | 892 | if (cnt > INDEX_IS_SMALL) return; |
f6bcfd97 | 893 | |
8ec2b484 HH |
894 | wxHtmlContentsItem* index = m_Data->GetIndex(); |
895 | ||
f6bcfd97 | 896 | for (int i = 0; i < cnt; i++) |
4f9297b0 | 897 | m_IndexList->Append(index[i].m_Name, (char*)(index + i)); |
8ec2b484 HH |
898 | } |
899 | ||
900 | void wxHtmlHelpFrame::CreateSearch() | |
901 | { | |
902 | if (! (m_SearchList && m_SearchChoice)) | |
d5bb85a0 | 903 | return ; |
4f9297b0 VS |
904 | m_SearchList->Clear(); |
905 | m_SearchChoice->Clear(); | |
906 | m_SearchChoice->Append(_("Search in all books")); | |
8ec2b484 HH |
907 | const wxHtmlBookRecArray& bookrec = m_Data->GetBookRecArray(); |
908 | int i, cnt = bookrec.GetCount(); | |
d5bb85a0 VS |
909 | for (i = 0; i < cnt; i++) |
910 | m_SearchChoice->Append(bookrec[i].GetTitle()); | |
8ec2b484 HH |
911 | m_SearchChoice->SetSelection(0); |
912 | } | |
913 | ||
914 | ||
b5a7b000 | 915 | void wxHtmlHelpFrame::RefreshLists() |
8ec2b484 | 916 | { |
b5a7b000 VS |
917 | CreateContents(); |
918 | CreateIndex(); | |
8ec2b484 HH |
919 | CreateSearch(); |
920 | } | |
921 | ||
922 | void wxHtmlHelpFrame::ReadCustomization(wxConfigBase *cfg, const wxString& path) | |
923 | { | |
924 | wxString oldpath; | |
925 | wxString tmp; | |
926 | ||
da4cc40c | 927 | if (path != wxEmptyString) |
4f9297b0 VS |
928 | { |
929 | oldpath = cfg->GetPath(); | |
930 | cfg->SetPath(_T("/") + path); | |
8ec2b484 HH |
931 | } |
932 | ||
4f9297b0 VS |
933 | m_Cfg.navig_on = cfg->Read(wxT("hcNavigPanel"), m_Cfg.navig_on) != 0; |
934 | m_Cfg.sashpos = cfg->Read(wxT("hcSashPos"), m_Cfg.sashpos); | |
935 | m_Cfg.x = cfg->Read(wxT("hcX"), m_Cfg.x); | |
936 | m_Cfg.y = cfg->Read(wxT("hcY"), m_Cfg.y); | |
937 | m_Cfg.w = cfg->Read(wxT("hcW"), m_Cfg.w); | |
938 | m_Cfg.h = cfg->Read(wxT("hcH"), m_Cfg.h); | |
8ec2b484 | 939 | |
4f9297b0 VS |
940 | m_FixedFace = cfg->Read(wxT("hcFixedFace"), m_FixedFace); |
941 | m_NormalFace = cfg->Read(wxT("hcNormalFace"), m_NormalFace); | |
c269cf62 | 942 | m_FontSize = cfg->Read(wxT("hcBaseFontSize"), m_FontSize); |
83efdf33 | 943 | |
382e6efe VS |
944 | { |
945 | int i; | |
946 | int cnt; | |
947 | wxString val, s; | |
f6bcfd97 | 948 | |
4f9297b0 | 949 | cnt = cfg->Read(wxT("hcBookmarksCnt"), 0L); |
da4cc40c | 950 | if (cnt != 0) |
3379ed37 | 951 | { |
382e6efe VS |
952 | m_BookmarksNames.Clear(); |
953 | m_BookmarksPages.Clear(); | |
da4cc40c | 954 | if (m_Bookmarks) |
3379ed37 | 955 | { |
4f9297b0 VS |
956 | m_Bookmarks->Clear(); |
957 | m_Bookmarks->Append(_("(bookmarks)")); | |
382e6efe | 958 | } |
f6bcfd97 | 959 | |
da4cc40c | 960 | for (i = 0; i < cnt; i++) |
3379ed37 | 961 | { |
0413cec5 | 962 | val.Printf(wxT("hcBookmark_%i"), i); |
4f9297b0 | 963 | s = cfg->Read(val); |
382e6efe | 964 | m_BookmarksNames.Add(s); |
4f9297b0 | 965 | if (m_Bookmarks) m_Bookmarks->Append(s); |
0413cec5 | 966 | val.Printf(wxT("hcBookmark_%i_url"), i); |
4f9297b0 | 967 | s = cfg->Read(val); |
382e6efe VS |
968 | m_BookmarksPages.Add(s); |
969 | } | |
970 | } | |
971 | } | |
972 | ||
8ec2b484 | 973 | if (m_HtmlWin) |
3e5296e7 | 974 | m_HtmlWin->ReadCustomization(cfg); |
8ec2b484 HH |
975 | |
976 | if (path != wxEmptyString) | |
4f9297b0 | 977 | cfg->SetPath(oldpath); |
8ec2b484 HH |
978 | } |
979 | ||
980 | void wxHtmlHelpFrame::WriteCustomization(wxConfigBase *cfg, const wxString& path) | |
981 | { | |
982 | wxString oldpath; | |
983 | wxString tmp; | |
8ec2b484 | 984 | |
da4cc40c | 985 | if (path != wxEmptyString) |
4f9297b0 VS |
986 | { |
987 | oldpath = cfg->GetPath(); | |
988 | cfg->SetPath(_T("/") + path); | |
8ec2b484 HH |
989 | } |
990 | ||
4f9297b0 VS |
991 | cfg->Write(wxT("hcNavigPanel"), m_Cfg.navig_on); |
992 | cfg->Write(wxT("hcSashPos"), (long)m_Cfg.sashpos); | |
2b5f62a0 VZ |
993 | if ( !IsIconized() ) |
994 | { | |
995 | // Don't write if iconized as this would make the window | |
996 | // disappear next time it is shown! | |
997 | cfg->Write(wxT("hcX"), (long)m_Cfg.x); | |
998 | cfg->Write(wxT("hcY"), (long)m_Cfg.y); | |
999 | cfg->Write(wxT("hcW"), (long)m_Cfg.w); | |
1000 | cfg->Write(wxT("hcH"), (long)m_Cfg.h); | |
1001 | } | |
4f9297b0 VS |
1002 | cfg->Write(wxT("hcFixedFace"), m_FixedFace); |
1003 | cfg->Write(wxT("hcNormalFace"), m_NormalFace); | |
c269cf62 | 1004 | cfg->Write(wxT("hcBaseFontSize"), (long)m_FontSize); |
4f9297b0 | 1005 | |
da4cc40c | 1006 | if (m_Bookmarks) |
4f9297b0 | 1007 | { |
382e6efe VS |
1008 | int i; |
1009 | int cnt = m_BookmarksNames.GetCount(); | |
1010 | wxString val; | |
f6bcfd97 | 1011 | |
4f9297b0 | 1012 | cfg->Write(wxT("hcBookmarksCnt"), (long)cnt); |
da4cc40c | 1013 | for (i = 0; i < cnt; i++) |
3379ed37 | 1014 | { |
0413cec5 | 1015 | val.Printf(wxT("hcBookmark_%i"), i); |
4f9297b0 | 1016 | cfg->Write(val, m_BookmarksNames[i]); |
0413cec5 | 1017 | val.Printf(wxT("hcBookmark_%i_url"), i); |
4f9297b0 | 1018 | cfg->Write(val, m_BookmarksPages[i]); |
382e6efe VS |
1019 | } |
1020 | } | |
8ec2b484 HH |
1021 | |
1022 | if (m_HtmlWin) | |
3e5296e7 | 1023 | m_HtmlWin->WriteCustomization(cfg); |
8ec2b484 HH |
1024 | |
1025 | if (path != wxEmptyString) | |
4f9297b0 | 1026 | cfg->SetPath(oldpath); |
8ec2b484 HH |
1027 | } |
1028 | ||
1029 | ||
83efdf33 VS |
1030 | |
1031 | ||
1032 | ||
8eb2940f | 1033 | static void SetFontsToHtmlWin(wxHtmlWindow *win, wxString scalf, wxString fixf, int size) |
83efdf33 | 1034 | { |
c269cf62 VS |
1035 | int f_sizes[7]; |
1036 | f_sizes[0] = int(size * 0.6); | |
1037 | f_sizes[1] = int(size * 0.8); | |
1038 | f_sizes[2] = size; | |
1039 | f_sizes[3] = int(size * 1.2); | |
1040 | f_sizes[4] = int(size * 1.4); | |
1041 | f_sizes[5] = int(size * 1.6); | |
1042 | f_sizes[6] = int(size * 1.8); | |
1043 | ||
1044 | win->SetFonts(scalf, fixf, f_sizes); | |
83efdf33 VS |
1045 | } |
1046 | ||
1047 | ||
1048 | class wxHtmlHelpFrameOptionsDialog : public wxDialog | |
1049 | { | |
c269cf62 VS |
1050 | public: |
1051 | wxComboBox *NormalFont, *FixedFont; | |
1052 | wxSpinCtrl *FontSize; | |
1053 | wxHtmlWindow *TestWin; | |
83efdf33 | 1054 | |
dabbc6a5 DS |
1055 | wxHtmlHelpFrameOptionsDialog(wxWindow *parent) |
1056 | : wxDialog(parent, wxID_ANY, wxString(_("Help Browser Options"))) | |
c269cf62 VS |
1057 | { |
1058 | wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL); | |
1059 | wxFlexGridSizer *sizer = new wxFlexGridSizer(2, 3, 2, 5); | |
1060 | ||
dabbc6a5 DS |
1061 | sizer->Add(new wxStaticText(this, wxID_ANY, _("Normal font:"))); |
1062 | sizer->Add(new wxStaticText(this, wxID_ANY, _("Fixed font:"))); | |
1063 | sizer->Add(new wxStaticText(this, wxID_ANY, _("Font size:"))); | |
c269cf62 | 1064 | |
dabbc6a5 | 1065 | sizer->Add(NormalFont = new wxComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, |
c269cf62 VS |
1066 | wxSize(200, 200), |
1067 | 0, NULL, wxCB_DROPDOWN | wxCB_READONLY)); | |
1068 | ||
dabbc6a5 | 1069 | sizer->Add(FixedFont = new wxComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, |
c269cf62 VS |
1070 | wxSize(200, 200), |
1071 | 0, NULL, wxCB_DROPDOWN | wxCB_READONLY)); | |
1072 | ||
dabbc6a5 | 1073 | sizer->Add(FontSize = new wxSpinCtrl(this, wxID_ANY)); |
c269cf62 VS |
1074 | FontSize->SetRange(2, 100); |
1075 | ||
1076 | topsizer->Add(sizer, 0, wxLEFT|wxRIGHT|wxTOP, 10); | |
1077 | ||
dabbc6a5 | 1078 | topsizer->Add(new wxStaticText(this, wxID_ANY, _("Preview:")), |
c269cf62 | 1079 | 0, wxLEFT | wxTOP, 10); |
dabbc6a5 | 1080 | topsizer->Add(TestWin = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxSize(20, 150), |
c269cf62 VS |
1081 | wxHW_SCROLLBAR_AUTO | wxSUNKEN_BORDER), |
1082 | 1, wxEXPAND | wxLEFT|wxTOP|wxRIGHT, 10); | |
1083 | ||
1084 | wxBoxSizer *sizer2 = new wxBoxSizer(wxHORIZONTAL); | |
1085 | wxButton *ok; | |
1086 | sizer2->Add(ok = new wxButton(this, wxID_OK, _("OK")), 0, wxALL, 10); | |
1087 | ok->SetDefault(); | |
1088 | sizer2->Add(new wxButton(this, wxID_CANCEL, _("Cancel")), 0, wxALL, 10); | |
1089 | topsizer->Add(sizer2, 0, wxALIGN_RIGHT); | |
1090 | ||
c269cf62 VS |
1091 | SetSizer(topsizer); |
1092 | topsizer->Fit(this); | |
1093 | Centre(wxBOTH); | |
1094 | } | |
f6bcfd97 | 1095 | |
83efdf33 | 1096 | |
c269cf62 VS |
1097 | void UpdateTestWin() |
1098 | { | |
1099 | wxBusyCursor bcur; | |
1100 | SetFontsToHtmlWin(TestWin, | |
1101 | NormalFont->GetStringSelection(), | |
1102 | FixedFont->GetStringSelection(), | |
1103 | FontSize->GetValue()); | |
311ccb86 VZ |
1104 | |
1105 | wxString content(_("font size")); | |
1106 | ||
1107 | content = _T("<font size=-2>") + content + _T(" -2</font><br>") | |
1108 | _T("<font size=-1>") + content + _T(" -1</font><br>") | |
1109 | _T("<font size=+0>") + content + _T(" +0</font><br>") | |
1110 | _T("<font size=+1>") + content + _T(" +1</font><br>") | |
1111 | _T("<font size=+2>") + content + _T(" +2</font><br>") | |
1112 | _T("<font size=+3>") + content + _T(" +3</font><br>") | |
1113 | _T("<font size=+4>") + content + _T(" +4</font><br>") ; | |
1114 | ||
1115 | content = wxString( _T("<html><body><table><tr><td>") ) + | |
1116 | _("Normal face<br>and <u>underlined</u>. ") + | |
1117 | _("<i>Italic face.</i> ") + | |
1118 | _("<b>Bold face.</b> ") + | |
1119 | _("<b><i>Bold italic face.</i></b><br>") + | |
1120 | content + | |
1121 | wxString( _T("</td><td><tt>") ) + | |
1122 | _("Fixed size face.<br> <b>bold</b> <i>italic</i> ") + | |
1123 | _("<b><i>bold italic <u>underlined</u></i></b><br>") + | |
1124 | content + | |
1125 | _T("</tt></td></tr></table></body></html>"); | |
1126 | ||
1127 | TestWin->SetPage( content ); | |
c269cf62 | 1128 | } |
83efdf33 | 1129 | |
c269cf62 VS |
1130 | void OnUpdate(wxCommandEvent& WXUNUSED(event)) |
1131 | { | |
1132 | UpdateTestWin(); | |
1133 | } | |
aab49a0b JS |
1134 | void OnUpdateSpin(wxSpinEvent& WXUNUSED(event)) |
1135 | { | |
1136 | UpdateTestWin(); | |
1137 | } | |
83efdf33 | 1138 | |
c269cf62 | 1139 | DECLARE_EVENT_TABLE() |
22f3361e | 1140 | DECLARE_NO_COPY_CLASS(wxHtmlHelpFrameOptionsDialog) |
83efdf33 VS |
1141 | }; |
1142 | ||
1143 | BEGIN_EVENT_TABLE(wxHtmlHelpFrameOptionsDialog, wxDialog) | |
dabbc6a5 DS |
1144 | EVT_COMBOBOX(wxID_ANY, wxHtmlHelpFrameOptionsDialog::OnUpdate) |
1145 | EVT_SPINCTRL(wxID_ANY, wxHtmlHelpFrameOptionsDialog::OnUpdateSpin) | |
83efdf33 VS |
1146 | END_EVENT_TABLE() |
1147 | ||
83efdf33 VS |
1148 | void wxHtmlHelpFrame::OptionsDialog() |
1149 | { | |
1150 | wxHtmlHelpFrameOptionsDialog dlg(this); | |
1151 | unsigned i; | |
f6bcfd97 | 1152 | |
da4cc40c | 1153 | if (m_NormalFonts == NULL) |
4f9297b0 | 1154 | { |
83efdf33 VS |
1155 | wxFontEnumerator enu; |
1156 | enu.EnumerateFacenames(); | |
1157 | m_NormalFonts = new wxArrayString; | |
1158 | *m_NormalFonts = *enu.GetFacenames(); | |
222ed1d6 | 1159 | m_NormalFonts->Sort(wxStringSortAscending); |
83efdf33 | 1160 | } |
da4cc40c | 1161 | if (m_FixedFonts == NULL) |
4f9297b0 | 1162 | { |
83efdf33 | 1163 | wxFontEnumerator enu; |
dabbc6a5 | 1164 | enu.EnumerateFacenames(wxFONTENCODING_SYSTEM, true /*enum fixed width only*/); |
83efdf33 VS |
1165 | m_FixedFonts = new wxArrayString; |
1166 | *m_FixedFonts = *enu.GetFacenames(); | |
222ed1d6 | 1167 | m_FixedFonts->Sort(wxStringSortAscending); |
83efdf33 | 1168 | } |
dabbc6a5 | 1169 | |
c269cf62 VS |
1170 | // VS: We want to show the font that is actually used by wxHtmlWindow. |
1171 | // If customization dialog wasn't used yet, facenames are empty and | |
1172 | // wxHtmlWindow uses default fonts -- let's find out what they | |
1173 | // are so that we can pass them to the dialog: | |
1174 | if (m_NormalFace.empty()) | |
1175 | { | |
dabbc6a5 | 1176 | wxFont fnt(m_FontSize, wxSWISS, wxNORMAL, wxNORMAL, false); |
c269cf62 VS |
1177 | m_NormalFace = fnt.GetFaceName(); |
1178 | } | |
1179 | if (m_FixedFace.empty()) | |
1180 | { | |
dabbc6a5 | 1181 | wxFont fnt(m_FontSize, wxMODERN, wxNORMAL, wxNORMAL, false); |
c269cf62 VS |
1182 | m_FixedFace = fnt.GetFaceName(); |
1183 | } | |
f6bcfd97 | 1184 | |
4f9297b0 VS |
1185 | for (i = 0; i < m_NormalFonts->GetCount(); i++) |
1186 | dlg.NormalFont->Append((*m_NormalFonts)[i]); | |
1187 | for (i = 0; i < m_FixedFonts->GetCount(); i++) | |
1188 | dlg.FixedFont->Append((*m_FixedFonts)[i]); | |
c269cf62 VS |
1189 | if (!m_NormalFace.empty()) |
1190 | dlg.NormalFont->SetStringSelection(m_NormalFace); | |
1191 | else | |
1affde0a | 1192 | dlg.NormalFont->SetSelection(0); |
c269cf62 VS |
1193 | if (!m_FixedFace.empty()) |
1194 | dlg.FixedFont->SetStringSelection(m_FixedFace); | |
1195 | else | |
1196 | dlg.FixedFont->SetSelection(0); | |
1197 | dlg.FontSize->SetValue(m_FontSize); | |
83efdf33 | 1198 | dlg.UpdateTestWin(); |
f6bcfd97 | 1199 | |
da4cc40c | 1200 | if (dlg.ShowModal() == wxID_OK) |
4f9297b0 VS |
1201 | { |
1202 | m_NormalFace = dlg.NormalFont->GetStringSelection(); | |
1203 | m_FixedFace = dlg.FixedFont->GetStringSelection(); | |
c269cf62 | 1204 | m_FontSize = dlg.FontSize->GetValue(); |
8eb2940f | 1205 | SetFontsToHtmlWin(m_HtmlWin, m_NormalFace, m_FixedFace, m_FontSize); |
83efdf33 VS |
1206 | } |
1207 | } | |
1208 | ||
1209 | ||
1210 | ||
0646614d VS |
1211 | void wxHtmlHelpFrame::NotifyPageChanged() |
1212 | { | |
1213 | if (m_UpdateContents && m_PagesHash) | |
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 | 1220 | ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage() + wxT("#") + an); |
0646614d VS |
1221 | if (ha) |
1222 | { | |
1223 | bool olduc = m_UpdateContents; | |
dabbc6a5 | 1224 | m_UpdateContents = false; |
4f9297b0 VS |
1225 | m_ContentsBox->SelectItem(ha->m_Id); |
1226 | m_ContentsBox->EnsureVisible(ha->m_Id); | |
0646614d VS |
1227 | m_UpdateContents = olduc; |
1228 | } | |
1229 | } | |
1230 | } | |
1231 | ||
83efdf33 VS |
1232 | |
1233 | ||
8ec2b484 HH |
1234 | /* |
1235 | EVENT HANDLING : | |
1236 | */ | |
1237 | ||
1238 | ||
d45bc436 RR |
1239 | void wxHtmlHelpFrame::OnActivate(wxActivateEvent& event) |
1240 | { | |
1241 | // This saves one mouse click when using the | |
1242 | // wxHTML for context sensitive help systems | |
2b5f62a0 VZ |
1243 | #ifndef __WXGTK__ |
1244 | // NB: wxActivateEvent is a bit broken in wxGTK | |
1245 | // and is sometimes sent when it should not be | |
d45bc436 RR |
1246 | if (event.GetActive() && m_HtmlWin) |
1247 | m_HtmlWin->SetFocus(); | |
2b5f62a0 | 1248 | #endif |
fbd90401 VS |
1249 | |
1250 | event.Skip(); | |
d45bc436 RR |
1251 | } |
1252 | ||
8ec2b484 HH |
1253 | void wxHtmlHelpFrame::OnToolbar(wxCommandEvent& event) |
1254 | { | |
da4cc40c | 1255 | switch (event.GetId()) |
4f9297b0 | 1256 | { |
8ec2b484 | 1257 | case wxID_HTML_BACK : |
4f9297b0 | 1258 | m_HtmlWin->HistoryBack(); |
0646614d | 1259 | NotifyPageChanged(); |
8ec2b484 | 1260 | break; |
382e6efe | 1261 | |
8ec2b484 | 1262 | case wxID_HTML_FORWARD : |
4f9297b0 | 1263 | m_HtmlWin->HistoryForward(); |
0646614d VS |
1264 | NotifyPageChanged(); |
1265 | break; | |
f6bcfd97 BP |
1266 | |
1267 | case wxID_HTML_UP : | |
1268 | if (m_PagesHash) | |
0646614d | 1269 | { |
4f9297b0 | 1270 | wxString an = m_HtmlWin->GetOpenedAnchor(); |
0646614d VS |
1271 | wxHtmlHelpHashData *ha; |
1272 | if (an.IsEmpty()) | |
4f9297b0 | 1273 | ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage()); |
0646614d | 1274 | else |
4f9297b0 VS |
1275 | ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage() + wxT("#") + an); |
1276 | if (ha && ha->m_Index > 0) | |
0646614d | 1277 | { |
4f9297b0 | 1278 | wxHtmlContentsItem *it = m_Data->GetContents() + (ha->m_Index - 1); |
7df9fbc3 JS |
1279 | if (it->m_Page[0] != 0) |
1280 | { | |
468ae730 | 1281 | m_HtmlWin->LoadPage(it->GetFullPath()); |
7df9fbc3 JS |
1282 | NotifyPageChanged(); |
1283 | } | |
0646614d VS |
1284 | } |
1285 | } | |
1286 | break; | |
1287 | ||
f6bcfd97 BP |
1288 | case wxID_HTML_UPNODE : |
1289 | if (m_PagesHash) | |
0646614d | 1290 | { |
4f9297b0 | 1291 | wxString an = m_HtmlWin->GetOpenedAnchor(); |
0646614d VS |
1292 | wxHtmlHelpHashData *ha; |
1293 | if (an.IsEmpty()) | |
4f9297b0 | 1294 | ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage()); |
0646614d | 1295 | else |
4f9297b0 VS |
1296 | ha = (wxHtmlHelpHashData*) m_PagesHash->Get(m_HtmlWin->GetOpenedPage() + wxT("#") + an); |
1297 | if (ha && ha->m_Index > 0) | |
0646614d | 1298 | { |
4f9297b0 | 1299 | int level = m_Data->GetContents()[ha->m_Index].m_Level - 1; |
0646614d | 1300 | wxHtmlContentsItem *it; |
4f9297b0 | 1301 | int ind = ha->m_Index - 1; |
f6bcfd97 | 1302 | |
4f9297b0 VS |
1303 | it = m_Data->GetContents() + ind; |
1304 | while (ind >= 0 && it->m_Level != level) ind--, it--; | |
0646614d VS |
1305 | if (ind >= 0) |
1306 | { | |
7df9fbc3 JS |
1307 | if (it->m_Page[0] != 0) |
1308 | { | |
468ae730 | 1309 | m_HtmlWin->LoadPage(it->GetFullPath()); |
7df9fbc3 JS |
1310 | NotifyPageChanged(); |
1311 | } | |
0646614d VS |
1312 | } |
1313 | } | |
1314 | } | |
1315 | break; | |
1316 | ||
f6bcfd97 BP |
1317 | case wxID_HTML_DOWN : |
1318 | if (m_PagesHash) | |
0646614d | 1319 | { |
4f9297b0 | 1320 | wxString an = m_HtmlWin->GetOpenedAnchor(); |
721ab905 | 1321 | wxString adr; |
0646614d | 1322 | wxHtmlHelpHashData *ha; |
f6bcfd97 | 1323 | |
4f9297b0 VS |
1324 | if (an.IsEmpty()) adr = m_HtmlWin->GetOpenedPage(); |
1325 | else adr = m_HtmlWin->GetOpenedPage() + wxT("#") + an; | |
721ab905 | 1326 | |
4f9297b0 | 1327 | ha = (wxHtmlHelpHashData*) m_PagesHash->Get(adr); |
0646614d | 1328 | |
4f9297b0 | 1329 | if (ha && ha->m_Index < m_Data->GetContentsCnt() - 1) |
0646614d | 1330 | { |
4f9297b0 | 1331 | wxHtmlContentsItem *it = m_Data->GetContents() + (ha->m_Index + 1); |
f6bcfd97 | 1332 | |
468ae730 | 1333 | while (it->GetFullPath() == adr) it++; |
7df9fbc3 JS |
1334 | |
1335 | if (it->m_Page[0] != 0) | |
1336 | { | |
468ae730 | 1337 | m_HtmlWin->LoadPage(it->GetFullPath()); |
7df9fbc3 JS |
1338 | NotifyPageChanged(); |
1339 | } | |
0646614d VS |
1340 | } |
1341 | } | |
8ec2b484 | 1342 | break; |
382e6efe | 1343 | |
8ec2b484 | 1344 | case wxID_HTML_PANEL : |
0646614d VS |
1345 | { |
1346 | if (! (m_Splitter && m_NavigPan)) | |
1347 | return ; | |
da4cc40c | 1348 | if (m_Splitter->IsSplit()) |
3379ed37 | 1349 | { |
4f9297b0 VS |
1350 | m_Cfg.sashpos = m_Splitter->GetSashPosition(); |
1351 | m_Splitter->Unsplit(m_NavigPan); | |
dabbc6a5 | 1352 | m_Cfg.navig_on = false; |
da4cc40c | 1353 | } |
3379ed37 VZ |
1354 | else |
1355 | { | |
dabbc6a5 DS |
1356 | m_NavigPan->Show(); |
1357 | m_HtmlWin->Show(); | |
4f9297b0 | 1358 | m_Splitter->SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); |
dabbc6a5 | 1359 | m_Cfg.navig_on = true; |
0646614d | 1360 | } |
8ec2b484 HH |
1361 | } |
1362 | break; | |
382e6efe | 1363 | |
83efdf33 VS |
1364 | case wxID_HTML_OPTIONS : |
1365 | OptionsDialog(); | |
1366 | break; | |
f6bcfd97 BP |
1367 | |
1368 | case wxID_HTML_BOOKMARKSADD : | |
382e6efe VS |
1369 | { |
1370 | wxString item; | |
1371 | wxString url; | |
f6bcfd97 | 1372 | |
4f9297b0 VS |
1373 | item = m_HtmlWin->GetOpenedPageTitle(); |
1374 | url = m_HtmlWin->GetOpenedPage(); | |
da4cc40c | 1375 | if (item == wxEmptyString) |
3379ed37 | 1376 | item = url.AfterLast(wxT('/')); |
da4cc40c | 1377 | if (m_BookmarksPages.Index(url) == wxNOT_FOUND) |
3379ed37 | 1378 | { |
4f9297b0 | 1379 | m_Bookmarks->Append(item); |
382e6efe VS |
1380 | m_BookmarksNames.Add(item); |
1381 | m_BookmarksPages.Add(url); | |
1382 | } | |
1383 | } | |
1384 | break; | |
f6bcfd97 BP |
1385 | |
1386 | case wxID_HTML_BOOKMARKSREMOVE : | |
382e6efe VS |
1387 | { |
1388 | wxString item; | |
1389 | int pos; | |
f6bcfd97 | 1390 | |
4f9297b0 | 1391 | item = m_Bookmarks->GetStringSelection(); |
382e6efe | 1392 | pos = m_BookmarksNames.Index(item); |
da4cc40c | 1393 | if (pos != wxNOT_FOUND) |
3379ed37 | 1394 | { |
ba8c1601 MB |
1395 | m_BookmarksNames.RemoveAt(pos); |
1396 | m_BookmarksPages.RemoveAt(pos); | |
4f9297b0 | 1397 | m_Bookmarks->Delete(m_Bookmarks->GetSelection()); |
382e6efe VS |
1398 | } |
1399 | } | |
1400 | break; | |
0646614d VS |
1401 | |
1402 | #if wxUSE_PRINTING_ARCHITECTURE | |
1403 | case wxID_HTML_PRINT : | |
1404 | { | |
f6bcfd97 | 1405 | if (m_Printer == NULL) |
0646614d | 1406 | m_Printer = new wxHtmlEasyPrinting(_("Help Printing"), this); |
4f9297b0 | 1407 | if (!m_HtmlWin->GetOpenedPage()) |
f5ba273e VS |
1408 | wxLogWarning(_("Cannot print empty page.")); |
1409 | else | |
4f9297b0 | 1410 | m_Printer->PrintFile(m_HtmlWin->GetOpenedPage()); |
0646614d VS |
1411 | } |
1412 | break; | |
1413 | #endif | |
1414 | ||
1415 | case wxID_HTML_OPENFILE : | |
1416 | { | |
3527f29c VS |
1417 | wxString filemask = wxString( |
1418 | _("HTML files (*.html;*.htm)|*.html;*.htm|")) + | |
1419 | _("Help books (*.htb)|*.htb|Help books (*.zip)|*.zip|") + | |
1420 | _("HTML Help Project (*.hhp)|*.hhp|") + | |
1421 | #if wxUSE_LIBMSPACK | |
1422 | _("Compressed HTML Help file (*.chm)|*.chm|") + | |
1423 | #endif | |
1424 | _("All files (*.*)|*"); | |
f6bcfd97 BP |
1425 | wxString s = wxFileSelector(_("Open HTML document"), |
1426 | wxEmptyString, | |
1427 | wxEmptyString, | |
1428 | wxEmptyString, | |
3527f29c | 1429 | filemask, |
f6bcfd97 BP |
1430 | wxOPEN | wxFILE_MUST_EXIST, |
1431 | this); | |
0646614d VS |
1432 | if (!s.IsEmpty()) |
1433 | { | |
1434 | wxString ext = s.Right(4).Lower(); | |
3527f29c VS |
1435 | if (ext == _T(".zip") || ext == _T(".htb") || |
1436 | #if wxUSE_LIBMSPACK | |
1437 | ext == _T(".chm") || | |
1438 | #endif | |
1439 | ext == _T(".hhp")) | |
0646614d VS |
1440 | { |
1441 | wxBusyCursor bcur; | |
4f9297b0 | 1442 | m_Data->AddBook(s); |
0646614d VS |
1443 | RefreshLists(); |
1444 | } | |
1445 | else | |
4f9297b0 | 1446 | m_HtmlWin->LoadPage(s); |
0646614d VS |
1447 | } |
1448 | } | |
1449 | break; | |
8ec2b484 HH |
1450 | } |
1451 | } | |
1452 | ||
1453 | ||
1454 | ||
1455 | void wxHtmlHelpFrame::OnContentsSel(wxTreeEvent& event) | |
1456 | { | |
1457 | wxHtmlHelpTreeItemData *pg; | |
0646614d | 1458 | wxHtmlContentsItem *it; |
8ec2b484 | 1459 | |
4f9297b0 | 1460 | pg = (wxHtmlHelpTreeItemData*) m_ContentsBox->GetItemData(event.GetItem()); |
f6bcfd97 BP |
1461 | |
1462 | if (pg && m_UpdateContents) | |
0646614d | 1463 | { |
4f9297b0 | 1464 | it = m_Data->GetContents() + (pg->m_Id); |
dabbc6a5 | 1465 | m_UpdateContents = false; |
7df9fbc3 | 1466 | if (it->m_Page[0] != 0) |
468ae730 | 1467 | m_HtmlWin->LoadPage(it->GetFullPath()); |
dabbc6a5 | 1468 | m_UpdateContents = true; |
0646614d | 1469 | } |
8ec2b484 HH |
1470 | } |
1471 | ||
1472 | ||
1473 | ||
a4c97004 | 1474 | void wxHtmlHelpFrame::OnIndexSel(wxCommandEvent& WXUNUSED(event)) |
8ec2b484 | 1475 | { |
4f9297b0 | 1476 | wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_IndexList->GetClientData(m_IndexList->GetSelection()); |
7df9fbc3 | 1477 | if (it->m_Page[0] != 0) |
468ae730 | 1478 | m_HtmlWin->LoadPage(it->GetFullPath()); |
0646614d | 1479 | NotifyPageChanged(); |
8ec2b484 HH |
1480 | } |
1481 | ||
1482 | ||
f0b6a33f VS |
1483 | void wxHtmlHelpFrame::OnIndexFind(wxCommandEvent& event) |
1484 | { | |
4f9297b0 | 1485 | wxString sr = m_IndexText->GetLineText(0); |
240c2873 | 1486 | sr.MakeLower(); |
f6bcfd97 | 1487 | if (sr == wxEmptyString) |
4f9297b0 | 1488 | { |
f0b6a33f | 1489 | OnIndexAll(event); |
4f9297b0 | 1490 | } |
da4cc40c | 1491 | else |
4f9297b0 | 1492 | { |
f0b6a33f VS |
1493 | wxBusyCursor bcur; |
1494 | const wxChar *cstr = sr.c_str(); | |
33ac7e6f | 1495 | wxChar mybuff[512]; |
3379ed37 | 1496 | wxChar *ptr; |
dabbc6a5 | 1497 | bool first = true; |
f6bcfd97 | 1498 | |
f0b6a33f VS |
1499 | m_IndexList->Clear(); |
1500 | int cnt = m_Data->GetIndexCnt(); | |
1501 | wxHtmlContentsItem* index = m_Data->GetIndex(); | |
1502 | ||
240c2873 | 1503 | int displ = 0; |
f0b6a33f | 1504 | for (int i = 0; i < cnt; i++) |
240c2873 VS |
1505 | { |
1506 | wxStrncpy(mybuff, index[i].m_Name, 512); | |
f6bcfd97 BP |
1507 | mybuff[511] = _T('\0'); |
1508 | for (ptr = mybuff; *ptr != 0; ptr++) | |
1509 | if (*ptr >= _T('A') && *ptr <= _T('Z')) | |
1510 | *ptr -= (wxChar)(_T('A') - _T('a')); | |
da4cc40c | 1511 | if (wxStrstr(mybuff, cstr) != NULL) |
3379ed37 | 1512 | { |
4f9297b0 | 1513 | m_IndexList->Append(index[i].m_Name, (char*)(index + i)); |
240c2873 | 1514 | displ++; |
da4cc40c | 1515 | if (first) |
3379ed37 | 1516 | { |
7df9fbc3 | 1517 | if (index[i].m_Page[0] != 0) |
468ae730 | 1518 | m_HtmlWin->LoadPage(index[i].GetFullPath()); |
0646614d | 1519 | NotifyPageChanged(); |
dabbc6a5 | 1520 | first = false; |
f0b6a33f VS |
1521 | } |
1522 | } | |
240c2873 VS |
1523 | } |
1524 | ||
1525 | wxString cnttext; | |
1526 | cnttext.Printf(_("%i of %i"), displ, cnt); | |
4f9297b0 | 1527 | m_IndexCountInfo->SetLabel(cnttext); |
f0b6a33f | 1528 | |
4f9297b0 VS |
1529 | m_IndexText->SetSelection(0, sr.Length()); |
1530 | m_IndexText->SetFocus(); | |
f0b6a33f VS |
1531 | } |
1532 | } | |
1533 | ||
1534 | void wxHtmlHelpFrame::OnIndexAll(wxCommandEvent& WXUNUSED(event)) | |
1535 | { | |
1536 | wxBusyCursor bcur; | |
f6bcfd97 | 1537 | |
f0b6a33f VS |
1538 | m_IndexList->Clear(); |
1539 | int cnt = m_Data->GetIndexCnt(); | |
dabbc6a5 | 1540 | bool first = true; |
f0b6a33f VS |
1541 | wxHtmlContentsItem* index = m_Data->GetIndex(); |
1542 | ||
da4cc40c | 1543 | for (int i = 0; i < cnt; i++) |
4f9297b0 VS |
1544 | { |
1545 | m_IndexList->Append(index[i].m_Name, (char*)(index + i)); | |
da4cc40c | 1546 | if (first) |
3379ed37 | 1547 | { |
7df9fbc3 | 1548 | if (index[i].m_Page[0] != 0) |
468ae730 | 1549 | m_HtmlWin->LoadPage(index[i].GetFullPath()); |
0646614d | 1550 | NotifyPageChanged(); |
dabbc6a5 | 1551 | first = false; |
f0b6a33f VS |
1552 | } |
1553 | } | |
240c2873 VS |
1554 | |
1555 | wxString cnttext; | |
1556 | cnttext.Printf(_("%i of %i"), cnt, cnt); | |
4f9297b0 | 1557 | m_IndexCountInfo->SetLabel(cnttext); |
f0b6a33f VS |
1558 | } |
1559 | ||
8ec2b484 | 1560 | |
a4c97004 | 1561 | void wxHtmlHelpFrame::OnSearchSel(wxCommandEvent& WXUNUSED(event)) |
8ec2b484 | 1562 | { |
4f9297b0 | 1563 | wxHtmlContentsItem *it = (wxHtmlContentsItem*) m_SearchList->GetClientData(m_SearchList->GetSelection()); |
f6bcfd97 | 1564 | if (it) |
0646614d | 1565 | { |
7df9fbc3 | 1566 | if (it->m_Page[0] != 0) |
468ae730 | 1567 | m_HtmlWin->LoadPage(it->GetFullPath()); |
0646614d VS |
1568 | NotifyPageChanged(); |
1569 | } | |
8ec2b484 HH |
1570 | } |
1571 | ||
a4c97004 | 1572 | void wxHtmlHelpFrame::OnSearch(wxCommandEvent& WXUNUSED(event)) |
8ec2b484 | 1573 | { |
4f9297b0 | 1574 | wxString sr = m_SearchText->GetLineText(0); |
8ec2b484 | 1575 | |
69b5cec2 VS |
1576 | if (!sr.empty()) |
1577 | KeywordSearch(sr, wxHELP_SEARCH_ALL); | |
8ec2b484 HH |
1578 | } |
1579 | ||
382e6efe VS |
1580 | void wxHtmlHelpFrame::OnBookmarksSel(wxCommandEvent& WXUNUSED(event)) |
1581 | { | |
4f9297b0 | 1582 | wxString sr = m_Bookmarks->GetStringSelection(); |
382e6efe | 1583 | |
ae80f837 | 1584 | if (sr != wxEmptyString && sr != _("(bookmarks)")) |
0646614d | 1585 | { |
4f9297b0 | 1586 | m_HtmlWin->LoadPage(m_BookmarksPages[m_BookmarksNames.Index(sr)]); |
0646614d VS |
1587 | NotifyPageChanged(); |
1588 | } | |
382e6efe VS |
1589 | } |
1590 | ||
8ec2b484 HH |
1591 | void wxHtmlHelpFrame::OnCloseWindow(wxCloseEvent& evt) |
1592 | { | |
68364659 VS |
1593 | GetSize(&m_Cfg.w, &m_Cfg.h); |
1594 | GetPosition(&m_Cfg.x, &m_Cfg.y); | |
5c172c17 | 1595 | |
5152b0e5 JS |
1596 | #ifdef __WXGTK__ |
1597 | if (IsGrabbed()) | |
1598 | { | |
1599 | RemoveGrab(); | |
1600 | } | |
1601 | #endif | |
dabbc6a5 | 1602 | |
4f9297b0 | 1603 | if (m_Splitter && m_Cfg.navig_on) m_Cfg.sashpos = m_Splitter->GetSashPosition(); |
68364659 | 1604 | |
d5bb85a0 VS |
1605 | if (m_Config) |
1606 | WriteCustomization(m_Config, m_ConfigRoot); | |
68364659 | 1607 | |
b4414c1f JS |
1608 | if (m_helpController && m_helpController->IsKindOf(CLASSINFO(wxHtmlHelpController))) |
1609 | { | |
1610 | ((wxHtmlHelpController*) m_helpController)->OnCloseFrame(evt); | |
1611 | } | |
1612 | ||
8ec2b484 HH |
1613 | evt.Skip(); |
1614 | } | |
1615 | ||
d9b21c9f | 1616 | #ifdef __WXMAC__ |
4aa31786 | 1617 | void wxHtmlHelpFrame::OnClose(wxCommandEvent& event) |
d9b21c9f | 1618 | { |
dabbc6a5 | 1619 | Close(true); |
d9b21c9f JS |
1620 | } |
1621 | ||
1622 | void wxHtmlHelpFrame::OnAbout(wxCommandEvent& event) | |
1623 | { | |
77ffb593 | 1624 | wxMessageBox(wxT("wxWidgets HTML Help Viewer (c) 1998-2003, Vaclav Slavik et al"), wxT("HelpView"), |
d9b21c9f JS |
1625 | wxICON_INFORMATION|wxOK, this); |
1626 | } | |
1627 | #endif | |
1628 | ||
8ec2b484 | 1629 | BEGIN_EVENT_TABLE(wxHtmlHelpFrame, wxFrame) |
d45bc436 | 1630 | EVT_ACTIVATE(wxHtmlHelpFrame::OnActivate) |
ae80f837 VS |
1631 | EVT_TOOL_RANGE(wxID_HTML_PANEL, wxID_HTML_OPTIONS, wxHtmlHelpFrame::OnToolbar) |
1632 | EVT_BUTTON(wxID_HTML_BOOKMARKSREMOVE, wxHtmlHelpFrame::OnToolbar) | |
1633 | EVT_BUTTON(wxID_HTML_BOOKMARKSADD, wxHtmlHelpFrame::OnToolbar) | |
8ec2b484 HH |
1634 | EVT_TREE_SEL_CHANGED(wxID_HTML_TREECTRL, wxHtmlHelpFrame::OnContentsSel) |
1635 | EVT_LISTBOX(wxID_HTML_INDEXLIST, wxHtmlHelpFrame::OnIndexSel) | |
1636 | EVT_LISTBOX(wxID_HTML_SEARCHLIST, wxHtmlHelpFrame::OnSearchSel) | |
1637 | EVT_BUTTON(wxID_HTML_SEARCHBUTTON, wxHtmlHelpFrame::OnSearch) | |
1638 | EVT_TEXT_ENTER(wxID_HTML_SEARCHTEXT, wxHtmlHelpFrame::OnSearch) | |
f0b6a33f VS |
1639 | EVT_BUTTON(wxID_HTML_INDEXBUTTON, wxHtmlHelpFrame::OnIndexFind) |
1640 | EVT_TEXT_ENTER(wxID_HTML_INDEXTEXT, wxHtmlHelpFrame::OnIndexFind) | |
1641 | EVT_BUTTON(wxID_HTML_INDEXBUTTONALL, wxHtmlHelpFrame::OnIndexAll) | |
382e6efe | 1642 | EVT_COMBOBOX(wxID_HTML_BOOKMARKSLIST, wxHtmlHelpFrame::OnBookmarksSel) |
f6bcfd97 | 1643 | EVT_CLOSE(wxHtmlHelpFrame::OnCloseWindow) |
d9b21c9f | 1644 | #ifdef __WXMAC__ |
4aa31786 | 1645 | EVT_MENU(wxID_CLOSE, wxHtmlHelpFrame::OnClose) |
d9b21c9f JS |
1646 | EVT_MENU(wxID_ABOUT, wxHtmlHelpFrame::OnAbout) |
1647 | #endif | |
1648 | ||
8ec2b484 HH |
1649 | END_EVENT_TABLE() |
1650 | ||
3379ed37 VZ |
1651 | #endif // wxUSE_WXHTML_HELP |
1652 |