xref: /haiku/src/apps/debugger/user_interface/gui/team_window/SourceView.h (revision 83b1a68c52ba3e0e8796282759f694b7fdddf06d)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Copyright 2013, Rene Gollent, rene@gollent.com.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef SOURCE_VIEW_H
7 #define SOURCE_VIEW_H
8 
9 
10 #include <Font.h>
11 #include <View.h>
12 
13 #include "Types.h"
14 
15 
16 class Breakpoint;
17 class FunctionInstance;
18 class SourceCode;
19 class StackFrame;
20 class StackTrace;
21 class Statement;
22 class Team;
23 class Thread;
24 class UserBreakpoint;
25 
26 
27 class SourceView : public BView {
28 public:
29 	class Listener;
30 
31 public:
32 								SourceView(Team* team, Listener* listener);
33 								~SourceView();
34 
35 	static	SourceView*			Create(Team* team, Listener* listener);
36 									// throws
37 
38 	virtual	void				MessageReceived(BMessage* message);
39 
40 			void				UnsetListener();
41 
42 			void				SetStackTrace(StackTrace* stackTrace,
43 									Thread* thread);
44 			void				SetStackFrame(StackFrame* stackFrame);
45 			void				SetSourceCode(SourceCode* sourceCode);
46 
47 			void				UserBreakpointChanged(
48 									UserBreakpoint* breakpoint);
49 
50 			bool				ScrollToAddress(target_addr_t address);
51 			bool				ScrollToLine(uint32 line);
52 
53 			void				HighlightBorder(bool state);
54 	virtual	void				TargetedByScrollView(BScrollView* scrollView);
55 
56 	virtual	BSize				MinSize();
57 	virtual	BSize				MaxSize();
58 	virtual	BSize				PreferredSize();
59 
60 	virtual	void				DoLayout();
61 
62 private:
63 			class BaseView;
64 			class MarkerManager;
65 			class MarkerView;
66 			class TextView;
67 
68 			// for gcc2
69 			friend class TextView;
70 			friend class MarkerView;
71 
72 			struct FontInfo {
73 				BFont		font;
74 				font_height	fontHeight;
75 				float		lineHeight;
76 			};
77 
78 protected:
79 			bool				GetStatementForLine(int32 line,
80 									Statement*& _statement);
81 
82 private:
83 			void				_Init();
84 			void				_UpdateScrollBars();
85 			BSize				_DataRectSize() const;
86 
87 private:
88 			Team*				fTeam;
89 			Thread*				fActiveThread;
90 			StackTrace*			fStackTrace;
91 			StackFrame*			fStackFrame;
92 			SourceCode*			fSourceCode;
93 			MarkerManager*		fMarkerManager;
94 			MarkerView*			fMarkerView;
95 			TextView*			fTextView;
96 			FontInfo			fFontInfo;
97 			Listener*			fListener;
98 };
99 
100 
101 class SourceView::Listener {
102 public:
103 	virtual						~Listener();
104 
105 	virtual	void				SetBreakpointRequested(
106 									target_addr_t address, bool enabled) = 0;
107 	virtual	void				ClearBreakpointRequested(
108 									target_addr_t address) = 0;
109 	virtual void				ThreadActionRequested(Thread* thread,
110 									uint32 action, target_addr_t address) = 0;
111 	virtual	void				FunctionSourceCodeRequested(
112 									FunctionInstance* function,
113 									bool forceDisassembly) = 0;
114 };
115 
116 
117 #endif	// SOURCE_VIEW_H
118