X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/21dc463833b8a5e57215d7a9f69e17d68062bf72..32cdc45397d8c0a24735f84e1dcf83bba1980f2d:/src/html/helpdata.cpp diff --git a/src/html/helpdata.cpp b/src/html/helpdata.cpp index 65d3da7f4c..506fc99d8f 100644 --- a/src/html/helpdata.cpp +++ b/src/html/helpdata.cpp @@ -18,7 +18,7 @@ #if wxUSE_HTML && wxUSE_STREAMS -#ifndef WXPRECOMP +#ifndef WX_PRECOMP #include "wx/intl.h" #include "wx/log.h" #endif @@ -125,9 +125,9 @@ public: wxObject* GetProduct() { return NULL; } protected: - virtual void AddText(const wxChar* WXUNUSED(txt)) {} + virtual void AddText(const wxString& WXUNUSED(txt)) {} - DECLARE_NO_COPY_CLASS(HP_Parser) + wxDECLARE_NO_COPY_CLASS(HP_Parser); }; @@ -170,7 +170,7 @@ class HP_TagHandler : public wxHtmlTagHandler m_parentItem = NULL; } - DECLARE_NO_COPY_CLASS(HP_TagHandler) + wxDECLARE_NO_COPY_CLASS(HP_TagHandler); }; @@ -265,17 +265,10 @@ IMPLEMENT_DYNAMIC_CLASS(wxHtmlHelpData, wxObject) wxHtmlHelpData::wxHtmlHelpData() { -#if WXWIN_COMPATIBILITY_2_4 - m_cacheContents = NULL; - m_cacheIndex = NULL; -#endif } wxHtmlHelpData::~wxHtmlHelpData() { -#if WXWIN_COMPATIBILITY_2_4 - CleanCompatibilityData(); -#endif } bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, @@ -291,7 +284,7 @@ bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, HP_TagHandler *handler = new HP_TagHandler(book); parser.AddTagHandler(handler); - f = ( contentsfile.empty() ? (wxFSFile*) NULL : fsys.OpenFile(contentsfile) ); + f = ( contentsfile.empty() ? NULL : fsys.OpenFile(contentsfile) ); if (f) { buf.clear(); @@ -305,7 +298,7 @@ bool wxHtmlHelpData::LoadMSProject(wxHtmlBookRecord *book, wxFileSystem& fsys, wxLogError(_("Cannot open contents file: %s"), contentsfile.c_str()); } - f = ( indexfile.empty() ? (wxFSFile*) NULL : fsys.OpenFile(indexfile) ); + f = ( indexfile.empty() ? NULL : fsys.OpenFile(indexfile) ); if (f) { buf.clear(); @@ -703,25 +696,34 @@ bool wxHtmlHelpData::AddBook(const wxString& book) title, contents, index, start, fsys.GetPath()); delete fi; -#if WXWIN_COMPATIBILITY_2_4 - CleanCompatibilityData(); -#endif - return rtval; } wxString wxHtmlHelpData::FindPageByName(const wxString& x) { - int cnt; int i; - wxFileSystem fsys; - wxFSFile *f; - /* 1. try to open given file: */ - - cnt = m_bookRecords.GetCount(); - for (i = 0; i < cnt; i++) + bool has_non_ascii = false; + wxString::const_iterator it; + for (it = x.begin(); it != x.end(); ++it) { + wxUniChar ch = *it; + if (!ch.IsAscii()) + { + has_non_ascii = true; + break; + } + } + + int cnt = m_bookRecords.GetCount(); + + if (!has_non_ascii) + { + wxFileSystem fsys; + wxFSFile *f; + // 1. try to open given file: + for (i = 0; i < cnt; i++) + { f = fsys.OpenFile(m_bookRecords[i].GetFullPath(x)); if (f) { @@ -729,19 +731,18 @@ wxString wxHtmlHelpData::FindPageByName(const wxString& x) delete f; return url; } + } } - /* 2. try to find a book: */ - + // 2. try to find a book: for (i = 0; i < cnt; i++) { if (m_bookRecords[i].GetTitle() == x) return m_bookRecords[i].GetFullPath(m_bookRecords[i].GetStart()); } - /* 3. try to find in contents: */ - + // 3. try to find in contents: cnt = m_contents.size(); for (i = 0; i < cnt; i++) { @@ -750,8 +751,7 @@ wxString wxHtmlHelpData::FindPageByName(const wxString& x) } - /* 4. try to find in index: */ - + // 4. try to find in index: cnt = m_index.size(); for (i = 0; i < cnt; i++) { @@ -759,6 +759,13 @@ wxString wxHtmlHelpData::FindPageByName(const wxString& x) return m_index[i].GetFullPath(); } + // 4b. if still not found, try case-insensitive comparison + for (i = 0; i < cnt; i++) + { + if (m_index[i].name.CmpNoCase(x) == 0) + return m_index[i].GetFullPath(); + } + return wxEmptyString; } @@ -776,90 +783,6 @@ wxString wxHtmlHelpData::FindPageById(int id) return wxEmptyString; } -#if WXWIN_COMPATIBILITY_2_4 -wxHtmlContentsItem::wxHtmlContentsItem() - : m_Level(0), m_ID(wxID_ANY), m_Name(NULL), m_Page(NULL), m_Book(NULL), - m_autofree(false) -{ -} - -wxHtmlContentsItem::wxHtmlContentsItem(const wxHtmlHelpDataItem& d) -{ - m_autofree = true; - m_Level = d.level; - m_ID = d.id; - m_Name = wxStrdup(d.name.c_str()); - m_Page = wxStrdup(d.page.c_str()); - m_Book = d.book; -} - -wxHtmlContentsItem& wxHtmlContentsItem::operator=(const wxHtmlContentsItem& d) -{ - if (m_autofree) - { - free(m_Name); - free(m_Page); - } - m_autofree = true; - m_Level = d.m_Level; - m_ID = d.m_ID; - m_Name = d.m_Name ? wxStrdup(d.m_Name) : NULL; - m_Page = d.m_Page ? wxStrdup(d.m_Page) : NULL; - m_Book = d.m_Book; - return *this; -} - -wxHtmlContentsItem::~wxHtmlContentsItem() -{ - if (m_autofree) - { - free(m_Name); - free(m_Page); - } -} - -wxHtmlContentsItem* wxHtmlHelpData::GetContents() -{ - if (!m_cacheContents && !m_contents.empty()) - { - size_t len = m_contents.size(); - m_cacheContents = new wxHtmlContentsItem[len]; - for (size_t i = 0; i < len; i++) - m_cacheContents[i] = m_contents[i]; - } - return m_cacheContents; -} - -int wxHtmlHelpData::GetContentsCnt() -{ - return m_contents.size(); -} - -wxHtmlContentsItem* wxHtmlHelpData::GetIndex() -{ - if (!m_cacheContents && !m_index.empty()) - { - size_t len = m_index.size(); - m_cacheContents = new wxHtmlContentsItem[len]; - for (size_t i = 0; i < len; i++) - m_cacheContents[i] = m_index[i]; - } - return m_cacheContents; -} - -int wxHtmlHelpData::GetIndexCnt() -{ - return m_index.size(); -} - -void wxHtmlHelpData::CleanCompatibilityData() -{ - delete[] m_cacheContents; - m_cacheContents = NULL; - delete[] m_cacheIndex; - m_cacheIndex = NULL; -} -#endif // WXWIN_COMPATIBILITY_2_4 //---------------------------------------------------------------------------------- // wxHtmlSearchStatus functions @@ -897,15 +820,6 @@ wxHtmlSearchStatus::wxHtmlSearchStatus(wxHtmlHelpData* data, const wxString& key m_Active = (m_CurIndex < m_MaxIndex); } -#if WXWIN_COMPATIBILITY_2_4 -wxHtmlContentsItem* wxHtmlSearchStatus::GetContentsItem() -{ - static wxHtmlContentsItem it; - it = wxHtmlContentsItem(*m_CurItem); - return ⁢ -} -#endif - bool wxHtmlSearchStatus::Search() { wxFSFile *file;