Пример #1
0
    void toFront (bool makeActive) override
    {
        view.callVoidMethod (ComponentPeerView.bringToFront);

        if (makeActive)
            grabFocus();

        handleBroughtToFront();
    }
Пример #2
0
bool LegacyTextEditor::insertCharAtCursor( uint16_t c )
{
    if( !isEditable() )
        return 0;

    if( !m_state.isFocused() )
        if( !grabFocus() )
            return false;				// Couldn't get input focus...

    return _insertCharAtCursor(c);
}
Пример #3
0
int BRB::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = View::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: positionChanged((*reinterpret_cast< const Quackle::GamePosition(*)>(_a[1]))); break;
        case 1: grabFocus(); break;
        }
        _id -= 2;
    }
    return _id;
}
Пример #4
0
int QuickEntryRack::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = View::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: positionChanged((*reinterpret_cast< const Quackle::GamePosition(*)>(_a[1]))); break;
        case 1: grabFocus(); break;
        case 2: quickEditReturnPressed(); break;
        case 3: shuffle(); break;
        }
        _id -= 4;
    }
    return _id;
}
Пример #5
0
	bool LineEditor::insertCharAtCaret( uint16_t c )
	{
		if( !_isEditable() )
			return false;
	
		if( !m_state.isFocused() )
			if( !grabFocus() )
				return false;				// Couldn't get input focus...
	
		if( !m_text.putChar( c ) )
			return false;
	
		Base::msgRouter()->post( new TextEditMsg(text.ptr(),false) );
	
		_adjustViewOfs();
		return true;
	}
Пример #6
0
	int LineEditor::insertTextAtCaret( const CharSeq& str )
	{
		if( !_isEditable() )
			return 0;
	
		if( !m_state.isFocused() )
			if( !grabFocus() )
				return 0;				// Couldn't get input focus...
	
		int retVal = m_text.putText( str );
	
		Base::msgRouter()->post( new TextEditMsg(text.ptr(),false) );
	
		_adjustViewOfs();
	
		return retVal;
	}
Пример #7
0
int LegacyTextEditor::insertTextAtCursor( const CharSeq& str )
{
    if( !isEditable() )
        return 0;

    if( !m_state.isFocused() )
        if( !grabFocus() )
            return 0;				// Couldn't get input focus...

    int nChars = m_text.putText( str );

    if( m_maxLines != 0 && m_maxLines < m_text.nbSoftLines() )
    {
        m_text.unputText( nChars );
        nChars = 0;
    }

    return nChars;
}
Пример #8
0
int View::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = BaseView::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: setCandidateMove((*reinterpret_cast< const Quackle::Move(*)>(_a[1]))); break;
        case 1: removeCandidateMoves((*reinterpret_cast< const Quackle::MoveList(*)>(_a[1]))); break;
        case 2: commit(); break;
        case 3: setRack((*reinterpret_cast< const Quackle::Rack(*)>(_a[1]))); break;
        case 4: setNote((*reinterpret_cast< const UVString(*)>(_a[1]))); break;
        case 5: positionChanged((*reinterpret_cast< const Quackle::GamePosition(*)>(_a[1]))); break;
        case 6: movesChanged((*reinterpret_cast< const Quackle::MoveList(*)>(_a[1]))); break;
        case 7: grabFocus(); break;
        }
        _id -= 8;
    }
    return _id;
}
Пример #9
0
	void Widget::_componentRequestFocus( const Component * pComponent )
	{
		grabFocus();
	}
