Implemented BTextView::HideTyping(). Now it will display B_UTF8_BULLET

chars instead of the real text if this option is enabled. Note that 
there are problems with the text width, i.e. the calculation is still 
done with the "real" chars, leading to text corruption.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18837 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2006-09-14 14:51:18 +00:00
parent 3a70724f43
commit 575a68b317
2 changed files with 47 additions and 20 deletions

View File

@ -2438,16 +2438,16 @@ BTextView::DoesUndo() const
void
BTextView::HideTyping(bool enabled)
{
CALLED();
//TODO: Implement ?
//fText->SetPasswordMode(enabled);
if (enabled)
Delete(0, fText->Length());
fText->SetPasswordMode(enabled);
}
bool
BTextView::IsTypingHidden() const
{
CALLED();
return fText->PasswordMode();
}
@ -3636,13 +3636,13 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, bool era
long offset = startOffset != -1 ? startOffset : line->offset;
const BFont *font = NULL;
const rgb_color *color = NULL;
int32 numChars;
int32 numBytes;
// iterate through each style on this line
while ((numChars = fStyles->Iterate(offset, length, fInline, &font, &color)) != 0) {
while ((numBytes = fStyles->Iterate(offset, length, fInline, &font, &color)) != 0) {
view->SetFont(font);
view->SetHighColor(*color);
tabChars = numChars;
tabChars = numBytes;
do {
foundTab = fText->FindChar(B_TAB, offset, &tabChars);
if (foundTab) {
@ -3650,7 +3650,7 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, bool era
numTabs++;
if ((*fText)[offset + tabChars + numTabs] != B_TAB)
break;
} while ((tabChars + numTabs) < numChars);
} while ((tabChars + numTabs) < numBytes);
}
if (inputRegion.CountRects() > 0) {
@ -3680,7 +3680,8 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, bool era
view->PopState();
}
view->DrawString(fText->GetString(offset, tabChars), tabChars);
const char *string = fText->GetString(offset, numBytes);
view->DrawString(string);
if (foundTab) {
float penPos = PenLocation().x - fTextRect.left;
@ -3695,8 +3696,8 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, bool era
offset += tabChars;
length -= tabChars;
numChars -= tabChars;
tabChars = numChars;
numBytes -= tabChars;
tabChars = numBytes;
numTabs = 0;
} while (foundTab && tabChars > 0);
}

View File

@ -10,7 +10,10 @@
#include <cstdlib>
#include <cstring>
#include <utf8_functions.h>
#include <File.h>
#include <InterfaceDefs.h> // for B_UTF8_BULLET
#include "TextGapBuffer.h"
@ -166,15 +169,18 @@ _BTextGapBuffer_::SizeGapTo(long inCount)
const char *
_BTextGapBuffer_::GetString(int32 fromOffset, int32 numChars)
_BTextGapBuffer_::GetString(int32 fromOffset, int32 numBytes)
{
// numBytes won't necessarily be honored. This function could return more
// bytes than specified (for example when in password mode)
// TODO: Fix this, it's not very nice.
char *result = "";
if (numChars < 1)
return (result);
if (numBytes < 1)
return result;
bool isStartBeforeGap = (fromOffset < fGapIndex);
bool isEndBeforeGap = ((fromOffset + numChars - 1) < fGapIndex);
bool isEndBeforeGap = ((fromOffset + numBytes - 1) < fGapIndex);
if (isStartBeforeGap == isEndBeforeGap) {
result = fBuffer + fromOffset;
@ -182,17 +188,37 @@ _BTextGapBuffer_::GetString(int32 fromOffset, int32 numChars)
result += fGapCount;
} else {
if (fScratchSize < numChars) {
fScratchBuffer = (char *)realloc(fScratchBuffer, numChars);
fScratchSize = numChars;
if (fScratchSize < numBytes) {
fScratchBuffer = (char *)realloc(fScratchBuffer, numBytes);
fScratchSize = numBytes;
}
for (long i = 0; i < numChars; i++)
for (long i = 0; i < numBytes; i++)
fScratchBuffer[i] = (*this)[fromOffset + i];
result = fScratchBuffer;
}
// TODO: this could be improved. We are overwriting what we did some lines ago,
// we could just avoid to do that.
if (fPasswordMode) {
uint32 numChars = UTF8CountChars(result, numBytes);
uint32 charLen = UTF8CountBytes(B_UTF8_BULLET, 1);
uint32 newSize = numChars * charLen + 1;
if ((uint32)fScratchSize < newSize) {
fScratchBuffer = (char *)realloc(fScratchBuffer, newSize);
fScratchSize = newSize;
}
result = fScratchBuffer;
char *scratchPtr = result;
for (uint32 i = 0; i < numChars; i++) {
memcpy(scratchPtr, B_UTF8_BULLET, charLen);
scratchPtr += charLen;
}
scratchPtr = '\0';
}
return result;
}
@ -206,7 +232,7 @@ _BTextGapBuffer_::FindChar(char inChar, long fromIndex, long *ioDelta)
continue;
if ((*this)[fromIndex + i] == inChar) {
*ioDelta = i;
return (true);
return true;
}
}