BOOL TextView::BackDelete() { ULONG selstart = min(m_nSelectionStart, m_nSelectionEnd); ULONG selend = max(m_nSelectionStart, m_nSelectionEnd); // if there's a selection then delete it if(selstart != selend) { m_pTextDoc->erase_text(selstart, selend-selstart); m_nCursorOffset = selstart; m_pTextDoc->m_seq.breakopt(); } // otherwise do a back-delete else if(m_nCursorOffset > 0) { //m_nCursorOffset--; ULONG oldpos = m_nCursorOffset; MoveCharPrev(); //m_pTextDoc->erase_text(m_nCursorOffset, 1); m_pTextDoc->erase_text(m_nCursorOffset, oldpos - m_nCursorOffset); } m_nSelectionStart = m_nCursorOffset; m_nSelectionEnd = m_nCursorOffset; ResetLineCache(); RefreshWindow(); Smeg(FALSE); return TRUE; }
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; }
BOOL TextView::Redo() { if(m_nEditMode == MODE_READONLY) return FALSE; if(!m_pTextDoc->Redo(&m_nSelectionStart, &m_nSelectionEnd)) return FALSE; m_nCursorOffset = m_nSelectionEnd; ResetLineCache(); RefreshWindow(); Smeg(m_nSelectionStart != m_nSelectionEnd); return TRUE; }
BOOL TextViewBase::Undo() { if(m_nEditMode == MODE_READONLY) return FALSE; if(!m_pTextDoc->Undo(&m_nSelectionStart, &m_nSelectionEnd)) return FALSE; //m_nCursorOffset = m_nSelectionEnd; ResetLineCache(); RefreshWindow(); Smeg(m_nSelectionStart != m_nSelectionEnd); NotifyParent(TVN_CHANGED); 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; }
BOOL TextViewBase::BackDelete() { 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); //m_pTextDoc->lineinfo_from_lineno(m_nCurrentLine_D, &line_offset, &line_length, NULL, NULL); // if there's a selection then delete it if(selstart != selend) { if(selstart + length >= line_length + line_offset) { nead_Smeg = true; } m_pTextDoc->erase_text(selstart, selend-selstart); m_nSelectionEnd = selstart; m_pTextDoc->m_seq.breakopt(); } // otherwise do a back-delete else if (m_nSelectionEnd > 0) { //m_nCursorOffset--; ULONG oldpos = m_nSelectionEnd; MoveCharPrev(); length = oldpos - m_nSelectionEnd; if (m_nSelectionEnd < line_offset) { nead_Smeg = true; } m_pTextDoc->erase_text(m_nSelectionEnd, length); } m_nSelectionStart = m_nSelectionEnd; //m_nSelectionEnd = m_nCursorOffset; //FilePosToCharPos(m_nCursorOffset, &m_CurrentCharPos); if(nead_Smeg) { Smeg(FALSE); }else { int old_offset = m_nSelectionEnd; m_pTextDoc->init_linebuffer(); ResetLineCache( m_nCurrentLine_D); //FilePosToCharPos(m_nCursorOffset, &m_CurrentCharPos); MoveLineStart(0, false); InvalidateRange((m_nSelectionEnd ? m_nSelectionEnd - 1 : 0), line_offset + line_length); m_nSelectionEnd = old_offset; RepositionCaret(); } #ifdef _DEBUG wchar_t db_string[200]; wsprintf(db_string, L"m_nSelectionEnd=%d\n", m_nSelectionEnd); OutputDebugString(db_string); #endif return TRUE; }
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; }