added a parameter to _BTextGapBuffer_::GetString() so that the caller knows how many bytes are really returned. password mode looks better now
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18965 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -3661,11 +3661,9 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, bool era
|
|||||||
view->PopState();
|
view->PopState();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *string = fText->GetString(offset, tabChars);
|
int32 returnedBytes = 0;
|
||||||
// TODO: GetString() could return less or more bytes than requested
|
const char *string = fText->GetString(offset, tabChars, &returnedBytes);
|
||||||
// Improve the backend api so it's more robust and pass back the returned
|
view->DrawString(string, returnedBytes);
|
||||||
// bytes
|
|
||||||
view->DrawString(string, tabChars);
|
|
||||||
|
|
||||||
if (foundTab) {
|
if (foundTab) {
|
||||||
float penPos = PenLocation().x - fTextRect.left;
|
float penPos = PenLocation().x - fTextRect.left;
|
||||||
|
|||||||
@@ -169,15 +169,15 @@ _BTextGapBuffer_::SizeGapTo(long inCount)
|
|||||||
|
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
_BTextGapBuffer_::GetString(int32 fromOffset, int32 numBytes)
|
_BTextGapBuffer_::GetString(int32 fromOffset, int32 numBytes, int32 *returnedBytes)
|
||||||
{
|
{
|
||||||
// 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 (numBytes < 1)
|
if (numBytes < 1) {
|
||||||
|
if (returnedBytes != NULL)
|
||||||
|
*returnedBytes = 0;
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool isStartBeforeGap = (fromOffset < fGapIndex);
|
bool isStartBeforeGap = (fromOffset < fGapIndex);
|
||||||
bool isEndBeforeGap = ((fromOffset + numBytes - 1) < fGapIndex);
|
bool isEndBeforeGap = ((fromOffset + numBytes - 1) < fGapIndex);
|
||||||
@@ -199,6 +199,9 @@ _BTextGapBuffer_::GetString(int32 fromOffset, int32 numBytes)
|
|||||||
result = fScratchBuffer;
|
result = fScratchBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (returnedBytes != NULL)
|
||||||
|
*returnedBytes = numBytes;
|
||||||
|
|
||||||
// TODO: this could be improved. We are overwriting what we did some lines ago,
|
// TODO: this could be improved. We are overwriting what we did some lines ago,
|
||||||
// we could just avoid to do that.
|
// we could just avoid to do that.
|
||||||
if (fPasswordMode) {
|
if (fPasswordMode) {
|
||||||
@@ -217,6 +220,8 @@ _BTextGapBuffer_::GetString(int32 fromOffset, int32 numBytes)
|
|||||||
scratchPtr += charLen;
|
scratchPtr += charLen;
|
||||||
}
|
}
|
||||||
scratchPtr = '\0';
|
scratchPtr = '\0';
|
||||||
|
if (returnedBytes != NULL)
|
||||||
|
*returnedBytes = newSize - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
|
|
||||||
class BFile;
|
class BFile;
|
||||||
// _BTextGapBuffer_ class ------------------------------------------------------
|
|
||||||
class _BTextGapBuffer_ {
|
class _BTextGapBuffer_ {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -27,32 +26,31 @@ virtual ~_BTextGapBuffer_();
|
|||||||
void MoveGapTo(int32 toIndex);
|
void MoveGapTo(int32 toIndex);
|
||||||
void SizeGapTo(int32 inCount);
|
void SizeGapTo(int32 inCount);
|
||||||
|
|
||||||
const char *GetString(int32 fromOffset, int32 numChars);
|
|
||||||
bool FindChar(char inChar, int32 fromIndex, int32 *ioDelta);
|
bool FindChar(char inChar, int32 fromIndex, int32 *ioDelta);
|
||||||
|
|
||||||
const char *Text();
|
const char *Text();
|
||||||
int32 Length() const;
|
int32 Length() const;
|
||||||
char operator[](int32 index) const;
|
char operator[](int32 index) const;
|
||||||
|
|
||||||
|
|
||||||
// char *RealText();
|
// char *RealText();
|
||||||
void GetString(int32 offset, int32 length, char *buffer);
|
const char *GetString(int32 fromOffset, int32 numBytes, int32 *returnedBytes);
|
||||||
// void GetString(int32, int32 *);
|
void GetString(int32 offset, int32 length, char *buffer);
|
||||||
|
|
||||||
char RealCharAt(int32 offset) const;
|
char RealCharAt(int32 offset) const;
|
||||||
|
|
||||||
bool PasswordMode() const;
|
bool PasswordMode() const;
|
||||||
void SetPasswordMode(bool);
|
void SetPasswordMode(bool);
|
||||||
|
|
||||||
// void Resize(int32 size);
|
// void Resize(int32 size);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int32 fExtraCount; // when realloc()-ing
|
int32 fExtraCount; // when realloc()-ing
|
||||||
int32 fItemCount; // logical count
|
int32 fItemCount; // logical count
|
||||||
char *fBuffer; // allocated memory
|
char *fBuffer; // allocated memory
|
||||||
int32 fBufferCount; // physical count
|
int32 fBufferCount; // physical count
|
||||||
int32 fGapIndex; // gap position
|
int32 fGapIndex; // gap position
|
||||||
int32 fGapCount; // gap count
|
int32 fGapCount; // gap count
|
||||||
char *fScratchBuffer; // for GetString
|
char *fScratchBuffer; // for GetString
|
||||||
int32 fScratchSize; // scratch size
|
int32 fScratchSize; // scratch size
|
||||||
bool fPasswordMode;
|
bool fPasswordMode;
|
||||||
|
|||||||
Reference in New Issue
Block a user