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:
@@ -2438,16 +2438,16 @@ BTextView::DoesUndo() const
|
|||||||
void
|
void
|
||||||
BTextView::HideTyping(bool enabled)
|
BTextView::HideTyping(bool enabled)
|
||||||
{
|
{
|
||||||
CALLED();
|
if (enabled)
|
||||||
//TODO: Implement ?
|
Delete(0, fText->Length());
|
||||||
//fText->SetPasswordMode(enabled);
|
|
||||||
|
fText->SetPasswordMode(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BTextView::IsTypingHidden() const
|
BTextView::IsTypingHidden() const
|
||||||
{
|
{
|
||||||
CALLED();
|
|
||||||
return fText->PasswordMode();
|
return fText->PasswordMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3636,13 +3636,13 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, bool era
|
|||||||
long offset = startOffset != -1 ? startOffset : line->offset;
|
long offset = startOffset != -1 ? startOffset : line->offset;
|
||||||
const BFont *font = NULL;
|
const BFont *font = NULL;
|
||||||
const rgb_color *color = NULL;
|
const rgb_color *color = NULL;
|
||||||
int32 numChars;
|
int32 numBytes;
|
||||||
// iterate through each style on this line
|
// 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->SetFont(font);
|
||||||
view->SetHighColor(*color);
|
view->SetHighColor(*color);
|
||||||
|
|
||||||
tabChars = numChars;
|
tabChars = numBytes;
|
||||||
do {
|
do {
|
||||||
foundTab = fText->FindChar(B_TAB, offset, &tabChars);
|
foundTab = fText->FindChar(B_TAB, offset, &tabChars);
|
||||||
if (foundTab) {
|
if (foundTab) {
|
||||||
@@ -3650,7 +3650,7 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, bool era
|
|||||||
numTabs++;
|
numTabs++;
|
||||||
if ((*fText)[offset + tabChars + numTabs] != B_TAB)
|
if ((*fText)[offset + tabChars + numTabs] != B_TAB)
|
||||||
break;
|
break;
|
||||||
} while ((tabChars + numTabs) < numChars);
|
} while ((tabChars + numTabs) < numBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inputRegion.CountRects() > 0) {
|
if (inputRegion.CountRects() > 0) {
|
||||||
@@ -3680,7 +3680,8 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, bool era
|
|||||||
view->PopState();
|
view->PopState();
|
||||||
}
|
}
|
||||||
|
|
||||||
view->DrawString(fText->GetString(offset, tabChars), tabChars);
|
const char *string = fText->GetString(offset, numBytes);
|
||||||
|
view->DrawString(string);
|
||||||
|
|
||||||
if (foundTab) {
|
if (foundTab) {
|
||||||
float penPos = PenLocation().x - fTextRect.left;
|
float penPos = PenLocation().x - fTextRect.left;
|
||||||
@@ -3695,8 +3696,8 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, bool era
|
|||||||
|
|
||||||
offset += tabChars;
|
offset += tabChars;
|
||||||
length -= tabChars;
|
length -= tabChars;
|
||||||
numChars -= tabChars;
|
numBytes -= tabChars;
|
||||||
tabChars = numChars;
|
tabChars = numBytes;
|
||||||
numTabs = 0;
|
numTabs = 0;
|
||||||
} while (foundTab && tabChars > 0);
|
} while (foundTab && tabChars > 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,10 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include <utf8_functions.h>
|
||||||
|
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
|
#include <InterfaceDefs.h> // for B_UTF8_BULLET
|
||||||
|
|
||||||
#include "TextGapBuffer.h"
|
#include "TextGapBuffer.h"
|
||||||
|
|
||||||
@@ -166,15 +169,18 @@ _BTextGapBuffer_::SizeGapTo(long inCount)
|
|||||||
|
|
||||||
|
|
||||||
const char *
|
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 = "";
|
char *result = "";
|
||||||
|
|
||||||
if (numChars < 1)
|
if (numBytes < 1)
|
||||||
return (result);
|
return result;
|
||||||
|
|
||||||
bool isStartBeforeGap = (fromOffset < fGapIndex);
|
bool isStartBeforeGap = (fromOffset < fGapIndex);
|
||||||
bool isEndBeforeGap = ((fromOffset + numChars - 1) < fGapIndex);
|
bool isEndBeforeGap = ((fromOffset + numBytes - 1) < fGapIndex);
|
||||||
|
|
||||||
if (isStartBeforeGap == isEndBeforeGap) {
|
if (isStartBeforeGap == isEndBeforeGap) {
|
||||||
result = fBuffer + fromOffset;
|
result = fBuffer + fromOffset;
|
||||||
@@ -182,17 +188,37 @@ _BTextGapBuffer_::GetString(int32 fromOffset, int32 numChars)
|
|||||||
result += fGapCount;
|
result += fGapCount;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (fScratchSize < numChars) {
|
if (fScratchSize < numBytes) {
|
||||||
fScratchBuffer = (char *)realloc(fScratchBuffer, numChars);
|
fScratchBuffer = (char *)realloc(fScratchBuffer, numBytes);
|
||||||
fScratchSize = numChars;
|
fScratchSize = numBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (long i = 0; i < numChars; i++)
|
for (long i = 0; i < numBytes; i++)
|
||||||
fScratchBuffer[i] = (*this)[fromOffset + i];
|
fScratchBuffer[i] = (*this)[fromOffset + i];
|
||||||
|
|
||||||
result = fScratchBuffer;
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +232,7 @@ _BTextGapBuffer_::FindChar(char inChar, long fromIndex, long *ioDelta)
|
|||||||
continue;
|
continue;
|
||||||
if ((*this)[fromIndex + i] == inChar) {
|
if ((*this)[fromIndex + i] == inChar) {
|
||||||
*ioDelta = i;
|
*ioDelta = i;
|
||||||
return (true);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user