diff --git a/src/kits/interface/BTextView/LineBuffer.h b/src/kits/interface/BTextView/LineBuffer.h index 6206deee3e..d7beaff9a2 100644 --- a/src/kits/interface/BTextView/LineBuffer.h +++ b/src/kits/interface/BTextView/LineBuffer.h @@ -27,15 +27,12 @@ #include #include "TextViewSupportBuffer.h" -// It's important that this struct remains as is, -// as it's the way it is in BeOS, and if we change it, -// it would lead to some issues as long as we use "mixed" libraries. typedef struct STELine { long offset; // offset of first character of line float origin; // pixel position of top of line float ascent; // maximum ascent for line float width; // not used for now, but could be -} STELine, *STELinePtr; +} STELine; // _BLineBuffer_ class --------------------------------------------------------- @@ -56,7 +53,7 @@ virtual ~_BLineBuffer_(); void BumpOffset(int32 delta, int32 index); long NumLines() const; - const STELinePtr operator[](int32 index) const; + STELine * operator[](int32 index) const; }; @@ -67,7 +64,7 @@ _BLineBuffer_::NumLines() const } -inline const STELinePtr +inline STELine * _BLineBuffer_::operator[](int32 index) const { return &fBuffer[index]; diff --git a/src/kits/interface/BTextView/StyleBuffer.cpp b/src/kits/interface/BTextView/StyleBuffer.cpp index 2297260c7f..43af2c9978 100644 --- a/src/kits/interface/BTextView/StyleBuffer.cpp +++ b/src/kits/interface/BTextView/StyleBuffer.cpp @@ -143,11 +143,8 @@ _BStyleRecordBuffer_::MatchRecord(const BFont *inFont, const rgb_color *inColor, int32 *outIndex) { for (int32 i = 0; i < fItemCount; i++) { - if (*inFont == fBuffer[i].style.font - && inColor->red == fBuffer[i].style.color.red - && inColor->green == fBuffer[i].style.color.green - && inColor->blue == fBuffer[i].style.color.blue - && inColor->alpha == fBuffer[i].style.color.alpha) { + if (*inFont == fBuffer[i].style.font + && *inColor == fBuffer[i].style.color) { *outIndex = i; return true; } @@ -185,7 +182,7 @@ _BStyleBuffer_::IsValidNullStyle() const void _BStyleBuffer_::SyncNullStyle(int32 offset) { - if ((fValidNullStyle) || (fStyleRunDesc.ItemCount() < 1)) + if (fValidNullStyle || fStyleRunDesc.ItemCount() < 1) return; int32 index = OffsetToRun(offset); @@ -199,7 +196,7 @@ void _BStyleBuffer_::SetNullStyle(uint32 inMode, const BFont *inFont, const rgb_color *inColor, int32 offset) { - if ((fValidNullStyle) || (fStyleRunDesc.ItemCount() < 1)) + if (fValidNullStyle || fStyleRunDesc.ItemCount() < 1) SetStyle(inMode, inFont, &fNullStyle.font, inColor, &fNullStyle.color); else { int32 index = OffsetToRun(offset - 1); @@ -329,16 +326,15 @@ _BStyleBuffer_::GetStyle(int32 inOffset, BFont *outFont, rgb_color *outColor) co STEStyleRange* _BStyleBuffer_::GetStyleRange(int32 startOffset, int32 endOffset) const { - STEStyleRange* result = NULL; - int32 startIndex = OffsetToRun(startOffset); int32 endIndex = OffsetToRun(endOffset); int32 numStyles = endIndex - startIndex + 1; - numStyles = (numStyles < 1) ? 1 : numStyles; + if (numStyles < 1) + numStyles = 1; - result = (STEStyleRange*)malloc(sizeof(int32) - + sizeof(STEStyleRun) * numStyles); + STEStyleRange* result = (STEStyleRange *)malloc(sizeof(int32) + + sizeof(STEStyleRun) * numStyles); if (!result) return NULL; @@ -348,7 +344,8 @@ _BStyleBuffer_::GetStyleRange(int32 startOffset, int32 endOffset) const for (int32 index = 0; index < numStyles; index++) { *run = (*this)[startIndex + index]; run->offset -= startOffset; - run->offset = (run->offset < 0) ? 0 : run->offset; + if (run->offset < 0) + run->offset = 0; run++; } @@ -394,9 +391,8 @@ _BStyleBuffer_::RemoveStyleRange(int32 fromOffset, int32 toOffset) void _BStyleBuffer_::RemoveStyles(int32 index, int32 count) { - for (int32 i = index; i < (index + count); i++) { + for (int32 i = index; i < (index + count); i++) fStyleRecord.RemoveRecord(fStyleRunDesc[i]->index); - } fStyleRunDesc.RemoveDescs(index, count); } @@ -449,9 +445,8 @@ _BStyleBuffer_::BumpOffset(int32 delta, int32 index) void -_BStyleBuffer_::SetStyle(uint32 mode, const BFont *fromFont, - BFont *toFont, const rgb_color *fromColor, - rgb_color *toColor) +_BStyleBuffer_::SetStyle(uint32 mode, const BFont *fromFont, BFont *toFont, + const rgb_color *fromColor, rgb_color *toColor) { if (mode & B_FONT_FAMILY_AND_STYLE) toFont->SetFamilyAndStyle(fromFont->FamilyAndStyle()); @@ -545,10 +540,7 @@ _BStyleBuffer_::ContinuousGetStyle(BFont *outFont, uint32 *ioMode, mode &= ~B_FONT_SHEAR; } - if (theStyle.color.red != style->color.red - || theStyle.color.green != style->color.green - || theStyle.color.blue != style->color.blue - || theStyle.color.alpha != style->color.alpha) + if (theStyle.color != style->color) oneColor = false; // TODO: Finish this: handle B_FONT_FACE, B_FONT_FLAGS, etc. diff --git a/src/kits/interface/BTextView/TextView.cpp b/src/kits/interface/BTextView/TextView.cpp index 69b0fb70b7..9971096c5d 100644 --- a/src/kits/interface/BTextView/TextView.cpp +++ b/src/kits/interface/BTextView/TextView.cpp @@ -615,7 +615,6 @@ void BTextView::MouseMoved(BPoint where, uint32 code, const BMessage *message) { // Check if it's a "click'n'move - // TODO: Currently always returns false if (PerformMouseMoved(where, code)) return; @@ -1542,22 +1541,7 @@ void BTextView::SetFontAndColor(const BFont *inFont, uint32 inMode, const rgb_color *inColor) { - CALLED(); - CancelInputMethod(); - - BFont newFont = *inFont; - NormalizeFont(&newFont); - - // add the style to the style buffer - fStyles->SetStyleRange(fSelStart, fSelEnd, fText->Length(), - inMode, &newFont, inColor); - - if (inMode & B_FONT_FAMILY_AND_STYLE || inMode & B_FONT_SIZE) - // recalc the line breaks and redraw with new style - Refresh(fSelStart, fSelEnd, fSelStart != fSelEnd, false); - else - // the line breaks wont change, simply redraw - DrawLines(LineAt(fSelStart), LineAt(fSelEnd), fSelStart, true); + SetFontAndColor(fSelStart, fSelEnd, inFont, inMode, inColor); } @@ -1586,8 +1570,7 @@ BTextView::SetFontAndColor(int32 startOffset, int32 endOffset, void -BTextView::GetFontAndColor(int32 inOffset, BFont *outFont, - rgb_color *outColor) const +BTextView::GetFontAndColor(int32 inOffset, BFont *outFont, rgb_color *outColor) const { CALLED(); fStyles->GetStyle(inOffset, outFont, outColor); @@ -1595,36 +1578,42 @@ BTextView::GetFontAndColor(int32 inOffset, BFont *outFont, void -BTextView::GetFontAndColor(BFont *outFont, uint32 *outMode, - rgb_color *outColor, bool *outEqColor) const +BTextView::GetFontAndColor(BFont *outFont, uint32 *outMode, rgb_color *outColor, bool *outEqColor) const { CALLED(); - fStyles->ContinuousGetStyle(outFont, outMode, outColor, outEqColor, - fSelStart, fSelEnd); + fStyles->ContinuousGetStyle(outFont, outMode, outColor, outEqColor, fSelStart, fSelEnd); } void -BTextView::SetRunArray(int32 startOffset, int32 endOffset, - const text_run_array *inRuns) +BTextView::SetRunArray(int32 startOffset, int32 endOffset, const text_run_array *inRuns) { CALLED(); - + if (startOffset > endOffset) + return; + CancelInputMethod(); + int32 textLength = fText->Length(); + // pin offsets at reasonable values - startOffset = (startOffset < 0) ? 0 : startOffset; - endOffset = (endOffset < 0) ? 0 : endOffset; - endOffset = (endOffset > fText->Length()) ? fText->Length() : endOffset; + if (startOffset < 0) + startOffset = 0; + else if (startOffset > textLength) + startOffset = textLength; + + if (endOffset < 0) + endOffset = 0; + else if (endOffset > textLength) + endOffset = textLength; long numStyles = inRuns->count; if (numStyles > 0) { - int32 textLength = fText->Length(); const text_run *theRun = &inRuns->runs[0]; for (long index = 0; index < numStyles; index++) { long fromOffset = theRun->offset + startOffset; long toOffset = endOffset; - if ((index + 1) < numStyles) { + if (index + 1 < numStyles) { toOffset = (theRun + 1)->offset + startOffset; toOffset = (toOffset > endOffset) ? endOffset : toOffset; } @@ -2027,10 +2016,9 @@ BTextView::LineWidth(int32 lineNum) const { if (lineNum < 0 || lineNum >= fLines->NumLines()) return 0; - else { - STELine* line = (*fLines)[lineNum]; - return StyledWidth(line->offset, (line + 1)->offset - line->offset); - } + + STELine* line = (*fLines)[lineNum]; + return StyledWidth(line->offset, (line + 1)->offset - line->offset); } @@ -2062,9 +2050,7 @@ BTextView::TextHeight(int32 startLine, int32 endLine) const if (endLine == numLines - 1 && (*fText)[fText->Length() - 1] == '\n') height += (*fLines)[endLine + 1]->origin - (*fLines)[endLine]->origin; - height = ceil(height); - - return height; + return ceil(height); } @@ -2779,8 +2765,7 @@ BTextView::UndoState(bool *isRedo) const void -BTextView::GetDragParameters(BMessage *drag, BBitmap **bitmap, - BPoint *point, BHandler **handler) +BTextView::GetDragParameters(BMessage *drag, BBitmap **bitmap, BPoint *point, BHandler **handler) { CALLED(); if (drag == NULL) @@ -3542,9 +3527,7 @@ BTextView::FindLineBreak(int32 fromOffset, float *outAscent, } } - offset = min_c(offset, limit); - - return offset; + return min_c(offset, limit); } @@ -3616,16 +3599,14 @@ BTextView::DoInsertText(const char *inText, int32 inLength, int32 inOffset, void -BTextView::DoDeleteText(int32 fromOffset, int32 toOffset, - _BTextChangeResult_ *outResult) +BTextView::DoDeleteText(int32 fromOffset, int32 toOffset, _BTextChangeResult_ *outResult) { CALLED(); } void -BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, - bool erase) +BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset, bool erase) { // clip the text BRect clipRect = Bounds() & fTextRect; @@ -3955,10 +3936,8 @@ void BTextView::TrackDrag(BPoint where) { CALLED(); - if (Bounds().Contains(where)) { - int32 offset = OffsetAt(where); - DragCaret(offset); - } + if (Bounds().Contains(where)) + DragCaret(OffsetAt(where)); } @@ -4460,7 +4439,7 @@ BTextView::HandleInputMethodLocationRequest() return; int32 offset = fInline->Offset(); - int32 limit = offset + fInline->Length(); + const int32 limit = offset + fInline->Length(); BMessage message(B_INPUT_METHOD_EVENT); message.AddInt32("be:opcode", B_INPUT_METHOD_LOCATION_REQUEST);