/** * @file XTPSyntaxEditGoToLineDlg.cpp * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ #include "stdafx.h" #include "SyntaxEdit/Resource.h" // common includes #include "Common/XTPTypeId.h" #include "Common/XTPFramework.h" #include "Common/XTPSystemHelpers.h" #include "Common/XTPSynchro.h" #include "Common/XTPApplication.h" #include "Common/XTPSingleton.h" #include "Common/XTPGdiObjects.h" #include "Common/XTPDrawHelpers.h" #include "Common/XTPResourceManager.h" #include "Common/XTPColorManager.h" // syntax editor includes #include "SyntaxEdit/XTPSyntaxEditDefines.h" #include "SyntaxEdit/XTPSyntaxEditStruct.h" #include "SyntaxEdit/XTPSyntaxEditCtrl.h" #include "SyntaxEdit/XTPSyntaxEditGoToLineDlg.h" #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif //=========================================================================== // CXTPSyntaxEditGoToLineDlg //=========================================================================== CXTPSyntaxEditGoToLineDlg::CXTPSyntaxEditGoToLineDlg(CWnd* pParent /*=NULL*/) : // CDialog(CXTPSyntaxEditGoToLineDlg::IDD, pParent), m_iMaxLineNo(0) , m_bHideOnFind(TRUE) , m_bSelectLine(FALSE) , m_ptWndPos(CPoint(-1, -1)) , m_pEditCtrl(NULL) { InitModalIndirect(XTPResourceManager()->LoadDialogTemplate(IDD), pParent); //{{AFX_DATA_INIT(CXTPSyntaxEditGoToLineDlg) m_iLineNo = 0; m_csLineNo = _T(""); //}}AFX_DATA_INIT } void CXTPSyntaxEditGoToLineDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CXTPSyntaxEditGoToLineDlg) DDX_Control(pDX, XTP_IDC_EDIT_LINENO, m_wndEditLineNo); DDX_Text(pDX, XTP_IDC_EDIT_LINENO, m_iLineNo); DDX_Text(pDX, XTP_IDC_EDIT_TXT_LINENO, m_csLineNo); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CXTPSyntaxEditGoToLineDlg, CDialog) //{{AFX_MSG_MAP(CXTPSyntaxEditGoToLineDlg) ON_EN_CHANGE(XTP_IDC_EDIT_LINENO, OnChangeEditLineNo) ON_BN_CLICKED(XTP_IDC_EDIT_BTN_GOTO, OnBtnGoTo) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CXTPSyntaxEditGoToLineDlg message handlers void CXTPSyntaxEditGoToLineDlg::OnChangeEditLineNo() { UpdateData(); } BOOL CXTPSyntaxEditGoToLineDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here _ASSERTE(m_pEditCtrl); m_iMaxLineNo = m_pEditCtrl->GetRowCount(); m_iLineNo = m_pEditCtrl->GetCurRow(); m_csLineNo.Format(XTPResourceManager()->LoadString(XTP_IDS_EDIT_LINENO), m_iMaxLineNo); UpdateData(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } BOOL CXTPSyntaxEditGoToLineDlg::ShowDialog(CXTPSyntaxEditCtrl* pEditCtrl, BOOL bSelectLine /*=FALSE*/, BOOL bHideOnFind /*=FALSE*/) { _ASSERTE(pEditCtrl); if (!::IsWindow(pEditCtrl->GetSafeHwnd())) return FALSE; m_pEditCtrl = pEditCtrl; m_bSelectLine = bSelectLine; m_bHideOnFind = bHideOnFind; // already created, bring to foreground. if (::IsWindow(m_hWnd)) { ::ShowWindow(m_hWnd, SW_RESTORE); ::BringWindowToTop(m_hWnd); ::SetForegroundWindow(m_hWnd); } else { if (!CreateIndirect(XTPResourceManager()->LoadDialogTemplate(IDD), m_pEditCtrl)) { TRACE0("Error creating go to dialog.\n"); return FALSE; } UpdateData(FALSE); LoadPos(); CXTPWindowRect rc(this); ::MoveWindow(m_hWnd, m_ptWndPos.x, m_ptWndPos.y, rc.Width(), rc.Height(), FALSE); ::ShowWindow(m_hWnd, SW_SHOW); } m_wndEditLineNo.SetFocus(); m_wndEditLineNo.SetSel(0, -1); return TRUE; } BOOL CXTPSyntaxEditGoToLineDlg::LoadPos() { if (!::IsWindow(m_hWnd)) return FALSE; if (m_ptWndPos.x != -1 && m_ptWndPos.y != -1) return FALSE; CXTPWindowRect r1(this); CXTPWindowRect r2(m_pEditCtrl); m_ptWndPos.x = r2.left + ((r2.Width() - r1.Width()) / 2); m_ptWndPos.y = r2.top + ((r2.Height() - r1.Height()) / 2); return TRUE; } BOOL CXTPSyntaxEditGoToLineDlg::SavePos() { if (!::IsWindow(m_hWnd)) return FALSE; CXTPWindowRect rc(this); m_ptWndPos = rc.TopLeft(); return TRUE; } BOOL CXTPSyntaxEditGoToLineDlg::PreTranslateMessage(MSG* pMsg) { if ((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_RETURN)) { OnBtnGoTo(); return TRUE; // don't close dialog. } return CDialog::PreTranslateMessage(pMsg); } void CXTPSyntaxEditGoToLineDlg::OnBtnGoTo() { if (m_iLineNo > m_iMaxLineNo) { m_iLineNo = m_iMaxLineNo; UpdateData(FALSE); } else if (m_iLineNo < 1) { m_iLineNo = 1; UpdateData(FALSE); } m_pEditCtrl->GoToRow(m_iLineNo, m_bSelectLine); if (!m_bHideOnFind && !m_bSelectLine) m_pEditCtrl->SetFocus(); else if (m_bHideOnFind) OnCancel(); else m_wndEditLineNo.SetSel(0, -1); } void CXTPSyntaxEditGoToLineDlg::OnCancel() { SavePos(); CDialog::OnCancel(); if (::IsWindow(m_hWnd)) ::DestroyWindow(m_hWnd); }