void GuiTextEditCtrl::invalidText(bool playSound) { mTextValid = false; if ( playSound ) playDeniedSound(); }
void GuiTextEditCtrl::handleCharInput( U16 ascii ) { S32 stringLen = mTextBuffer.length(); // Get the character ready to add to a UTF8 string. UTF16 convertedChar[2] = { ascii, 0 }; //see if it's a number field if ( mProfile->mNumbersOnly ) { if ( ascii == '-') { //a minus sign only exists at the beginning, and only a single minus sign if ( mCursorPos != 0 && !isAllTextSelected() ) { playDeniedSound(); return; } if ( mInsertOn && ( mTextBuffer.getChar(0) == '-' ) ) { playDeniedSound(); return; } } // BJTODO: This is probably not unicode safe. else if ( ascii != '.' && (ascii < '0' || ascii > '9') ) { playDeniedSound(); return; } } //save the current state saveUndoState(); bool alreadyCut = false; //delete anything highlighted if ( mBlockEnd > 0 ) { mTextBuffer.cut(mBlockStart, mBlockEnd-mBlockStart); mCursorPos = mBlockStart; mBlockStart = 0; mBlockEnd = 0; // We just changed the string length! // Get its new value. stringLen = mTextBuffer.length(); // If we already had text highlighted, we just want to cut that text. // Don't cut the next character even if insert is not on. alreadyCut = true; } if ( ( mInsertOn && ( stringLen < mMaxStrLen ) ) || ( !mInsertOn && ( mCursorPos < mMaxStrLen ) ) ) { if ( mCursorPos == stringLen ) { mTextBuffer.append(convertedChar); mCursorPos++; } else { if ( mInsertOn || alreadyCut ) { mTextBuffer.insert(mCursorPos, convertedChar); mCursorPos++; } else { mTextBuffer.cut(mCursorPos, 1); mTextBuffer.insert(mCursorPos, convertedChar); mCursorPos++; } } } else playDeniedSound(); //reset the history index mHistoryDirty = true; //execute the console command if it exists execConsoleCallback(); }