XTPSyntaxEditGoToLineDlg.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:6k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // XTPSyntaxEditGoToLineDlg.cpp : implementation file
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "Resource.h"
  22. // common includes
  23. #include "Common/XTPDrawHelpers.h"
  24. #include "Common/XTPNotifyConnection.h"
  25. #include "Common/XTPSmartPtrInternalT.h"
  26. #include "Common/XTPResourceManager.h"
  27. // syntax editor includes
  28. #include "XTPSyntaxEditDefines.h"
  29. #include "XTPSyntaxEditStruct.h"
  30. #include "XTPSyntaxEditLexPtrs.h"
  31. #include "XTPSyntaxEditLexClassSubObjT.h"
  32. #include "XTPSyntaxEditTextIterator.h"
  33. #include "XTPSyntaxEditSectionManager.h"
  34. #include "XTPSyntaxEditLexCfgFileReader.h"
  35. #include "XTPSyntaxEditLexClassSubObjDef.h"
  36. #include "XTPSyntaxEditLexClass.h"
  37. #include "XTPSyntaxEditLexParser.h"
  38. #include "XTPSyntaxEditCtrl.h"
  39. #include "XTPSyntaxEditGoToLineDlg.h"
  40. #ifdef _DEBUG
  41. #define new DEBUG_NEW
  42. #undef THIS_FILE
  43. static char THIS_FILE[] = __FILE__;
  44. #endif
  45. //===========================================================================
  46. // CXTPSyntaxEditGoToLineDlg
  47. //===========================================================================
  48. CXTPSyntaxEditGoToLineDlg::CXTPSyntaxEditGoToLineDlg(CWnd* pParent /*=NULL*/)
  49. : //CDialog(CXTPSyntaxEditGoToLineDlg::IDD, pParent),
  50. m_pEditCtrl(NULL)
  51. , m_iMaxLineNo(0)
  52. , m_ptWndPos(CPoint(-1,-1))
  53. , m_bHideOnFind(TRUE)
  54. , m_bSelectLine(FALSE)
  55. {
  56. InitModalIndirect(XTPResourceManager()->LoadDialogTemplate(IDD), pParent);
  57. //{{AFX_DATA_INIT(CXTPSyntaxEditGoToLineDlg)
  58. m_iLineNo = 0;
  59. m_csLineNo = _T("");
  60. //}}AFX_DATA_INIT
  61. }
  62. void CXTPSyntaxEditGoToLineDlg::DoDataExchange(CDataExchange* pDX)
  63. {
  64. CDialog::DoDataExchange(pDX);
  65. //{{AFX_DATA_MAP(CXTPSyntaxEditGoToLineDlg)
  66. DDX_Control(pDX, XTP_IDC_EDIT_LINENO, m_wndEditLineNo);
  67. DDX_Text(pDX, XTP_IDC_EDIT_LINENO, m_iLineNo);
  68. DDX_Text(pDX, XTP_IDC_EDIT_TXT_LINENO, m_csLineNo);
  69. //}}AFX_DATA_MAP
  70. }
  71. BEGIN_MESSAGE_MAP(CXTPSyntaxEditGoToLineDlg, CDialog)
  72. //{{AFX_MSG_MAP(CXTPSyntaxEditGoToLineDlg)
  73. ON_EN_CHANGE(XTP_IDC_EDIT_LINENO, OnChangeEditLineNo)
  74. ON_BN_CLICKED(XTP_IDC_EDIT_BTN_GOTO, OnBtnGoTo)
  75. //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CXTPSyntaxEditGoToLineDlg message handlers
  79. void CXTPSyntaxEditGoToLineDlg::OnChangeEditLineNo()
  80. {
  81. UpdateData();
  82. }
  83. BOOL CXTPSyntaxEditGoToLineDlg::OnInitDialog()
  84. {
  85. CDialog::OnInitDialog();
  86. // TODO: Add extra initialization here
  87. ASSERT_VALID(m_pEditCtrl);
  88. m_iMaxLineNo = m_pEditCtrl->GetRowCount();
  89. m_iLineNo    = m_pEditCtrl->GetCurRow();
  90. m_csLineNo.Format(XTPResourceManager()->LoadString(XTP_IDS_EDIT_LINENO), m_iMaxLineNo);
  91. UpdateData(FALSE);
  92. return TRUE;  // return TRUE unless you set the focus to a control
  93.               // EXCEPTION: OCX Property Pages should return FALSE
  94. }
  95. BOOL CXTPSyntaxEditGoToLineDlg::ShowDialog(CXTPSyntaxEditCtrl* pEditCtrl, BOOL bSelectLine /*=FALSE*/, BOOL bHideOnFind /*=FALSE*/)
  96. {
  97. ASSERT_VALID(pEditCtrl);
  98. if (!::IsWindow(pEditCtrl->GetSafeHwnd()))
  99. return FALSE;
  100. m_pEditCtrl = pEditCtrl;
  101. m_bSelectLine = bSelectLine;
  102. m_bHideOnFind = bHideOnFind;
  103. // already created, bring to foreground.
  104. if (::IsWindow(m_hWnd))
  105. {
  106. ::ShowWindow(m_hWnd, SW_RESTORE);
  107. ::BringWindowToTop(m_hWnd);
  108. ::SetForegroundWindow(m_hWnd);
  109. }
  110. else
  111. {
  112. if (!CreateIndirect(XTPResourceManager()->LoadDialogTemplate2(MAKEINTRESOURCE(IDD)), m_pEditCtrl))
  113. {
  114. TRACE0("Error creating go to dialog.n");
  115. return FALSE;
  116. }
  117. UpdateData(FALSE);
  118. LoadPos();
  119. CXTPWindowRect rc(this);
  120. ::MoveWindow(m_hWnd, m_ptWndPos.x, m_ptWndPos.y, rc.Width(), rc.Height(), FALSE);
  121. ::ShowWindow(m_hWnd, SW_SHOW);
  122. }
  123. m_wndEditLineNo.SetFocus();
  124. m_wndEditLineNo.SetSel(0,-1);
  125. return TRUE;
  126. }
  127. BOOL CXTPSyntaxEditGoToLineDlg::LoadPos()
  128. {
  129. if (!::IsWindow(m_hWnd))
  130. return FALSE;
  131. if (m_ptWndPos.x != -1 && m_ptWndPos.y != -1)
  132. return FALSE;
  133. CXTPWindowRect r1(this);
  134. CXTPWindowRect r2(m_pEditCtrl);
  135. m_ptWndPos.x = r2.left + ((r2.Width()-r1.Width())/2);
  136. m_ptWndPos.y = r2.top + ((r2.Height()-r1.Height())/2);
  137. return TRUE;
  138. }
  139. BOOL CXTPSyntaxEditGoToLineDlg::SavePos()
  140. {
  141. if (!::IsWindow(m_hWnd))
  142. return FALSE;
  143. CXTPWindowRect rc(this);
  144. m_ptWndPos = rc.TopLeft();
  145. return TRUE;
  146. }
  147. BOOL CXTPSyntaxEditGoToLineDlg::PreTranslateMessage(MSG* pMsg)
  148. {
  149. if ((pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_RETURN))
  150. {
  151. OnBtnGoTo();
  152. return TRUE; // don't close dialog.
  153. }
  154. return CDialog::PreTranslateMessage(pMsg);
  155. }
  156. void CXTPSyntaxEditGoToLineDlg::OnBtnGoTo()
  157. {
  158. if (m_iLineNo > m_iMaxLineNo)
  159. {
  160. m_iLineNo = m_iMaxLineNo;
  161. UpdateData(FALSE);
  162. }
  163. else if (m_iLineNo < 1)
  164. {
  165. m_iLineNo = 1;
  166. UpdateData(FALSE);
  167. }
  168. m_pEditCtrl->GoToRow(m_iLineNo, m_bSelectLine);
  169. if (!m_bHideOnFind && !m_bSelectLine)
  170. m_pEditCtrl->SetFocus();
  171. else if (m_bHideOnFind)
  172. OnCancel();
  173. else
  174. m_wndEditLineNo.SetSel(0,-1);
  175. }
  176. void CXTPSyntaxEditGoToLineDlg::OnCancel()
  177. {
  178. SavePos();
  179. CDialog::OnCancel();
  180. if (::IsWindow(m_hWnd))
  181. ::DestroyWindow(m_hWnd);
  182. }