Skip to content

Commit 9949a3e

Browse files
author
Lee, Jae-Hong
committed
Implement CCEditBox for Tizen. (develop branch)
1 parent e7912bd commit 9949a3e

File tree

5 files changed

+191
-53
lines changed

5 files changed

+191
-53
lines changed

cocos2dx/platform/tizen/CCOspForm.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,27 @@ THE SOFTWARE.
2626
#include "CCOspForm.h"
2727
#include "CCDirector.h"
2828
#include "CCEGLView.h"
29+
#include <FBase.h>
30+
#include <FText.h>
2931

3032
USING_NS_CC;
33+
using namespace Tizen::Base;
34+
using namespace Tizen::Text;
3135
using namespace Tizen::Ui;
3236
using namespace Tizen::Ui::Controls;
3337
using namespace Tizen::Graphics;
3438

39+
CCOspForm::CCOspForm()
40+
: __pKeypad(null)
41+
, m_pfEditTextCallback(null)
42+
, m_pCtx(null)
43+
{
44+
}
45+
46+
CCOspForm::~CCOspForm()
47+
{
48+
}
49+
3550
result
3651
CCOspForm::OnInitializing(void)
3752
{
@@ -41,6 +56,16 @@ CCOspForm::OnInitializing(void)
4156
return E_SUCCESS;
4257
}
4358

59+
result
60+
CCOspForm::OnTerminating(void)
61+
{
62+
result r = E_SUCCESS;
63+
64+
__pKeypad->Destroy();
65+
66+
return r;
67+
}
68+
4469
void
4570
CCOspForm:: OnTouchDoublePressed(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
4671
{
@@ -87,3 +112,51 @@ CCOspForm::OnTouchReleased(const Control& source, const Point& currentPosition,
87112
float y = currentPosition.y;
88113
CCDirector::sharedDirector()->getOpenGLView()->handleTouchesEnd(1, &id, &x, &y);
89114
}
115+
116+
void CCOspForm::OnTextValueChanged(const Tizen::Ui::Control& source)
117+
{
118+
String text = __pKeypad->GetText();
119+
AsciiEncoding ascii;
120+
m_pfEditTextCallback((const char *)ascii.GetBytesN(text)->GetPointer(), m_pCtx);
121+
}
122+
123+
void CCOspForm::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
124+
{
125+
m_pfEditTextCallback("", m_pCtx);
126+
}
127+
128+
void
129+
CCOspForm::ShowKeypad(KeypadStyle keypadStyle, KeypadInputModeCategory keypadCategory, bool bSingleLineEnabled, bool bTextPrediction, int nMaxLength, EditTextCallback pfEditTextCallback, void* pCtx)
130+
{
131+
m_pfEditTextCallback = pfEditTextCallback;
132+
m_pCtx = pCtx;
133+
134+
if (__pKeypad)
135+
{
136+
__pKeypad->RemoveTextEventListener(*this);
137+
__pKeypad->Destroy();
138+
__pKeypad = null;
139+
}
140+
141+
if (nMaxLength > 100)
142+
nMaxLength = 100;
143+
else if (nMaxLength == -1)
144+
nMaxLength = 100;
145+
146+
__pKeypad = new Keypad();
147+
__pKeypad->Construct(keypadStyle, keypadCategory, nMaxLength);
148+
__pKeypad->AddTextEventListener(*this);
149+
150+
__pKeypad->SetTextPredictionEnabled(bTextPrediction);
151+
__pKeypad->SetSingleLineEnabled(bSingleLineEnabled);
152+
__pKeypad->SetShowState(true);
153+
__pKeypad->Show();
154+
}
155+
156+
void
157+
CCOspForm::CloseKeypad()
158+
{
159+
__pKeypad->SetShowState(false);
160+
Invalidate(true);
161+
}
162+

cocos2dx/platform/tizen/CCOspForm.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,37 @@ THE SOFTWARE.
2929
#include <FBase.h>
3030
#include <FUi.h>
3131

32+
typedef void (*EditTextCallback)(const char* pText, void* ctx);
33+
3234
class CCOspForm
3335
: public Tizen::Ui::Controls::Form
3436
, public Tizen::Ui::ITouchEventListener
37+
, public Tizen::Ui::ITextEventListener
3538
{
3639
public:
40+
CCOspForm();
41+
~CCOspForm();
42+
3743
virtual result OnInitializing(void);
44+
virtual result OnTerminating(void);
3845
virtual void OnTouchDoublePressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
3946
virtual void OnTouchFocusIn(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
4047
virtual void OnTouchFocusOut(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
4148
virtual void OnTouchLongPressed (const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
4249
virtual void OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
4350
virtual void OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
4451
virtual void OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo);
52+
53+
// ITextEventListener
54+
virtual void OnTextValueChanged(const Tizen::Ui::Control& source);
55+
virtual void OnTextValueChangeCanceled(const Tizen::Ui::Control& source);
56+
57+
void ShowKeypad(Tizen::Ui::Controls::KeypadStyle keypadStyle, Tizen::Ui::Controls::KeypadInputModeCategory keypadCategory, bool bSingleLineEnabled, bool bTextPrediction, int nMaxLength, EditTextCallback pfEditTextCallback, void* pCtx);
58+
void CloseKeypad();
59+
60+
Tizen::Ui::Controls::Keypad*__pKeypad;
61+
EditTextCallback m_pfEditTextCallback;
62+
void* m_pCtx;
4563
};
4664

4765
#endif // _CCOSPFORM_H_

0 commit comments

Comments
 (0)