[Haiku-commits] r31175 - haiku/trunk/src/apps/debugger/gui/team_window
bonefish at BerliOS
bonefish at mail.berlios.de
Mon Jun 22 03:30:56 CEST 2009
Author: bonefish
Date: 2009-06-22 03:30:55 +0200 (Mon, 22 Jun 2009)
New Revision: 31175
ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=31175&view=rev
Modified:
haiku/trunk/src/apps/debugger/gui/team_window/SourceView.cpp
Log:
Uninlined the implementations of the inner classes. No functional change.
Modified: haiku/trunk/src/apps/debugger/gui/team_window/SourceView.cpp
===================================================================
--- haiku/trunk/src/apps/debugger/gui/team_window/SourceView.cpp 2009-06-22 01:13:57 UTC (rev 31174)
+++ haiku/trunk/src/apps/debugger/gui/team_window/SourceView.cpp 2009-06-22 01:30:55 UTC (rev 31175)
@@ -29,332 +29,456 @@
class SourceView::BaseView : public BView {
public:
- BaseView(const char* name, SourceView* sourceView, FontInfo* fontInfo)
- :
- BView(name, B_WILL_DRAW | B_SUBPIXEL_PRECISE),
- fSourceView(sourceView),
- fFontInfo(fontInfo),
- fSourceCode(NULL)
- {
- }
+ BaseView(const char* name,
+ SourceView* sourceView, FontInfo* fontInfo);
- virtual void SetSourceCode(SourceCode* sourceCode)
- {
- fSourceCode = sourceCode;
+ virtual void SetSourceCode(SourceCode* sourceCode);
- InvalidateLayout();
- Invalidate();
- }
+ virtual BSize PreferredSize();
- virtual BSize PreferredSize()
- {
- return MinSize();
- }
-
protected:
- int32 LineCount() const
- {
- return fSourceCode != NULL ? fSourceCode->CountLines() : 0;
- }
+ inline int32 LineCount() const;
- float TotalHeight() const
- {
- float height = LineCount() * fFontInfo->lineHeight - 1;
- return std::max(height, kMinViewHeight);
- }
+ inline float TotalHeight() const;
- 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);
- }
+ void GetLineRange(BRect rect, int32& minLine,
+ int32& maxLine);
protected:
- SourceView* fSourceView;
- FontInfo* fFontInfo;
- SourceCode* fSourceCode;
+ SourceView* fSourceView;
+ FontInfo* fFontInfo;
+ SourceCode* fSourceCode;
};
class SourceView::MarkerView : public BaseView {
public:
- MarkerView(SourceView* sourceView, FontInfo* fontInfo)
- :
- BaseView("source marker view", sourceView, fontInfo),
- fStackTrace(NULL),
- fStackFrame(NULL),
- fMarkers(20, true),
- fMarkersValid(false)
- {
- SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
- }
+ MarkerView(SourceView* sourceView,
+ FontInfo* fontInfo);
+ ~MarkerView();
- ~MarkerView()
- {
- }
+ virtual void SetSourceCode(SourceCode* sourceCode);
- virtual void SetSourceCode(SourceCode* sourceCode)
- {
- fMarkers.MakeEmpty();
- fMarkersValid = false;
- BaseView::SetSourceCode(sourceCode);
- }
+ void SetStackTrace(StackTrace* stackTrace);
+ void SetStackFrame(StackFrame* stackFrame);
- void SetStackTrace(StackTrace* stackTrace)
- {
- fStackTrace = stackTrace;
- fMarkers.MakeEmpty();
- fMarkersValid = false;
- Invalidate();
- }
+ virtual BSize MinSize();
+ virtual BSize MaxSize();
- void SetStackFrame(StackFrame* stackFrame)
- {
- fStackFrame = stackFrame;
- fMarkers.MakeEmpty();
- fMarkersValid = false;
- Invalidate();
- }
+ virtual void Draw(BRect updateRect);
- virtual BSize MinSize()
- {
- return BSize(40, TotalHeight());
- }
+private:
+ struct Marker;
+ struct InstructionPointerMarker;
- virtual BSize MaxSize()
- {
- return BSize(MinSize().width, B_SIZE_UNLIMITED);
- }
+ typedef BObjectList<Marker> MarkerList;
- virtual void Draw(BRect updateRect)
- {
- _UpdateMarkers();
+private:
+ void _UpdateMarkers();
- if (fSourceCode == NULL || fMarkers.IsEmpty())
- return;
+private:
+ StackTrace* fStackTrace;
+ StackFrame* fStackFrame;
+ MarkerList fMarkers;
+ bool fMarkersValid;
+};
- // get the lines intersecting with the update rect
- int32 minLine, maxLine;
- GetLineRange(updateRect, minLine, maxLine);
- // draw the markers
- float width = Bounds().Width();
- // TODO: The markers should be sorted, so we don't need to iterate over
- // all of them.
- for (int32 i = 0; Marker* marker = fMarkers.ItemAt(i); i++) {
- int32 line = marker->Line();
- if (line < minLine || line > maxLine)
- continue;
+struct SourceView::MarkerView::Marker {
+ Marker(uint32 line);
+ virtual ~Marker();
- float y = (float)line * fFontInfo->lineHeight;
- BRect rect(0, y, width, y + fFontInfo->lineHeight - 1);
- marker->Draw(this, rect);
- }
+ inline uint32 Line() const;
- // TODO: Draw possible breakpoint marks!
- }
+ virtual void Draw(MarkerView* view, BRect rect) = 0;
private:
- struct Marker {
- Marker(uint32 line)
- :
- fLine(line)
- {
- }
+ uint32 fLine;
+};
- virtual ~Marker()
- {
- }
- uint32 Line() const
- {
- return fLine;
- }
+struct SourceView::MarkerView::InstructionPointerMarker : Marker {
+ InstructionPointerMarker(uint32 line,
+ bool topIP, bool currentIP);
- virtual void Draw(MarkerView* view, BRect rect) = 0;
+ virtual void Draw(MarkerView* view, BRect rect);
- private:
- uint32 fLine;
- };
+private:
+ void _DrawArrow(BView* view, BPoint tip, BSize size,
+ BSize base, const rgb_color& color,
+ bool fill);
- struct InstructionPointerMarker : Marker {
- InstructionPointerMarker(uint32 line, bool topIP, bool currentIP)
- :
- Marker(line),
- fIsTopIP(topIP),
- fIsCurrentIP(currentIP)
- {
- }
+private:
+ bool fIsTopIP;
+ bool fIsCurrentIP;
+};
- 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);
- }
- }
+class SourceView::TextView : public BaseView {
+public:
+ TextView(SourceView* sourceView,
+ FontInfo* fontInfo);
- private:
- void _DrawArrow(BView* view, BPoint tip, BSize size, BSize base,
- const rgb_color& color, bool fill)
- {
- view->SetHighColor(color);
+ virtual void SetSourceCode(SourceCode* sourceCode);
- 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;
+ virtual BSize MinSize();
+ virtual BSize MaxSize();
- 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);
+ virtual void Draw(BRect updateRect);
- if (fill)
- view->FillPolygon(points, 7);
- else
- view->StrokePolygon(points, 7);
- }
+private:
+ float _MaxLineWidth();
- private:
- bool fIsTopIP;
- bool fIsCurrentIP;
- };
+private:
+ float fMaxLineWidth;
+ rgb_color fTextColor;
+};
- typedef BObjectList<Marker> MarkerList;
-private:
- void _UpdateMarkers()
- {
- if (fMarkersValid)
- return;
+// #pragma mark - BaseView
- fMarkers.MakeEmpty();
- if (fSourceCode != NULL && fStackTrace != NULL) {
- for (int32 i = 0; StackFrame* frame = fStackTrace->FrameAt(i);
- i++) {
- target_addr_t ip = frame->InstructionPointer();
- Statement* statement = fSourceCode->StatementAtAddress(ip);
- if (statement == NULL)
- continue;
- uint32 line = statement->StartSourceLocation().Line();
- if (line >= (uint32)LineCount())
- continue;
+SourceView::BaseView::BaseView(const char* name, SourceView* sourceView,
+ FontInfo* fontInfo)
+ :
+ BView(name, B_WILL_DRAW | B_SUBPIXEL_PRECISE),
+ fSourceView(sourceView),
+ fFontInfo(fontInfo),
+ fSourceCode(NULL)
+{
+}
- Marker* marker = new(std::nothrow) InstructionPointerMarker(
- line, i == 0, frame == fStackFrame);
- if (marker == NULL || !fMarkers.AddItem(marker)) {
- delete marker;
- break;
- }
- }
- }
- // TODO: Filter duplicate IP markers (recursive functions)!
+void
+SourceView::BaseView::SetSourceCode(SourceCode* sourceCode)
+{
+ fSourceCode = sourceCode;
- fMarkersValid = true;
- }
+ InvalidateLayout();
+ Invalidate();
+}
-private:
- StackTrace* fStackTrace;
- StackFrame* fStackFrame;
- MarkerList fMarkers;
- bool fMarkersValid;
-};
+BSize
+SourceView::BaseView::PreferredSize()
+{
+ return MinSize();
+}
-class SourceView::TextView : public BaseView {
-public:
- TextView(SourceView* sourceView, FontInfo* fontInfo)
- :
- BaseView("source text view", sourceView, fontInfo),
- fMaxLineWidth(-1)
- {
- SetViewColor(ui_color(B_DOCUMENT_BACKGROUND_COLOR));
- fTextColor = ui_color(B_DOCUMENT_TEXT_COLOR);
- }
- virtual void SetSourceCode(SourceCode* sourceCode)
- {
- fMaxLineWidth = -1;
- BaseView::SetSourceCode(sourceCode);
- }
+int32
+SourceView::BaseView::LineCount() const
+{
+ return fSourceCode != NULL ? fSourceCode->CountLines() : 0;
+}
- virtual BSize MinSize()
- {
- return BSize(kLeftTextMargin + _MaxLineWidth() - 1, TotalHeight());
+
+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);
}
- virtual BSize MaxSize()
- {
- return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED);
+ // 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);
}
+}
- virtual void Draw(BRect updateRect)
- {
- if (fSourceCode == NULL)
- return;
- // get the lines intersecting with the update rect
- int32 minLine, maxLine;
- GetLineRange(updateRect, minLine, maxLine);
+void
+SourceView::MarkerView::InstructionPointerMarker::_DrawArrow(BView* view,
+ BPoint tip, BSize size, BSize base, const rgb_color& color, bool fill)
+{
+ view->SetHighColor(color);
- // draw the affected lines
- SetHighColor(fTextColor);
- SetFont(&fFontInfo->font);
- for (int32 i = minLine; i <= maxLine; i++) {
- float y = (float)(i + 1) * fFontInfo->lineHeight
- - fFontInfo->fontHeight.descent;
- DrawString(fSourceCode->LineAt(i), BPoint(kLeftTextMargin, y));
- }
+ 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),
+ fStackTrace(NULL),
+ fStackFrame(NULL),
+ fMarkers(20, true),
+ fMarkersValid(false)
+{
+ SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
+}
+
+
+SourceView::MarkerView::~MarkerView()
+{
+}
+
+
+void
+SourceView::MarkerView::SetSourceCode(SourceCode* sourceCode)
+{
+ fMarkers.MakeEmpty();
+ fMarkersValid = false;
+ BaseView::SetSourceCode(sourceCode);
+}
+
+
+void
+SourceView::MarkerView::SetStackTrace(StackTrace* stackTrace)
+{
+ fStackTrace = stackTrace;
+ fMarkers.MakeEmpty();
+ fMarkersValid = false;
+ Invalidate();
+}
+
+
+void
+SourceView::MarkerView::SetStackFrame(StackFrame* stackFrame)
+{
+ fStackFrame = stackFrame;
+ fMarkers.MakeEmpty();
+ fMarkersValid = false;
+ Invalidate();
+}
+
+
+BSize
+SourceView::MarkerView::MinSize()
+{
+ return BSize(40, TotalHeight());
+}
+
+
+BSize
+SourceView::MarkerView::MaxSize()
+{
+ return BSize(MinSize().width, B_SIZE_UNLIMITED);
+}
+
+void
+SourceView::MarkerView::Draw(BRect updateRect)
+{
+ _UpdateMarkers();
+
+ if (fSourceCode == NULL || fMarkers.IsEmpty())
+ return;
+
+ // get the lines intersecting with the update rect
+ int32 minLine, maxLine;
+ GetLineRange(updateRect, minLine, maxLine);
+
+ // draw the markers
+ float width = Bounds().Width();
+ // TODO: The markers should be sorted, so we don't need to iterate over
+ // all of them.
+ for (int32 i = 0; Marker* marker = fMarkers.ItemAt(i); i++) {
+ int32 line = marker->Line();
+ if (line < minLine || line > maxLine)
+ continue;
+
+ float y = (float)line * fFontInfo->lineHeight;
+ BRect rect(0, y, width, y + fFontInfo->lineHeight - 1);
+ marker->Draw(this, rect);
}
-private:
- float _MaxLineWidth()
- {
- if (fMaxLineWidth >= 0)
- return fMaxLineWidth;
+ // TODO: Draw possible breakpoint marks!
+}
- fMaxLineWidth = 0;
- if (fSourceCode != NULL) {
- for (int32 i = 0; const char* line = fSourceCode->LineAt(i); i++) {
- fMaxLineWidth = std::max(fMaxLineWidth,
- fFontInfo->font.StringWidth(line));
+
+void
+SourceView::MarkerView::_UpdateMarkers()
+{
+ if (fMarkersValid)
+ return;
+
+ fMarkers.MakeEmpty();
+
+ if (fSourceCode != NULL && fStackTrace != NULL) {
+ for (int32 i = 0; StackFrame* frame = fStackTrace->FrameAt(i);
+ i++) {
+ target_addr_t ip = frame->InstructionPointer();
+ Statement* statement = fSourceCode->StatementAtAddress(ip);
+ if (statement == NULL)
+ continue;
+ uint32 line = statement->StartSourceLocation().Line();
+ if (line >= (uint32)LineCount())
+ continue;
+
+ Marker* marker = new(std::nothrow) InstructionPointerMarker(
+ line, i == 0, frame == fStackFrame);
+ if (marker == NULL || !fMarkers.AddItem(marker)) {
+ delete marker;
+ break;
}
}
+ }
+ // TODO: Filter duplicate IP markers (recursive functions)!
+ fMarkersValid = true;
+}
+
+
+// #pragma mark - TextView
+
+
+SourceView::TextView::TextView(SourceView* sourceView, FontInfo* fontInfo)
+ :
+ BaseView("source text view", sourceView, fontInfo),
+ fMaxLineWidth(-1)
+{
+ SetViewColor(ui_color(B_DOCUMENT_BACKGROUND_COLOR));
+ fTextColor = ui_color(B_DOCUMENT_TEXT_COLOR);
+}
+
+
+void
+SourceView::TextView::SetSourceCode(SourceCode* sourceCode)
+{
+ fMaxLineWidth = -1;
+ BaseView::SetSourceCode(sourceCode);
+}
+
+
+BSize
+SourceView::TextView::MinSize()
+{
+ return BSize(kLeftTextMargin + _MaxLineWidth() - 1, TotalHeight());
+}
+
+
+BSize
+SourceView::TextView::MaxSize()
+{
+ return BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED);
+}
+
+
+void
+SourceView::TextView::Draw(BRect updateRect)
+{
+ if (fSourceCode == NULL)
+ return;
+
+ // get the lines intersecting with the update rect
+ int32 minLine, maxLine;
+ GetLineRange(updateRect, minLine, maxLine);
+
+ // draw the affected lines
+ SetHighColor(fTextColor);
+ SetFont(&fFontInfo->font);
+ for (int32 i = minLine; i <= maxLine; i++) {
+ float y = (float)(i + 1) * fFontInfo->lineHeight
+ - fFontInfo->fontHeight.descent;
+ DrawString(fSourceCode->LineAt(i), BPoint(kLeftTextMargin, y));
+ }
+}
+
+
+float
+SourceView::TextView::_MaxLineWidth()
+{
+ if (fMaxLineWidth >= 0)
return fMaxLineWidth;
+
+ fMaxLineWidth = 0;
+ if (fSourceCode != NULL) {
+ for (int32 i = 0; const char* line = fSourceCode->LineAt(i); i++) {
+ fMaxLineWidth = std::max(fMaxLineWidth,
+ fFontInfo->font.StringWidth(line));
+ }
}
-private:
- float fMaxLineWidth;
- rgb_color fTextColor;
-};
+ return fMaxLineWidth;
+}
// #pragma mark - SourceView
More information about the Haiku-commits
mailing list