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