1212
1313constexpr int FILENAME_LEN_IN_TITLE = 16 ;
1414
15+ namespace SliderPercent
16+ {
17+ constexpr const int nDefault = 100 ;
18+ constexpr const int nMinZoom = 80 ;
19+ constexpr const int nMaxZoom = 250 ;
20+ }; // namespace SliderPercent
21+
1522JsonViewDlg::JsonViewDlg (HINSTANCE hInstance, const NppData& nppData, const bool & isReady, int nCmdId, std::shared_ptr<Setting>& pSetting)
1623 : DockingDlgInterface(IDD_TREEDLG)
1724 , m_NppData(nppData)
@@ -895,6 +902,27 @@ void JsonViewDlg::EnableControls(const std::vector<DWORD>& ids, bool enable)
895902 EnableWindow (GetDlgItem (getHSelf (), id), enable ? TRUE : FALSE );
896903}
897904
905+ auto JsonViewDlg::GetSliderPosition () const -> int
906+ {
907+ HWND hSlider = GetDlgItem (getHSelf (), IDC_ZOOM_SLIDER);
908+ int pos = static_cast <int >(SendMessage (hSlider, TBM_GETPOS, 0 , 0 ));
909+
910+ return pos;
911+ }
912+
913+ void JsonViewDlg::SetSliderPosition (int pos) const
914+ {
915+ // Set slider position
916+ HWND hSlider = GetDlgItem (getHSelf (), IDC_ZOOM_SLIDER);
917+ SendMessage (hSlider, TBM_SETPOS, TRUE , pos);
918+
919+ // Set slider position in text value
920+ HWND hZoomPercent = GetDlgItem (getHSelf (), IDC_ZOOM_PERCENT);
921+ wchar_t zoomText[16 ] {};
922+ wsprintf (zoomText, L" %d%%" , pos);
923+ SetWindowText (hZoomPercent, zoomText);
924+ }
925+
898926void JsonViewDlg::SetTreeViewZoom (double dwZoomFactor)
899927{
900928 HWND hTreeView = GetDlgItem (getHSelf (), IDC_TREE);
@@ -915,20 +943,32 @@ void JsonViewDlg::SetTreeViewZoom(double dwZoomFactor)
915943 InvalidateRect (hTreeView, nullptr , TRUE );
916944}
917945
918- void JsonViewDlg::HandleZoom (bool zoomIn)
946+ void JsonViewDlg::UpdateUIOnZoom (int zoomPercentage)
947+ {
948+ // Update slider
949+ SetSliderPosition (zoomPercentage);
950+
951+ // Update the Tree view
952+ double zoomFactor = zoomPercentage / 100.0 ;
953+ SetTreeViewZoom (zoomFactor);
954+ }
955+
956+ void JsonViewDlg::HandleZoomOnScroll (WPARAM wParam)
919957{
920- static double zoomLevel = 1.0 ; // Start at 100% zoom (Max 300% and min 80%)
958+ int pos = GetSliderPosition (); // Current slider position
959+ int delta = GET_WHEEL_DELTA_WPARAM (wParam);
921960
922- if (zoomIn && zoomLevel < 3.0 )
961+ // Adjust zoom based on scroll direction
962+ if (delta > 0 && pos < SliderPercent::nMaxZoom)
923963 {
924- zoomLevel += 0.1 ; // Zoom in (max 300%)
964+ pos += 10 ; // Zoom in
925965 }
926- else if (!zoomIn && zoomLevel > 0.8 )
966+ else if (delta < 0 && pos > SliderPercent::nMinZoom )
927967 {
928- zoomLevel -= 0.1 ; // Zoom out (min 80%)
968+ pos -= 10 ; // Zoom out
929969 }
930970
931- SetTreeViewZoom (zoomLevel );
971+ UpdateUIOnZoom (pos );
932972}
933973
934974void JsonViewDlg::HandleTreeEvents (LPARAM lParam) const
@@ -1072,6 +1112,12 @@ INT_PTR JsonViewDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
10721112 // Set default node path as JSON
10731113 SetDlgItemText (_hSelf, IDC_EDT_NODEPATH, JSON_ROOT);
10741114
1115+ // Set slider range from 80% to 200%
1116+ // Set initial position to 100% (no zoom)
1117+ HWND hSlider = GetDlgItem (getHSelf (), IDC_ZOOM_SLIDER);
1118+ SendMessage (hSlider, TBM_SETRANGE, TRUE , MAKELPARAM (SliderPercent::nMinZoom, SliderPercent::nMaxZoom));
1119+ SendMessage (hSlider, TBM_SETPOS, TRUE , SliderPercent::nDefault);
1120+
10751121 return TRUE ;
10761122 }
10771123
@@ -1147,12 +1193,27 @@ INT_PTR JsonViewDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
11471193 {
11481194 if (GetKeyState (VK_CONTROL) & 0x8000 )
11491195 {
1150- HandleZoom (GET_WHEEL_DELTA_WPARAM (wParam) > 0 );
1196+ HandleZoomOnScroll (wParam);
1197+ return TRUE ;
1198+ }
1199+ return FALSE ;
1200+ }
1201+
1202+ case WM_HSCROLL:
1203+ {
1204+ HWND hSlider = GetDlgItem (getHSelf (), IDC_ZOOM_SLIDER);
1205+
1206+ if (reinterpret_cast <HWND>(lParam) == hSlider)
1207+ {
1208+ int pos = GetSliderPosition ();
1209+ UpdateUIOnZoom (pos);
1210+
11511211 return TRUE ;
11521212 }
11531213 return FALSE ;
11541214 }
11551215
1216+
11561217 default :
11571218 return DockingDlgInterface::run_dlgProc (message, wParam, lParam);
11581219 }
0 commit comments