void CHexEdit::OnEditClear() { m_currentAddress = m_selStart; SelDelete(m_selStart, m_selEnd); RepositionCaret(m_currentAddress); RedrawWindow(); }
LONG TextViewBase::OnLButtonDblClick(UINT nFlags, int mx, int my) { // remove any existing selection InvalidateRange(m_nSelectionStart, m_nSelectionEnd); ULONG lineno, fileoff; int xpos; // map the mouse-coordinates to a real file-offset-coordinate MouseCoordToFilePos(mx, my, &lineno, &fileoff, &xpos); //m_nAnchorPosX = m_nCaretPosX; // move selection-start to start of word MoveWordStart(); m_nSelectionStart = m_nSelectionEnd;// m_nCursorOffset; // move selection-end to end of word MoveWordEnd(); //m_nSelectionEnd = m_nCursorOffset; // update caret position InvalidateRange(m_nSelectionStart, m_nSelectionEnd); //UpdateCaretOffset(m_nCursorOffset, TRUE, &m_nCaretPosX, &m_nCurrentLine); //m_nAnchorPosX = m_nCaretPosX; RepositionCaret(); NotifyParent(TVN_CURSOR_CHANGE); NotifyParent(TVN_SELECTION_CHANGED); return 0; }
void CHexEdit::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { pScrollBar; if(!m_pData) return; int oa = m_topindex; switch(nSBCode) { case SB_LINEDOWN: if(m_topindex < m_length - m_lpp*m_bpr) { //ScrollWindow(0, -m_lineHeight, rc); m_topindex += m_bpr; RedrawWindow(); } break; case SB_LINEUP: if(m_topindex > 0) { //ScrollWindow(0, m_lineHeight, rc); m_topindex -= m_bpr; RedrawWindow(); } break; case SB_PAGEDOWN: if(m_topindex < m_length - m_lpp*m_bpr) { m_topindex += m_bpr * m_lpp; if(m_topindex > m_length - m_lpp*m_bpr) m_topindex = m_length - m_lpp*m_bpr; RedrawWindow(); } break; case SB_PAGEUP: if(m_topindex > 0) { m_topindex -= m_bpr * m_lpp; if(m_topindex < 0) m_topindex = 0; RedrawWindow(); } break; case SB_THUMBTRACK: m_topindex = nPos * m_bpr; RedrawWindow(); break; } ::SetScrollPos(this->m_hWnd, SB_VERT, m_topindex / m_bpr, TRUE); if(!m_bNoAddressChange) m_currentAddress += (m_topindex - oa); TRACE("!!%d %d %d",m_topindex,oa,m_currentAddress); RepositionCaret(m_currentAddress); }
void CHexEdit::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { pScrollBar; if(!m_pData) return; int oa = m_topindex; switch(nSBCode) { case SB_LINEDOWN: if(m_topindex < m_length - m_lpp*m_bpr) { m_topindex += m_bpr; Invalidate(FALSE); } break; case SB_LINEUP: if(m_topindex > 0) { m_topindex -= m_bpr; Invalidate(FALSE); } break; case SB_PAGEDOWN: if(m_topindex < m_length - m_lpp*m_bpr) { m_topindex += m_bpr * m_lpp; if(m_topindex > m_length - m_lpp*m_bpr) m_topindex = m_length - m_lpp*m_bpr; Invalidate(FALSE); } break; case SB_PAGEUP: if(m_topindex > 0) { m_topindex -= m_bpr * m_lpp; if(m_topindex < 0) m_topindex = 0; Invalidate(FALSE); } break; case SB_THUMBTRACK: m_topindex = nPos * m_bpr; Invalidate(FALSE); break; } ::SetScrollPos(this->m_hWnd, SB_VERT, m_topindex / m_bpr, TRUE); RepositionCaret(m_currentAddress); }
LONG TextViewBase::OnSetFocus(HWND hwndOld) { //CreateCaret(m_hWnd, (HBITMAP)NULL, m_nCaretWidth, m_nLineHeight); m_bFocused = true; CreateMyCaret(); RepositionCaret(); ShowCaret(m_hWnd); RefreshWindow(); return 0; }
void CHexEdit::ResetPos(BOOL b) { if(b) { m_selStart=m_selEnd=m_currentAddress; } else { m_currentAddress=m_selEnd; } RepositionCaret(m_currentAddress); }
void CHexEdit::Move(int x, int y) { switch(m_currentMode) { case EDIT_NONE: return; case EDIT_HIGH: if(x != 0) m_currentMode = EDIT_LOW; if(x == -1) m_currentAddress --; m_currentAddress += y* m_bpr; break; case EDIT_LOW: if(x != 0) m_currentMode = EDIT_HIGH; if(x == 1) m_currentAddress++; m_currentAddress += y* m_bpr; break; case EDIT_ASCII: { m_currentAddress += x; m_currentAddress += y*m_bpr; } break; } if(m_currentAddress < 0) m_currentAddress = 0; if(m_currentAddress >= m_length) { m_currentAddress -= x; m_currentAddress -= y*m_bpr; } m_bNoAddressChange = TRUE; if(m_currentAddress < m_topindex) { OnVScroll(SB_LINEUP, 0, NULL); } if(m_currentAddress >= m_topindex + m_lpp*m_bpr) { OnVScroll(SB_LINEDOWN, 0, NULL); } m_bNoAddressChange = FALSE; //ScrollIntoView(m_currentAddress); RepositionCaret(m_currentAddress); }
void TextView::Smeg(BOOL fAdvancing) { m_pTextDoc->init_linebuffer(); m_nLineCount = m_pTextDoc->linecount(); UpdateMetrics(); UpdateMarginWidth(); SetupScrollbars(); UpdateCaretOffset(m_nCursorOffset, fAdvancing, &m_nCaretPosX, &m_nCurrentLine); m_nAnchorPosX = m_nCaretPosX; ScrollToPosition(m_nCaretPosX, m_nCurrentLine); RepositionCaret(); }
void CHexEdit::SelDelete(int s, int e) { LPBYTE p = (LPBYTE) malloc(m_length - (e-s)+1); memcpy(p, m_pData, s); if(s < m_length-(e-s)) memcpy(p+s, m_pData+e, (m_length -e)); free(m_pData); SetSel(-1, -1); m_pData = p; m_length = m_length-(e-s); if(m_currentAddress > m_length) { m_currentAddress = m_length; RepositionCaret(m_currentAddress); } m_bUpdate = TRUE; }
void CHexEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { nFlags;nRepCnt; if(!m_pData) return; if(nChar == '\t') return; if(GetKeyState(VK_CONTROL) & 0x80000000) { switch(nChar) { case 0x03: if(IsSelected()) OnEditCopy(); return; case 0x16: OnEditPaste(); return; case 0x18: if(IsSelected()) OnEditCut(); return; case 0x1a: OnEditUndo(); return; } } if(nChar == 0x08) { if(m_currentAddress > 0) { m_currentAddress--; SelDelete(m_currentAddress, m_currentAddress+1); RepositionCaret(m_currentAddress); RedrawWindow(); } return; } SetSel(-1, -1); switch(m_currentMode) { case EDIT_NONE: return; case EDIT_HIGH: case EDIT_LOW: if((nChar >= '0' && nChar <= '9') || (nChar >= 'a' && nChar <= 'f')) { UINT b = nChar - '0'; if(b > 9) b = 10 + nChar - 'a'; if(m_currentMode == EDIT_HIGH) { m_pData[m_currentAddress] = (unsigned char)((m_pData[m_currentAddress] & 0x0f) | (b << 4)); } else { m_pData[m_currentAddress] = (unsigned char)((m_pData[m_currentAddress] & 0xf0) | b); } Move(1,0); } break; case EDIT_ASCII: m_pData[m_currentAddress] = (unsigned char)nChar; Move(1,0); break; } RedrawWindow(); }
// // 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; }
// // Move to end of file // VOID TextViewBase::MoveFileEnd() { m_nSelectionEnd = m_pTextDoc->charCount(); RepositionCaret(); ScrollToCaret(); }
// // Move to start of file // VOID TextViewBase::MoveFileStart() { m_nSelectionEnd = 0; RepositionCaret(); ScrollToCaret(); }
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; }
LRESULT HexView::OnChar(UINT nChar) { if(nChar < 32) return 0; if(m_nEditMode == HVMODE_READONLY) { MessageBeep(MB_ICONASTERISK); return 0; } if(m_nWhichPane == 0) // hex column { int cl[4] = { 2, 3, 3, 8 }; int cb[4] = { 16, 10, 8, 2 }; //int cw[4] = { 2, 3, 3, 2 }; int cf = m_nControlStyles & HVS_FORMAT_MASK; int val; BYTE b = 0; // get data under caret if(m_nSubItem > 0) { b = m_pDataSeq->getlastmodref(); } else { GetData(m_nCursorOffset, &b, 1); } // check this is an allowed character if(cf == HVS_FORMAT_HEX && !isxdigit(nChar) || cf == HVS_FORMAT_DEC && !(nChar >= '0' && nChar <= '9') || cf == HVS_FORMAT_OCT && !(nChar >= '0' && nChar <= '7') || cf == HVS_FORMAT_BIN && !(nChar >= '0' && nChar <= '1') ) { MessageBeep(MB_ICONASTERISK); return 0; } int val2; if(nChar >= 'a') val2 = nChar - 'a' + 0x0a; else if(nChar >= 'A') val2 = nChar - 'A' + 0x0A; else val2 = nChar - '0'; int power = 1; int base = cb[cf]; for(int i = cl[cf] - 1; i > m_nSubItem; i--) power *= base; if(m_nEditMode == HVMODE_INSERT) b = 0; val = b; val = (val / power) % base; val *= power; val = b - val; val += val2 * power; // check that we won't overflow the underlying value if(val > 0xff) { //MessageBeep(MB_ICONASTERISK); //return 0; val -= b % power; } if(m_nSubItem++ == 0) { b = (BYTE)val; // enter the data EnterData(&b, 1, m_nWhichPane == 0 ? false : true, true, false); } else { // directly edit the byte in the sequence - this // prevents us from introducing any more spans than necessary // and keeps this as a single 'byte' edit m_pDataSeq->getlastmodref() = val; ContentChanged(); if(m_nSubItem == cl[cf]) { m_nSubItem = 0; m_nCursorOffset++; } RepositionCaret(); } } else { BYTE b = nChar; // ascii column - enter the data as-is m_nSubItem = 0; EnterData(&b, 1, true, true, false); } return 0; }