Beispiel #1
0
void UICCTextField::insertText(const char*  text, size_t len)
{
    std::string input_text = text;
    if (strcmp(text, "\n") != 0)
    {
        if (_maxLengthEnabled)
        {
            long text_count = StringUtils::getCharacterCountInUTF8String(getString());
            if (text_count >= _maxLength)
            {
                // password
                if (_passwordEnabled)
                {
                    setPasswordText(getString().c_str());
                }
                return;
            }
            long input_count = StringUtils::getCharacterCountInUTF8String(text);
//            CCLOG("UICCTextField text=%s  len=%d\n",text,(int)len);
//            CCLOG("UICCTextField text len=%d  input_count=%ld\n",(int)strlen(text), input_count);
            if ((len*1.0/input_count)>3.0)
            {
                cocos2d::MessageBox("大哥,请勿输入表情符!!!","严重警告");
                return;
            }
            long total = text_count + input_count;
            if (total > _maxLength)
            {
                long length = _maxLength - text_count;
                input_text = Helper::getSubStringOfUTF8String(input_text, 0, length);
                len  = input_text.length();
            }
        }
    }
    TextFieldTTF::insertText(input_text.c_str(), len);
    // password
    if (_passwordEnabled)
    {
        if (TextFieldTTF::getCharCount() > 0)
        {
            setPasswordText(getString().c_str());
        }
    }
}
Beispiel #2
0
void UICCTextField::insertText(const char*  text, size_t len)
{
    std::string input_text = text;
    
    if (strcmp(text, "\n") != 0)
    {
        if (_maxLengthEnabled)
        {
            long text_count = StringUtils::getCharacterCountInUTF8String(getString());
            if (text_count >= _maxLength)
            {
                // password
                if (this->isSecureTextEntry())
                {
                    setPasswordText(getString());
                }
                return;
            }
            
            long input_count = StringUtils::getCharacterCountInUTF8String(text);
            long total = text_count + input_count;
            
            if (total > _maxLength)
            {
                long length = _maxLength - text_count;
                
                input_text = Helper::getSubStringOfUTF8String(input_text, 0, length);
                len  = input_text.length();
            }
        }
    }
    TextFieldTTF::insertText(input_text.c_str(), len);
    
    // password
    if (this->isSecureTextEntry())
    {
        if (TextFieldTTF::getCharCount() > 0)
        {
            setPasswordText(getString());
        }
    }
}
Beispiel #3
0
void UICCTextField::deleteBackward()
{
    TextFieldTTF::deleteBackward();
    
    if (TextFieldTTF::getCharCount() > 0)
    {
        // password
        if (this->isSecureTextEntry())
        {
            setPasswordText(_inputText);
        }
    }
}
Beispiel #4
0
void UICCTextField::deleteBackward()
{
    TextFieldTTF::deleteBackward();
    
    if (TextFieldTTF::getCharCount() > 0)
    {
        // password
        if (_passwordEnabled)
        {
            setPasswordText(_inputText.c_str());
        }
    }
}
Beispiel #5
0
void UICCTextField::deleteBackward()
{
    CCTextFieldTTF::deleteBackward();
    
    if (CCTextFieldTTF::getCharCount() > 0)
    {
        // password
        if (m_bPasswordEnabled)
        {
            setPasswordText(m_pInputText->c_str());
        }
    }
}
Beispiel #6
0
void UICCTextField::insertText(const char * text, int len)
{
    std::string str_text = text;
    ssize_t str_len = TextFieldTTF::getString().size();
    
    if (strcmp(text, "\n") != 0)
    {
        if (_maxLengthEnabled)
        {
            int multiple = 1;
            char value = text[0];
            if (value < 0 || value > 127)
            {
                multiple = 3;
            }
            
            if (str_len + len > _maxLength * multiple)
            {
                str_text = str_text.substr(0, _maxLength * multiple);
                len = _maxLength * multiple;
                /*
                 int mod = str_len % 3;
                 int offset = (mod == 0) ? 0 : (3 - mod);
                 int amount = str_len + offset;
                 str_text = str_text.substr(0, _maxLength - amount);
                 //                CCLOG("str_test = %s", str_text.c_str());
                 */
            }
        }
    }
    TextFieldTTF::insertText(str_text.c_str(), len);
    
    // password
    if (_passwordEnabled)
    {
        if (TextFieldTTF::getCharCount() > 0)
        {
            setPasswordText(_inputText.c_str());
        }
    }
}
Beispiel #7
0
void UICCTextField::insertText(const char * text, int len)
{
    std::string input_text = text;
    
    if (strcmp(text, "\n") != 0)
    {
        if (_maxLengthEnabled)
        {
            int text_count = _calcCharCount(getString().c_str());
            if (text_count >= _maxLength)
            {
                // password
                if (_passwordEnabled)
                {
                    setPasswordText(getString().c_str());
                }
                return;
            }
            
#if ((CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32))
            int input_count = _calcCharCount(text);
            int total = total = text_count + input_count;
            
            if (total > _maxLength)
            {
                int end = 0;
                int length = _maxLength - text_count;
                
                for (int i = 0; i < length; ++i)
                {
                    char value = text[i];
                    
                    if (value >= 0 && value <= 127) // ascii
                    {
                        end++;
                    }
                    else
                    {
                        end += 3;
                    }
                }
                input_text = input_text.substr(0, end);
                len  = end;
            }
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
            int input_count = _calcCharCount(text);
            if (input_count > _maxLength)
            {
                int ascii = 0;
                int unicode = 0;
                int end = 0;
                int count = 0;
                
                for (int i = 0; i < input_count * 3; ++i)
                {
                    char value = text[i];
                    
                    if (value >= 0 && value <= 127) // ascii
                    {
                        ascii++;
                        count++;
                    }
                    else
                    {
                        unicode++;
                        if (unicode % 3 == 0)
                        {
                            count++;
                        }
                    }
                    
                    if (count == _maxLength)
                    {
                        break;
                    }
                }
                end = ascii + unicode;
                input_text = input_text.substr(0, end);
                len  = end;
            }
#endif
        }
    }
    TextFieldTTF::insertText(input_text.c_str(), len);
    
    // password
    if (_passwordEnabled)
    {
        if (TextFieldTTF::getCharCount() > 0)
        {
            setPasswordText(getString().c_str());
        }
    }
}