Ejemplo n.º 1
0
void ChatInput::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent)
{
    TextField::mouseWheelMovedUp(mouseEvent);

    if (isFocused() && mCurHist != mHistory.begin() && mHistory.size() > 0)
    {
        // Move backward through the history
        mCurHist--;
        setText(*mCurHist);
        setCaretPosition(getText().length());
        mouseEvent.consume();
    }
}
Ejemplo n.º 2
0
void ChatInput::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent)
{
    TextField::mouseWheelMovedDown(mouseEvent);

    if (isFocused() && mCurHist != mHistory.end())
    {
        // Move forward through the history
        HistoryIterator prevHist = mCurHist++;

        if (mCurHist != mHistory.end())
        {
            setText(*mCurHist);
            setCaretPosition(getText().length());
        }
        else
            mCurHist = prevHist;

        mouseEvent.consume();
    }
}
void EditableTextComponent::keyTyped(const KeyEventUnrecPtr e)
{
	
    if(getEnabled() && getEditable() && !(e->getModifiers() &( KeyEvent::KEY_MODIFIER_ALT | KeyEvent::KEY_MODIFIER_CONTROL | KeyEvent::KEY_MODIFIER_META )))
	{
		if(e->getKeyChar()>31 && e->getKeyChar() < 127)
		{
			if(hasSelection())
			{
                deleteSelectedText();
				setCaretPosition(_TextSelectionStart);
			}
            insert(std::string( 1,e->getKeyChar() ), _TextSelectionStart);
			_TextSelectionStart = getCaretPosition();
			_TextSelectionEnd = _TextSelectionStart;
		}
		if(e->getKey()== e->KEY_BACK_SPACE)
		{
			if(hasSelection())
			{
                deleteSelectedText();
			}
			else
			{	
                //erase at the current caret position
                Int32 DeleteIndex(getCaretPosition());
                if(DeleteIndex != 0)
                {
                    moveCaret(-1);
                    deleteRange(DeleteIndex-1, DeleteIndex);
                }
			}
		}
		if(e->getKey()== e->KEY_DELETE)
		{
			if(hasSelection())
			{
                deleteSelectedText();
			}
			else if(getText().size()>0)
			{
				//erase at the current caret position
                deleteRange(getCaretPosition(), getCaretPosition()+1);
				_TextSelectionStart = getCaretPosition();
				_TextSelectionEnd = _TextSelectionStart;
			}
		}
	}
	
    switch(e->getKey())
    {
    case KeyEvent::KEY_RIGHT:
    case KeyEvent::KEY_KEYPAD_RIGHT:
        moveCaret(1);
        break;
    case KeyEvent::KEY_LEFT:
    case KeyEvent::KEY_KEYPAD_LEFT:
        moveCaret(-1);
        break;
    case KeyEvent::KEY_V:
        if(e->getModifiers() & KeyEvent::KEY_MODIFIER_COMMAND)
        {
            paste();
        }
        break;
    case KeyEvent::KEY_C:
        if(e->getModifiers() & KeyEvent::KEY_MODIFIER_COMMAND)
        {
            copy();
        }
        break;
    case KeyEvent::KEY_X:
        if(e->getModifiers() & KeyEvent::KEY_MODIFIER_COMMAND)
        {
            cut();
        }
        break;
    case KeyEvent::KEY_A:
        if(e->getModifiers() & KeyEvent::KEY_MODIFIER_COMMAND)
        {
            selectAll();
        }
        break;
    }

	Inherited::keyTyped(e);
}
Ejemplo n.º 4
0
void Label::mouseDragged(MouseEventDetails* const e)
{
    if(getTextSelectable())
    {
        Pnt2f TopLeftText, BottomRightText, TempPos;
        Pnt2f TopLeftText1, BottomRightText1;
        Pnt2f TopLeft, BottomRight;
        Int32 OriginalPosition = getCaretPosition();
        getFont()->getBounds(getText(), TopLeftText, BottomRightText);
        getInsideBorderBounds(TopLeft, BottomRight);
        TempPos = calculateAlignment(TopLeft, BottomRight-TopLeft, BottomRightText-TopLeftText, getAlignment().y(), getAlignment().x());
        if(e->getButton() == MouseEventDetails::BUTTON1)
        {
            //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())
            {
                setCaretPosition(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())
            {
                setCaretPosition(getText().size());
            }
            else
            {
                //check letter by letter for the mouse's position
                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
                    {
                        if(DrawingSurfaceToComponent(e->getLocation(), this).x() < (BottomRightText1.x()-BottomRightText.x())/2.0 + BottomRightText.x())
                        {

                            setCaretPosition(i);
                            break;
                        }
                        else
                        {

                            setCaretPosition(i+1);
                            break;
                        }
                    }
                }
            }
            if(getCaretPosition() < OriginalPosition)
            {
                if(getCaretPosition() < _TextSelectionStart)
                {
                    _TextSelectionStart = getCaretPosition();
                }
                else
                {
                    _TextSelectionEnd = getCaretPosition();
                }
            }
            else if(getCaretPosition() > OriginalPosition)
            {
                if(getCaretPosition() > _TextSelectionEnd)
                {
                    _TextSelectionEnd = getCaretPosition();
                }
                else
                {
                    _TextSelectionStart = getCaretPosition();
                }
            }
        }
    }
    

    Inherited::mouseDragged(e);
}
Ejemplo n.º 5
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);

}
Ejemplo n.º 6
0
    void Text::remove(int numberOfCharacters)
    {
        if (mRows.empty() || numberOfCharacters == 0)
            return;

        // We should remove characters left of the caret position.
        if (numberOfCharacters < 0)
        {
            while (numberOfCharacters != 0)
            {
                // If the caret position is zero there is nothing
                // more to do.
                if (mCaretPosition == 0)
                    break;

                // If we are at the end of the row
                // and the row is not the first row we
                // need to merge two rows.
                if (mCaretColumn == 0 && mCaretRow != 0)
                {
                    mRows[mCaretRow - 1] += mRows[mCaretRow];
                    mRows.erase(mRows.begin() + mCaretRow);
                    setCaretRow(mCaretRow - 1);
                    setCaretColumn(getNumberOfCharacters(mCaretRow));
                }
                else
                {
                    mRows[mCaretRow].erase(mCaretColumn - 1, 1);
                    setCaretPosition(mCaretPosition - 1);
                }

                numberOfCharacters++;
            }
        }
        // We should remove characters right of the caret position.
        else if (numberOfCharacters > 0)
        {
            while (numberOfCharacters != 0)
            {
                // If all rows have been removed there is nothing
                // more to do.
                if (mRows.empty())
                    break;

                // If we are at the end of row and the row
                // is not the last row we need to merge two
                // rows.
                if (mCaretColumn == mRows[mCaretRow].size()
                    && mCaretRow < (mRows.size() - 1))
                {
                    mRows[mCaretRow] += mRows[mCaretRow + 1];
                    mRows.erase(mRows.begin() + mCaretRow + 1);
                }
                else
                {
                    mRows[mCaretRow].erase(mCaretColumn, 1);
                }

                numberOfCharacters--;
            }
        }
    }
Ejemplo n.º 7
0
int TextBuffer::setPoint(int p) 
{
  setCaretPosition(p);
  return getCaretPosition();
}