void CCrystalEditView::Paste() { if (! QueryEditable()) return; if (m_pTextBuffer == NULL) return; if(m_pTextBuffer->m_bUndoGroup) m_pTextBuffer->FlushUndoGroup(this); m_pTextBuffer->BeginUndoGroup(); DeleteCurrentSelection(); CString text; if (GetFromClipboard(text)) { CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); int x, y; m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, text, y, x, CE_ACTION_PASTE); // [JRT] ptCursorPos.x = x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetAnchor(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); } m_pTextBuffer->FlushUndoGroup(this); }
BOOL CCrystalEditView::ReplaceSelection(LPCTSTR pszNewText) { ASSERT(pszNewText != NULL); if (IsSelection()) DeleteCurrentSelection(); CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); int x, y; m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszNewText, y, x, CE_ACTION_REPLACE); // [JRT] CPoint ptEndOfBlock = CPoint(x, y); ASSERT_VALIDTEXTPOS(ptCursorPos); ASSERT_VALIDTEXTPOS(ptEndOfBlock); SetAnchor(ptEndOfBlock); SetSelection(ptCursorPos, ptEndOfBlock); SetCursorPos(ptEndOfBlock); EnsureVisible(ptEndOfBlock); return TRUE; }
void CCrystalEditView::OnEditTab() { if (! QueryEditable() || m_pTextBuffer == NULL) return; BOOL bTabify = FALSE; CPoint ptSelStart, ptSelEnd; if (IsSelection()) { GetSelection(ptSelStart, ptSelEnd); bTabify = ptSelStart.y != ptSelEnd.y; } if (bTabify) { m_pTextBuffer->BeginUndoGroup(); int nStartLine = ptSelStart.y; int nEndLine = ptSelEnd.y; ptSelStart.x = 0; if (ptSelEnd.x > 0) { if (ptSelEnd.y == GetLineCount() - 1) { ptSelEnd.x = GetLineLength(ptSelEnd.y); } else { ptSelEnd.x = 0; ptSelEnd.y ++; } } else nEndLine --; SetSelection(ptSelStart, ptSelEnd); SetCursorPos(ptSelEnd); EnsureVisible(ptSelEnd); // Shift selection to right m_bHorzScrollBarLocked = TRUE; static const TCHAR pszText[] = _T("\t"); for (int L = nStartLine; L <= nEndLine; L ++) { int x, y; m_pTextBuffer->InsertText(this, L, 0, pszText, y, x, CE_ACTION_INDENT); // [JRT] } m_bHorzScrollBarLocked = FALSE; RecalcHorzScrollBar(); m_pTextBuffer->FlushUndoGroup(this); return; } if (m_bOvrMode) { CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); int nLineLength = GetLineLength(ptCursorPos.y); LPCTSTR pszLineChars = GetLineChars(ptCursorPos.y); if (ptCursorPos.x < nLineLength) { int nTabSize = GetTabSize(); int nChars = nTabSize - CalculateActualOffset(ptCursorPos.y, ptCursorPos.x) % nTabSize; ASSERT(nChars > 0 && nChars <= nTabSize); while (nChars > 0) { if (ptCursorPos.x == nLineLength) break; if (pszLineChars[ptCursorPos.x] == _T('\t')) { ptCursorPos.x ++; break; } ptCursorPos.x ++; nChars --; } ASSERT(ptCursorPos.x <= nLineLength); ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); return; } } m_pTextBuffer->BeginUndoGroup(); DeleteCurrentSelection(); CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); static const TCHAR pszText[] = _T("\t"); int x, y; m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszText, y, x, CE_ACTION_TYPING); // [JRT] ptCursorPos.x = x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); m_pTextBuffer->FlushUndoGroup(this); }
void CCrystalEditView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { CCrystalTextView::OnChar(nChar, nRepCnt, nFlags); if ((::GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0 || (::GetAsyncKeyState(VK_RBUTTON) & 0x8000) != 0) return; if (nChar ==32 || nChar == VK_RETURN) if(nCursorColor==COLORINDEX_NORMALTEXT||nCursorColor==COLORINDEX_KEYWORD) {//анализ на предмет использования шаблонов CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); if(ptCursorPos.y>=0&&ptCursorPos.y<GetLineCount()) { CString Str = GetLineChars(ptCursorPos.y); int nLength = GetLineLength(ptCursorPos.y); Str=Str.Left(min(ptCursorPos.x,nLength)); CValue vDeleteText; CValue vInsertText; extern int AfxCallInitProc(CString csName,CValue Param,CValue &vDeleteText,CValue &vInsertText); int nRet=AfxCallInitProc("ПриВыбореШаблона",String(Str),vDeleteText,vInsertText); if(nRet) { int nDeleteCount=vDeleteText.GetString().GetLength(); int nStartPos=max(0,ptCursorPos.x-nDeleteCount); if(nDeleteCount>0) m_pTextBuffer->DeleteText(this, ptCursorPos.y, nStartPos, ptCursorPos.y, ptCursorPos.x, CE_ACTION_TYPING); int x, y; CString csStrInsert=vInsertText.GetString(); m_pTextBuffer->InsertText(this, ptCursorPos.y, nStartPos, csStrInsert, y, x, CE_ACTION_TYPING); CPoint ptEnd; ptEnd.x=x; ptEnd.y=y; ptCursorPos.x=0; SetSelection(ptCursorPos, ptEnd); FormatSelection(0); ptEnd.y-=(csStrInsert.Replace("\r","\r")+1)/2; ptEnd.x=GetLineLength(ptEnd.y); SetSelection(ptEnd, ptEnd); SetAnchor(ptEnd); SetCursorPos(ptEnd); EnsureVisible(ptEnd); MoveEnd(0); } } } BOOL bTranslated = FALSE; if (nChar == VK_RETURN) { if (m_bOvrMode) { CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); if (ptCursorPos.y < GetLineCount() - 1) { ptCursorPos.x = 0; ptCursorPos.y++; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); return; } } m_pTextBuffer->BeginUndoGroup(); if (QueryEditable() && m_pTextBuffer != NULL) { DeleteCurrentSelection(); int x, y; CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); const static TCHAR pszText[3] = _T("\r\n"); m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszText, y, x, CE_ACTION_TYPING); // [JRT] int nLenght = GetLineLength(ptCursorPos.y); CString sLineBuf = GetLineChars(ptCursorPos.y); CString sBegin=""; for(int i=0;i<=nLenght;i++) { char cChr; cChr = sLineBuf.GetAt(i); if(!IsLetter(cChr,1)) sBegin+=cChr; else break; } int nPos=ptCursorPos.x; m_pTextBuffer->InsertText(this,y,x, sBegin, y, x, CE_ACTION_TYPING); // [JRT] ptCursorPos.x = x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); /* FormatSelection(-1); if(nPos>0) { MoveEnd(0); } */ } m_pTextBuffer->FlushUndoGroup(this); return; } if (nChar > 31) { if (QueryEditable() && m_pTextBuffer != NULL) { BOOL bUndoBeginGroup=m_pTextBuffer->m_bUndoGroup; if(!bUndoBeginGroup) m_pTextBuffer->BeginUndoGroup(nChar != _T(' ')); CPoint ptSelStart, ptSelEnd; GetSelection(ptSelStart, ptSelEnd); CPoint ptCursorPos; if (ptSelStart != ptSelEnd) { ptCursorPos = ptSelStart; DeleteCurrentSelection(); } else { ptCursorPos = GetCursorPos(); if (m_bOvrMode && ptCursorPos.x < GetLineLength(ptCursorPos.y)) m_pTextBuffer->DeleteText(this, ptCursorPos.y, ptCursorPos.x, ptCursorPos.y, ptCursorPos.x + 1, CE_ACTION_TYPING); // [JRT] } ASSERT_VALIDTEXTPOS(ptCursorPos); char pszText[2]; pszText[0] = (char) nChar; pszText[1] = 0; int x,y; USES_CONVERSION; m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, A2T(pszText), y, x, CE_ACTION_TYPING); // [JRT] ptCursorPos.x = x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); if(!bUndoBeginGroup) m_pTextBuffer->FlushUndoGroup(this); } } }
void CEditWnd::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { CTextWnd::OnChar(nChar, nRepCnt, nFlags); if (m_bOemCharset) CharToOemBuff((char*)&nChar, (char*)&nChar, 1); if ((::GetAsyncKeyState(VK_LBUTTON) | ::GetAsyncKeyState(VK_RBUTTON)) & 0x8000) return; BOOL bTranslated = FALSE; if (nChar == VK_RETURN) { m_pTextBuffer->BeginUndoGroup(); if (QueryEditable() && m_pTextBuffer != NULL) { DeleteCurrentSelection(); CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); int x, y; CString pszText = "\r\n"; bool flag; if (ptCursorPos.x > 0) { LPCSTR chars1 = GetLineChars(ptCursorPos.y); char *p = 0; for (int j = 0; j < QUOTE_LENGTH && j < GetLineLength(ptCursorPos.y); j++) if (chars1[j] == '>') p = (char*)chars1 + j; flag = p != 0 && ptCursorPos.x < GetLineLength(ptCursorPos.y); //Вставим знаки квоты if (flag) { p++; while (isspace((unsigned char)*p)) p++; pszText += CString(chars1, (int)(p - chars1)); } //Автоотступ else if (m_bAutoIndent) { LPCSTR chars = m_pTextBuffer->GetLineChars(ptCursorPos.y); int len = m_pTextBuffer->GetLineLength(ptCursorPos.y); for (int j = 0; j < len && isspace((unsigned char)chars[j]); j++) pszText += chars[j]; } } else flag = false; m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszText, y, x, CE_ACTION_TYPING); ptCursorPos.x = flag ? 0 : x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); } m_pTextBuffer->FlushUndoGroup(this); return; } else if (nChar > 31) { if (QueryEditable() && m_pTextBuffer != NULL) { m_pTextBuffer->BeginUndoGroup(nChar != _T(' ')); CPoint ptSelStart, ptSelEnd; GetSelection(ptSelStart, ptSelEnd); CPoint ptCursorPos; if (ptSelStart != ptSelEnd) { ptCursorPos = ptSelStart; DeleteCurrentSelection(); } else ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); char pszText[2]; pszText[0] = (char) nChar; pszText[1] = 0; int x, y; m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszText, y, x, CE_ACTION_TYPING); // [JRT] ptCursorPos.x = x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); m_pTextBuffer->FlushUndoGroup(this); } } }
void CEditWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { CTextWnd::OnKeyDown(nChar, nRepCnt, nFlags); if (!QueryEditable() || m_pTextBuffer == NULL) return; bool isShift = (GetKeyState(VK_SHIFT) & 0xF0) != 0; bool isCtrl = (GetKeyState(VK_CONTROL) & 0xF0) != 0; if (nChar == VK_TAB) { BOOL bTabify = FALSE; CPoint ptSelStart, ptSelEnd; if (IsSelection()) { GetSelection(ptSelStart, ptSelEnd); bTabify = ptSelStart.y != ptSelEnd.y; } if (bTabify) { m_pTextBuffer->BeginUndoGroup(); int nStartLine = ptSelStart.y; int nEndLine = ptSelEnd.y; ptSelStart.x = 0; if (ptSelEnd.x > 0) { if (ptSelEnd.y == GetLineCount() - 1) { ptSelEnd.x = GetLineLength(ptSelEnd.y); } else { ptSelEnd.x = 0; ptSelEnd.y ++; } } else nEndLine --; SetSelection(ptSelStart, ptSelEnd); SetCursorPos(ptSelEnd); EnsureVisible(ptSelEnd); // Shift selection to right m_bHorzScrollBarLocked = TRUE; //static const TCHAR pszText[] = _T("\t"); CString pszText; if (!m_bReplaceTabs) pszText = "\t"; else { CString tmp(' ', GetTabSize()); pszText = tmp; } for (int L = nStartLine; L <= nEndLine; L ++) { int x, y; m_pTextBuffer->InsertText(this, L, 0, pszText, y, x, CE_ACTION_INDENT); } m_bHorzScrollBarLocked = FALSE; RecalcHorzScrollBar(); m_pTextBuffer->FlushUndoGroup(this); } else { m_pTextBuffer->BeginUndoGroup(); DeleteCurrentSelection(); CPoint ptCursorPos = GetCursorPos(); ASSERT_VALIDTEXTPOS(ptCursorPos); CString pszText; if (!m_bReplaceTabs) pszText = "\t"; else { CString tmp(' ', GetTabSize()); pszText = tmp; } int x, y; m_pTextBuffer->InsertText(this, ptCursorPos.y, ptCursorPos.x, pszText, y, x, CE_ACTION_TYPING); ptCursorPos.x = x; ptCursorPos.y = y; ASSERT_VALIDTEXTPOS(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetAnchor(ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); m_pTextBuffer->FlushUndoGroup(this); } } if (nChar == VK_BACK && !IsSelection()) { CPoint ptCursorPos = GetCursorPos(); if (ptCursorPos.y > 0 || (ptCursorPos.x > 0 && ptCursorPos.y == 0)) { CPoint ptCurrentCursorPos = ptCursorPos; bool bDeleted = false; if(ptCursorPos.x == 0) { ptCursorPos.y--; ptCursorPos.x = GetLineLength(ptCursorPos.y); bDeleted = true; } else { ptCursorPos.x--; bDeleted = true; } ASSERT_VALIDTEXTPOS(ptCursorPos); SetAnchor(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); if (bDeleted) m_pTextBuffer->DeleteText(this, ptCursorPos.y, ptCursorPos.x, ptCurrentCursorPos.y, ptCurrentCursorPos.x, CE_ACTION_BACKSPACE); } } if (nChar == VK_DELETE && !isShift) { CPoint ptSelStart, ptSelEnd; GetSelection(ptSelStart, ptSelEnd); if (ptSelStart == ptSelEnd) { if (ptSelEnd.x == GetLineLength(ptSelEnd.y)) { if (ptSelEnd.y == GetLineCount() - 1) return; ptSelEnd.y++; ptSelEnd.x = 0; if (GetLineLength(ptSelStart.y) != 0) { LPCSTR chars = GetLineChars(ptSelEnd.y); for (int j = 0; j < QUOTE_LENGTH && j < GetLineLength(ptSelEnd.y); j++) if (chars[j] == '>') ptSelEnd.x = j + 1; while (ptSelEnd.x < GetLineLength(ptSelEnd.y) && (chars[ptSelEnd.x] == ' ' || chars[ptSelEnd.x] == '\t')) ptSelEnd.x++; } } else ptSelEnd.x++; } CPoint ptCursorPos = ptSelStart; ASSERT_VALIDTEXTPOS(ptCursorPos); SetAnchor(ptCursorPos); SetSelection(ptCursorPos, ptCursorPos); SetCursorPos(ptCursorPos); EnsureVisible(ptCursorPos); m_pTextBuffer->DeleteText(this, ptSelStart.y, ptSelStart.x, ptSelEnd.y, ptSelEnd.x, CE_ACTION_DELETE); } if ((nChar == 'X' && isCtrl) || (nChar == VK_DELETE && isShift)) Cut(); if ((nChar == 'V' && isCtrl) || (nChar == VK_INSERT && isShift)) Paste(); if (nChar == 'Z' && isCtrl && isShift) Redo(); if (nChar == 'Z' && isCtrl && !isShift) Undo(); }