void FixedHeightLayoutManager::doubleClickHandler(void)
{
	UInt32 initIndex = _CaretIndex;
	PlainDocumentLeafElementRefPtr theElement = dynamic_cast<PlainDocumentLeafElement*>(rootElement->getElement(_CaretLine));
	std::string theString = theElement->getText();

	Int32 BeginWord = 0;
	Int32 EndWord = theElement->getTextLength();

	if(isPunctuationChar(theString[_CaretIndex]))
	{
		EndWord = _CaretIndex + 1;
		BeginWord = _CaretIndex;
	}
	else
	{
		for(Int32 i = _CaretIndex; i < theElement->getTextLength(); i++)
		{
			if(!isWordChar(theString[i]))
			{
				EndWord = i;
				break;
			}
		}
		for(Int32 i = _CaretIndex; i >= 0; i--)
		{
			if(!isWordChar(theString[i]))
			{
				BeginWord = i + 1;
				break;
			}
		}
	}

	HEL = HSL = _CaretLine;
	HSI = BeginWord;
	HEI = EndWord;

	_CaretIndex = EndWord;

	recalculateCaretPositions();

	getParentTextDomArea()->setCaretPosition(getParentTextDomArea()->getCaretPosition()+ (EndWord - initIndex));

}
示例#2
0
void Label::mouseClicked(MouseEventDetails* const e)
{    
    if(getTextSelectable())
    {
        Int32 Position(0);
        Int32 BeginWord = 0;
        Int32 EndWord = getText().size();
        if(e->getButton() == MouseEventDetails::BUTTON1)
        {

            if(e->getClickCount() == 2)
            {
                Pnt2f TopLeftText, BottomRightText, TempPos;
                Pnt2f TopLeftText1, BottomRightText1;
                Pnt2f TopLeft, BottomRight;
                getFont()->getBounds(getText(), TopLeftText, BottomRightText);
                getInsideBorderBounds(TopLeft, BottomRight);
                TempPos = calculateAlignment(TopLeft, BottomRight-TopLeft, BottomRightText-TopLeftText, getAlignment().y(), getAlignment().x());

                //set caret position to proper place
                //if the mouse is to the left of the text, set it to the begining.
                Pnt2f temp = DrawingSurfaceToComponent(e->getLocation(), this);
                if(DrawingSurfaceToComponent(e->getLocation(), this).x() <= TempPos.x())
                {
                    Position = 0;
                }//if the mouse is to the right of the text, set it to the end
                else if(DrawingSurfaceToComponent(e->getLocation(), this).x() >= TempPos.x()+BottomRightText.x())
                {
                    Position = getText().size();
                }
                else
                {
                    for(UInt32 i = 0; i <getText().size(); i++)
                    {        
                        calculateTextBounds(0,i, TopLeftText, BottomRightText);
                        calculateTextBounds(0,i+1, TopLeftText1, BottomRightText1);
                        if(DrawingSurfaceToComponent(e->getLocation(), this).x()>BottomRightText.x()
                           && DrawingSurfaceToComponent(e->getLocation(), this).x() <= BottomRightText1.x())//check to see if it's in the right spot
                        {
                            Position = i;
                            break;
                        }
                    }
                }
                if(isPunctuationChar(getText()[Position]))
                {
                    EndWord = Position + 1;
                    BeginWord = Position;
                }
                else{
                    for(Int32 i = Position; i < getText().size(); i++)
                    {
                        if(!isWordChar(getText()[i]))
                        {
                            EndWord = i;
                            break;
                        }
                    }
                    for(Int32 i = Position; i >= 0; i--)
                    {
                        if(!isWordChar(getText()[i]))
                        {
                            BeginWord = i + 1;
                            break;
                        }
                    }
                }
                _TextSelectionEnd = EndWord;
                _TextSelectionStart = BeginWord;
                setCaretPosition(EndWord);
            }
        }
    }
    Inherited::mouseClicked(e);

}