예제 #1
0
static void editBoxCallbackFunc(const char* pText, void* ctx)
{
    EditBoxImplWin* thiz = (EditBoxImplWin*)ctx;
    thiz->setText(pText);

    if (thiz->getDelegate() != NULL)
    {
        thiz->getDelegate()->editBoxTextChanged(thiz->getEditBox(), thiz->getText());
        thiz->getDelegate()->editBoxEditingDidEnd(thiz->getEditBox());
        thiz->getDelegate()->editBoxReturn(thiz->getEditBox());
    }
    
    EditBox* pEditBox = thiz->getEditBox();
    if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler())
    {
        CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "changed",pEditBox);
        ScriptEvent event(kCommonEvent,(void*)&data);
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
        memset(data.eventName,0,64*sizeof(char));
        strncpy(data.eventName,"ended",64);
        event.data = (void*)&data;
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
        memset(data.eventName,0,64*sizeof(char));
        strncpy(data.eventName,"return",64);
        event.data = (void*)&data;
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }
}
예제 #2
0
void EditBoxImplWin::openKeyboard()
{
    if (_delegate != NULL)
    {
        _delegate->editBoxEditingDidBegin(_editBox);
    }
    
    EditBox* pEditBox = this->getEditBox();
    if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler())
    {
        CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox);
        ScriptEvent event(kCommonEvent,(void*)&data);
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }
    
	std::string placeHolder = _labelPlaceHolder->getString();
	if (placeHolder.length() == 0)
		placeHolder = "Enter value";

	char pText[100]= {0};
	std::string text = getText();
	if (text.length())
		strncpy(pText, text.c_str(), 100);
	bool didChange = CWin32InputBox::InputBox("Input", placeHolder.c_str(), pText, 100, false) == IDOK;
	
	if (didChange) 	
		setText(pText);

	if (_delegate != NULL) {
		if (didChange)
			_delegate->editBoxTextChanged(_editBox, getText());
		_delegate->editBoxEditingDidEnd(_editBox);
		_delegate->editBoxReturn(_editBox);
	}
}
static void editBoxCallbackFunc(const char* pText, void* ctx)
{
    EditBoxImplAndroid* thiz = (EditBoxImplAndroid*)ctx;
    bool isBack = strlen(pText) == 1 && pText[0] == '\b';
    if(!isBack)
        thiz->setText(pText);
	
    if (thiz->getDelegate() != NULL)
    {
        if(!isBack)
            thiz->getDelegate()->editBoxTextChanged(thiz->getEditBox(), thiz->getText());
        thiz->getDelegate()->editBoxEditingDidEnd(thiz->getEditBox());
        thiz->getDelegate()->editBoxReturn(thiz->getEditBox());
    }
    
#if CC_ENABLE_SCRIPT_BINDING
    EditBox* pEditBox = thiz->getEditBox();
    if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler())
    {        
        CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "changed",pEditBox);
        ScriptEvent event(kCommonEvent,(void*)&data);
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
        memset(data.eventName, 0, sizeof(data.eventName));
        strncpy(data.eventName, "ended", sizeof(data.eventName));
        event.data = (void*)&data;
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
        memset(data.eventName, 0, sizeof(data.eventName));
        strncpy(data.eventName, "return", sizeof(data.eventName));
        event.data = (void*)&data;
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }
#endif
}
예제 #4
0
void EditBoxImplAndroid::openKeyboard()
{
    if (_delegate != NULL)
    {
        _delegate->editBoxEditingDidBegin(_editBox);
    }
    
#if CC_ENABLE_SCRIPT_BINDING
    EditBox* pEditBox = this->getEditBox();
    if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler())
    {        
        CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox);
        ScriptEvent event(cocos2d::kCommonEvent,(void*)&data);
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }
#endif
	
    showEditTextDialogJNI(  _placeHolder.c_str(),
						  _text.c_str(),
						  (int)_editBoxInputMode,
						  (int)_editBoxInputFlag,
						  (int)_keyboardReturnType,
						  _maxLength,
						  editBoxCallbackFunc,
						  (void*)this  );
	
}
void EditBoxImplWin::openKeyboard()
{
    if (_delegate != nullptr)
    {
        _delegate->editBoxEditingDidBegin(_editBox);
    }
    
    EditBox* pEditBox = this->getEditBox();
    if (nullptr != pEditBox && 0 != pEditBox->getScriptEditBoxHandler())
    {
        CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox);
        ScriptEvent event(kCommonEvent,(void*)&data);
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }
    
	std::string placeHolder = _labelPlaceHolder->getString();
	if (placeHolder.length() == 0)
		placeHolder = "Enter value";

	char pText[100]= {0};
	std::string text = getText();
	if (text.length())
		strncpy(pText, text.c_str(), 100);
	GLView *glView = Director::getInstance()->getOpenGLView();
	GLFWwindow *glfwWindow = glView->getWindow();
	HWND hwnd = glfwGetWin32Window(glfwWindow);
	bool didChange = CWin32InputBox::InputBox("Input", placeHolder.c_str(), pText, 100, false, hwnd) == IDOK;
	
	if (didChange) 	
		setText(pText);

	if (_delegate != nullptr) {
		if (didChange)
			_delegate->editBoxTextChanged(_editBox, getText());
		_delegate->editBoxEditingDidEnd(_editBox);
		_delegate->editBoxReturn(_editBox);
	}
    
