X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c1dc9f8394c1488ad8e7d945e6f943f7b34554ce..4521f6c88cbefa7f13e3733d344776b795f981e4:/src/html/helpdata.cpp diff --git a/src/html/helpdata.cpp b/src/html/helpdata.cpp index a21a2ab70b..c60c74e626 100644 --- a/src/html/helpdata.cpp +++ b/src/html/helpdata.cpp @@ -4,7 +4,6 @@ // Notes: Based on htmlhelp.cpp, implementing a monolithic // HTML Help controller class, by Vaclav Slavik // Author: Harm van der Heijden and Vaclav Slavik -// RCS-ID: $Id$ // Copyright: (c) Harm van der Heijden and Vaclav Slavik // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -18,7 +17,7 @@ #if wxUSE_HTML && wxUSE_STREAMS -#ifndef WXPRECOMP +#ifndef WX_PRECOMP #include "wx/intl.h" #include "wx/log.h" #endif @@ -51,11 +50,11 @@ static const wxChar* ReadLine(const wxChar *line, wxChar *buf, size_t bufsize) wxChar *endptr = buf + bufsize - 1; const wxChar *readptr = line; - while (*readptr != 0 && *readptr != _T('\r') && *readptr != _T('\n') && + while (*readptr != 0 && *readptr != wxT('\r') && *readptr != wxT('\n') && writeptr != endptr) *(writeptr++) = *(readptr++); *writeptr = 0; - while (*readptr == _T('\r') || *readptr == _T('\n')) + while (*readptr == wxT('\r') || *readptr == wxT('\n')) readptr++; if (*readptr == 0) return NULL; @@ -125,9 +124,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 +169,7 @@ class HP_TagHandler : public wxHtmlTagHandler m_parentItem = NULL; } - DECLARE_NO_COPY_CLASS(HP_TagHandler) + wxDECLARE_NO_COPY_CLASS(HP_TagHandler); }; @@ -245,7 +244,7 @@ bool HP_TagHandler::HandleTag(const wxHtmlTag& tag) wxString wxHtmlBookRecord::GetFullPath(const wxString &page) const { - if (wxIsAbsolutePath(page)) + if (wxIsAbsolutePath(page) || page.Find(wxT("file:")) == 0) return page; else return m_BasePath + page; @@ -255,7 +254,7 @@ wxString wxHtmlHelpDataItem::GetIndentedName() const { wxString s; for (int i = 1; i < level; i++) - s << _T(" "); + s << wxT(" "); s << name; return s; } @@ -284,7 +283,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(); @@ -298,7 +297,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(); @@ -475,11 +474,11 @@ void wxHtmlHelpData::SetTempDir(const wxString& path) m_tempPath = path; else { - if (wxIsAbsolutePath(path)) m_tempPath = path; - else m_tempPath = wxGetCwd() + _T("/") + path; + wxFileName fn; + fn.AssignDir(path); + fn.MakeAbsolute(); - if (m_tempPath[m_tempPath.length() - 1] != _T('/')) - m_tempPath << _T('/'); + m_tempPath = fn.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR); } } @@ -501,6 +500,18 @@ bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile, const wxString& indexfile, const wxString& deftopic, const wxString& path) { +#if wxUSE_WCHAR_T + #if wxUSE_UNICODE + #define CORRECT_STR(str, conv) \ + str = wxString((str).mb_str(wxConvISO8859_1), conv) + #else + #define CORRECT_STR(str, conv) \ + str = wxString((str).wc_str(conv), wxConvLocal) + #endif +#else + #define CORRECT_STR(str, conv) +#endif + wxFileSystem fsys; wxFSFile *fi; wxHtmlBookRecord *bookr; @@ -518,7 +529,16 @@ bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile, return true; // book is (was) loaded } - bookr = new wxHtmlBookRecord(bookfile.GetLocation(), fsys.GetPath(), title, deftopic); + wxString title1 = title; + if (encoding != wxFONTENCODING_SYSTEM) + { + wxCSConv conv(encoding); + CORRECT_STR(title1, conv); + if (title1.IsEmpty() && !title.IsEmpty()) + title1 = title; + } + + bookr = new wxHtmlBookRecord(bookfile.GetLocation(), fsys.GetPath(), title1, deftopic); wxHtmlHelpDataItem *bookitem = new wxHtmlHelpDataItem; bookitem->level = 0; @@ -569,20 +589,12 @@ bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile, // Now store the contents range bookr->SetContentsRange(cont_start, m_contents.size()); -#if wxUSE_WCHAR_T // MS HTML Help files [written by MS HTML Help Workshop] are broken // in that the data are iso-8859-1 (including HTML entities), but must // be interpreted as being in language's windows charset. Correct the // differences here and also convert to wxConvLocal in ANSI build if (encoding != wxFONTENCODING_SYSTEM) { - #if wxUSE_UNICODE - #define CORRECT_STR(str, conv) \ - str = wxString((str).mb_str(wxConvISO8859_1), conv) - #else - #define CORRECT_STR(str, conv) \ - str = wxString((str).wc_str(conv), wxConvLocal) - #endif wxCSConv conv(encoding); size_t IndexCnt = m_index.size(); size_t ContentsCnt = m_contents.size(); @@ -597,11 +609,6 @@ bool wxHtmlHelpData::AddBookParam(const wxFSFile& bookfile, } #undef CORRECT_STR } -#else - wxUnusedVar(IndexOld); - wxUnusedVar(ContentsOld); - wxASSERT_MSG(encoding == wxFONTENCODING_SYSTEM, wxT("Help files need charset conversion, but wxUSE_WCHAR_T is 0")); -#endif // wxUSE_WCHAR_T/!wxUSE_WCHAR_T m_bookRecords.Add(bookr); if (!m_index.empty()) @@ -674,16 +681,16 @@ bool wxHtmlHelpData::AddBook(const wxString& book) for (wxChar *ch = linebuf; *ch != wxT('\0') && *ch != wxT('='); ch++) *ch = (wxChar)wxTolower(*ch); - if (wxStrstr(linebuf, _T("title=")) == linebuf) - title = linebuf + wxStrlen(_T("title=")); - if (wxStrstr(linebuf, _T("default topic=")) == linebuf) - start = linebuf + wxStrlen(_T("default topic=")); - if (wxStrstr(linebuf, _T("index file=")) == linebuf) - index = linebuf + wxStrlen(_T("index file=")); - if (wxStrstr(linebuf, _T("contents file=")) == linebuf) - contents = linebuf + wxStrlen(_T("contents file=")); - if (wxStrstr(linebuf, _T("charset=")) == linebuf) - charset = linebuf + wxStrlen(_T("charset=")); + if (wxStrstr(linebuf, wxT("title=")) == linebuf) + title = linebuf + wxStrlen(wxT("title=")); + if (wxStrstr(linebuf, wxT("default topic=")) == linebuf) + start = linebuf + wxStrlen(wxT("default topic=")); + if (wxStrstr(linebuf, wxT("index file=")) == linebuf) + index = linebuf + wxStrlen(wxT("index file=")); + if (wxStrstr(linebuf, wxT("contents file=")) == linebuf) + contents = linebuf + wxStrlen(wxT("contents file=")); + if (wxStrstr(linebuf, wxT("charset=")) == linebuf) + charset = linebuf + wxStrlen(wxT("charset=")); } while (lineptr != NULL); wxFontEncoding enc = wxFONTENCODING_SYSTEM; @@ -701,15 +708,29 @@ bool wxHtmlHelpData::AddBook(const wxString& book) 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) { @@ -717,6 +738,7 @@ wxString wxHtmlHelpData::FindPageByName(const wxString& x) delete f; return url; } + } } @@ -829,11 +851,11 @@ bool wxHtmlSearchStatus::Search() { const wxChar *p1, *p2; for (p1 = thepage.c_str(), p2 = m_LastPage.c_str(); - *p1 != 0 && *p1 != _T('#') && *p1 == *p2; p1++, p2++) {} + *p1 != 0 && *p1 != wxT('#') && *p1 == *p2; p1++, p2++) {} m_LastPage = thepage; - if (*p1 == 0 || *p1 == _T('#')) + if (*p1 == 0 || *p1 == wxT('#')) return false; } else m_LastPage = thepage; @@ -877,7 +899,7 @@ void wxHtmlSearchEngine::LookFor(const wxString& keyword, bool case_sensitive, b static inline bool WHITESPACE(wxChar c) { - return c == _T(' ') || c == _T('\n') || c == _T('\r') || c == _T('\t'); + return c == wxT(' ') || c == wxT('\n') || c == wxT('\r') || c == wxT('\t'); } // replace continuous spaces by one single space @@ -896,7 +918,7 @@ static inline wxString CompressSpaces(const wxString & str) { continue; } - ch = _T(' '); + ch = wxT(' '); space_counted = true; } else @@ -928,19 +950,19 @@ bool wxHtmlSearchEngine::Scan(const wxFSFile& file) wxChar c = *pBufStr; if (insideTag) { - if (c == _T('>')) + if (c == wxT('>')) { insideTag = false; // replace the tag by an empty space - c = _T(' '); + c = wxT(' '); } else continue; } - else if (c == _T('<')) + else if (c == wxT('<')) { wxChar nextCh = *(pBufStr + 1); - if (nextCh == _T('/') || !WHITESPACE(nextCh)) + if (nextCh == wxT('/') || !WHITESPACE(nextCh)) { insideTag = true; continue; @@ -956,10 +978,10 @@ bool wxHtmlSearchEngine::Scan(const wxFSFile& file) if (m_WholeWords) { // insert ' ' at the beginning and at the end - keyword.insert( 0, _T(" ") ); - keyword.append( _T(" ") ); - bufStr.insert( 0, _T(" ") ); - bufStr.append( _T(" ") ); + keyword.insert( 0, wxT(" ") ); + keyword.append( wxT(" ") ); + bufStr.insert( 0, wxT(" ") ); + bufStr.append( wxT(" ") ); } // remove continuous spaces