static void StrListTest() { WStrList l; utassert(l.Count() == 0); l.Append(str::Dup(L"one")); l.Append(str::Dup(L"two")); l.Append(str::Dup(L"One")); utassert(l.Count() == 3); utassert(str::Eq(l.At(0), L"one")); utassert(str::EqI(l.At(2), L"one")); utassert(l.Find(L"One") == 2); utassert(l.FindI(L"One") == 0); utassert(l.Find(L"Two") == -1); }
void ChmEngineImpl::DisplayPage(const WCHAR *pageUrl) { if (IsExternalUrl(pageUrl)) { // open external links in an external browser // (same as for PDF, XPS, etc. documents) if (navCb) navCb->LaunchBrowser(pageUrl); return; } int pageNo = pages.Find(ScopedMem<WCHAR>(str::ToPlainUrl(pageUrl))) + 1; if (pageNo) currentPageNo = pageNo; // This is a hack that seems to be needed for some chm files where // url starts with "..\" even though it's not accepted by ie as // a correct its: url. There's a possibility it breaks some other // chm files (I don't know such cases, though). // A more robust solution would try to match with the actual // names of files inside chm package. if (str::StartsWith(pageUrl, L"..\\")) pageUrl += 3; if (str::StartsWith(pageUrl, L"/")) pageUrl++; assert(htmlWindow); if (htmlWindow) htmlWindow->NavigateToDataUrl(pageUrl); }
PageDestination *ChmEngineImpl::GetNamedDest(const WCHAR *name) { ScopedMem<WCHAR> plainUrl(str::ToPlainUrl(name)); int pageNo = pages.Find(plainUrl) + 1; if (pageNo > 0) return new ChmTocItem(NULL, pageNo, str::Dup(name)); return NULL; }
// We fake page numbers by doing a depth-first traversal of // toc tree and considering each unique html page in toc tree // as a page int CreatePageNoForURL(const WCHAR *url) { if (!url || IsExternalUrl(url)) return 0; ScopedMem<WCHAR> plainUrl(str::ToPlainUrl(url)); int pageNo = pages->Find(plainUrl) + 1; if (pageNo > 0) return pageNo; pages->Append(plainUrl.StealData()); return pages->Count(); }
// Called after html document has been loaded. // Sync the state of the ui with the page (show // the right page number, select the right item in toc tree) void ChmEngineImpl::OnDocumentComplete(const WCHAR *url) { if (!url) return; if (*url == '/') ++url; int pageNo = pages.Find(ScopedMem<WCHAR>(str::ToPlainUrl(url))) + 1; if (pageNo) { currentPageNo = pageNo; if (navCb) navCb->PageNoChanged(pageNo); } }