Example #1
0
 void TabbedPane::keyDown( KeyEvent &keyEvent )
 {
   if(keyEvent.getExtendedKey() == EXT_KEY_LEFT)
   {
     if(getSelectedIndex() > 0)
     {
       setSelectedTab(getSelectedIndex() - 1);
       keyEvent.consume();
     }
   }
   else if(keyEvent.getExtendedKey() == EXT_KEY_RIGHT)
   {
     setSelectedTab(getSelectedIndex() + 1);
     keyEvent.consume();
   }
 }
Example #2
0
	void ScrollPane::keyRepeatCB( KeyEvent &keyEvent )
	{
			keyAction(keyEvent.getExtendedKey());
	}
Example #3
0
	void TextField::handleKeyboard( KeyEvent &keyEvent )
	{
		if(handleHotkeys(keyEvent))
		{
			return;
		}

		//delete the next character
		if(keyEvent.getKey() == KEY_DELETE)
		{
			if(getCaretPosition() == getTextLength()
				&& getSelectionStart() == getSelectionEnd())
			{
				return;
			}

			if(isReadOnly())
			{
				return;
			}

			if(getSelectionStart() == getSelectionEnd())
			{
				removeNextCharacter();
			}
			else
			{
				deleteSelection();
			}
			setBlinking(true);
			invalidateBlink();
			return;
		}

		//delete the previous character
		if(keyEvent.getKey() == KEY_BACKSPACE)
		{
			if(getCaretPosition() == 0 && getSelectionStart() == getSelectionEnd())
			{
				return;
			}

			if(isReadOnly())
			{
				return;
			}

			if(getSelectionStart() == getSelectionEnd())
			{
				removeLastCharacter();
			}
			else
			{
				deleteSelection();
			}
			setBlinking(true);
			invalidateBlink();
			return;
		}

		if(keyEvent.getUnichar() >= ' ')
		{
			if(isReadOnly())
			{
				setBlinking(true);
				invalidateBlink();
				return;
			}

			if( isNumeric())
			{
				if(keyEvent.getUnichar() >= 0x30  && keyEvent.getUnichar() <= 0x39 )
				{
					deleteSelection();
					addToNextCharacter(keyEvent.getUnichar());
					setBlinking(true);
					invalidateBlink();
				}
				else if(wantedDecimal() && keyEvent.getUnichar() == 0x2e )
				{
					//check if there is already a decimal
					const char *text = getText().c_str();
					for (int i = 0; i < getTextLength(); ++i)
					{
						if(text[i] == 0x2e)
						{
							return;
						}
					}

					deleteSelection();
					addToNextCharacter(keyEvent.getUnichar());
					setBlinking(true);
					invalidateBlink();
				}
				else if(wantedMinus() && keyEvent.getUnichar() == 0x2d )
				{
					//check if we are in the first position
					if(getCaretPosition() != 0)
					{
						return;
					}

					//check if there is already a minus
					const char *text = getText().c_str();
					for (int i = 0; i < getTextLength(); ++i)
					{
						if(text[i] == 0x2d)
						{
							return;
						}
					}

					deleteSelection();
					addToNextCharacter(keyEvent.getUnichar());
					setBlinking(true);
					invalidateBlink();
				}
				

				return;
			}
			deleteSelection();
			addToNextCharacter(keyEvent.getUnichar());

			setBlinking(true);
			invalidateBlink();
			return;
		}

		switch (keyEvent.getExtendedKey())
		{
		case EXT_KEY_RIGHT:

			if(getCaretPosition() == getTextLength() 
				&& getSelectionStart() != getSelectionEnd() &&
				keyEvent.shift())
			{
				return;
			}
			else if(getCaretPosition() == getTextLength() 
				&& getSelectionStart() == getSelectionEnd())
			{
				return;
			}

			positionCaret(getCaretPosition() + 1);

			if(keyEvent.shift())
			{
				if(getSelectionStart() == getSelectionEnd())
				{
					setSelection(getCaretPosition() - 1, getCaretPosition());
				}
				else
				{
					if(getCaretPosition() - 1 < getSelectionEnd())
						setSelection(getSelectionEnd(), getCaretPosition());
					else
						setSelection(getSelectionStart(), getCaretPosition());
				}
			}
			else if(getSelectionStart() != getSelectionEnd())
			{
				int caretPos = getSelectionEnd();
				setSelection(0,0);
				positionCaret(caretPos);
			}

			setBlinking(true);
			invalidateBlink();
			break;
		case EXT_KEY_LEFT:

			if(getCaretPosition() == 0 
				&& getSelectionStart() != getSelectionEnd() &&
				keyEvent.shift())
			{
				return;
			}
			else if(getCaretPosition() == 0
				&& getSelectionStart() == getSelectionEnd())
			{
				return;
			}

			positionCaret(getCaretPosition() - 1);

			if(keyEvent.shift())
			{
				if(getSelectionStart() == getSelectionEnd())
				{
					setSelection(getCaretPosition() + 1, getCaretPosition());
				}
				else
				{
					if(getCaretPosition() + 1 < getSelectionEnd())
						setSelection(getSelectionEnd(), getCaretPosition());
					else
						setSelection(getSelectionStart(), getCaretPosition());
				}
			}

			else if(getSelectionStart() != getSelectionEnd())
			{
				int caretPos = getSelectionStart();
				setSelection(0,0);
				positionCaret(caretPos);
			}

			setBlinking(true);
			invalidateBlink();
			break;
		}

	}