Uninlined the implementations of the inner classes. No functional change.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31175 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-06-22 01:30:55 +00:00
parent 7367310fbe
commit ce5d942c1a
+279 -155
View File
@@ -29,48 +29,20 @@ static const float kMinViewHeight = 80.0f;
class SourceView::BaseView : public BView { class SourceView::BaseView : public BView {
public: public:
BaseView(const char* name, SourceView* sourceView, FontInfo* fontInfo) BaseView(const char* name,
: SourceView* sourceView, FontInfo* fontInfo);
BView(name, B_WILL_DRAW | B_SUBPIXEL_PRECISE),
fSourceView(sourceView),
fFontInfo(fontInfo),
fSourceCode(NULL)
{
}
virtual void SetSourceCode(SourceCode* sourceCode) virtual void SetSourceCode(SourceCode* sourceCode);
{
fSourceCode = sourceCode;
InvalidateLayout(); virtual BSize PreferredSize();
Invalidate();
}
virtual BSize PreferredSize()
{
return MinSize();
}
protected: protected:
int32 LineCount() const inline int32 LineCount() const;
{
return fSourceCode != NULL ? fSourceCode->CountLines() : 0;
}
float TotalHeight() const inline float TotalHeight() const;
{
float height = LineCount() * fFontInfo->lineHeight - 1;
return std::max(height, kMinViewHeight);
}
void GetLineRange(BRect rect, int32& minLine, int32& maxLine) void GetLineRange(BRect rect, int32& minLine,
{ int32& maxLine);
int32 lineHeight = (int32)fFontInfo->lineHeight;
minLine = (int32)rect.top / lineHeight;
maxLine = ((int32)ceilf(rect.bottom) + lineHeight - 1) / lineHeight;
minLine = std::max(minLine, 0L);
maxLine = std::min(maxLine, fSourceCode->CountLines() - 1);
}
protected: protected:
@@ -82,7 +54,238 @@ protected:
class SourceView::MarkerView : public BaseView { class SourceView::MarkerView : public BaseView {
public: public:
MarkerView(SourceView* sourceView, FontInfo* fontInfo) MarkerView(SourceView* sourceView,
FontInfo* fontInfo);
~MarkerView();
virtual void SetSourceCode(SourceCode* sourceCode);
void SetStackTrace(StackTrace* stackTrace);
void SetStackFrame(StackFrame* stackFrame);
virtual BSize MinSize();
virtual BSize MaxSize();
virtual void Draw(BRect updateRect);
private:
struct Marker;
struct InstructionPointerMarker;
typedef BObjectList<Marker> MarkerList;
private:
void _UpdateMarkers();
private:
StackTrace* fStackTrace;
StackFrame* fStackFrame;
MarkerList fMarkers;
bool fMarkersValid;
};
struct SourceView::MarkerView::Marker {
Marker(uint32 line);
virtual ~Marker();
inline uint32 Line() const;
virtual void Draw(MarkerView* view, BRect rect) = 0;
private:
uint32 fLine;
};
struct SourceView::MarkerView::InstructionPointerMarker : Marker {
InstructionPointerMarker(uint32 line,
bool topIP, bool currentIP);
virtual void Draw(MarkerView* view, BRect rect);
private:
void _DrawArrow(BView* view, BPoint tip, BSize size,
BSize base, const rgb_color& color,
bool fill);
private:
bool fIsTopIP;
bool fIsCurrentIP;
};
class SourceView::TextView : public BaseView {
public:
TextView(SourceView* sourceView,
FontInfo* fontInfo);
virtual void SetSourceCode(SourceCode* sourceCode);
virtual BSize MinSize();
virtual BSize MaxSize();
virtual void Draw(BRect updateRect);
private:
float _MaxLineWidth();
private:
float fMaxLineWidth;
rgb_color fTextColor;
};
// #pragma mark - BaseView
SourceView::BaseView::BaseView(const char* name, SourceView* sourceView,
FontInfo* fontInfo)
:
BView(name, B_WILL_DRAW | B_SUBPIXEL_PRECISE),
fSourceView(sourceView),
fFontInfo(fontInfo),
fSourceCode(NULL)
{
}
void
SourceView::BaseView::SetSourceCode(SourceCode* sourceCode)
{
fSourceCode = sourceCode;
InvalidateLayout();
Invalidate();
}
BSize
SourceView::BaseView::PreferredSize()
{
return MinSize();
}
int32
SourceView::BaseView::LineCount() const
{
return fSourceCode != NULL ? fSourceCode->CountLines() : 0;
}
float
SourceView::BaseView::TotalHeight() const
{
float height = LineCount() * fFontInfo->lineHeight - 1;
return std::max(height, kMinViewHeight);
}
void
SourceView::BaseView::GetLineRange(BRect rect, int32& minLine, int32& maxLine)
{
int32 lineHeight = (int32)fFontInfo->lineHeight;
minLine = (int32)rect.top / lineHeight;
maxLine = ((int32)ceilf(rect.bottom) + lineHeight - 1) / lineHeight;
minLine = std::max(minLine, 0L);
maxLine = std::min(maxLine, fSourceCode->CountLines() - 1);
}
// #pragma mark - MarkerView::Marker
SourceView::MarkerView::Marker::Marker(uint32 line)
:
fLine(line)
{
}
SourceView::MarkerView::Marker::~Marker()
{
}
uint32
SourceView::MarkerView::Marker::Line() const
{
return fLine;
}
// #pragma mark - MarkerView::InstructionPointerMarker
SourceView::MarkerView::InstructionPointerMarker::InstructionPointerMarker(
uint32 line, bool topIP, bool currentIP)
:
Marker(line),
fIsTopIP(topIP),
fIsCurrentIP(currentIP)
{
}
void
SourceView::MarkerView::InstructionPointerMarker::Draw(MarkerView* view,
BRect rect)
{
// Get the arrow color -- for the top IP, if current, we use blue,
// otherwise a gray.
rgb_color color;
if (fIsCurrentIP && fIsTopIP) {
color.set_to(0, 0, 255, 255);
} else {
color = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_DARKEN_3_TINT);
}
// Draw a filled array for the current IP, otherwise just an
// outline.
BPoint tip(rect.right - 3.5f, floorf((rect.top + rect.bottom) / 2));
if (fIsCurrentIP) {
_DrawArrow(view, tip, BSize(10, 10), BSize(5, 5), color, true);
} else {
_DrawArrow(view, tip + BPoint(-0.5f, 0), BSize(9, 8),
BSize(5, 4), color, false);
}
}
void
SourceView::MarkerView::InstructionPointerMarker::_DrawArrow(BView* view,
BPoint tip, BSize size, BSize base, const rgb_color& color, bool fill)
{
view->SetHighColor(color);
float baseTop = tip.y - base.height / 2;
float baseBottom = tip.y + base.height / 2;
float top = tip.y - size.height / 2;
float bottom = tip.y + size.height / 2;
float left = tip.x - size.width;
float middle = left + base.width;
BPoint points[7];
points[0].Set(tip.x, tip.y);
points[1].Set(middle, top);
points[2].Set(middle, baseTop);
points[3].Set(left, baseTop);
points[4].Set(left, baseBottom);
points[5].Set(middle, baseBottom);
points[6].Set(middle, bottom);
if (fill)
view->FillPolygon(points, 7);
else
view->StrokePolygon(points, 7);
}
// #pragma mark - MarkerView
SourceView::MarkerView::MarkerView(SourceView* sourceView, FontInfo* fontInfo)
: :
BaseView("source marker view", sourceView, fontInfo), BaseView("source marker view", sourceView, fontInfo),
fStackTrace(NULL), fStackTrace(NULL),
@@ -93,18 +296,23 @@ public:
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
} }
~MarkerView()
SourceView::MarkerView::~MarkerView()
{ {
} }
virtual void SetSourceCode(SourceCode* sourceCode)
void
SourceView::MarkerView::SetSourceCode(SourceCode* sourceCode)
{ {
fMarkers.MakeEmpty(); fMarkers.MakeEmpty();
fMarkersValid = false; fMarkersValid = false;
BaseView::SetSourceCode(sourceCode); BaseView::SetSourceCode(sourceCode);
} }
void SetStackTrace(StackTrace* stackTrace)
void
SourceView::MarkerView::SetStackTrace(StackTrace* stackTrace)
{ {
fStackTrace = stackTrace; fStackTrace = stackTrace;
fMarkers.MakeEmpty(); fMarkers.MakeEmpty();
@@ -112,7 +320,9 @@ public:
Invalidate(); Invalidate();
} }
void SetStackFrame(StackFrame* stackFrame)
void
SourceView::MarkerView::SetStackFrame(StackFrame* stackFrame)
{ {
fStackFrame = stackFrame; fStackFrame = stackFrame;
fMarkers.MakeEmpty(); fMarkers.MakeEmpty();
@@ -120,17 +330,22 @@ public:
Invalidate(); Invalidate();
} }
virtual BSize MinSize()
BSize
SourceView::MarkerView::MinSize()
{ {
return BSize(40, TotalHeight()); return BSize(40, TotalHeight());
} }
virtual BSize MaxSize()
BSize
SourceView::MarkerView::MaxSize()
{ {
return BSize(MinSize().width, B_SIZE_UNLIMITED); return BSize(MinSize().width, B_SIZE_UNLIMITED);
} }
virtual void Draw(BRect updateRect) void
SourceView::MarkerView::Draw(BRect updateRect)
{ {
_UpdateMarkers(); _UpdateMarkers();
@@ -158,98 +373,9 @@ public:
// TODO: Draw possible breakpoint marks! // TODO: Draw possible breakpoint marks!
} }
private:
struct Marker {
Marker(uint32 line)
:
fLine(line)
{
}
virtual ~Marker() void
{ SourceView::MarkerView::_UpdateMarkers()
}
uint32 Line() const
{
return fLine;
}
virtual void Draw(MarkerView* view, BRect rect) = 0;
private:
uint32 fLine;
};
struct InstructionPointerMarker : Marker {
InstructionPointerMarker(uint32 line, bool topIP, bool currentIP)
:
Marker(line),
fIsTopIP(topIP),
fIsCurrentIP(currentIP)
{
}
virtual void Draw(MarkerView* view, BRect rect)
{
// Get the arrow color -- for the top IP, if current, we use blue,
// otherwise a gray.
rgb_color color;
if (fIsCurrentIP && fIsTopIP) {
color.set_to(0, 0, 255, 255);
} else {
color = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_DARKEN_3_TINT);
}
// Draw a filled array for the current IP, otherwise just an
// outline.
BPoint tip(rect.right - 3.5f, floorf((rect.top + rect.bottom) / 2));
if (fIsCurrentIP) {
_DrawArrow(view, tip, BSize(10, 10), BSize(5, 5), color, true);
} else {
_DrawArrow(view, tip + BPoint(-0.5f, 0), BSize(9, 8),
BSize(5, 4), color, false);
}
}
private:
void _DrawArrow(BView* view, BPoint tip, BSize size, BSize base,
const rgb_color& color, bool fill)
{
view->SetHighColor(color);
float baseTop = tip.y - base.height / 2;
float baseBottom = tip.y + base.height / 2;
float top = tip.y - size.height / 2;
float bottom = tip.y + size.height / 2;
float left = tip.x - size.width;
float middle = left + base.width;
BPoint points[7];
points[0].Set(tip.x, tip.y);
points[1].Set(middle, top);
points[2].Set(middle, baseTop);
points[3].Set(left, baseTop);
points[4].Set(left, baseBottom);
points[5].Set(middle, baseBottom);
points[6].Set(middle, bottom);
if (fill)
view->FillPolygon(points, 7);
else
view->StrokePolygon(points, 7);
}
private:
bool fIsTopIP;
bool fIsCurrentIP;
};
typedef BObjectList<Marker> MarkerList;
private:
void _UpdateMarkers()
{ {
if (fMarkersValid) if (fMarkersValid)
return; return;
@@ -280,17 +406,11 @@ private:
fMarkersValid = true; fMarkersValid = true;
} }
private:
StackTrace* fStackTrace; // #pragma mark - TextView
StackFrame* fStackFrame;
MarkerList fMarkers;
bool fMarkersValid;
};
class SourceView::TextView : public BaseView { SourceView::TextView::TextView(SourceView* sourceView, FontInfo* fontInfo)
public:
TextView(SourceView* sourceView, FontInfo* fontInfo)
: :
BaseView("source text view", sourceView, fontInfo), BaseView("source text view", sourceView, fontInfo),
fMaxLineWidth(-1) fMaxLineWidth(-1)
@@ -299,23 +419,31 @@ public:
fTextColor = ui_color(B_DOCUMENT_TEXT_COLOR); fTextColor = ui_color(B_DOCUMENT_TEXT_COLOR);
} }
virtual void SetSourceCode(SourceCode* sourceCode)
void
SourceView::TextView::SetSourceCode(SourceCode* sourceCode)
{ {
fMaxLineWidth = -1; fMaxLineWidth = -1;
BaseView::SetSourceCode(sourceCode); BaseView::SetSourceCode(sourceCode);
} }
virtual BSize MinSize()
BSize
SourceView::TextView::MinSize()
{ {
return BSize(kLeftTextMargin + _MaxLineWidth() - 1, TotalHeight()); return BSize(kLeftTextMargin + _MaxLineWidth() - 1, TotalHeight());
} }
virtual BSize MaxSize()
BSize
SourceView::TextView::MaxSize()
{ {
return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED); return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED);
} }
virtual void Draw(BRect updateRect)
void
SourceView::TextView::Draw(BRect updateRect)
{ {
if (fSourceCode == NULL) if (fSourceCode == NULL)
return; return;
@@ -334,8 +462,9 @@ public:
} }
} }
private:
float _MaxLineWidth() float
SourceView::TextView::_MaxLineWidth()
{ {
if (fMaxLineWidth >= 0) if (fMaxLineWidth >= 0)
return fMaxLineWidth; return fMaxLineWidth;
@@ -351,11 +480,6 @@ private:
return fMaxLineWidth; return fMaxLineWidth;
} }
private:
float fMaxLineWidth;
rgb_color fTextColor;
};
// #pragma mark - SourceView // #pragma mark - SourceView