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