Implement CCEditBox for Tizen. (develop branch)

This commit is contained in:
Lee, Jae-Hong 2013-05-26 20:40:13 +09:00
parent 44e1382b9a
commit 47fac0ed98
5 changed files with 191 additions and 53 deletions

View File

@ -26,12 +26,27 @@ THE SOFTWARE.
#include "CCOspForm.h"
#include "CCDirector.h"
#include "CCEGLView.h"
#include <FBase.h>
#include <FText.h>
USING_NS_CC;
using namespace Tizen::Base;
using namespace Tizen::Text;
using namespace Tizen::Ui;
using namespace Tizen::Ui::Controls;
using namespace Tizen::Graphics;
CCOspForm::CCOspForm()
: __pKeypad(null)
, m_pfEditTextCallback(null)
, m_pCtx(null)
{
}
CCOspForm::~CCOspForm()
{
}
result
CCOspForm::OnInitializing(void)
{
@ -41,6 +56,16 @@ CCOspForm::OnInitializing(void)
return E_SUCCESS;
}
result
CCOspForm::OnTerminating(void)
{
result r = E_SUCCESS;
__pKeypad->Destroy();
return r;
}
void
CCOspForm:: OnTouchDoublePressed(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
{
@ -87,3 +112,51 @@ CCOspForm::OnTouchReleased(const Control& source, const Point& currentPosition,
float y = currentPosition.y;
CCDirector::sharedDirector()->getOpenGLView()->handleTouchesEnd(1, &id, &x, &y);
}
void CCOspForm::OnTextValueChanged(const Tizen::Ui::Control& source)
{
String text = __pKeypad->GetText();
AsciiEncoding ascii;
m_pfEditTextCallback((const char *)ascii.GetBytesN(text)->GetPointer(), m_pCtx);
}
void CCOspForm::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
{
m_pfEditTextCallback("", m_pCtx);
}
void
CCOspForm::ShowKeypad(KeypadStyle keypadStyle, KeypadInputModeCategory keypadCategory, bool bSingleLineEnabled, bool bTextPrediction, int nMaxLength, EditTextCallback pfEditTextCallback, void* pCtx)
{
m_pfEditTextCallback = pfEditTextCallback;
m_pCtx = pCtx;
if (__pKeypad)
{
__pKeypad->RemoveTextEventListener(*this);
__pKeypad->Destroy();
__pKeypad = null;
}
if (nMaxLength > 100)
nMaxLength = 100;
else if (nMaxLength == -1)
nMaxLength = 100;
__pKeypad = new Keypad();
__pKeypad->Construct(keypadStyle, keypadCategory, nMaxLength);
__pKeypad->AddTextEventListener(*this);
__pKeypad->SetTextPredictionEnabled(bTextPrediction);
__pKeypad->SetSingleLineEnabled(bSingleLineEnabled);
__pKeypad->SetShowState(true);
__pKeypad->Show();
}
void
CCOspForm::CloseKeypad()
{
__pKeypad->SetShowState(false);
Invalidate(true);
}

View File

@ -29,12 +29,19 @@ THE SOFTWARE.
#include <FBase.h>
#include <FUi.h>
typedef void (*EditTextCallback)(const char* pText, void* ctx);
class CCOspForm
: public Tizen::Ui::Controls::Form
, public Tizen::Ui::ITouchEventListener
, public Tizen::Ui::ITextEventListener
{
public:
CCOspForm();
~CCOspForm();
virtual result OnInitializing(void);
virtual result OnTerminating(void);
virtual void OnTouchDoublePressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
virtual void OnTouchFocusIn(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
virtual void OnTouchFocusOut(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
@ -42,6 +49,17 @@ public:
virtual void OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
virtual void OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
virtual void OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
// ITextEventListener
virtual void OnTextValueChanged(const Tizen::Ui::Control& source);
virtual void OnTextValueChangeCanceled(const Tizen::Ui::Control& source);
void ShowKeypad(Tizen::Ui::Controls::KeypadStyle keypadStyle, Tizen::Ui::Controls::KeypadInputModeCategory keypadCategory, bool bSingleLineEnabled, bool bTextPrediction, int nMaxLength, EditTextCallback pfEditTextCallback, void* pCtx);
void CloseKeypad();
Tizen::Ui::Controls::Keypad*__pKeypad;
EditTextCallback m_pfEditTextCallback;
void* m_pCtx;
};
#endif // _CCOSPFORM_H_

View File

@ -1,6 +1,7 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2012 James Chen
Copyright (c) 2013 Lee, Jae-Hong
http://www.cocos2d-x.org
@ -28,7 +29,9 @@
#if (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
#include "CCEditBox.h"
#include "platform/tizen/CCOspForm.h"
using namespace Tizen::Ui::Controls;
NS_CC_EXT_BEGIN
@ -48,17 +51,14 @@ CCEditBoxImplTizen::CCEditBoxImplTizen(CCEditBox* pEditText)
, m_colPlaceHolder(ccGRAY)
, m_nMaxLength(-1)
{
}
CCEditBoxImplTizen::~CCEditBoxImplTizen()
{
}
void CCEditBoxImplTizen::doAnimationWhenKeyboardMove(float duration, float distance)
{
}
static const int CC_EDIT_BOX_PADDING = 5;
@ -67,35 +67,35 @@ bool CCEditBoxImplTizen::initWithSize(const CCSize& size)
{
int fontSize = (int)size.height-12;
m_pLabel = CCLabelTTF::create("", "", size.height-12);
// align the text vertically center
// align the text vertically center
m_pLabel->setAnchorPoint(ccp(0, 0.5f));
m_pLabel->setPosition(ccp(CC_EDIT_BOX_PADDING, size.height / 2.0f));
m_pLabel->setColor(m_colText);
m_pEditBox->addChild(m_pLabel);
m_pLabelPlaceHolder = CCLabelTTF::create("", "", size.height-12);
// align the text vertically center
// align the text vertically center
m_pLabelPlaceHolder->setAnchorPoint(ccp(0, 0.5f));
m_pLabelPlaceHolder->setPosition(ccp(CC_EDIT_BOX_PADDING, size.height / 2.0f));
m_pLabelPlaceHolder->setVisible(false);
m_pLabelPlaceHolder->setColor(m_colPlaceHolder);
m_pEditBox->addChild(m_pLabelPlaceHolder);
m_EditSize = size;
return true;
}
void CCEditBoxImplTizen::setFont(const char* pFontName, int fontSize)
{
if(m_pLabel != NULL) {
m_pLabel->setFontName(pFontName);
m_pLabel->setFontSize(fontSize);
}
if(m_pLabelPlaceHolder != NULL) {
m_pLabelPlaceHolder->setFontName(pFontName);
m_pLabelPlaceHolder->setFontSize(fontSize);
}
if(m_pLabel != NULL) {
m_pLabel->setFontName(pFontName);
m_pLabel->setFontSize(fontSize);
}
if(m_pLabelPlaceHolder != NULL) {
m_pLabelPlaceHolder->setFontName(pFontName);
m_pLabelPlaceHolder->setFontSize(fontSize);
}
}
void CCEditBoxImplTizen::setFontColor(const ccColor3B& color)
@ -106,10 +106,10 @@ void CCEditBoxImplTizen::setFontColor(const ccColor3B& color)
void CCEditBoxImplTizen::setPlaceholderFont(const char* pFontName, int fontSize)
{
if(m_pLabelPlaceHolder != NULL) {
m_pLabelPlaceHolder->setFontName(pFontName);
m_pLabelPlaceHolder->setFontSize(fontSize);
}
if(m_pLabelPlaceHolder != NULL) {
m_pLabelPlaceHolder->setFontName(pFontName);
m_pLabelPlaceHolder->setFontSize(fontSize);
}
}
void CCEditBoxImplTizen::setPlaceholderFontColor(const ccColor3B& color)
@ -153,19 +153,19 @@ void CCEditBoxImplTizen::setText(const char* pText)
if (pText != NULL)
{
m_strText = pText;
if (m_strText.length() > 0)
{
m_pLabelPlaceHolder->setVisible(false);
std::string strToShow;
if (kEditBoxInputFlagPassword == m_eEditBoxInputFlag)
{
long length = cc_utf8_strlen(m_strText.c_str(), -1);
for (long i = 0; i < length; i++)
{
strToShow.append("\u25CF");
strToShow.append("*");
}
}
else
@ -173,15 +173,15 @@ void CCEditBoxImplTizen::setText(const char* pText)
strToShow = m_strText;
}
m_pLabel->setString(strToShow.c_str());
m_pLabel->setString(strToShow.c_str());
// Clip the text width to fit to the text box
float fMaxWidth = m_EditSize.width - CC_EDIT_BOX_PADDING * 2;
CCRect clippingRect = m_pLabel->getTextureRect();
if(clippingRect.size.width > fMaxWidth) {
clippingRect.size.width = fMaxWidth;
m_pLabel->setTextureRect(clippingRect);
}
// Clip the text width to fit to the text box
float fMaxWidth = m_EditSize.width - CC_EDIT_BOX_PADDING * 2;
CCRect clippingRect = m_pLabel->getTextureRect();
if(clippingRect.size.width > fMaxWidth) {
clippingRect.size.width = fMaxWidth;
m_pLabel->setTextureRect(clippingRect);
}
}
else
@ -189,7 +189,7 @@ void CCEditBoxImplTizen::setText(const char* pText)
m_pLabelPlaceHolder->setVisible(true);
m_pLabel->setString("");
}
}
}
@ -207,46 +207,40 @@ void CCEditBoxImplTizen::setPlaceHolder(const char* pText)
{
m_pLabelPlaceHolder->setVisible(true);
}
m_pLabelPlaceHolder->setString(m_strPlaceHolder.c_str());
}
}
void CCEditBoxImplTizen::setPosition(const CCPoint& pos)
{
}
void CCEditBoxImplTizen::setVisible(bool visible)
{
}
void CCEditBoxImplTizen::setContentSize(const CCSize& size)
{
}
void CCEditBoxImplTizen::setAnchorPoint(const CCPoint& anchorPoint)
{
}
void CCEditBoxImplTizen::visit(void)
{
}
void CCEditBoxImplTizen::onEnter(void)
{
}
static void editBoxCallbackFunc(const char* pText, void* ctx)
{
CCEditBoxImplTizen* thiz = (CCEditBoxImplTizen*)ctx;
thiz->setText(pText);
if (thiz->getDelegate() != NULL)
{
thiz->getDelegate()->editBoxTextChanged(thiz->getCCEditBox(), thiz->getText());
@ -276,11 +270,63 @@ void CCEditBoxImplTizen::openKeyboard()
cocos2d::CCScriptEngineProtocol* pEngine = cocos2d::CCScriptEngineManager::sharedManager()->getScriptEngine();
pEngine->executeEvent(pEditBox->getScriptEditBoxHandler(), "began",pEditBox);
}
KeypadStyle keypadStyle = KEYPAD_STYLE_NORMAL;
KeypadInputModeCategory keypadCategory = KEYPAD_MODE_ALPHA;
bool bSingleLineEnabled = false;
switch (m_eEditBoxInputMode)
{
case kEditBoxInputModeAny:
keypadStyle = KEYPAD_STYLE_NORMAL;
break;
case kEditBoxInputModeEmailAddr:
keypadStyle = KEYPAD_STYLE_EMAIL;
break;
case kEditBoxInputModeNumeric:
case kEditBoxInputModeDecimal:
keypadStyle = KEYPAD_STYLE_NUMBER;
keypadCategory = KEYPAD_MODE_NUMERIC;
break;
case kEditBoxInputModePhoneNumber:
keypadStyle = KEYPAD_STYLE_PHONE_NUMBER;
break;
case kEditBoxInputModeUrl:
keypadStyle = KEYPAD_STYLE_URL;
break;
case kEditBoxInputModeSingleLine:
bSingleLineEnabled = true;
break;
default:
keypadStyle = KEYPAD_STYLE_NORMAL;
break;
}
bool bTextPrediction = true;
switch (m_eEditBoxInputFlag)
{
case kEditBoxInputFlagPassword:
keypadStyle = KEYPAD_STYLE_PASSWORD;
break;
case kEditBoxInputFlagSensitive:
bTextPrediction = false;
break;
default:
break;
}
((CCOspForm *)CCOspApplication::GetInstance()->getCCOspForm())->ShowKeypad(
keypadStyle,
keypadCategory,
bSingleLineEnabled,
bTextPrediction,
m_nMaxLength,
editBoxCallbackFunc,
(void*)this);
}
void CCEditBoxImplTizen::closeKeyboard()
{
((CCOspForm *)CCOspApplication::GetInstance()->getCCOspForm())->CloseKeypad();
}
NS_CC_EXT_END

