Exemplo n.º 1
0
void CATextField::moveSelectChars(bool isLeftBtn, const CCPoint& pt)
{
	int l, r, p;
	calculateSelChars(convertToNodeSpace(pt), l, r, p);

	if (isLeftBtn)
	{
		if (p < m_curSelCharRange.second)
			m_curSelCharRange.first = p;
	}
	else
	{
		if (p > m_curSelCharRange.first)
			m_curSelCharRange.second = p;
	}

	m_iString_l_length = l;
	m_iString_r_length = r;
	bool isBackward = p < m_iCurPos;
	m_iCurPos = p;
	adjustCursorMove(!isBackward);
	CATextSelectView* pSelCharsView = CATextSelectView::create();
	bool ll, rr;
	CCRect cc = convertRectToWorldSpace(getZZCRect(&ll, &rr));
	pSelCharsView->showTextSelView(cc, this, ll, rr);
	this->hideCursorMark();
}
Exemplo n.º 2
0
	void MoveMouseArrow(const DPoint& pt)
	{
		calculateSelChars(pt, m_iString_l_length, m_iString_r_length, m_iCurPos);
		m_curSelCharRange.first = MIN(m_iCurPos, m_iStartMovePos);
		m_curSelCharRange.second = MAX(m_iCurPos, m_iStartMovePos);
		adjustCursorMove();
		m_pTextViewMark->setFrame(getZZCRect());
		m_pTextViewMark->setVisible(true);
	}
Exemplo n.º 3
0
void CATextField::cursorMoveBackward()
{
	if (m_iCurPos == 0 || m_sText.empty())
		return;

	int iPrevPos = m_iCurPos, nMoveLen = 1;
	while (0x80 == (0xC0 & m_sText.at(m_iCurPos - nMoveLen)))
	{
		++nMoveLen;
	}
	m_iCurPos -= nMoveLen;

	m_curSelCharRange.first = m_curSelCharRange.second = m_iCurPos;
	adjustCursorMove(false);
}
Exemplo n.º 4
0
	bool execCurSelCharRange()
	{
		m_pTextViewMark->setVisible(false);

		if (m_curSelCharRange.first == m_curSelCharRange.second)
			return false;

		int iOldCurPos = m_curSelCharRange.first;
		std::string cszText = m_sText.erase(m_curSelCharRange.first, m_curSelCharRange.second - m_curSelCharRange.first);
		setText(cszText);

		m_iCurPos = iOldCurPos;
		showCursorMark();
		adjustCursorMove();
		return true;
	}
