BOOL TextView::ForwardDelete() { ULONG selstart = min(m_nSelectionStart, m_nSelectionEnd); ULONG selend = max(m_nSelectionStart, m_nSelectionEnd); if(selstart != selend) { m_pTextDoc->erase_text(selstart, selend-selstart); m_nCursorOffset = selstart; m_pTextDoc->m_seq.breakopt(); } else { BYTE tmp[2]; //USPCACHE * uspCache; //CSCRIPT_LOGATTR * logAttr; //ULONG lineOffset; //ULONG index; m_pTextDoc->m_seq.render(m_nCursorOffset, tmp, 2); /*GetLogAttr(m_nCurrentLine, &uspCache, &logAttr, &lineOffset); index = m_nCursorOffset - lineOffset; do { m_pTextDoc->seq.erase(m_nCursorOffset, 1); index++; } while(!logAttr[index].fCharStop);*/ ULONG oldpos = m_nCursorOffset; MoveCharNext(); m_pTextDoc->erase_text(oldpos, m_nCursorOffset - oldpos); m_nCursorOffset = oldpos; //if(tmp[0] == '\r') // m_pTextDoc->erase_text(m_nCursorOffset, 2); //else // m_pTextDoc->erase_text(m_nCursorOffset, 1); } m_nSelectionStart = m_nCursorOffset; m_nSelectionEnd = m_nCursorOffset; ResetLineCache(); RefreshWindow(); Smeg(FALSE); return TRUE; }
// // TextView::EnterText // // Import the specified text into the TextView at the current // cursor position, replacing any text-selection in the process // ULONG TextView::EnterText(TCHAR *szText, ULONG nLength) { ULONG selstart = min(m_nSelectionStart, m_nSelectionEnd); ULONG selend = max(m_nSelectionStart, m_nSelectionEnd); BOOL fReplaceSelection = (selstart == selend) ? FALSE : TRUE; ULONG erase_len = nLength; switch(m_nEditMode) { case MODE_READONLY: return 0; case MODE_INSERT: // if there is a selection then remove it if(fReplaceSelection) { // group this erase with the insert/replace operation m_pTextDoc->m_seq.group(); m_pTextDoc->erase_text(selstart, selend-selstart); m_nCursorOffset = selstart; } if(!m_pTextDoc->insert_text(m_nCursorOffset, szText, nLength)) return 0; if(fReplaceSelection) m_pTextDoc->m_seq.ungroup(); break; case MODE_OVERWRITE: if(fReplaceSelection) { erase_len = selend - selstart; m_nCursorOffset = selstart; } else { ULONG lineoff; USPCACHE *uspCache = GetUspCache(0, m_nCurrentLine, &lineoff); // single-character overwrite - must behave like 'forward delete' // and remove a whole character-cluster (i.e. maybe more than 1 char) if(nLength == 1) { ULONG oldpos = m_nCursorOffset; MoveCharNext(); erase_len = m_nCursorOffset - oldpos; m_nCursorOffset = oldpos; } // if we are at the end of a line (just before the CRLF) then we must // not erase any text - instead we act like a regular insertion if(m_nCursorOffset == lineoff + uspCache->length_CRLF) erase_len = 0; } if(!m_pTextDoc->replace_text(m_nCursorOffset, szText, nLength, erase_len)) return 0; break; default: return 0; } // update cursor+selection positions m_nCursorOffset += nLength; m_nSelectionStart = m_nCursorOffset; m_nSelectionEnd = m_nCursorOffset; // we altered the document, recalculate line+scrollbar information ResetLineCache(); RefreshWindow(); Smeg(TRUE); NotifyParent(TVN_CURSOR_CHANGE); return nLength; }
// // TextView::EnterText // // Import the specified text into the TextView at the current // cursor position, replacing any text-selection in the process // ULONG TextViewBase::EnterText(const TCHAR *szText, ULONG nLength) { #ifdef _DEBUG wchar_t db_string[200]; wsprintf(db_string, L"EnterText m_nSelectionEnd=%d\n", m_nSelectionEnd); OutputDebugString(db_string); #endif ULONG selstart = min(m_nSelectionStart, m_nSelectionEnd); ULONG selend = max(m_nSelectionStart, m_nSelectionEnd); BOOL fReplaceSelection = (selstart == selend) ? FALSE : TRUE; ULONG erase_len = nLength; ULONG line_offset = 0, line_length = 0; bool result = m_pTextDoc->lineinfo_from_lineno(m_nCurrentLine_D, &line_offset, &line_length, NULL, NULL); if(m_nCurrentLine_D != 0 && !result) { int stop = 1; throw MnException(); } switch(m_nEditMode) { case MODE_READONLY: return 0; case MODE_INSERT: // if there is a selection then remove it if(fReplaceSelection) { // group this erase with the insert/replace operation m_pTextDoc->m_seq.group(); m_pTextDoc->erase_text(selstart, selend-selstart); m_nSelectionEnd = selstart; } if(!m_pTextDoc->insert_text(m_nSelectionEnd, szText, nLength)) return 0; if(fReplaceSelection) m_pTextDoc->m_seq.ungroup(); break; case MODE_OVERWRITE: if(fReplaceSelection) { erase_len = selend - selstart; m_nSelectionEnd = selstart; } else { //ULONG lastPosition; ULONG lineoff; ULONG length_CRLF; /* USPCACHE *uspCache = GetUspCache(0, m_nCurrentLine, &lineoff);*/ GetOffsetAndLength_CRLF( m_nCurrentLine_D, &lineoff, &length_CRLF); // single-character overwrite - must behave like 'forward delete' // and remove a whole character-cluster (i.e. maybe more than 1 char) if(nLength == 1) { ULONG oldpos = m_nSelectionEnd; MoveCharNext(); erase_len = m_nSelectionEnd - oldpos; m_nSelectionEnd = oldpos; } // if we are at the end of a line (just before the CRLF) then we must // not erase any text - instead we act like a regular insertion if (m_nSelectionEnd == lineoff + length_CRLF) erase_len = 0; } if(!m_pTextDoc->replace_text(m_nSelectionEnd, szText, nLength, erase_len)) return 0; break; default: return 0; } // update cursor+selection positions m_nSelectionEnd += nLength; m_nSelectionStart = m_nSelectionEnd; //m_nSelectionEnd = m_nCursorOffset; // we altered the document, recalculate line+scrollbar information //RefreshWindow(); int a1 = '\n'; int a2 = '\r'; //ULONG offset, len; if(nLength == 1 && !fReplaceSelection && line_length < MAX_LINE_LENGTH - 1) { FilePosToCharPos(m_nSelectionEnd, &m_CurrentCharPos); if(szText[0] =='\n' ) { wchar_t debug[50]; wsprintf(debug, L"newline m_nCursorOffset%d", m_nSelectionEnd); OutputDebugString(debug); Smeg(TRUE); } else if(szText[0] =='\r') { } else { m_pTextDoc->init_linebuffer(); ResetLineCache( m_nCurrentLine_D); InvalidateRange(m_nSelectionEnd - 1, line_offset + line_length + 1); RepositionCaret(); } }else { //ResetLineCache( ); Smeg(TRUE); } NotifyParent(TVN_CURSOR_CHANGE); return nLength; }
// // Process keyboard-navigation keys // LONG TextViewBase::OnKeyDown(UINT nKeyCode, UINT nFlags) { bool fCtrlDown = IsKeyPressed(VK_CONTROL); bool fShiftDown = IsKeyPressed(VK_SHIFT); BOOL fAdvancing = FALSE; long oldCursorOffset = m_nSelectionEnd; // // Process the key-press. Cursor movement is different depending // on if <ctrl> is held down or not, so act accordingly // switch(nKeyCode) { case VK_SHIFT: case VK_CONTROL: return 0; case 'a': case 'A': { if(fCtrlDown) SelectAll(); } return 0; // CTRL+Z undo case 'z': case 'Z': if(fCtrlDown && Undo()) /*NotifyParent(TVN_CHANGED);*/ return 0; // CTRL+Y redo case 'y': case 'Y': if(fCtrlDown && Redo()) //NotifyParent(TVN_CHANGED); return 0; // CTRL+C copy case 'c': case 'C': { //if(fCtrlDown && Redo()) // NotifyParent(TVN_CHANGED); if(fCtrlDown) return OnCopy(); else break; } case 'x': case 'X': { if(fCtrlDown) return OnCut(); else break; } case 'v': case 'V': { if(fCtrlDown) return OnPaste(); else break; } // Change insert mode / clipboard copy&paste case VK_INSERT: if(fCtrlDown) { OnCopy(); NotifyParent(TVN_CHANGED); } else if(fShiftDown) { OnPaste(); NotifyParent(TVN_CHANGED); } else { if(m_nEditMode == MODE_INSERT) m_nEditMode = MODE_OVERWRITE; else if(m_nEditMode == MODE_OVERWRITE) m_nEditMode = MODE_INSERT; NotifyParent(TVN_EDITMODE_CHANGE); } return 0; case VK_DELETE: if(m_nEditMode != MODE_READONLY) { if(fShiftDown) OnCut(); else ForwardDelete(); NotifyParent(TVN_CHANGED); } return 0; case VK_BACK: if(m_nEditMode != MODE_READONLY) { BackDelete(); fAdvancing = FALSE; NotifyParent(TVN_CHANGED); } return 0; case VK_LEFT: if(fCtrlDown) MoveWordPrev(); else MoveCharPrev(); fAdvancing = FALSE; break; case VK_RIGHT: if(fCtrlDown) MoveWordNext(); else MoveCharNext(); fAdvancing = TRUE; break; case VK_UP: if(fCtrlDown) Scroll(0, -1); else MoveLineUp(1); break; case VK_DOWN: if(fCtrlDown) Scroll(0, 1); else MoveLineDown(1); break; case VK_PRIOR: if(!fCtrlDown) MovePageUp(); break; case VK_NEXT: if(!fCtrlDown) MovePageDown(); break; case VK_HOME: if(fCtrlDown) MoveFileStart(); else MoveLineStart(m_nCurrentLine); break; case VK_END: if(fCtrlDown) MoveFileEnd(); else MoveLineEnd(m_nCurrentLine); break; default: return 0; } // Extend selection if <shift> is down if(fShiftDown) { InvalidateRange(m_nSelectionEnd, oldCursorOffset); //m_nSelectionEnd = m_nCursorOffset; } // Otherwise clear the selection else { if(m_nSelectionStart != m_nSelectionEnd) InvalidateRange(m_nSelectionStart, m_nSelectionEnd); //m_nSelectionEnd = m_nCursorOffset; m_nSelectionStart = m_nSelectionEnd; } // update caret-location (xpos, line#) from the offset //UpdateCaretOffset(m_nCursorOffset, fAdvancing, &m_nCaretPosX, &m_nCurrentLine); CHAR_POS cp; FilePosToCharPos(m_nSelectionEnd, &cp); m_nCurrentLine_D = cp.logLine; // maintain the caret 'anchor' position *except* for up/down actions if(nKeyCode != VK_UP && nKeyCode != VK_DOWN) { //m_nAnchorPosX = m_nCaretPosX; // scroll as necessary to keep caret within viewport //ScrollToPosition(m_nCaretPosX, m_nCurrentLine); } else { // scroll as necessary to keep caret within viewport if(!fCtrlDown); //ScrollToPosition(m_nCaretPosX, m_nCurrentLine); } NotifyParent(TVN_CURSOR_CHANGE); return 0; }
BOOL TextViewBase::ForwardDelete() { ULONG selstart = min(m_nSelectionStart, m_nSelectionEnd); ULONG selend = max(m_nSelectionStart, m_nSelectionEnd); ULONG length = selend - selstart; bool nead_Smeg = false; ULONG line_offset, line_length, line_no; m_pTextDoc->lineinfo_from_offset(selstart, &line_no, &line_offset, &line_length,NULL, NULL); if(selstart != selend) { if(selstart + length >= line_length + line_offset) { nead_Smeg = true; } m_pTextDoc->erase_text(selstart, length); //m_nCursorOffset = selstart; m_pTextDoc->m_seq.breakopt(); } else { ULONG oldpos = m_nSelectionEnd; MoveCharNext(); length = m_nSelectionEnd - oldpos; m_pTextDoc->erase_text(oldpos, length); m_nSelectionEnd = oldpos; if(oldpos + length >= line_length + line_offset) { nead_Smeg = true; } //else // m_pTextDoc->erase_text(m_nCursorOffset, 1); } m_nSelectionStart = selstart; m_nSelectionEnd = selstart; FilePosToCharPos(selstart, &m_CurrentCharPos); if(nead_Smeg) { Smeg(FALSE); }else { m_pTextDoc->init_linebuffer(); if(m_pTextDoc->lineinfo_from_lineno(m_nCurrentLine_D, &line_offset, &line_length ,NULL,NULL)) { ResetLineCache( m_nCurrentLine_D); InvalidateRange(min(m_nSelectionEnd - 1, 0), line_offset + line_length); RepositionCaret(); } } return TRUE; }