2012-08-15 14:33:56 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2012 James Chen
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CCEditBox.h"
|
2012-08-17 14:29:07 +08:00
|
|
|
#include "CCEditBoxImpl.h"
|
2012-08-15 14:33:56 +08:00
|
|
|
|
|
|
|
NS_CC_EXT_BEGIN
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
EditBox::EditBox(void)
|
2013-06-15 14:03:30 +08:00
|
|
|
: _editBoxImpl(NULL)
|
|
|
|
, _delegate(NULL)
|
2013-07-26 17:45:01 +08:00
|
|
|
, _editBoxInputMode(EditBox::InputMode::SINGLE_LINE)
|
|
|
|
, _editBoxInputFlag(EditBox::InputFlag::INTIAL_CAPS_ALL_CHARACTERS)
|
|
|
|
, _keyboardReturnType(KeyboardReturnType::DEFAULT)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _fontSize(-1)
|
|
|
|
, _placeholderFontSize(-1)
|
2013-07-08 18:11:32 +08:00
|
|
|
, _colText(Color3B::WHITE)
|
|
|
|
, _colPlaceHolder(Color3B::GRAY)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _maxLength(0)
|
|
|
|
, _adjustHeight(0.0f)
|
|
|
|
, _scriptEditBoxHandler(0)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
EditBox::~EditBox(void)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_DELETE(_editBoxImpl);
|
2013-05-24 11:42:27 +08:00
|
|
|
unregisterScriptEditBoxHandler();
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-26 14:37:26 +08:00
|
|
|
void EditBox::touchDownAction(Object *sender, Control::EventType controlEvent)
|
2013-03-12 17:23:12 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->openKeyboard();
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
EditBox* EditBox::create(const Size& size, Scale9Sprite* pNormal9SpriteBg, Scale9Sprite* pPressed9SpriteBg/* = NULL*/, Scale9Sprite* pDisabled9SpriteBg/* = NULL*/)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
EditBox* pRet = new EditBox();
|
2012-08-15 14:33:56 +08:00
|
|
|
|
2012-08-17 14:29:07 +08:00
|
|
|
if (pRet != NULL && pRet->initWithSizeAndBackgroundSprite(size, pNormal9SpriteBg))
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2012-08-17 14:29:07 +08:00
|
|
|
if (pPressed9SpriteBg != NULL)
|
|
|
|
{
|
2013-07-26 14:37:26 +08:00
|
|
|
pRet->setBackgroundSpriteForState(pPressed9SpriteBg, Control::State::HIGH_LIGHTED);
|
2012-08-17 14:29:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pDisabled9SpriteBg != NULL)
|
|
|
|
{
|
2013-07-26 14:37:26 +08:00
|
|
|
pRet->setBackgroundSpriteForState(pDisabled9SpriteBg, Control::State::DISABLED);
|
2012-08-17 14:29:07 +08:00
|
|
|
}
|
2012-08-15 14:33:56 +08:00
|
|
|
pRet->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
bool EditBox::initWithSizeAndBackgroundSprite(const Size& size, Scale9Sprite* pPressed9SpriteBg)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
if (ControlButton::initWithBackgroundSprite(pPressed9SpriteBg))
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl = __createSystemEditBox(this);
|
|
|
|
_editBoxImpl->initWithSize(size);
|
2012-08-15 14:33:56 +08:00
|
|
|
|
2013-03-14 14:29:22 +08:00
|
|
|
this->setZoomOnTouchDown(false);
|
2012-08-15 14:33:56 +08:00
|
|
|
this->setPreferredSize(size);
|
2013-07-12 14:11:55 +08:00
|
|
|
this->setPosition(Point(0, 0));
|
2013-07-26 14:37:26 +08:00
|
|
|
this->addTargetWithActionForControlEvent(this, cccontrol_selector(EditBox::touchDownAction), Control::EventType::TOUCH_UP_INSIDE);
|
2012-08-15 14:33:56 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::setDelegate(EditBoxDelegate* pDelegate)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_delegate = pDelegate;
|
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setDelegate(pDelegate);
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
EditBoxDelegate* EditBox::getDelegate()
|
2013-06-05 14:30:14 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _delegate;
|
2013-06-05 14:30:14 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::setText(const char* pText)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
|
|
|
if (pText != NULL)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_text = pText;
|
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setText(pText);
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
const char* EditBox::getText(void)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
const char* pText = _editBoxImpl->getText();
|
2013-03-12 17:23:12 +08:00
|
|
|
if(pText != NULL)
|
|
|
|
return pText;
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
|
2013-03-12 17:23:12 +08:00
|
|
|
return "";
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::setFont(const char* pFontName, int fontSize)
|
2013-02-20 21:41:08 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_fontName = pFontName;
|
|
|
|
_fontSize = fontSize;
|
2013-02-20 21:41:08 +08:00
|
|
|
if (pFontName != NULL)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editBoxImpl != NULL)
|
2013-02-20 21:41:08 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setFont(pFontName, fontSize);
|
2013-02-20 21:41:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::setFontName(const char* pFontName)
|
2013-04-02 21:31:30 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_fontName = pFontName;
|
|
|
|
if (_editBoxImpl != NULL && _fontSize != -1)
|
2013-04-02 21:31:30 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setFont(pFontName, _fontSize);
|
2013-04-02 21:31:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::setFontSize(int fontSize)
|
2013-04-02 21:31:30 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_fontSize = fontSize;
|
|
|
|
if (_editBoxImpl != NULL && _fontName.length() > 0)
|
2013-04-02 21:31:30 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setFont(_fontName.c_str(), _fontSize);
|
2013-04-02 21:31:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
void EditBox::setFontColor(const Color3B& color)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_colText = color;
|
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setFontColor(color);
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::setPlaceholderFont(const char* pFontName, int fontSize)
|
2013-02-25 14:05:38 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_placeholderFontName = pFontName;
|
|
|
|
_placeholderFontSize = fontSize;
|
2013-02-25 14:05:38 +08:00
|
|
|
if (pFontName != NULL)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editBoxImpl != NULL)
|
2013-02-25 14:05:38 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setPlaceholderFont(pFontName, fontSize);
|
2013-02-25 14:05:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::setPlaceholderFontName(const char* pFontName)
|
2013-04-02 21:31:30 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_placeholderFontName = pFontName;
|
|
|
|
if (_editBoxImpl != NULL && _placeholderFontSize != -1)
|
2013-04-02 21:31:30 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setPlaceholderFont(pFontName, _fontSize);
|
2013-04-02 21:31:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::setPlaceholderFontSize(int fontSize)
|
2013-04-02 21:31:30 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_placeholderFontSize = fontSize;
|
|
|
|
if (_editBoxImpl != NULL && _placeholderFontName.length() > 0)
|
2013-04-02 21:31:30 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setPlaceholderFont(_placeholderFontName.c_str(), _fontSize);
|
2013-04-02 21:31:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
void EditBox::setPlaceholderFontColor(const Color3B& color)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_colText = color;
|
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setPlaceholderFontColor(color);
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::setPlaceHolder(const char* pText)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
|
|
|
if (pText != NULL)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_placeHolder = pText;
|
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setPlaceHolder(pText);
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
const char* EditBox::getPlaceHolder(void)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _placeHolder.c_str();
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 17:45:01 +08:00
|
|
|
void EditBox::setInputMode(EditBox::InputMode inputMode)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxInputMode = inputMode;
|
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setInputMode(inputMode);
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::setMaxLength(int maxLength)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_maxLength = maxLength;
|
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setMaxLength(maxLength);
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
int EditBox::getMaxLength()
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _maxLength;
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 17:45:01 +08:00
|
|
|
void EditBox::setInputFlag(EditBox::InputFlag inputFlag)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxInputFlag = inputFlag;
|
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setInputFlag(inputFlag);
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-26 17:45:01 +08:00
|
|
|
void EditBox::setReturnType(EditBox::KeyboardReturnType returnType)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setReturnType(returnType);
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* override function */
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::setPosition(const Point& pos)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
ControlButton::setPosition(pos);
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setPosition(pos);
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::setVisible(bool visible)
|
2013-03-03 18:58:51 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
ControlButton::setVisible(visible);
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editBoxImpl != NULL)
|
2013-03-03 18:58:51 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setVisible(visible);
|
2013-03-03 18:58:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::setContentSize(const Size& size)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
ControlButton::setContentSize(size);
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setContentSize(size);
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::setAnchorPoint(const Point& anchorPoint)
|
2013-02-20 21:41:08 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
ControlButton::setAnchorPoint(anchorPoint);
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editBoxImpl != NULL)
|
2013-02-20 21:41:08 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->setAnchorPoint(anchorPoint);
|
2013-02-20 21:41:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::visit(void)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
ControlButton::visit();
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->visit();
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::onEnter(void)
|
2013-03-12 17:23:12 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
ControlButton::onEnter();
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editBoxImpl != NULL)
|
2013-03-12 17:23:12 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->onEnter();
|
2013-03-12 17:23:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::onExit(void)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
ControlButton::onExit();
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
|
|
|
// remove system edit control
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->closeKeyboard();
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
static Rect getRect(Node * pNode)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Size contentSize = pNode->getContentSize();
|
2013-07-12 14:30:26 +08:00
|
|
|
Rect rect = Rect(0, 0, contentSize.width, contentSize.height);
|
2013-07-22 14:28:19 +08:00
|
|
|
return RectApplyAffineTransform(rect, pNode->getNodeToWorldTransform());
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::keyboardWillShow(IMEKeyboardNotificationInfo& info)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2012-08-17 14:29:07 +08:00
|
|
|
// CCLOG("CCEditBox::keyboardWillShow");
|
2013-06-20 14:15:53 +08:00
|
|
|
Rect rectTracked = getRect(this);
|
2013-02-20 21:52:49 +08:00
|
|
|
// some adjustment for margin between the keyboard and the edit box.
|
|
|
|
rectTracked.origin.y -= 4;
|
2013-03-14 14:29:22 +08:00
|
|
|
|
2012-08-17 14:29:07 +08:00
|
|
|
// if the keyboard area doesn't intersect with the tracking node area, nothing needs to be done.
|
|
|
|
if (!rectTracked.intersectsRect(info.end))
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2012-08-17 14:29:07 +08:00
|
|
|
CCLOG("needn't to adjust view layout.");
|
2012-08-15 14:33:56 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// assume keyboard at the bottom of screen, calculate the vertical adjustment.
|
2013-06-15 14:03:30 +08:00
|
|
|
_adjustHeight = info.end.getMaxY() - rectTracked.getMinY();
|
|
|
|
// CCLOG("CCEditBox:needAdjustVerticalPosition(%f)", _adjustHeight);
|
2012-08-15 14:33:56 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->doAnimationWhenKeyboardMove(info.duration, _adjustHeight);
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::keyboardDidShow(IMEKeyboardNotificationInfo& info)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-03-12 17:23:12 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::keyboardWillHide(IMEKeyboardNotificationInfo& info)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2012-08-17 14:29:07 +08:00
|
|
|
// CCLOG("CCEditBox::keyboardWillHide");
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editBoxImpl != NULL)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editBoxImpl->doAnimationWhenKeyboardMove(info.duration, -_adjustHeight);
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::keyboardDidHide(IMEKeyboardNotificationInfo& info)
|
2012-08-15 14:33:56 +08:00
|
|
|
{
|
2013-03-12 17:23:12 +08:00
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::registerScriptEditBoxHandler(int handler)
|
2013-05-24 11:42:27 +08:00
|
|
|
{
|
|
|
|
unregisterScriptEditBoxHandler();
|
2013-06-15 14:03:30 +08:00
|
|
|
_scriptEditBoxHandler = handler;
|
2013-05-24 11:42:27 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void EditBox::unregisterScriptEditBoxHandler(void)
|
2013-05-24 11:42:27 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (0 != _scriptEditBoxHandler)
|
2013-05-24 11:42:27 +08:00
|
|
|
{
|
2013-07-22 17:24:54 +08:00
|
|
|
ScriptEngineManager::getInstance()->getScriptEngine()->removeScriptHandler(_scriptEditBoxHandler);
|
2013-06-15 14:03:30 +08:00
|
|
|
_scriptEditBoxHandler = 0;
|
2013-05-24 11:42:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-15 14:33:56 +08:00
|
|
|
|
|
|
|
NS_CC_EXT_END
|