XTPSyntaxEditCtrl.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:195k
源码类别:
对话框与窗口
开发平台:
Visual C++
- CXTPFontDC fontDC(&dc, GetPaintManager()->GetFont());
- m_DrawTextProcessor.RecalcRowHeight(&dc, GetPaintManager()->GetFont());
- if (m_hWnd && ::IsWindow(m_hWnd))
- {
- //m_pToolTip->SetFont(GetPaintManager()->GetFontToolTip());
- CalculateEditbarLength();
- Invalidate(FALSE);
- _UpdateIMEStatus();
- }
- }
- void CXTPSyntaxEditCtrl::_UpdateIMEStatus()
- {
- m_bIMEsupported = m_ImmWrapper.ImmIsIME();
- if (!m_bIMEsupported || !m_hWnd || !::IsWindow(m_hWnd))
- return;
- // IME Support
- XTP_HIMC hIMC = m_ImmWrapper.ImmGetContext(m_hWnd);
- if (hIMC)
- {
- LOGFONT lfFont;
- ::ZeroMemory(&lfFont, sizeof(lfFont));
- BOOL bFont = GetPaintManager()->GetFont()->GetLogFont(&lfFont);
- ASSERT(bFont);
- if (bFont)
- {
- VERIFY(m_ImmWrapper.ImmSetCompositionFont(hIMC, &lfFont));
- }
- VERIFY(m_ImmWrapper.ImmReleaseContext(m_hWnd, hIMC));
- }
- }
- LRESULT CXTPSyntaxEditCtrl::OnGetFont(WPARAM wParam, LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(wParam);
- UNREFERENCED_PARAMETER(lParam);
- return (LRESULT)GetPaintManager()->GetFont()->GetSafeHandle();
- }
- LRESULT CXTPSyntaxEditCtrl::OnSetFont(WPARAM wParam, LPARAM lParam)
- {
- HFONT hFont = (HFONT)wParam;
- LOGFONT lfFont;
- LOGFONT *pLF = NULL; // set the default font if hFont == NULL
- if (hFont)
- {
- ::ZeroMemory(&lfFont, sizeof(LOGFONT));
- if (!::GetObject(hFont, sizeof(LOGFONT), &lfFont))
- {
- ASSERT(FALSE);
- return 0;
- }
- pLF = &lfFont;
- }
- SetFontIndirect(pLF, FALSE);
- if (LOWORD(lParam))
- UpdateWindow();
- //Default();
- return 0;
- }
- LRESULT CXTPSyntaxEditCtrl::OnInputLanguage(WPARAM, LPARAM)
- {
- _UpdateIMEStatus();
- if (m_bIMEsupported)
- SetCurCaretPos(GetCurrentDocumentRow(), m_nDispCol, FALSE, FALSE);
- Default();
- return 1;
- }
- void CXTPSyntaxEditCtrl::SetDocModified(BOOL bModified)
- {
- XTP_EDIT_NMHDR_DOCMODIFIED dm;
- // NMHDR codes
- dm.nmhdr.code = XTP_EDIT_NM_SETDOCMODIFIED;
- dm.nmhdr.hwndFrom = m_hWnd;
- dm.nmhdr.idFrom = GetDlgCtrlID();
- // modified flag
- dm.bModified = bModified;
- // Notify the parent window
- if (::IsWindow(m_pParentWnd->GetSafeHwnd()))
- {
- m_pParentWnd->SendMessage(
- WM_NOTIFY, (WPARAM)dm.nmhdr.idFrom, (LPARAM)&dm);
- }
- }
- void CXTPSyntaxEditCtrl::InsertString(LPCTSTR szText, int iRow, int iCol, BOOL bDeleteSelection)
- {
- if (!CanEditDoc())
- return;
- int nPrevRow = GetCurrentDocumentRow();
- if (nPrevRow != iRow)
- SetCurrentDocumentRow(iRow);
- m_nCurrentCol = iCol;
- if (bDeleteSelection)
- DeleteSelection();
- // At first determine what type of CRLF it has
- const int nTextLen = (int)_tcsclen(szText);
- if (nTextLen == 0)
- return;
- int nRowFrom = GetCurrentDocumentRow();
- int nColFrom = m_nCurrentCol;
- //**----------------------
- OnBeforeEditChanged(nRowFrom, nColFrom);
- //**----------------------
- if (GetAutoIndent() && m_nAutoIndentCol > 0)
- {
- CString strInsertText(
- CString(_T('t'), m_nInsertTabCount) +
- CString(_T(' '), m_nInsertSpaceCount));
- m_pBuffer->InsertText(strInsertText, GetCurrentDocumentRow(), m_nCurrentCol);
- m_nCurrentCol = m_nInsertTabCount + m_nInsertSpaceCount + 1;
- m_nAutoIndentCol = 0;
- }
- XTP_EDIT_LINECOL finalLC;
- BOOL bInsRes = m_pBuffer->InsertText(szText, GetCurrentDocumentRow(),
- m_nCurrentCol, TRUE, &finalLC);
- if (bDeleteSelection)
- m_pBuffer->GetUndoRedoManager()->ChainLastCommand();
- if (bInsRes)
- {
- SetCurrentDocumentRow(finalLC.nLine);
- m_nCurrentCol = finalLC.nCol;
- m_nDispCol = CalcDispCol(GetLineText(finalLC.nLine), m_nCurrentCol);
- }
- RecalcScrollBars();
- UINT nAction = XTP_EDIT_EDITACTION_MODIFYROW;
- int nCurDocRow = GetCurrentDocumentRow();
- if (nCurDocRow > nPrevRow)
- nAction |= XTP_EDIT_EDITACTION_INSERTROW;
- //**----------------------
- OnEditChanged(nRowFrom, nColFrom, nCurDocRow, m_nCurrentCol, xtpEditActInsert);
- //**----------------------
- NotifyEditChanged(nPrevRow, nCurDocRow, nAction);
- SetCurCaretPos(nCurDocRow, m_nDispCol, FALSE/*, FALSE*/);
- }
- void CXTPSyntaxEditCtrl::InsertTextBlock(LPCTSTR szText, int iRow, int iCol, BOOL bDeleteSelection)
- {
- if (!CanEditDoc())
- return;
- int nPrevRow = GetCurrentDocumentRow();
- if (nPrevRow != iRow)
- {
- SetCurrentDocumentRow(iRow);
- }
- m_nCurrentCol = iCol;
- if (bDeleteSelection)
- {
- DeleteSelection();
- }
- // At first determine what type of CRLF it has
- const int nTextLen = (int)_tcsclen(szText);
- if (nTextLen == 0)
- return;
- int nRowFrom = GetCurrentDocumentRow();
- int nColFrom = m_nCurrentCol;
- //**----------------------
- OnBeforeEditChanged(nRowFrom, nColFrom);
- //**----------------------
- XTP_EDIT_LINECOL finalLC;
- BOOL bInsRes = m_pBuffer->InsertTextBlock(szText, GetCurrentDocumentRow(),
- iCol, TRUE, &finalLC);
- UNREFERENCED_PARAMETER(bInsRes);
- if (bDeleteSelection)
- m_pBuffer->GetUndoRedoManager()->ChainLastCommand();
- RecalcScrollBars();
- UINT nAction = XTP_EDIT_EDITACTION_MODIFYROW;
- int nCurDocRow = GetCurrentDocumentRow();
- if (nCurDocRow > nPrevRow)
- nAction |= XTP_EDIT_EDITACTION_INSERTROW;
- //**----------------------
- OnEditChanged(nRowFrom, nColFrom, nCurDocRow, m_nCurrentCol, xtpEditActInsert);
- //**----------------------
- NotifyEditChanged(nPrevRow, nCurDocRow, nAction);
- SetCurCaretPos(nCurDocRow, m_nDispCol, FALSE/*, FALSE*/);
- }
- void CXTPSyntaxEditCtrl::UpdateScrollPos(DWORD dwUpdate/* = XTP_EDIT_UPDATE_ALL*/)
- {
- XTP_EDIT_NMHDR_SETSCROLLPOS ssp;
- // NMHDR codes
- ssp.nmhdr.code = XTP_EDIT_NM_UPDATESCROLLPOS;
- ssp.nmhdr.hwndFrom = m_hWnd;
- ssp.nmhdr.idFrom = GetDlgCtrlID();
- // Update flag
- ssp.dwUpdate = dwUpdate;
- // Notify the parent window
- if (::IsWindow(m_pParentWnd->GetSafeHwnd()))
- {
- m_pParentWnd->SendMessage(
- WM_NOTIFY, (WPARAM)ssp.nmhdr.idFrom, (LPARAM)&ssp);
- }
- }
- void CXTPSyntaxEditCtrl::_EnableScrollBarNotify(DWORD dwScrollBar, DWORD dwState)
- {
- ASSERT(dwScrollBar != 0 && (dwScrollBar & (WS_VSCROLL|WS_HSCROLL)) != 0);
- XTP_EDIT_NMHDR_ENABLESCROLLBAR nmEScroll;
- // NMHDR codes
- nmEScroll.nmhdr.code = XTP_EDIT_NM_ENABLESCROLLBAR;
- nmEScroll.nmhdr.hwndFrom = m_hWnd;
- nmEScroll.nmhdr.idFrom = GetDlgCtrlID();
- // Update flag
- nmEScroll.dwScrollBar = dwScrollBar;
- nmEScroll.dwState = dwState;
- // Notify the parent window
- if (::IsWindow(m_pParentWnd->GetSafeHwnd()))
- {
- m_pParentWnd->SendMessage(
- WM_NOTIFY, (WPARAM)nmEScroll.nmhdr.idFrom, (LPARAM)&nmEScroll);
- }
- }
- void CXTPSyntaxEditCtrl::SetOverwriteMode(BOOL bOverwriteMode)
- {
- if (bOverwriteMode != m_pBuffer->GetOverwriteFlag() )
- {
- m_pBuffer->SetOverwriteFlag(bOverwriteMode);
- SetCurCaretPos(GetCurrentDocumentRow(), m_nDispCol, FALSE/*, FALSE*/);
- }
- }
- BOOL CXTPSyntaxEditCtrl::OnEraseBkgnd(CDC* pDC)
- {
- UNREFERENCED_PARAMETER(pDC);
- return TRUE;
- }
- XTP_EDIT_LINECOL CXTPSyntaxEditCtrl::_SubtractSelSizeFromPos(XTP_EDIT_LINECOL lcDispPos)
- {
- XTP_EDIT_LINECOL lcStart = m_Selection.GetNormalStart_disp();
- XTP_EDIT_LINECOL lcEnd = m_Selection.GetNormalEnd_disp();
- if (lcDispPos <= lcStart)
- return lcDispPos;
- if (lcDispPos < lcEnd && !m_Selection.bBlockSelectionMode)
- {
- ASSERT(FALSE);
- lcDispPos = lcEnd;
- }
- if (m_Selection.bBlockSelectionMode)
- {
- if (lcDispPos.nLine >= lcStart.nLine && lcDispPos.nLine <= lcEnd.nLine)
- {
- if (lcDispPos.nCol >= lcEnd.nCol)
- lcDispPos.nCol -= lcEnd.nCol - lcStart.nCol;
- }
- }
- else
- {
- if (lcEnd.nLine != lcStart.nLine)
- lcDispPos.nLine -= lcEnd.nLine - lcStart.nLine;
- if (lcEnd.nLine == lcDispPos.nLine)
- {
- if (lcEnd.nLine == lcStart.nLine)
- {
- ASSERT(lcDispPos.nCol >= lcEnd.nCol);
- lcDispPos.nCol -= lcEnd.nCol - lcStart.nCol;
- }
- else
- {
- lcDispPos.nCol -= lcEnd.nCol;
- }
- }
- }
- return lcDispPos;
- }
- void CXTPSyntaxEditCtrl::CopyOrMoveText(BOOL bCopy)
- {
- if (!m_Selection.IsSelExist() || m_Selection.IsInSel_disp(m_ptDropPos.y, m_ptDropPos.x))
- return;
- CMemFile memfile(CalcAveDataSize(m_Selection.GetNormalStart_str().nLine,
- m_Selection.GetNormalEnd_str().nLine));
- BOOL bRes = m_pBuffer->GetBuffer(m_Selection.GetNormalStart_disp(),
- m_Selection.GetNormalEnd_disp(), memfile,
- m_Selection.bBlockSelectionMode);
- if (!bRes)
- return;
- memfile.Write((const void *)_T("