Respect the maximum bytes set by SetMaxBytes() in Insert() and on

keydown. Fixed SetMaxBytes() so that it respect multibyte characters
(it removes the whole character in case it doesn't fit).
This can be seen in BColorControls, where you can't write numbers with 
more than 3 characters anymore.  


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23605 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2008-01-18 12:01:31 +00:00
parent 2fa152e4f0
commit 75ee0a2911
1 changed files with 19 additions and 10 deletions

View File

@ -2166,8 +2166,16 @@ BTextView::SetMaxBytes(int32 max)
const int32 textLength = fText->Length(); const int32 textLength = fText->Length();
fMaxBytes = max; fMaxBytes = max;
if (fMaxBytes < textLength) if (fMaxBytes < textLength) {
Delete(fMaxBytes, textLength); int32 offset = fMaxBytes;
// Delete the text after fMaxBytes, but
// respect multibyte characters boundaries.
const int32 previousInitial = _PreviousInitialByte(offset);
if (_NextInitialByte(previousInitial) != offset)
offset = previousInitial;
Delete(offset, textLength);
}
} }
@ -3013,7 +3021,7 @@ BTextView::_HandlePageKey(uint32 inPageKey)
*/ */
void void
BTextView::_HandleAlphaKey(const char *bytes, int32 numBytes) BTextView::_HandleAlphaKey(const char *bytes, int32 numBytes)
{ {
// TODO: block input if not editable (Andrew) // TODO: block input if not editable (Andrew)
if (fUndo) { if (fUndo) {
_BTypingUndoBuffer_ *undoBuffer = dynamic_cast<_BTypingUndoBuffer_ *>(fUndo); _BTypingUndoBuffer_ *undoBuffer = dynamic_cast<_BTypingUndoBuffer_ *>(fUndo);
@ -3042,18 +3050,16 @@ BTextView::_HandleAlphaKey(const char *bytes, int32 numBytes)
offset++; offset++;
if (start != offset) if (start != offset)
InsertText(Text() + start, offset - start, fSelStart, NULL); _DoInsertText(Text() + start, offset - start, fSelStart, NULL, NULL);
InsertText(bytes, numBytes, fSelStart, NULL); _DoInsertText(bytes, numBytes, fSelStart, NULL, NULL);
numBytes += offset - start;
} else } else
InsertText(bytes, numBytes, fSelStart, NULL); _DoInsertText(bytes, numBytes, fSelStart, NULL, NULL);
fClickOffset = fSelEnd = fSelStart = fSelStart + numBytes; fClickOffset = fSelEnd;
if (Window()) ScrollToOffset(fClickOffset);
_Refresh(saveStart, fSelEnd, erase, true);
} }
@ -3473,6 +3479,9 @@ BTextView::_DoInsertText(const char *inText, int32 inLength, int32 inOffset,
{ {
_CancelInputMethod(); _CancelInputMethod();
if (TextLength() + inLength > MaxBytes())
return;
// Don't do any check, the public methods will have adjusted // Don't do any check, the public methods will have adjusted
// eventual bogus values... // eventual bogus values...