- Some more error checking in some functions

- Fixed SetMaxBytes(), and made it delete the text if it's longer than the indicated bytes
- Fixed Delete(int32, int32) as it was doing bad things if you deleted the final part of the text
- Fixed PageDown handling (at least, it looks like so)


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8673 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2004-08-27 08:35:15 +00:00
parent 758fe00be9
commit 6276c26824
+42 -18
View File
@@ -854,6 +854,7 @@ BTextView::MessageReceived(BMessage *message)
} }
break; break;
} }
case B_SET_PROPERTY: case B_SET_PROPERTY:
case B_GET_PROPERTY: case B_GET_PROPERTY:
case B_COUNT_PROPERTIES: case B_COUNT_PROPERTIES:
@@ -944,8 +945,7 @@ BTextView::ResolveSpecifier(BMessage *message, int32 index,
target = this; target = this;
if (!target) if (!target)
target = BView::ResolveSpecifier(message, index, specifier, what, target = BView::ResolveSpecifier(message, index, specifier, what, property);
property);
return target; return target;
} }
@@ -1224,17 +1224,24 @@ BTextView::Delete(int32 startOffset, int32 endOffset)
// hide the caret/unhilite the selection // hide the caret/unhilite the selection
if (fActive) { if (fActive) {
if (startOffset != endOffset) if (fSelStart != fSelEnd)
Highlight(startOffset, endOffset); Highlight(fSelStart, fSelEnd);
else { else {
if (fCaretVisible) if (fCaretVisible)
InvertCaret(); InvertCaret();
} }
} }
// remove data from buffer // remove data from buffer
DeleteText(startOffset, endOffset); DeleteText(startOffset, endOffset);
// Check if the caret needs to be moved
if (fClickOffset >= endOffset)
fClickOffset -= (endOffset - startOffset);
else if (fClickOffset >= startOffset && fClickOffset < endOffset)
fClickOffset = startOffset;
fSelEnd = fSelStart = fClickOffset;
// recalc line breaks and draw what's left // recalc line breaks and draw what's left
Refresh(startOffset, endOffset, true, true); Refresh(startOffset, endOffset, true, true);
@@ -1298,6 +1305,9 @@ BTextView::ByteAt(int32 offset) const
} }
/*! \brief Returns the number of lines that the object contains.
\return The number of lines contained in the BTextView object.
*/
int32 int32
BTextView::CountLines() const BTextView::CountLines() const
{ {
@@ -1551,13 +1561,17 @@ void
BTextView::GetSelection(int32 *outStart, int32 *outEnd) const BTextView::GetSelection(int32 *outStart, int32 *outEnd) const
{ {
CALLED(); CALLED();
int32 start = 0, end = 0;
if (fSelectable) { if (fSelectable) {
*outStart = fSelStart; start = fSelStart;
*outEnd = fSelEnd; end = fSelEnd;
} else {
*outStart = 0;
*outEnd = 0;
} }
if (outStart)
*outStart = start;
if (outEnd)
*outEnd = end;
} }
@@ -1726,6 +1740,12 @@ BTextView::RunArray(int32 startOffset, int32 endOffset,
text_run_array *res = (text_run_array *)malloc(sizeof(int32) + text_run_array *res = (text_run_array *)malloc(sizeof(int32) +
(sizeof(text_run) * styleRange->count)); (sizeof(text_run) * styleRange->count));
if (!res) {
if (outSize)
*outSize = 0;
return NULL;
}
res->count = styleRange->count; res->count = styleRange->count;
for (int32 i = 0; i < res->count; i++) { for (int32 i = 0; i < res->count; i++) {
@@ -1998,6 +2018,7 @@ BTextView::FindWord(int32 inOffset, int32 *outFromOffset,
break; break;
} }
if (outFromOffset)
*outFromOffset = offset; *outFromOffset = offset;
// check to the right // check to the right
@@ -2007,6 +2028,7 @@ BTextView::FindWord(int32 inOffset, int32 *outFromOffset,
break; break;
} }
if (outToOffset)
*outToOffset = offset; *outToOffset = offset;
} }
@@ -2049,8 +2071,7 @@ BTextView::TextHeight(int32 startLine, int32 endLine) const
endLine = numLines - 1; endLine = numLines - 1;
// TODO: This looks broken as well. What do we do if there's only one line ? // TODO: This looks broken as well. What do we do if there's only one line ?
float height = (*fLines)[endLine + 1]->origin - float height = (*fLines)[endLine + 1]->origin - (*fLines)[startLine]->origin;
(*fLines)[startLine]->origin;
if (endLine == numLines - 1 && (*fText)[fText->Length() - 1] == '\n') if (endLine == numLines - 1 && (*fText)[fText->Length() - 1] == '\n')
height += (*fLines)[endLine + 1]->origin - (*fLines)[endLine]->origin; height += (*fLines)[endLine + 1]->origin - (*fLines)[endLine]->origin;
@@ -2065,6 +2086,9 @@ BTextView::GetTextRegion(int32 startOffset, int32 endOffset,
BRegion *outRegion) const BRegion *outRegion) const
{ {
CALLED(); CALLED();
if (!outRegion)
return;
outRegion->MakeEmpty(); outRegion->MakeEmpty();
// return an empty region if the range is invalid // return an empty region if the range is invalid
@@ -2355,10 +2379,11 @@ void
BTextView::SetMaxBytes(int32 max) BTextView::SetMaxBytes(int32 max)
{ {
CALLED(); CALLED();
// TODO: Finish this: int32 textLength = fText->Length();
// We probably have to check if the existing text is longer than the new
// fMaxBytes, and truncate if it's the case
fMaxBytes = max; fMaxBytes = max;
if (fMaxBytes < textLength)
Delete(fMaxBytes, textLength);
} }
@@ -3077,7 +3102,7 @@ BTextView::HandlePageKey(uint32 inPageKey)
if (ScrollBar(B_VERTICAL) != NULL) if (ScrollBar(B_VERTICAL) != NULL)
ScrollBar(B_VERTICAL)->SetValue(ScrollBar(B_VERTICAL)->Value() + delta); ScrollBar(B_VERTICAL)->SetValue(ScrollBar(B_VERTICAL)->Value() + delta);
fClickOffset = OffsetAt(LineAt(PointAt(currentOffset + delta))); fClickOffset = OffsetAt(LineAt(PointAt(currentOffset + delta)) + 1);
if (shiftDown) { if (shiftDown) {
if (fClickOffset >= fSelEnd) if (fClickOffset >= fSelEnd)
@@ -3648,9 +3673,8 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
rgb_color blue = {152, 203, 255}; rgb_color blue = {152, 203, 255};
//rgb_color red = {255, 152, 152}; //rgb_color red = {255, 152, 152};
SetHighColor(blue);
SetLowColor(blue); SetLowColor(blue);
FillRect(rect); FillRect(rect, B_SOLID_LOW);
PopState(); PopState();
} }