X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5526e819eca4465ed5520d49bccfebc6a28045e0..3a5bcc4db0851bf8cd3063917511b0b17c7f9679:/src/html/htmlhelp.cpp diff --git a/src/html/htmlhelp.cpp b/src/html/htmlhelp.cpp index 22d69b06cd..8ea6466640 100644 --- a/src/html/htmlhelp.cpp +++ b/src/html/htmlhelp.cpp @@ -5,14 +5,17 @@ // Licence: wxWindows Licence ///////////////////////////////////////////////////////////////////////////// +#error This file should not be compiled! Update your build system! \ +(configure users, rerun configure to get a new Makefile) \ +Instead of htmlhelp[_io], use helpdata, helpfrm and helpctrl. This \ +file is only left to point out the problem and will be removed r.s.n. #ifdef __GNUG__ -#pragma implementation +#pragma implementation "htmlhelp.h" #endif -#include +#include "wx/wxprec.h" -#include "wx/defs.h" #if wxUSE_HTML #ifdef __BORDLANDC__ @@ -20,10 +23,8 @@ #endif #ifndef WXPRECOMP -#include #endif - #include #include #include @@ -41,63 +42,20 @@ // Bitmaps: #ifndef __WXMSW__ -#include "bitmaps/panel.xpm" -#include "bitmaps/back.xpm" -#include "bitmaps/forward.xpm" -#include "bitmaps/book.xpm" -#include "bitmaps/folder.xpm" -#include "bitmaps/page.xpm" -#endif - -#include "search.h" - - - -//----------------------------------------------------------------------------- -// Helper constants -//----------------------------------------------------------------------------- - - -// Command IDs : - -enum { - wxID_HTML_PANEL = wxID_HIGHEST + 1, - wxID_HTML_BACK, - wxID_HTML_FORWARD, - wxID_HTML_TREECTRL, - wxID_HTML_INDEXPAGE, - wxID_HTML_INDEXLIST, - wxID_HTML_NOTEBOOK, - wxID_HTML_SEARCHPAGE, - wxID_HTML_SEARCHTEXT, - wxID_HTML_SEARCHLIST, - wxID_HTML_SEARCHBUTTON -}; - - -// Images: - -enum { - IMG_Book = 0, - IMG_Folder, - IMG_Page -}; - - - - + // XPM hack: make the arrays const + #define static static const + #include "bitmaps/panel.xpm" + #include "bitmaps/back.xpm" + #include "bitmaps/forward.xpm" + #include "bitmaps/book.xpm" + #include "bitmaps/folder.xpm" + #include "bitmaps/page.xpm" -class HtmlHelpTreeItemData : public wxTreeItemData -{ - private: - wxString m_Page; - - public: - HtmlHelpTreeItemData(HtmlContentsItem *it) : wxTreeItemData() {m_Page = it -> m_Book -> GetBasePath() + it -> m_Page;} - const wxString& GetPage() {return m_Page;} -}; + #undef static +#endif +#include "search.h" @@ -143,6 +101,15 @@ wxHtmlHelpController::wxHtmlHelpController() : wxEvtHandler() m_ContentsCnt = 0; m_Index = NULL; m_IndexCnt = 0; + + m_IndexBox = NULL; + m_ContentsBox = NULL; + m_SearchList = NULL; + m_SearchText = NULL; + m_SearchButton = NULL; + m_HtmlWin = NULL; + m_Splitter = NULL; + m_NavigPan = NULL; } @@ -155,15 +122,15 @@ wxHtmlHelpController::~wxHtmlHelpController() delete m_ContentsImageList; if (m_Contents) { for (i = 0; i < m_ContentsCnt; i++) { - free(m_Contents[i].m_Page); - free(m_Contents[i].m_Name); + delete[] m_Contents[i].m_Page; + delete[] m_Contents[i].m_Name; } free(m_Contents); } if (m_Index) { for (i = 0; i < m_IndexCnt; i++) { - free(m_Index[i].m_Page); - free(m_Index[i].m_Name); + delete[] m_Index[i].m_Page; + delete[] m_Index[i].m_Name; } free(m_Index); } @@ -202,12 +169,12 @@ static char* ReadLine(char *line, char *buf) static wxString SafeFileName(const wxString& s) { wxString res = s; - res.Replace(":", "_", TRUE); - res.Replace(" ", "_", TRUE); - res.Replace("/", "_", TRUE); - res.Replace("\\", "_", TRUE); - res.Replace("#", "_", TRUE); - res.Replace(".", "_", TRUE); + res.Replace(_T(":"), _T("_"), TRUE); + res.Replace(_T(" "), _T("_"), TRUE); + res.Replace(_T("/"), _T("_"), TRUE); + res.Replace(_T("\\"), _T("_"), TRUE); + res.Replace(_T("#"), _T("_"), TRUE); + res.Replace(_T("."), _T("_"), TRUE); return res; } @@ -219,7 +186,7 @@ static int IndexCompareFunc(const void *a, const void *b) -bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg = FALSE) +bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg) { wxFSFile *fi; wxFileSystem fsys; @@ -230,12 +197,12 @@ bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg = FA int sz; char *buff, *lineptr; char linebuf[300]; - + wxString title = _("noname"), safetitle, start = wxEmptyString, contents = wxEmptyString, index = wxEmptyString; - + if (wxIsAbsolutePath(book)) bookFull = book; else bookFull = wxGetCwd() + "/" + book; @@ -243,8 +210,8 @@ bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg = FA if (fi == NULL) return FALSE; fsys.ChangePathTo(bookFull); s = fi -> GetStream(); - sz = s -> StreamSize(); - buff = (char*) malloc(sz+1); + sz = s -> GetSize(); + buff = new char[sz+1]; buff[sz] = 0; s -> Read(buff, sz); lineptr = buff; @@ -260,7 +227,7 @@ bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg = FA if (strstr(linebuf, "Contents file=") == linebuf) contents = linebuf + strlen("Contents file="); } - free(buff); + delete[] buff; bookr = new HtmlBookRecord(fsys.GetPath(), title, start); @@ -268,9 +235,9 @@ bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg = FA m_Contents = (HtmlContentsItem*) realloc(m_Contents, (m_ContentsCnt + HTML_REALLOC_STEP) * sizeof(HtmlContentsItem)); m_Contents[m_ContentsCnt].m_Level = 0; m_Contents[m_ContentsCnt].m_ID = 0; - m_Contents[m_ContentsCnt].m_Page = (char*) malloc(start.Length() + 1); + m_Contents[m_ContentsCnt].m_Page = new char[start.Length() + 1]; strcpy(m_Contents[m_ContentsCnt].m_Page, start.c_str()); - m_Contents[m_ContentsCnt].m_Name = (char*) malloc(title.Length() + 1); + m_Contents[m_ContentsCnt].m_Name = new char [title.Length() + 1]; strcpy(m_Contents[m_ContentsCnt].m_Name, title.c_str()); m_Contents[m_ContentsCnt].m_Book = bookr; m_ContentsCnt++; @@ -295,7 +262,7 @@ bool wxHtmlHelpController::AddBook(const wxString& book, bool show_wait_msg = FA m_BookRecords.Add(bookr); if (m_IndexCnt > 0) qsort(m_Index, m_IndexCnt, sizeof(HtmlContentsItem), IndexCompareFunc); - + return TRUE; } @@ -412,14 +379,15 @@ class MyProgressDlg : public wxDialog public: bool m_Canceled; - MyProgressDlg(wxWindow *parent) : wxDialog(parent, -1, - _("Searching..."), - wxPoint(0, 0), + MyProgressDlg(wxWindow *parent) : wxDialog(parent, -1, + _("Searching..."), + wxPoint(0, 0), #ifdef __WXGTK__ - wxSize(300, 110)) + wxSize(300, 110) #else - wxSize(300, 130)) + wxSize(300, 130) #endif + ) {m_Canceled = FALSE;} void OnCancel(wxCommandEvent& event) {m_Canceled = TRUE;} DECLARE_EVENT_TABLE() @@ -430,23 +398,26 @@ END_EVENT_TABLE() #endif - + bool wxHtmlHelpController::KeywordSearch(const wxString& keyword) { int foundcnt = 0; - CreateHelpWindow(); + // if these are not set, we can't continue + if (! (m_SearchList && m_HtmlWin)) + return FALSE; m_Frame -> Raise(); - if (!m_Splitter -> IsSplit()) { - m_NavigPan -> Show(TRUE); - m_HtmlWin -> Show(TRUE); - m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); + if (m_Splitter && m_NavigPan && m_SearchButton) { + if (!m_Splitter -> IsSplit()) { + m_NavigPan -> Show(TRUE); + m_HtmlWin -> Show(TRUE); + m_Splitter -> SplitVertically(m_NavigPan, m_HtmlWin, m_Cfg.sashpos); + } + m_NavigPan -> SetSelection(2); + m_SearchList -> Clear(); + m_SearchText -> SetValue(keyword); + m_SearchButton -> Enable(FALSE); } - m_NavigPan -> SetSelection(2); - m_SearchList -> Clear(); - m_SearchText -> SetValue(keyword); - m_SearchButton -> Enable(FALSE); - { int cnt = m_ContentsCnt; wxSearchEngine engine; @@ -504,10 +475,12 @@ bool wxHtmlHelpController::KeywordSearch(const wxString& keyword) progress.Close(TRUE); #endif } - - m_SearchButton -> Enable(TRUE); - m_SearchText -> SetSelection(0, keyword.Length()); - m_SearchText -> SetFocus(); + if (m_SearchButton) + m_SearchButton -> Enable(TRUE); + if (m_SearchText) { + m_SearchText -> SetSelection(0, keyword.Length()); + m_SearchText -> SetFocus(); + } if (foundcnt) { HtmlContentsItem *it = (HtmlContentsItem*) m_SearchList -> GetClientData(0); if (it) m_HtmlWin -> LoadPage(it -> m_Book -> GetBasePath() + it -> m_Page); @@ -528,11 +501,13 @@ void wxHtmlHelpController::CreateHelpWindow() if (m_Frame) { m_Frame -> Raise(); - m_Frame -> Show(TRUE); + m_Frame -> Show(TRUE); return; } +#if wxUSE_BUSYINFO wxBusyInfo busyinfo(_("Preparing help window...")); +#endif if (m_Config) ReadCustomization(m_Config, m_ConfigRoot); @@ -665,7 +640,7 @@ void wxHtmlHelpController::CreateContents() for (int i = 0; i < count; i++) { it = m_Contents + i; - roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem(roots[it -> m_Level], it -> m_Name, IMG_Page, -1, new HtmlHelpTreeItemData(it)); + roots[it -> m_Level + 1] = m_ContentsBox -> AppendItem(roots[it -> m_Level], it -> m_Name, IMG_Page, -1, new wxHtmlHelpTreeItemData(it)); if (it -> m_Level == 0) { m_ContentsBox -> SetItemBold(roots[1], TRUE); m_ContentsBox -> SetItemImage(roots[1], IMG_Book); @@ -722,7 +697,7 @@ void wxHtmlHelpController::ReadCustomization(wxConfigBase *cfg, wxString path) cfg -> SetPath(path); } - m_Cfg.navig_on = (bool) cfg -> Read("hcNavigPanel", m_Cfg.navig_on); + m_Cfg.navig_on = cfg -> Read("hcNavigPanel", m_Cfg.navig_on) != 0; m_Cfg.sashpos = cfg -> Read("hcSashPos", m_Cfg.sashpos); m_Cfg.x = cfg -> Read("hcX", m_Cfg.x); m_Cfg.y = cfg -> Read("hcY", m_Cfg.y); @@ -792,9 +767,9 @@ void wxHtmlHelpController::OnToolbar(wxCommandEvent& event) void wxHtmlHelpController::OnContentsSel(wxTreeEvent& event) { - HtmlHelpTreeItemData *pg; + wxHtmlHelpTreeItemData *pg; - pg = (HtmlHelpTreeItemData*) m_ContentsBox -> GetItemData(event.GetItem()); + pg = (wxHtmlHelpTreeItemData*) m_ContentsBox -> GetItemData(event.GetItem()); if (pg) m_HtmlWin -> LoadPage(pg -> GetPage()); }