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

对话框与窗口

开发平台:

Visual C++

  1. // XTPSyntaxEditView.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 SYNTAX EDIT 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/XTPVC50Helpers.h"
  27. #include "Common/XTPVC80Helpers.h"
  28. #include "Common/XTPResourceManager.h"
  29. // syntax editor includes
  30. #include "XTPSyntaxEditDefines.h"
  31. #include "XTPSyntaxEditStruct.h"
  32. #include "XTPSyntaxEditUndoManager.h"
  33. #include "XTPSyntaxEditLexPtrs.h"
  34. #include "XTPSyntaxEditLexClassSubObjT.h"
  35. #include "XTPSyntaxEditTextIterator.h"
  36. #include "XTPSyntaxEditSectionManager.h"
  37. #include "XTPSyntaxEditLexCfgFileReader.h"
  38. #include "XTPSyntaxEditLexParser.h"
  39. #include "XTPSyntaxEditBufferManager.h"
  40. #include "XTPSyntaxEditFindReplaceDlg.h"
  41. #include "XTPSyntaxEditCtrl.h"
  42. #include "XTPSyntaxEditDoc.h"
  43. #include "XTPSyntaxEditView.h"
  44. #include "XTPSyntaxEditPaintManager.h"
  45. #ifdef _DEBUG
  46. #define new DEBUG_NEW
  47. #undef THIS_FILE
  48. static char THIS_FILE[] = __FILE__;
  49. #endif
  50. DWORD_PTR           CXTPSyntaxEditView::ms_dwSignature = 0;
  51. BOOL                CXTPSyntaxEditView::ms_bDroppedHere = FALSE;
  52. POINT              CXTPSyntaxEditView::ms_ptDropPos;
  53. CXTPSyntaxEditView* CXTPSyntaxEditView::ms_pTargetView = NULL;
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CXTPSyntaxEditView
  56. CXTPSyntaxEditFindReplaceDlg* CXTPSyntaxEditView::m_pFindReplaceDlg = NULL;
  57. IMPLEMENT_DYNCREATE(CXTPSyntaxEditView, CView)
  58. CXTPSyntaxEditView::CXTPSyntaxEditView() :
  59. m_pParentWnd(NULL)
  60. , m_iTopRow(1)
  61. , m_szPage(CSize(850,1100))
  62. , m_nPrevTopRow(1)
  63. , m_bOleDragging(FALSE)
  64. , m_bFilesDragging(FALSE)
  65. , m_bDraggingStartedHere(FALSE)
  66. , m_bDraggingOver(FALSE)
  67. , m_bScrollBars(TRUE)
  68. , m_nParserThreadPriority_WhenActive(THREAD_PRIORITY_LOWEST)
  69. , m_nParserThreadPriority_WhenInactive(THREAD_PRIORITY_IDLE)
  70. , m_bInitialUpdateWasCalled(FALSE)
  71. {
  72. m_pEditCtrl = NULL;
  73. ZeroMemory(&m_lfPrevFont, sizeof(m_lfPrevFont));
  74. m_pPrintOptions = new CXTPSyntaxEditViewPrintOptions();
  75. // init defaults
  76. if (m_pPrintOptions)
  77. {
  78. m_pPrintOptions->GetPageHeader()->m_strFormatString = _T("&w &b&b &d &t");
  79. m_pPrintOptions->GetPageFooter()->m_strFormatString = _T("Page &p of &P");
  80. }
  81. GetEditCtrl().SetCreateScrollbarOnParent(TRUE);
  82. CMDTARGET_ADDREF(m_pFindReplaceDlg);
  83. m_bPrintDirect = FALSE;
  84. m_bResizeControlWithView = TRUE;
  85. m_bOnSizeRunning = FALSE;
  86. }
  87. CXTPSyntaxEditView::~CXTPSyntaxEditView()
  88. {
  89. CMDTARGET_RELEASE(m_pEditCtrl);
  90. CMDTARGET_RELEASE(m_pPrintOptions);
  91. if (m_pFindReplaceDlg && IsWindow(m_pFindReplaceDlg->GetSafeHwnd()))
  92. m_pFindReplaceDlg->SendMessage(WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0);
  93. CMDTARGET_RELEASE(m_pFindReplaceDlg);
  94. }
  95. BEGIN_MESSAGE_MAP(CXTPSyntaxEditView, CView)
  96. //{{AFX_MSG_MAP(CXTPSyntaxEditView)
  97. ON_WM_CREATE()
  98. ON_WM_SIZE()
  99. ON_WM_KEYDOWN()
  100. ON_WM_CHAR()
  101. ON_WM_VSCROLL()
  102. ON_WM_HSCROLL()
  103. ON_WM_SETFOCUS()
  104. ON_WM_LBUTTONDBLCLK()
  105. ON_WM_ERASEBKGND()
  106. ON_WM_PAINT()
  107. ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
  108. ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
  109. ON_COMMAND(ID_EDIT_REDO, OnEditRedo)
  110. ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo)
  111. ON_COMMAND(ID_EDIT_CUT, OnEditCut)
  112. ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
  113. ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  114. ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
  115. ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
  116. ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
  117. ON_COMMAND(ID_EDIT_CLEAR, OnEditDelete)
  118. ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateEditDelete)
  119. ON_COMMAND(ID_EDIT_SELECT_ALL, OnEditSelectAll)
  120. ON_UPDATE_COMMAND_UI(ID_EDIT_SELECT_ALL, OnUpdateEditSelectAll)
  121. ON_COMMAND(ID_EDIT_FIND, OnEditFind)
  122. ON_UPDATE_COMMAND_UI(ID_EDIT_FIND, OnUpdateEditFind)
  123. ON_COMMAND(ID_EDIT_REPLACE, OnEditReplace)
  124. ON_UPDATE_COMMAND_UI(ID_EDIT_REPLACE, OnUpdateEditReplace)
  125. ON_COMMAND(ID_EDIT_REPEAT, OnEditRepeat)
  126. ON_UPDATE_COMMAND_UI(ID_EDIT_REPEAT, OnUpdateEditRepeat)
  127. //}}AFX_MSG_MAP
  128. END_MESSAGE_MAP()
  129. /////////////////////////////////////////////////////////////////////////////
  130. // CXTPSyntaxEditView drawing
  131. void CXTPSyntaxEditView::OnDraw(CDC* pDC)
  132. {
  133. UNREFERENCED_PARAMETER(pDC);
  134. // Do nothing because actual drawing is inside the child edit control
  135. }
  136. void CXTPSyntaxEditView::OnPaint()
  137. {
  138. Default();
  139. }
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CXTPSyntaxEditView diagnostics
  142. #ifdef _DEBUG
  143. void CXTPSyntaxEditView::AssertValid() const
  144. {
  145. CView::AssertValid();
  146. }
  147. void CXTPSyntaxEditView::Dump(CDumpContext& dc) const
  148. {
  149. CView::Dump(dc);
  150. }
  151. #endif //_DEBUG
  152. /////////////////////////////////////////////////////////////////////////////
  153. // CXTPSyntaxEditView command handlers
  154. void CXTPSyntaxEditView::OnEditUndo()
  155. {
  156. GetEditCtrl().Undo();
  157. UpdateSiblings();
  158. Invalidate(FALSE);
  159. }
  160. void CXTPSyntaxEditView::OnUpdateEditUndo(CCmdUI* pCmdUI)
  161. {
  162. pCmdUI->Enable(GetEditCtrl().CanUndo());
  163. }
  164. void CXTPSyntaxEditView::OnEditRedo()
  165. {
  166. GetEditCtrl().Redo();
  167. UpdateSiblings();
  168. Invalidate(FALSE);
  169. }
  170. void CXTPSyntaxEditView::OnUpdateEditRedo(CCmdUI* pCmdUI)
  171. {
  172. pCmdUI->Enable(GetEditCtrl().CanRedo());
  173. }
  174. void CXTPSyntaxEditView::OnEditCut()
  175. {
  176. GetEditCtrl().Cut();
  177. }
  178. void CXTPSyntaxEditView::OnUpdateEditCut(CCmdUI* pCmdUI)
  179. {
  180. pCmdUI->Enable(GetEditCtrl().IsSelectionExist());
  181. }
  182. void CXTPSyntaxEditView::OnEditCopy()
  183. {
  184. GetEditCtrl().Copy();
  185. }
  186. void CXTPSyntaxEditView::OnUpdateEditCopy(CCmdUI* pCmdUI)
  187. {
  188. pCmdUI->Enable(GetEditCtrl().IsSelectionExist());
  189. }
  190. void CXTPSyntaxEditView::OnEditPaste()
  191. {
  192. GetEditCtrl().Paste();
  193. }
  194. void CXTPSyntaxEditView::OnUpdateEditPaste(CCmdUI* pCmdUI)
  195. {
  196. pCmdUI->Enable(IsClipboardFormatAvailable(CF_TEXT));
  197. }
  198. void CXTPSyntaxEditView::OnEditDelete()
  199. {
  200. GetEditCtrl().DeleteSelection();
  201. }
  202. void CXTPSyntaxEditView::OnUpdateEditDelete(CCmdUI* pCmdUI)
  203. {
  204. pCmdUI->Enable(GetEditCtrl().IsSelectionExist());
  205. }
  206. void CXTPSyntaxEditView::OnEditSelectAll()
  207. {
  208. GetEditCtrl().SelectAll();
  209. }
  210. void CXTPSyntaxEditView::OnUpdateEditSelectAll(CCmdUI* pCmdUI)
  211. {
  212. pCmdUI->Enable(TRUE);
  213. }
  214. CXTPSyntaxEditFindReplaceDlg* CXTPSyntaxEditView::GetFindReplaceDlg()
  215. {
  216. if (!m_pFindReplaceDlg)
  217. m_pFindReplaceDlg = new CXTPSyntaxEditFindReplaceDlg();
  218. return m_pFindReplaceDlg;
  219. }
  220. void CXTPSyntaxEditView::OnEditFind()
  221. {
  222. _EditFindReplace(FALSE) ;
  223. }
  224. void CXTPSyntaxEditView::OnEditReplace()
  225. {
  226. _EditFindReplace(TRUE);
  227. }
  228. void CXTPSyntaxEditView::_EditFindReplace(BOOL bReplaceDlg)
  229. {
  230. if (!GetFindReplaceDlg())
  231. return;
  232. CString csSelText;
  233. GetEditCtrl().GetSelectionText(csSelText);
  234. if (csSelText.IsEmpty())
  235. {
  236. CPoint pt(GetCaretPos());
  237. pt.y += 2;
  238. GetEditCtrl().SelectWord(pt);
  239. GetEditCtrl().GetSelectionText(csSelText);
  240. }
  241. csSelText = csSelText.SpanExcluding(_T("rn"));
  242. REPLACE_S(csSelText, _T("t"), _T("    "));
  243. if (!csSelText.IsEmpty())
  244. {
  245. GetFindReplaceDlg()->m_csFindText = csSelText;
  246. }
  247. GetFindReplaceDlg()->ShowDialog(&GetEditCtrl(), bReplaceDlg);
  248. }
  249. void CXTPSyntaxEditView::OnUpdateEditFind(CCmdUI* pCmdUI)
  250. {
  251. pCmdUI->Enable(TRUE);
  252. }
  253. void CXTPSyntaxEditView::OnUpdateEditReplace(CCmdUI* pCmdUI)
  254. {
  255. pCmdUI->Enable(TRUE);
  256. }
  257. void CXTPSyntaxEditView::OnEditRepeat()
  258. {
  259. if (!GetFindReplaceDlg())
  260. return;
  261. if (IsWindow(GetFindReplaceDlg()->m_hWnd))
  262. GetFindReplaceDlg()->SendMessage(WM_COMMAND, MAKEWPARAM(IDCANCEL, 0), 0);
  263. BOOL bShiftKey  = (::GetKeyState(VK_SHIFT) & KF_UP) != 0;
  264. if (GetEditCtrl().Find(GetFindReplaceDlg()->m_csFindText,
  265. GetFindReplaceDlg()->m_bMatchWholeWord,
  266. GetFindReplaceDlg()->m_bMatchCase, !bShiftKey))
  267. {
  268. SetDirty();
  269. GetParentFrame()->SetMessageText(AFX_IDS_IDLEMESSAGE);
  270. }
  271. else
  272. {
  273. //AfxMessageBox(XTPResourceManager()->LoadString(XTP_IDS_EDIT_MSG_FSEARCH));
  274. if (GetEditCtrl().GetRowCount() > 0)
  275. {
  276. int nStartRow = 0;
  277. int nStartCol = 0;
  278. if (bShiftKey)
  279. {
  280. nStartRow = GetEditCtrl().GetRowCount();
  281. nStartCol = GetEditCtrl().GetEditBuffer()->GetLineTextLengthC(GetEditCtrl().GetRowCount()-1);
  282. }
  283. if (GetEditCtrl().Find(GetFindReplaceDlg()->m_csFindText,
  284. GetFindReplaceDlg()->m_bMatchWholeWord, GetFindReplaceDlg()->m_bMatchCase,
  285. !bShiftKey, TRUE, nStartRow, nStartCol))
  286. {
  287. SetDirty();
  288. }
  289. GetParentFrame()->SetMessageText(XTPResourceManager()->LoadString(XTP_IDS_EDIT_MSG_FSEARCH));
  290. }
  291. }
  292. }
  293. void CXTPSyntaxEditView::OnUpdateEditRepeat(CCmdUI* pCmdUI)
  294. {
  295. pCmdUI->Enable(GetFindReplaceDlg() && !GetFindReplaceDlg()->m_csFindText.IsEmpty());
  296. }
  297. /////////////////////////////////////////////////////////////////////////////
  298. // CXTPSyntaxEditView message handlers
  299. int CXTPSyntaxEditView::OnCreate(LPCREATESTRUCT lpCS)
  300. {
  301. if (CView::OnCreate(lpCS) == -1)
  302. return -1;
  303. // initialize parent window pointer.
  304. m_pParentWnd = CWnd::FromHandlePermanent(lpCS->hwndParent);
  305. if (!::IsWindow(m_pParentWnd->GetSafeHwnd()))
  306. return -1;
  307. // get data manager and context pointers.
  308. CXTPSyntaxEditBufferManager* pDataManager = GetDataManager();
  309. CCreateContext* pContext = (CCreateContext*)lpCS->lpCreateParams;
  310. // create the edit control.
  311. if (!GetEditCtrl().Create(this, m_bScrollBars, m_bScrollBars, pDataManager, pContext))
  312. {
  313. TRACE0("Failed to create edit control.n");
  314. return -1;
  315. }
  316. GetEditCtrl().RecalcScrollBars();
  317. GetEditCtrl().SetTopRow(m_iTopRow);
  318. GetEditCtrl().EnableOleDrag(m_dropTarget.Register(this));
  319. // get the document.
  320. CXTPSyntaxEditDoc *pDoc = GetDocument();
  321. if (!pDoc)
  322. {
  323. GetEditCtrl().GetEditBuffer()->InsertText(_T(""), 1,1, FALSE);
  324. return 0;
  325. }
  326. // Inherit any special back and foreground color lines
  327. CXTPSyntaxEditView *pView = pDoc->GetFirstView();
  328. if (pView != this && ::IsWindow(pView->GetSafeHwnd()))
  329. GetEditCtrl() = pView->GetEditCtrl();
  330. if (!pDataManager)
  331. pDoc->SetDataManager(GetEditCtrl().GetEditBuffer());
  332. return 0;
  333. }
  334. void CXTPSyntaxEditView::OnSize(UINT nType, int cx, int cy)
  335. {
  336. CView::OnSize(nType, cx, cy);
  337. if (m_bOnSizeRunning)
  338. return;
  339. m_bOnSizeRunning = TRUE;
  340. if (m_bResizeControlWithView && ::IsWindow(GetEditCtrl().m_hWnd))
  341. {
  342. CXTPClientRect rc(this);
  343. GetEditCtrl().MoveWindow(&rc, FALSE);
  344. GetEditCtrl().RecalcScrollBars();
  345. // for case when RecalcScrollBars() call change a view size (by disabling/enabling scrollbars)
  346. CXTPClientRect rc2(this);
  347. if (rc2 != rc)
  348. {
  349. GetEditCtrl().MoveWindow(&rc2, FALSE);
  350. GetEditCtrl().RecalcScrollBars();
  351. }
  352. }
  353. m_bOnSizeRunning = FALSE;
  354. }
  355. void CXTPSyntaxEditView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  356. {
  357. if (GetEditCtrl().SendMessage(WM_KEYDOWN,
  358. nChar, nFlags) != 0)
  359. {
  360. CView::OnKeyDown(nChar, nRepCnt, nFlags);
  361. }
  362. }
  363. void CXTPSyntaxEditView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  364. {
  365. if (GetEditCtrl().SendMessage(WM_CHAR,
  366. (WPARAM)nChar, (LPARAM)nFlags) != 0)
  367. {
  368. CView::OnChar(nChar, nRepCnt, nFlags);
  369. }
  370. }
  371. void CXTPSyntaxEditView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  372. {
  373. if (GetEditCtrl().SendMessage(WM_VSCROLL,
  374. MAKEWPARAM(nSBCode, nPos), (LPARAM)pScrollBar->GetSafeHwnd()) != 0)
  375. {
  376. CView::OnVScroll(nSBCode, nPos, pScrollBar);
  377. }
  378. }
  379. void CXTPSyntaxEditView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  380. {
  381. if (GetEditCtrl().SendMessage(WM_HSCROLL,
  382. MAKEWPARAM(nSBCode, nPos), (LPARAM)pScrollBar->GetSafeHwnd()) != 0)
  383. {
  384. CView::OnHScroll(nSBCode, nPos, pScrollBar);
  385. }
  386. }
  387. void CXTPSyntaxEditView::OnInitialUpdate()
  388. {
  389. CView::OnInitialUpdate();
  390. OnUpdate(NULL, xtpEditHintInitView);
  391. m_bInitialUpdateWasCalled = TRUE;
  392. }
  393. BOOL CXTPSyntaxEditView::OnEraseBkgnd(CDC*)
  394. {
  395. return TRUE;
  396. }
  397. int CXTPSyntaxEditView::GetTopRow()
  398. {
  399. return GetEditCtrl().GetTopRow();
  400. }
  401. BOOL CXTPSyntaxEditView::SetTopRow(int iRow)
  402. {
  403. m_iTopRow = iRow;
  404. return TRUE;
  405. }
  406. BOOL CXTPSyntaxEditView::OnEditChanging(NMHDR* pNMHDR, LRESULT* pResult)
  407. {
  408. UNREFERENCED_PARAMETER(pNMHDR);
  409. *pResult = !CanChangeReadonlyFile();
  410. return TRUE;
  411. }
  412. BOOL CXTPSyntaxEditView::OnEditChanged(NMHDR* pNMHDR, LRESULT* pResult)
  413. {
  414. XTP_EDIT_NMHDR_EDITCHANGED* pNMHDR_EC = (XTP_EDIT_NMHDR_EDITCHANGED*)pNMHDR;
  415. UpdateSiblings(pNMHDR_EC);
  416. *pResult = 1;
  417. return TRUE;
  418. }
  419. BOOL CXTPSyntaxEditView::OnSetDocModified(NMHDR* pNMHDR, LRESULT* pResult)
  420. {
  421. XTP_EDIT_NMHDR_DOCMODIFIED* pNMHDR_DM = (XTP_EDIT_NMHDR_DOCMODIFIED*)pNMHDR;
  422. CDocument *pDoc = GetDocument();
  423. if (!pDoc)
  424. return TRUE;
  425. pDoc->SetModifiedFlag(pNMHDR_DM->bModified);
  426. const CString& strTitle = pDoc->GetTitle();
  427. int nPos = strTitle.ReverseFind(_T('*'));
  428. if (pNMHDR_DM->bModified)
  429. {
  430. if (nPos == -1)
  431. {
  432. CString strNewTitle = strTitle;
  433. strNewTitle += _T(" *");
  434. pDoc->SetTitle(strNewTitle);
  435. }
  436. }
  437. else
  438. {
  439. if (nPos > 0)
  440. {
  441. CString strNewTitle = strTitle.Left(nPos - 1);
  442. pDoc->SetTitle(strNewTitle);
  443. }
  444. }
  445. *pResult = 1;
  446. return TRUE;
  447. }
  448. BOOL CXTPSyntaxEditView::OnDrawBookmark(NMHDR* pNMHDR, LRESULT* pResult)
  449. {
  450. UNREFERENCED_PARAMETER(pNMHDR);
  451. *pResult = 0;
  452. return TRUE;
  453. }
  454. BOOL CXTPSyntaxEditView::OnRowColChanged(NMHDR* pNMHDR, LRESULT* pResult)
  455. {
  456. XTP_EDIT_NMHDR_ROWCOLCHANGED* pNMHDR_RCC = (XTP_EDIT_NMHDR_ROWCOLCHANGED*)pNMHDR;
  457. UNREFERENCED_PARAMETER(pNMHDR_RCC);
  458. *pResult = 0;
  459. return TRUE;
  460. }
  461. BOOL CXTPSyntaxEditView::OnUpdateScrollPos(NMHDR* pNMHDR, LRESULT* pResult)
  462. {
  463. XTP_EDIT_NMHDR_SETSCROLLPOS* pNMHDR_SSP = (XTP_EDIT_NMHDR_SETSCROLLPOS*)pNMHDR;
  464. CDocument *pDoc = GetDocument();
  465. ASSERT(pDoc);
  466. if (pDoc)
  467. {
  468. pDoc->UpdateAllViews(this, xtpEditHintUpdateScrollPos, (CObject*)pNMHDR_SSP);
  469. //TRACE(_T("n"));
  470. }
  471. *pResult = 1;
  472. return TRUE;
  473. }
  474. BOOL CXTPSyntaxEditView::OnEnableScrollBar(NMHDR* pNMHDR, LRESULT* pResult)
  475. {
  476. XTP_EDIT_NMHDR_ENABLESCROLLBAR* pNMHDR_ESCR = (XTP_EDIT_NMHDR_ENABLESCROLLBAR*)pNMHDR;
  477. CSplitterWnd *pSplitterWnd = GetEditCtrl().IsCreateScrollbarOnParent() ? GetParentSplitter(this, TRUE) : NULL;
  478. if (pSplitterWnd)
  479. {
  480. DWORD dwStyle = (DWORD)pSplitterWnd->GetScrollStyle();
  481. DWORD dwStyleNew = 0;
  482. if ((pNMHDR_ESCR->dwScrollBar & WS_VSCROLL) && GetVertScrollBar())
  483. dwStyleNew |= pNMHDR_ESCR->dwState & WS_VSCROLL;
  484. else
  485. dwStyleNew |= dwStyle & WS_VSCROLL;
  486. if ((pNMHDR_ESCR->dwScrollBar & WS_HSCROLL)  && GetHorzScrollBar())
  487. dwStyleNew |= pNMHDR_ESCR->dwState & WS_HSCROLL;
  488. else
  489. dwStyleNew |= dwStyle & WS_HSCROLL;
  490. if (dwStyleNew != dwStyle)
  491. {
  492. pSplitterWnd->SetScrollStyle(dwStyleNew);
  493. // Check have all splitter panes already created
  494. int nRowsCount = pSplitterWnd->GetRowCount();
  495. int nColsCount = pSplitterWnd->GetColumnCount();
  496. for (int nRow = 0; nRow < nRowsCount; nRow++)
  497. {
  498. for (int nCol = 0; nCol < nColsCount; nCol++)
  499. {
  500. if (!GetSplitterView(nRow, nCol))
  501. {
  502. return FALSE;
  503. }
  504. }
  505. }
  506. pSplitterWnd->RecalcLayout();
  507. }
  508. }
  509. *pResult = 1;
  510. return TRUE;
  511. }
  512. BOOL CXTPSyntaxEditView::OnInsertKey(NMHDR* pNMHDR, LRESULT* pResult)
  513. {
  514. UNREFERENCED_PARAMETER(pNMHDR);
  515. *pResult = 0;
  516. return TRUE;
  517. }
  518. BOOL CXTPSyntaxEditView::OnSelInit(NMHDR* pNMHDR, LRESULT* pResult)
  519. {
  520. UNREFERENCED_PARAMETER(pNMHDR);
  521. UpdateSiblings(NULL, FALSE);
  522. *pResult = 0;
  523. return TRUE;
  524. }
  525. BOOL CXTPSyntaxEditView::OnStartOleDrag(NMHDR* pNMHDR, LRESULT* pResult)
  526. {
  527. UNREFERENCED_PARAMETER(pNMHDR);
  528. StartOleDrag();
  529. *pResult = 0;
  530. return TRUE;
  531. }
  532. BOOL CXTPSyntaxEditView::OnMarginClicked(NMHDR* pNMHDR, LRESULT* pResult)
  533. {
  534. XTP_EDIT_NMHDR_MARGINCLICKED* pNMMarginClicked = (XTP_EDIT_NMHDR_MARGINCLICKED*)pNMHDR;
  535. UNREFERENCED_PARAMETER(pNMMarginClicked);
  536. *pResult = 0;
  537. return TRUE;
  538. }
  539. BOOL CXTPSyntaxEditView::OnParseEvent(NMHDR* pNMHDR, LRESULT* pResult)
  540. {
  541. XTP_EDIT_NMHDR_PARSEEVENT* pNMParseEvent = (XTP_EDIT_NMHDR_PARSEEVENT*)pNMHDR;
  542. UNREFERENCED_PARAMETER(pNMParseEvent);
  543. *pResult = 0;
  544. return TRUE;
  545. }
  546. BOOL CXTPSyntaxEditView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  547. {
  548. NMHDR* pNMHDR = (NMHDR*)lParam;
  549. if (pNMHDR && pNMHDR->hwndFrom == GetEditCtrl().m_hWnd)
  550. {
  551. switch (pNMHDR->code)
  552. {
  553. case XTP_EDIT_NM_EDITCHANGING:
  554. return OnEditChanging(pNMHDR, pResult);
  555. case XTP_EDIT_NM_EDITCHANGED:
  556. return OnEditChanged(pNMHDR, pResult);
  557. case XTP_EDIT_NM_SETDOCMODIFIED:
  558. return OnSetDocModified(pNMHDR, pResult);
  559. case XTP_EDIT_NM_DRAWBOOKMARK:
  560. return OnDrawBookmark(pNMHDR, pResult);
  561. case XTP_EDIT_NM_ROWCOLCHANGED:
  562. return OnRowColChanged(pNMHDR, pResult);
  563. case XTP_EDIT_NM_UPDATESCROLLPOS:
  564. return OnUpdateScrollPos(pNMHDR, pResult);
  565. case XTP_EDIT_NM_ENABLESCROLLBAR:
  566. return OnEnableScrollBar(pNMHDR, pResult);
  567. case XTP_EDIT_NM_INSERTKEY:
  568. return OnInsertKey(pNMHDR, pResult);
  569. case XTP_EDIT_NM_SELINIT:
  570. return OnSelInit(pNMHDR, pResult);
  571. case XTP_EDIT_NM_STARTOLEDRAG:
  572. return OnStartOleDrag(pNMHDR, pResult);
  573. case XTP_EDIT_NM_MARGINCLICKED:
  574. return OnMarginClicked(pNMHDR, pResult);
  575. case XTP_EDIT_NM_PARSEEVENT:
  576. return OnParseEvent(pNMHDR, pResult);
  577. }
  578. }
  579. return CView::OnNotify(wParam, lParam, pResult);
  580. }
  581. void CXTPSyntaxEditView::Refresh()
  582. {
  583. CWaitCursor wait;
  584. GetEditCtrl().RefreshColors();
  585. m_iTopRow = GetEditCtrl().GetTopRow();
  586. if (m_iTopRow != -1)
  587. GetEditCtrl().SetTopRow(m_iTopRow);
  588. GetEditCtrl().RecalcScrollBars();
  589. GetEditCtrl().NotifyCurRowCol(GetEditCtrl().GetCurRow(), GetEditCtrl().GetCurCol());
  590. }
  591. void CXTPSyntaxEditView::OnSetFocus(CWnd* pOldWnd)
  592. {
  593. CView::OnSetFocus(pOldWnd);
  594. GetEditCtrl().SetFocus();
  595. }
  596. void CXTPSyntaxEditView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
  597. {
  598. ASSERT(pInfo != NULL);  // overriding OnPaint -- never get this.
  599. if (!pInfo)
  600. return;
  601. int nVisibleRowsCount = GetEditCtrl().GetVisibleRowsCount();
  602. if (pInfo->m_nCurPage == 1 && nVisibleRowsCount == 0)
  603. {
  604. pInfo->m_bContinuePrinting = TRUE;
  605. }
  606. else if (pInfo->m_nCurPage > 1 && pInfo->m_nCurPage == (UINT)m_aPageStart.GetSize() &&
  607. m_aPageStart[pInfo->m_nCurPage - 1] >= (UINT)nVisibleRowsCount)
  608. {
  609. // can't paginate to that page, thus cannot print it.
  610. pInfo->m_bContinuePrinting = FALSE;
  611. }
  612. else if (pInfo->m_nCurPage > (UINT)m_aPageStart.GetSize() &&
  613. !PaginateTo(pDC, pInfo))
  614. {
  615. // can't paginate to that page, thus cannot print it.
  616. pInfo->m_bContinuePrinting = FALSE;
  617. }
  618. //-----------------------------------------------------------------------
  619. pDC->SetMapMode(MM_ANISOTROPIC);
  620. pDC->SetViewportExt(pDC->GetDeviceCaps(LOGPIXELSX),
  621. pDC->GetDeviceCaps(LOGPIXELSY));
  622. pDC->SetWindowExt(100, 100);
  623. // ptOrg is in logical coordinates
  624. pDC->OffsetWindowOrg(0, 0);
  625. }
  626. void CXTPSyntaxEditView::OnFilePageSetup()
  627. {
  628. /*
  629. DWORD dwFlags = PSD_MARGINS | PSD_INWININIINTLMEASURE;
  630. CXTPReportPageSetupDialog dlgPageSetup(GetPrintOptions(), dwFlags, this);
  631. XTPGetPrinterDeviceDefaults(dlgPageSetup.m_psd.hDevMode, dlgPageSetup.m_psd.hDevNames);
  632. int nDlgRes = (int)dlgPageSetup.DoModal();
  633. if (nDlgRes == IDOK)
  634. {
  635. AfxGetApp()->SelectPrinter(dlgPageSetup.m_psd.hDevNames, dlgPageSetup.m_psd.hDevMode, FALSE);
  636. }
  637. */
  638. }
  639. BOOL CXTPSyntaxEditView::OnPreparePrinting(CPrintInfo* pInfo)
  640. {
  641. pInfo->m_bDirect = m_bPrintDirect;
  642. m_nPrevTopRow = GetEditCtrl().GetTopRow();
  643. CWinApp* pWinApp = AfxGetApp();
  644. if (pWinApp)
  645. pWinApp->m_nNumPreviewPages = 1;
  646. pInfo->SetMinPage(1);
  647. return DoPreparePrinting(pInfo);
  648. }
  649. void CXTPSyntaxEditView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
  650. {
  651. if (GetEditCtrl().GetSyntaxColor())
  652. {
  653. CWaitCursor _WC;
  654. XTP_EDIT_LINECOL pos1_0 = {INT_MAX,0};
  655. CXTPSyntaxEditLexTextSchema* ptrTextSch = GetEditCtrl().GetEditBuffer()->GetLexParser()->GetTextSchema();
  656. if (ptrTextSch)
  657. {
  658. //GetEditCtrl().GetEditBuffer()->GetLexParser()->StopParseInThread();
  659. GetEditCtrl().GetEditBuffer()->GetLexParser()->CloseParseThread();
  660. CXTPSyntaxEditTextIterator txtIter(GetEditCtrl().GetEditBuffer());
  661. ptrTextSch->RunParseUpdate(TRUE, &txtIter, &pos1_0, NULL);
  662. }
  663. }
  664. //GetEditCtrl().SetRedraw(FALSE);
  665. GetEditCtrl().m_bDisableRedraw = TRUE;
  666. m_nPrevTopRow = GetEditCtrl().GetTopRow();
  667. ASSERT(m_aPageStart.GetSize() == 0);
  668. m_aPageStart.RemoveAll();
  669. m_aPageStart.Add(1);
  670. CString str1, str2;
  671. if (m_pPrintOptions && m_pPrintOptions->GetPageHeader())
  672. str1 = m_pPrintOptions->GetPageHeader()->m_strFormatString;
  673. if (m_pPrintOptions && m_pPrintOptions->GetPageFooter())
  674. str2 = m_pPrintOptions->GetPageFooter()->m_strFormatString;
  675. if (str1.Find(_T("&P")) >= 0 || str2.Find(_T("&P")) >= 0)
  676. {
  677. int nCurPage = pInfo->m_nCurPage;
  678. pInfo->m_nCurPage = 65535;
  679. if (PaginateTo(pDC, pInfo))
  680. {
  681. pInfo->SetMaxPage((int)m_aPageStart.GetSize() - 1);
  682. //          CWinApp* pWinApp = AfxGetApp();
  683. //          if (pWinApp)
  684. //              pWinApp->m_nNumPreviewPages = m_aPageStart.GetSize();
  685. }
  686. pInfo->m_nCurPage = nCurPage;
  687. }
  688. //  CView::OnBeginPrinting(pDC, pInfo);
  689. }
  690. void CXTPSyntaxEditView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
  691. {
  692. CView::OnEndPrinting(pDC, pInfo);
  693. m_aPageStart.RemoveAll();
  694. GetEditCtrl().SetTopRow(m_nPrevTopRow);
  695. //GetEditCtrl().SetRedraw(TRUE);
  696. GetEditCtrl().m_bDisableRedraw = FALSE;
  697. GetEditCtrl().RecalcScrollBars();
  698. }
  699. extern BOOL CALLBACK _XTPAbortProc(HDC, int);
  700. BOOL CXTPSyntaxEditView::PaginateTo(CDC* pDC, CPrintInfo* pInfo)
  701. // attempts pagination to pInfo->m_nCurPage, TRUE == success
  702. {
  703. ASSERT_VALID(this);
  704. ASSERT_VALID(pDC);
  705. BOOL bAborted = FALSE;
  706. CXTPPrintingDialog dlgPrintStatus(this);
  707. CString strTemp = GetPageTitle();
  708. dlgPrintStatus.SetWindowText(_T("Calculating pages..."));
  709. dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_DOCNAME, strTemp);
  710. dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PRINTERNAME, pInfo->m_pPD->GetDeviceName());
  711. dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PORTNAME, pInfo->m_pPD->GetPortName());
  712. dlgPrintStatus.ShowWindow(SW_SHOW);
  713. dlgPrintStatus.UpdateWindow();
  714. CRect rectSave = pInfo->m_rectDraw;
  715. UINT nPageSave = pInfo->m_nCurPage;
  716. //BOOL bBlackWhiteSaved = m_pPrintOptions->m_bBlackWhitePrinting;
  717. //m_pPrintOptions->m_bBlackWhitePrinting = FALSE;
  718. ASSERT(nPageSave > 1);
  719. ASSERT(nPageSave >= (UINT)m_aPageStart.GetSize());
  720. VERIFY(pDC->SaveDC() != 0);
  721. pDC->IntersectClipRect(0, 0, 0, 0);
  722. pInfo->m_nCurPage = (UINT)m_aPageStart.GetSize();
  723. while (pInfo->m_nCurPage < nPageSave)
  724. {
  725. ASSERT(pInfo->m_nCurPage == (UINT)m_aPageStart.GetSize());
  726. OnPrepareDC(pDC, pInfo);
  727. if (!pInfo->m_bContinuePrinting)
  728. break;
  729. strTemp.Format(_T("%d"), pInfo->m_nCurPage);
  730. dlgPrintStatus.SetDlgItemText(AFX_IDC_PRINT_PAGENUM, strTemp);
  731. pInfo->m_rectDraw.SetRect(0, 0, pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));
  732. pDC->DPtoLP(&pInfo->m_rectDraw);
  733. OnPrint(pDC, pInfo);
  734. //if (pInfo->m_nCurPage == (UINT)m_aPageStart.GetSize())
  735. //  break;
  736. ++pInfo->m_nCurPage;
  737. if(!_XTPAbortProc(0, 0))
  738. {
  739. bAborted = TRUE;
  740. break;
  741. }
  742. }
  743. dlgPrintStatus.DestroyWindow();
  744. BOOL bResult = !bAborted && (pInfo->m_nCurPage == nPageSave || nPageSave == 65535);
  745. pInfo->m_bContinuePrinting = bResult;
  746. pDC->RestoreDC(-1);
  747. //m_pPrintOptions->m_bBlackWhitePrinting = bBlackWhiteSaved;
  748. pInfo->m_nCurPage = nPageSave;
  749. pInfo->m_rectDraw = rectSave;
  750. ASSERT_VALID(this);
  751. return bResult;
  752. }
  753. CString CXTPSyntaxEditView::GetPageTitle()
  754. {
  755. CString strTitle;
  756. if (!GetDocument())
  757. return strTitle;
  758. strTitle = GetDocument()->GetPathName();
  759. //CString strFileName = strPathName.Right(strPathName.GetLength()-(strPathName.ReverseFind(_T('\')) + 1));
  760. if (strTitle.IsEmpty())
  761. {
  762. strTitle= GetDocument()->GetTitle();
  763. REMOVE_S(strTitle, _T('*'));
  764. }
  765. return strTitle;
  766. }
  767. void CXTPSyntaxEditView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
  768. {
  769. CRect rcMargins = m_pPrintOptions->GetMarginsLP(pDC);
  770. CRect rcPrint = pInfo->m_rectDraw;
  771. rcPrint.DeflateRect(rcMargins);
  772. //  if (!m_pPrintOptions->m_bBlackWhitePrinting)
  773. CRect rcPageHeader = rcPrint;
  774. CRect rcPageFooter = rcPrint;
  775. //CString strTitle = CXTPPrintPageHeaderFooter::GetParentFrameTitle(this);
  776. CString strTitle = GetPageTitle();
  777. m_pPrintOptions->GetPageHeader()->FormatTexts(pInfo, strTitle);
  778. m_pPrintOptions->GetPageFooter()->FormatTexts(pInfo, strTitle);
  779. pDC->SetBkColor(RGB(255, 255, 255));
  780. if (!m_pPrintOptions->GetPageHeader()->IsEmpty())
  781. {
  782. m_pPrintOptions->GetPageHeader()->Draw(pDC, rcPageHeader);
  783. rcPageHeader.top = rcPageHeader.bottom + 3;
  784. rcPageHeader.bottom = rcPageHeader.top + 2;
  785. pDC->FillSolidRect(rcPageHeader, RGB(0, 0, 0));
  786. rcPrint.top = rcPageHeader.bottom + 7;
  787. }
  788. if (!m_pPrintOptions->GetPageFooter()->IsEmpty())
  789. {
  790. m_pPrintOptions->GetPageFooter()->Draw(pDC, rcPageFooter, TRUE);
  791. rcPrint.bottom = rcPageFooter.top - 7;
  792. }
  793. //----------------------------------------------------------
  794. UINT nPage = pInfo->m_nCurPage;
  795. ASSERT(nPage <= (UINT)m_aPageStart.GetSize());
  796. UINT nIndex = m_aPageStart[nPage-1];
  797. GetEditCtrl().SetTopRow(nIndex);
  798. int nOptions = 0;
  799. //nOptions = nOptions | DT_WORDBREAK;
  800. //nOptions = nOptions | DT_SINGLELINE;
  801. // print as much as possible in the current page.
  802. nIndex += GetEditCtrl().PrintPage(pDC, rcPrint, nOptions);
  803. // update pagination information for page just printed
  804. if (nPage == (UINT)m_aPageStart.GetSize())
  805. {
  806. m_aPageStart.Add(nIndex);
  807. }
  808. else
  809. {
  810. ASSERT(nPage < (UINT)m_aPageStart.GetSize());
  811. m_aPageStart[nPage] = nIndex;
  812. }
  813. if (!m_pPrintOptions->GetPageFooter()->IsEmpty())
  814. {
  815. m_pPrintOptions->GetPageFooter()->Draw(pDC, rcPageFooter);
  816. rcPageFooter.top = rcPageFooter.top - 3;
  817. rcPageFooter.bottom = rcPageFooter.top + 1;
  818. pDC->FillSolidRect(rcPageFooter, RGB(0, 0, 0));
  819. }
  820. }
  821. CXTPSyntaxEditCtrl& CXTPSyntaxEditView::GetEditCtrl()
  822. {
  823. return m_pEditCtrl ? *m_pEditCtrl : m_wndEditCtrl;
  824. }
  825. void CXTPSyntaxEditView::SetEditCtrl(CXTPSyntaxEditCtrl* pControl)
  826. {
  827. if (::IsWindow(m_wndEditCtrl.GetSafeHwnd()))
  828. m_wndEditCtrl.DestroyWindow();
  829. m_pEditCtrl = pControl;
  830. }
  831. void CXTPSyntaxEditView::UpdateScrollPos(CView* pSender, DWORD dwUpdate/* = XTP_EDIT_UPDATE_ALL*/)
  832. {
  833. CSplitterWnd *pSplitterWnd = GetParentSplitter(this, FALSE);
  834. CXTPSyntaxEditView* pActiveView = (CXTPSyntaxEditView*)(pSender ? pSender : GetParentFrame()->GetActiveView());
  835. //TRACE(_T("SyntaxEditView::UpdateScrollPos.this=%x. "), this);
  836. if (pSplitterWnd && pActiveView && GetEditCtrl().IsCreateScrollbarOnParent())
  837. {
  838. int nSplRowsCount = pSplitterWnd->GetRowCount();
  839. int nSplColsCount = pSplitterWnd->GetColumnCount();
  840. //  See CSplitterWnd::IdFromRowCol() implementation for details
  841. int nSenderRow = min(nSplRowsCount-1, (pActiveView->GetDlgCtrlID() - AFX_IDW_PANE_FIRST) / 16);
  842. int nSenderCol = min(nSplColsCount-1, (pActiveView->GetDlgCtrlID() - AFX_IDW_PANE_FIRST) % 16);
  843. int nRow = min(nSplRowsCount-1, (GetDlgCtrlID() - AFX_IDW_PANE_FIRST) / 16);
  844. int nCol = min(nSplColsCount-1, (GetDlgCtrlID() - AFX_IDW_PANE_FIRST) % 16);
  845. //TRACE(_T(" splitter.senderViev=%x-(Row, Col)(%d, %d).thisView[%d, %d] "), pActiveView, nSenderRow, nSenderCol, nRow, nCol);
  846. if (nSenderRow != nRow || nSenderCol != nCol)
  847. {
  848. if ((dwUpdate & XTP_EDIT_UPDATE_HORZ) && (nRow == nSenderRow) && (nCol != nSenderCol))
  849. {
  850. UpdateSiblingScrollPos(pActiveView, XTP_EDIT_UPDATE_HORZ);
  851. //TRACE(_T(" XTP_EDIT_UPDATE_HORZ"));
  852. }
  853. if ((dwUpdate & XTP_EDIT_UPDATE_VERT) && (nRow != nSenderRow) && (nCol == nSenderCol))
  854. {
  855. UpdateSiblingScrollPos(pActiveView, XTP_EDIT_UPDATE_VERT);
  856. //TRACE(_T(" XTP_EDIT_UPDATE_VERT"));
  857. }
  858. if ((dwUpdate & XTP_EDIT_UPDATE_DIAG) && (nRow != nSenderRow) && (nCol != nSenderCol))
  859. {
  860. UpdateSiblingScrollPos(pActiveView, XTP_EDIT_UPDATE_DIAG);
  861. //TRACE(_T(" XTP_EDIT_UPDATE_DIAG"));
  862. }
  863. }
  864. }
  865. else
  866. {
  867. GetEditCtrl().RecalcScrollBars();
  868. GetEditCtrl().Invalidate(FALSE);
  869. }
  870. //TRACE(_T(" n"));
  871. }
  872. void CXTPSyntaxEditView::UpdateSiblingScrollPos(CXTPSyntaxEditView *pSender, DWORD dwUpdate)
  873. {
  874. ASSERT_VALID(pSender);
  875. ASSERT_KINDOF(CXTPSyntaxEditView, pSender);
  876. if (pSender == this)
  877. return;
  878. CFrameWnd *pFrameWnd1 = GetParentFrame();
  879. CFrameWnd *pFrameWnd2 = pSender->GetParentFrame();
  880. GetEditCtrl().RecalcScrollBars();
  881. switch (dwUpdate & XTP_EDIT_UPDATE_ALL)
  882. {
  883. case XTP_EDIT_UPDATE_HORZ:
  884. {
  885. GetEditCtrl().Invalidate(FALSE);
  886. if (pFrameWnd1 == pFrameWnd2)
  887. {
  888. int nTopRow = pSender->GetEditCtrl().GetTopRow();
  889. if (nTopRow != GetEditCtrl().GetTopRow())
  890. {
  891. GetEditCtrl().SetTopRow(nTopRow);
  892. GetEditCtrl().UpdateWindow();
  893. GetEditCtrl().RecalcScrollBars();
  894. }
  895. }
  896. }
  897. break;
  898. case XTP_EDIT_UPDATE_VERT:
  899. {
  900. if (pFrameWnd1 == pFrameWnd2)
  901. {
  902. int nXOffset = pSender->GetEditCtrl().GetDrawTextProcessor().GetScrollXOffset();
  903. GetEditCtrl().GetDrawTextProcessor().SetScrollXOffset(nXOffset);
  904. }
  905. GetEditCtrl().Invalidate(FALSE);
  906. }
  907. break;
  908. case XTP_EDIT_UPDATE_DIAG:
  909. {
  910. GetEditCtrl().Invalidate(FALSE);
  911. }
  912. break;
  913. }
  914. }
  915. CXTPSyntaxEditView *CXTPSyntaxEditView::GetSplitterView(int nRow, int nCol)
  916. {
  917. CSplitterWnd *pSplitterWnd = GetParentSplitter(this, FALSE);
  918. if (pSplitterWnd != NULL)
  919. {
  920. CWnd* pView = pSplitterWnd->GetDlgItem(pSplitterWnd->IdFromRowCol(nRow, nCol));
  921. if (!pView)
  922. return NULL;
  923. return DYNAMIC_DOWNCAST(CXTPSyntaxEditView, pView);
  924. }
  925. return NULL;
  926. }
  927. BOOL CXTPSyntaxEditView::PreCreateWindow(CREATESTRUCT& cs)
  928. {
  929. // As CView provides its own window class and own drawing code
  930. // do not call CView::PreCreateWindow
  931. if (!CWnd::PreCreateWindow(cs))
  932. return FALSE;
  933. return TRUE;
  934. }
  935. void CXTPSyntaxEditView::UpdateSiblings(XTP_EDIT_NMHDR_EDITCHANGED* pNMHDR_EC, BOOL bTextChanged)
  936. {
  937. if (!GetDocument())
  938. return;
  939. POSITION pos = GetDocument()->GetFirstViewPosition();
  940. while (pos)
  941. {
  942. CXTPSyntaxEditView* pView = DYNAMIC_DOWNCAST(CXTPSyntaxEditView, GetDocument()->GetNextView(pos));
  943. if (!pView || pView == this)
  944. continue;
  945. CXTPSyntaxEditCtrl& wndEditCtrl = pView->GetEditCtrl();
  946. if (pNMHDR_EC || bTextChanged)
  947. {
  948. wndEditCtrl.CalculateEditbarLength();
  949. }
  950. if (pNMHDR_EC)
  951. {
  952. wndEditCtrl.InvalidateRows(pNMHDR_EC->nRowFrom);
  953. wndEditCtrl.Invalidate(FALSE);
  954. wndEditCtrl.UpdateWindow();
  955. }
  956. else
  957. {
  958. wndEditCtrl.Unselect();
  959. }
  960. }
  961. }
  962. void CXTPSyntaxEditView::SetDirty()
  963. {
  964. GetEditCtrl().Invalidate(FALSE);
  965. }
  966. AFX_STATIC BOOL AFX_CDECL EnsureViewIsActive(CView* pView)
  967. {
  968. // Get a pointer to the view's parent frame.
  969. CFrameWnd* pParentFrame = DYNAMIC_DOWNCAST(
  970. CMDIChildWnd, pView->GetParentFrame());
  971. if (pParentFrame)
  972. {
  973. // If the top level frame is MDI activate.
  974. CMDIFrameWnd* pMDIFrameWnd = DYNAMIC_DOWNCAST(
  975. CMDIFrameWnd, pView->GetTopLevelFrame());
  976. if (pMDIFrameWnd)
  977. {
  978. if (pMDIFrameWnd->MDIGetActive() != pParentFrame)
  979. pMDIFrameWnd->MDIActivate(pParentFrame);
  980. }
  981. // If nested in a splitter set active pane.
  982. CSplitterWnd* pSplitterWnd = DYNAMIC_DOWNCAST(
  983. CSplitterWnd, pView->GetParent());
  984. if (pSplitterWnd)
  985. {
  986. if (pSplitterWnd->GetActivePane() != pView)
  987. pSplitterWnd->SetActivePane(0, 0, pView);
  988. }
  989. else
  990. {
  991. if (pParentFrame->GetActiveView() != pView)
  992. pParentFrame->SetActiveView(pView);
  993. }
  994. return TRUE;
  995. }
  996. return FALSE;
  997. }
  998. DROPEFFECT CXTPSyntaxEditView::OnDragEnter(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
  999. {
  1000. #ifdef _UNICODE
  1001. m_bOleDragging = pDataObject->IsDataAvailable(CF_UNICODETEXT);
  1002. #else
  1003. m_bOleDragging = pDataObject->IsDataAvailable(CF_TEXT);
  1004. #endif
  1005. m_bFilesDragging = pDataObject->IsDataAvailable(CF_HDROP);
  1006. ms_bDroppedHere = FALSE;
  1007. EnsureViewIsActive(this);
  1008. return CView::OnDragEnter(pDataObject, dwKeyState, point);
  1009. }
  1010. void CXTPSyntaxEditView::OnDragLeave()
  1011. {
  1012. m_bOleDragging = FALSE;
  1013. m_bFilesDragging = FALSE;
  1014. ms_bDroppedHere = FALSE;
  1015. CView::OnDragLeave();
  1016. }
  1017. DROPEFFECT CXTPSyntaxEditView::OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
  1018. {
  1019. UNREFERENCED_PARAMETER(pDataObject);
  1020. if (m_bFilesDragging)
  1021. {
  1022. return DROPEFFECT_COPY;
  1023. }
  1024. if (!m_bOleDragging)
  1025. return DROPEFFECT_NONE;
  1026. DROPEFFECT effect;
  1027. if (dwKeyState & MK_CONTROL)
  1028. effect = DROPEFFECT_COPY;
  1029. else
  1030. effect = DROPEFFECT_MOVE;
  1031. int nRow, nDispCol;
  1032. GetEditCtrl().RowColFromPoint(point, &nRow, NULL, NULL, &nDispCol);
  1033. int iPrevRow = GetEditCtrl().GetCurRow();
  1034. int iPrevCol = GetEditCtrl().GetCurCol();
  1035. int nTopRow = GetEditCtrl().GetTopRow();
  1036. int nRowPerPage = GetEditCtrl().GetRowPerPage();
  1037. int nEndRow = GetEditCtrl().GetRowCount();
  1038. if (nRow == nTopRow && nRow > 1)
  1039. nRow--;
  1040. if (nRow == (nTopRow + nRowPerPage - 1) && nRow < nEndRow)
  1041. nRow++;
  1042. if (nRow != iPrevRow || nDispCol != iPrevCol)
  1043. {
  1044. GetEditCtrl().SetCurPos(nRow, nDispCol, TRUE, TRUE);
  1045. }
  1046. //TRACE(_T("nOnDragOver top row = %d"), GetEditCtrl().GetTopRow());
  1047. if (GetFocus() != &GetEditCtrl())
  1048. GetEditCtrl().SetFocus();
  1049. m_bDraggingOver = TRUE;
  1050. ms_bDroppedHere = FALSE;
  1051. return effect;
  1052. }
  1053. BOOL CXTPSyntaxEditView::OnDrop(COleDataObject* pDataObject, DROPEFFECT dropEffect,
  1054.    CPoint point)
  1055. {
  1056. UNREFERENCED_PARAMETER(dropEffect); UNREFERENCED_PARAMETER(point);
  1057. if (m_bFilesDragging)
  1058. {
  1059. HGLOBAL hDropInfo = pDataObject->GetGlobalData(CF_HDROP);
  1060. OnDropFiles((HDROP)hDropInfo);
  1061. m_bFilesDragging = FALSE;
  1062. return TRUE;
  1063. }
  1064. m_bOleDragging = FALSE;
  1065. //TRACE(_T("nOnDragDrop top row = %d"), GetEditCtrl().GetTopRow());
  1066. if (ms_dwSignature != (DWORD_PTR)(GetEditCtrl().GetEditBuffer()))
  1067. {
  1068. #ifdef _UNICODE
  1069. HGLOBAL hMem = pDataObject->GetGlobalData(CF_UNICODETEXT);
  1070. #else
  1071. HGLOBAL hMem = pDataObject->GetGlobalData(CF_TEXT);
  1072. #endif
  1073. LPTSTR szText = (LPTSTR)GlobalLock(hMem);
  1074. int iRow = GetEditCtrl().GetCurRow();
  1075. int iAbsCol = GetEditCtrl().GetCurAbsCol();
  1076. GetEditCtrl().Unselect();
  1077. GetEditCtrl().InsertString(szText, iRow, iAbsCol, FALSE);
  1078. GetEditCtrl().GetEditBuffer()->GetUndoRedoManager()->SetLastCommandText(XTP_IDS_EDIT_PASTE);
  1079. if (GetDocument())
  1080. GetDocument()->SetModifiedFlag(TRUE);
  1081. GlobalUnlock(hMem);
  1082. GlobalFree(hMem);
  1083. GetEditCtrl().CancelRightButtonDrag();
  1084. ms_bDroppedHere = FALSE;
  1085. }
  1086. else
  1087. {
  1088. int nRow = GetEditCtrl().GetCurRow();
  1089. int nDispCol = GetEditCtrl().GetCurCol();
  1090. if (GetEditCtrl().GetSelection().IsInSel_disp(nRow, nDispCol))
  1091. {
  1092. GetEditCtrl().Unselect();
  1093. return FALSE;
  1094. }
  1095. ms_ptDropPos.x = nDispCol;
  1096. ms_ptDropPos.y = nRow;
  1097. ms_bDroppedHere = TRUE;
  1098. ms_pTargetView = this;
  1099. }
  1100. m_bDraggingStartedHere = FALSE;
  1101. return TRUE;
  1102. }
  1103. void CXTPSyntaxEditView::StartOleDrag()
  1104. {
  1105. HGLOBAL hMemText = GetEditCtrl().GetSelectionBuffer(CF_TEXT);
  1106. if (!hMemText)
  1107. return;
  1108. HGLOBAL hMemUnicodeText = GetEditCtrl().GetSelectionBuffer(CF_UNICODETEXT);
  1109. if (!hMemUnicodeText)
  1110. return;
  1111. COleDataSource dataSource;
  1112. dataSource.CacheGlobalData(CF_TEXT, hMemText);
  1113. dataSource.CacheGlobalData(CF_UNICODETEXT, hMemUnicodeText);
  1114. ms_bDroppedHere = FALSE;
  1115. m_bDraggingStartedHere = TRUE;
  1116. ms_dwSignature = (DWORD_PTR)GetEditCtrl().GetEditBuffer();
  1117. ms_pTargetView = NULL;
  1118. DROPEFFECT effect = dataSource.DoDragDrop(DROPEFFECT_COPY|DROPEFFECT_MOVE);
  1119. //TRACE(_T("nStartOleDrag top row = %d"), GetEditCtrl().GetTopRow());
  1120. if (effect != DROPEFFECT_NONE)
  1121. {
  1122. if (ms_bDroppedHere)
  1123. {
  1124. GetEditCtrl().SetDropPos(ms_ptDropPos.y, ms_ptDropPos.x);
  1125. GetEditCtrl().HandleDrop(effect == DROPEFFECT_COPY);
  1126. if (ms_pTargetView && ms_pTargetView != this)
  1127. GetEditCtrl().Unselect();
  1128. CXTPSyntaxEditCtrl& wndEditCtrl = ms_pTargetView->GetEditCtrl();
  1129. wndEditCtrl.NotifyCurRowCol(wndEditCtrl.GetCurRow(), wndEditCtrl.GetCurCol());
  1130. }
  1131. else if (effect == DROPEFFECT_MOVE)
  1132. {
  1133. GetEditCtrl().DeleteSelection();
  1134. GetEditCtrl().Invalidate(FALSE);
  1135. }
  1136. GetEditCtrl().CancelRightButtonDrag();
  1137. if (!ms_bDroppedHere)
  1138. {
  1139. CPoint ptStartSel, ptEndSel;
  1140. if (GetEditCtrl().IsSelectionExist())
  1141. {
  1142. XTP_EDIT_LINECOL lcSel = GetEditCtrl().GetSelection().GetNormalStart_disp();
  1143. GetEditCtrl().SetCurPos(lcSel.nLine, lcSel.nCol, TRUE);
  1144. }
  1145. }
  1146. }
  1147. if (effect == DROPEFFECT_NONE)
  1148. {
  1149. if (!m_bDraggingOver)
  1150. {
  1151. if (!GetEditCtrl().IsRightButtonDrag())
  1152. GetEditCtrl().Unselect();
  1153. int nRow, nCol;
  1154. CPoint point;
  1155. GetCursorPos(&point);
  1156. GetEditCtrl().ScreenToClient(&point);
  1157. GetEditCtrl().RowColFromPoint(point, &nRow, &nCol);
  1158. if (!GetEditCtrl().IsRightButtonDrag())
  1159. {
  1160. GetEditCtrl().SetCurPos(nRow, nCol, TRUE, TRUE);
  1161. }
  1162. else
  1163. {
  1164. GetEditCtrl().CancelRightButtonDrag();
  1165. GetEditCtrl().ShowDefaultContextMenu();
  1166. }
  1167. }
  1168. else
  1169. {
  1170. if (GetEditCtrl().IsSelectionExist())
  1171. {
  1172. XTP_EDIT_LINECOL lcSel = GetEditCtrl().GetSelection().GetNormalStart_disp();
  1173. GetEditCtrl().SetCurPos(lcSel.nLine, lcSel.nCol, TRUE);
  1174. }
  1175. }
  1176. if (GetEditCtrl().IsRightButtonDrag())
  1177. GetEditCtrl().CancelRightButtonDrag();
  1178. }
  1179. m_bDraggingStartedHere = FALSE;
  1180. m_bDraggingOver = FALSE;
  1181. ms_bDroppedHere = FALSE;
  1182. ms_dwSignature = 0;
  1183. }
  1184. void CXTPSyntaxEditView::UpdateAllViews()
  1185. {
  1186. if (GetDocument())
  1187. {
  1188. XTP_EDIT_NMHDR_SETSCROLLPOS nmUpdateScroll;
  1189. ZeroMemory(&nmUpdateScroll, sizeof(nmUpdateScroll));
  1190. nmUpdateScroll.dwUpdate = XTP_EDIT_UPDATE_ALL;
  1191. GetDocument()->UpdateAllViews(NULL, xtpEditHintUpdateScrollPos, (CObject*)&nmUpdateScroll);
  1192. }
  1193. Invalidate(FALSE);
  1194. UpdateWindow();
  1195. }
  1196. void CXTPSyntaxEditView::SetSyntaxColor(BOOL bEnable)
  1197. {
  1198. CDocument* pDoc = GetDocument();
  1199. if (pDoc != NULL)
  1200. {
  1201. pDoc->UpdateAllViews(NULL, xtpEditHintSetSyntaxColor, (CObject*)(BOOL*)&bEnable);
  1202. }
  1203. }
  1204. void CXTPSyntaxEditView::SetAutoIndent(BOOL bEnable)
  1205. {
  1206. CDocument* pDoc = GetDocument();
  1207. if (pDoc != NULL)
  1208. {
  1209. pDoc->UpdateAllViews(NULL, xtpEditHintSetAutoIndent, (CObject*)(BOOL*)&bEnable);
  1210. }
  1211. }
  1212. void CXTPSyntaxEditView::SetSelMargin(BOOL bEnable)
  1213. {
  1214. CDocument* pDoc = GetDocument();
  1215. if (pDoc != NULL)
  1216. {
  1217. pDoc->UpdateAllViews(NULL, xtpEditHintSetSelMargin, (CObject*)(BOOL*)&bEnable);
  1218. }
  1219. }
  1220. BOOL CXTPSyntaxEditView::SetScrollBars(BOOL bHorz, BOOL bVert, BOOL bUpdateReg/*=FALSE*/, BOOL bRecalcLayout/*=TRUE*/)
  1221. {
  1222. if (m_bScrollBars)
  1223. {
  1224. if (!GetEditCtrl().SetScrollBars(bHorz, bVert, bUpdateReg))
  1225. return FALSE;
  1226. }
  1227. CSplitterWnd* pSplitterWnd = GetEditCtrl().IsCreateScrollbarOnParent() ? GetParentSplitter(this, TRUE) : NULL;
  1228. if (pSplitterWnd)
  1229. {
  1230. DWORD dwStyle = 0;
  1231. if (bVert)
  1232. dwStyle |= WS_VSCROLL;
  1233. if (bHorz)
  1234. dwStyle |= WS_HSCROLL;
  1235. pSplitterWnd->SetScrollStyle(dwStyle);
  1236. if (bRecalcLayout)
  1237. {
  1238. // Check have all splitter panes already created
  1239. int nRowsCount = pSplitterWnd->GetRowCount();
  1240. int nColsCount = pSplitterWnd->GetColumnCount();
  1241. for (int nRow = 0; nRow < nRowsCount; nRow++)
  1242. {
  1243. for (int nCol = 0; nCol < nColsCount; nCol++)
  1244. {
  1245. if (!GetSplitterView(nRow, nCol))
  1246. {
  1247. return FALSE;
  1248. }
  1249. }
  1250. }
  1251. pSplitterWnd->RecalcLayout();
  1252. }
  1253. return TRUE;
  1254. }
  1255. return TRUE;
  1256. }
  1257. BOOL CXTPSyntaxEditView::GetVertScrollBar()
  1258. {
  1259. return GetEditCtrl().GetVertScrollBar();
  1260. }
  1261. BOOL CXTPSyntaxEditView::GetHorzScrollBar()
  1262. {
  1263. return GetEditCtrl().GetHorzScrollBar();
  1264. }
  1265. BOOL CXTPSyntaxEditView::CanChangeReadonlyFile()
  1266. {
  1267. return TRUE;
  1268. }
  1269. void CXTPSyntaxEditView::SetLineNumbers(BOOL bEnable)
  1270. {
  1271. CDocument* pDoc = GetDocument();
  1272. if (pDoc != NULL)
  1273. {
  1274. pDoc->UpdateAllViews(NULL, xtpEditHintSetLineNum, (CObject*)(BOOL*)&bEnable);
  1275. }
  1276. }
  1277. void CXTPSyntaxEditView::SetFontIndirect(LOGFONT *pLogFont, BOOL bUpdateReg/*=FALSE*/)
  1278. {
  1279. GetEditCtrl().SetFontIndirect(pLogFont, bUpdateReg);
  1280. CDocument* pDoc = GetDocument();
  1281. if (pDoc != NULL)
  1282. {
  1283. pDoc->UpdateAllViews(this, xtpEditHintSetFont, (CObject*)pLogFont);
  1284. }
  1285. }
  1286. void CXTPSyntaxEditView::OnDropFiles(HDROP hDropInfo)
  1287. {
  1288. if (AfxGetApp() && AfxGetApp()->m_pMainWnd)
  1289. {
  1290. AfxGetApp()->m_pMainWnd->PostMessage(WM_DROPFILES,(WPARAM)hDropInfo);
  1291. }
  1292. else
  1293. {
  1294. ::DragFinish(hDropInfo);
  1295. }
  1296. }
  1297. void CXTPSyntaxEditView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
  1298. {
  1299. if (pSender == this)
  1300. {
  1301. return;
  1302. }
  1303. switch (lHint)
  1304. {
  1305. case xtpEditHintUpdateScrollPos:
  1306. {
  1307. XTP_EDIT_NMHDR_SETSCROLLPOS* pNMHDR_SSP = (XTP_EDIT_NMHDR_SETSCROLLPOS*)pHint;
  1308. UpdateScrollPos(pSender, pNMHDR_SSP->dwUpdate);
  1309. }
  1310. break;
  1311. case xtpEditHintSetSyntaxColor:
  1312. {
  1313. BOOL bEnable = *(BOOL*)pHint;
  1314. GetEditCtrl().SetSyntaxColor(bEnable);
  1315. }
  1316. break;
  1317. case xtpEditHintSetAutoIndent:
  1318. {
  1319. BOOL bEnable = *(BOOL*)pHint;
  1320. GetEditCtrl().SetAutoIndent(bEnable);
  1321. }
  1322. break;
  1323. case xtpEditHintSetSelMargin:
  1324. {
  1325. BOOL bEnable = *(BOOL*)pHint;
  1326. GetEditCtrl().SetSelMargin(bEnable);
  1327. }
  1328. break;
  1329. case xtpEditHintSetLineNum:
  1330. {
  1331. BOOL bEnable = *(BOOL*)pHint;
  1332. GetEditCtrl().SetLineNumbers(bEnable);
  1333. }
  1334. break;
  1335. case xtpEditHintSetFont:
  1336. {
  1337. LOGFONT* pLogFont = (LOGFONT*)pHint;
  1338. GetEditCtrl().SetFontIndirect(pLogFont);
  1339. }
  1340. break;
  1341. case xtpEditHintInitView:
  1342. {
  1343. GetEditCtrl().GetRegValues();
  1344. // Update font.
  1345. CXTPSyntaxEditView* pSrcView = DYNAMIC_DOWNCAST(CXTPSyntaxEditView, pSender);
  1346. if (pSrcView)
  1347. {
  1348. LOGFONT lf;
  1349. pSrcView->GetEditCtrl().GetPaintManager()->GetFont()->GetLogFont(&lf);
  1350. GetEditCtrl().SetFontIndirect(&lf);
  1351. }
  1352. GetEditCtrl().RestoreCursor();
  1353. // Update scrollbars.
  1354. SetScrollBars(GetEditCtrl().GetHorzScrollBar(),
  1355.   GetEditCtrl().GetVertScrollBar(), FALSE, TRUE);
  1356. Refresh();
  1357. }
  1358. break;
  1359. case xtpEditHintRefreshView:
  1360. {
  1361. Refresh();
  1362. }
  1363. break;
  1364. }
  1365. }
  1366. void CXTPSyntaxEditView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
  1367. {
  1368. int nPriority = bActivate ? m_nParserThreadPriority_WhenActive :
  1369. m_nParserThreadPriority_WhenInactive;
  1370. CXTPSyntaxEditLexParser* pParser = GetLexParser();
  1371. if (pParser)
  1372. {
  1373. pParser->SetParseThreadPriority(nPriority);
  1374. }
  1375. GetEditCtrl().SetActive(bActivate);
  1376. CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
  1377. }
  1378. BOOL CXTPSyntaxEditView::IsInitialUpdateWasCalled()
  1379. {
  1380. return m_bInitialUpdateWasCalled;
  1381. }
  1382. CXTPSyntaxEditDoc* CXTPSyntaxEditView::GetDocument()
  1383. {
  1384. return DYNAMIC_DOWNCAST(CXTPSyntaxEditDoc, m_pDocument);
  1385. }
  1386. CXTPSyntaxEditBufferManager* CXTPSyntaxEditView::GetDataManager()
  1387. {
  1388. CXTPSyntaxEditDoc* pDoc = GetDocument();
  1389. if (pDoc)
  1390. {
  1391. return pDoc->GetDataManager();
  1392. }
  1393. return NULL;
  1394. }
  1395. XTPSyntaxEditLexAnalyser::CXTPSyntaxEditLexParser* CXTPSyntaxEditView::GetLexParser()
  1396. {
  1397. CXTPSyntaxEditBufferManager* pDataManager = GetDataManager();
  1398. if (!pDataManager)
  1399. pDataManager = GetEditCtrl().GetEditBuffer();
  1400. if (pDataManager)
  1401. return pDataManager->GetLexParser();
  1402. return NULL;
  1403. }
  1404. /////////////////////////////////////////////////////////////////////////////
  1405. //class CXTPSyntaxEditViewPrintOptions
  1406. IMPLEMENT_DYNAMIC(CXTPSyntaxEditViewPrintOptions, CXTPPrintOptions)
  1407. CXTPSyntaxEditViewPrintOptions::CXTPSyntaxEditViewPrintOptions()
  1408. {
  1409. }