Exemplo n.º 5
0
void CATextField::cursorMoveForward()
{
	if (m_iCurPos == m_sText.length() || m_sText.empty())
		return;

	int iPrevPos = m_iCurPos, nMoveLen = 1;
	for (std::string::size_type n = m_iCurPos + nMoveLen; n < m_sText.length() && 0x80 == (0xC0 & m_sText.at(n));)
	{
		++nMoveLen;
		n = m_iCurPos + nMoveLen;
	}
	m_iCurPos += nMoveLen;

	m_curSelCharRange.first = m_curSelCharRange.second = m_iCurPos;
	adjustCursorMove(true);
}
Exemplo n.º 6
0
void CATextField::deleteBackward()
{
	CC_RETURN_IF(m_iCurPos == 0 || m_sText.empty());
    if (m_nInputType==KEY_BOARD_INPUT_PASSWORD)
    {
		CC_RETURN_IF(m_pDelegate && m_pDelegate->onTextFieldDeleteBackward(this, m_sText.c_str(), (int)m_sText.length(), m_iCurPos - (int)m_sText.length()));
        CC_RETURN_IF(m_pDelegate && m_pDelegate->onTextFieldDeleteBackward(this, m_sText.c_str(), (int)m_sText.length()));
        m_sText.clear();
		m_vTextFiledChars.clear();
		this->updateImage();
		m_iString_l_length = 0;
		m_iString_r_length = 0;
		m_iString_o_length = 0;
		m_iCurPos = 0;
		m_curSelCharRange = std::make_pair(0, 0);
        setCursorPosition();
        return;
    }

	std::string cszDelStr;
	if (m_curSelCharRange.first != m_curSelCharRange.second)
	{
		cszDelStr = m_sText.substr(m_curSelCharRange.first, m_curSelCharRange.second - m_curSelCharRange.first);
	}
	else
	{
		int nDeleteLen = 1;
		while (0x80 == (0xC0 & m_sText.at(m_iCurPos - nDeleteLen)))
		{
			++nDeleteLen;
		}
		cszDelStr = m_sText.substr(m_iCurPos - nDeleteLen, nDeleteLen);
	}
	CC_RETURN_IF(m_pDelegate && m_pDelegate->onTextFieldDeleteBackward(this, cszDelStr.c_str(), (int)cszDelStr.length(), m_iCurPos - (int)cszDelStr.length()));
	CC_RETURN_IF(m_pDelegate && m_pDelegate->onTextFieldDeleteBackward(this, cszDelStr.c_str(), (int)cszDelStr.length()));
	CC_RETURN_IF(execCurSelCharRange());

	int nDeleteLen = (int)cszDelStr.size();
    m_sText.erase(m_iCurPos - nDeleteLen, nDeleteLen);
    m_iCurPos -= nDeleteLen;
	m_curSelCharRange = std::make_pair(m_iCurPos, m_iCurPos);
	m_vTextFiledChars.erase(m_vTextFiledChars.begin() + getStringCharCount(m_sText.substr(0, m_iCurPos)));
	
	adjustCursorMove(false);
    CCLog("··· deleteBackward text:%s", m_sText.c_str());
}
Exemplo n.º 7
0
void CATextField::insertText(const char * text, int len)
{
    CC_RETURN_IF(len <= 0);
    CC_RETURN_IF(text == 0);
    CC_RETURN_IF(m_pDelegate && m_pDelegate->onTextFieldInsertText(this, text, len, m_iCurPos));
	CC_RETURN_IF(m_pDelegate && m_pDelegate->onTextFieldInsertText(this, text, len));
    
    if (!strcmp(text, "\n"))
    {
        getKeyBoradReturnCallBack();
        return;
    }
	
	execCurSelCharRange();
    analyzeString(text, len);
	adjustCursorMove(true);
}
Exemplo n.º 8
0
void CATextField::moveArrowBtn(const CCPoint& pt)
{
	if (m_nInputType == KEY_BOARD_INPUT_PASSWORD)
		return;


    this->showCursorMark();
	
	int l, r, p;
	calculateSelChars(convertToNodeSpace(pt), l, r, p);
	m_curSelCharRange = std::make_pair(m_iCurPos, m_iCurPos);

	m_iString_l_length = l;
	m_iString_r_length = r;
	bool isBackward = p < m_iCurPos;
	m_iCurPos = p;
	adjustCursorMove(!isBackward);
}
Exemplo n.º 9
0
	void insertText(const char * text, int len)
	{
		if (!strcmp(text, "\n"))
		{
			getKeyBoradReturnCallBack();

			CATextFieldDelegate* pDelegate = m_pTextFieldX->getDelegate();
            if (m_pTextFieldX->isAllowkeyBoardHide())
            {
                m_pTextFieldX->resignFirstResponder();
				EndMouseMoveArr();
            }
			if (pDelegate)
			{
				pDelegate->textFieldShouldReturn(m_pTextFieldX);
			}
			return;
		}

		if (m_sText.size() + len > m_pTextFieldX->getMaxLenght())
			return;
		
		std::string cszAddText;
		cszAddText.append(text, len);
		if (m_curSelCharRange.first != m_curSelCharRange.second)
		{
			if (!textValueChanged(m_curSelCharRange.first, m_curSelCharRange.second - m_curSelCharRange.first, cszAddText))
				return;
		}
		else
		{
			if (!textValueChanged(m_iCurPos, 0, cszAddText))
				return;
		}

		execCurSelCharRange();
		analyzeString(text, len);
		adjustCursorMove();
	}
Exemplo n.º 10
0
void CATextField::ccTouchEnded(CATouch *pTouch, CAEvent *pEvent)
{
	CATouchView::ccTouchEnded(pTouch, pEvent);

	if (CATextToolBarView::isTextToolBarShow())
		return;

    if (m_bMoved)
    {
        m_bMoved = false;
        return;
    }
    
    CCPoint point = this->convertTouchToNodeSpace(pTouch);
    
    if (this->getBounds().containsPoint(point))
    {
        if (!isFirstResponder())
        {
            becomeFirstResponder();
        }
        calculateSelChars(point, m_iString_l_length, m_iString_r_length, m_iCurPos);
        adjustCursorMove();
        
#if CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID
        CCEGLView * pGlView = CAApplication::getApplication()->getOpenGLView();
        pGlView->setIMECursorPos(getCursorPos(), getContentText());
#endif
    }
    else
    {
		resignFirstResponder();
	}

	m_curSelCharRange = std::make_pair(m_iCurPos, m_iCurPos);
	execCurSelCharRange();

}
Exemplo n.º 11
0
	void deleteBackward()
	{
		CC_RETURN_IF(m_sText.empty() || m_iCurPos==0);
		if (m_pTextFieldX->isSecureTextEntry())
		{
			clearText();
			updateImage();
			return;
		}

		if (m_curSelCharRange.first != m_curSelCharRange.second)
		{
			if (!textValueChanged(m_curSelCharRange.first, m_curSelCharRange.second - m_curSelCharRange.first, ""))
				return;
			
			CC_RETURN_IF(execCurSelCharRange());
		}
		else
		{
			int nDeleteLen = 1;
			while (0x80 == (0xC0 & m_sText.at(m_iCurPos - nDeleteLen)))
			{
				++nDeleteLen;
			}

			if (!textValueChanged(m_iCurPos, nDeleteLen, ""))
				return;

			m_sText.erase(m_iCurPos - nDeleteLen, nDeleteLen);
			m_iCurPos -= nDeleteLen;
			m_curSelCharRange = std::make_pair(m_iCurPos, m_iCurPos);
			m_vTextFiledChars.erase(m_vTextFiledChars.begin() + getStringCharCount(m_sText.substr(0, m_iCurPos)));

			adjustCursorMove();
		}
	}
Exemplo n.º 12
0
void CATextField::setTextEditAlign(eTextEditAlign e)
{
	m_eTextEditAlign = e;
	updateImage();
	adjustCursorMove();
}