void TextField::setText(const char * text) { reloadScroll(); m_contentView.setText(text); if (isEditing()) { setCursorLocation(draftTextLength()); } }
void HistoryViewCell::setHighlighted(bool highlight) { m_highlighted = highlight; m_inputView.setBackgroundColor(backgroundColor()); m_scrollableOutputView.outputView()->setHighlighted(false); if (isHighlighted()) { if (m_selectedSubviewType == SubviewType::Input) { m_inputView.setBackgroundColor(Palette::Select); } else { m_scrollableOutputView.outputView()->setHighlighted(true); } } reloadScroll(); }
bool TextField::privateHandleEvent(Ion::Events::Event event) { if (Responder::handleEvent(event)) { /* The only event Responder handles is 'Toolbox' displaying. In that case, * the text field is forced into editing mode. */ if (!isEditing()) { setEditing(true); } return true; } if (event == Ion::Events::Left && isEditing() && cursorLocation() > 0) { return setCursorLocation(cursorLocation()-1); } if (event == Ion::Events::ShiftLeft && isEditing()) { return setCursorLocation(0); } if (event == Ion::Events::Right && isEditing() && cursorLocation() < draftTextLength()) { return setCursorLocation(cursorLocation()+1); } if (event == Ion::Events::ShiftRight && isEditing()) { return setCursorLocation(draftTextLength()); } if (isEditing() && textFieldShouldFinishEditing(event)) { char bufferText[ContentView::k_maxBufferSize]; strlcpy(bufferText, m_contentView.textBuffer(), ContentView::k_maxBufferSize); strlcpy(m_contentView.textBuffer(), m_contentView.draftTextBuffer(), m_contentView.bufferSize()); int cursorLoc = cursorLocation(); setEditing(false, m_hasTwoBuffers); if (m_delegate->textFieldDidFinishEditing(this, text(), event)) { /* We allow overscroll to avoid calling layoutSubviews twice because the * content might have changed. */ reloadScroll(true); return true; } /* if the text was refused (textInputDidFinishEditing returned false, we * reset the textfield in the same state as before */ char bufferDraft[ContentView::k_maxBufferSize]; strlcpy(bufferDraft, m_contentView.textBuffer(), ContentView::k_maxBufferSize); setText(bufferText); setEditing(true); setText(bufferDraft); setCursorLocation(cursorLoc); return true; } if (event == Ion::Events::Backspace && isEditing()) { return removeChar(); } if (event == Ion::Events::Back && isEditing()) { setEditing(false); reloadScroll(); m_delegate->textFieldDidAbortEditing(this); return true; } if (event == Ion::Events::Clear && isEditing()) { if (!removeEndOfLine()) { setEditing(true, true); } return true; } if (event == Ion::Events::Copy && !isEditing()) { Clipboard::sharedClipboard()->store(text()); return true; } if (event == Ion::Events::Cut && !isEditing()) { Clipboard::sharedClipboard()->store(text()); setEditing(true, true); return true; } return false; }
void TextField::setEditing(bool isEditing, bool reinitDrafBuffer) { m_contentView.setEditing(isEditing, reinitDrafBuffer); if (reinitDrafBuffer) { reloadScroll(); } }
void HistoryViewCell::reloadCell() { m_scrollableOutputView.outputView()->reloadCell(); layoutSubviews(); reloadScroll(); }