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-
2215JsonViewDlg::JsonViewDlg (HINSTANCE hInstance, const NppData& nppData, const bool & isReady, int nCmdId, std::shared_ptr<Setting>& pSetting)
2316 : DockingDlgInterface(IDD_TREEDLG)
2417 , m_NppData(nppData)
2518 , m_IsNppReady(isReady)
2619 , m_nDlgId(nCmdId)
2720 , m_pEditor(std::make_unique<ScintillaEditor>(nppData))
2821 , m_pTreeView(std::make_unique<TreeViewCtrl>())
22+ , m_pTreeViewZoom(std::make_unique<SliderCtrl>())
2923 , m_pSetting(pSetting)
3024 , m_pCurrFileName(std::make_unique<wchar_t []>(FILENAME_LEN_IN_TITLE))
3125{
@@ -902,25 +896,14 @@ void JsonViewDlg::EnableControls(const std::vector<DWORD>& ids, bool enable)
902896 EnableWindow (GetDlgItem (getHSelf (), id), enable ? TRUE : FALSE );
903897}
904898
905- auto JsonViewDlg::GetSliderPosition () const -> int
899+ auto JsonViewDlg::GetZoomLevel () const -> int
906900{
907- HWND hSlider = GetDlgItem (getHSelf (), IDC_ZOOM_SLIDER);
908- int pos = static_cast <int >(SendMessage (hSlider, TBM_GETPOS, 0 , 0 ));
909-
910- return pos;
901+ return m_pTreeViewZoom->GetPosition ();
911902}
912903
913- void JsonViewDlg::SetSliderPosition (int pos) const
904+ void JsonViewDlg::SetZoomLevel (int pos) const
914905{
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);
906+ m_pTreeViewZoom->SetPosition (pos);
924907}
925908
926909void JsonViewDlg::SetTreeViewZoom (double dwZoomFactor) const
@@ -945,8 +928,8 @@ void JsonViewDlg::SetTreeViewZoom(double dwZoomFactor) const
945928
946929void JsonViewDlg::UpdateUIOnZoom (int zoomPercentage) const
947930{
948- // Update slider
949- SetSliderPosition (zoomPercentage);
931+ // Update zoom level on slider
932+ SetZoomLevel (zoomPercentage);
950933
951934 // Update the Tree view
952935 double zoomFactor = zoomPercentage / 100.0 ;
@@ -955,15 +938,17 @@ void JsonViewDlg::UpdateUIOnZoom(int zoomPercentage) const
955938
956939void JsonViewDlg::HandleZoomOnScroll (WPARAM wParam) const
957940{
958- int pos = GetSliderPosition (); // Current slider position
941+ int pos = GetZoomLevel (); // Current zoom level
959942 int delta = GET_WHEEL_DELTA_WPARAM (wParam);
960943
961- // Adjust zoom based on scroll direction
962- if (delta > 0 && pos < SliderPercent::nMaxZoom)
944+ const auto & zoomRange = m_pTreeViewZoom->GetRange ();
945+ const bool isZoom = delta > 0 ;
946+
947+ if (isZoom && pos < zoomRange.m_nMaxZoom )
963948 {
964949 pos += 10 ; // Zoom in
965950 }
966- else if (delta < 0 && pos > SliderPercent::nMinZoom )
951+ else if (!isZoom && pos > zoomRange. m_nMinZoom )
967952 {
968953 pos -= 10 ; // Zoom out
969954 }
@@ -1106,18 +1091,13 @@ INT_PTR JsonViewDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
11061091 ::SetWindowLongPtr (getHSelf(), GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this ));
11071092
11081093 m_pTreeView->OnInit (getHSelf (), IDC_TREE);
1094+ m_pTreeViewZoom->OnInit (getHSelf (), IDC_ZOOM_SLIDER, IDC_ZOOM_PERCENT);
11091095
11101096 PrepareButtons ();
11111097
11121098 // Set default node path as JSON
11131099 SetDlgItemText (_hSelf, IDC_EDT_NODEPATH, JSON_ROOT);
11141100
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-
11211101 return TRUE ;
11221102 }
11231103
@@ -1205,7 +1185,7 @@ INT_PTR JsonViewDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
12051185
12061186 if (reinterpret_cast <HWND>(lParam) == hSlider)
12071187 {
1208- int pos = GetSliderPosition ();
1188+ int pos = m_pTreeViewZoom-> GetPosition ();
12091189 UpdateUIOnZoom (pos);
12101190
12111191 return TRUE ;
0 commit comments