diff --git a/src/ChmModel.cpp b/src/ChmModel.cpp index ea15eec668c4..cbd2a36edce6 100644 --- a/src/ChmModel.cpp +++ b/src/ChmModel.cpp @@ -565,32 +565,44 @@ TocTree* ChmModel::GetToc() { float ChmModel::GetNextZoomStep(float towardsLevel) const { float currZoom = GetZoomVirtual(true); if (MaybeGetNextZoomByIncrement(&currZoom, towardsLevel)) { + // chm uses browser control which only supports integer zoom levels + // this ensures we're not stuck on a given zoom level i.e. advance by at least 1% + int iCurrZoom2 = (int)GetZoomVirtual(true); + int iCurrZoom = (int)currZoom; + if (iCurrZoom == iCurrZoom2) { + currZoom += 1.f; + } return currZoom; } - Vec* zoomLevels = gGlobalPrefs->zoomLevels; - ReportIf(zoomLevels->size() != 0 && (zoomLevels->at(0) < kZoomMin || zoomLevels->Last() > kZoomMax)); - ReportIf(zoomLevels->size() != 0 && zoomLevels->at(0) > zoomLevels->Last()); - - const float FUZZ = 0.01f; - float newZoom = towardsLevel; - if (currZoom < towardsLevel) { - for (size_t i = 0; i < zoomLevels->size(); i++) { - if (zoomLevels->at(i) - FUZZ > currZoom) { - newZoom = zoomLevels->at(i); + int nZoomLevels; + float* zoomLevels = GetDefaultZoomLevels(&nZoomLevels); + + // chm uses browser control which only supports integer zoom levels + // this ensures we're not stuck on a given zoom level + // due to float => int truncation + int iCurrZoom = (int)currZoom; + int iTowardsLevel = (int)towardsLevel; + int iNewZoom = iTowardsLevel; + if (iCurrZoom < towardsLevel) { + for (int i = 0; i < nZoomLevels; i++) { + int iZoom = (int)zoomLevels[i]; + if (iZoom > iCurrZoom) { + iNewZoom = iZoom; break; } } - } else if (currZoom > towardsLevel) { - for (size_t i = zoomLevels->size(); i > 0; i--) { - if (zoomLevels->at(i - 1) + FUZZ < currZoom) { - newZoom = zoomLevels->at(i - 1); + } else if (iCurrZoom > towardsLevel) { + for (int i = nZoomLevels - 1; i >= 0; i--) { + int iZoom = (int)zoomLevels[i]; + if (iZoom < iCurrZoom) { + iNewZoom = iZoom; break; } } } - return newZoom; + return (float)iNewZoom; } void ChmModel::GetDisplayState(FileState* fs) { diff --git a/src/DisplayMode.h b/src/DisplayMode.h index 664e5797c217..c8e10936ed64 100644 --- a/src/DisplayMode.h +++ b/src/DisplayMode.h @@ -12,3 +12,4 @@ DisplayMode DisplayModeFromString(const char* s, DisplayMode defVal); float ZoomFromString(const char* s, float defVal); void ZoomToString(char** dst, float zoom, FileState* stateForIssue2140); bool MaybeGetNextZoomByIncrement(float* currZoomInOut, float towardsLevel); +float* GetDefaultZoomLevels(int* nZoomLevelsOut); diff --git a/src/DisplayModel.cpp b/src/DisplayModel.cpp index 4f09de3e753c..cf6056be79b3 100644 --- a/src/DisplayModel.cpp +++ b/src/DisplayModel.cpp @@ -1612,25 +1612,19 @@ bool MaybeGetNextZoomByIncrement(float* currZoomInOut, float towardsLevel) { return true; } -float DisplayModel::GetNextZoomStep(float towardsLevel) const { - float currZoom = GetZoomVirtual(true); - if (MaybeGetNextZoomByIncrement(&currZoom, towardsLevel)) { - return currZoom; - } - - // differences to Adobe Reader: starts at 8.33 (instead of 1 and 6.25) - // and has four additional intermediary zoom levels ("added") - // clang-format off - static float defaultZooms[] = { - 8.33f, 12.5f, 18 /* added */, 25, 33.33f, 50, 66.67f, 75, - 100, 125, 150, 200, 300, 400, 600, 800, 1000 /* added */, - 1200, 1600, 2000 /* added */, 2400, 3200, 4800 /* added */, 6400 - }; - // clang-format on - // ReportIf(defaultZooms[0] != kZoomMin || defaultZooms[dimof(defaultZooms)-1] != kZoomMax); - - float* zoomLevels = defaultZooms; - int nZoomLevels = dimofi(defaultZooms); +// differences to Adobe Reader: starts at 8.33 (instead of 1 and 6.25) +// and has four additional intermediary zoom levels ("added") +// clang-format off +static float defaultZoomLevels[] = { + 8.33f, 12.5f, 18 /* added */, 25, 33.33f, 50, 66.67f, 75, + 100, 125, 150, 200, 300, 400, 600, 800, 1000 /* added */, + 1200, 1600, 2000 /* added */, 2400, 3200, 4800 /* added */, 6400 +}; +// clang-format on + +float* GetDefaultZoomLevels(int* nZoomLevelsOut) { + float* zoomLevels = defaultZoomLevels; + int nZoomLevels = dimofi(defaultZoomLevels); int nCustomZooms = gGlobalPrefs->zoomLevels->Size(); if (nCustomZooms > 0) { @@ -1639,11 +1633,25 @@ float DisplayModel::GetNextZoomStep(float towardsLevel) const { zoomLevels = gGlobalPrefs->zoomLevels->LendData(); nZoomLevels = nCustomZooms; } + *nZoomLevelsOut = nZoomLevels; + return zoomLevels; +} +float DisplayModel::GetNextZoomStep(float towardsLevel) const { + float currZoom = GetZoomVirtual(true); if (currZoom == towardsLevel) { return towardsLevel; } + if (MaybeGetNextZoomByIncrement(&currZoom, towardsLevel)) { + return currZoom; + } + + // ReportIf(defaultZooms[0] != kZoomMin || defaultZooms[dimof(defaultZooms)-1] != kZoomMax); + + int nZoomLevels; + float* zoomLevels = GetDefaultZoomLevels(&nZoomLevels); + float pageZoom = (float)HUGE_VAL, widthZoom = (float)HUGE_VAL; for (int pageNo = 1; pageNo <= PageCount(); pageNo++) { if (PageShown(pageNo)) { diff --git a/src/Notifications.cpp b/src/Notifications.cpp index dd09d68ba3fe..c74427117068 100644 --- a/src/Notifications.cpp +++ b/src/Notifications.cpp @@ -478,6 +478,7 @@ NotificationWnd* ShowNotification(const NotificationCreateArgs& args) { delete wnd; return nullptr; } + BringWindowToTop(wnd->hwnd); NotifsAdd(wnd, args.groupId); return wnd; } diff --git a/src/SumatraPDF.cpp b/src/SumatraPDF.cpp index 8faa09ea0c26..f5c79bb5e3cf 100644 --- a/src/SumatraPDF.cpp +++ b/src/SumatraPDF.cpp @@ -870,6 +870,9 @@ static void UpdatePageInfoHelper(DocController* ctrl, NotificationWnd* wnd, int } static void TogglePageInfoHelper(MainWindow* win) { + if (!win || !win->IsDocLoaded()) { + return; + } NotificationWnd* wnd = GetNotificationForGroup(win->hwndCanvas, kNotifPageInfo); if (wnd) { RemoveNotificationsForGroup(win->hwndCanvas, kNotifPageInfo); @@ -929,7 +932,6 @@ void ControllerCallbackHandler::PageNoChanged(DocController* ctrl, int pageNo) { if (!wnd) { return; } - ReportIf(!win->AsFixed()); UpdatePageInfoHelper(win->ctrl, wnd, pageNo); } @@ -5811,13 +5813,11 @@ static LRESULT FrameOnCommand(MainWindow* win, HWND hwnd, UINT msg, WPARAM wp, L ToggleFavorites(win); break; - case CmdTogglePageInfo: - if (dm) { - // "page info" tip: make figuring out current page and - // total pages count a one-key action (unless they're already visible) - TogglePageInfoHelper(win); - } - break; + case CmdTogglePageInfo: { + // "page info" tip: make figuring out current page and + // total pages count a one-key action (unless they're already visible) + TogglePageInfoHelper(win); + } break; case CmdInvertColors: { gGlobalPrefs->fixedPageUI.invertColors ^= true;