Files
Upsilon/escher/src/input_view_controller.cpp
Émilie Feral 75948af80f [escher] in text field, reinit the draft text buffer when changing the editing state
Change-Id: I595a9abac3ee593556ec37df9c7065a06f3c856c
2016-12-15 13:51:41 +01:00

63 lines
2.1 KiB
C++

#include <escher/input_view_controller.h>
#include <escher/app.h>
#include <assert.h>
InputViewController::TextFieldController::TextFieldController(Responder * parentResponder, TextFieldDelegate * textFieldDelegate) :
ViewController(parentResponder),
m_textField(parentResponder, m_textBody, m_textBody, 255, textFieldDelegate)
{
m_textBody[0] = 0;
}
View * InputViewController::TextFieldController::view() {
return &m_textField;
}
void InputViewController::TextFieldController::didBecomeFirstResponder() {
app()->setFirstResponder(&m_textField);
}
TextField * InputViewController::TextFieldController::textField() {
return &m_textField;
}
InputViewController::InputViewController(Responder * parentResponder, ViewController * child, TextFieldDelegate * textFieldDelegate) :
ModalViewController(parentResponder, child),
m_textFieldController(TextFieldController(this, this)),
m_successAction(Invocation(nullptr, nullptr)),
m_failureAction(Invocation(nullptr, nullptr)),
m_textFieldDelegate(textFieldDelegate)
{
}
const char * InputViewController::title() const {
return "InputViewController";
}
const char * InputViewController::textBody() {
return m_textFieldController.textField()->text();
}
void InputViewController::edit(Responder * caller, Ion::Events::Event event, void * context, Invocation::Action successAction, Invocation::Action failureAction) {
m_successAction = Invocation(successAction, context);
m_failureAction = Invocation(failureAction, context);
m_textFieldController.textField()->handleEvent(event);
displayModalViewController(&m_textFieldController, 1.0f, 1.0f);
}
bool InputViewController::textFieldDidFinishEditing(TextField * textField, const char * text) {
m_successAction.perform(this);
dismissModalViewController();
return true;
}
bool InputViewController::textFieldDidAbortEditing(TextField * textField, const char * text) {
m_failureAction.perform(this);
dismissModalViewController();
return true;
}
bool InputViewController::textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) {
return m_textFieldDelegate->textFieldDidReceiveEvent(textField, event);
}