diff --git a/src/NppJsonViewer/JsonViewDlg.cpp b/src/NppJsonViewer/JsonViewDlg.cpp index 0fe6f5f..d0a66b6 100644 --- a/src/NppJsonViewer/JsonViewDlg.cpp +++ b/src/NppJsonViewer/JsonViewDlg.cpp @@ -466,18 +466,18 @@ void JsonViewDlg::AppendNodeCount(HTREEITEM node, unsigned elementCount, bool bA m_pTreeView->UpdateNodeText(node, txt); } -void JsonViewDlg::UpdateNodePath(HTREEITEM htiNode) +void JsonViewDlg::UpdateNodePath(HTREEITEM htiNode) const { std::wstring nodePath = m_pTreeView->GetNodePath(htiNode); CUtility::SetEditCtrlText(::GetDlgItem(_hSelf, IDC_EDT_NODEPATH), nodePath); } -void JsonViewDlg::GoToLine(size_t nLineToGo) +void JsonViewDlg::GoToLine(size_t nLineToGo) const { m_pEditor->GoToLine(nLineToGo); } -void JsonViewDlg::GoToPosition(size_t nLineToGo, size_t nPos, size_t nLen) +void JsonViewDlg::GoToPosition(size_t nLineToGo, size_t nPos, size_t nLen) const { m_pEditor->GoToPosition(nLineToGo, nPos, nLen); } @@ -673,7 +673,7 @@ void JsonViewDlg::AdjustDocPanelSize(int nWidth, int nHeight) const auto moveWindowIDs = {IDC_BTN_SEARCH}; // elements which requires both resizing and move - const auto resizeAndmoveWindowIDs = {IDC_EDT_NODEPATH}; + const auto resizeAndMoveWindowIDs = {IDC_EDT_NODEPATH}; const UINT flags = SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_SHOWWINDOW; @@ -700,7 +700,7 @@ void JsonViewDlg::AdjustDocPanelSize(int nWidth, int nHeight) ::SetWindowPos(hWnd, NULL, rc.left + addWidth, rc.top, 0, 0, SWP_NOSIZE | flags); } - for (int id : resizeAndmoveWindowIDs) + for (int id : resizeAndMoveWindowIDs) { HWND hWnd = GetDlgItem(_hSelf, id); @@ -895,7 +895,7 @@ void JsonViewDlg::EnableControls(const std::vector& ids, bool enable) EnableWindow(GetDlgItem(getHSelf(), id), enable ? TRUE : FALSE); } -void JsonViewDlg::HandleTreeEvents(LPARAM lParam) +void JsonViewDlg::HandleTreeEvents(LPARAM lParam) const { LPNMHDR lpnmh = reinterpret_cast(lParam); if (!lpnmh || lpnmh->idFrom != IDC_TREE) @@ -1029,7 +1029,7 @@ INT_PTR JsonViewDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) // Save ourselves in GWLP_USERDATA. ::SetWindowLongPtr(getHSelf(), GWLP_USERDATA, reinterpret_cast(this)); - m_pTreeView->OnInit(getHSelf()); + m_pTreeView->OnInit(getHSelf(), IDC_TREE); PrepareButtons(); diff --git a/src/NppJsonViewer/JsonViewDlg.h b/src/NppJsonViewer/JsonViewDlg.h index bff36e6..3fb2a32 100644 --- a/src/NppJsonViewer/JsonViewDlg.h +++ b/src/NppJsonViewer/JsonViewDlg.h @@ -59,9 +59,9 @@ class JsonViewDlg void ValidateJson(); - void UpdateNodePath(HTREEITEM htiNode); - void GoToLine(size_t nLineToGo); - void GoToPosition(size_t nLineToGo, size_t nPos, size_t nLen); + void UpdateNodePath(HTREEITEM htiNode) const; + void GoToLine(size_t nLineToGo) const; + void GoToPosition(size_t nLineToGo, size_t nPos, size_t nLen) const; void SearchInTree(); @@ -89,7 +89,7 @@ class JsonViewDlg void ShowControls(const std::vector& ids, bool show); void EnableControls(const std::vector& ids, bool enable); - void HandleTreeEvents(LPARAM lParam); + void HandleTreeEvents(LPARAM lParam) const; auto GetFormatSetting() const -> std::tuple; diff --git a/src/NppJsonViewer/TreeViewCtrl.cpp b/src/NppJsonViewer/TreeViewCtrl.cpp index 844c685..d2ff8fd 100644 --- a/src/NppJsonViewer/TreeViewCtrl.cpp +++ b/src/NppJsonViewer/TreeViewCtrl.cpp @@ -2,13 +2,13 @@ #include "TreeViewCtrl.h" #include "Define.h" -#include "resource.h" -void TreeViewCtrl::OnInit(HWND hParent) +void TreeViewCtrl::OnInit(HWND hParent, int ctrlID) { + m_nCtrlID = ctrlID; m_hParent = hParent; - m_hTree = GetDlgItem(m_hParent, IDC_TREE); + m_hTree = GetDlgItem(m_hParent, m_nCtrlID); } auto TreeViewCtrl::InitTree() -> HTREEITEM @@ -43,7 +43,7 @@ auto TreeViewCtrl::InsertNode(const std::wstring& text, LPARAM lparam, HTREEITEM tvInsert.item.pszText = const_cast(text.c_str()); tvInsert.item.lParam = lparam; - HTREEITEM item = reinterpret_cast(SendDlgItemMessage(m_hParent, IDC_TREE, TVM_INSERTITEM, 0, reinterpret_cast(&tvInsert))); + HTREEITEM item = reinterpret_cast(SendDlgItemMessage(m_hParent, m_nCtrlID, TVM_INSERTITEM, 0, reinterpret_cast(&tvInsert))); return item; } diff --git a/src/NppJsonViewer/TreeViewCtrl.h b/src/NppJsonViewer/TreeViewCtrl.h index 73dfb01..c5153af 100644 --- a/src/NppJsonViewer/TreeViewCtrl.h +++ b/src/NppJsonViewer/TreeViewCtrl.h @@ -11,13 +11,14 @@ class TreeViewCtrl { HWND m_hTree = nullptr; HWND m_hParent = nullptr; + int m_nCtrlID = 0; size_t m_nMaxNodeTextLength = 0; public: TreeViewCtrl() = default; ~TreeViewCtrl() = default; - void OnInit(HWND hParent); + void OnInit(HWND hParent, int ctrlID); HWND GetTreeViewHandle() const {