#if CC_ENABLE_SCRIPT_BINDING
    if (nullptr != _editBox && 0 != _editBox->getScriptEditBoxHandler())
    {
        CommonScriptData data(_editBox->getScriptEditBoxHandler(), "changed",_editBox);
        ScriptEvent event(kCommonEvent,(void*)&data);
        if (didChange)
        {
            ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
        }
        memset(data.eventName,0,sizeof(data.eventName));
        strncpy(data.eventName,"ended",sizeof(data.eventName));
        event.data = (void*)&data;
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
        memset(data.eventName,0,sizeof(data.eventName));
        strncpy(data.eventName,"return",sizeof(data.eventName));
        event.data = (void*)&data;
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }
#endif // #if CC_ENABLE_SCRIPT_BINDING
}
static void editBoxCallbackFunc(const char* pText, void* ctx)
{
    EditBoxImplAndroid* thiz = (EditBoxImplAndroid*)ctx;
    thiz->setText(pText);
	
    if (thiz->getDelegate() != NULL)
    {
        thiz->getDelegate()->editBoxTextChanged(thiz->getEditBox(), thiz->getText());
        thiz->getDelegate()->editBoxEditingDidEnd(thiz->getEditBox());
        thiz->getDelegate()->editBoxReturn(thiz->getEditBox());
    }
    
    EditBox* pEditBox = thiz->getEditBox();
    if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler())
    {
        cocos2d::ScriptEngineProtocol* pEngine = cocos2d::ScriptEngineManager::sharedManager()->getScriptEngine();
        pEngine->executeEvent(pEditBox->getScriptEditBoxHandler(), "changed",pEditBox);
        pEngine->executeEvent(pEditBox->getScriptEditBoxHandler(), "ended",pEditBox);
        pEngine->executeEvent(pEditBox->getScriptEditBoxHandler(), "return",pEditBox);
    }
}
void EditBoxImplAndroid::openKeyboard()
{
    if (_delegate != NULL)
    {
        _delegate->editBoxEditingDidBegin(_editBox);
    }
    EditBox* pEditBox = this->getEditBox();
    if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler())
    {
        cocos2d::ScriptEngineProtocol* pEngine = cocos2d::ScriptEngineManager::sharedManager()->getScriptEngine();
        pEngine->executeEvent(pEditBox->getScriptEditBoxHandler(), "began",pEditBox);
    }
	
    showEditTextDialogJNI(  _placeHolder.c_str(),
						  _text.c_str(),
						  _editBoxInputMode,
						  _editBoxInputFlag,
						  _keyboardReturnType,
						  _maxLength,
						  editBoxCallbackFunc,
						  (void*)this  );
	
}
void EditBoxImplTizen::openKeyboard()
{
    if (s_keypadWin)
    {
        return;
    }

    if (_delegate != NULL)
    {
        _delegate->editBoxEditingDidBegin(_editBox);
    }

#if CC_ENABLE_SCRIPT_BINDING
    EditBox* pEditBox = this->getEditBox();
    if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler())
    {
        CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox);
        ScriptEvent event(cocos2d::kCommonEvent,(void*)&data);
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }
#endif

    Evas_Object* parent = Application::getInstance()->_win;
    GLView* glView = Director::getInstance()->getOpenGLView();
    Size frameSize = glView->getFrameSize();

    s_keypadWin = elm_win_add(parent, "cocos2d-x", ELM_WIN_BASIC);
    elm_win_autodel_set(s_keypadWin, EINA_TRUE);
    elm_win_conformant_set(s_keypadWin, EINA_TRUE);
    elm_win_alpha_set(s_keypadWin, EINA_TRUE);
    evas_object_show(s_keypadWin);
    eext_object_event_callback_add(s_keypadWin, EEXT_CALLBACK_BACK, entry_back_cb, this);
    int rots[2];
    rots[0] = (int)(elm_win_rotation_get(parent));
    rots[1] = rots[0] + 180 % 360;
    elm_win_wm_rotation_available_rotations_set(s_keypadWin, rots, 2);

    Evas_Object* bgFull = elm_bg_add(s_keypadWin);
    evas_object_color_set(bgFull, 0, 0, 0, 0xa0);
    evas_object_resize(bgFull, frameSize.width, frameSize.height);
    evas_object_show(bgFull);

    int height = frameSize.height / 10;
    Evas_Object* rectangle = elm_bg_add(bgFull);
    evas_object_resize(rectangle, frameSize.width, height);
    evas_object_move(rectangle, 0, height);
    evas_object_color_set(rectangle, 0xff, 0xff, 0xff, 0xff);
    evas_object_show(rectangle);

    Evas_Object* title = elm_entry_add(rectangle);
    evas_object_resize(title, frameSize.width, height);
    auto text = _placeHolder.c_str();
    auto richText = (char*)malloc(strlen(text) + 50);
    sprintf(richText,"<color=#ffffff>%s</>", text);
    elm_entry_entry_set(title, richText);
    elm_entry_editable_set(title, EINA_FALSE);
    //elm_entry_drag_disabled_set(title, EINA_TRUE);
    //elm_entry_drop_disabled_set(title, EINA_TRUE);
    evas_object_show(title);
    free(richText);

    Evas_Object* entry = elm_entry_add(bgFull);
    elm_object_focus_set(entry, EINA_TRUE);
    evas_object_resize(entry, frameSize.width, height);
    evas_object_move(entry, 0, height);
    elm_entry_single_line_set(entry, EINA_TRUE);
    elm_entry_line_wrap_set(entry, ELM_WRAP_MIXED);
    elm_entry_entry_set(entry, _text.c_str());
    evas_object_show(entry);
    elm_object_focus_set(entry, EINA_TRUE);
    eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
    Elm_Entry_Filter_Limit_Size limit_size = { 0, };
    limit_size.max_char_count = _maxLength;
    elm_entry_markup_filter_append(entry, elm_entry_filter_limit_size, &limit_size);
    elm_entry_input_panel_return_key_type_set(entry, ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
    elm_entry_prediction_allow_set(entry, EINA_FALSE);

    evas_object_smart_callback_add(entry, "activated", entry_activated_cb, this);

    switch(_editBoxInputFlag)
    {
    case EditBox::InputFlag::PASSWORD:
        elm_entry_password_set(entry, EINA_TRUE);
        elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_EMAIL);
        break;
    case EditBox::InputFlag::SENSITIVE:
        elm_entry_input_hint_set(entry, ELM_INPUT_HINT_SENSITIVE_DATA);
        break;
    case EditBox::InputFlag::INITIAL_CAPS_WORD:
        elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_WORD);
        break;
    case EditBox::InputFlag::INITIAL_CAPS_SENTENCE:
        elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_SENTENCE);
        break;
    case EditBox::InputFlag::INITIAL_CAPS_ALL_CHARACTERS:
        elm_entry_autocapital_type_set(entry, ELM_AUTOCAPITAL_TYPE_ALLCHARACTER);
        break;
    }

    switch(_editBoxInputMode)
    {
    case EditBox::InputMode::ANY:
        break;
    case EditBox::InputMode::EMAIL_ADDRESS:
        elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_EMAIL);
        break;
    case EditBox::InputMode::NUMERIC:
        elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NUMBER);
        break;
    case EditBox::InputMode::PHONE_NUMBER:
        elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_PHONENUMBER);
        break;
    case EditBox::InputMode::URL:
        elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_URL);
        break;
    case EditBox::InputMode::DECIMAL:
        elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_HEX); //fixme?
        break;
    case EditBox::InputMode::SINGLE_LINE:
        break;
    }
}
예제 #9
0
void EditBoxImplTizen::openKeyboard()
{
    if (_delegate != NULL)
    {
        _delegate->editBoxEditingDidBegin(_editBox);
    }
    EditBox* pEditBox = this->getEditBox();
    if (NULL != pEditBox && 0 != pEditBox->getScriptEditBoxHandler())
    {
        CommonScriptData data(pEditBox->getScriptEditBoxHandler(), "began",pEditBox);
        ScriptEvent event(kCommonEvent,(void*)&data);
        ScriptEngineManager::getInstance()->getScriptEngine()->sendEvent(&event);
    }

    KeypadStyle keypadStyle = KEYPAD_STYLE_NORMAL;
    KeypadInputModeCategory keypadCategory = KEYPAD_MODE_ALPHA;
    bool bSingleLineEnabled = false;
    switch (_editBoxInputMode)
    {
    case EditBox::InputMode::ANY:
        keypadStyle = KEYPAD_STYLE_NORMAL;
        break;
    case EditBox::InputMode::EMAIL_ADDRESS:
        keypadStyle = KEYPAD_STYLE_EMAIL;
        break;
    case EditBox::InputMode::NUMERIC:
    case EditBox::InputMode::DECIMAL:
        keypadStyle = KEYPAD_STYLE_NUMBER;
        keypadCategory = KEYPAD_MODE_NUMERIC;
        break;
    case EditBox::InputMode::PHONE_NUMBER:
        keypadStyle = KEYPAD_STYLE_PHONE_NUMBER;
        break;
    case EditBox::InputMode::URL:
        keypadStyle = KEYPAD_STYLE_URL;
        break;
    case EditBox::InputMode::SINGLE_LINE:
        bSingleLineEnabled = true;
        break;
    default:
        keypadStyle = KEYPAD_STYLE_NORMAL;
        break;
    }

    bool bTextPrediction = true;
    switch (_editBoxInputFlag)
    {
    case EditBox::InputFlag::PASSWORD:
        keypadStyle = KEYPAD_STYLE_PASSWORD;
        break;
    case EditBox::InputFlag::SENSITIVE:
        bTextPrediction = false;
        break;
    default:
        break;
    }

    ((OspForm *)OspApplication::GetInstance()->getOspForm())->ShowKeypad(
        _text.c_str(),
        keypadStyle,
        keypadCategory,
        bSingleLineEnabled,
        bTextPrediction,
        _maxLength,
        editBoxCallbackFunc,
        (void*)this);
}