void StressTest::OnTimer(int timerIdGot) { CrashIf(timerId != timerIdGot); KillTimer(win->hwndFrame, timerId); if (!win->IsDocLoaded()) { if (!GoToNextFile()) { Finished(true); return; } TickTimer(); return; } // chm documents aren't rendered and we block until we show them // so we can assume previous page has been shown and go to next page if (!win->AsFixed()) { if (!GoToNextPage()) return; goto Next; } // For non-image files, we detect if a page was rendered by checking the cache // (but we don't wait more than 3 seconds). // Image files are always fully rendered in WM_PAINT, so we know the page // has already been rendered. DisplayModel* dm = win->AsFixed(); bool didRender = gRenderCache.Exists(dm, currPage, dm->GetRotation()); if (!didRender && dm->ShouldCacheRendering(currPage)) { double timeInMs = currPageRenderTime.GetTimeInMs(); if (timeInMs > 3.0 * 1000) { if (!GoToNextPage()) return; } } else if (!GoToNextPage()) { return; } MakeRandomSelection(win, currPage); Next: TickTimer(); }
void LinkHandler::LaunchFile(const WCHAR *path, PageDestination *link) { // for safety, only handle relative paths and only open them in SumatraPDF // (unless they're of an allowed perceived type) and never launch any external // file in plugin mode (where documents are supposed to be self-contained) WCHAR drive; if (str::StartsWith(path, L"\\") || str::Parse(path, L"%c:\\", &drive) || gPluginMode) { return; } // TODO: link is deleted when opening the document in a new tab RemoteDestination *remoteLink = NULL; if (link) { remoteLink = new RemoteDestination(link); link = NULL; } ScopedMem<WCHAR> fullPath(path::GetDir(owner->ctrl->FilePath())); fullPath.Set(path::Join(fullPath, path)); fullPath.Set(path::Normalize(fullPath)); // TODO: respect link->ld.gotor.new_window for PDF documents ? WindowInfo *newWin = FindWindowInfoByFile(fullPath, true); // TODO: don't show window until it's certain that there was no error if (!newWin) { LoadArgs args(fullPath, owner); newWin = LoadDocument(args); if (!newWin) { delete remoteLink; return; } } if (!newWin->IsDocLoaded()) { CloseTab(newWin); // OpenFileExternally rejects files we'd otherwise // have to show a notification to be sure (which we // consider bad UI and thus simply don't) bool ok = OpenFileExternally(fullPath); if (!ok) { ScopedMem<WCHAR> msg(str::Format(_TR("Error loading %s"), fullPath)); owner->ShowNotification(msg, true /* autoDismiss */, true /* highlight */); } delete remoteLink; return; } newWin->Focus(); if (!remoteLink) return; ScopedMem<WCHAR> destName(remoteLink->GetDestName()); if (destName) { PageDestination *dest = newWin->ctrl->GetNamedDest(destName); if (dest) { newWin->linkHandler->ScrollTo(dest); delete dest; } } else { newWin->linkHandler->ScrollTo(remoteLink); } delete remoteLink; }
bool StressTest::OpenFile(const TCHAR *fileName) { bool reuse = rand() % 3 != 1; _tprintf(_T("%s\n"), fileName); fflush(stdout); LoadArgs args(fileName, NULL, true /* show */, reuse); WindowInfo *w = LoadDocument(args); if (!w) return false; if (w == win) { // WindowInfo reused if (!win->dm) return false; } else if (!w->dm) { // new WindowInfo CloseWindow(w, false, true); return false; } // transfer ownership of stressTest object to a new window and close the // current one assert(this == win->stressTest); if (w != win) { if (win->IsDocLoaded()) { // try to provoke a crash in RenderCache cleanup code ClientRect rect(win->hwndFrame); rect.Inflate(rand() % 10, rand() % 10); SendMessage(win->hwndFrame, WM_SIZE, 0, MAKELONG(rect.dx, rect.dy)); win->RenderPage(1); win->RepaintAsync(); } WindowInfo *toClose = win; w->stressTest = win->stressTest; win->stressTest = NULL; win = w; CloseWindow(toClose, false, false); } if (!win->dm) return false; win->dm->ChangeDisplayMode(DM_CONTINUOUS); win->dm->ZoomTo(ZOOM_FIT_PAGE); win->dm->GoToFirstPage(); if (win->tocVisible || gGlobalPrefs.favVisible) SetSidebarVisibility(win, win->tocVisible, gGlobalPrefs.favVisible); currPage = pageRanges.At(0).start; win->dm->GoToPage(currPage, 0); currPageRenderTime.Start(); ++filesCount; pageForSearchStart = (rand() % win->dm->PageCount()) + 1; // search immediately in single page documents if (1 == pageForSearchStart) { // use text that is unlikely to be found, so that we search all pages win::SetText(win->hwndFindBox, _T("!z_yt")); FindTextOnThread(win); } int secs = SecsSinceSystemTime(stressStartTime); ScopedMem<TCHAR> tm(FormatTime(secs)); ScopedMem<TCHAR> s(str::Format(_T("File %d: %s, time: %s"), filesCount, fileName, tm)); ShowNotification(win, s, false, false, NG_STRESS_TEST_SUMMARY); return true; }
static void RelayoutTocItem(LPNMTVCUSTOMDRAW ntvcd) { // code inspired by http://www.codeguru.com/cpp/controls/treeview/multiview/article.php/c3985/ LPNMCUSTOMDRAW ncd = &ntvcd->nmcd; HWND hTV = ncd->hdr.hwndFrom; HTREEITEM hItem = (HTREEITEM)ncd->dwItemSpec; RECT rcItem; if (0 == ncd->rc.right - ncd->rc.left || 0 == ncd->rc.bottom - ncd->rc.top) return; if (!TreeView_GetItemRect(hTV, hItem, &rcItem, TRUE)) return; if (rcItem.right > ncd->rc.right) rcItem.right = ncd->rc.right; // Clear the label RECT rcFullWidth = rcItem; rcFullWidth.right = ncd->rc.right; FillRect(ncd->hdc, &rcFullWidth, GetSysColorBrush(COLOR_WINDOW)); // Get the label's text WCHAR szText[MAX_PATH]; TVITEM item; item.hItem = hItem; item.mask = TVIF_TEXT | TVIF_PARAM; item.pszText = szText; item.cchTextMax = MAX_PATH; TreeView_GetItem(hTV, &item); // Draw the page number right-aligned (if there is one) WindowInfo *win = FindWindowInfoByHwnd(hTV); DocTocItem *tocItem = (DocTocItem *)item.lParam; ScopedMem<WCHAR> label; if (tocItem->pageNo && win && win->IsDocLoaded()) { label.Set(win->ctrl->GetPageLabel(tocItem->pageNo)); label.Set(str::Join(L" ", label)); } if (label && str::EndsWith(item.pszText, label)) { RECT rcPageNo = rcFullWidth; InflateRect(&rcPageNo, -2, -1); SIZE txtSize; GetTextExtentPoint32(ncd->hdc, label, str::Len(label), &txtSize); rcPageNo.left = rcPageNo.right - txtSize.cx; SetTextColor(ncd->hdc, GetSysColor(COLOR_WINDOWTEXT)); SetBkColor(ncd->hdc, GetSysColor(COLOR_WINDOW)); DrawText(ncd->hdc, label, -1, &rcPageNo, DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX); // Reduce the size of the label and cut off the page number rcItem.right = std::max(rcItem.right - txtSize.cx, 0); szText[str::Len(szText) - str::Len(label)] = '\0'; } SetTextColor(ncd->hdc, ntvcd->clrText); SetBkColor(ncd->hdc, ntvcd->clrTextBk); // Draw the focus rectangle (including proper background color) HBRUSH brushBg = CreateSolidBrush(ntvcd->clrTextBk); FillRect(ncd->hdc, &rcItem, brushBg); DeleteObject(brushBg); if ((ncd->uItemState & CDIS_FOCUS)) DrawFocusRect(ncd->hdc, &rcItem); InflateRect(&rcItem, -2, -1); DrawText(ncd->hdc, szText, -1, &rcItem, DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_WORD_ELLIPSIS); }
bool StressTest::OpenFile(const WCHAR* fileName) { wprintf(L"%s\n", fileName); fflush(stdout); LoadArgs args(fileName); args.forceReuse = rand() % 3 != 1; WindowInfo* w = LoadDocument(args); if (!w) return false; if (w == win) { // WindowInfo reused if (!win->IsDocLoaded()) return false; } else if (!w->IsDocLoaded()) { // new WindowInfo CloseWindow(w, false); return false; } // transfer ownership of stressTest object to a new window and close the // current one AssertCrash(this == win->stressTest); if (w != win) { if (win->IsDocLoaded()) { // try to provoke a crash in RenderCache cleanup code ClientRect rect(win->hwndFrame); rect.Inflate(rand() % 10, rand() % 10); SendMessage(win->hwndFrame, WM_SIZE, 0, MAKELONG(rect.dx, rect.dy)); if (win->AsFixed()) win->cbHandler->RequestRendering(1); win->RepaintAsync(); } WindowInfo* toClose = win; w->stressTest = win->stressTest; win->stressTest = nullptr; win = w; CloseWindow(toClose, false); } if (!win->IsDocLoaded()) return false; win->ctrl->SetDisplayMode(DM_CONTINUOUS); win->ctrl->SetZoomVirtual(ZOOM_FIT_PAGE, nullptr); win->ctrl->GoToFirstPage(); if (win->tocVisible || gGlobalPrefs->showFavorites) SetSidebarVisibility(win, win->tocVisible, gGlobalPrefs->showFavorites); currPage = pageRanges.at(0).start; win->ctrl->GoToPage(currPage, false); currPageRenderTime.Start(); ++filesCount; pageForSearchStart = (rand() % win->ctrl->PageCount()) + 1; // search immediately in single page documents if (1 == pageForSearchStart) { // use text that is unlikely to be found, so that we search all pages win::SetText(win->hwndFindBox, L"!z_yt"); FindTextOnThread(win, TextSearchDirection::Forward, true); } int secs = SecsSinceSystemTime(stressStartTime); AutoFreeW tm(FormatTime(secs)); AutoFreeW s(str::Format(L"File %d: %s, time: %s", filesCount, fileName, tm)); win->ShowNotification(s, NOS_PERSIST, NG_STRESS_TEST_SUMMARY); return true; }