Пример #10
0
	void LineEditor::_receive( const Msg_p& pMsg )
	{
		Widget::_receive(pMsg);
	
		MsgRouter_p	pHandler = Base::msgRouter();
		MsgType event = pMsg->type();
	
		if( event == MsgType::Tick )
		{
			if( _isSelectable() && m_state.isFocused() )
			{
				m_text.incTime( TickMsg::cast(pMsg)->timediff() );
				_requestRender();					//TODO: Should only render the cursor and selection!
			}
			return;
		}
	
		if( (event == MsgType::MousePress || event == MsgType::MouseDrag) && MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left )
		{
			MouseButtonMsg_p pButtonMsg = MouseButtonMsg::cast(pMsg);
			
			if( !m_state.isFocused() )
				grabFocus();
	
			if( m_state.isFocused() )
			{
				if( _isSelectable() && (pButtonMsg->modKeys() & MODKEY_SHIFT) )
				{
					m_text.setSelectionMode(true);
				}
	
				Coord ofs = pButtonMsg->pointerPos() - globalPos();
				int x = ofs.x + m_viewOfs;
				int y = 0;
	
				if( m_bPasswordMode )
				{
					TextAttr	attr;
					m_text.getBaseAttr( attr );
	
					Pen	pen;
					pen.setAttributes( attr );
					pen.setChar(m_pwGlyph);
					pen.advancePos();
	
					int spacing = pen.getPosX();
					int height = pen.getLineSpacing();
	
					int line = y/height;
					int col = (x+spacing/2)/spacing;
					if(col < 0)
					{
						col = 0;
						line = 0;
					}
					m_text.gotoSoftPos(line,col);
				}
				else
				{
					m_text.cursorGotoCoord( Coord(x, 0), Rect(0,0,1000000,1000000) );
				}
	
				if(_isSelectable() && event == MsgType::MousePress && !(pButtonMsg->modKeys() & MODKEY_SHIFT))
				{
					m_text.clearSelection();
					m_text.setSelectionMode(true);
				}
			}
			_adjustViewOfs();
		}
	
		if( event == MsgType::MouseRelease )
		{
			if( m_state.isFocused() && MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left )
				m_text.setSelectionMode(false);
		}		
	
		if( event == MsgType::TextInput )
		{
			String str = TextInputMsg::cast(pMsg)->text();
	
			if( _isEditable() && m_state.isFocused() )
			{
				if(m_text.hasSelection())
					m_text.delSelection();
				m_text.setSelectionMode(false);

				bool bModified = false;
				for( int i = 0 ; i < str.length() ; i++ )
				{
					unsigned short ch = str.chars()[i].getGlyph();
					
					if( ch >= 32 && ch != 127 )
					{
						if( m_text.putChar( ch ) )
							bModified = true;
					}
				}

				if( bModified )
				{
					if( pHandler )
						pHandler->post( new TextEditMsg(text.ptr(),false) );

					_adjustViewOfs();
				}
	
			}
		}
	
		if( event == MsgType::KeyRelease && m_state.isFocused() )
		{
			Key key = KeyMsg::cast(pMsg)->translatedKeyCode();
			switch( key )
			{
				case Key::Shift:
					if(!Base::inputHandler()->isButtonPressed(MouseButton::Left))
						m_text.setSelectionMode(false);
				break;
			}
		}
	
		if( (event == MsgType::KeyPress || event == MsgType::KeyRepeat) && _isEditable() && m_state.isFocused() )
		{
			KeyMsg_p pKeyMsg = KeyMsg::cast(pMsg);
			Key key = pKeyMsg->translatedKeyCode();
			switch( key )
			{
				case Key::Left:
					if( pKeyMsg->modKeys() & MODKEY_SHIFT )
						m_text.setSelectionMode(true);
	
					if( pKeyMsg->modKeys() & MODKEY_CTRL )
					{
						if( m_bPasswordMode )
							m_text.goBol();
						else
							m_text.gotoPrevWord();
					}
					else
					{
						m_text.goLeft();
					}
					break;
				case Key::Right:
					if( pKeyMsg->modKeys() & MODKEY_SHIFT )
						m_text.setSelectionMode(true);
	
					if( pKeyMsg->modKeys() & MODKEY_CTRL )
					{
						if( m_bPasswordMode )
							m_text.goEol();
						else
							m_text.gotoNextWord();
					}
					else
					{
						m_text.goRight();
					}
					break;
	
				case Key::Backspace:
				{
					if(m_text.hasSelection())
						m_text.delSelection();
					else if( (pKeyMsg->modKeys() & MODKEY_CTRL) && !m_bPasswordMode)
						m_text.delPrevWord();
					else
						m_text.delPrevChar();
	
					if( pHandler )
						pHandler->post( new TextEditMsg(text.ptr(),false) );
					break;
				}
	
				case Key::Delete:
				{
					if(m_text.hasSelection())
						m_text.delSelection();
					else if( (pKeyMsg->modKeys() & MODKEY_CTRL) && !m_bPasswordMode)
						m_text.delNextWord();
					else
						m_text.delNextChar();
	
					if( pHandler )
						pHandler->post( new TextEditMsg(text.ptr(),false) );
					break;
				}
	
				case Key::Home:
	
					/*
					 *	I am not sure if this is the proper way to this, but in my opinion, the default
					 *	"actions" has to be separated from any modifier key action combination
					 */
					switch( pKeyMsg->modKeys() )
					{
	
					case MODKEY_CTRL:
						break;
	
					default: // no modifier key was pressed
						if(pKeyMsg->modKeys() & MODKEY_SHIFT )
							m_text.setSelectionMode(true);
	
						m_text.goBol();
						break;
					}
	
					break;
	
				case Key::End:
	
					/*
				 	 *	I am not sure if this is the proper way to this, but in my opinion, the default
			 		 *	"actions" has to be separated from any modifier key action combination
					 */
					switch( pKeyMsg->modKeys() )
					{
	
					case MODKEY_CTRL:
						break;
	
					default: // no modifier key was pressed
						if( pKeyMsg->modKeys() & MODKEY_SHIFT )
							m_text.setSelectionMode(true);
	
						m_text.goEol();
						break;
					}
	
					break;
	
				default:
					break;
			}
			_adjustViewOfs();
		}
	
		// Swallow message depending on rules.
	
		if( pMsg->isMouseButtreceive() )
		{
			if( MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left )
				pMsg->swallow();
		}
		else if( pMsg->isKeyMsg() )
		{
			Key key = KeyMsg::cast(pMsg)->translatedKeyCode();
			if( KeyMsg::cast(pMsg)->isMovementKey() == true ||
				key == Key::Delete || key == Key::Backspace )
					pMsg->swallow();
			
			//TODO: Would be good if we didn't forward any character-creating keys either...
		}
	}
