Added some comments, some small style changes, and some TODO items.

Simplified some code.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8458 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2004-07-23 09:58:25 +00:00
parent b87611aa33
commit 41e3acb043
+106 -53
View File
@@ -404,8 +404,8 @@ BTextView::Draw(BRect updateRect)
{ {
CALLED(); CALLED();
// what lines need to be drawn? // what lines need to be drawn?
long startLine = LineAt(BPoint(0.0f, updateRect.top)); int32 startLine = LineAt(BPoint(0.0f, updateRect.top));
long endLine = LineAt(BPoint(0.0f, updateRect.bottom)); int32 endLine = LineAt(BPoint(0.0f, updateRect.bottom));
DrawLines(startLine, endLine); DrawLines(startLine, endLine);
@@ -523,11 +523,9 @@ BTextView::MouseDown(BPoint where)
break; break;
case 2: case 2:
{
// double click, select word by word // double click, select word by word
FindWord(mouseOffset, &start, &end); FindWord(mouseOffset, &start, &end);
break; break;
}
default: default:
// new click, select char by char // new click, select char by char
@@ -942,7 +940,8 @@ BTextView::ResolveSpecifier(BMessage *message, int32 index,
return target; return target;
} }
//------------------------------------------------------------------------------
status_t status_t
BTextView::GetSupportedSuites(BMessage *data) BTextView::GetSupportedSuites(BMessage *data)
{ {
@@ -965,14 +964,16 @@ BTextView::GetSupportedSuites(BMessage *data)
return BView::GetSupportedSuites(data); return BView::GetSupportedSuites(data);
} }
//------------------------------------------------------------------------------
status_t status_t
BTextView::Perform(perform_code d, void *arg) BTextView::Perform(perform_code d, void *arg)
{ {
CALLED(); CALLED();
return BView::Perform(d, arg); return BView::Perform(d, arg);
} }
//------------------------------------------------------------------------------
void void
BTextView::SetText(const char *inText, const text_run_array *inRuns) BTextView::SetText(const char *inText, const text_run_array *inRuns)
{ {
@@ -1010,7 +1011,8 @@ BTextView::SetText(const char *inText, const text_run_array *inRuns)
InvertCaret(); InvertCaret();
} }
} }
//------------------------------------------------------------------------------
void void
BTextView::SetText(const char *inText, int32 inLength, BTextView::SetText(const char *inText, int32 inLength,
const text_run_array *inRuns) const text_run_array *inRuns)
@@ -1047,7 +1049,8 @@ BTextView::SetText(const char *inText, int32 inLength,
InvertCaret(); InvertCaret();
} }
} }
//------------------------------------------------------------------------------
void void
BTextView::SetText(BFile *inFile, int32 inOffset, int32 inLength, BTextView::SetText(BFile *inFile, int32 inOffset, int32 inLength,
const text_run_array *inRuns) const text_run_array *inRuns)
@@ -1090,14 +1093,16 @@ BTextView::SetText(BFile *inFile, int32 inOffset, int32 inLength,
InvertCaret(); InvertCaret();
} }
} }
//------------------------------------------------------------------------------
void void
BTextView::Insert(const char *inText, const text_run_array *inRuns) BTextView::Insert(const char *inText, const text_run_array *inRuns)
{ {
CALLED(); CALLED();
Insert(fSelStart, inText, strlen(inText), inRuns); Insert(fSelStart, inText, strlen(inText), inRuns);
} }
//------------------------------------------------------------------------------
void void
BTextView::Insert(const char *inText, int32 inLength, BTextView::Insert(const char *inText, int32 inLength,
const text_run_array *inRuns) const text_run_array *inRuns)
@@ -1105,7 +1110,8 @@ BTextView::Insert(const char *inText, int32 inLength,
CALLED(); CALLED();
Insert(fSelStart, inText, inLength, inRuns); Insert(fSelStart, inText, inLength, inRuns);
} }
//------------------------------------------------------------------------------
void void
BTextView::Insert(int32 startOffset, const char *inText, int32 inLength, BTextView::Insert(int32 startOffset, const char *inText, int32 inLength,
const text_run_array *inRuns) const text_run_array *inRuns)
@@ -1254,7 +1260,8 @@ BTextView::TextLength() const
CALLED(); CALLED();
return fText->Length(); return fText->Length();
} }
//------------------------------------------------------------------------------
void void
BTextView::GetText(int32 offset, int32 length, char *buffer) const BTextView::GetText(int32 offset, int32 length, char *buffer) const
{ {
@@ -1279,7 +1286,8 @@ BTextView::ByteAt(int32 offset) const
return (*fText)[offset]; return (*fText)[offset];
} }
//------------------------------------------------------------------------------
int32 int32
BTextView::CountLines() const BTextView::CountLines() const
{ {
@@ -1743,7 +1751,14 @@ BTextView::LineAt(BPoint point) const
CALLED(); CALLED();
return fLines->PixelToLine(point.y - fTextRect.top); return fLines->PixelToLine(point.y - fTextRect.top);
} }
//------------------------------------------------------------------------------
/*! \brief Returns the location of the charachter at the given offset.
\param inOffset The offset of the charachter.
\param outHeight Here the function will put the height of the charachter at the
given offset.
\return A BPoint which is the location of the charachter.
*/
BPoint BPoint
BTextView::PointAt(int32 inOffset, float *outHeight) const BTextView::PointAt(int32 inOffset, float *outHeight) const
{ {
@@ -1751,6 +1766,8 @@ BTextView::PointAt(int32 inOffset, float *outHeight) const
BPoint result; BPoint result;
int32 textLength = fText->Length(); int32 textLength = fText->Length();
int32 lineNum = LineAt(inOffset); int32 lineNum = LineAt(inOffset);
// TODO: This looks broken. line + 1 could go outside the line buffer
STELinePtr line = (*fLines)[lineNum]; STELinePtr line = (*fLines)[lineNum];
float height = (line + 1)->origin - line->origin; float height = (line + 1)->origin - line->origin;
@@ -1797,7 +1814,12 @@ BTextView::PointAt(int32 inOffset, float *outHeight) const
return result; return result;
} }
//------------------------------------------------------------------------------
/*! \brief Returns the offset for the given location.
\param point A BPoint which specify the wanted location.
\return The offset for the given point.
*/
int32 int32
BTextView::OffsetAt(BPoint point) const BTextView::OffsetAt(BPoint point) const
{ {
@@ -1922,7 +1944,12 @@ BTextView::OffsetAt(BPoint point) const
return offset; return offset;
} }
//------------------------------------------------------------------------------
/*! \brief Returns the offset of the given line.
\param line A line number.
\return The offset of the passed line.
*/
int32 int32
BTextView::OffsetAt(int32 line) const BTextView::OffsetAt(int32 line) const
{ {
@@ -1931,7 +1958,8 @@ BTextView::OffsetAt(int32 line) const
return (*fLines)[line]->offset; return (*fLines)[line]->offset;
} }
//------------------------------------------------------------------------------
void void
BTextView::FindWord(int32 inOffset, int32 *outFromOffset, BTextView::FindWord(int32 inOffset, int32 *outFromOffset,
int32 *outToOffset) int32 *outToOffset)
@@ -1969,10 +1997,8 @@ float
BTextView::LineWidth(int32 lineNum) const BTextView::LineWidth(int32 lineNum) const
{ {
CALLED(); CALLED();
if (lineNum < 0) if (lineNum < 0 || lineNum >= fLines->NumLines())
return (*fLines)[0]->width; return 0;
else if (lineNum > fLines->NumLines() - 1)
return (*fLines)[fLines->NumLines() - 1]->width;
else else
return (*fLines)[lineNum]->width; return (*fLines)[lineNum]->width;
} }
@@ -1982,12 +2008,7 @@ float
BTextView::LineHeight(int32 lineNum) const BTextView::LineHeight(int32 lineNum) const
{ {
CALLED(); CALLED();
if (lineNum < 0) return TextHeight(lineNum, lineNum);
return (*fLines)[0]->ascent;
else if (lineNum > fLines->NumLines() - 1)
return (*fLines)[fLines->NumLines() - 1]->ascent;
else
return (*fLines)[lineNum]->ascent;
} }
@@ -2005,6 +2026,7 @@ BTextView::TextHeight(int32 startLine, int32 endLine) const
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;
return height; return height;
} }
@@ -2059,7 +2081,8 @@ BTextView::GetTextRegion(int32 startOffset, int32 endOffset,
outRegion->Include(selRect); outRegion->Include(selRect);
} }
} }
//------------------------------------------------------------------------------
void void
BTextView::ScrollToOffset(int32 inOffset) BTextView::ScrollToOffset(int32 inOffset)
{ {
@@ -2079,7 +2102,8 @@ BTextView::ScrollToOffset(int32 inOffset)
ScrollBar(B_VERTICAL)->SetValue(point.y - (bounds.IntegerHeight() / 2)); ScrollBar(B_VERTICAL)->SetValue(point.y - (bounds.IntegerHeight() / 2));
} }
} }
//------------------------------------------------------------------------------
void void
BTextView::ScrollToSelection() BTextView::ScrollToSelection()
{ {
@@ -2107,7 +2131,8 @@ BTextView::Highlight(int32 startOffset, int32 endOffset)
FillRegion(&selRegion, B_SOLID_HIGH); FillRegion(&selRegion, B_SOLID_HIGH);
SetDrawingMode(B_OP_COPY); SetDrawingMode(B_OP_COPY);
} }
//------------------------------------------------------------------------------
void void
BTextView::SetTextRect(BRect rect) BTextView::SetTextRect(BRect rect)
{ {
@@ -2120,14 +2145,17 @@ BTextView::SetTextRect(BRect rect)
if (Window() != NULL) if (Window() != NULL)
Refresh(0, fLines->NumLines(), true, false); Refresh(0, fLines->NumLines(), true, false);
} }
//------------------------------------------------------------------------------
BRect BRect
BTextView::TextRect() const BTextView::TextRect() const
{ {
CALLED(); CALLED();
return fTextRect; return fTextRect;
} }
//------------------------------------------------------------------------------
void void
BTextView::SetStylable(bool stylable) BTextView::SetStylable(bool stylable)
{ {
@@ -2146,7 +2174,8 @@ BTextView::IsStylable() const
CALLED(); CALLED();
return fStylable; return fStylable;
} }
//------------------------------------------------------------------------------
void void
BTextView::SetTabWidth(float width) BTextView::SetTabWidth(float width)
{ {
@@ -2817,7 +2846,7 @@ BTextView::HandleArrowKey(uint32 inArrowKey)
fClickOffset = PreviousInitialByte(fClickOffset); fClickOffset = PreviousInitialByte(fClickOffset);
if (shiftDown) { if (shiftDown) {
if (fClickOffset > fSelStart) if (fClickOffset >= fSelStart)
selEnd = fClickOffset; selEnd = fClickOffset;
else else
selStart = fClickOffset; selStart = fClickOffset;
@@ -2832,7 +2861,7 @@ BTextView::HandleArrowKey(uint32 inArrowKey)
fClickOffset = NextInitialByte(fClickOffset); fClickOffset = NextInitialByte(fClickOffset);
if (shiftDown) { if (shiftDown) {
if (fClickOffset < fSelEnd) if (fClickOffset <= fSelEnd)
selStart = fClickOffset; selStart = fClickOffset;
else else
selEnd = fClickOffset; selEnd = fClickOffset;
@@ -2918,7 +2947,8 @@ BTextView::HandleDelete()
Refresh(fSelStart, fSelEnd, true, true); Refresh(fSelStart, fSelEnd, true, true);
} }
//------------------------------------------------------------------------------
void void
BTextView::HandlePageKey(uint32 inPageKey) BTextView::HandlePageKey(uint32 inPageKey)
{ {
@@ -2970,6 +3000,7 @@ BTextView::HandlePageKey(uint32 inPageKey)
case B_PAGE_UP: case B_PAGE_UP:
case B_PAGE_DOWN: case B_PAGE_DOWN:
// TODO: Fix this
{ {
if (ScrollBar(B_VERTICAL) != NULL) { if (ScrollBar(B_VERTICAL) != NULL) {
float delta = Bounds().Height(); float delta = Bounds().Height();
@@ -2980,7 +3011,8 @@ BTextView::HandlePageKey(uint32 inPageKey)
} }
} }
} }
//------------------------------------------------------------------------------
void void
BTextView::HandleAlphaKey(const char *bytes, int32 numBytes) BTextView::HandleAlphaKey(const char *bytes, int32 numBytes)
{ {
@@ -3101,7 +3133,8 @@ BTextView::Refresh(int32 fromOffset, int32 toOffset, bool erase,
Flush(); //// Flush(); ////
} }
//------------------------------------------------------------------------------
void void
BTextView::RecalLineBreaks(int32 *startLine, int32 *endLine) BTextView::RecalLineBreaks(int32 *startLine, int32 *endLine)
{ {
@@ -3175,7 +3208,8 @@ BTextView::RecalLineBreaks(int32 *startLine, int32 *endLine)
*endLine = lineIndex - 1; *endLine = lineIndex - 1;
*startLine = min_c(*startLine, *endLine); *startLine = min_c(*startLine, *endLine);
} }
//------------------------------------------------------------------------------
int32 int32
BTextView::FindLineBreak(int32 fromOffset, float *outAscent, BTextView::FindLineBreak(int32 fromOffset, float *outAscent,
float *outDescent, float *ioWidth) float *outDescent, float *ioWidth)
@@ -3410,7 +3444,8 @@ BTextView::ActualTabWidth(float location) const
CALLED(); CALLED();
return fTabWidth - fmod(location, fTabWidth); return fTabWidth - fmod(location, fTabWidth);
} }
//------------------------------------------------------------------------------
void void
BTextView::DoInsertText(const char *inText, int32 inLength, int32 inOffset, BTextView::DoInsertText(const char *inText, int32 inLength, int32 inOffset,
const text_run_array *inRuns, const text_run_array *inRuns,
@@ -3418,14 +3453,16 @@ BTextView::DoInsertText(const char *inText, int32 inLength, int32 inOffset,
{ {
CALLED(); CALLED();
} }
//------------------------------------------------------------------------------
void void
BTextView::DoDeleteText(int32 fromOffset, int32 toOffset, BTextView::DoDeleteText(int32 fromOffset, int32 toOffset,
_BTextChangeResult_ *outResult) _BTextChangeResult_ *outResult)
{ {
CALLED(); CALLED();
} }
//------------------------------------------------------------------------------
void void
BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
bool erase) bool erase)
@@ -3551,7 +3588,8 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
ConstrainClippingRegion(NULL); ConstrainClippingRegion(NULL);
} }
//------------------------------------------------------------------------------
void void
BTextView::DrawCaret(int32 offset) BTextView::DrawCaret(int32 offset)
{ {
@@ -3617,20 +3655,23 @@ BTextView::DragCaret(int32 offset)
fDragOffset = offset; fDragOffset = offset;
} }
//------------------------------------------------------------------------------
void void
BTextView::StopMouseTracking() BTextView::StopMouseTracking()
{ {
CALLED(); CALLED();
} }
//------------------------------------------------------------------------------
bool bool
BTextView::PerformMouseUp(BPoint where) BTextView::PerformMouseUp(BPoint where)
{ {
CALLED(); CALLED();
return false; return false;
} }
//------------------------------------------------------------------------------
bool BTextView::PerformMouseMoved(BPoint where, uint32 code) bool BTextView::PerformMouseMoved(BPoint where, uint32 code)
{ {
CALLED(); CALLED();
@@ -3703,7 +3744,14 @@ BTextView::InitiateDrag()
DragMessage(drag, dragRect, dragHandler); DragMessage(drag, dragRect, dragHandler);
} }
} }
//------------------------------------------------------------------------------
/*! \brief Called when some data is dropped on the view.
\param inMessage The message which has been dropped.
\param where The location where the message has been dropped.
\param offset ?
\return \c true if the message was handled, \c false if not.
*/
bool bool
BTextView::MessageDropped(BMessage *inMessage, BPoint where, BPoint offset) BTextView::MessageDropped(BMessage *inMessage, BPoint where, BPoint offset)
{ {
@@ -3928,8 +3976,10 @@ uint32
BTextView::CharClassification(int32 offset) const BTextView::CharClassification(int32 offset) const
{ {
CALLED(); CALLED();
// Should check against a list of characters containing also // TODO:Should check against a list of characters containing also
// japanese word breakers // japanese word breakers.
// And what about other languages ? Isn't there a better way to check
// for separator charachters ?
switch (fText->RealCharAt(offset)) { switch (fText->RealCharAt(offset)) {
case B_SPACE: case B_SPACE:
case '_': case '_':
@@ -3993,7 +4043,8 @@ BTextView::PreviousInitialByte(int32 offset) const
return count ? offset : 0; return count ? offset : 0;
} }
//------------------------------------------------------------------------------
bool bool
BTextView::GetProperty(BMessage *specifier, int32 form, BTextView::GetProperty(BMessage *specifier, int32 form,
const char *property, BMessage *reply) const char *property, BMessage *reply)
@@ -4029,7 +4080,8 @@ BTextView::GetProperty(BMessage *specifier, int32 form,
else else
return false; return false;
} }
//------------------------------------------------------------------------------
bool bool
BTextView::SetProperty(BMessage *specifier, int32 form, BTextView::SetProperty(BMessage *specifier, int32 form,
const char *property, BMessage *reply) const char *property, BMessage *reply)
@@ -4071,7 +4123,8 @@ BTextView::SetProperty(BMessage *specifier, int32 form,
else else
return false; return false;
} }
//------------------------------------------------------------------------------
bool bool
BTextView::CountProperties(BMessage *specifier, int32 form, BTextView::CountProperties(BMessage *specifier, int32 form,
const char *property, BMessage *reply) const char *property, BMessage *reply)