From 92194962f6ef41d4b67f1052aa43e987d77b6579 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 3 Jul 2009 00:34:48 +0000 Subject: [PATCH] Display tabs correctly (hardcoded as 4 spaces ATM). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31381 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../debugger/gui/team_window/SourceView.cpp | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/apps/debugger/gui/team_window/SourceView.cpp b/src/apps/debugger/gui/team_window/SourceView.cpp index ea3f327187..cee30f31af 100644 --- a/src/apps/debugger/gui/team_window/SourceView.cpp +++ b/src/apps/debugger/gui/team_window/SourceView.cpp @@ -28,6 +28,8 @@ static const int32 kLeftTextMargin = 3; static const float kMinViewHeight = 80.0f; +static const int32 kSpacesPerTab = 4; + // TODO: Should be settable! class SourceView::BaseView : public BView { @@ -204,6 +206,8 @@ public: private: float _MaxLineWidth(); + void _FormatLine(const char* line, + BString& formattedLine); private: float fMaxLineWidth; @@ -811,7 +815,9 @@ SourceView::TextView::Draw(BRect updateRect) for (int32 i = minLine; i <= maxLine; i++) { float y = (float)(i + 1) * fFontInfo->lineHeight - fFontInfo->fontHeight.descent; - DrawString(fSourceCode->LineAt(i), BPoint(kLeftTextMargin, y)); + BString lineString; + _FormatLine(fSourceCode->LineAt(i), lineString); + DrawString(lineString, BPoint(kLeftTextMargin, y)); } } @@ -834,6 +840,24 @@ SourceView::TextView::_MaxLineWidth() } +void +SourceView::TextView::_FormatLine(const char* line, BString& formattedLine) +{ + int32 column = 0; + for (; *line != '\0'; line++) { + // TODO: That's probably not very efficient! + if (*line == '\t') { + int32 nextTabStop = (column / kSpacesPerTab + 1) * kSpacesPerTab; + for (; column < nextTabStop; column++) + formattedLine << ' '; + } else { + formattedLine << *line; + column++; + } + } +} + + // #pragma mark - SourceView