void ZoomToSelection(WindowInfo *win, float factor, bool scrollToFit, bool relative) { if (!win->IsDocLoaded()) return; PointI pt; bool zoomToPt = win->showSelection && win->selectionOnPage; // either scroll towards the center of the current selection if (zoomToPt) { RectI selRect; for (size_t i = 0; i < win->selectionOnPage->Count(); i++) { selRect = selRect.Union(win->selectionOnPage->At(i).GetRect(win->dm)); } ClientRect rc(win->hwndCanvas); pt.x = 2 * selRect.x + selRect.dx - rc.dx / 2; pt.y = 2 * selRect.y + selRect.dy - rc.dy / 2; pt.x = limitValue(pt.x, selRect.x, selRect.x + selRect.dx); pt.y = limitValue(pt.y, selRect.y, selRect.y + selRect.dy); int pageNo = win->dm->GetPageNoByPoint(pt); if (!win->dm->ValidPageNo(pageNo) || !win->dm->PageVisible(pageNo)) zoomToPt = false; } // or towards the top-left-most part of the first visible page else { int page = win->dm->FirstVisiblePageNo(); PageInfo *pageInfo = win->dm->GetPageInfo(page); if (pageInfo) { RectI visible = pageInfo->pageOnScreen.Intersect(win->canvasRc); pt = visible.TL(); int pageNo = win->dm->GetPageNoByPoint(pt); if (!visible.IsEmpty() && win->dm->ValidPageNo(pageNo) && win->dm->PageVisible(pageNo)) zoomToPt = true; } } if (!relative && (ZOOM_FIT_PAGE == factor || ZOOM_FIT_CONTENT == factor) && scrollToFit) zoomToPt = false; if (relative) win->dm->ZoomBy(factor, zoomToPt ? &pt : NULL); else win->dm->ZoomTo(factor, zoomToPt ? &pt : NULL); UpdateToolbarState(win); }
// Show the result of a PDF forward-search synchronization (initiated by a DDE command) void ShowForwardSearchResult(WindowInfo *win, const WCHAR *fileName, UINT line, UINT col, UINT ret, UINT page, Vec<RectI> &rects) { win->fwdSearchMark.rects.Reset(); const PageInfo *pi = win->dm->GetPageInfo(page); if ((ret == PDFSYNCERR_SUCCESS) && (rects.Count() > 0) && (NULL != pi)) { // remember the position of the search result for drawing the rect later on win->fwdSearchMark.rects = rects; win->fwdSearchMark.page = page; win->fwdSearchMark.show = true; win->fwdSearchMark.hideStep = 0; if (!gUserPrefs->forwardSearch.highlightPermanent) SetTimer(win->hwndCanvas, HIDE_FWDSRCHMARK_TIMER_ID, HIDE_FWDSRCHMARK_DELAY_IN_MS, NULL); // Scroll to show the overall highlighted zone int pageNo = page; RectI overallrc = rects.At(0); for (size_t i = 1; i < rects.Count(); i++) overallrc = overallrc.Union(rects.At(i)); TextSel res = { 1, &pageNo, &overallrc }; if (!win->dm->PageVisible(page)) win->dm->GoToPage(page, 0, true); if (!win->dm->ShowResultRectToScreen(&res)) win->RepaintAsync(); if (IsIconic(win->hwndFrame)) ShowWindowAsync(win->hwndFrame, SW_RESTORE); return; } ScopedMem<WCHAR> buf; if (ret == PDFSYNCERR_SYNCFILE_NOTFOUND) ShowNotification(win, _TR("No synchronization file found")); else if (ret == PDFSYNCERR_SYNCFILE_CANNOT_BE_OPENED) ShowNotification(win, _TR("Synchronization file cannot be opened")); else if (ret == PDFSYNCERR_INVALID_PAGE_NUMBER) buf.Set(str::Format(_TR("Page number %u inexistant"), page)); else if (ret == PDFSYNCERR_NO_SYNC_AT_LOCATION) ShowNotification(win, _TR("No synchronization info at this position")); else if (ret == PDFSYNCERR_UNKNOWN_SOURCEFILE) buf.Set(str::Format(_TR("Unknown source file (%s)"), fileName)); else if (ret == PDFSYNCERR_NORECORD_IN_SOURCEFILE) buf.Set(str::Format(_TR("Source file %s has no synchronization point"), fileName)); else if (ret == PDFSYNCERR_NORECORD_FOR_THATLINE) buf.Set(str::Format(_TR("No result found around line %u in file %s"), line, fileName)); else if (ret == PDFSYNCERR_NOSYNCPOINT_FOR_LINERECORD) buf.Set(str::Format(_TR("No result found around line %u in file %s"), line, fileName)); if (buf) ShowNotification(win, buf); }
void ZoomToSelection(WindowInfo* win, float factor, bool scrollToFit, bool relative) { PointI pt; bool zoomToPt = false; if (win->AsFixed()) { DisplayModel* dm = win->AsFixed(); // when not zooming to fit (which contradicts zooming to a specific point), ... if (!relative && (ZOOM_FIT_PAGE == factor || ZOOM_FIT_CONTENT == factor) && scrollToFit) { zoomToPt = false; } // either scroll towards the center of the current selection (if there is any) ... else if (win->showSelection && win->currentTab->selectionOnPage) { RectI selRect; for (SelectionOnPage& sel : *win->currentTab->selectionOnPage) { selRect = selRect.Union(sel.GetRect(dm)); } ClientRect rc(win->hwndCanvas); pt.x = 2 * selRect.x + selRect.dx - rc.dx / 2; pt.y = 2 * selRect.y + selRect.dy - rc.dy / 2; pt.x = limitValue(pt.x, selRect.x, selRect.x + selRect.dx); pt.y = limitValue(pt.y, selRect.y, selRect.y + selRect.dy); int pageNo = dm->GetPageNoByPoint(pt); zoomToPt = dm->ValidPageNo(pageNo) && dm->PageVisible(pageNo); } // or towards the top-left-most part of the first visible page else { int page = dm->FirstVisiblePageNo(); PageInfo* pageInfo = dm->GetPageInfo(page); if (pageInfo) { RectI visible = pageInfo->pageOnScreen.Intersect(win->canvasRc); pt = visible.TL(); int pageNo = dm->GetPageNoByPoint(pt); zoomToPt = !visible.IsEmpty() && dm->ValidPageNo(pageNo) && dm->PageVisible(pageNo); } } } win->ctrl->SetZoomVirtual(factor * (relative ? win->ctrl->GetZoomVirtual(true) : 1), zoomToPt ? &pt : nullptr); UpdateToolbarState(win); }
static BOOL CALLBACK GetMonitorRectProc(HMONITOR hMonitor, HDC hdc, LPRECT rcMonitor, LPARAM data) { RectI *rcAll = (RectI *)data; *rcAll = rcAll->Union(RectI::FromRECT(*rcMonitor)); return TRUE; }