Uncommented the code which makes auto indenting possible.

Correctly maintain fClickOffset in SetText().
Some small style fixes.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8988 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2004-09-17 10:16:06 +00:00
parent 08acc659ec
commit 7575ec2d87
+48 -26
View File
@@ -271,8 +271,8 @@ BTextView::BTextView(BMessage *archive)
ssize_t runSize = 0; ssize_t runSize = 0;
const void *flattenedRun = NULL; const void *flattenedRun = NULL;
if (archive->FindData("_runs", B_RAW_TYPE, &flattenedRun, &runSize) == B_OK) {
if (archive->FindData("_runs", B_RAW_TYPE, &flattenedRun, &runSize) == B_OK) {
text_run_array *runArray = UnflattenRunArray(flattenedRun, (int32 *)&runSize); text_run_array *runArray = UnflattenRunArray(flattenedRun, (int32 *)&runSize);
if (runArray) { if (runArray) {
SetRunArray(0, TextLength(), runArray); SetRunArray(0, TextLength(), runArray);
@@ -540,12 +540,14 @@ BTextView::MouseDown(BPoint where)
// new click, select char by char // new click, select char by char
break; break;
} }
if (shiftDown) { if (shiftDown) {
if (mouseOffset > anchor) if (mouseOffset > anchor)
start = anchor; start = anchor;
else else
end = anchor; end = anchor;
} }
Select(start, end); Select(start, end);
// Should we scroll the view? // Should we scroll the view?
@@ -840,11 +842,9 @@ BTextView::MessageReceived(BMessage *message)
} }
case B_INPUT_METHOD_STOPPED: case B_INPUT_METHOD_STOPPED:
{
delete fInline; delete fInline;
fInline = NULL; fInline = NULL;
break; break;
}
case B_INPUT_METHOD_CHANGED: case B_INPUT_METHOD_CHANGED:
HandleInputMethodChanged(message); HandleInputMethodChanged(message);
@@ -968,13 +968,13 @@ BTextView::GetSupportedSuites(BMessage *data)
err = data->AddString("suites", "suite/vnd.Be-text-view"); err = data->AddString("suites", "suite/vnd.Be-text-view");
if (err != B_OK) if (err < B_OK)
return err; return err;
BPropertyInfo prop_info(sPropertyList); BPropertyInfo prop_info(sPropertyList);
err = data->AddFlat("messages", &prop_info); err = data->AddFlat("messages", &prop_info);
if (err != B_OK) if (err < B_OK)
return err; return err;
return BView::GetSupportedSuites(data); return BView::GetSupportedSuites(data);
@@ -1015,7 +1015,7 @@ BTextView::SetText(const char *inText, const text_run_array *inRuns)
if (inText != NULL && len > 0) if (inText != NULL && len > 0)
InsertText(inText, len, 0, inRuns); InsertText(inText, len, 0, inRuns);
fSelStart = fSelEnd = 0; fClickOffset = fSelStart = fSelEnd = 0;
// recalc line breaks and draw the text // recalc line breaks and draw the text
Refresh(0, len, true, true); Refresh(0, len, true, true);
@@ -1053,7 +1053,7 @@ BTextView::SetText(const char *inText, int32 inLength,
if (inText != NULL && inLength > 0) if (inText != NULL && inLength > 0)
InsertText(inText, inLength, 0, inRuns); InsertText(inText, inLength, 0, inRuns);
fSelStart = fSelEnd = 0; fClickOffset = fSelStart = fSelEnd = 0;
// recalc line breaks and draw the text // recalc line breaks and draw the text
Refresh(0, inLength, true, true); Refresh(0, inLength, true, true);
@@ -1289,10 +1289,8 @@ void
BTextView::GetText(int32 offset, int32 length, char *buffer) const BTextView::GetText(int32 offset, int32 length, char *buffer) const
{ {
CALLED(); CALLED();
if (buffer == NULL) if (buffer != NULL)
return; fText->GetString(offset, length, buffer);
fText->GetString(offset, length, buffer);
} }
@@ -2047,6 +2045,9 @@ BTextView::CanEndLine(int32 offset)
} }
/*! \brief Returns the width of the line at the given index.
\param lineNum A line index.
*/
float float
BTextView::LineWidth(int32 lineNum) const BTextView::LineWidth(int32 lineNum) const
{ {
@@ -2058,6 +2059,9 @@ BTextView::LineWidth(int32 lineNum) const
} }
/*! \brief Returns the height of the line at the given index.
\param lineNum A line index.
*/
float float
BTextView::LineHeight(int32 lineNum) const BTextView::LineHeight(int32 lineNum) const
{ {
@@ -2066,6 +2070,10 @@ BTextView::LineHeight(int32 lineNum) const
} }
/*! \brief Returns the height of the text comprised between the two given lines.
\param startLine The index of the starting line.
\param endLine The index of the ending line.
*/
float float
BTextView::TextHeight(int32 startLine, int32 endLine) const BTextView::TextHeight(int32 startLine, int32 endLine) const
{ {
@@ -2206,7 +2214,6 @@ BTextView::SetTextRect(BRect rect)
} }
BRect BRect
BTextView::TextRect() const BTextView::TextRect() const
{ {
@@ -2701,7 +2708,8 @@ BTextView::UnflattenRunArray(const void *data, int32 *outSize)
return run_array; return run_array;
} }
//------------------------------------------------------------------------------
void void
BTextView::InsertText(const char *inText, int32 inLength, int32 inOffset, BTextView::InsertText(const char *inText, int32 inLength, int32 inOffset,
const text_run_array *inRuns) const text_run_array *inRuns)
@@ -2730,7 +2738,8 @@ BTextView::InsertText(const char *inText, int32 inLength, int32 inOffset,
fText->Length(), B_FONT_ALL, NULL, NULL); fText->Length(), B_FONT_ALL, NULL, NULL);
} }
} }
//------------------------------------------------------------------------------
void void
BTextView::DeleteText(int32 fromOffset, int32 toOffset) BTextView::DeleteText(int32 fromOffset, int32 toOffset)
{ {
@@ -2752,7 +2761,11 @@ BTextView::DeleteText(int32 fromOffset, int32 toOffset)
// remove any style runs that have been obliterated // remove any style runs that have been obliterated
fStyles->RemoveStyleRange(fromOffset, toOffset); fStyles->RemoveStyleRange(fromOffset, toOffset);
} }
//------------------------------------------------------------------------------
/*! \brief Undoes the last changes.
\param clipboard A clipboard to use for the undo operation.
*/
void void
BTextView::Undo(BClipboard *clipboard) BTextView::Undo(BClipboard *clipboard)
{ {
@@ -2760,14 +2773,16 @@ BTextView::Undo(BClipboard *clipboard)
if (fUndo) if (fUndo)
fUndo->Undo(clipboard); fUndo->Undo(clipboard);
} }
//------------------------------------------------------------------------------
undo_state undo_state
BTextView::UndoState(bool *isRedo) const BTextView::UndoState(bool *isRedo) const
{ {
CALLED(); CALLED();
return fUndo == NULL ? B_UNDO_UNAVAILABLE : fUndo->State(isRedo); return fUndo == NULL ? B_UNDO_UNAVAILABLE : fUndo->State(isRedo);
} }
//------------------------------------------------------------------------------
void void
BTextView::GetDragParameters(BMessage *drag, BBitmap **bitmap, BTextView::GetDragParameters(BMessage *drag, BBitmap **bitmap,
BPoint *point, BHandler **handler) BPoint *point, BHandler **handler)
@@ -2798,7 +2813,8 @@ BTextView::GetDragParameters(BMessage *drag, BBitmap **bitmap,
if (handler != NULL) if (handler != NULL)
*handler = NULL; *handler = NULL;
} }
//------------------------------------------------------------------------------
void BTextView::_ReservedTextView3() {} void BTextView::_ReservedTextView3() {}
void BTextView::_ReservedTextView4() {} void BTextView::_ReservedTextView4() {}
void BTextView::_ReservedTextView5() {} void BTextView::_ReservedTextView5() {}
@@ -3029,6 +3045,9 @@ BTextView::HandleDelete()
} }
/*! \brief Called when a "Page key" is pressed.
\param inPageKey The page key which has been pressed.
*/
void void
BTextView::HandlePageKey(uint32 inPageKey) BTextView::HandlePageKey(uint32 inPageKey)
{ {
@@ -3124,6 +3143,10 @@ BTextView::HandlePageKey(uint32 inPageKey)
} }
/*! \brief Called when an alphanumeric key is pressed.
\param bytes The string or charachter associated with the key.
\param numBytes The amount of bytes containes in "bytes".
*/
void void
BTextView::HandleAlphaKey(const char *bytes, int32 numBytes) BTextView::HandleAlphaKey(const char *bytes, int32 numBytes)
{ {
@@ -3145,23 +3168,21 @@ BTextView::HandleAlphaKey(const char *bytes, int32 numBytes)
refresh = true; refresh = true;
} }
/* if (fAutoindent && numBytes == 1 && *bytes == B_ENTER) if (fAutoindent && numBytes == 1 && *bytes == B_ENTER) {
{
int32 start, offset; int32 start, offset;
start = offset = OffsetAt(LineAt(fSelStart)); start = offset = OffsetAt(LineAt(fSelStart));
const char *text = Text();
while (*(text + offset) != '\0' && while (ByteAt(offset) != '\0' &&
*(text + offset) == B_TAB || *(text + offset) == B_SPACE) (ByteAt(offset) == B_TAB || ByteAt(offset) == B_SPACE))
offset++; offset++;
if (start != offset) if (start != offset)
InsertText(text + start, offset - start, fSelStart, NULL); InsertText(Text() + start, offset - start, fSelStart, NULL);
InsertText(bytes, numBytes, fSelStart, NULL); InsertText(bytes, numBytes, fSelStart, NULL);
numBytes += offset - start; numBytes += offset - start;
}
else*/ } else
InsertText(bytes, numBytes, fSelStart, NULL); InsertText(bytes, numBytes, fSelStart, NULL);
fClickOffset = fSelEnd = fSelStart = fSelStart + numBytes; fClickOffset = fSelEnd = fSelStart = fSelStart + numBytes;
@@ -3620,6 +3641,7 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
eraseRect = clipRect; eraseRect = clipRect;
} }
for (long i = startLine; i <= endLine; i++) { for (long i = startLine; i <= endLine; i++) {
long length = (line + 1)->offset - line->offset; long length = (line + 1)->offset - line->offset;
// DrawString() chokes if you draw a newline // DrawString() chokes if you draw a newline