this should complete the work on password mode for BTextView:

* fixed +/- 1 bug in _BTextGapBuffer_::GetString()
* used the correct text and offsets in BTextView whenever the visible
  text is to be used
* when copying to the clipboard, copy the bullets
* when dragging the text, drag the bullets
TODO:
* test more with UTF8 chars in the original text (I am unsure if fSelStart
  and so on is really in bytes rather than glyphs)
* test with multiple font styles



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22787 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2007-11-01 15:58:07 +00:00
parent 6a0f79107d
commit 23b6ac7e15
3 changed files with 20 additions and 11 deletions

View File

@ -1233,8 +1233,9 @@ BTextView::Copy(BClipboard *clipboard)
BMessage *clip = clipboard->Data();
if (clip != NULL) {
clip->AddData("text/plain", B_MIME_TYPE, Text() + fSelStart,
fSelEnd - fSelStart);
int32 numBytes = fSelEnd - fSelStart;
const char* text = fText->GetString(fSelStart, &numBytes);
clip->AddData("text/plain", B_MIME_TYPE, text, numBytes);
int32 size;
if (fStylable) {
@ -2642,9 +2643,10 @@ BTextView::GetDragParameters(BMessage *drag, BBitmap **bitmap, BPoint *point,
drag->AddInt32("be_actions", B_TRASH_TARGET);
// add the text
drag->AddData("text/plain", B_MIME_TYPE, fText->RealText() + fSelStart,
fSelEnd - fSelStart);
int32 numBytes = fSelEnd - fSelStart;
const char* text = fText->GetString(fSelStart, &numBytes);
drag->AddData("text/plain", B_MIME_TYPE, text, numBytes);
// add the corresponding styles
int32 size = 0;
text_run_array *styles = RunArray(fSelStart, fSelEnd, &size);
@ -3422,10 +3424,15 @@ BTextView::_StyledWidth(int32 fromOffset, int32 length, float *outAscent,
LockWidthBuffer();
result += sWidths->StringWidth(*fText, fromOffset, numChars, font);
UnlockWidthBuffer();
} else
} else {
#endif
result += font->StringWidth(fText->RealText() + fromOffset, numChars);
const char* text = fText->GetString(fromOffset, &numChars);
result += font->StringWidth(text, numChars);
#if USE_WIDTHBUFFER
}
#endif
fromOffset += numChars;
length -= numChars;
}

View File

@ -205,7 +205,7 @@ _BTextGapBuffer_::GetString(int32 fromOffset, int32 *_numBytes)
uint32 numChars = UTF8CountChars(result, numBytes);
uint32 charLen = UTF8CountBytes(B_UTF8_BULLET, 1);
uint32 newSize = numChars * charLen;
if ((uint32)fScratchSize < newSize) {
fScratchBuffer = (char *)realloc(fScratchBuffer, newSize);
fScratchSize = newSize;
@ -217,7 +217,8 @@ _BTextGapBuffer_::GetString(int32 fromOffset, int32 *_numBytes)
memcpy(scratchPtr, B_UTF8_BULLET, charLen);
scratchPtr += charLen;
}
*_numBytes = newSize - 1;
*_numBytes = newSize;
}
return result;

View File

@ -148,7 +148,8 @@ float
_BWidthBuffer_::StringWidth(_BTextGapBuffer_ &inBuffer, int32 fromOffset, int32 length,
const BFont *inStyle)
{
return StringWidth(inBuffer.Text(), fromOffset, length, inStyle);
const char* text = inBuffer.GetString(fromOffset, &length);
return StringWidth(text, 0, length, inStyle);
}