1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * @brief Implementation of the WMGotoDlg dialog.
10 #include "TrDialogs.h"
17 * @brief Class for Goto-dialog.
18 * This dialog allows user to go to certain line or or difference in the file
19 * compare. As there are two panels with different line numbers, there is a
20 * choice for target panel. When dialog is opened, its values are initialized
21 * for active file's line number.
23 class WMGotoDlg::Impl : public CTrDialog
27 explicit Impl(WMGotoDlg *p, CWnd* pParent = nullptr); // standard constructor
30 //{{AFX_DATA(WMGotoDlg)
31 enum { IDD = IDD_WMGOTO };
35 // ClassWizard generated virtual function overrides
36 //{{AFX_VIRTUAL(WMGotoDlg)
38 virtual BOOL OnInitDialog() override;
39 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
45 // Generated message map functions
46 //{{AFX_MSG(WMGotoDlg)
47 // NOTE: the ClassWizard will add member functions here
48 afx_msg void OnChangeParam();
49 afx_msg void OnBnClicked(UINT nID);
55 String m_strRange; /**< Acceptable range */
59 void UpdateGoToButton();
62 /////////////////////////////////////////////////////////////////////////////
68 WMGotoDlg::Impl::Impl(WMGotoDlg *p, CWnd* pParent /*= nullptr*/)
69 : CTrDialog(WMGotoDlg::Impl::IDD, pParent), m_p(p)
74 * @brief Initialize the dialog.
75 * @return Always TRUE.
77 BOOL WMGotoDlg::Impl::OnInitDialog()
79 LangTranslateDialog(m_hWnd);
80 CDialog::OnInitDialog();
82 if (m_p->m_nFiles < 3)
83 EnableDlgItem(IDC_WMGOTO_FILEMIDDLE, false);
84 if (m_p->m_nLastDiff == 0)
85 EnableDlgItem(IDC_WMGOTO_TODIFF, false);
94 void WMGotoDlg::Impl::DoDataExchange(CDataExchange* pDX)
96 CTrDialog::DoDataExchange(pDX);
97 //{{AFX_DATA_MAP(WMGotoDlg)
98 DDX_Text(pDX, IDC_WMGOTO_PARAM, m_p->m_strParam);
99 DDX_Radio(pDX, IDC_WMGOTO_FILELEFT, m_p->m_nFile);
100 DDX_Radio(pDX, IDC_WMGOTO_TOLINE, m_p->m_nGotoWhat);
101 DDX_Text(pDX, IDC_WMGOTO_RANGE, m_strRange);
106 BEGIN_MESSAGE_MAP(WMGotoDlg::Impl, CTrDialog)
107 //{{AFX_MSG_MAP(WMGotoDlg::Impl)
108 // NOTE: the ClassWizard will add message map macros here
109 ON_EN_CHANGE(IDC_WMGOTO_PARAM, OnChangeParam)
110 ON_CONTROL_RANGE(BN_CLICKED, IDC_WMGOTO_FILELEFT, IDC_WMGOTO_FILERIGHT, OnBnClicked)
111 ON_CONTROL_RANGE(BN_CLICKED, IDC_WMGOTO_TOLINE, IDC_WMGOTO_TODIFF, OnBnClicked)
116 * @brief Called when the edit string changes.
118 void WMGotoDlg::Impl::OnChangeParam()
125 * @brief Called when user selects "File" or "Go to what" radio button.
126 * @param [in] nID Button ID of the selected item
128 void WMGotoDlg::Impl::OnBnClicked(UINT nID)
130 bool bIsValidId = (nID >= IDC_WMGOTO_FILELEFT && nID <= IDC_WMGOTO_FILERIGHT) || (nID >= IDC_WMGOTO_TOLINE && nID <= IDC_WMGOTO_TODIFF);
142 * @brief Get upper bound of acceptable range for selected "File" and "Go to what".
143 * @return Upper bound of acceptable range for selected "File" and "Go to what".
145 int WMGotoDlg::Impl::GetRangeMax()
147 bool bIsValidState = ((m_p->m_nGotoWhat >= 0 && m_p->m_nGotoWhat <= 1) && (m_p->m_nFile >= 0 && m_p->m_nFile <= 2));
148 assert(bIsValidState);
152 return (m_p->m_nGotoWhat == 0) ? m_p->m_nLastLine[m_p->m_nFile] : m_p->m_nLastDiff;
156 * @brief Update the acceptable range.
158 void WMGotoDlg::Impl::UpdateRange()
160 int nRangeMax = GetRangeMax();
161 m_strRange = (nRangeMax > 0) ? strutils::format(_T("(1-%d)"), nRangeMax) : _T("");
165 * @brief Update the enabled state of the "Go to" button.
167 void WMGotoDlg::Impl::UpdateGoToButton()
172 nNum = std::stoi(m_p->m_strParam);
179 bool bEnable = (nNum > 0 && nNum <= GetRangeMax());
180 EnableDlgItem(IDOK, bEnable);
183 /////////////////////////////////////////////////////////////////////////////
184 // WMGotoDlg message handlers
188 WMGotoDlg::WMGotoDlg()
189 : m_pimpl(new WMGotoDlg::Impl(this)), m_nFile(-1), m_nGotoWhat(-1), m_nFiles(-1), m_nLastLine{-1, -1, -1}, m_nLastDiff(-1) {}
190 WMGotoDlg::~WMGotoDlg() = default;
191 int WMGotoDlg::DoModal() { return static_cast<int>(m_pimpl->DoModal()); }