@@ -19,6 +19,7 @@ JsonViewDlg::JsonViewDlg(HINSTANCE hInstance, const NppData& nppData, const bool
1919 , m_nDlgId(nCmdId)
2020 , m_pEditor(std::make_unique<ScintillaEditor>(nppData))
2121 , m_pTreeView(std::make_unique<TreeViewCtrl>())
22+ , m_pTreeViewZoom(std::make_unique<SliderCtrl>())
2223 , m_pSetting(pSetting)
2324 , m_pCurrFileName(std::make_unique<wchar_t []>(FILENAME_LEN_IN_TITLE))
2425{
@@ -895,6 +896,74 @@ void JsonViewDlg::EnableControls(const std::vector<DWORD>& ids, bool enable)
895896 EnableWindow (GetDlgItem (getHSelf (), id), enable ? TRUE : FALSE );
896897}
897898
899+ auto JsonViewDlg::GetZoomLevel () const -> int
900+ {
901+ return m_pTreeViewZoom->GetPosition ();
902+ }
903+
904+ void JsonViewDlg::SetZoomLevel (int pos) const
905+ {
906+ m_pTreeViewZoom->SetPosition (pos);
907+ }
908+
909+ void JsonViewDlg::SetTreeViewZoom (double dwZoomFactor) const
910+ {
911+ HWND hTreeView = GetDlgItem (getHSelf (), IDC_TREE);
912+ static HFONT hCurrentFont = reinterpret_cast <HFONT>(SendMessage (hTreeView, WM_GETFONT, 0 , 0 ));
913+
914+ LOGFONT logFont {};
915+ GetObject (hCurrentFont, sizeof (LOGFONT), &logFont);
916+ logFont.lfHeight = static_cast <LONG>(logFont.lfHeight * dwZoomFactor);
917+
918+ static HFONT hTreeFont = nullptr ;
919+ if (hTreeFont)
920+ {
921+ DeleteObject (hTreeFont);
922+ }
923+ hTreeFont = CreateFontIndirect (&logFont);
924+
925+ SendMessage (hTreeView, WM_SETFONT, reinterpret_cast <WPARAM>(hTreeFont), TRUE );
926+ InvalidateRect (hTreeView, nullptr , TRUE );
927+ }
928+
929+ void JsonViewDlg::UpdateUIOnZoom (int zoomPercentage) const
930+ {
931+ // Update zoom level on slider
932+ SetZoomLevel (zoomPercentage);
933+
934+ // Update the Tree view
935+ double zoomFactor = zoomPercentage / 100.0 ;
936+ SetTreeViewZoom (zoomFactor);
937+ }
938+
939+ void JsonViewDlg::HandleZoomOnScroll (WPARAM wParam) const
940+ {
941+ int pos = GetZoomLevel (); // Current zoom level
942+ int delta = GET_WHEEL_DELTA_WPARAM (wParam);
943+
944+ const auto & zoomRange = m_pTreeViewZoom->GetRange ();
945+ const bool isZoomIn = delta > 0 ;
946+ bool bRefreshUI = true ;
947+
948+ if (isZoomIn && pos < zoomRange.m_nMaxZoom )
949+ {
950+ pos += 10 ; // Zoom in
951+ }
952+ else if (!isZoomIn && pos > zoomRange.m_nMinZoom )
953+ {
954+ pos -= 10 ; // Zoom out
955+ }
956+ else
957+ {
958+ bRefreshUI = false ;
959+ }
960+
961+ if (bRefreshUI)
962+ {
963+ UpdateUIOnZoom (pos);
964+ }
965+ }
966+
898967void JsonViewDlg::HandleTreeEvents (LPARAM lParam) const
899968{
900969 LPNMHDR lpnmh = reinterpret_cast <LPNMHDR>(lParam);
@@ -1030,6 +1099,7 @@ INT_PTR JsonViewDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
10301099 ::SetWindowLongPtr (getHSelf(), GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this ));
10311100
10321101 m_pTreeView->OnInit (getHSelf (), IDC_TREE);
1102+ m_pTreeViewZoom->OnInit (getHSelf (), IDC_ZOOM_SLIDER, IDC_ZOOM_PERCENT);
10331103
10341104 PrepareButtons ();
10351105
@@ -1107,6 +1177,31 @@ INT_PTR JsonViewDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
11071177 return TRUE ;
11081178 }
11091179
1180+ case WM_MOUSEWHEEL:
1181+ {
1182+ if (GetKeyState (VK_CONTROL) & 0x8000 )
1183+ {
1184+ HandleZoomOnScroll (wParam);
1185+ return TRUE ;
1186+ }
1187+ return FALSE ;
1188+ }
1189+
1190+ case WM_HSCROLL:
1191+ {
1192+ HWND hSlider = GetDlgItem (getHSelf (), IDC_ZOOM_SLIDER);
1193+
1194+ if (reinterpret_cast <HWND>(lParam) == hSlider)
1195+ {
1196+ int pos = m_pTreeViewZoom->GetPosition ();
1197+ UpdateUIOnZoom (pos);
1198+
1199+ return TRUE ;
1200+ }
1201+ return FALSE ;
1202+ }
1203+
1204+
11101205 default :
11111206 return DockingDlgInterface::run_dlgProc (message, wParam, lParam);
11121207 }
0 commit comments