void TextField::addToNextCharacter( int unichar ) { if(getTextLength() + 1 > getMaxLength()) { return; } char buffer[8]; for(int i = 0; i < 8; ++i) { buffer[i] = 0; } unicodeFunctions.encodeUtf8(buffer,unichar); std::string appendStr = buffer; std::string text; if(!isPassword()) text = getText(); else text = getPassword(); unicodeFunctions.insert(text,getCaretPosition(),buffer); setThisText(text); positionCaret(getCaretPosition() + 1); }
void TextField::mousePressed(MouseEventDetails* const e) { Pnt2f TopLeftText, BottomRightText, TempPos; Pnt2f TopLeftText1, BottomRightText1; Pnt2f TopLeft, BottomRight; getFont()->getBounds(getDrawnText(), 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(getDrawnText().size()); } else { for(UInt32 i = 0; i <getDrawnText().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+0.5 + BottomRightText.x()) { setCaretPosition(i); break; } else { setCaretPosition(i+1); break; } } } } _TextSelectionEnd = getCaretPosition(); _TextSelectionStart = getCaretPosition(); } if(getParentWindow() != NULL && getParentWindow()->getParentDrawingSurface()!=NULL&& getParentWindow()->getParentDrawingSurface()->getEventProducer() != NULL) { _MouseDownKeyTypedConnection = getParentWindow()->getParentDrawingSurface()->getEventProducer()->connectKeyTyped(boost::bind(&TextField::handleMouseDownKeyTyped, this, _1)); _MouseDownMouseReleasedConnection = getParentWindow()->getParentDrawingSurface()->getEventProducer()->connectMouseReleased(boost::bind(&TextField::handleMouseDownMouseReleased, this, _1)); _MouseDownMouseDraggedConnection = getParentWindow()->getParentDrawingSurface()->getEventProducer()->connectMouseDragged(boost::bind(&TextField::handleMouseDownMouseDragged, this, _1)); } Inherited::mousePressed(e); }
int TextBuffer::bufferMax() { // really stupid but its much faster than getText().length() ! int cp1 = getCaretPosition(); setCaretVisible(false); setCaretPosition(BUFMAX); int cp2=getCaretPosition(); setCaretPosition(cp1); setCaretVisible(true); return cp2; }
void Label::mousePressed(MouseEventDetails* const e) { if(getTextSelectable()) { 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()); 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 { 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+0.5 + BottomRightText.x()) { setCaretPosition(i); break; } else { setCaretPosition(i+1); break; } } } } _TextSelectionEnd = getCaretPosition(); _TextSelectionStart = getCaretPosition(); } } Inherited::mousePressed(e); }
void Text::insert(int character) { char c = (char)character; if (mRows.empty()) { if (c == '\n') mRows.push_back(""); else mRows.push_back(std::string(1, c)); } else { if (c == '\n') { mRows.insert(mRows.begin() + mCaretRow + 1, mRows[mCaretRow].substr(mCaretColumn, mRows[mCaretRow].size() - mCaretColumn)); mRows[mCaretRow].resize(mCaretColumn); } else mRows[mCaretRow].insert(mCaretColumn, std::string(1, c)); } setCaretPosition(getCaretPosition() + 1); }
void EditableTextComponent::overwriteSelection(const std::string& Text) { //Delete selected text deleteSelectedText(); //Write to Caret position insert(Text, getCaretPosition()); }
void TextField::removeNextCharacter() { //don't try to remove past the end if(getCaretPosition() + 1 > getTextLength()) { return; } std::string text; if(!isPassword()) text = getText(); else text = getPassword(); unicodeFunctions.erase(text,getCaretPosition(),1); setThisText(text); positionCaret(getCaretPosition()); }
int TextField::solveCaretRetPos( int initialAmount, int retOffset ) { int tempResult = retOffset + alignOffset - initialAmount; int tempCaret = getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0,getCaretPosition())) + tempResult; if(tempCaret > getAdjustedWidth() + getLeftPadding() || tempCaret < getLeftPadding()) { return getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0, getCaretPosition() + 1 )) - getAdjustedWidth(); } else { return initialAmount; } }
int TextBuffer::pointEOL() { int here = getCaretPosition(); setCaretVisible(false); int there=gotoEOL(); setCaretPosition(here); setCaretVisible(true); return there; }
void TextField::setFont( const Font *font ) { Widget::setFont(font); if(getInnerSize().getHeight() < getFont()->getLineHeight()) { setSize(getSize().getWidth(),getFont()->getLineHeight() + getMargin(SIDE_TOP) + getMargin(SIDE_BOTTOM)); } positionCaret(getCaretPosition()); }
void TextField::removeLastCharacter() { //don't try to remove past the beginning if(getCaretPosition() - 1 < 0) { return; } std::string text; if(!isPassword()) text = getText(); else text = getPassword(); unicodeFunctions.erase(text,getCaretPosition() - 1,1); setThisText(text); positionCaret(getCaretPosition() - 1,false); }
void TextDomArea::handlePastingAString(const std::string& theClipboard) { DocumentElementAttribute temp; if(getLayoutManager()->isSomethingSelected()) { deleteSelectedUsingCommandManager();//getLayoutManager()->deleteSelected(); } getDocumentModel()->insertString(getCaretPosition(),theClipboard,temp);/// need to deal with this...... getLayoutManager()->updateViews(); getLayoutManager()->updateSize(); updatePreferredSize(); }
void TextField::mouseDown( MouseEvent &mouseEvent ) { if(mouseEvent.getButton() != MOUSE_BUTTON_LEFT) { return; } dragged = false; int x = mouseEvent.getX() - getTextOffset() - getMargin(SIDE_LEFT); positionCaret(getFont()->getStringIndexFromPosition(getText(),x)); internalSelStart = getCaretPosition(); setSelection(0,0); mouseEvent.consume(); }
void TextField::paste() { if(isReadOnly()) { return; } std::string pasteResult = Clipboard::paste(); if(pasteResult.length() == 0 || getTextLength() - getSelectionLength() == getMaxLength()) { return; } deleteSelection(); int start = getCaretPosition(); std::string noNewLine; for(size_t i = 0; i < pasteResult.size(); ++i) { if(pasteResult[i] != '\n') { noNewLine += pasteResult[i]; } } int length = int(unicodeFunctions.length(noNewLine)); int numRemainingChar = getMaxLength() - getTextLength(); if(numRemainingChar < length) { noNewLine = unicodeFunctions.subStr(noNewLine,0,numRemainingChar); length = numRemainingChar; } if(length > 0) { std::string* cText = (std::string*)&getText(); unicodeFunctions.insert(*cText,start,noNewLine); setThisText(*cText); positionCaret(caretPosition + length); } }
void TextField::mouseDrag( MouseEvent &mouseEvent ) { if(mouseEvent.getButton() != MOUSE_BUTTON_LEFT) { return; } if(!isSelectable()) { return; } dragged = true; int maxcharSkip = getMaxCharacterSkip(); maxCharacterSkip = 1; int x = mouseEvent.getX() - getTextOffset() - getMargin(SIDE_LEFT); positionCaret(getFont()->getStringIndexFromPosition(getText(),x)); setSelection(internalSelStart,getCaretPosition()); maxCharacterSkip = maxcharSkip; mouseEvent.consume(); }
void TextField::appendText( const std::string& text, bool atCurrentPosition /*= true*/ ) { if(text.length() == 0 || getTextLength() - getSelectionLength() == getMaxLength()) { return; } deleteSelection(); if(!atCurrentPosition) { positionCaret(getTextLength()); } int start = getCaretPosition(); std::string noNewLine; for(size_t i = 0; i < text.size(); ++i) { if(text[i] != '\n') { noNewLine += text[i]; } } int length = int(unicodeFunctions.length(noNewLine)); int numRemainingChar = getMaxLength() - getTextLength(); if(numRemainingChar < length) { noNewLine = unicodeFunctions.subStr(noNewLine,0,numRemainingChar); length = numRemainingChar; } if(length > 0) { std::string* cText = (std::string*)&getText(); unicodeFunctions.insert(*cText,start,noNewLine); setThisText(*cText); positionCaret(caretPosition + length); } }
bool TextBuffer::findNext(String str, bool wrap) { // start looking at current cursor position (if region exists caret // position is end of region) int pos=getCaretPosition(); int wid=str.length(); int tot=size(); int got=-1; // bool wrap=true; while (true) { if (pos>tot-wid) // not enough chars to make a match { if (wrap) { wrap=false; pos=0; } else break; } String tmp=getTextSubstring(pos, pos+100); got=tmp.indexOf(str); if (got>-1) { pos += got; break; } int len=tmp.length(); // next search position must overlapping current end pos=pos+len-wid+1; } if (got>-1) { setHighlightedRegion(pos,wid); return true; } return false; }
bool TextBuffer::findPrevious(String str, bool wrap) { int pos=getCaretPosition()-getHighlightedRegionLength(); int wid=str.length(); int tot=size(); int got=-1; while (true) { if (pos<=wid) // not enough chars to make a match { if (wrap) { wrap=false; pos=tot; } else break; } int top=pos-100; if (top<0) top=0; String tmp=getTextSubstring(top, pos); int len=tmp.length(); got=tmp.lastIndexOf(str); if (got>-1) { pos -= (len-got); break; } // next search position must overlapping current end pos=top+wid; } if (got>-1) { setHighlightedRegion(pos,wid); return true; } return false; }
void GUIInputCaret::moveCaretUp() { UINT32 charIdx = getCharIdxAtCaretPos(); if(charIdx > 0) charIdx -= 1; UINT32 lineIdx = getLineForChar(charIdx); const GUIInputLineDesc& desc = getLineDesc(lineIdx); // If char is a newline, I want that to count as being on the next line because that's // how user sees it if(desc.isNewline(charIdx)) lineIdx++; if(lineIdx == 0) { moveCaretToStart(); return; } Vector2I caretCoords = getCaretPosition(mElement->_getTextInputOffset()); caretCoords.y -= getCaretHeight(); moveCaretToPos(caretCoords); }
void TextBuffer::clearRegion() { setHighlightedRegion(getCaretPosition(),0); }
void TextField::scrollToCaret(bool negetiveChange, bool reposition) { int retOffset = getLeftPadding(); int textWidth = getFont()->getTextWidth(getText()); if(textWidth < getAdjustedWidth()) { switch(getTextAlignment()) { case ALIGN_LEFT: alignOffset = 0; break; case ALIGN_CENTER: alignOffset = (getAdjustedWidth() - textWidth) / 2; break; case ALIGN_RIGHT: alignOffset = getAdjustedWidth() - textWidth; break; default: break; } } else { alignOffset = 0; } if(getTextLength() == 0 || getCaretPosition() == 0) { tOffset = retOffset; setTextOffset(retOffset + alignOffset); return; } if(reposition) { //do we need to move? if(getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0,getCaretPosition())) > -tOffset + getAdjustedWidth() + getLeftPadding() ) { //scroll to end if(getTextLength() < getCaretPosition() + getMaxCharacterSkip()) { retOffset -= solveCaretRetPos(getFont()->getTextWidth(getText()) - getAdjustedWidth(), retOffset); } else { int initialPlace = getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0, getCaretPosition() + getMaxCharacterSkip() )) - getAdjustedWidth(); retOffset -= solveCaretRetPos(initialPlace,retOffset); } tOffset = retOffset; setTextOffset(retOffset + alignOffset); return; } else if(tOffset + getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0,getCaretPosition())) <= leftPadding) { if(getCaretPosition() - getMaxCharacterSkip() > 0) { int initialPlace = getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0, getCaretPosition() - getMaxCharacterSkip() )); retOffset -= solveCaretRetPos(initialPlace,retOffset); } tOffset = retOffset; setTextOffset(retOffset + alignOffset); return; } else if(negetiveChange ) { int change = getCaretLocation() - getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0, getCaretPosition() )) ; if(change <= getLeftPadding()) { tOffset = change; setTextOffset(change); } else { tOffset = leftPadding; setTextOffset(leftPadding + alignOffset); } return; } } //if there is more text than width //but theres not enough to fill the width //then fill the width int a = getAdjustedWidth() + getLeftPadding(); int b = getTextOffset() + textWidth; if(a > b && getTextOffset() < getLeftPadding()) { retOffset = -textWidth + getInnerSize().getWidth() - getRightPadding(); tOffset = retOffset; } else if(getTextOffset() >= getLeftPadding() ) { tOffset = leftPadding; setTextOffset(leftPadding + alignOffset); return; } setTextOffset(tOffset + alignOffset); }
Vector2I GUIInputCaret::getSpriteOffset() const { return getCaretPosition(getTextOffset()); }
void TextField::relocateCaret() { caretLocation = getFont()->getTextWidth(unicodeFunctions.subStr(getText(), 0,getCaretPosition())) + getTextOffset(); }
int TextBuffer::setPoint(int p) { setCaretPosition(p); return getCaretPosition(); }
int TextBuffer::point() { return getCaretPosition(); }
void TextField::drawInternal(Graphics* const TheGraphics, Real32 Opacity) const { Pnt2f Alignment; Pnt2f TopLeft, BottomRight; getInsideBorderBounds(TopLeft, BottomRight); //Text Color Color4f TextColor = getDrawnTextColor(); if(getDrawnText() != "" && getFont() != NULL) { Alignment = calculateAlignment(TopLeft, BottomRight-TopLeft, getFont()->getBounds(getDrawnText()), getAlignment().y(), getAlignment().x()); if(_TextSelectionStart >= _TextSelectionEnd) { TheGraphics->drawText(Alignment, getDrawnText(), getFont(), TextColor, getOpacity()*Opacity); } else { //Draw Text Befor the Selection TheGraphics->drawText(Alignment, getDrawnText().substr(0, _TextSelectionStart), getFont(), TextColor, getOpacity()*Opacity); //Draw Selection Pnt2f TextTopLeft, TextBottomRight; getFont()->getBounds(getDrawnText().substr(0, _TextSelectionStart), TextTopLeft, TextBottomRight); TheGraphics->drawQuad(Alignment + Vec2f(TextBottomRight.x(),0), Alignment + Vec2f(getFont()->getBounds(getDrawnText().substr(0, _TextSelectionEnd)).x(), 0), Alignment + Vec2f(getFont()->getBounds(getDrawnText().substr(0, _TextSelectionEnd))), Alignment + Vec2f(TextBottomRight), getSelectionBoxColor(), getSelectionBoxColor(), getSelectionBoxColor(), getSelectionBoxColor(), getOpacity()); //Draw Selected Text TheGraphics->drawText(Alignment + Vec2f(TextBottomRight.x(), 0), getDrawnText().substr(_TextSelectionStart, _TextSelectionEnd-_TextSelectionStart), getFont(), getSelectionTextColor(), getOpacity()*Opacity); //Draw Text After selection getFont()->getBounds(getDrawnText().substr(0, _TextSelectionEnd), TextTopLeft, TextBottomRight); TheGraphics->drawText(Alignment + Vec2f(TextBottomRight.x(), 0), getDrawnText().substr(_TextSelectionEnd, getDrawnText().size()-_TextSelectionEnd), getFont(), TextColor, getOpacity()*Opacity); } } else { Alignment = calculateAlignment(TopLeft, BottomRight-TopLeft, getFont()->getBounds("|"), getAlignment().y(), getAlignment().x()); } if(getEnabled() && getEditable() && getFocused() && _CurrentCaretBlinkElps <= 0.5*LookAndFeelManager::the()->getLookAndFeel()->getTextCaretRate()) { //Draw the caret TheGraphics->drawLine(Alignment+Vec2f(getFont()->getBounds(getDrawnText().substr(0, getCaretPosition())).x(), 0), Alignment + Vec2f(getFont()->getBounds(getDrawnText().substr(0, getCaretPosition())).x(), getFont()->getBounds(getDrawnText()).y()), .5, TextColor, getOpacity()*Opacity); } //Draw the Descriptive text if empty if(getDrawnText().empty() && !getEmptyDescText().empty() && getEmptyDescTextFont() != NULL) { Alignment = calculateAlignment(TopLeft, BottomRight-TopLeft, getEmptyDescTextFont()->getBounds(getEmptyDescText()), getAlignment().y(), getAlignment().x()); TheGraphics->drawText(Alignment, getEmptyDescText(), getEmptyDescTextFont(), getEmptyDescTextColor(), getOpacity()*Opacity); } }
void TextField::handleMouseDownMouseDragged(MouseEventDetails* const e) { Pnt2f TopLeftText, BottomRightText, TempPos; Pnt2f TopLeftText1, BottomRightText1; Pnt2f TopLeft, BottomRight; Int32 OriginalPosition = getCaretPosition(); getFont()->getBounds(getDrawnText(), 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(getDrawnText().size()); } else { //check letter by letter for the mouse's position for(UInt32 i = 0; i <getDrawnText().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(); } } } }
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); }
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; } }