2013-04-30 00:14:11 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
Copyright (c) 2013 Lee, Jae-Hong
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2013-04-30 23:58:33 +08:00
|
|
|
|
|
|
|
#include "CCOspForm.h"
|
|
|
|
#include "CCDirector.h"
|
|
|
|
#include "CCEGLView.h"
|
2013-05-29 21:46:52 +08:00
|
|
|
#include "text_input_node/CCIMEDispatcher.h"
|
2013-05-26 19:40:13 +08:00
|
|
|
#include <FBase.h>
|
|
|
|
#include <FText.h>
|
2013-04-30 23:58:33 +08:00
|
|
|
|
|
|
|
USING_NS_CC;
|
2013-05-26 19:40:13 +08:00
|
|
|
using namespace Tizen::Base;
|
|
|
|
using namespace Tizen::Text;
|
2013-04-30 23:58:33 +08:00
|
|
|
using namespace Tizen::Ui;
|
|
|
|
using namespace Tizen::Ui::Controls;
|
|
|
|
using namespace Tizen::Graphics;
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
OspForm::OspForm()
|
2013-05-26 19:40:13 +08:00
|
|
|
: __pKeypad(null)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _editTextCallback(null)
|
|
|
|
, _ctx(null)
|
2013-05-26 19:40:13 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
OspForm::~OspForm()
|
2013-05-26 19:40:13 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-30 23:58:33 +08:00
|
|
|
result
|
2013-06-20 14:13:12 +08:00
|
|
|
OspForm::OnInitializing(void)
|
2013-04-30 23:58:33 +08:00
|
|
|
{
|
|
|
|
AddTouchEventListener(*this);
|
|
|
|
SetMultipointTouchEnabled(true);
|
|
|
|
|
|
|
|
return E_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2013-05-26 19:40:13 +08:00
|
|
|
result
|
2013-06-20 14:13:12 +08:00
|
|
|
OspForm::OnTerminating(void)
|
2013-05-26 19:40:13 +08:00
|
|
|
{
|
|
|
|
result r = E_SUCCESS;
|
|
|
|
|
2013-05-29 09:52:45 +08:00
|
|
|
if (__pKeypad)
|
|
|
|
__pKeypad->Destroy();
|
2013-05-26 19:40:13 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Director::sharedDirector()->getAccelerometer()->stopSensor();
|
2013-06-19 08:31:34 +08:00
|
|
|
|
2013-05-26 19:40:13 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2013-04-30 23:58:33 +08:00
|
|
|
void
|
2013-06-20 18:20:27 +08:00
|
|
|
OspForm:: OnTouchDoublePressed(const Control& source, const Tizen::Graphics::Point& currentPosition, const TouchEventInfo& touchInfo)
|
2013-04-30 23:58:33 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-20 18:20:27 +08:00
|
|
|
OspForm:: OnTouchFocusIn(const Control& source, const Tizen::Graphics::Point& currentPosition, const TouchEventInfo& touchInfo)
|
2013-04-30 23:58:33 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-20 18:20:27 +08:00
|
|
|
OspForm::OnTouchFocusOut(const Control& source, const Tizen::Graphics::Point& currentPosition, const TouchEventInfo& touchInfo)
|
2013-04-30 23:58:33 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-20 18:20:27 +08:00
|
|
|
OspForm::OnTouchLongPressed(const Control& source, const Tizen::Graphics::Point& currentPosition, const TouchEventInfo& touchInfo)
|
2013-04-30 23:58:33 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-20 18:20:27 +08:00
|
|
|
OspForm::OnTouchMoved(const Control& source, const Tizen::Graphics::Point& currentPosition, const TouchEventInfo& touchInfo)
|
2013-04-30 23:58:33 +08:00
|
|
|
{
|
|
|
|
int id = touchInfo.GetPointId();
|
|
|
|
float x = currentPosition.x;
|
|
|
|
float y = currentPosition.y;
|
2013-06-20 14:13:12 +08:00
|
|
|
Director::sharedDirector()->getOpenGLView()->handleTouchesMove(1, &id, &x, &y);
|
2013-04-30 23:58:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-20 18:20:27 +08:00
|
|
|
OspForm::OnTouchPressed(const Control& source, const Tizen::Graphics::Point& currentPosition, const TouchEventInfo& touchInfo)
|
2013-04-30 23:58:33 +08:00
|
|
|
{
|
|
|
|
int id = touchInfo.GetPointId();
|
|
|
|
float x = currentPosition.x;
|
|
|
|
float y = currentPosition.y;
|
2013-06-20 14:13:12 +08:00
|
|
|
Director::sharedDirector()->getOpenGLView()->handleTouchesBegin(1, &id, &x, &y);
|
2013-04-30 23:58:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-20 18:20:27 +08:00
|
|
|
OspForm::OnTouchReleased(const Control& source, const Tizen::Graphics::Point& currentPosition, const TouchEventInfo& touchInfo)
|
2013-04-30 23:58:33 +08:00
|
|
|
{
|
|
|
|
int id = touchInfo.GetPointId();
|
|
|
|
float x = currentPosition.x;
|
|
|
|
float y = currentPosition.y;
|
2013-06-20 14:13:12 +08:00
|
|
|
Director::sharedDirector()->getOpenGLView()->handleTouchesEnd(1, &id, &x, &y);
|
2013-04-30 23:58:33 +08:00
|
|
|
}
|
2013-05-26 19:40:13 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void OspForm::OnTextValueChanged(const Tizen::Ui::Control& source)
|
2013-05-26 19:40:13 +08:00
|
|
|
{
|
2013-06-20 18:20:27 +08:00
|
|
|
Tizen::Base::String text = __pKeypad->GetText();
|
2013-05-28 19:04:37 +08:00
|
|
|
Utf8Encoding utf8;
|
2013-05-29 09:52:45 +08:00
|
|
|
ByteBuffer* buffer = utf8.GetBytesN(text);
|
2013-05-28 19:04:37 +08:00
|
|
|
const char* pText = "";
|
2013-05-29 09:52:45 +08:00
|
|
|
if (buffer)
|
|
|
|
pText = (const char *)buffer->GetPointer();
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editTextCallback)
|
2013-05-29 21:46:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editTextCallback(pText, _ctx);
|
2013-05-29 21:46:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
const char* pContentText = IMEDispatcher::sharedDispatcher()->getContentText();
|
2013-05-29 21:46:52 +08:00
|
|
|
|
|
|
|
for (unsigned int i = strlen(pContentText); i > 0; i--)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
|
2013-05-29 21:46:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string text("");
|
|
|
|
if (pText != null)
|
|
|
|
{
|
|
|
|
text = pText;
|
|
|
|
if (text.compare("") == 0)
|
|
|
|
{
|
|
|
|
text = "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text.at(text.length() - 1) != '\n')
|
|
|
|
{
|
|
|
|
text += '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
IMEDispatcher::sharedDispatcher()->dispatchInsertText(text.c_str(), text.length());
|
2013-05-29 21:46:52 +08:00
|
|
|
}
|
2013-05-29 09:52:45 +08:00
|
|
|
|
|
|
|
if (buffer)
|
|
|
|
delete buffer;
|
2013-05-26 19:40:13 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void OspForm::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
|
2013-05-26 19:40:13 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_editTextCallback)
|
2013-05-29 21:46:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editTextCallback("", _ctx);
|
2013-05-29 21:46:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
const char* pContentText = IMEDispatcher::sharedDispatcher()->getContentText();
|
2013-05-29 21:46:52 +08:00
|
|
|
|
|
|
|
for (unsigned int i = strlen(pContentText); i > 0; i--)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
IMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
|
2013-05-29 21:46:52 +08:00
|
|
|
}
|
|
|
|
}
|
2013-05-26 19:40:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-20 14:13:12 +08:00
|
|
|
OspForm::ShowKeypad(const char* pMessage, KeypadStyle keypadStyle, KeypadInputModeCategory keypadCategory, bool bSingleLineEnabled, bool bTextPrediction, int nMaxLength, EditTextCallback pfEditTextCallback, void* pCtx)
|
2013-05-26 19:40:13 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_editTextCallback = pfEditTextCallback;
|
|
|
|
_ctx = pCtx;
|
2013-05-26 19:40:13 +08:00
|
|
|
|
|
|
|
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);
|
2013-06-20 18:20:27 +08:00
|
|
|
__pKeypad->SetText(Tizen::Base::String(pMessage));
|
2013-05-26 19:40:13 +08:00
|
|
|
__pKeypad->SetShowState(true);
|
|
|
|
__pKeypad->Show();
|
|
|
|
}
|
|
|
|
|
2013-05-29 21:46:52 +08:00
|
|
|
void
|
2013-06-20 14:13:12 +08:00
|
|
|
OspForm::ShowKeypad()
|
2013-05-29 21:46:52 +08:00
|
|
|
{
|
|
|
|
ShowKeypad(
|
2013-06-20 14:13:12 +08:00
|
|
|
IMEDispatcher::sharedDispatcher()->getContentText(),
|
2013-05-29 21:46:52 +08:00
|
|
|
KEYPAD_STYLE_NORMAL,
|
|
|
|
KEYPAD_MODE_ALPHA,
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
100,
|
|
|
|
null,
|
|
|
|
null);
|
|
|
|
}
|
|
|
|
|
2013-05-26 19:40:13 +08:00
|
|
|
void
|
2013-06-20 14:13:12 +08:00
|
|
|
OspForm::CloseKeypad()
|
2013-05-26 19:40:13 +08:00
|
|
|
{
|
|
|
|
__pKeypad->SetShowState(false);
|
|
|
|
Invalidate(true);
|
|
|
|
}
|
|
|
|
|