Пример #11
0
void LegacyTextEditor::_onMsg( const Msg_p& pMsg )
{
    Widget::_onMsg(pMsg);

    MsgType type 				= pMsg->type();

    if( type == MsgType::Tick )
    {
        if( isSelectable() && m_state.isFocused() )
        {
            m_text.incTime( TickMsg::cast(pMsg)->timediff() );
            _requestRender();					//TODO: Should only render the cursor and selection!
        }
        return;
    }



    if( m_state.isFocused() && (type == MsgType::MousePress || type == MsgType::MouseDrag) && MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left )
    {
        MouseButtonMsg_p p = MouseButtonMsg::cast(pMsg);

        ModifierKeys modKeys 	= p->modKeys();
        Coord pointerPos = p->pointerPos();

        if( isSelectable() && (modKeys & MODKEY_SHIFT) )
        {
            m_text.setSelectionMode(true);
        }

        m_text.cursorGotoCoord( pointerPos, globalGeo() );

        if(isSelectable() && type == MsgType::MousePress && !(modKeys & MODKEY_SHIFT))
        {
            m_text.clearSelection();
            m_text.setSelectionMode(true);
        }
    }
    else if( type == MsgType::MouseRelease  )
    {
        if(m_state.isFocused() && MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left)
            m_text.setSelectionMode(false);
    }
    else if( !m_state.isFocused() && isEditable() && type == MsgType::MousePress && MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left )
    {
        grabFocus();
    }


    if( type == MsgType::TextInput )
    {
        if( isEditable() )
        {
            String text = TextInputMsg::cast(pMsg)->text();

            for( int i = 0 ; i < text.length() ; i++ )
            {
                unsigned short chr = text.chars()[i].getGlyph();

                if( chr >= 32 && chr != 127)
                {
                    _insertCharAtCursor(chr);
                }
                else if( chr == 13 )
                {
                    _insertCharAtCursor('\n');
                }
                else if( chr == '\t' && m_bTabLock )
                {
                    _insertCharAtCursor( '\t' );
                }
            }
        }
    }

    if( type == MsgType::KeyRelease )
    {
        switch( KeyMsg::cast(pMsg)->translatedKeyCode() )
        {
        case Key::Shift:
            if(!Base::inputHandler()->isButtonPressed(MouseButton::Left))
                m_text.setSelectionMode(false);
            break;
        }
    }

    if( (type == MsgType::KeyPress || type == MsgType::KeyRepeat) && isEditable() )
    {
        KeyMsg_p p = KeyMsg::cast(pMsg);
        ModifierKeys modKeys = p->modKeys();

        switch( p->translatedKeyCode() )
        {
        case Key::Left:
            if( modKeys & MODKEY_SHIFT )
                m_text.setSelectionMode(true);

            if( modKeys & MODKEY_CTRL )
                m_text.gotoPrevWord();
            else
                m_text.goLeft();
            break;
        case Key::Right:
            if( modKeys & MODKEY_SHIFT )
                m_text.setSelectionMode(true);

            if( modKeys & MODKEY_CTRL )
                m_text.gotoNextWord();
            else
                m_text.goRight();
            break;

        case Key::Up:
            if( modKeys & MODKEY_SHIFT )
                m_text.setSelectionMode(true);

            m_text.cursorGoUp( 1, globalGeo() );
            break;

        case Key::Down:
            if( modKeys & MODKEY_SHIFT )
                m_text.setSelectionMode(true);

            m_text.cursorGoDown( 1, globalGeo() );
            break;

        case Key::Backspace:
            if(m_text.hasSelection())
                m_text.delSelection();
            else if( modKeys & MODKEY_CTRL )
                m_text.delPrevWord();
            else
                m_text.delPrevChar();
            break;

        case Key::Delete:
            if(m_text.hasSelection())
                m_text.delSelection();
            else if( modKeys & MODKEY_CTRL )
                m_text.delNextWord();
            else
                m_text.delNextChar();
            break;

        case Key::Home:
            if( modKeys & MODKEY_SHIFT )
                m_text.setSelectionMode(true);

            if( modKeys & MODKEY_CTRL )
                m_text.goBot();
            else
                m_text.goBol();
            break;

        case Key::End:
            if( modKeys & MODKEY_SHIFT )
                m_text.setSelectionMode(true);

            if( modKeys & MODKEY_CTRL )
                m_text.goEot();
            else
                m_text.goEol();
            break;

        default:
            break;
        }
    }

    // Let text object handle its actions.
    /*
    	bool bChanged = m_text.onAction( action, button_key, globalGeo(), Coord(info.x, info.y) );
    	if( bChanged )
    		RequestRender();
    */

    // Swallow message depending on rules.

    if( pMsg->isMouseButtonMsg() && isSelectable() )
    {
        if( MouseButtonMsg::cast(pMsg)->button() == MouseButton::Left )
            pMsg->swallow();
    }
    else if( pMsg->isKeyMsg() && isEditable() )
    {
        Key key = KeyMsg::cast(pMsg)->translatedKeyCode();
        if( KeyMsg::cast(pMsg)->isMovementKey() == true ||
                key == Key::Delete || key == Key::Backspace || key == Key::Return || (key == Key::Tab && m_bTabLock) )
            pMsg->swallow();

        //TODO: Would be good if we didn't forward any character-creating keys either...
    }
    else if( type == MsgType::TextInput )
        pMsg->swallow();
}