diff --git a/far/viewer.cpp b/far/viewer.cpp index e8a26d57944..69ca6b556f1 100644 --- a/far/viewer.cpp +++ b/far/viewer.cpp @@ -126,7 +126,7 @@ enum class Viewer::SearchDisposition static int ViewerID=0; -static constexpr int s_BytesPerStripe = 8; +static constexpr int s_HexModeBytesPerStripe = 8; static bool IsCodePageSupportedInViewer(uintptr_t cp) { @@ -209,33 +209,33 @@ wchar_t Viewer::ZeroChar() const return ViOpt.Visible0x00 && ViOpt.ZeroChar > 0 ? static_cast(ViOpt.ZeroChar) : 0; } -int Viewer::CalculateMaxBytesPerLineByScreenWidth() const +int Viewer::CalculateHexModeMaxBytesPerLine() const { const int OffsetWidth = 12; // includes offset plus colon and space const int ByteWidth = 4; // two hex digits, one space, one character in dump const int BytesGroupSeparatorWidth = 2; - const int MininumBytesCount = s_BytesPerStripe; + const int MininumBytesCount = s_HexModeBytesPerStripe; auto BytesCount = MininumBytesCount; - for (auto width = XX2 - (OffsetWidth + MininumBytesCount * ByteWidth + BytesGroupSeparatorWidth); width >= ByteWidth; width -= ByteWidth) + for (auto width = ScrollbarAdjustedRight - (OffsetWidth + MininumBytesCount * ByteWidth + BytesGroupSeparatorWidth); width >= ByteWidth; width -= ByteWidth) { ++BytesCount; - if (!(BytesCount % s_BytesPerStripe)) + if (!(BytesCount % s_HexModeBytesPerStripe)) width -= BytesGroupSeparatorWidth; } return BytesCount; } -void Viewer::AdjustBytesPerLine(int const Amount) +void Viewer::AdjustHexModeBytesPerLine(int const Amount) { - const size_t NewValue = std::clamp(static_cast(m_BytesPerLine) + Amount, s_BytesPerStripe, CalculateMaxBytesPerLineByScreenWidth()); + const size_t NewValue = std::clamp(static_cast(m_HexModeBytesPerLine) + Amount, s_HexModeBytesPerStripe, CalculateHexModeMaxBytesPerLine()); - if (NewValue == m_BytesPerLine) + if (NewValue == m_HexModeBytesPerLine) return; - m_BytesPerLine = NewValue; + m_HexModeBytesPerLine = NewValue; Show(); } @@ -456,13 +456,13 @@ bool Viewer::isBinaryFile(uintptr_t cp) // very approximate: looks for '\0' in f void Viewer::AdjustWidth() { - Width = m_Where.width(); - XX2 = m_Where.right; + ScrollbarAdjustedWidth = m_Where.width(); + ScrollbarAdjustedRight = m_Where.right; if (ViOpt.ShowScrollbar && !m_bQuickView) { - Width--; - XX2--; + ScrollbarAdjustedWidth--; + ScrollbarAdjustedRight--; } } @@ -512,7 +512,7 @@ void Viewer::ShowPage(int nMode) SetScreen(m_Where, L' ', colors::PaletteColorToFarColor(COL_VIEWERTEXT)); GotoXY(m_Where.left, m_Where.top); SetColor(COL_WARNDIALOGTEXT); - Text(cut_right(msg(lng::MViewerCannotOpenFile), XX2 - m_Where.left + 1)); + Text(cut_right(msg(lng::MViewerCannotOpenFile), ScrollbarAdjustedRight - m_Where.left + 1)); ShowStatus(); } @@ -598,11 +598,11 @@ void Viewer::ShowPage(int nMode) if (static_cast(i.Data.size()) > LeftPos) { - Text(fit_to_left(i.Data.substr(LeftPos), Width)); + Text(fit_to_left(i.Data.substr(LeftPos), ScrollbarAdjustedWidth)); } else { - Text(string(Width, L' ')); + Text(string(ScrollbarAdjustedWidth, L' ')); } if (SelectSize >= 0 && i.bSelection) @@ -614,7 +614,7 @@ void Viewer::ShowPage(int nMode) else SelX1 = i.nSelStart - LeftPos; - if (!m_Wrap && (i.nSelEnd < LeftPos || i.nSelStart > LeftPos + XX2 - m_Where.left)) + if (!m_Wrap && (i.nSelEnd < LeftPos || i.nSelStart > LeftPos + ScrollbarAdjustedRight - m_Where.left)) { if (AdjustSelPosition) { @@ -640,9 +640,9 @@ void Viewer::ShowPage(int nMode) } } - if (static_cast(i.Data.size()) > LeftPos + Width && ViOpt.ShowArrows) + if (static_cast(i.Data.size()) > LeftPos + ScrollbarAdjustedWidth && ViOpt.ShowArrows) { - GotoXY(XX2,Y); + GotoXY(ScrollbarAdjustedRight,Y); SetColor(COL_VIEWERARROWS); Text(L'»'); } @@ -706,7 +706,7 @@ int Viewer::GetModeDependentCharSize() const int Viewer::GetModeDependentLineSize() const { - return static_cast(m_DisplayMode == VMT_HEX? m_BytesPerLine : Width * getChSize(m_Codepage)); + return static_cast(m_DisplayMode == VMT_HEX? m_HexModeBytesPerLine : ScrollbarAdjustedWidth * getChSize(m_Codepage)); } int Viewer::txt_dump(std::string_view const Str, size_t ClientWidth, string& OutStr, wchar_t ZeroChar, int tail) const @@ -791,8 +791,8 @@ void Viewer::ShowDump() { const int CharSize = getChSize(m_Codepage); const int xl = m_Codepage == CP_UTF8? 4 - 1 : m_Codepage == MB.GetCP()? static_cast(MB.GetSize() - 1) : 0; - std::vector line(Width * CharSize + xl); - const DWORD mb = Width * CharSize; + std::vector line(ScrollbarAdjustedWidth * CharSize + xl); + const DWORD mb = ScrollbarAdjustedWidth * CharSize; FilePos -= FilePos % CharSize; vseek(SecondPos = FilePos, FILE_BEGIN); @@ -822,13 +822,13 @@ void Viewer::ShowDump() else LastPage = EndFile = veof(); - tail = txt_dump({ line.data(), BytesRead }, Width, OutStr, ZeroChar(), tail); + tail = txt_dump({ line.data(), BytesRead }, ScrollbarAdjustedWidth, OutStr, ZeroChar(), tail); Text(fit_to_left(OutStr, ObjWidth())); if ( SelectSize > 0 && bpos < SelectPos+SelectSize && bpos+mb > SelectPos ) { const int bsel = SelectPos > bpos? static_cast(SelectPos - bpos) / CharSize : 0; - const int esel = SelectPos + SelectSize < bpos + mb? (static_cast(SelectPos + SelectSize - bpos) + CharSize - 1) / CharSize : Width; + const int esel = SelectPos + SelectSize < bpos + mb? (static_cast(SelectPos + SelectSize - bpos) + CharSize - 1) / CharSize : ScrollbarAdjustedWidth; SetColor(COL_VIEWERSELECTEDTEXT); GotoXY(bsel, Y); Text(cut_right(OutStr.substr(bsel), esel - bsel)); @@ -846,13 +846,13 @@ void Viewer::ShowHex() LastPage = false; - if (m_PrevXX2 != XX2) + if (m_PrevHexModeScrollbarAdjustedRight != ScrollbarAdjustedRight) { - m_PrevXX2 = XX2; + m_PrevHexModeScrollbarAdjustedRight = ScrollbarAdjustedRight; // TODO: Add an option if constexpr ((false)) { - m_BytesPerLine = std::min(static_cast(CalculateMaxBytesPerLineByScreenWidth()), m_BytesPerLine); + m_HexModeBytesPerLine = std::min(static_cast(CalculateHexModeMaxBytesPerLine()), m_HexModeBytesPerLine); } } @@ -886,12 +886,12 @@ void Viewer::ShowHex() if ( SelectSize < 0 ) bSelStartFound = bSelEndFound = false; - std::vector RawBuffer(m_BytesPerLine + 3, 0); + std::vector RawBuffer(m_HexModeBytesPerLine + 3, 0); size_t BytesRead = 0; - const auto BytesToRead = CP_UTF8 == m_Codepage ? m_BytesPerLine + 4 - 1 : (m_Codepage == MB.GetCP() ? m_BytesPerLine + MB.GetSize() - 1 : m_BytesPerLine); + const auto BytesToRead = CP_UTF8 == m_Codepage ? m_HexModeBytesPerLine + 4 - 1 : (m_Codepage == MB.GetCP() ? m_HexModeBytesPerLine + MB.GetSize() - 1 : m_HexModeBytesPerLine); Reader.Read(RawBuffer.data(), BytesToRead, &BytesRead); - if (BytesRead > m_BytesPerLine) - Reader.Unread(BytesRead - m_BytesPerLine); + if (BytesRead > m_HexModeBytesPerLine) + Reader.Unread(BytesRead - m_HexModeBytesPerLine); else LastPage = EndFile = veof(); @@ -904,20 +904,20 @@ void Viewer::ShowHex() { if ( SelectSize >= 0 ) { - if (SelectPos >= fpos && SelectPos < fpos + static_cast(m_BytesPerLine)) + if (SelectPos >= fpos && SelectPos < fpos + static_cast(m_HexModeBytesPerLine)) { const auto off = static_cast(SelectPos - fpos); bSelStartFound = true; - SelStart = static_cast(OutStr.size() + 3 * off + (off < s_BytesPerStripe? 0 : BorderLine.size())); + SelStart = static_cast(OutStr.size() + 3 * off + (off < s_HexModeBytesPerStripe? 0 : BorderLine.size())); if (!SelectSize) --SelStart; } const auto selectEnd = SelectPos + SelectSize - 1; - if (selectEnd >= fpos && selectEnd < fpos + static_cast(m_BytesPerLine)) + if (selectEnd >= fpos && selectEnd < fpos + static_cast(m_HexModeBytesPerLine)) { const auto off = static_cast(selectEnd - fpos); bSelEndFound = true; - SelEnd = SelectSize ? static_cast(OutStr.size() + 3 * off + (off < s_BytesPerStripe? 0 : BorderLine.size()) + 1) : SelStart; + SelEnd = SelectSize ? static_cast(OutStr.size() + 3 * off + (off < s_HexModeBytesPerStripe? 0 : BorderLine.size()) + 1) : SelStart; } else if ( SelectSize == 0 && SelectPos == fpos ) { @@ -926,17 +926,17 @@ void Viewer::ShowHex() } } - for (const auto X: std::views::iota(0uz, m_BytesPerLine)) + for (const auto X: std::views::iota(0uz, m_HexModeBytesPerLine)) { if (X < BytesRead) far::format_to(OutStr, L"{:02X} "sv, static_cast(RawBuffer[X])); else OutStr.append(3, L' '); - if (X + 1 != m_BytesPerLine && (X + 1) % s_BytesPerStripe == 0) + if (X + 1 != m_HexModeBytesPerLine && (X + 1) % s_HexModeBytesPerStripe == 0) OutStr += BorderLine; } - tail = txt_dump({ RawBuffer.data(), BytesRead }, m_BytesPerLine, TextStr, ZeroChar(), tail); + tail = txt_dump({ RawBuffer.data(), BytesRead }, m_HexModeBytesPerLine, TextStr, ZeroChar(), tail); } if ((SelEnd <= SelStart) && bSelStartFound && bSelEndFound && SelectSize > 0 ) @@ -1102,18 +1102,18 @@ void Viewer::ReadString(ViewerString *pString, int MaxSize, bool update_cache) if ( !m_Wrap ) continue; - if (m_WordWrap && OutPtr <= Width && CanWrapLineAt(ch)) + if (m_WordWrap && OutPtr <= ScrollbarAdjustedWidth && CanWrapLineAt(ch)) { wrap_out = OutPtr; wrap_pos = fpos1; } - if ( OutPtr < Width ) + if ( OutPtr < ScrollbarAdjustedWidth ) continue; if ( !m_WordWrap ) break; - if ( OutPtr > Width ) + if ( OutPtr > ScrollbarAdjustedWidth ) { if ( wrap_out <= 0 || IsBlankOrEos(ch) ) { @@ -1222,7 +1222,7 @@ long long Viewer::EndOfScreen(int line) { vseek(Strings.back().nFilePos, FILE_BEGIN); int col = 0; - const auto rmargin = static_cast(LeftPos) + Width; + const auto rmargin = static_cast(LeftPos) + ScrollbarAdjustedWidth; wchar_t ch; while (vgetc(&ch)) { @@ -1295,7 +1295,7 @@ long long Viewer::XYfilepos(int col, int row) switch (m_DisplayMode) { case VMT_DUMP: - pos = FilePos + csz*(Width*row + col); + pos = FilePos + csz*(ScrollbarAdjustedWidth*row + col); break; case VMT_HEX: @@ -1303,8 +1303,8 @@ long long Viewer::XYfilepos(int col, int row) //0000000020: 31 00 2E 00 30 00 22 00 | 20 00 65 00 6E 00 63 00 1.0" enc - 2-byte if (col < 11) col = 0; else if (col < 35) col = (col-11)/3; - else if (col < 37) col = s_BytesPerStripe; - else if (col < 61) col = s_BytesPerStripe + (col-37)/3; + else if (col < 37) col = s_HexModeBytesPerStripe; + else if (col < 61) col = s_HexModeBytesPerStripe + (col-37)/3; else if (col < 63) col = 0; else if (col < 63 + 16 / csz) col = (col-63) * csz; else col = 16; @@ -1806,8 +1806,8 @@ bool Viewer::process_key(const Manager::Key& Key) { if (LeftPos>0 && ViewFile) { - if (m_DisplayMode == VMT_HEX && LeftPos > 80 - Width) - LeftPos=std::max(80-Width,1); + if (m_DisplayMode == VMT_HEX && LeftPos > 80 - ScrollbarAdjustedWidth) + LeftPos=std::max(80-ScrollbarAdjustedWidth,1); LeftPos--; Show(); @@ -1874,22 +1874,22 @@ bool Viewer::process_key(const Manager::Key& Key) case KEY_ALTLEFT: case KEY_RALTLEFT: - AdjustBytesPerLine(-1); + AdjustHexModeBytesPerLine(-1); return true; case KEY_CTRLALTLEFT: case KEY_RCTRLALTLEFT: case KEY_CTRLRALTLEFT: case KEY_RCTRLRALTLEFT: - AdjustBytesPerLine(-16); + AdjustHexModeBytesPerLine(-16); return true; case KEY_ALTRIGHT: case KEY_RALTRIGHT: - AdjustBytesPerLine(1); + AdjustHexModeBytesPerLine(1); return true; case KEY_CTRLALTRIGHT: case KEY_RCTRLALTRIGHT: case KEY_CTRLRALTRIGHT: case KEY_RCTRLRALTRIGHT: - AdjustBytesPerLine(16); + AdjustHexModeBytesPerLine(16); return true; case KEY_CTRLSHIFTLEFT: case KEY_CTRLSHIFTNUMPAD4: @@ -1914,7 +1914,7 @@ bool Viewer::process_key(const Manager::Key& Key) { return std::max(Value, i.Data.size()); }); - LeftPos = (MaxLen > static_cast(Width))? MaxLen - Width : 0; + LeftPos = (MaxLen > static_cast(ScrollbarAdjustedWidth))? MaxLen - ScrollbarAdjustedWidth : 0; Show(); } @@ -2121,7 +2121,7 @@ void Viewer::CacheLine( long long start, int length, bool have_eol ) return; if ( lcache_ready - && (lcache_wrap != static_cast(m_Wrap) || lcache_wwrap != static_cast(m_WordWrap) || lcache_width != Width) + && (lcache_wrap != static_cast(m_Wrap) || lcache_wwrap != static_cast(m_WordWrap) || lcache_width != ScrollbarAdjustedWidth) ){ lcache_ready = false; } @@ -2136,7 +2136,7 @@ void Viewer::CacheLine( long long start, int length, bool have_eol ) lcache_lines[0] = (have_eol ? -start : +start); lcache_lines[1] = start + length; - lcache_wrap = m_Wrap; lcache_wwrap = m_WordWrap; lcache_width = Width; + lcache_wrap = m_Wrap; lcache_wwrap = m_WordWrap; lcache_width = ScrollbarAdjustedWidth; lcache_ready = true; } else if (start == lcache_last) @@ -2197,7 +2197,7 @@ void Viewer::CacheLine( long long start, int length, bool have_eol ) int Viewer::CacheFindUp( long long start ) { if ( lcache_ready - && (lcache_wrap != static_cast(m_Wrap) || lcache_wwrap != static_cast(m_WordWrap) || lcache_width != Width) + && (lcache_wrap != static_cast(m_Wrap) || lcache_wwrap != static_cast(m_WordWrap) || lcache_width != ScrollbarAdjustedWidth) ){ lcache_ready = false; } @@ -3759,8 +3759,8 @@ void Viewer::SelectText(const long long& MatchPos,const long long& SearchLength, if ( vString.eol_length == 0 ) { const auto found_offset = static_cast(vString.Data.size()); - if ( found_offset > Width-10 ) - LeftPos = (Width <= 10 ? found_offset : found_offset + 10 - Width); + if ( found_offset > ScrollbarAdjustedWidth-10 ) + LeftPos = (ScrollbarAdjustedWidth <= 10 ? found_offset : found_offset + 10 - ScrollbarAdjustedWidth); } } } diff --git a/far/viewer.hpp b/far/viewer.hpp index d06311eee39..5412685c4e9 100644 --- a/far/viewer.hpp +++ b/far/viewer.hpp @@ -170,8 +170,8 @@ class Viewer:public SimpleScreenObject wchar_t ZeroChar() const; size_t MaxViewLineSize() const { return ViOpt.MaxLineSize; } size_t MaxViewLineBufferSize() const { return ViOpt.MaxLineSize + 15; } - int CalculateMaxBytesPerLineByScreenWidth() const; - void AdjustBytesPerLine(int Amount); + int CalculateHexModeMaxBytesPerLine() const; + void AdjustHexModeBytesPerLine(int Amount); friend class FileViewer; @@ -234,7 +234,10 @@ class Viewer:public SimpleScreenObject std::list UndoData; int LastKeyUndo{}; - int Width{}, XX2{}; // используется при расчете ширины при скролбаре + // используется при расчете ширины при скролбаре + int ScrollbarAdjustedWidth{}; + int ScrollbarAdjustedRight{}; + int ViewerID; bool OpenFailed{}; bool bVE_READ_Sent{}; @@ -307,8 +310,8 @@ class Viewer:public SimpleScreenObject std::vector ReadBuffer; F8CP f8cps{true}; std::optional m_GotoHex; - int m_PrevXX2{}; - size_t m_BytesPerLine{ 16 }; + int m_PrevHexModeScrollbarAdjustedRight{}; + size_t m_HexModeBytesPerLine{ 16 }; }; class ViewerContainer