Skip to content

Commit fddc8be

Browse files
committed
Add zoom feature for treeview on ctrl+mouse scroll
1 parent 3f37522 commit fddc8be

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/NppJsonViewer/JsonViewDlg.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,42 @@ void JsonViewDlg::EnableControls(const std::vector<DWORD>& ids, bool enable)
895895
EnableWindow(GetDlgItem(getHSelf(), id), enable ? TRUE : FALSE);
896896
}
897897

898+
void JsonViewDlg::SetTreeViewZoom(double dwZoomFactor)
899+
{
900+
HWND hTreeView = GetDlgItem(getHSelf(), IDC_TREE);
901+
static HFONT hCurrentFont = reinterpret_cast<HFONT>(SendMessage(hTreeView, WM_GETFONT, 0, 0));
902+
903+
LOGFONT logFont {};
904+
GetObject(hCurrentFont, sizeof(LOGFONT), &logFont);
905+
logFont.lfHeight = static_cast<LONG>(logFont.lfHeight * dwZoomFactor);
906+
907+
static HFONT hTreeFont = nullptr;
908+
if (hTreeFont)
909+
{
910+
DeleteObject(hTreeFont);
911+
}
912+
hTreeFont = CreateFontIndirect(&logFont);
913+
914+
SendMessage(hTreeView, WM_SETFONT, reinterpret_cast<WPARAM>(hTreeFont), TRUE);
915+
InvalidateRect(hTreeView, nullptr, TRUE);
916+
}
917+
918+
void JsonViewDlg::HandleZoom(bool zoomIn)
919+
{
920+
static double zoomLevel = 1.0; // Start at 100% zoom (Max 300% and min 80%)
921+
922+
if (zoomIn && zoomLevel < 3.0)
923+
{
924+
zoomLevel += 0.1; // Zoom in (max 300%)
925+
}
926+
else if (!zoomIn && zoomLevel > 0.8)
927+
{
928+
zoomLevel -= 0.1; // Zoom out (min 80%)
929+
}
930+
931+
SetTreeViewZoom(zoomLevel);
932+
}
933+
898934
void JsonViewDlg::HandleTreeEvents(LPARAM lParam) const
899935
{
900936
LPNMHDR lpnmh = reinterpret_cast<LPNMHDR>(lParam);
@@ -1107,6 +1143,16 @@ INT_PTR JsonViewDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
11071143
return TRUE;
11081144
}
11091145

1146+
case WM_MOUSEWHEEL:
1147+
{
1148+
if (GetKeyState(VK_CONTROL) & 0x8000)
1149+
{
1150+
HandleZoom(GET_WHEEL_DELTA_WPARAM(wParam) > 0);
1151+
return TRUE;
1152+
}
1153+
return FALSE;
1154+
}
1155+
11101156
default:
11111157
return DockingDlgInterface::run_dlgProc(message, wParam, lParam);
11121158
}

src/NppJsonViewer/JsonViewDlg.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ class JsonViewDlg
8989
void ShowControls(const std::vector<DWORD>& ids, bool show);
9090
void EnableControls(const std::vector<DWORD>& ids, bool enable);
9191

92+
auto GetZoomLevel() const -> int;
93+
void SetZoomLevel(int pos) const;
94+
void SetTreeViewZoom(double dwZoomFactor) const;
95+
void UpdateUIOnZoom(int zoomPercentage) const;
96+
void HandleZoomOnScroll(WPARAM wParam) const;
97+
9298
void HandleTreeEvents(LPARAM lParam) const;
9399

94100
auto GetFormatSetting() const -> std::tuple<LE, LF, char, unsigned>;

0 commit comments

Comments
 (0)