2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 cocos2d-x.org
|
|
|
|
|
|
|
|
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 "CCKeypadDelegate.h"
|
|
|
|
#include "ccMacros.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2010-12-13 14:10:39 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
// KeypadHandler
|
2010-12-13 14:10:39 +08:00
|
|
|
//
|
2012-04-19 14:35:52 +08:00
|
|
|
//------------------------------------------------------------------
|
2013-06-20 14:13:12 +08:00
|
|
|
KeypadDelegate* KeypadHandler::getDelegate()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _delegate;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
KeypadHandler::~KeypadHandler()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_delegate)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
dynamic_cast<Object*>(_delegate)->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void KeypadHandler::setDelegate(KeypadDelegate *pDelegate)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
if (pDelegate)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
dynamic_cast<Object*>(pDelegate)->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_delegate)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
dynamic_cast<Object*>(_delegate)->release();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
_delegate = pDelegate;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool KeypadHandler::initWithDelegate(KeypadDelegate *pDelegate)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(pDelegate != NULL, "It's a wrong delegate!");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_delegate = pDelegate;
|
2013-06-20 14:13:12 +08:00
|
|
|
dynamic_cast<Object*>(pDelegate)->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
KeypadHandler* KeypadHandler::handlerWithDelegate(KeypadDelegate *pDelegate)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
KeypadHandler* pHandler = new KeypadHandler;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
if (pHandler)
|
|
|
|
{
|
|
|
|
if (pHandler->initWithDelegate(pDelegate))
|
|
|
|
{
|
|
|
|
pHandler->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE_NULL(pHandler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_END
|