View File

@ -1,6 +1,7 @@
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2012 James Chen
Copyright (c) 2013 Lee, Jae-Hong
http://www.cocos2d-x.org
@ -42,7 +43,7 @@ class CCEditBoxImplTizen : public CCEditBoxImpl
public:
CCEditBoxImplTizen(CCEditBox* pEditText);
virtual ~CCEditBoxImplTizen();
virtual bool initWithSize(const CCSize& size);
virtual void setFont(const char* pFontName, int fontSize);
virtual void setFontColor(const ccColor3B& color);
@ -54,30 +55,30 @@ public:
virtual int getMaxLength();
virtual void setReturnType(KeyboardReturnType returnType);
virtual bool isEditing();
virtual void setText(const char* pText);
virtual const char* getText(void);
virtual void setPlaceHolder(const char* pText);
virtual void setPosition(const CCPoint& pos);
virtual void setVisible(bool visible);
virtual void setContentSize(const CCSize& size);
virtual void setAnchorPoint(const CCPoint& anchorPoint);
virtual void setAnchorPoint(const CCPoint& anchorPoint);
virtual void visit(void);
virtual void onEnter(void);
virtual void onEnter(void);
virtual void doAnimationWhenKeyboardMove(float duration, float distance);
virtual void openKeyboard();
virtual void closeKeyboard();
private:
CCLabelTTF* m_pLabel;
CCLabelTTF* m_pLabelPlaceHolder;
EditBoxInputMode m_eEditBoxInputMode;
EditBoxInputFlag m_eEditBoxInputFlag;
KeyboardReturnType m_eKeyboardReturnType;
std::string m_strText;
std::string m_strPlaceHolder;
ccColor3B m_colText;
ccColor3B m_colPlaceHolder;

View File

@ -8,7 +8,7 @@
#endif
#include "TableViewTest/TableViewTestScene.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
#include "EditBoxTest/EditBoxTest.h"
#endif
@ -24,7 +24,7 @@ enum
TEST_CCCONTROLBUTTON,
TEST_COCOSBUILDER,
TEST_HTTPCLIENT,
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
TEST_EDITBOX,
#endif
TEST_TABLEVIEW,
@ -39,7 +39,7 @@ static const std::string testsName[TEST_MAX_COUNT] =
#if (CC_TARGET_PLATFORM != CC_PLATFORM_EMSCRIPTEN)
"HttpClientTest",
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
"EditBoxTest",
#endif
"TableViewTest"
@ -109,7 +109,7 @@ void ExtensionsMainLayer::menuCallback(CCObject* pSender)
}
break;
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN)
case TEST_EDITBOX:
{
runEditBoxTest();