void CChatWnd::OnChatUnderline() { if ( IsInRange( _T("u") ) ) InsertText( _T("[/u]") ); else InsertText( _T("[u]") ); }
void CChatWnd::OnChatItalic() { if ( IsInRange( _T("i") ) ) InsertText( _T("[/i]") ); else InsertText( _T("[i]") ); }
void CChatWnd::OnChatBold() { if ( IsInRange( _T("b") ) ) InsertText( _T("[/b]") ); else InsertText( _T("[b]") ); }
void EditTextTask::OnKeyDown(wxKeyEvent &event) { if ( m_done ) return; int code = event.GetKeyCode(); event.Skip(true); if ( code == WXK_ESCAPE ) { CloseTask(); event.Skip(false); } if ( code == WXK_DELETE || code == WXK_NUMPAD_DELETE || code == WXK_BACK ) { if ( HasSelection() ) DeleteSelection(); else if ( code == WXK_BACK ) DeleteBack(); else Delete(); event.Skip(false); } if ( code == WXK_RETURN || code == WXK_NUMPAD_ENTER ) { InsertText(_T("\n")); event.Skip(false); } if ( code == WXK_TAB ) { InsertText(_T("\t")); event.Skip(false); } }
void CodeEditor::OnCharAdded(wxScintillaEvent &event) { char ch = event.GetKey(); int currentLine = GetCurrentLine(); int pos = GetCurrentPos(); if (ch == wxT('\n') && currentLine > 0) { BeginUndoAction(); wxString indent = GetLineIndentString(currentLine - 1); wxChar b = GetLastNonWhitespaceChar(); if(b == wxT('{')) { if(GetUseTabs()) indent << wxT("\t"); else indent << wxT(" "); } InsertText(pos, indent); GotoPos((int)(pos + indent.Length())); ChooseCaretX(); EndUndoAction(); } else if(ch == wxT('}')) { BeginUndoAction(); wxString line = GetLine(currentLine); line.Trim(false); line.Trim(true); if(line.Matches(wxT("}"))) { pos = GetCurrentPos() - 2; pos = FindBlockStart(pos, wxT('{'), wxT('}')); if(pos != -1) { wxString indent = GetLineIndentString(LineFromPosition(pos)); indent << wxT('}'); DelLineLeft(); DelLineRight(); pos = GetCurrentPos(); InsertText(pos, indent); GotoPos((int)(pos + indent.Length())); ChooseCaretX(); } } EndUndoAction(); } }
static void AnnotationFormInit( void ) { FormType* annotationForm; annotationForm = FrmGetFormPtr( frmAnnotation ); if ( ( entryP->flags & ANNOTATION_BOOKMARK ) && entryP->id.indexInParagraph == NEW_ANNOTATION ) { SetFormTitle( annotationForm, strAddBookmarkTitle ); } else { SetFormTitle( annotationForm, strAnnotationTitle ); } scrollBar = GetObjectPtr( frmAnnotationScrollBar ); if ( Prefs()->scrollbar == SCROLLBAR_LEFT ) { SetObjectPosition( annotationForm, frmAnnotationField, false ); SetObjectPosition( annotationForm, frmAnnotationScrollBar, true ); } field = GetObjectPtr( frmAnnotationField ); CtlSetUsable( GetObjectPtr( frmAnnotationDelete ), entryP->id.indexInParagraph != NEW_ANNOTATION ); FrmDrawForm( annotationForm ); InsertText( field, data ); if ( entryP->id.indexInParagraph == NEW_ANNOTATION ) FldSetSelection( field, 0, StrLen( data ) ); else FldSetInsertionPoint( field, 0 ); UpdateFieldScrollbar( field, scrollBar ); FrmSetFocus( annotationForm, FrmGetObjectIndex( annotationForm, frmAnnotationField ) ); }
void CPWL_Edit::PasteText() { if (!CanPaste()) return; CFX_WideString swClipboard; if (IFX_SystemHandler* pSH = GetSystemHandler()) swClipboard = pSH->GetClipboardText(GetAttachedHWnd()); if (m_pFillerNotify) { FX_BOOL bRC = TRUE; FX_BOOL bExit = FALSE; CFX_WideString strChangeEx; int nSelStart = 0; int nSelEnd = 0; GetSel(nSelStart, nSelEnd); m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swClipboard, strChangeEx, nSelStart, nSelEnd, TRUE, bRC, bExit, 0); if (!bRC) return; if (bExit) return; } if (swClipboard.GetLength() > 0) { Clear(); InsertText(swClipboard.c_str()); } }
void CChatWnd::OnChatEmoticons() { CAutoPtr< CMenu > pIconMenu( Emoticons.CreateMenu() ); if ( UINT nID = m_wndToolBar.ThrowMenu( ID_CHAT_EMOTICONS, pIconMenu, this, TRUE ) ) { if ( LPCTSTR pszToken = Emoticons.GetText( nID - 1 ) ) InsertText( CString( _T(" ") ) + pszToken + _T(" ") ); } }
void MythUITextEdit::PasteTextFromClipboard(QClipboard::Mode mode) { QClipboard *clipboard = QApplication::clipboard(); if (!clipboard->supportsSelection()) mode = QClipboard::Clipboard; if (clipboard) InsertText(clipboard->text(mode)); }
void cbStyledTextCtrl::DoBraceCompletion(const wxChar& ch) { const int pos = GetCurrentPos(); const int style = GetStyleAt(pos); if (IsComment(style) || IsComment(GetStyleAt(pos - 2))) return; // do nothing if (ch == wxT('\'') || ch == wxT('"')) { if (GetCharAt(pos) == ch) { DeleteBack(); CharRight(); } else if (!IsString(GetStyleAt(pos - 2)) && !IsCharacter(GetStyleAt(pos - 2))) InsertText(pos, ch); return; // done } if (IsString(style) || IsCharacter(style)) return; // do nothing const wxString opBraces(wxT("([{")); const int opBraceIdx = opBraces.Find(ch); const wxString clBraces(wxT(")]}")); const int clBraceIdx = clBraces.Find(ch); if ( (opBraceIdx != wxNOT_FOUND) || (clBraceIdx != wxNOT_FOUND) ) { if ( GetCharAt(pos) == ch ) { DeleteBack(); CharRight(); } else if (opBraceIdx != wxNOT_FOUND) { int nextPos = pos; while ( wxIsspace(GetCharAt(nextPos)) && (nextPos < GetLength()) ) ++nextPos; if ( ((wxChar)GetCharAt(nextPos) != clBraces[opBraceIdx]) || (BraceMatch(nextPos) != wxNOT_FOUND) ) { InsertText(pos, clBraces[opBraceIdx]); } } } }
void CChatWnd::OnChatColour() { CColorDialog dlg( 0, CC_ANYCOLOR | CC_FULLOPEN ); if ( dlg.DoModal() != IDOK ) return; COLORREF cr = dlg.GetColor(); CString str; str.Format( _T("[c:#%.2x%.2x%.2x]"), GetRValue( cr ), GetGValue( cr ), GetBValue( cr ) ); InsertText( str ); }
void CEditWnd::Paste () { if (!QueryEditable ()) return; if (m_pTextBuffer == NULL) return; CString text; if (GetFromClipboard (text)) InsertText(text, CE_ACTION_PASTE); }
void FB_STC::ReplaceText(int from, int to, const wxString& text) { if (from == to) { InsertText(to, text); return; } SetTargetStart(from); SetTargetEnd(to); ReplaceTarget(text); }
boolean CompletionEditor::HandleChar (char c) { if (c == complete_) { InsertText("", 0); const char* best = nil; int match = 0; int length = text->LineOffset(text->EndOfLine(0)); for (int i = 0; i < count_; ++i) { for (int j = 0; ; ++j) { char c = completions_[i][j]; if (j < length) { if (text->Char(j) != c) { match = Math::max(match, j); break; } } else { if (best == nil) { best = completions_[i]; match = strlen(best); break; } else { if (c == '\0' || best[j] != c) { match = Math::min(match, j); break; } } } } } Select(match, length); if (match > length) { InsertText(best+length, match-length); } else if (best != nil && best[match] != '\0') { GetWorld()->RingBell(1); } return false; } else { return StringEditor::HandleChar(c); } }
BOOL CTextEditor::InsertAtSelection(LPCWSTR psz) { if (!RemoveText(_nSelStart, _nSelEnd - _nSelStart)) return FALSE; if (!InsertText(_nSelStart, psz, lstrlen(psz))) return FALSE; _nSelStart += lstrlen(psz); _nSelEnd = _nSelStart; return TRUE; }
void EditTextTask::Paste() { if ( wxTheClipboard->Open() ) { if ( wxTheClipboard->IsSupported( wxDF_TEXT ) ) { wxTextDataObject data; wxTheClipboard->GetData( data ); InsertText( data.GetText() ); } wxTheClipboard->Close(); } }
void CSynBCGPEditCtrl::ReplaceTextToFormatter( BOOL bAllText /*= TRUE*/ ) { if (bAllText) { SetSel2(0, -1, TRUE, FALSE); } CString strSelText(GetSelText()); if (strSelText.IsEmpty()) { return; } CT2A strTextIn(strSelText, GetACP()); CString strTextOut, strMsgOut; CFormatterHelp formatterSP; if (formatterSP.DoFormatter(m_SynLanguage.GetCurLanguage(), strTextIn, strTextOut, strMsgOut)) { SetLastUndoReason(g_dwUATFormatter); DeleteSelectedText (FALSE, FALSE, TRUE); if (!globalData.bIsWindowsVista) //XP的时候 { if (theApp.m_bChangedLang) { strTextOut = CA2T(CT2A(strTextOut), GetACP()); } } InsertText (strTextOut, m_nCurrOffset, FALSE); if (bAllText) { SetSel2(0, 0, FALSE); } else { RedrawWindow (); } } else { if (bAllText) { SetSel2(0, 0, FALSE); } } CChildFrame *pFrame = ((CChildFrame *)((CView *)GetParent())->GetParentFrame()); if (pFrame != NULL) { pFrame->AddOutputMsg(strMsgOut); } }
//returns -1 if code not handled, otherwise returns new insertion pos UInt32 TextInputJournal::ResolveControlCode(UInt8 controlCode, UInt32 insertPos) { if (IsFull()) return -1; UInt32 newPos = insertPos; switch (controlCode) { case DIK_RETURN: //line break newPos = InsertText(insertPos, kTagStrings[kHTMLTag_BR].c_str()); break; case DIK_UP: //move to end of previous line newPos = FindLineStart(insertPos); if (newPos > GetMinPos()) newPos = SeekPosition(newPos, true, true); break; case DIK_DOWN: //move to start of next line newPos = FindLineEnd(insertPos); if (newPos <= GetMaxPos()) newPos = SeekPosition(newPos, false, true); break; case DIK_C: //align center newPos = SetLineStartingTag(insertPos, kHTMLTag_DIV_Center); break; case DIK_L: //align left newPos = SetLineStartingTag(insertPos, kHTMLTag_DIV_Left); break; case DIK_R: //align right newPos = SetLineStartingTag(insertPos, kHTMLTag_DIV_Right); break; case DIK_1: case DIK_2: case DIK_3: case DIK_4: case DIK_5: //Change font { char fontNum = controlCode - DIK_1 + '1'; m_inputText[12] = fontNum; break; } default: newPos = -1; } return newPos; }
bool Movie::SearchText(string textName) { if (!m_texts) { m_texts = make_shared<Texts>(); for (int dlDepth = 0; dlDepth < data->depths; ++dlDepth) { Object *obj = m_displayList[dlDepth].get(); if (obj && obj->IsText()) InsertText(obj->objectId); } } if (m_texts->find(textName) != m_texts->end()) return true; return false; }
BOOL CTextEditor::InsertAtSelection(LPCWSTR psz) { LONG lOldSelEnd = _nSelEnd; if (!RemoveText(_nSelStart, _nSelEnd - _nSelStart)) return FALSE; if (!InsertText(_nSelStart, psz, lstrlen(psz))) return FALSE; _nSelStart += lstrlen(psz); _nSelEnd = _nSelStart; _pTextStore->OnTextChange(_nSelStart, lOldSelEnd, _nSelEnd); _pTextStore->OnSelectionChange(); return TRUE; }
BOOL CTextEditor::InsertResultAtComposition(LPCWSTR psz) { if (!RemoveText(_nCompStart, _nCompEnd - _nCompStart)) return FALSE; if (!InsertText(_nCompStart, psz, lstrlen(psz))) return FALSE; _nSelStart = _nCompStart += lstrlen(psz); _nSelEnd = _nSelStart; _nCompStart = _nSelStart; _nCompEnd = _nSelEnd; ClearAttrAndClauseInfo(); return TRUE; }
void FieldStringEditor::do_xselection_paste(const Event& e) { XDisplay* disp = GetWorld()->display()->rep()->display_; unsigned int win = GetCanvas()->rep()->window_->rep()->xwindow_; Atom target_property = XInternAtom(disp, "PASTESTRING", false); Atom actual_atom; int actual_format; unsigned long ret_length, ret_remaining; unsigned char* data; int ret=XGetWindowProperty(disp, win, target_property, 0L, BUFSIZ, false, XA_STRING, &actual_atom, &actual_format, &ret_length, &ret_remaining, &data); if (ret == Success && data) { InsertText((char*) data, strlen((char*)data)); XFree(data); } }
BOOL CTextEditor::UpdateComposition(LPCWSTR psz, LONG lDeltaStart, LONG lCursorPos, const BYTE *prgAttr, LONG lAttr, const LONG *prgClauseInfo, LONG lClauseInfo) { UINT nDeltaStart = (lDeltaStart >= 0) ? (UINT)lDeltaStart : 0; UINT nCursorPos = (lCursorPos >= 0) ? (UINT)lCursorPos : 0; if (!RemoveText(_nCompStart + nDeltaStart, _nCompEnd - _nCompStart - nDeltaStart)) return FALSE; if (!InsertText(_nCompStart + nDeltaStart, psz + nDeltaStart, lstrlen(psz) - nDeltaStart)) return FALSE; _nCompEnd = _nCompStart + lstrlen(psz); _nSelStart = _nCompStart + nCursorPos; _nSelEnd = _nCompStart + nCursorPos; if (_prgAttr) { LocalFree(_prgAttr); _lAttr = 0; _prgAttr = NULL; } if (_prgClauseInfo) { LocalFree(_prgClauseInfo); _prgClauseInfo = NULL; _lClauseInfo = 0; } _prgAttr = (BYTE *)LocalAlloc(LPTR, lAttr); if (_prgAttr) { memcpy(_prgAttr, prgAttr, lAttr); _lAttr = lAttr / sizeof(BYTE); } _prgClauseInfo = (LONG *)LocalAlloc(LPTR, lClauseInfo); if (_prgClauseInfo) { memcpy(_prgClauseInfo, prgClauseInfo, lClauseInfo); _lClauseInfo = lClauseInfo / sizeof(LONG); } return TRUE; }
bool cbStyledTextCtrl::DoSelectionBraceCompletion(const wxChar& ch) { if (GetLastSelectedText().IsEmpty()) return false; // nothing changed const wxString braces(wxT("([{<'\")]}>'\"")); const int braceAIdx = braces.Find(ch, true); // from end (so caret is placed after quotes) if (braceAIdx == wxNOT_FOUND) return false; // nothing changed const int braceBIdx = (braceAIdx + (braces.Length() / 2)) % braces.Length(); BeginUndoAction(); DeleteBack(); if (braceAIdx < braceBIdx) InsertText(GetCurrentPos(), braces[braceAIdx] + GetLastSelectedText() + braces[braceBIdx]); else AddText(braces[braceBIdx] + GetLastSelectedText() + braces[braceAIdx]); EndUndoAction(); return true; // succeeded }
void DisassemblyTextCtrl::OnGPM(wxMouseEvent& event) { if(platform::gtk == false) // only if GPM is not already implemented by the OS { int pos = PositionFromPoint(wxPoint(event.GetX(), event.GetY())); if(pos == wxSCI_INVALID_POSITION) return; int start = GetSelectionStart(); int end = GetSelectionEnd(); const wxString s = GetSelectedText(); if(pos < GetCurrentPos()) { start += s.length(); end += s.length(); } InsertText(pos, s); SetSelectionVoid(start, end); } } // end of OnGPM
NS_IMETHODIMP mozSpellChecker::Replace(const nsAString &aOldWord, const nsAString &aNewWord, bool aAllOccurrences) { if(!mConverter) return NS_ERROR_NULL_POINTER; nsAutoString newWord(aNewWord); // sigh if(aAllOccurrences){ int32_t selOffset; int32_t startBlock,currentBlock,currOffset; int32_t begin,end; bool done; nsresult result; nsAutoString str; // find out where we are result = SetupDoc(&selOffset); if(NS_FAILED(result)) return result; result = GetCurrentBlockIndex(mTsDoc,&startBlock); if(NS_FAILED(result)) return result; //start at the beginning result = mTsDoc->FirstBlock(); currOffset=0; currentBlock = 0; while( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done ) { result = mTsDoc->GetCurrentTextBlock(&str); do{ result = mConverter->FindNextWord(str.get(),str.Length(),currOffset,&begin,&end); if(NS_SUCCEEDED(result)&&(begin != -1)){ if (aOldWord.Equals(Substring(str, begin, end-begin))) { // if we are before the current selection point but in the same block // move the selection point forwards if((currentBlock == startBlock)&&(begin < selOffset)){ selOffset += int32_t(aNewWord.Length()) - int32_t(aOldWord.Length()); if(selOffset < begin) selOffset=begin; } mTsDoc->SetSelection(begin, end-begin); mTsDoc->InsertText(&newWord); mTsDoc->GetCurrentTextBlock(&str); end += (aNewWord.Length() - aOldWord.Length()); // recursion was cute in GEB, not here. } } currOffset = end; }while(currOffset != -1); mTsDoc->NextBlock(); currentBlock++; currOffset=0; } // We are done replacing. Put the selection point back where we found it (or equivalent); result = mTsDoc->FirstBlock(); currentBlock = 0; while(( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done ) &&(currentBlock < startBlock)){ mTsDoc->NextBlock(); } //After we have moved to the block where the first occurrence of replace was done, put the //selection to the next word following it. In case there is no word following it i.e if it happens //to be the last word in that block, then move to the next block and put the selection to the //first word in that block, otherwise when the Setupdoc() is called, it queries the LastSelectedBlock() //and the selection offset of the last occurrence of the replaced word is taken instead of the first //occurrence and things get messed up as reported in the bug 244969 if( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done ){ nsString str; result = mTsDoc->GetCurrentTextBlock(&str); result = mConverter->FindNextWord(str.get(),str.Length(),selOffset,&begin,&end); if(end == -1) { mTsDoc->NextBlock(); selOffset=0; result = mTsDoc->GetCurrentTextBlock(&str); result = mConverter->FindNextWord(str.get(),str.Length(),selOffset,&begin,&end); mTsDoc->SetSelection(begin, 0); } else mTsDoc->SetSelection(begin, 0); } } else{ mTsDoc->InsertText(&newWord); } return NS_OK; }
bool ctlSQLBox::BlockComment(bool uncomment) { wxString lineEnd; switch (GetEOLMode()) { case wxSTC_EOL_LF: lineEnd = wxT("\n"); break; case wxSTC_EOL_CRLF: lineEnd = wxT("\r\n"); break; case wxSTC_EOL_CR: lineEnd = wxT("\r"); break; } // Save the start position const wxString comment = wxT("-- "); int start = GetSelectionStart(); if (!GetSelectedText().IsEmpty()) { wxString selection = GetSelectedText(); if (!uncomment) { selection.Replace(lineEnd, lineEnd + comment); selection.Prepend(comment); if (selection.EndsWith(comment)) selection = selection.Left(selection.Length() - comment.Length()); } else { selection.Replace(lineEnd + comment, lineEnd); if (selection.StartsWith(comment)) selection = selection.Right(selection.Length() - comment.Length()); } ReplaceSelection(selection); SetSelection(start, start + selection.Length()); } else { // No text selection - (un)comment the current line int column = GetColumn(start); int curLineNum = GetCurrentLine(); int pos = PositionFromLine(curLineNum); if (!uncomment) { InsertText(pos, comment); } else { wxString t = GetTextRange(pos, pos + comment.Length()); if (t == comment) { // The line starts with a comment, so we remove it SetTargetStart(pos); SetTargetEnd(pos + comment.Length()); ReplaceTarget(wxT("")); } else { // The line doesn't start with a comment, do nothing return false; } } if (GetLineCount() > curLineNum) { wxString nextLine = GetLine(curLineNum + 1); if (nextLine.EndsWith(lineEnd)) nextLine = nextLine.Left(nextLine.Length() - lineEnd.Length()); int nextColumn = (nextLine.Length() < (unsigned int)column ? nextLine.Length() : column); GotoPos(PositionFromLine(curLineNum + 1) + nextColumn); } } return true; }
void ctlSQLBox::OnKeyDown(wxKeyEvent &event) { #ifdef __WXGTK__ event.m_metaDown = false; #endif // Get the line ending type wxString lineEnd; switch (GetEOLMode()) { case wxSTC_EOL_LF: lineEnd = wxT("\n"); break; case wxSTC_EOL_CRLF: lineEnd = wxT("\r\n"); break; case wxSTC_EOL_CR: lineEnd = wxT("\r"); break; } // Block comment/uncomment if (event.GetKeyCode() == 'K') { // Comment (Ctrl+k) if (event.GetModifiers() == wxMOD_CONTROL) { if (BlockComment(false)) return; } // Uncomment (Ctrl+Shift+K) else if (event.GetModifiers() == (wxMOD_CONTROL | wxMOD_SHIFT)) { if (BlockComment(true)) return; } } // Autoindent if (m_autoIndent && event.GetKeyCode() == WXK_RETURN) { wxString indent, line; line = GetLine(GetCurrentLine()); // Get the offset for the current line - basically, whether // or not it ends with a \r\n, \n or \r, and if so, the length int offset = 0; if (line.EndsWith(wxT("\r\n"))) offset = 2; else if (line.EndsWith(wxT("\n"))) offset = 1; else if (line.EndsWith(wxT("\r"))) offset = 1; // Get the indent. This is every leading space or tab on the // line, up until the current cursor position. int x = 0; int max = line.Length() - (GetLineEndPosition(GetCurrentLine()) - GetCurrentPos()) - offset; if(line != wxEmptyString) { while ((line[x] == '\t' || line[x] == ' ') && x < max) indent += line[x++]; } // Select any indent in front of the cursor to be removed. If // the cursor is positioned after any non-indent characters, // we don't remove anything. If there is already some selected, // don't select anything new at all. if (indent.Length() != 0 && (unsigned int)GetCurrentPos() <= ((GetLineEndPosition(GetCurrentLine()) - line.Length()) + indent.Length() + offset) && GetSelectedText() == wxEmptyString) SetSelection(GetLineEndPosition(GetCurrentLine()) - line.Length() + offset, GetLineEndPosition(GetCurrentLine()) - line.Length() + indent.Length() + offset); // Lose any selected text. ReplaceSelection(wxEmptyString); // Insert a replacement \n (or whatever), and the indent at the insertion point. InsertText(GetCurrentPos(), lineEnd + indent); // Now, reset the position, and clear the selection SetCurrentPos(GetCurrentPos() + indent.Length() + lineEnd.Length()); SetSelection(GetCurrentPos(), GetCurrentPos()); } else if (m_dlgFindReplace && event.GetKeyCode() == WXK_F3) { m_dlgFindReplace->FindNext(); } else event.Skip(); }
bool ctlSQLBox::DoFind(const wxString &find, const wxString &replace, bool doReplace, bool wholeWord, bool matchCase, bool useRegexps, bool startAtTop, bool reverse) { int flags = 0; int startPos = GetSelectionStart(); int endPos = GetTextLength(); // Setup flags if (wholeWord) flags |= wxSTC_FIND_WHOLEWORD; if (matchCase) flags |= wxSTC_FIND_MATCHCASE; // Replace the current selection, if there is one and it matches the find param. wxString current = GetSelectedText(); if (doReplace) { if (useRegexps) { CharacterRange cr = RegexFindText(GetSelectionStart(), GetSelectionEnd(), find); if (GetSelectionStart() == cr.cpMin && GetSelectionEnd() == cr.cpMax) { if (cr.cpMin == cr.cpMax) // Must be finding a special char, such as $ (line end) { InsertText(cr.cpMax, replace); SetSelection(cr.cpMax, cr.cpMax + replace.Length()); SetCurrentPos(cr.cpMax + replace.Length()); // Stop if we've got to the end. This is important for the $ // case where it'll just keep finding the end of the line!! if ((int)(cr.cpMin + replace.Length()) == GetLength()) return false; } else { ReplaceSelection(replace); SetSelection(startPos, startPos + replace.Length()); SetCurrentPos(startPos + replace.Length()); } } } else if ((matchCase && current == find) || (!matchCase && current.Upper() == find.Upper())) { ReplaceSelection(replace); if (!reverse) { SetSelection(startPos, startPos + replace.Length()); SetCurrentPos(startPos + replace.Length()); } else { SetSelection(startPos + replace.Length(), startPos); SetCurrentPos(startPos); } } } //////////////////////////////////////////////////////////////////////// // Figure out the starting position for the next search //////////////////////////////////////////////////////////////////////// if (startAtTop) { startPos = 0; endPos = GetTextLength(); } else { if (reverse) { endPos = 0; startPos = GetCurrentPos(); } else { endPos = GetTextLength(); startPos = GetCurrentPos(); } } size_t selStart = 0, selEnd = 0; if (useRegexps) { CharacterRange cr = RegexFindText(startPos, endPos, find); selStart = cr.cpMin; selEnd = cr.cpMax; } else { selStart = FindText(startPos, endPos, find, flags); selEnd = selStart + find.Length(); } if (selStart >= 0 && selStart != (size_t)(-1)) { if (reverse) { SetCurrentPos(selStart); SetSelection(selEnd, selStart); } else { SetCurrentPos(selEnd); SetSelection(selStart, selEnd); } EnsureCaretVisible(); return true; } else return false; }
void FindTextView::KeyDown(const char* bytes, int32 numBytes) { if (fMode == kHexMode) { // filter out invalid (for hex mode) characters if (numBytes > 1) return; switch (bytes[0]) { case B_RIGHT_ARROW: case B_LEFT_ARROW: case B_UP_ARROW: case B_DOWN_ARROW: case B_HOME: case B_END: case B_PAGE_UP: case B_PAGE_DOWN: break; case B_BACKSPACE: case B_DELETE: { int32 start, end; GetSelection(&start, &end); if (bytes[0] == B_BACKSPACE && --start < 0) { if (end == 0) return; start = 0; } if (ByteAt(start) == ' ') BTextView::KeyDown(bytes, numBytes); BTextView::KeyDown(bytes, numBytes); if (bytes[0] == B_BACKSPACE) GetSelection(&start, &end); _HexReformat(start, start); Select(start, start); return; } default: { if (!strchr("0123456789abcdefABCDEF", bytes[0])) return; // the original KeyDown() has severe cursor setting // problems with our InsertText(). int32 start, end; GetSelection(&start, &end); InsertText(bytes, 1, start, NULL); return; } } } BTextView::KeyDown(bytes, numBytes); }