fixed a bug: TextInputTextWithAction can't stop CCTextFieldTTF's action when click enter button.

This commit is contained in:
yangws 2011-05-11 18:22:55 +08:00
parent ec27d588a6
commit b8a9db98dc
2 changed files with 25 additions and 19 deletions

View File

@ -179,17 +179,9 @@ void CCTextFieldTTF::insertText(const char * text, int len)
len = nPos;
sInsert.erase(nPos);
}
if (len <= 0)
{
// close keyboard
CCEGLView * pGlView = CCDirector::sharedDirector()->getOpenGLView();
if (pGlView)
{
pGlView->setIMEKeyboardState(false);
}
return;
}
if (len > 0)
{
if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, sInsert.c_str(), len))
{
// delegate doesn't want insert text
@ -202,6 +194,20 @@ void CCTextFieldTTF::insertText(const char * text, int len)
setString(sText.c_str());
}
if (sInsert.npos == nPos) {
return;
}
// '\n' has inserted, let delegate process first
if (m_pDelegate && m_pDelegate->onTextFieldInsertText(this, "\n", 1))
{
return;
}
// if lelegate hasn't process, detach with ime as default
detachWithIME();
}
void CCTextFieldTTF::deleteBackward()
{
int nStrLen = m_pInputText->length();

View File

@ -368,18 +368,18 @@ bool TextFieldTTFActionTest::onTextFieldDetachWithIME(CCTextFieldTTF * pSender)
bool TextFieldTTFActionTest::onTextFieldInsertText(CCTextFieldTTF * pSender, const char * text, int nLen)
{
// if insert enter, treat as default to detach with ime
if ('\n' == *text)
{
return false;
}
// if the textfield's char count more than m_nCharLimit, doesn't insert text anymore.
if (pSender->getCharCount() >= m_nCharLimit)
{
return true;
}
// if insert enter, treat as default
if ('\n' == *text)
{
return false;
}
// create a insert text sprite and do some action
CCLabelTTF * label = CCLabelTTF::labelWithString(text, FONT_NAME, FONT_SIZE);
this->addChild(label);